| | |
| | | package cn.huge.module.ctuser.controller; |
| | | package cn.huge.module.ctuser.controller.web; |
| | | |
| | | import cn.huge.base.common.dto.SelectTermDTO; |
| | | import cn.huge.base.common.utils.ObjectUtils; |
| | | import cn.huge.base.common.utils.ReturnFailUtils; |
| | | import cn.huge.base.common.utils.ReturnSucUtils; |
| | | import cn.huge.base.common.utils.SelectTermUtils; |
| | | import cn.huge.base.config.CurrentUser; |
| | | import cn.huge.module.ctuser.domain.po.CtUser; |
| | | import cn.huge.module.ctuser.service.CtUserService; |
| | | import cn.huge.module.ctrole.domain.po.CtRole; |
| | | import cn.huge.module.ctrole.service.CtRoleService; |
| | | import cn.huge.module.ctuser.domain.po.*; |
| | | import cn.huge.module.ctuser.service.*; |
| | | import cn.huge.module.cust.constant.RoleBaseEnum; |
| | | import cn.huge.module.cust.constant.UserBaseConsts; |
| | | import cn.huge.module.cust.dto.CtUserDTO; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.google.common.collect.Maps; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Page; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | |
| | | |
| | | @Autowired |
| | | private CtUserService service; |
| | | |
| | | @Autowired |
| | | private CtUnitService ctUnitService; |
| | | |
| | | @Autowired |
| | | private CtRoleService ctRoleService; |
| | | |
| | | @Autowired |
| | | private CtDeptService ctDeptService; |
| | | |
| | | @Autowired |
| | | private CtUseroleService ctUseroleService; |
| | | |
| | | @Autowired |
| | | private CtAccountService ctAccountService; |
| | | |
| | | @Autowired |
| | | private CtUsepostService ctUsepostService; |
| | | |
| | | /** |
| | | * 获取请求URL参数 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取人员信息列表查询条件 |
| | | * @url {ctx}/api/v1/ctUser/listSelectTerm |
| | | * @return userId 登录用户标识称 |
| | | * @return Object |
| | | * @throws Exception |
| | | */ |
| | | @GetMapping("/listSelectTerm") |
| | | public Object listSelectTerm(@CurrentUser String userId) { |
| | | try { |
| | | Map<String, Object> result = Maps.newHashMap(); |
| | | // 获取当前登录用户 |
| | | CtUser loginUser = service.getById(userId); |
| | | // 组织条件 |
| | | QueryWrapper<CtUnit> ctUnitQueryWrapper = new QueryWrapper<>(); |
| | | ctUnitQueryWrapper.eq("cust_id", loginUser.getCustId()); |
| | | List<CtUnit> ctUnits = ctUnitService.list(ctUnitQueryWrapper); |
| | | List<SelectTermDTO> unitSelectTerms = new ArrayList<>(); |
| | | for (CtUnit ctUnit: ctUnits) { |
| | | SelectTermDTO unitSelectTerm = new SelectTermDTO(); |
| | | unitSelectTerm.setValue(ctUnit.getId()); |
| | | unitSelectTerm.setLabel(ctUnit.getUnitName()); |
| | | unitSelectTerm.setParentId(ctUnit.getParentId()); |
| | | unitSelectTerms.add(unitSelectTerm); |
| | | |
| | | // 部门条件 |
| | | QueryWrapper<CtDept> ctDeptQueryWrapper = new QueryWrapper<>(); |
| | | ctDeptQueryWrapper.eq("unit_id", ctUnit.getId()); |
| | | List<CtDept> ctDepts = ctDeptService.list(ctDeptQueryWrapper); |
| | | if (CollectionUtils.isNotEmpty(ctDepts)) { |
| | | List<SelectTermDTO> deptSelectTerms = new ArrayList<>(); |
| | | for (CtDept ctDept : ctDepts) { |
| | | SelectTermDTO deptSelectTerm = new SelectTermDTO(); |
| | | deptSelectTerm.setValue(ctDept.getId()); |
| | | deptSelectTerm.setLabel(ctDept.getName()); |
| | | deptSelectTerm.setParentId(ctDept.getParentId()); |
| | | deptSelectTerms.add(deptSelectTerm); |
| | | } |
| | | List<SelectTermDTO> depts = SelectTermUtils.createTreeByRoot(deptSelectTerms); |
| | | unitSelectTerm.setChainList(depts); |
| | | } |
| | | } |
| | | result.put("units", SelectTermUtils.createTreeByFirst(unitSelectTerms, loginUser.getUnitId())); |
| | | |
| | | // 角色条件 |
| | | QueryWrapper<CtRole> ctRoleQueryWrapper = new QueryWrapper<>(); |
| | | ctRoleQueryWrapper.eq("unit_id", loginUser.getUnitId()); |
| | | //判断是否为村居(村居不应该有调委会管理员角色) |
| | | QueryWrapper<CtUnit> ctUnitQueryWrapper1 = new QueryWrapper<>(); |
| | | ctUnitQueryWrapper1.eq("id", loginUser.getUnitId()).eq("cust_id", loginUser.getCustId()) |
| | | .select("unit_type"); |
| | | CtUnit ctUnit = ctUnitService.getOne(ctUnitQueryWrapper1); |
| | | if(UserBaseConsts.UNIT_TYPE_4.equals(ctUnit.getUnitType())){ |
| | | ctRoleQueryWrapper.ne("role_code", RoleBaseEnum.ROLE_9.getIndex()); |
| | | } |
| | | List<CtRole> ctRoleList = ctRoleService.list(ctRoleQueryWrapper); |
| | | List<SelectTermDTO> roleSelectTerms = new ArrayList<>(); |
| | | for (CtRole ctRole: ctRoleList){ |
| | | SelectTermDTO selectTerm = new SelectTermDTO(); |
| | | selectTerm.setValue(ctRole.getRoleCode()); |
| | | selectTerm.setLabel(ctRole.getName()); |
| | | roleSelectTerms.add(selectTerm); |
| | | } |
| | | result.put("roles", roleSelectTerms); |
| | | return ReturnSucUtils.getRepInfo( "查询成功", result); |
| | | } catch (Exception e) { |
| | | log.error("Controller接口[CtUserController.listSelectTerm]请求异常:"+e, e); |
| | | return ReturnFailUtils.getRepInfo("查询失败", null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 条件分页查询人员信息 |
| | | * @url {ctx}/api/v1/ctUser/pageQuery |
| | | * @param page 页码 |
| | | * @param size 每页数量 |
| | | * @return Object |
| | | */ |
| | | @GetMapping("/pageQuery") |
| | | public Object pageQuery(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size, |
| | | @CurrentUser String userId) { |
| | | try { |
| | | // 获取当前登录用户 |
| | | CtUserDTO loginUser = service.clientGetUserAll(userId); |
| | | Map<String, Object> result = Maps.newHashMap(); |
| | | Map<String, Object> terms = getParameter(); |
| | | if (RoleBaseEnum.checkAdminPower(loginUser)){ |
| | | terms.put("custId", loginUser.getCustId()); |
| | | }else if (RoleBaseEnum.checkCourtOrUnitPower(loginUser.getRoleCodes())){ |
| | | terms.put("custId", loginUser.getCustId()); |
| | | String unitId = (String) terms.get("unitId"); |
| | | if (StringUtils.isEmpty(unitId)){ |
| | | terms.put("unitId", loginUser.getUnitId()); |
| | | } |
| | | }else { |
| | | terms.put("custId", loginUser.getCustId()); |
| | | terms.put("id", loginUser.getId()); |
| | | } |
| | | Sort sort = Sort.by(Sort.Direction.DESC, "t1.create_time"); |
| | | PageRequest pageRequest = PageRequest.of(page-1, size, sort); |
| | | Page<CtUser> ctUserPage = service.pageUserAndRole(pageRequest, terms); |
| | | QueryWrapper<CtAccount> accountQueryWrapper = new QueryWrapper<>(); |
| | | QueryWrapper<CtUserole> ctUseroleQueryWrapper = new QueryWrapper<>(); |
| | | QueryWrapper<CtUsepost> ctUsepostQueryWrapper = new QueryWrapper<>(); |
| | | for (CtUser ctUser: ctUserPage){ |
| | | accountQueryWrapper.clear(); |
| | | // 密码 |
| | | accountQueryWrapper.eq("acc_type", UserBaseConsts.ACC_TYPE_1); |
| | | accountQueryWrapper.eq("user_id", ctUser.getId()); |
| | | CtAccount ctAccount = ctAccountService.getOne(accountQueryWrapper); |
| | | if (ObjectUtils.isNotEmpty(ctAccount)){ |
| | | ctUser.setAcc(ctAccount.getAcc()); |
| | | ctUser.setCipher(ctAccount.getCipherOpen()); |
| | | } |
| | | // 角色 |
| | | ctUseroleQueryWrapper.clear(); |
| | | ctUseroleQueryWrapper.eq("user_id", ctUser.getId()); |
| | | List<CtUserole> ctUseroleList = ctUseroleService.list(ctUseroleQueryWrapper); |
| | | if (ObjectUtils.isNotEmpty(ctUseroleList)){ |
| | | for (CtUserole ctUserole: ctUseroleList){ |
| | | ctUserole.setRoleId(ctUserole.getRoleCode()); |
| | | } |
| | | ctUser.setCtUseroleList(ctUseroleList); |
| | | } |
| | | // 岗位 |
| | | ctUsepostQueryWrapper.clear(); |
| | | ctUsepostQueryWrapper.eq("user_id", ctUser.getId()); |
| | | List<CtUsepost> ctUsepostList = ctUsepostService.list(ctUsepostQueryWrapper); |
| | | if (ObjectUtils.isNotEmpty(ctUsepostList)) { |
| | | ctUser.setCtUsepostList(ctUsepostList); |
| | | } |
| | | } |
| | | result.put("ctUserPage", ctUserPage); |
| | | terms = Maps.newHashMap(); |
| | | // 生效名额 |
| | | terms.put("status", UserBaseConsts.USER_STATUS_1); |
| | | terms.put("custId", loginUser.getCustId()); |
| | | if (RoleBaseEnum.checkAdminPower(loginUser)){ |
| | | terms.put("custId", loginUser.getCustId()); |
| | | }else if (RoleBaseEnum.checkCourtOrUnitPower(loginUser.getRoleCodes())){ |
| | | terms.put("custId", loginUser.getCustId()); |
| | | String unitId = (String) terms.get("unitId"); |
| | | if (StringUtils.isEmpty(unitId)){ |
| | | terms.put("unitId", loginUser.getUnitId()); |
| | | } |
| | | }else { |
| | | terms.put("custId", loginUser.getCustId()); |
| | | terms.put("id", loginUser.getId()); |
| | | } |
| | | long countZzStatus = service.countTerms(terms); |
| | | result.put("countZzStatus", countZzStatus); |
| | | return ReturnSucUtils.getRepInfo( "处理成功", result); |
| | | } catch (Exception e) { |
| | | log.error("Controller接口[CtUserController.pageQuery]请求异常:"+e, e); |
| | | return ReturnFailUtils.getRepInfo(e.getMessage(), null); |
| | | } |
| | | } |
| | | } |