[update] 部门、角色、用户关联
This commit is contained in:
		| @ -51,6 +51,15 @@ public class BusProjectController extends BaseController { | |||||||
|         return projectService.queryPageList(req, pageQuery); |         return projectService.queryPageList(req, pageQuery); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 查询项目列表 | ||||||
|  |      */ | ||||||
|  |     @SaCheckPermission("project:project:listNoDept") | ||||||
|  |     @GetMapping("/listNoDept") | ||||||
|  |     public R<List<BusProjectVo>> listNoDept() { | ||||||
|  |         return R.ok(projectService.queryListNoDept()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 查询项目下的子项目列表 |      * 查询项目下的子项目列表 | ||||||
|      */ |      */ | ||||||
|  | |||||||
| @ -49,6 +49,13 @@ public interface IBusProjectService extends IService<BusProject> { | |||||||
|      */ |      */ | ||||||
|     List<BusProjectVo> queryList(BusProjectQueryReq req); |     List<BusProjectVo> queryList(BusProjectQueryReq req); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 查询未绑定部门的项目列表(不查询子项目) | ||||||
|  |      * | ||||||
|  |      * @return 项目列表 | ||||||
|  |      */ | ||||||
|  |     List<BusProjectVo> queryListNoDept(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 查询项目下的子项目列表 |      * 查询项目下的子项目列表 | ||||||
|      * |      * | ||||||
|  | |||||||
| @ -50,6 +50,9 @@ import org.dromara.project.service.IBusProjectService; | |||||||
| import org.dromara.project.service.IBusUserProjectRelevancyService; | import org.dromara.project.service.IBusUserProjectRelevancyService; | ||||||
| import org.dromara.quality.service.IQltKnowledgeDocumentService; | import org.dromara.quality.service.IQltKnowledgeDocumentService; | ||||||
| import org.dromara.safety.service.IHseKnowledgeDocumentService; | import org.dromara.safety.service.IHseKnowledgeDocumentService; | ||||||
|  | import org.dromara.system.domain.SysDept; | ||||||
|  | import org.dromara.system.domain.enums.SysDeptIsSubsetEnum; | ||||||
|  | import org.dromara.system.mapper.SysDeptMapper; | ||||||
| import org.dromara.workflow.service.IFlwDefinitionService; | import org.dromara.workflow.service.IFlwDefinitionService; | ||||||
| import org.springframework.beans.BeanUtils; | import org.springframework.beans.BeanUtils; | ||||||
| import org.springframework.context.annotation.Lazy; | import org.springframework.context.annotation.Lazy; | ||||||
| @ -112,6 +115,10 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj | |||||||
|     @Resource |     @Resource | ||||||
|     private IFlwDefinitionService flwDefinitionService; |     private IFlwDefinitionService flwDefinitionService; | ||||||
|  |  | ||||||
|  |     @Lazy | ||||||
|  |     @Resource | ||||||
|  |     private SysDeptMapper deptMapper; | ||||||
|  |  | ||||||
|     @Lazy |     @Lazy | ||||||
|     @Resource |     @Resource | ||||||
|     private IBusProjectService self; |     private IBusProjectService self; | ||||||
| @ -177,6 +184,27 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj | |||||||
|         return this.list(lqw).stream().map(this::getVo).toList(); |         return this.list(lqw).stream().map(this::getVo).toList(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 查询未绑定部门的项目列表(不查询子项目) | ||||||
|  |      * | ||||||
|  |      * @return 项目列表 | ||||||
|  |      */ | ||||||
|  |     @Override | ||||||
|  |     public List<BusProjectVo> queryListNoDept() { | ||||||
|  |         LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>(); | ||||||
|  |         lqw.eq(SysDept::getIsSubset, SysDeptIsSubsetEnum.NO.getCode()); | ||||||
|  |         lqw.isNotNull(SysDept::getProjectId); | ||||||
|  |         List<SysDept> depts = deptMapper.selectList(lqw); | ||||||
|  |         List<Long> idList = depts.stream().map(SysDept::getProjectId).toList(); | ||||||
|  |         List<BusProject> allProjectList = this.lambdaQuery() | ||||||
|  |             .eq(BusProject::getPId, BusProjectConstant.PARENT_ID) | ||||||
|  |             .list(); | ||||||
|  |         List<BusProject> projectList = allProjectList.stream() | ||||||
|  |             .filter(project -> !idList.contains(project.getId())) | ||||||
|  |             .toList(); | ||||||
|  |         return projectList.stream().map(this::getVo).toList(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 查询项目下的子项目列表 |      * 查询项目下的子项目列表 | ||||||
|      * |      * | ||||||
|  | |||||||
| @ -55,8 +55,8 @@ public class SysRoleController extends BaseController { | |||||||
|      */ |      */ | ||||||
|     @SaCheckPermission("system:role:list") |     @SaCheckPermission("system:role:list") | ||||||
|     @GetMapping("/listNoPage") |     @GetMapping("/listNoPage") | ||||||
|     public List<SysRoleVo> listNoPage(SysRoleBo role) { |     public R<List<SysRoleVo>> listNoPage(SysRoleBo role) { | ||||||
|         return roleService.selectRoleList(role); |         return R.ok(roleService.selectRoleList(role)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @ -103,6 +103,9 @@ public class SysRoleController extends BaseController { | |||||||
|         if (deptVo == null) { |         if (deptVo == null) { | ||||||
|             return R.fail("新增角色'" + role.getRoleName() + "'失败,关联的部门不存在"); |             return R.fail("新增角色'" + role.getRoleName() + "'失败,关联的部门不存在"); | ||||||
|         } |         } | ||||||
|  |         if (deptVo.getParentId() == 0) { | ||||||
|  |             return R.fail("新增角色'" + role.getRoleName() + "'失败,关联的部门不能为顶级部门"); | ||||||
|  |         } | ||||||
|         return toAjax(roleService.insertRole(role)); |         return toAjax(roleService.insertRole(role)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -120,7 +123,17 @@ public class SysRoleController extends BaseController { | |||||||
|         } else if (!roleService.checkRoleKeyUnique(role)) { |         } else if (!roleService.checkRoleKeyUnique(role)) { | ||||||
|             return R.fail("修改角色'" + role.getRoleName() + "'失败,角色权限已存在"); |             return R.fail("修改角色'" + role.getRoleName() + "'失败,角色权限已存在"); | ||||||
|         } |         } | ||||||
|  |         Long deptId = role.getDeptId(); | ||||||
|  |         if (deptId == null) { | ||||||
|  |             return R.fail("新增角色'" + role.getRoleName() + "'失败,请选择关联的部门"); | ||||||
|  |         } | ||||||
|  |         SysDeptVo deptVo = deptService.selectDeptById(deptId); | ||||||
|  |         if (deptVo == null) { | ||||||
|  |             return R.fail("新增角色'" + role.getRoleName() + "'失败,关联的部门不存在"); | ||||||
|  |         } | ||||||
|  |         if (deptVo.getParentId() == 0) { | ||||||
|  |             return R.fail("新增角色'" + role.getRoleName() + "'失败,关联的部门不能为顶级部门"); | ||||||
|  |         } | ||||||
|         if (roleService.updateRole(role) > 0) { |         if (roleService.updateRole(role) > 0) { | ||||||
|             roleService.cleanOnlineUserByRole(role.getRoleId()); |             roleService.cleanOnlineUserByRole(role.getRoleId()); | ||||||
|             return R.ok(); |             return R.ok(); | ||||||
|  | |||||||
| @ -2,13 +2,13 @@ package org.dromara.system.controller.system; | |||||||
|  |  | ||||||
| import cn.dev33.satoken.annotation.SaCheckPermission; | import cn.dev33.satoken.annotation.SaCheckPermission; | ||||||
| import cn.dev33.satoken.secure.BCrypt; | import cn.dev33.satoken.secure.BCrypt; | ||||||
|  | import cn.hutool.core.collection.CollUtil; | ||||||
| import cn.hutool.core.lang.tree.Tree; | import cn.hutool.core.lang.tree.Tree; | ||||||
| import cn.hutool.core.util.ArrayUtil; | import cn.hutool.core.util.ArrayUtil; | ||||||
| import cn.hutool.core.util.ObjectUtil; | import cn.hutool.core.util.ObjectUtil; | ||||||
| import jakarta.servlet.http.HttpServletResponse; | import jakarta.servlet.http.HttpServletResponse; | ||||||
| import jakarta.validation.constraints.NotNull; | import jakarta.validation.constraints.NotNull; | ||||||
| import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||||
| import org.dromara.common.core.constant.SystemConstants; |  | ||||||
| import org.dromara.common.core.domain.R; | import org.dromara.common.core.domain.R; | ||||||
| import org.dromara.common.core.domain.model.LoginUser; | import org.dromara.common.core.domain.model.LoginUser; | ||||||
| import org.dromara.common.core.utils.StreamUtils; | import org.dromara.common.core.utils.StreamUtils; | ||||||
| @ -132,20 +132,29 @@ public class SysUserController extends BaseController { | |||||||
|         if (ObjectUtil.isNotNull(userId)) { |         if (ObjectUtil.isNotNull(userId)) { | ||||||
|             userService.checkUserDataScope(userId); |             userService.checkUserDataScope(userId); | ||||||
|             SysUserVo sysUser = userService.selectUserById(userId); |             SysUserVo sysUser = userService.selectUserById(userId); | ||||||
|  |             List<SysRoleVo> roles = sysUser.getRoles(); | ||||||
|  |             if (CollUtil.isNotEmpty(roles)) { | ||||||
|  |                 sysUser.setRoleIds(roles.stream().map(SysRoleVo::getRoleId).toList().toArray(Long[]::new)); | ||||||
|  |             } | ||||||
|             userInfoVo.setUser(sysUser); |             userInfoVo.setUser(sysUser); | ||||||
|             userInfoVo.setRoleIds(roleService.selectRoleListByUserId(userId)); | //            userInfoVo.setRoleIds(roleService.selectRoleListByUserId(userId)); | ||||||
|             Long deptId = sysUser.getDeptId(); |             Long deptId = sysUser.getDeptId(); | ||||||
|             if (ObjectUtil.isNotNull(deptId)) { |             if (ObjectUtil.isNotNull(deptId)) { | ||||||
|                 SysPostBo postBo = new SysPostBo(); |                 SysPostBo postBo = new SysPostBo(); | ||||||
|                 postBo.setDeptId(deptId); |                 postBo.setDeptId(deptId); | ||||||
|                 userInfoVo.setPosts(postService.selectPostList(postBo)); |                 userInfoVo.setPosts(postService.selectPostList(postBo)); | ||||||
|                 userInfoVo.setPostIds(postService.selectPostListByUserId(userId)); |                 userInfoVo.setPostIds(postService.selectPostListByUserId(userId)); | ||||||
|  |                 SysRoleBo role = new SysRoleBo(); | ||||||
|  |                 role.setDeptId(deptId); | ||||||
|  |                 List<SysRoleVo> roleVoList = roleService.selectRoleList(role); | ||||||
|  |                 userInfoVo.setRoles(roleVoList); | ||||||
|  |                 userInfoVo.setRoleIds(roleVoList.stream().map(SysRoleVo::getRoleId).toList()); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         SysRoleBo roleBo = new SysRoleBo(); |         /*SysRoleBo roleBo = new SysRoleBo(); | ||||||
|         roleBo.setStatus(SystemConstants.NORMAL); |         roleBo.setStatus(SystemConstants.NORMAL); | ||||||
|         List<SysRoleVo> roles = roleService.selectRoleList(roleBo); |         List<SysRoleVo> roles = roleService.selectRoleList(roleBo); | ||||||
|         userInfoVo.setRoles(LoginHelper.isSuperAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isSuperAdmin())); |         userInfoVo.setRoles(LoginHelper.isSuperAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isSuperAdmin()));*/ | ||||||
|         return R.ok(userInfoVo); |         return R.ok(userInfoVo); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -2,15 +2,17 @@ package org.dromara.system.domain.vo; | |||||||
|  |  | ||||||
| import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | ||||||
| import com.alibaba.excel.annotation.ExcelProperty; | import com.alibaba.excel.annotation.ExcelProperty; | ||||||
| import org.dromara.common.excel.annotation.ExcelDictFormat; |  | ||||||
| import org.dromara.common.excel.convert.ExcelDictConvert; |  | ||||||
| import org.dromara.system.domain.SysDept; |  | ||||||
| import io.github.linpeilie.annotations.AutoMapper; | import io.github.linpeilie.annotations.AutoMapper; | ||||||
| import lombok.Data; | import lombok.Data; | ||||||
|  | import org.dromara.common.excel.annotation.ExcelDictFormat; | ||||||
|  | import org.dromara.common.excel.convert.ExcelDictConvert; | ||||||
|  | import org.dromara.project.domain.vo.project.BusProjectVo; | ||||||
|  | import org.dromara.system.domain.SysDept; | ||||||
|  |  | ||||||
| import java.io.Serial; | import java.io.Serial; | ||||||
| import java.io.Serializable; | import java.io.Serializable; | ||||||
| import java.util.Date; | import java.util.Date; | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 部门视图对象 sys_dept |  * 部门视图对象 sys_dept | ||||||
| @ -41,6 +43,17 @@ public class SysDeptVo implements Serializable { | |||||||
|      */ |      */ | ||||||
|     private String parentName; |     private String parentName; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 项目id | ||||||
|  |      */ | ||||||
|  |     private Long projectId; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 未绑定项目信息 | ||||||
|  |      */ | ||||||
|  |     private List<BusProjectVo> projectList; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 祖级列表 |      * 祖级列表 | ||||||
|      */ |      */ | ||||||
|  | |||||||
| @ -44,6 +44,12 @@ public class SysRoleVo implements Serializable { | |||||||
|     @ExcelProperty(value = "角色权限") |     @ExcelProperty(value = "角色权限") | ||||||
|     private String roleKey; |     private String roleKey; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 部门ID | ||||||
|  |      */ | ||||||
|  |     @ExcelProperty(value = "部门") | ||||||
|  |     private Long deptId; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 显示顺序 |      * 显示顺序 | ||||||
|      */ |      */ | ||||||
|  | |||||||
| @ -21,6 +21,7 @@ import org.dromara.common.mybatis.helper.DataBaseHelper; | |||||||
| import org.dromara.common.redis.utils.CacheUtils; | import org.dromara.common.redis.utils.CacheUtils; | ||||||
| import org.dromara.common.satoken.utils.LoginHelper; | import org.dromara.common.satoken.utils.LoginHelper; | ||||||
| import org.dromara.project.domain.BusProject; | import org.dromara.project.domain.BusProject; | ||||||
|  | import org.dromara.project.domain.vo.project.BusProjectVo; | ||||||
| import org.dromara.project.service.IBusProjectService; | import org.dromara.project.service.IBusProjectService; | ||||||
| import org.dromara.project.service.IBusUserProjectRelevancyService; | import org.dromara.project.service.IBusUserProjectRelevancyService; | ||||||
| import org.dromara.system.domain.SysDept; | import org.dromara.system.domain.SysDept; | ||||||
| @ -164,6 +165,12 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { | |||||||
|         SysDeptVo parentDept = baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>() |         SysDeptVo parentDept = baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>() | ||||||
|             .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId())); |             .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId())); | ||||||
|         dept.setParentName(ObjectUtils.notNullGetter(parentDept, SysDeptVo::getDeptName)); |         dept.setParentName(ObjectUtils.notNullGetter(parentDept, SysDeptVo::getDeptName)); | ||||||
|  |         List<BusProjectVo> projectVos = new ArrayList<>(projectService.queryListNoDept()); | ||||||
|  |         if (dept.getIsSubset().equals(SysDeptIsSubsetEnum.NO.getCode()) && dept.getProjectId() != null) { | ||||||
|  |             BusProjectVo vo = projectService.getVo(projectService.getById(dept.getProjectId())); | ||||||
|  |             projectVos.add(vo); | ||||||
|  |         } | ||||||
|  |         dept.setProjectList(projectVos); | ||||||
|         return dept; |         return dept; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -395,6 +402,13 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { | |||||||
|                 if (project == null) { |                 if (project == null) { | ||||||
|                     throw new ServiceException("项目不存在", HttpStatus.NOT_FOUND); |                     throw new ServiceException("项目不存在", HttpStatus.NOT_FOUND); | ||||||
|                 } |                 } | ||||||
|  |                 // 判断该项目是否被绑定 | ||||||
|  |                 LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>(); | ||||||
|  |                 queryWrapper.eq(SysDept::getProjectId, projectId); | ||||||
|  |                 Long l = baseMapper.selectCount(queryWrapper); | ||||||
|  |                 if (l > 0) { | ||||||
|  |                     throw new ServiceException("该项目已被其他部门绑定", HttpStatus.CONFLICT); | ||||||
|  |                 } | ||||||
|                 dept.setProjectId(projectId); |                 dept.setProjectId(projectId); | ||||||
|                 // 判断是否有需要新增项目关联的用户 |                 // 判断是否有需要新增项目关联的用户 | ||||||
|                 List<Long> deptIds = this.getParentDeptIds(dept); |                 List<Long> deptIds = this.getParentDeptIds(dept); | ||||||
| @ -485,6 +499,13 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { | |||||||
|             if (project == null) { |             if (project == null) { | ||||||
|                 throw new ServiceException("关联项目不存在", HttpStatus.NOT_FOUND); |                 throw new ServiceException("关联项目不存在", HttpStatus.NOT_FOUND); | ||||||
|             } |             } | ||||||
|  |             // 判断新项目是否被绑定 | ||||||
|  |             LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>(); | ||||||
|  |             queryWrapper.eq(SysDept::getProjectId, newProjectId); | ||||||
|  |             Long l = baseMapper.selectCount(queryWrapper); | ||||||
|  |             if (l > 0) { | ||||||
|  |                 throw new ServiceException("该项目已被其他部门绑定", HttpStatus.CONFLICT); | ||||||
|  |             } | ||||||
|             // 获取当前部门及其上级部门 ID 列表 |             // 获取当前部门及其上级部门 ID 列表 | ||||||
|             List<Long> deptIds = this.getParentDeptIds(dept); |             List<Long> deptIds = this.getParentDeptIds(dept); | ||||||
|             // 获取部门用户 ID |             // 获取部门用户 ID | ||||||
|  | |||||||
| @ -11,6 +11,7 @@ | |||||||
|         select distinct r.role_id, |         select distinct r.role_id, | ||||||
|                         r.role_name, |                         r.role_name, | ||||||
|                         r.role_key, |                         r.role_key, | ||||||
|  |                         r.dept_id, | ||||||
|                         r.role_sort, |                         r.role_sort, | ||||||
|                         r.data_scope, |                         r.data_scope, | ||||||
|                         r.menu_check_strictly, |                         r.menu_check_strictly, | ||||||
| @ -45,12 +46,14 @@ | |||||||
|         select r.role_id, |         select r.role_id, | ||||||
|                r.role_name, |                r.role_name, | ||||||
|                r.role_key, |                r.role_key, | ||||||
|  |                r.dept_id, | ||||||
|                r.role_sort, |                r.role_sort, | ||||||
|                r.data_scope, |                r.data_scope, | ||||||
|                r.status, |                r.status, | ||||||
|                r.is_special |                r.is_special | ||||||
|         from sys_role r |         from sys_role r | ||||||
|         WHERE r.del_flag = '0' and r.role_id in (select role_id from sys_user_role where user_id = #{userId}) |         WHERE r.del_flag = '0' | ||||||
|  |           and r.role_id in (select role_id from sys_user_role where user_id = #{userId}) | ||||||
|     </select> |     </select> | ||||||
|  |  | ||||||
|     <select id="selectRoleById" resultMap="SysRoleResult"> |     <select id="selectRoleById" resultMap="SysRoleResult"> | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user