| | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import cn.dev33.satoken.secure.BCrypt; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.lang.tree.Tree; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | |
| | | import com.ruoyi.system.domain.vo.SysUserExportVo; |
| | | import com.ruoyi.system.domain.vo.SysUserImportVo; |
| | | import com.ruoyi.system.listener.SysUserImportListener; |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import com.ruoyi.system.service.ISysPostService; |
| | | import com.ruoyi.system.service.ISysRoleService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.Parameters; |
| | | import io.swagger.v3.oas.annotations.enums.ParameterIn; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | * @author Lion Li |
| | | */ |
| | | @Validated |
| | | @Tag(name ="用户信息控制器", description = "用户信息管理") |
| | | @RequiredArgsConstructor |
| | | @RestController |
| | | @RequestMapping("/system/user") |
| | |
| | | private final ISysUserService userService; |
| | | private final ISysRoleService roleService; |
| | | private final ISysPostService postService; |
| | | private final ISysDeptService deptService; |
| | | |
| | | /** |
| | | * 获取用户列表 |
| | | */ |
| | | @Operation(summary = "获取用户列表") |
| | | @SaCheckPermission("system:user:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysUser> list(SysUser user, PageQuery pageQuery) { |
| | | return userService.selectPageUserList(user, pageQuery); |
| | | } |
| | | |
| | | @Operation(summary = "导出用户列表") |
| | | /** |
| | | * 导出用户列表 |
| | | */ |
| | | @Log(title = "用户管理", businessType = BusinessType.EXPORT) |
| | | @SaCheckPermission("system:user:export") |
| | | @PostMapping("/export") |
| | |
| | | ExcelUtil.exportExcel(listVo, "用户数据", SysUserExportVo.class, response); |
| | | } |
| | | |
| | | @Operation(summary = "导入用户列表") |
| | | @Parameters({ |
| | | @Parameter(name = "file", description = "导入文件", required = true), |
| | | }) |
| | | /** |
| | | * 导入数据 |
| | | * |
| | | * @param file 导入文件 |
| | | * @param updateSupport 是否更新已存在数据 |
| | | */ |
| | | @Log(title = "用户管理", businessType = BusinessType.IMPORT) |
| | | @SaCheckPermission("system:user:import") |
| | | @PostMapping("/importData") |
| | | @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| | | public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception { |
| | | ExcelResult<SysUserImportVo> result = ExcelUtil.importExcel(file.getInputStream(), SysUserImportVo.class, new SysUserImportListener(updateSupport)); |
| | | return R.ok(result.getAnalysis()); |
| | | } |
| | | |
| | | @Operation(summary = "下载导入模板") |
| | | /** |
| | | * 获取导入模板 |
| | | */ |
| | | @PostMapping("/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) { |
| | | ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", SysUserImportVo.class, response); |
| | |
| | | |
| | | /** |
| | | * 根据用户编号获取详细信息 |
| | | * |
| | | * @param userId 用户ID |
| | | */ |
| | | @Operation(summary = "根据用户编号获取详细信息") |
| | | @SaCheckPermission("system:user:query") |
| | | @GetMapping(value = {"/", "/{userId}"}) |
| | | public R<Map<String, Object>> getInfo(@Parameter(name = "用户ID") @PathVariable(value = "userId", required = false) Long userId) { |
| | | public R<Map<String, Object>> getInfo(@PathVariable(value = "userId", required = false) Long userId) { |
| | | userService.checkUserDataScope(userId); |
| | | Map<String, Object> ajax = new HashMap<>(); |
| | | List<SysRole> roles = roleService.selectRoleAll(); |
| | |
| | | /** |
| | | * 新增用户 |
| | | */ |
| | | @Operation(summary = "新增用户") |
| | | @SaCheckPermission("system:user:add") |
| | | @Log(title = "用户管理", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public R<Void> add(@Validated @RequestBody SysUser user) { |
| | | if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName()))) { |
| | | if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user))) { |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | } else if (StringUtils.isNotEmpty(user.getPhonenumber()) |
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { |
| | |
| | | /** |
| | | * 修改用户 |
| | | */ |
| | | @Operation(summary = "修改用户") |
| | | @SaCheckPermission("system:user:edit") |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public R<Void> edit(@Validated @RequestBody SysUser user) { |
| | | userService.checkUserAllowed(user); |
| | | userService.checkUserDataScope(user.getUserId()); |
| | | if (StringUtils.isNotEmpty(user.getPhonenumber()) |
| | | if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user))) { |
| | | return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | } else if (StringUtils.isNotEmpty(user.getPhonenumber()) |
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { |
| | | return R.fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } else if (StringUtils.isNotEmpty(user.getEmail()) |
| | |
| | | |
| | | /** |
| | | * 删除用户 |
| | | * |
| | | * @param userIds 角色ID串 |
| | | */ |
| | | @Operation(summary = "删除用户") |
| | | @SaCheckPermission("system:user:remove") |
| | | @Log(title = "用户管理", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{userIds}") |
| | | public R<Void> remove(@Parameter(name = "角色ID串") @PathVariable Long[] userIds) { |
| | | public R<Void> remove(@PathVariable Long[] userIds) { |
| | | if (ArrayUtil.contains(userIds, getUserId())) { |
| | | return R.fail("当前用户不能删除"); |
| | | } |
| | |
| | | /** |
| | | * 重置密码 |
| | | */ |
| | | @Operation(summary = "重置密码") |
| | | @SaCheckPermission("system:user:resetPwd") |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/resetPwd") |
| | |
| | | /** |
| | | * 状态修改 |
| | | */ |
| | | @Operation(summary = "状态修改") |
| | | @SaCheckPermission("system:user:edit") |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | |
| | | |
| | | /** |
| | | * 根据用户编号获取授权角色 |
| | | * |
| | | * @param userId 用户ID |
| | | */ |
| | | @Operation(summary = "根据用户编号获取授权角色") |
| | | @SaCheckPermission("system:user:query") |
| | | @GetMapping("/authRole/{userId}") |
| | | public R<Map<String, Object>> authRole(@Parameter(name = "用户ID") @PathVariable("userId") Long userId) { |
| | | public R<Map<String, Object>> authRole(@PathVariable Long userId) { |
| | | SysUser user = userService.selectUserById(userId); |
| | | List<SysRole> roles = roleService.selectRolesByUserId(userId); |
| | | Map<String, Object> ajax = new HashMap<>(); |
| | |
| | | |
| | | /** |
| | | * 用户授权角色 |
| | | * |
| | | * @param userId 用户Id |
| | | * @param roleIds 角色ID串 |
| | | */ |
| | | @Operation(summary = "用户授权角色") |
| | | @Parameters({ |
| | | @Parameter(name = "userId", description = "用户Id", in = ParameterIn.QUERY), |
| | | @Parameter(name = "roleIds", description = "角色ID串", in = ParameterIn.QUERY) |
| | | }) |
| | | @SaCheckPermission("system:user:edit") |
| | | @Log(title = "用户管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authRole") |
| | |
| | | userService.insertUserAuth(userId, roleIds); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 获取部门树列表 |
| | | */ |
| | | @SaCheckPermission("system:user:list") |
| | | @GetMapping("/deptTree") |
| | | public R<List<Tree<Long>>> deptTree(SysDept dept) { |
| | | return R.ok(deptService.selectDeptTreeList(dept)); |
| | | } |
| | | |
| | | } |