From 6c2a01f6bc53b27805dbd514ac7ea83b58af2323 Mon Sep 17 00:00:00 2001
From: liyj <1003249715@qq.com>
Date: Tue, 10 Sep 2024 20:34:18 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java | 137 +++++++++++++++++++++++++++++++++++++--------
1 files changed, 113 insertions(+), 24 deletions(-)
diff --git a/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java b/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java
index 5746d53..08bd4a3 100644
--- a/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java
+++ b/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java
@@ -10,7 +10,6 @@
import cn.huge.module.client.api.impl.UtilsClientImpl;
import cn.huge.module.constant.BaseConsts;
import cn.huge.module.ctrole.domain.po.CtRole;
-import cn.huge.module.ctrole.service.CtRoleService;
import cn.huge.module.ctuser.dao.mapper.CtUserMapper;
import cn.huge.module.ctuser.domain.po.*;
import cn.huge.module.ctuser.dto.CtUserSaveDTO;
@@ -18,6 +17,8 @@
import cn.huge.module.cust.constant.UserBaseConsts;
import cn.huge.module.cust.dto.CtUserDTO;
import cn.huge.module.redis.constant.RedisKeyConsts;
+import cn.huge.module.rsoper.domain.po.RsRole;
+import cn.huge.module.rsoper.service.RsRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -65,11 +66,11 @@
@Autowired
private CtUseroleService ctUseroleService;
@Autowired
- private CtRoleService ctRoleService;
- @Autowired
private CtUsepostService ctUsepostService;
@Autowired
private CtDeptService ctDeptService;
+ @Autowired
+ private RsRoleService rsRoleService;
@Autowired
private UtilsClientImpl utilsClient;
@@ -253,23 +254,13 @@
}
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 (ctUnit.getUnitType() == UserBaseConsts.UNIT_TYPE_4) {
- ctRoleQueryWrapper.ne("role_code", RoleBaseEnum.ROLE_9.getIndex());
- }
- List<CtRole> ctRoleList = ctRoleService.list(ctRoleQueryWrapper);
+ // 查询可选角色
List<SelectTermDTO> roleSelectTerms = new ArrayList<>();
- for (CtRole ctRole : ctRoleList) {
+ List<RsRole> rsRoleList = rsRoleService.list();
+ for (RsRole rsRole : rsRoleList) {
SelectTermDTO selectTerm = new SelectTermDTO();
- selectTerm.setValue(ctRole.getRoleCode());
- selectTerm.setLabel(ctRole.getName());
+ selectTerm.setValue(rsRole.getId());
+ selectTerm.setLabel(rsRole.getName());
roleSelectTerms.add(selectTerm);
}
result.put("roles", roleSelectTerms);
@@ -391,9 +382,9 @@
for (CtUserole ctUserole : ctUseroleList) {
ctUserole.setId(utilsClient.getNewTimeId());
ctUserole.setUserId(ctUser.getId());
- CtRole ctRole = ctRoleService.getByUnitIdAndRoleId(ctUser.getUnitId(), ctUserole.getRoleId());
- ctUserole.setRoleId(ctRole.getId());
- ctUserole.setRoleCode(ctRole.getRoleCode());
+ RsRole rsRole = rsRoleService.getById(ctUserole.getRoleId());
+ ctUserole.setRoleId(rsRole.getId());
+ ctUserole.setRoleCode(rsRole.getId());
ctUserole.setCustId(ctUser.getCustId());
ctUserole.setCreateTime(nowDate);
ctUserole.setUpdateTime(nowDate);
@@ -442,9 +433,9 @@
ctUserole.setId(utilsClient.getNewTimeId());
ctUserole.setUserId(ctUser.getId());
ctUserole.setCustId(ctUser.getCustId());
- CtRole ctRole = ctRoleService.getByUnitIdAndRoleId(ctUser.getUnitId(), ctUserole.getRoleId());
- ctUserole.setRoleId(ctRole.getId());
- ctUserole.setRoleCode(ctRole.getRoleCode());
+ RsRole rsRole = rsRoleService.getById(ctUserole.getRoleId());
+ ctUserole.setRoleId(rsRole.getId());
+ ctUserole.setRoleCode(rsRole.getId());
ctUserole.setCreateTime(nowDate);
ctUserole.setUpdateTime(nowDate);
ctUseroleService.save(ctUserole);
@@ -600,4 +591,102 @@
ctDeptService.updateCtDept(ctDept);
}
}
+
+ /**
+ * 根据部门和角色查询
+ * @param deptIdList 部门编号
+ * @param roleCode 角色代码
+ * @return List<SelectTermDTO>
+ */
+ public List<CtUser> listUserByDeptRoleList(List<String> deptIdList, String roleCode){
+ return mapper.listUserByDeptRoleList(deptIdList, roleCode);
+ }
+
+ /**
+ * 按条件分页查询
+ *
+ * @param userId 分页对象
+ * @param roleCode 条件
+ * @return Page
+ */
+ public List<SelectTermDTO> userChoose(String userId, String roleCode) {
+ // 获取当前登录用户
+ CtUserDTO loginUser = clientGetUserAll(userId);
+ // 组织条件
+ QueryWrapper<CtUnit> ctUnitQueryWrapper = new QueryWrapper<>();
+ if (RoleBaseEnum.checkAdminPower(loginUser)){
+ ctUnitQueryWrapper.eq("cust_id", loginUser.getCustId()).select("id", "unit_name", "parent_id");
+ }else {
+ ctUnitQueryWrapper.eq("id", loginUser.getUnitId()).select("id", "unit_name", "parent_id");
+ }
+ List<CtUnit> ctUnitList = ctUnitService.list(ctUnitQueryWrapper);
+ List<SelectTermDTO> unitSelectTerms = new ArrayList<>();
+
+ List<String> unitIdList= ctUnitList.stream().map(CtUnit::getId).collect(Collectors.toList());
+ // 部门条件
+ QueryWrapper<CtDept> ctDeptQueryWrapper = new QueryWrapper<>();
+ ctDeptQueryWrapper.in("unit_id", unitIdList).select("id", "unit_id", "name", "parent_id");
+ List<CtDept> ctDeptList = ctDeptService.list(ctDeptQueryWrapper);
+ List<String> deptIdList = ctDeptList.stream().map(CtDept::getId).collect(Collectors.toList());
+
+ // 人员条件
+ List<CtUser> ctUsers = null;
+ if (StringUtils.isNotEmpty(roleCode)){
+ ctUsers = listUserByDeptRoleList(deptIdList, roleCode);
+ }else {
+ QueryWrapper<CtUser> ctUserQueryWrapper = new QueryWrapper<>();
+ ctUserQueryWrapper.in("dept_id", deptIdList).select("id", "true_name", "dept_id");
+ ctUsers = this.list(ctUserQueryWrapper);
+ }
+ List<String> userIdList = ctUsers.stream().map(CtUser::getId).collect(Collectors.toList());
+ QueryWrapper<CtUserole> ctUserQueryWrapper = new QueryWrapper<>();
+ ctUserQueryWrapper.in("user_id", userIdList).select("user_id", "role_name");
+ List<CtUserole> roleList = ctUseroleService.list(ctUserQueryWrapper);
+
+ for(CtUnit ctUnit: ctUnitList){
+ SelectTermDTO unitSelectTerm = new SelectTermDTO();
+ unitSelectTerm.setValue(ctUnit.getId());
+ unitSelectTerm.setLabel(ctUnit.getUnitName());
+ unitSelectTerm.setParentId(ctUnit.getParentId());
+ unitSelectTerm.setCheckable(false);
+ List<SelectTermDTO> deptSelectTerms = new ArrayList<>();
+ for(CtDept ctDept : ctDeptList){
+ if(ctUnit.getId().equals(ctDept.getUnitId())){
+ SelectTermDTO deptSelectTerm = new SelectTermDTO();
+ deptSelectTerm.setValue(ctDept.getId());
+ deptSelectTerm.setLabel(ctDept.getName());
+ deptSelectTerm.setParentId(ctDept.getParentId());
+ deptSelectTerm.setCheckable(false);
+
+ if (CollectionUtils.isNotEmpty(ctUsers)) {
+ List<SelectTermDTO> userSelectTerms = new ArrayList<>();
+
+ for(CtUser ctUser : ctUsers){
+ if(ctUser.getDeptId().equals(ctDept.getId())){
+ List<CtUserole> ctUseroleList = new ArrayList<>();
+ for(CtUserole ctUserole: roleList){
+ if(ctUser.getId().equals(ctUserole.getUserId())){
+ ctUseroleList.add(ctUserole);
+ }
+ }
+ SelectTermDTO userSelectTerm = new SelectTermDTO();
+ userSelectTerm.setValue(ctUser.getId());
+ userSelectTerm.setCheckable(true);
+ String roleName = ctUseroleList.stream().map(CtUserole::getRoleName).collect(Collectors.joining(","));
+ userSelectTerm.setLabel(ctUser.getTrueName()+"("+roleName+")");
+ userSelectTerms.add(userSelectTerm);
+ }
+ }
+ List<SelectTermDTO> users = SelectTermUtils.createTreeByRoot(userSelectTerms);
+ deptSelectTerm.setChildren(users);
+ }
+ deptSelectTerms.add(deptSelectTerm);
+ }
+ List<SelectTermDTO> depts = SelectTermUtils.createTreeByRoot(deptSelectTerms);
+ unitSelectTerm.setChildren(depts);
+ }
+ unitSelectTerms.add(unitSelectTerm);
+ }
+ return SelectTermUtils.createTreeByFirst(unitSelectTerms, loginUser.getUnitId());
+ }
}
--
Gitblit v1.8.0