Sfoglia il codice sorgente

feat: user role limit

shc 8 mesi fa
parent
commit
e3afa265ac

+ 214 - 214
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/SysUserController.java

@@ -449,7 +449,7 @@ public class SysUserController {
         // 姓名去除空格(包括字符之间的所有空格都会去除)
         userDto.setRealname(StrUtil.cleanBlank(userDto.getRealname()));
 
-        SysDept sysDept = sysDeptService.getById(userDto.getDeptId());
+        // SysDept sysDept = sysDeptService.getById(userDto.getDeptId());
 
         List<SysUser> queryUserByPhoneList = userService.list(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, userDto.getUsername()));
         if (CollUtil.isNotEmpty(queryUserByPhoneList)) {
@@ -460,208 +460,208 @@ public class SysUserController {
         }
 
 
-        if (userDto.getRole().contains(2)) {
-            UserDTO userDTO = new UserDTO();
-            userDTO.setUsername(userDto.getUsername());
-            userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
-            List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
-
-            if (CollUtil.isNotEmpty(userDTOList)) {
-                for (UserVO userVO : userDTOList) {
-                    if (null != userVO.getRoleList()) {
-                        for (SysRole sysRole : userVO.getRoleList()) {
-                            if (sysRole.getRoleId() == 3) {
-                                return R.failed("用户已存在平台管理员角色,不能同时为药企管理员");
-                            }
-                            if (sysRole.getRoleId() == 4) {
-                                return R.failed("用户已存在平台管理员角色,不能同时为CSO管理员");
-                            }
-                            if (sysRole.getRoleId() == 5) {
-                                return R.failed("用户已存在平台管理员角色,不能同时为全职学术推广员");
-                            }
-                            if (sysRole.getRoleId() == 6) {
-                                return R.failed("用户已存在平台管理员角色,不能同时为兼职学术推广员");
-                            }
-                            if (sysRole.getRoleId() == 7) {
-                                return R.failed("用户已存在平台管理员角色,不能同时为财务管理员");
-                            }
-                            if (sysRole.getRoleId() == 31) {
-                                return R.failed("用户已存在平台管理员角色,不能同时为招商经理");
-                            }
-                        }
-                    }
-                }
-            }
-
-        } else if (userDto.getRole().contains(3)) {
-            UserDTO userDTO = new UserDTO();
-            userDTO.setUsername(userDto.getUsername());
-            userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
-            List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
-            if (CollUtil.isNotEmpty(userDTOList)) {
-                for (UserVO userVO : userDTOList) {
-                    if (null != userVO.getRoleList()) {
-                        for (SysRole sysRole : userVO.getRoleList()) {
-                            if (sysRole.getRoleId() == 2) {
-                                return R.failed("用户已存在药企管理员角色,不能同时为平台管理员");
-                            }
-
-                            if (sysRole.getRoleId() == 3) {
-                                return R.failed("用户已存在药企管理员角色,不能同时为药企管理员");
-                            }
-
-                            if (sysRole.getRoleId() == 4) {
-                                return R.failed("用户已存在药企管理员角色,不能同时为CSO管理员");
-                            }
-//							SysDept sysDept = sysDeptService.getById(userVO.getDeptId());
-                            if (sysDept.getLevel() == 3 || sysDept.getLevel() == 4) {
-                                if (sysRole.getRoleId() == 5) {
-                                    return R.failed("用户已存在CSO关系角色,不能同时为药企管理员");
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-
-        } else if (userDto.getRole().contains(4) || userDto.getRole().contains(37)) {
-            UserDTO userDTO = new UserDTO();
-            userDTO.setUsername(userDto.getUsername());
-            userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
-            List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
-            if (CollUtil.isNotEmpty(userDTOList)) {
-                for (UserVO userVO : userDTOList) {
-                    if (null != userVO.getRoleList()) {
-                        for (SysRole sysRole : userVO.getRoleList()) {
-                            if (sysRole.getRoleId() == 2) {
-                                return R.failed("用户已存在平台管理员角色,不能同时为CSO管理员");
-                            }
-                            if (sysRole.getRoleId() == 4) {
-                                return R.failed("用户已存在CSO管理员角色,不能为其他机构CSO管理员");
-                            }
-                            if (sysRole.getRoleId() == 9) {
-                                return R.failed("用户已存在CRO管理员,不能同时为CSO管理员");
-                            }
-
-                            if (sysRole.getRoleId() == 3) {
-                                return R.failed("用户已存在药企管理员角色,不能同时为CSO管理员");
-                            }
-                            if (sysRole.getRoleId() == 5) {
-                                SysUserRole sysUserRole = new SysUserRole();
-                                sysUserRole.setUserId(userVO.getUserId());
-                                List<SysUserRole> sysUserRoleList = sysUserRoleMapper.selectById(sysUserRole);
-                                for (SysUserRole userRole : sysUserRoleList) {
-                                    SysUser sysUser = userService.getById(userRole.getUserId());
-                                    if (!sysUser.getDeptId().equals(userDto.getDeptId())) {
-                                        return R.failed("用户已存在全职学术推广员角色,不能为其他机构CSO管理员");
-                                    }
-                                }
-                            }
-                            if (sysRole.getRoleId() == 31) {
-                                SysUserRole sysUserRole = new SysUserRole();
-                                sysUserRole.setUserId(userVO.getUserId());
-                                List<SysUserRole> sysUserRoleList = sysUserRoleMapper.selectById(sysUserRole);
-                                for (SysUserRole userRole : sysUserRoleList) {
-                                    SysUser sysUser = userService.getById(userRole.getUserId());
-                                    if (!sysUser.getDeptId().equals(userDto.getDeptId())) {
-                                        return R.failed("用户已存在招商经理角色,不能为其他机构CSO管理员");
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-
-        } else if (userDto.getRole().contains(7)) {
-            UserDTO userDTO = new UserDTO();
-            userDTO.setUsername(userDto.getUsername());
-            userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
-            List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
-            if (CollUtil.isNotEmpty(userDTOList)) {
-                for (UserVO userVO : userDTOList) {
-                    if (null != userVO.getRoleList()) {
-                        for (SysRole sysRole : userVO.getRoleList()) {
-                            if (sysRole.getRoleId() == 2) {
-                                return R.failed("用户已存在平台管理员,不能同时为财务管理员");
-                            }
-                            if (sysDept.getLevel() == 3 || sysDept.getLevel() == 4) {
-                                if (sysRole.getRoleId() == 3) {
-                                    return R.failed("用户已存在药企管理员,不能同时为CSO机构财务管理员");
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-
-        } else if (userDto.getRole().contains(9)) {
-            UserDTO userDTO = new UserDTO();
-            userDTO.setUsername(userDto.getUsername());
-            userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
-            List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
-            if (CollUtil.isNotEmpty(userDTOList)) {
-                for (UserVO userVO : userDTOList) {
-                    if (null != userVO.getRoleList()) {
-                        for (SysRole sysRole : userVO.getRoleList()) {
-                            if (sysRole.getRoleId() == 2) {
-                                return R.failed("用户已存在平台管理员,不能同时为CRO管理员");
-                            }
-                            if (sysRole.getRoleId() == 3) {
-                                return R.failed("用户已存在药企管理员,不能同时为CRO管理员");
-                            }
-                            if (sysRole.getRoleId() == 4) {
-                                return R.failed("用户已存在CSO管理员角色,不能同时为CRO管理员");
-                            }
-                            if (sysRole.getRoleId() == 9) {
-                                return R.failed("用户已存在CRO管理员角色");
-                            }
-                        }
-                    }
-                }
-            }
-
-        } else if (userDto.getRole().contains(31)) {
-            UserDTO userDTO = new UserDTO();
-            userDTO.setUsername(userDto.getUsername());
-            userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
-            List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
-            if (CollUtil.isNotEmpty(userDTOList)) {
-                for (UserVO userVO : userDTOList) {
-                    for (SysRole sysRole : userVO.getRoleList()) {
-                        if (sysRole.getRoleId() == 2) {
-                            return R.failed("用户已存在平台管理员,不能同时为招商经理");
-                        }
-                        if (sysRole.getRoleId() == 3) {
-                            if (sysDept.getLevel() == 3 || sysDept.getLevel() == 4) {
-                                return R.failed("用户已存在药企管理员,不能为CSO的招商经理");
-                            }
-                        }
-                        if (sysRole.getRoleId() == 4) {
-                            if (sysDept.getLevel() == 3 || sysDept.getLevel() == 4) {
-                                return R.failed("用户已存在CSO管理员,不能为其他CSO的招商经理");
-                            }
-                        }
-
-                    }
-                }
-            }
-        }
-
-        if (userDto.getRole().contains(3)) {
-            if (sysDept.getLevel() != 2) {
-                return R.failed("角色选为药企管理员时,组织架构必须为药企");
-            }
-        }
-        // }
-        if (!userDto.getDeptId().equals(SecurityUtils.getUser().getDeptId())) {
-            if (userDto.getRole().contains(5) || userDto.getRole().contains(6)) {
-                return R.failed("不能跨机构维护学术推广员");
-            }
-            if (userDto.getRole().contains(31)) {
-                return R.failed("不能跨机构维护招商经理");
-            }
-        }
+//         if (userDto.getRole().contains(2)) {
+//             UserDTO userDTO = new UserDTO();
+//             userDTO.setUsername(userDto.getUsername());
+//             userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
+//             List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
+//
+//             if (CollUtil.isNotEmpty(userDTOList)) {
+//                 for (UserVO userVO : userDTOList) {
+//                     if (null != userVO.getRoleList()) {
+//                         for (SysRole sysRole : userVO.getRoleList()) {
+//                             if (sysRole.getRoleId() == 3) {
+//                                 return R.failed("用户已存在平台管理员角色,不能同时为药企管理员");
+//                             }
+//                             if (sysRole.getRoleId() == 4) {
+//                                 return R.failed("用户已存在平台管理员角色,不能同时为CSO管理员");
+//                             }
+//                             if (sysRole.getRoleId() == 5) {
+//                                 return R.failed("用户已存在平台管理员角色,不能同时为全职学术推广员");
+//                             }
+//                             if (sysRole.getRoleId() == 6) {
+//                                 return R.failed("用户已存在平台管理员角色,不能同时为兼职学术推广员");
+//                             }
+//                             if (sysRole.getRoleId() == 7) {
+//                                 return R.failed("用户已存在平台管理员角色,不能同时为财务管理员");
+//                             }
+//                             if (sysRole.getRoleId() == 31) {
+//                                 return R.failed("用户已存在平台管理员角色,不能同时为招商经理");
+//                             }
+//                         }
+//                     }
+//                 }
+//             }
+//
+//         } else if (userDto.getRole().contains(3)) {
+//             UserDTO userDTO = new UserDTO();
+//             userDTO.setUsername(userDto.getUsername());
+//             userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
+//             List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
+//             if (CollUtil.isNotEmpty(userDTOList)) {
+//                 for (UserVO userVO : userDTOList) {
+//                     if (null != userVO.getRoleList()) {
+//                         for (SysRole sysRole : userVO.getRoleList()) {
+//                             if (sysRole.getRoleId() == 2) {
+//                                 return R.failed("用户已存在药企管理员角色,不能同时为平台管理员");
+//                             }
+//
+//                             if (sysRole.getRoleId() == 3) {
+//                                 return R.failed("用户已存在药企管理员角色,不能同时为药企管理员");
+//                             }
+//
+//                             if (sysRole.getRoleId() == 4) {
+//                                 return R.failed("用户已存在药企管理员角色,不能同时为CSO管理员");
+//                             }
+// //							SysDept sysDept = sysDeptService.getById(userVO.getDeptId());
+//                             if (sysDept.getLevel() == 3 || sysDept.getLevel() == 4) {
+//                                 if (sysRole.getRoleId() == 5) {
+//                                     return R.failed("用户已存在CSO关系角色,不能同时为药企管理员");
+//                                 }
+//                             }
+//                         }
+//                     }
+//                 }
+//             }
+//
+//         } else if (userDto.getRole().contains(4) || userDto.getRole().contains(37)) {
+//             UserDTO userDTO = new UserDTO();
+//             userDTO.setUsername(userDto.getUsername());
+//             userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
+//             List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
+//             if (CollUtil.isNotEmpty(userDTOList)) {
+//                 for (UserVO userVO : userDTOList) {
+//                     if (null != userVO.getRoleList()) {
+//                         for (SysRole sysRole : userVO.getRoleList()) {
+//                             if (sysRole.getRoleId() == 2) {
+//                                 return R.failed("用户已存在平台管理员角色,不能同时为CSO管理员");
+//                             }
+//                             if (sysRole.getRoleId() == 4) {
+//                                 return R.failed("用户已存在CSO管理员角色,不能为其他机构CSO管理员");
+//                             }
+//                             if (sysRole.getRoleId() == 9) {
+//                                 return R.failed("用户已存在CRO管理员,不能同时为CSO管理员");
+//                             }
+//
+//                             if (sysRole.getRoleId() == 3) {
+//                                 return R.failed("用户已存在药企管理员角色,不能同时为CSO管理员");
+//                             }
+//                             if (sysRole.getRoleId() == 5) {
+//                                 SysUserRole sysUserRole = new SysUserRole();
+//                                 sysUserRole.setUserId(userVO.getUserId());
+//                                 List<SysUserRole> sysUserRoleList = sysUserRoleMapper.selectById(sysUserRole);
+//                                 for (SysUserRole userRole : sysUserRoleList) {
+//                                     SysUser sysUser = userService.getById(userRole.getUserId());
+//                                     if (!sysUser.getDeptId().equals(userDto.getDeptId())) {
+//                                         return R.failed("用户已存在全职学术推广员角色,不能为其他机构CSO管理员");
+//                                     }
+//                                 }
+//                             }
+//                             if (sysRole.getRoleId() == 31) {
+//                                 SysUserRole sysUserRole = new SysUserRole();
+//                                 sysUserRole.setUserId(userVO.getUserId());
+//                                 List<SysUserRole> sysUserRoleList = sysUserRoleMapper.selectById(sysUserRole);
+//                                 for (SysUserRole userRole : sysUserRoleList) {
+//                                     SysUser sysUser = userService.getById(userRole.getUserId());
+//                                     if (!sysUser.getDeptId().equals(userDto.getDeptId())) {
+//                                         return R.failed("用户已存在招商经理角色,不能为其他机构CSO管理员");
+//                                     }
+//                                 }
+//                             }
+//                         }
+//                     }
+//                 }
+//             }
+//
+//         } else if (userDto.getRole().contains(7)) {
+//             UserDTO userDTO = new UserDTO();
+//             userDTO.setUsername(userDto.getUsername());
+//             userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
+//             List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
+//             if (CollUtil.isNotEmpty(userDTOList)) {
+//                 for (UserVO userVO : userDTOList) {
+//                     if (null != userVO.getRoleList()) {
+//                         for (SysRole sysRole : userVO.getRoleList()) {
+//                             if (sysRole.getRoleId() == 2) {
+//                                 return R.failed("用户已存在平台管理员,不能同时为财务管理员");
+//                             }
+//                             if (sysDept.getLevel() == 3 || sysDept.getLevel() == 4) {
+//                                 if (sysRole.getRoleId() == 3) {
+//                                     return R.failed("用户已存在药企管理员,不能同时为CSO机构财务管理员");
+//                                 }
+//                             }
+//                         }
+//                     }
+//                 }
+//             }
+//
+//         } else if (userDto.getRole().contains(9)) {
+//             UserDTO userDTO = new UserDTO();
+//             userDTO.setUsername(userDto.getUsername());
+//             userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
+//             List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
+//             if (CollUtil.isNotEmpty(userDTOList)) {
+//                 for (UserVO userVO : userDTOList) {
+//                     if (null != userVO.getRoleList()) {
+//                         for (SysRole sysRole : userVO.getRoleList()) {
+//                             if (sysRole.getRoleId() == 2) {
+//                                 return R.failed("用户已存在平台管理员,不能同时为CRO管理员");
+//                             }
+//                             if (sysRole.getRoleId() == 3) {
+//                                 return R.failed("用户已存在药企管理员,不能同时为CRO管理员");
+//                             }
+//                             if (sysRole.getRoleId() == 4) {
+//                                 return R.failed("用户已存在CSO管理员角色,不能同时为CRO管理员");
+//                             }
+//                             if (sysRole.getRoleId() == 9) {
+//                                 return R.failed("用户已存在CRO管理员角色");
+//                             }
+//                         }
+//                     }
+//                 }
+//             }
+//
+//         } else if (userDto.getRole().contains(31)) {
+//             UserDTO userDTO = new UserDTO();
+//             userDTO.setUsername(userDto.getUsername());
+//             userDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
+//             List<UserVO> userDTOList = sysUserMapper.selectByPhone(userDTO);
+//             if (CollUtil.isNotEmpty(userDTOList)) {
+//                 for (UserVO userVO : userDTOList) {
+//                     for (SysRole sysRole : userVO.getRoleList()) {
+//                         if (sysRole.getRoleId() == 2) {
+//                             return R.failed("用户已存在平台管理员,不能同时为招商经理");
+//                         }
+//                         if (sysRole.getRoleId() == 3) {
+//                             if (sysDept.getLevel() == 3 || sysDept.getLevel() == 4) {
+//                                 return R.failed("用户已存在药企管理员,不能为CSO的招商经理");
+//                             }
+//                         }
+//                         if (sysRole.getRoleId() == 4) {
+//                             if (sysDept.getLevel() == 3 || sysDept.getLevel() == 4) {
+//                                 return R.failed("用户已存在CSO管理员,不能为其他CSO的招商经理");
+//                             }
+//                         }
+//
+//                     }
+//                 }
+//             }
+//         }
+//
+//         if (userDto.getRole().contains(3)) {
+//             if (sysDept.getLevel() != 2) {
+//                 return R.failed("角色选为药企管理员时,组织架构必须为药企");
+//             }
+//         }
+//         // }
+//         if (!userDto.getDeptId().equals(SecurityUtils.getUser().getDeptId())) {
+//             if (userDto.getRole().contains(5) || userDto.getRole().contains(6)) {
+//                 return R.failed("不能跨机构维护学术推广员");
+//             }
+//             if (userDto.getRole().contains(31)) {
+//                 return R.failed("不能跨机构维护招商经理");
+//             }
+//         }
         SysUser query = new SysUser();
         query.setUsername(userDto.getUsername());
         query.setDeptId(userDto.getDeptId());
@@ -712,10 +712,10 @@ public class SysUserController {
         // 校验服务商
         HnqzUser operator = SecurityUtils.getUser();
         Integer deptId = resource.getDeptId();
-        if (!deptId.equals(operator.getDeptId())) {
-
-            return R.failed("不能跨机构维护学术推广员");
-        }
+        // if (!deptId.equals(operator.getDeptId())) {
+        //
+        //     return R.failed("不能跨机构维护学术推广员");
+        // }
 
 
         // 校验用户名
@@ -728,13 +728,13 @@ public class SysUserController {
 
         // 校验身份证上的年龄
         String idCardNumber = resource.getIdCardNumber().trim();
-        if (CharSequenceUtil.isNotEmpty(idCardNumber)) {
-            int ageByIdCard = IdcardUtil.getAgeByIdCard(idCardNumber);
-            if (ageByIdCard < 18 || ageByIdCard > 65) {
-                return R.failed("业务员年龄应在18~65周岁之间");
-            }
-
-        }
+        // if (CharSequenceUtil.isNotEmpty(idCardNumber)) {
+        //     int ageByIdCard = IdcardUtil.getAgeByIdCard(idCardNumber);
+        //     if (ageByIdCard < 18 || ageByIdCard > 65) {
+        //         return R.failed("业务员年龄应在18~65周岁之间");
+        //     }
+        //
+        // }
 
         UserDTO userDto = new UserDTO();
         userDto.setRole(role);