| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- package com.uas.sso.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.uas.sso.core.Status;
- import com.uas.sso.service.*;
- import org.springframework.data.domain.Page;
- import com.uas.sso.core.Const;
- import com.uas.sso.entity.User;
- import com.uas.sso.entity.UserAccount;
- import com.uas.sso.entity.Userspace;
- import com.uas.sso.exception.VisibleError;
- import com.uas.sso.support.SystemSession;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.ui.ModelMap;
- import org.springframework.util.CollectionUtils;
- import org.springframework.web.bind.annotation.*;
- /**
- * @author wangmh
- * @create 2018-01-13 19:39
- * @desc 云中心Controller
- **/
- @RestController
- @RequestMapping("/sso/center")
- public class YunCenterController extends BaseController {
- @Autowired
- private ApplyUserSpaceService applyUserSpaceService;
- @Autowired
- private UserService userService;
- @Autowired
- private UserspaceService userspaceService;
- @Autowired
- private UserspaceValidService userspaceValidService;
- /**
- * 获取登录用户信息
- * @return
- */
- @RequestMapping(value = "/user/info", method = RequestMethod.GET)
- public ModelMap findUserInfo() {
- // 获得登录用户
- UserAccount userAccount = SystemSession.getUserAccount();
- if (userAccount == null) {
- return error("未登录");
- }
- // 设置返回数据
- ModelMap data = new ModelMap();
- User user = userService.findOne(userAccount.getUserUU());
- user.setSalt(null);
- user.setPassword(null);
- data.put("user", new ModelMap().addAllAttributes(JSONObject.parseObject(JSONObject.toJSONString(user)))
- .addAttribute("hasQuestion", !CollectionUtils.isEmpty(user.getQuestions()))
- .addAttribute("lastLoginTime", user.getUserRecord().getLastLoginTime()));
- if (userAccount.getSpaceUU() != null) {
- Userspace userspace = userspaceService.findOne(userAccount.getSpaceUU());
- data.put("userspace", userspace);
- // 删除管理员的密码盐值,不返回给前端
- userspace.getAdmin().setSalt(null);
- userspace.getAdmin().setPassword(null);
- if (userspace.getValidCode() == Status.TO_BE_CERTIFIED.getCode()) {
- Userspace newUserSpace = userspaceValidService.getToBeCertified(userspace.getSpaceUU());
- data.put("newUserSpace", newUserSpace);
- }
- }
- // 删除用户密码和盐值,不返回给前端
- userAccount.setPassword(null);
- userAccount.setSalt(null);
- return success(data);
- }
- /**
- * 分页查询申请信息
- * @param page 页数
- * @param size 每页个数
- * @return
- */
- @RequestMapping(value = "/apply/info", method = RequestMethod.GET)
- @ResponseBody
- public ModelMap findApplyAll(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "20") int size) {
- UserAccount userAccount = SystemSession.getUserAccount();
- if (userAccount.getSpaceUU() == null) {
- return error(Const.SPACEUU_PERSONAL+"", "个人账号");
- }
- // 查询页面是从0开始,所以要减1
- return success(applyUserSpaceService.findApplyAll(page, size, userAccount.getSpaceUU()));
- }
- /**
- * 分页查询当前企业的所有人员
- * @param page 页号
- * @param size 每页大小
- * @return
- */
- @RequestMapping(value = "/member/info", method = RequestMethod.GET)
- @ResponseBody
- public ModelMap findMemberAll(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "20") int size) {
- UserAccount userAccount = getLoginUser();
- if (userAccount.getSpaceUU() == null) {
- return error(Const.SPACEUU_PERSONAL+"", "个人账号");
- }
- // 查询页面是从0开始,所以要减1
- Page<User> pUser = userService.findMemberBySpaceUU(page, size, userAccount.getSpaceUU());
- return success(pUser);
- }
- /**
- * 同意申请
- * @param userUU 用户uu号
- * @return
- */
- @RequestMapping(value = "/agree/apply", method = RequestMethod.POST)
- @ResponseBody
- public ModelMap agreeApply(Long userUU, Long id) {
- // 获取登录用户
- UserAccount userAccount = getLoginUser();
- if (userAccount.getSpaceUU() == null) {
- return error(Const.SPACEUU_PERSONAL+"", "个人账号");
- }
- // 同意申请操作
- applyUserSpaceService.agreeApply(userUU, id);
- return success();
- }
- /**
- * 拒绝申请
- * @param applyUserUU 申请者uu号
- * @return
- */
- @RequestMapping(value = "/disagree/apply", method = RequestMethod.POST)
- @ResponseBody
- public ModelMap disagreeApply(Long applyUserUU, Long id) {
- UserAccount userAccount = getLoginUser();
- if (userAccount.getSpaceUU() == null) {
- return error(String.valueOf(Const.SPACEUU_PERSONAL), "个人账号");
- }
- applyUserSpaceService.disagreeApply(applyUserUU, id);
- return success();
- }
- /**
- * 获取登录账号
- * @return
- */
- private UserAccount getLoginUser() {
- UserAccount userAccount = SystemSession.getUserAccount();
- if (userAccount == null) {
- throw new VisibleError("未登录");
- }
- return userAccount;
- }
- }
|