forked from gzzfw/backEnd/gz-dyh

xusd
2024-10-17 adddb6522e95c08bef6bc6b00338ff27d82aa55d
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;
@@ -214,6 +215,10 @@
        return mapper.selectById(loginUserId);
    }
    public CtUser getByIdCard(String idCard) {
        return mapper.selectByIdCard(idCard);
    }
    /**
     * web端-获取人员信息列表查询条件
     * @param userId 当前登录用户编号
@@ -253,23 +258,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);
@@ -363,7 +358,11 @@
                ctUser.setJoinWay(UserBaseConsts.JOIN_WAY_1);
                ctUser.setRealStatus(UserBaseConsts.REAL_STATUS_0);
                ctUser.setStatus(UserBaseConsts.USER_STATUS_1);
                ctUser.setCustId(loginUser.getCustId());
                if(loginUser!=null){
                    ctUser.setCustId(loginUser.getCustId());
                }else {
                    ctUser.setCustId("-1");
                }
                mapper.insert(ctUser);
                // 创建账号
@@ -391,9 +390,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 +441,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 +599,55 @@
            ctDeptService.updateCtDept(ctDept);
        }
    }
    /**
     * 根据部门和角色查询
     * @param unitId 组织编号
     * @param roleCode 角色代码
     * @return List<SelectTermDTO>
     */
    public List<CtUser> listUserByDeptRoleList(String unitId, String roleCode){
        return mapper.listUserByUnitRoleList(unitId, roleCode);
    }
    /**
     * 选择人员
     * @param userId
     * @param roleCode
     * @return
     */
    public List<SelectTermDTO> userChoose(String userId, String roleCode) {
        try {
            // 获取当前登录用户
            CtUserDTO loginUser = clientGetUserAll(userId);
            List<SelectTermDTO> result = new ArrayList<>();
            // 人员条件
            List<CtUser> ctUsers = null;
            if (StringUtils.isNotEmpty(roleCode)){
                ctUsers = listUserByDeptRoleList(loginUser.getUnitId(), roleCode);
            }else {
                QueryWrapper<CtUser> ctUserQueryWrapper = new QueryWrapper<>();
                ctUserQueryWrapper.in("unit_id", loginUser.getUnitId()).select("id", "true_name");
                ctUsers = this.list(ctUserQueryWrapper);
            }
            SelectTermDTO unitSelectTerm = new SelectTermDTO();
            unitSelectTerm.setValue(loginUser.getUnitId());
            unitSelectTerm.setLabel(loginUser.getUnitName());
            unitSelectTerm.setCheckable(false);
            List<SelectTermDTO> userSelectTerms = new ArrayList<>();
            for(CtUser ctUser : ctUsers){
                SelectTermDTO userSelectTerm = new SelectTermDTO();
                userSelectTerm.setValue(ctUser.getId());
                userSelectTerm.setCheckable(true);
                userSelectTerm.setLabel(ctUser.getTrueName());
                userSelectTerms.add(userSelectTerm);
            }
            unitSelectTerm.setChildren(userSelectTerms);
            result.add(unitSelectTerm);
            return result;
        }catch (Exception e) {
            log.error("[CtUserService.userChoose]调用失败,异常信息:" + e, e);
            throw new ServiceException("CtUserService.userChoose", e);
        }
    }
}