From ab3e4978b1be42097b269c10927bb51f11a63d78 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期四, 12 十二月 2024 23:32:33 +0800 Subject: [PATCH] update 优化 为部门角色岗位用户增加一些常用查询方法 --- ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/UserService.java | 9 +++ ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/dto/DeptDTO.java | 37 ++++++++++++ ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml | 11 +++ ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/DeptService.java | 19 ++++++ ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/utils/LoginHelper.java | 7 ++ ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java | 12 ++++ ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/core/page/PageQuery.java | 5 + ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java | 23 +++++++ ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java | 27 +++++++++ ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java | 7 +- ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/RoleService.java | 10 +++ 11 files changed, 164 insertions(+), 3 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/dto/DeptDTO.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/dto/DeptDTO.java new file mode 100644 index 0000000..65c012f --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/dto/DeptDTO.java @@ -0,0 +1,37 @@ +package org.dromara.common.core.domain.dto; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 閮ㄩ棬 + * + * @author AprilWind + */ + +@Data +@NoArgsConstructor +public class DeptDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 閮ㄩ棬ID + */ + private Long deptId; + + /** + * 鐖堕儴闂↖D + */ + private Long parentId; + + /** + * 閮ㄩ棬鍚嶇О + */ + private String deptName; + +} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/DeptService.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/DeptService.java index db9463e..f93d177 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/DeptService.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/DeptService.java @@ -1,5 +1,9 @@ package org.dromara.common.core.service; +import org.dromara.common.core.domain.dto.DeptDTO; + +import java.util.List; + /** * 閫氱敤 閮ㄩ棬鏈嶅姟 * @@ -15,4 +19,19 @@ */ String selectDeptNameByIds(String deptIds); + /** + * 鏍规嵁閮ㄩ棬ID鏌ヨ閮ㄩ棬璐熻矗浜� + * + * @param deptId 閮ㄩ棬ID锛岀敤浜庢寚瀹氶渶瑕佹煡璇㈢殑閮ㄩ棬 + * @return 杩斿洖璇ラ儴闂ㄧ殑璐熻矗浜篒D + */ + Long selectDeptLeaderById(Long deptId); + + /** + * 鏌ヨ閮ㄩ棬 + * + * @return 閮ㄩ棬鍒楄〃 + */ + List<DeptDTO> selectDeptsByList(); + } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/RoleService.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/RoleService.java new file mode 100644 index 0000000..ba62c82 --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/RoleService.java @@ -0,0 +1,10 @@ +package org.dromara.common.core.service; + +/** + * 閫氱敤 瑙掕壊鏈嶅姟 + * + * @author AprilWind + */ +public interface RoleService { + +} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/UserService.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/UserService.java index 43aef28..67cd54f 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/UserService.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/UserService.java @@ -82,4 +82,13 @@ * @return 鐢ㄦ埛 */ List<UserDTO> selectUsersByDeptIds(List<Long> deptIds); + + /** + * 閫氳繃宀椾綅ID鏌ヨ鐢ㄦ埛 + * + * @param postIds 宀椾綅ids + * @return 鐢ㄦ埛 + */ + List<UserDTO> selectUsersByPostIds(List<Long> postIds); + } diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/core/page/PageQuery.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/core/page/PageQuery.java index 3f7797d..1d5c3c9 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/core/page/PageQuery.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/core/page/PageQuery.java @@ -119,4 +119,9 @@ return (pageNum - 1) * pageSize; } + public PageQuery(Integer pageSize, Integer pageNum) { + this.pageSize = pageSize; + this.pageNum = pageNum; + } + } diff --git a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/utils/LoginHelper.java b/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/utils/LoginHelper.java index cdc5684..19557e1 100644 --- a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/utils/LoginHelper.java +++ b/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/utils/LoginHelper.java @@ -89,6 +89,13 @@ } /** + * 鑾峰彇鐢ㄦ埛id + */ + public static String getUserIdStr() { + return Convert.toStr(getExtra(USER_KEY)); + } + + /** * 鑾峰彇鐢ㄦ埛璐︽埛 */ public static String getUsername() { diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java index 0f2c906..b69624c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Constants; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Param; import org.dromara.common.mybatis.annotation.DataColumn; import org.dromara.common.mybatis.annotation.DataPermission; @@ -32,6 +33,17 @@ List<SysDeptVo> selectDeptList(@Param(Constants.WRAPPER) Wrapper<SysDept> queryWrapper); /** + * 鍒嗛〉鏌ヨ閮ㄩ棬绠$悊鏁版嵁 + * + * @param queryWrapper 鏌ヨ鏉′欢 + * @return 閮ㄩ棬淇℃伅闆嗗悎 + */ + @DataPermission({ + @DataColumn(key = "deptName", value = "dept_id"), + }) + Page<SysDeptVo> selectPageDeptList(@Param("page") Page<SysDeptVo> page, @Param(Constants.WRAPPER) Wrapper<SysDept> queryWrapper); + + /** * 缁熻鎸囧畾閮ㄩ棬ID鐨勯儴闂ㄦ暟閲� * * @param deptId 閮ㄩ棬ID diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java index 98c1bd6..be9e33d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java @@ -1,5 +1,6 @@ package org.dromara.system.service.impl; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.lang.tree.Tree; @@ -10,6 +11,7 @@ import lombok.RequiredArgsConstructor; import org.dromara.common.core.constant.CacheNames; import org.dromara.common.core.constant.SystemConstants; +import org.dromara.common.core.domain.dto.DeptDTO; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.service.DeptService; import org.dromara.common.core.utils.*; @@ -354,4 +356,29 @@ return baseMapper.deleteById(deptId); } + /** + * 鏍规嵁閮ㄩ棬ID鏌ヨ閮ㄩ棬璐熻矗浜� + * + * @param deptId 閮ㄩ棬ID锛岀敤浜庢寚瀹氶渶瑕佹煡璇㈢殑閮ㄩ棬 + * @return 杩斿洖璇ラ儴闂ㄧ殑璐熻矗浜篒D + */ + @Override + public Long selectDeptLeaderById(Long deptId) { + SysDeptVo vo = SpringUtils.getAopProxy(this).selectDeptById(deptId); + return vo.getLeader(); + } + + /** + * 鏌ヨ閮ㄩ棬 + * + * @return 閮ㄩ棬鍒楄〃 + */ + @Override + public List<DeptDTO> selectDeptsByList() { + List<SysDeptVo> list = baseMapper.selectDeptList(new LambdaQueryWrapper<SysDept>() + .select(SysDept::getDeptId, SysDept::getDeptName, SysDept::getParentId) + .eq(SysDept::getStatus, SystemConstants.NORMAL)); + return BeanUtil.copyToList(list, DeptDTO.class); + } + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java index cbca57e..4c00735 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java @@ -17,6 +17,7 @@ import org.dromara.common.core.constant.TenantConstants; import org.dromara.common.core.domain.model.LoginUser; import org.dromara.common.core.exception.ServiceException; +import org.dromara.common.core.service.RoleService; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StringUtils; @@ -47,7 +48,7 @@ */ @RequiredArgsConstructor @Service -public class SysRoleServiceImpl implements ISysRoleService { +public class SysRoleServiceImpl implements ISysRoleService, RoleService { private final SysRoleMapper baseMapper; private final SysRoleMenuMapper roleMenuMapper; @@ -351,7 +352,7 @@ private int insertRoleMenu(SysRoleBo role) { int rows = 1; // 鏂板鐢ㄦ埛涓庤鑹茬鐞� - List<SysRoleMenu> list = new ArrayList<SysRoleMenu>(); + List<SysRoleMenu> list = new ArrayList<>(); for (Long menuId : role.getMenuIds()) { SysRoleMenu rm = new SysRoleMenu(); rm.setRoleId(role.getRoleId()); @@ -372,7 +373,7 @@ private int insertRoleDept(SysRoleBo role) { int rows = 1; // 鏂板瑙掕壊涓庨儴闂紙鏁版嵁鏉冮檺锛夌鐞� - List<SysRoleDept> list = new ArrayList<SysRoleDept>(); + List<SysRoleDept> list = new ArrayList<>(); for (Long deptId : role.getDeptIds()) { SysRoleDept rd = new SysRoleDept(); rd.setRoleId(role.getRoleId()); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java index 4b57587..4081170 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java @@ -696,4 +696,27 @@ .in(SysUser::getDeptId, deptIds)); return BeanUtil.copyToList(list, UserDTO.class); } + + /** + * 閫氳繃宀椾綅ID鏌ヨ鐢ㄦ埛 + * + * @param postIds 宀椾綅ids + * @return 鐢ㄦ埛 + */ + @Override + public List<UserDTO> selectUsersByPostIds(List<Long> postIds) { + if (CollUtil.isEmpty(postIds)) { + return List.of(); + } + + // 閫氳繃宀椾綅ID鑾峰彇鐢ㄦ埛宀椾綅淇℃伅 + List<SysUserPost> userPosts = userPostMapper.selectList( + new LambdaQueryWrapper<SysUserPost>().in(SysUserPost::getPostId, postIds)); + + // 鑾峰彇鐢ㄦ埛ID鍒楄〃 + Set<Long> userIds = StreamUtils.toSet(userPosts, SysUserPost::getUserId); + + return selectListByIds(new ArrayList<>(userIds)); + } + } diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml index 6ad866f..9057a0e 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -18,6 +18,17 @@ from sys_dept ${ew.getCustomSqlSegment} </select> + <select id="selectPageDeptList" resultMap="SysDeptResult"> + select + <if test="ew.getSqlSelect != null"> + ${ew.getSqlSelect} + </if> + <if test="ew.getSqlSelect == null"> + * + </if> + from sys_dept ${ew.getCustomSqlSegment} + </select> + <select id="countDeptById" resultType="Long"> select count(*) from sys_dept where del_flag = '0' and dept_id = #{deptId} </select> -- Gitblit v1.9.3