新增:用户、部门、角色、岗位 下拉选接口与代码实现优化

This commit is contained in:
数据小王子 2024-03-06 08:53:11 +08:00
parent 2c180c89a9
commit fa75c7155a
12 changed files with 133 additions and 41 deletions

View File

@ -14,14 +14,7 @@ import com.ruoyi.system.service.ISysUserService;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.common.core.core.domain.AjaxResult;
@ -139,4 +132,15 @@ public class SysDeptController extends BaseController {
}
return R.ok();
}
/**
* 获取部门选择框列表
*
* @param deptIds 部门ID串
*/
@SaCheckPermission("system:dept:query")
@GetMapping("/optionselect")
public R<List<SysDeptVo>> optionselect(@RequestParam(required = false) Long[] deptIds) {
return R.ok(deptService.selectDeptByIds(deptIds == null ? null : List.of(deptIds)));
}
}

View File

@ -16,14 +16,7 @@ import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.system.service.ISysPostService;
@ -139,13 +132,12 @@ public class SysPostController extends BaseController
/**
* 获取岗位选择框列表
*
* @param postIds 岗位ID串
*/
@SaCheckPermission("system:post:query")
@GetMapping("/optionselect")
public R<List<SysPostVo>> optionselect()
{
SysPostBo sysPostBo = new SysPostBo();
sysPostBo.setStatus(UserConstants.POST_NORMAL);
List<SysPostVo> posts = postService.selectPostList(sysPostBo);
return R.ok(posts);
public R<List<SysPostVo>> optionselect(@RequestParam(required = false) Long[] postIds) {
return R.ok(postService.selectPostByIds(postIds == null ? null : List.of(postIds)));
}
}

View File

@ -20,14 +20,7 @@ import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.system.domain.SysUserRole;
import com.ruoyi.system.service.ISysDeptService;
@ -171,11 +164,13 @@ public class SysRoleController extends BaseController {
/**
* 获取角色选择框列表
*
* @param roleIds 角色ID串
*/
@SaCheckPermission("system:role:query")
@GetMapping("/optionselect")
public R<List<SysRoleVo>> optionSelect() {
return R.ok(roleService.selectRoleAll());
public R<List<SysRoleVo>> optionselect(@RequestParam(required = false) Long[] roleIds) {
return R.ok(roleService.selectRoleByIds(roleIds == null ? null : List.of(roleIds)));
}
/**

View File

@ -33,14 +33,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.common.core.core.domain.AjaxResult;
@ -233,6 +226,19 @@ public class SysUserController extends BaseController {
return R.ok();
}
/**
* 根据用户ID串批量获取用户基础信息
*
* @param userIds 用户ID串
* @param deptId 部门ID
*/
@SaCheckPermission("system:user:query")
@GetMapping("/optionselect")
public R<List<SysUserVo>> optionselect(@RequestParam(required = false) Long[] userIds,
@RequestParam(required = false) Long deptId) {
return R.ok(userService.selectUserByIds(userIds == null ? null : List.of(userIds), deptId));
}
/**
* 重置密码
*/

View File

@ -3,7 +3,6 @@ package com.ruoyi.system.service;
import java.util.List;
import cn.hutool.core.lang.tree.Tree;
import com.alibaba.excel.event.AbstractIgnoreExceptionReadListener;
import com.ruoyi.common.orm.core.service.IBaseService;
import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.domain.bo.SysDeptBo;
@ -56,6 +55,14 @@ public interface ISysDeptService extends IBaseService<SysDept>
*/
SysDeptVo selectDeptById(Long deptId);
/**
* 通过部门ID串查询部门
*
* @param deptIds 部门id串
* @return 部门列表信息
*/
List<SysDeptVo> selectDeptByIds(List<Long> deptIds);
/**
* 根据 部门名称 查询记录数量
* @param deptName 部门名称

View File

@ -54,6 +54,14 @@ public interface ISysPostService extends IBaseService<SysPost>
*/
List<Long> selectPostListByUserId(Long userId);
/**
* 通过岗位ID串查询岗位
*
* @param postIds 岗位id串
* @return 岗位列表信息
*/
List<SysPostVo> selectPostByIds(List<Long> postIds);
/**
* 校验岗位名称
*

View File

@ -76,6 +76,14 @@ public interface ISysRoleService extends IBaseService<SysRole>
*/
SysRoleVo selectRoleById(Long roleId);
/**
* 通过角色ID串查询角色
*
* @param roleIds 角色ID串
* @return 角色列表信息
*/
List<SysRoleVo> selectRoleByIds(List<Long> roleIds);
/**
* 校验角色名称是否唯一
*

View File

@ -97,6 +97,15 @@ public interface ISysUserService extends IBaseService<SysUser> {
*/
SysUserVo selectUserById(Long userId);
/**
* 通过用户ID串查询用户
*
* @param userIds 用户ID串
* @param deptId 部门id
* @return 用户列表信息
*/
List<SysUserVo> selectUserByIds(List<Long> userIds, Long deptId);
/**
* 个人中心模块通过用户ID查询用户
*

View File

@ -167,6 +167,22 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptMapper, SysDept>
return this.getOneAs(queryWrapper, SysDeptVo.class);
}
/**
* 通过部门ID串查询部门
*
* @param deptIds 部门id串
* @return 部门列表信息
*/
@Override
public List<SysDeptVo> selectDeptByIds(List<Long> deptIds) {
QueryWrapper queryWrapper = QueryWrapper.create()
.select(SYS_DEPT.DEPT_ID, SYS_DEPT.DEPT_NAME, SYS_DEPT.LEADER)
.from(SYS_DEPT)
.where(SYS_DEPT.STATUS.eq(UserConstants.DEPT_NORMAL))
.and(SYS_DEPT.DEPT_ID.in(deptIds));
return this.listAs(queryWrapper, SysDeptVo.class);
}
/**
* 根据 部门名称 查询记录数量
*

View File

@ -145,6 +145,22 @@ public class SysPostServiceImpl extends BaseServiceImpl<SysPostMapper, SysPost>
return this.listAs(queryWrapper, SysPostVo.class);
}
/**
* 通过岗位ID串查询岗位
*
* @param postIds 岗位id串
* @return 岗位列表信息
*/
@Override
public List<SysPostVo> selectPostByIds(List<Long> postIds) {
QueryWrapper queryWrapper = QueryWrapper.create()
.select(SYS_POST.POST_ID, SYS_POST.POST_NAME, SYS_POST.POST_CODE)
.from(SYS_POST)
.where(SYS_POST.STATUS.eq(UserConstants.POST_NORMAL))
.and(SYS_POST.POST_ID.in(postIds));
return this.listAs(queryWrapper, SysPostVo.class);
}
/**
* 校验岗位名称是否唯一
*

View File

@ -243,6 +243,19 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleMapper, SysRole>
return this.getOneAs(query().where(SYS_ROLE.ROLE_ID.eq(roleId)), SysRoleVo.class);
}
/**
* 通过角色ID串查询角色
*
* @param roleIds 角色ID串
* @return 角色列表信息
*/
@Override
public List<SysRoleVo> selectRoleByIds(List<Long> roleIds) {
QueryWrapper queryWrapper = query().where(SYS_ROLE.STATUS.eq(UserConstants.ROLE_NORMAL))
.and(SYS_ROLE.ROLE_ID.in(roleIds));
return this.listAs(queryWrapper, SysRoleVo.class);
}
/**
* 校验角色名称是否唯一
*

View File

@ -356,6 +356,24 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
return userMapper.selectOneWithRelationsByQueryAs(queryWrapper, SysUserVo.class);//使用Relation注解获取deptroles从sys_oss中查询头像地址URL
}
/**
* 通过用户ID串查询用户
*
* @param userIds 用户ID串
* @param deptId 部门id
* @return 用户列表信息
*/
@Override
public List<SysUserVo> selectUserByIds(List<Long> userIds, Long deptId) {
QueryWrapper queryWrapper = QueryWrapper.create()
.select(SYS_USER.USER_ID, SYS_USER.USER_NAME, SYS_USER.NICK_NAME)
.from(SYS_USER)
.where(SYS_USER.STATUS.eq(UserConstants.USER_NORMAL))
.and(SYS_USER.DEPT_ID.eq(deptId))
.and(SYS_USER.USER_ID.in(userIds));
return this.listAs(queryWrapper, SysUserVo.class);
}
/**
* 个人中心模块通过用户ID查询用户
*