add 新增 用户、部门、角色、岗位 下拉选接口与代码实现优化
| | |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import cn.hutool.core.convert.Convert; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.dromara.common.core.constant.UserConstants; |
| | | import org.dromara.common.core.domain.R; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | |
| | | import org.dromara.system.domain.bo.SysDeptBo; |
| | | import org.dromara.system.domain.vo.SysDeptVo; |
| | | import org.dromara.system.service.ISysDeptService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | deptService.checkDeptDataScope(deptId); |
| | | return toAjax(deptService.deleteDeptById(deptId)); |
| | | } |
| | | |
| | | /** |
| | | * 获取部门选择框列表 |
| | | * |
| | | * @param deptIds 部门ID串 |
| | | */ |
| | | @SaCheckPermission("system:dept:query") |
| | | @GetMapping("/optionselect") |
| | | public R<List<SysDeptVo>> optionselect(@RequestParam(required = false) Long[] deptIds) { |
| | | return R.ok(deptService.selectDeptByIds(List.of(deptIds))); |
| | | } |
| | | |
| | | } |
| | |
| | | package org.dromara.system.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.dromara.common.core.constant.UserConstants; |
| | | import org.dromara.common.core.domain.R; |
| | | import org.dromara.common.excel.utils.ExcelUtil; |
| | |
| | | import org.dromara.system.domain.bo.SysPostBo; |
| | | import org.dromara.system.domain.vo.SysPostVo; |
| | | import org.dromara.system.service.ISysPostService; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | |
| | | /** |
| | | * 获取岗位选择框列表 |
| | | * |
| | | * @param postIds 岗位ID串 |
| | | */ |
| | | @SaCheckPermission("system:dept:query") |
| | | @GetMapping("/optionselect") |
| | | public R<List<SysPostVo>> optionselect() { |
| | | SysPostBo postBo = new SysPostBo(); |
| | | postBo.setStatus(UserConstants.POST_NORMAL); |
| | | List<SysPostVo> posts = postService.selectPostList(postBo); |
| | | return R.ok(posts); |
| | | public R<List<SysPostVo>> optionselect(@RequestParam(required = false) Long[] postIds) { |
| | | return R.ok(postService.selectPostByIds(List.of(postIds))); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | /** |
| | | * 获取角色选择框列表 |
| | | * |
| | | * @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(List.of(roleIds))); |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.dromara.common.core.constant.UserConstants; |
| | | import org.dromara.common.core.domain.R; |
| | | import org.dromara.common.core.domain.model.LoginUser; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | | import org.dromara.common.core.utils.StreamUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.encrypt.annotation.ApiEncrypt; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据用户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(List.of(userIds), deptId)); |
| | | } |
| | | |
| | | /** |
| | | * 重置密码 |
| | | */ |
| | | @ApiEncrypt |
| | |
| | | SysDeptVo selectDeptById(Long deptId); |
| | | |
| | | /** |
| | | * 通过部门ID串查询部门 |
| | | * |
| | | * @param deptIds 部门id串 |
| | | * @return 部门列表信息 |
| | | */ |
| | | List<SysDeptVo> selectDeptByIds(List<Long> deptIds); |
| | | |
| | | /** |
| | | * 根据ID查询所有子部门数(正常状态) |
| | | * |
| | | * @param deptId 部门ID |
| | |
| | | List<Long> selectPostListByUserId(Long userId); |
| | | |
| | | /** |
| | | * 通过岗位ID串查询岗位 |
| | | * |
| | | * @param postIds 岗位id串 |
| | | * @return 岗位列表信息 |
| | | */ |
| | | List<SysPostVo> selectPostByIds(List<Long> postIds); |
| | | |
| | | /** |
| | | * 校验岗位名称 |
| | | * |
| | | * @param post 岗位信息 |
| | |
| | | SysRoleVo selectRoleById(Long roleId); |
| | | |
| | | /** |
| | | * 通过角色ID串查询角色 |
| | | * |
| | | * @param roleIds 角色ID串 |
| | | * @return 角色列表信息 |
| | | */ |
| | | List<SysRoleVo> selectRoleByIds(List<Long> roleIds); |
| | | |
| | | /** |
| | | * 校验角色名称是否唯一 |
| | | * |
| | | * @param role 角色信息 |
| | |
| | | SysUserVo selectUserById(Long userId); |
| | | |
| | | /** |
| | | * 通过用户ID串查询用户 |
| | | * |
| | | * @param userIds 用户ID串 |
| | | * @param deptId 部门id |
| | | * @return 用户列表信息 |
| | | */ |
| | | List<SysUserVo> selectUserByIds(List<Long> userIds, Long deptId); |
| | | |
| | | /** |
| | | * 根据用户ID查询用户所属角色组 |
| | | * |
| | | * @param userId 用户ID |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.dromara.common.core.constant.CacheNames; |
| | | import org.dromara.common.core.constant.UserConstants; |
| | | import org.dromara.common.core.exception.ServiceException; |
| | |
| | | import org.dromara.system.mapper.SysRoleMapper; |
| | | import org.dromara.system.mapper.SysUserMapper; |
| | | import org.dromara.system.service.ISysDeptService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | return dept; |
| | | } |
| | | |
| | | @Override |
| | | public List<SysDeptVo> selectDeptByIds(List<Long> deptIds) { |
| | | return baseMapper.selectDeptList(new LambdaQueryWrapper<SysDept>() |
| | | .select(SysDept::getDeptId, SysDept::getDeptName, SysDept::getLeader) |
| | | .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL) |
| | | .in(CollUtil.isNotEmpty(deptIds), SysDept::getDeptId, deptIds)); |
| | | } |
| | | |
| | | /** |
| | | * 通过部门ID查询部门名称 |
| | | * |
| | |
| | | package org.dromara.system.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.dromara.common.core.constant.UserConstants; |
| | | import org.dromara.common.core.exception.ServiceException; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | | import org.dromara.common.core.utils.StreamUtils; |
| | |
| | | import org.dromara.system.mapper.SysPostMapper; |
| | | import org.dromara.system.mapper.SysUserPostMapper; |
| | | import org.dromara.system.service.ISysPostService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Arrays; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过岗位ID串查询岗位 |
| | | * |
| | | * @param postIds 岗位id串 |
| | | * @return 岗位列表信息 |
| | | */ |
| | | @Override |
| | | public List<SysPostVo> selectPostByIds(List<Long> postIds) { |
| | | return baseMapper.selectVoList(new LambdaQueryWrapper<SysPost>() |
| | | .select(SysPost::getPostId, SysPost::getPostName, SysPost::getPostCode) |
| | | .eq(SysPost::getStatus, UserConstants.POST_NORMAL) |
| | | .in(CollUtil.isNotEmpty(postIds), SysPost::getPostId, postIds)); |
| | | } |
| | | |
| | | /** |
| | | * 校验岗位名称是否唯一 |
| | | * |
| | | * @param post 岗位信息 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过角色ID串查询角色 |
| | | * |
| | | * @param roleIds 角色ID串 |
| | | * @return 角色列表信息 |
| | | */ |
| | | @Override |
| | | public List<SysRoleVo> selectRoleByIds(List<Long> roleIds) { |
| | | return baseMapper.selectRoleList(new LambdaQueryWrapper<SysRole>() |
| | | .select(SysRole::getRoleId, SysRole::getRoleName, SysRole::getRoleKey) |
| | | .eq(SysRole::getStatus, UserConstants.ROLE_NORMAL) |
| | | .in(CollUtil.isNotEmpty(roleIds), SysRole::getRoleId, roleIds)); |
| | | } |
| | | |
| | | /** |
| | | * 校验角色名称是否唯一 |
| | | * |
| | | * @param role 角色信息 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过用户ID串查询用户 |
| | | * |
| | | * @param userIds 用户ID串 |
| | | * @param deptId 部门id |
| | | * @return 用户列表信息 |
| | | */ |
| | | @Override |
| | | public List<SysUserVo> selectUserByIds(List<Long> userIds, Long deptId) { |
| | | return baseMapper.selectVoList(new LambdaQueryWrapper<SysUser>() |
| | | .select(SysUser::getUserId, SysUser::getUserName, SysUser::getNickName) |
| | | .eq(SysUser::getStatus, UserConstants.USER_NORMAL) |
| | | .eq(ObjectUtil.isNotNull(deptId), SysUser::getDeptId, deptId) |
| | | .in(CollUtil.isNotEmpty(userIds), SysUser::getUserId, userIds)); |
| | | } |
| | | |
| | | /** |
| | | * 查询用户所属角色组 |
| | | * |
| | | * @param userId 用户ID |
| | |
| | | .select(SysUser::getNickName).eq(SysUser::getUserId, userId)); |
| | | return ObjectUtil.isNull(sysUser) ? null : sysUser.getNickName(); |
| | | } |
| | | |
| | | /** |
| | | * 通过用户ID查询用户手机号 |
| | | * |