| | |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.excel.ExcelResult; |
| | | import com.ruoyi.common.helper.LoginHelper; |
| | | import com.ruoyi.common.utils.StreamUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.system.domain.vo.SysUserExportVo; |
| | |
| | | import com.ruoyi.system.service.ISysPostService; |
| | | import com.ruoyi.system.service.ISysRoleService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import io.swagger.annotations.*; |
| | | 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.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 用户信息 |
| | |
| | | * @author Lion Li |
| | | */ |
| | | @Validated |
| | | @Api(value = "用户信息控制器", tags = {"用户信息管理"}) |
| | | @Tag(name ="用户信息控制器", description = "用户信息管理") |
| | | @RequiredArgsConstructor |
| | | @RestController |
| | | @RequestMapping("/system/user") |
| | |
| | | /** |
| | | * 获取用户列表 |
| | | */ |
| | | @ApiOperation("获取用户列表") |
| | | @SaCheckPermission("system:user:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysUser> list(SysUser user, PageQuery pageQuery) { |
| | | return userService.selectPageUserList(user, pageQuery); |
| | | } |
| | | |
| | | @ApiOperation("导出用户列表") |
| | | @Log(title = "用户管理", businessType = BusinessType.EXPORT) |
| | | @SaCheckPermission("system:user:export") |
| | | @PostMapping("/export") |
| | |
| | | ExcelUtil.exportExcel(listVo, "用户数据", SysUserExportVo.class, response); |
| | | } |
| | | |
| | | @ApiOperation("导入用户列表") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "file", value = "导入文件", dataType = "java.io.File", required = true), |
| | | @Parameters({ |
| | | @Parameter(name = "file", description = "导入文件", required = true), |
| | | }) |
| | | @Log(title = "用户管理", businessType = BusinessType.IMPORT) |
| | | @SaCheckPermission("system:user:import") |
| | |
| | | return R.ok(result.getAnalysis()); |
| | | } |
| | | |
| | | @ApiOperation("下载导入模板") |
| | | @PostMapping("/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) { |
| | | ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", SysUserImportVo.class, response); |
| | |
| | | /** |
| | | * 根据用户编号获取详细信息 |
| | | */ |
| | | @ApiOperation("根据用户编号获取详细信息") |
| | | @SaCheckPermission("system:user:query") |
| | | @GetMapping(value = {"/", "/{userId}"}) |
| | | public R<Map<String, Object>> getInfo(@ApiParam("用户ID") @PathVariable(value = "userId", required = false) Long userId) { |
| | | public R<Map<String, Object>> getInfo(@Parameter(name = "用户ID") @PathVariable(value = "userId", required = false) Long userId) { |
| | | userService.checkUserDataScope(userId); |
| | | Map<String, Object> ajax = new HashMap<>(); |
| | | List<SysRole> roles = roleService.selectRoleAll(); |
| | | ajax.put("roles", LoginHelper.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); |
| | | ajax.put("roles", LoginHelper.isAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isAdmin())); |
| | | ajax.put("posts", postService.selectPostAll()); |
| | | if (ObjectUtil.isNotNull(userId)) { |
| | | SysUser sysUser = userService.selectUserById(userId); |
| | | ajax.put("user", sysUser); |
| | | ajax.put("postIds", postService.selectPostListByUserId(userId)); |
| | | ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList())); |
| | | ajax.put("roleIds", StreamUtils.toList(sysUser.getRoles(), SysRole::getRoleId)); |
| | | } |
| | | return R.ok(ajax); |
| | | } |
| | |
| | | /** |
| | | * 新增用户 |
| | | */ |
| | | @ApiOperation("新增用户") |
| | | @SaCheckPermission("system:user:add") |
| | | @Log(title = "用户管理", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | |
| | | /** |
| | | * 修改用户 |
| | | */ |
| | | @ApiOperation("修改用户") |
| | | @SaCheckPermission("system:user:edit") |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | |
| | | /** |
| | | * 删除用户 |
| | | */ |
| | | @ApiOperation("删除用户") |
| | | @SaCheckPermission("system:user:remove") |
| | | @Log(title = "用户管理", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{userIds}") |
| | | public R<Void> remove(@ApiParam("角色ID串") @PathVariable Long[] userIds) { |
| | | public R<Void> remove(@Parameter(name = "角色ID串") @PathVariable Long[] userIds) { |
| | | if (ArrayUtil.contains(userIds, getUserId())) { |
| | | return R.fail("当前用户不能删除"); |
| | | } |
| | |
| | | /** |
| | | * 重置密码 |
| | | */ |
| | | @ApiOperation("重置密码") |
| | | @SaCheckPermission("system:user:resetPwd") |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/resetPwd") |
| | |
| | | /** |
| | | * 状态修改 |
| | | */ |
| | | @ApiOperation("状态修改") |
| | | @SaCheckPermission("system:user:edit") |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | |
| | | /** |
| | | * 根据用户编号获取授权角色 |
| | | */ |
| | | @ApiOperation("根据用户编号获取授权角色") |
| | | @SaCheckPermission("system:user:query") |
| | | @GetMapping("/authRole/{userId}") |
| | | public R<Map<String, Object>> authRole(@ApiParam("用户ID") @PathVariable("userId") Long userId) { |
| | | public R<Map<String, Object>> authRole(@Parameter(name = "用户ID") @PathVariable("userId") Long userId) { |
| | | SysUser user = userService.selectUserById(userId); |
| | | List<SysRole> roles = roleService.selectRolesByUserId(userId); |
| | | Map<String, Object> ajax = new HashMap<>(); |
| | | ajax.put("user", user); |
| | | ajax.put("roles", LoginHelper.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); |
| | | ajax.put("roles", LoginHelper.isAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isAdmin())); |
| | | return R.ok(ajax); |
| | | } |
| | | |
| | | /** |
| | | * 用户授权角色 |
| | | */ |
| | | @ApiOperation("用户授权角色") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "userId", value = "用户Id", paramType = "query", dataTypeClass = String.class), |
| | | @ApiImplicitParam(name = "roleIds", value = "角色ID串", paramType = "query", dataTypeClass = String.class) |
| | | @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) |