Commit 42dc4b6194bbc3ea7090e868604c631e9dd16fc0
1 parent
d4cf945a
🔧 简化 user 模块的 VO
Showing
18 changed files
with
222 additions
and
453 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.system.api.user; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 3 | 4 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| 4 | -import cn.iocoder.yudao.module.system.convert.user.UserConvert; | |
| 5 | 5 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 6 | 6 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 7 | 7 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -24,25 +24,25 @@ public class AdminUserApiImpl implements AdminUserApi { |
| 24 | 24 | @Override |
| 25 | 25 | public AdminUserRespDTO getUser(Long id) { |
| 26 | 26 | AdminUserDO user = userService.getUser(id); |
| 27 | - return UserConvert.INSTANCE.convert4(user); | |
| 27 | + return BeanUtils.toBean(user, AdminUserRespDTO.class); | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | @Override |
| 31 | 31 | public List<AdminUserRespDTO> getUserList(Collection<Long> ids) { |
| 32 | 32 | List<AdminUserDO> users = userService.getUserList(ids); |
| 33 | - return UserConvert.INSTANCE.convertList4(users); | |
| 33 | + return BeanUtils.toBean(users, AdminUserRespDTO.class); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | @Override |
| 37 | 37 | public List<AdminUserRespDTO> getUserListByDeptIds(Collection<Long> deptIds) { |
| 38 | 38 | List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds); |
| 39 | - return UserConvert.INSTANCE.convertList4(users); | |
| 39 | + return BeanUtils.toBean(users, AdminUserRespDTO.class); | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | @Override |
| 43 | 43 | public List<AdminUserRespDTO> getUserListByPostIds(Collection<Long> postIds) { |
| 44 | 44 | List<AdminUserDO> users = userService.getUserListByPostIds(postIds); |
| 45 | - return UserConvert.INSTANCE.convertList4(users); | |
| 45 | + return BeanUtils.toBean(users, AdminUserRespDTO.class); | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | @Override | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.user; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 8 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 9 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 4 | 10 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*; |
| 5 | 11 | import cn.iocoder.yudao.module.system.convert.user.UserConvert; |
| 6 | 12 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| 7 | 13 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 14 | +import cn.iocoder.yudao.module.system.enums.common.SexEnum; | |
| 8 | 15 | import cn.iocoder.yudao.module.system.service.dept.DeptService; |
| 9 | 16 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 10 | -import cn.iocoder.yudao.module.system.enums.common.SexEnum; | |
| 11 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 12 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 13 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 14 | -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | |
| 15 | -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 16 | -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 17 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 17 | +import io.swagger.v3.oas.annotations.Operation; | |
| 18 | 18 | import io.swagger.v3.oas.annotations.Parameter; |
| 19 | 19 | import io.swagger.v3.oas.annotations.Parameters; |
| 20 | -import io.swagger.v3.oas.annotations.Operation; | |
| 20 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 21 | 21 | import org.springframework.security.access.prepost.PreAuthorize; |
| 22 | 22 | import org.springframework.validation.annotation.Validated; |
| 23 | 23 | import org.springframework.web.bind.annotation.*; |
| ... | ... | @@ -27,11 +27,12 @@ import javax.annotation.Resource; |
| 27 | 27 | import javax.servlet.http.HttpServletResponse; |
| 28 | 28 | import javax.validation.Valid; |
| 29 | 29 | import java.io.IOException; |
| 30 | -import java.util.*; | |
| 30 | +import java.util.Arrays; | |
| 31 | +import java.util.List; | |
| 32 | +import java.util.Map; | |
| 31 | 33 | |
| 32 | 34 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 33 | 35 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 34 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 35 | 36 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 36 | 37 | |
| 37 | 38 | @Tag(name = "管理后台 - 用户") |
| ... | ... | @@ -48,7 +49,7 @@ public class UserController { |
| 48 | 49 | @PostMapping("/create") |
| 49 | 50 | @Operation(summary = "新增用户") |
| 50 | 51 | @PreAuthorize("@ss.hasPermission('system:user:create')") |
| 51 | - public CommonResult<Long> createUser(@Valid @RequestBody UserCreateReqVO reqVO) { | |
| 52 | + public CommonResult<Long> createUser(@Valid @RequestBody UserSaveReqVO reqVO) { | |
| 52 | 53 | Long id = userService.createUser(reqVO); |
| 53 | 54 | return success(id); |
| 54 | 55 | } |
| ... | ... | @@ -56,7 +57,7 @@ public class UserController { |
| 56 | 57 | @PutMapping("update") |
| 57 | 58 | @Operation(summary = "修改用户") |
| 58 | 59 | @PreAuthorize("@ss.hasPermission('system:user:update')") |
| 59 | - public CommonResult<Boolean> updateUser(@Valid @RequestBody UserUpdateReqVO reqVO) { | |
| 60 | + public CommonResult<Boolean> updateUser(@Valid @RequestBody UserSaveReqVO reqVO) { | |
| 60 | 61 | userService.updateUser(reqVO); |
| 61 | 62 | return success(true); |
| 62 | 63 | } |
| ... | ... | @@ -89,56 +90,27 @@ public class UserController { |
| 89 | 90 | @GetMapping("/page") |
| 90 | 91 | @Operation(summary = "获得用户分页列表") |
| 91 | 92 | @PreAuthorize("@ss.hasPermission('system:user:list')") |
| 92 | - public CommonResult<PageResult<UserPageItemRespVO>> getUserPage(@Valid UserPageReqVO reqVO) { | |
| 93 | + public CommonResult<PageResult<UserRespVO>> getUserPage(@Valid UserPageReqVO pageReqVO) { | |
| 93 | 94 | // 获得用户分页列表 |
| 94 | - PageResult<AdminUserDO> pageResult = userService.getUserPage(reqVO); | |
| 95 | + PageResult<AdminUserDO> pageResult = userService.getUserPage(pageReqVO); | |
| 95 | 96 | if (CollUtil.isEmpty(pageResult.getList())) { |
| 96 | - return success(new PageResult<>(pageResult.getTotal())); // 返回空 | |
| 97 | + return success(new PageResult<>(pageResult.getTotal())); | |
| 97 | 98 | } |
| 98 | - | |
| 99 | - // 获得拼接需要的数据 | |
| 100 | - Collection<Long> deptIds = convertList(pageResult.getList(), AdminUserDO::getDeptId); | |
| 101 | - Map<Long, DeptDO> deptMap = deptService.getDeptMap(deptIds); | |
| 102 | - // 拼接结果返回 | |
| 103 | - List<UserPageItemRespVO> userList = new ArrayList<>(pageResult.getList().size()); | |
| 104 | - pageResult.getList().forEach(user -> { | |
| 105 | - UserPageItemRespVO respVO = UserConvert.INSTANCE.convert(user); | |
| 106 | - respVO.setDept(UserConvert.INSTANCE.convert(deptMap.get(user.getDeptId()))); | |
| 107 | - userList.add(respVO); | |
| 108 | - }); | |
| 109 | - return success(new PageResult<>(userList, pageResult.getTotal())); | |
| 110 | - } | |
| 111 | - | |
| 112 | - // TODO @芋艿:看看这里怎么统一调整下;客户的选择组件; | |
| 113 | - @GetMapping("/all") | |
| 114 | - @Operation(summary = "查询所有用户列表") | |
| 115 | - public CommonResult<List<UserPageItemRespVO>> getAllUser() { | |
| 116 | - // 获得用户分页列表 | |
| 117 | - List<AdminUserDO> pageResult = userService.getUserList(); | |
| 118 | - if (CollUtil.isEmpty(pageResult)) { | |
| 119 | - return success(Collections.emptyList()); // 返回空 | |
| 120 | - } | |
| 121 | - | |
| 122 | - // 获得拼接需要的数据 | |
| 123 | - Collection<Long> deptIds = convertList(pageResult, AdminUserDO::getDeptId); | |
| 124 | - Map<Long, DeptDO> deptMap = deptService.getDeptMap(deptIds); | |
| 125 | - // 拼接结果返回 | |
| 126 | - List<UserPageItemRespVO> userList = new ArrayList<>(pageResult.size()); | |
| 127 | - pageResult.forEach(user -> { | |
| 128 | - UserPageItemRespVO respVO = UserConvert.INSTANCE.convert(user); | |
| 129 | - respVO.setDept(UserConvert.INSTANCE.convert(deptMap.get(user.getDeptId()))); | |
| 130 | - userList.add(respVO); | |
| 131 | - }); | |
| 132 | - return success(userList); | |
| 99 | + // 拼接数据 | |
| 100 | + Map<Long, DeptDO> deptMap = deptService.getDeptMap( | |
| 101 | + convertList(pageResult.getList(), AdminUserDO::getDeptId)); | |
| 102 | + return success(new PageResult<>(UserConvert.INSTANCE.convertList(pageResult.getList(), deptMap), | |
| 103 | + pageResult.getTotal())); | |
| 133 | 104 | } |
| 134 | 105 | |
| 135 | - @GetMapping("/list-all-simple") | |
| 106 | + @GetMapping({"/list-all-simple", "/simple-list"}) | |
| 136 | 107 | @Operation(summary = "获取用户精简信息列表", description = "只包含被开启的用户,主要用于前端的下拉选项") |
| 137 | 108 | public CommonResult<List<UserSimpleRespVO>> getSimpleUserList() { |
| 138 | - // 获用户列表,只要开启状态的 | |
| 139 | 109 | List<AdminUserDO> list = userService.getUserListByStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 140 | - // 排序后,返回给前端 | |
| 141 | - return success(UserConvert.INSTANCE.convertList04(list)); | |
| 110 | + // 拼接数据 | |
| 111 | + Map<Long, DeptDO> deptMap = deptService.getDeptMap( | |
| 112 | + convertList(list, AdminUserDO::getDeptId)); | |
| 113 | + return success(UserConvert.INSTANCE.convertSimpleList(list, deptMap)); | |
| 142 | 114 | } |
| 143 | 115 | |
| 144 | 116 | @GetMapping("/get") |
| ... | ... | @@ -147,41 +119,24 @@ public class UserController { |
| 147 | 119 | @PreAuthorize("@ss.hasPermission('system:user:query')") |
| 148 | 120 | public CommonResult<UserRespVO> getUser(@RequestParam("id") Long id) { |
| 149 | 121 | AdminUserDO user = userService.getUser(id); |
| 150 | - // 获得部门数据 | |
| 122 | + // 拼接数据 | |
| 151 | 123 | DeptDO dept = deptService.getDept(user.getDeptId()); |
| 152 | - return success(UserConvert.INSTANCE.convert(user).setDept(UserConvert.INSTANCE.convert(dept))); | |
| 124 | + return success(UserConvert.INSTANCE.convert(user, dept)); | |
| 153 | 125 | } |
| 154 | 126 | |
| 155 | 127 | @GetMapping("/export") |
| 156 | 128 | @Operation(summary = "导出用户") |
| 157 | 129 | @PreAuthorize("@ss.hasPermission('system:user:export')") |
| 158 | 130 | @OperateLog(type = EXPORT) |
| 159 | - public void exportUserList(@Validated UserExportReqVO reqVO, | |
| 131 | + public void exportUserList(@Validated UserPageReqVO exportReqVO, | |
| 160 | 132 | HttpServletResponse response) throws IOException { |
| 161 | - // 获得用户列表 | |
| 162 | - List<AdminUserDO> users = userService.getUserList(reqVO); | |
| 163 | - | |
| 164 | - // 获得拼接需要的数据 | |
| 165 | - Collection<Long> deptIds = convertList(users, AdminUserDO::getDeptId); | |
| 166 | - Map<Long, DeptDO> deptMap = deptService.getDeptMap(deptIds); | |
| 167 | - Map<Long, AdminUserDO> deptLeaderUserMap = userService.getUserMap( | |
| 168 | - convertSet(deptMap.values(), DeptDO::getLeaderUserId)); | |
| 169 | - // 拼接数据 | |
| 170 | - List<UserExcelVO> excelUsers = new ArrayList<>(users.size()); | |
| 171 | - users.forEach(user -> { | |
| 172 | - UserExcelVO excelVO = UserConvert.INSTANCE.convert02(user); | |
| 173 | - // 设置部门 | |
| 174 | - MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> { | |
| 175 | - excelVO.setDeptName(dept.getName()); | |
| 176 | - // 设置部门负责人的名字 | |
| 177 | - MapUtils.findAndThen(deptLeaderUserMap, dept.getLeaderUserId(), | |
| 178 | - deptLeaderUser -> excelVO.setDeptLeaderNickname(deptLeaderUser.getNickname())); | |
| 179 | - }); | |
| 180 | - excelUsers.add(excelVO); | |
| 181 | - }); | |
| 182 | - | |
| 183 | - // 输出 | |
| 184 | - ExcelUtils.write(response, "用户数据.xls", "用户列表", UserExcelVO.class, excelUsers); | |
| 133 | + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 134 | + List<AdminUserDO> list = userService.getUserPage(exportReqVO).getList(); | |
| 135 | + // 输出 Excel | |
| 136 | + Map<Long, DeptDO> deptMap = deptService.getDeptMap( | |
| 137 | + convertList(list, AdminUserDO::getDeptId)); | |
| 138 | + ExcelUtils.write(response, "用户数据.xls", "数据", UserRespVO.class, | |
| 139 | + UserConvert.INSTANCE.convertList(list, deptMap)); | |
| 185 | 140 | } |
| 186 | 141 | |
| 187 | 142 | @GetMapping("/get-import-template") |
| ... | ... | @@ -194,7 +149,6 @@ public class UserController { |
| 194 | 149 | UserImportExcelVO.builder().username("yuanma").deptId(2L).email("yuanma@iocoder.cn").mobile("15601701300") |
| 195 | 150 | .nickname("源码").status(CommonStatusEnum.DISABLE.getStatus()).sex(SexEnum.FEMALE.getSex()).build() |
| 196 | 151 | ); |
| 197 | - | |
| 198 | 152 | // 输出 |
| 199 | 153 | ExcelUtils.write(response, "用户导入模板.xls", "用户列表", UserImportExcelVO.class, list); |
| 200 | 154 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java
| ... | ... | @@ -58,27 +58,18 @@ public class UserProfileController { |
| 58 | 58 | @GetMapping("/get") |
| 59 | 59 | @Operation(summary = "获得登录用户信息") |
| 60 | 60 | @DataPermission(enable = false) // 关闭数据权限,避免只查看自己时,查询不到部门。 |
| 61 | - public CommonResult<UserProfileRespVO> profile() { | |
| 61 | + public CommonResult<UserProfileRespVO> getUserProfile() { | |
| 62 | 62 | // 获得用户基本信息 |
| 63 | 63 | AdminUserDO user = userService.getUser(getLoginUserId()); |
| 64 | - UserProfileRespVO resp = UserConvert.INSTANCE.convert03(user); | |
| 65 | 64 | // 获得用户角色 |
| 66 | 65 | List<RoleDO> userRoles = roleService.getRoleListFromCache(permissionService.getUserRoleIdListByUserId(user.getId())); |
| 67 | - resp.setRoles(UserConvert.INSTANCE.convertList(userRoles)); | |
| 68 | 66 | // 获得部门信息 |
| 69 | - if (user.getDeptId() != null) { | |
| 70 | - DeptDO dept = deptService.getDept(user.getDeptId()); | |
| 71 | - resp.setDept(UserConvert.INSTANCE.convert02(dept)); | |
| 72 | - } | |
| 67 | + DeptDO dept = user.getDeptId() != null ? deptService.getDept(user.getDeptId()) : null; | |
| 73 | 68 | // 获得岗位信息 |
| 74 | - if (CollUtil.isNotEmpty(user.getPostIds())) { | |
| 75 | - List<PostDO> posts = postService.getPostList(user.getPostIds()); | |
| 76 | - resp.setPosts(UserConvert.INSTANCE.convertList02(posts)); | |
| 77 | - } | |
| 69 | + List<PostDO> posts = CollUtil.isNotEmpty(user.getPostIds()) ? postService.getPostList(user.getPostIds()) : null; | |
| 78 | 70 | // 获得社交用户信息 |
| 79 | 71 | List<SocialUserDO> socialUsers = socialService.getSocialUserList(user.getId(), UserTypeEnum.ADMIN.getValue()); |
| 80 | - resp.setSocialUsers(UserConvert.INSTANCE.convertList03(socialUsers)); | |
| 81 | - return success(resp); | |
| 72 | + return success(UserConvert.INSTANCE.convert(user, userRoles, dept, posts, socialUsers)); | |
| 82 | 73 | } |
| 83 | 74 | |
| 84 | 75 | @PutMapping("/update") |
| ... | ... | @@ -95,7 +86,8 @@ public class UserProfileController { |
| 95 | 86 | return success(true); |
| 96 | 87 | } |
| 97 | 88 | |
| 98 | - @RequestMapping(value = "/update-avatar", method = {RequestMethod.POST, RequestMethod.PUT}) // 解决 uni-app 不支持 Put 上传文件的问题 | |
| 89 | + @RequestMapping(value = "/update-avatar", | |
| 90 | + method = {RequestMethod.POST, RequestMethod.PUT}) // 解决 uni-app 不支持 Put 上传文件的问题 | |
| 99 | 91 | @Operation(summary = "上传用户个人头像") |
| 100 | 92 | public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception { |
| 101 | 93 | if (file.isEmpty()) { | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/profile/UserProfileRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.user.vo.profile; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserBaseVO; | |
| 3 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; | |
| 4 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSimpleRespVO; | |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSimpleRespVO; | |
| 4 | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | -import lombok.AllArgsConstructor; | |
| 6 | 7 | import lombok.Data; |
| 7 | -import lombok.EqualsAndHashCode; | |
| 8 | -import lombok.NoArgsConstructor; | |
| 9 | 8 | |
| 10 | 9 | import java.time.LocalDateTime; |
| 11 | 10 | import java.util.List; |
| 12 | 11 | |
| 13 | - | |
| 14 | 12 | @Data |
| 15 | -@EqualsAndHashCode(callSuper = true) | |
| 16 | -@NoArgsConstructor | |
| 17 | -@AllArgsConstructor | |
| 18 | 13 | @Schema(description = "管理后台 - 用户个人中心信息 Response VO") |
| 19 | -public class UserProfileRespVO extends UserBaseVO { | |
| 14 | +public class UserProfileRespVO { | |
| 20 | 15 | |
| 21 | 16 | @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 22 | 17 | private Long id; |
| 23 | 18 | |
| 24 | - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 25 | - private Integer status; | |
| 19 | + @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") | |
| 20 | + private String username; | |
| 21 | + | |
| 22 | + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | |
| 23 | + private String nickname; | |
| 24 | + | |
| 25 | + @Schema(description = "用户邮箱", example = "yudao@iocoder.cn") | |
| 26 | + private String email; | |
| 27 | + | |
| 28 | + @Schema(description = "手机号码", example = "15601691300") | |
| 29 | + private String mobile; | |
| 30 | + | |
| 31 | + @Schema(description = "用户性别,参见 SexEnum 枚举类", example = "1") | |
| 32 | + private Integer sex; | |
| 33 | + | |
| 34 | + @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") | |
| 35 | + private String avatar; | |
| 26 | 36 | |
| 27 | 37 | @Schema(description = "最后登录 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "192.168.1.1") |
| 28 | 38 | private String loginIp; |
| ... | ... | @@ -36,58 +46,20 @@ public class UserProfileRespVO extends UserBaseVO { |
| 36 | 46 | /** |
| 37 | 47 | * 所属角色 |
| 38 | 48 | */ |
| 39 | - private List<Role> roles; | |
| 40 | - | |
| 49 | + private List<RoleSimpleRespVO> roles; | |
| 41 | 50 | /** |
| 42 | 51 | * 所在部门 |
| 43 | 52 | */ |
| 44 | - private Dept dept; | |
| 45 | - | |
| 53 | + private DeptSimpleRespVO dept; | |
| 46 | 54 | /** |
| 47 | 55 | * 所属岗位数组 |
| 48 | 56 | */ |
| 49 | - private List<Post> posts; | |
| 57 | + private List<PostSimpleRespVO> posts; | |
| 50 | 58 | /** |
| 51 | 59 | * 社交用户数组 |
| 52 | 60 | */ |
| 53 | 61 | private List<SocialUser> socialUsers; |
| 54 | 62 | |
| 55 | - @Schema(description = "角色") | |
| 56 | - @Data | |
| 57 | - public static class Role { | |
| 58 | - | |
| 59 | - @Schema(description = "角色编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 60 | - private Long id; | |
| 61 | - | |
| 62 | - @Schema(description = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "普通角色") | |
| 63 | - private String name; | |
| 64 | - | |
| 65 | - } | |
| 66 | - | |
| 67 | - @Schema(description = "部门") | |
| 68 | - @Data | |
| 69 | - public static class Dept { | |
| 70 | - | |
| 71 | - @Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 72 | - private Long id; | |
| 73 | - | |
| 74 | - @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "研发部") | |
| 75 | - private String name; | |
| 76 | - | |
| 77 | - } | |
| 78 | - | |
| 79 | - @Schema(description = "岗位") | |
| 80 | - @Data | |
| 81 | - public static class Post { | |
| 82 | - | |
| 83 | - @Schema(description = "岗位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 84 | - private Long id; | |
| 85 | - | |
| 86 | - @Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "开发") | |
| 87 | - private String name; | |
| 88 | - | |
| 89 | - } | |
| 90 | - | |
| 91 | 63 | @Schema(description = "社交用户") |
| 92 | 64 | @Data |
| 93 | 65 | public static class SocialUser { | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import org.hibernate.validator.constraints.Length; | |
| 7 | - | |
| 8 | -import javax.validation.constraints.NotEmpty; | |
| 9 | - | |
| 10 | -@Schema(description = "管理后台 - 用户创建 Request VO") | |
| 11 | -@Data | |
| 12 | -@EqualsAndHashCode(callSuper = true) | |
| 13 | -public class UserCreateReqVO extends UserBaseVO { | |
| 14 | - | |
| 15 | - @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") | |
| 16 | - @NotEmpty(message = "密码不能为空") | |
| 17 | - @Length(min = 4, max = 16, message = "密码长度为 4-16 位") | |
| 18 | - private String password; | |
| 19 | - | |
| 20 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserExcelVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | |
| 6 | -import com.alibaba.excel.annotation.ExcelProperty; | |
| 7 | -import lombok.Data; | |
| 8 | - | |
| 9 | -import java.time.LocalDateTime; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * 用户 Excel 导出 VO | |
| 13 | - */ | |
| 14 | -@Data | |
| 15 | -public class UserExcelVO { | |
| 16 | - | |
| 17 | - @ExcelProperty("用户编号") | |
| 18 | - private Long id; | |
| 19 | - | |
| 20 | - @ExcelProperty("用户名称") | |
| 21 | - private String username; | |
| 22 | - | |
| 23 | - @ExcelProperty("用户昵称") | |
| 24 | - private String nickname; | |
| 25 | - | |
| 26 | - @ExcelProperty("用户邮箱") | |
| 27 | - private String email; | |
| 28 | - | |
| 29 | - @ExcelProperty("手机号码") | |
| 30 | - private String mobile; | |
| 31 | - | |
| 32 | - @ExcelProperty(value = "用户性别", converter = DictConvert.class) | |
| 33 | - @DictFormat(DictTypeConstants.USER_SEX) | |
| 34 | - private Integer sex; | |
| 35 | - | |
| 36 | - @ExcelProperty(value = "帐号状态", converter = DictConvert.class) | |
| 37 | - @DictFormat(DictTypeConstants.COMMON_STATUS) | |
| 38 | - private Integer status; | |
| 39 | - | |
| 40 | - @ExcelProperty("最后登录IP") | |
| 41 | - private String loginIp; | |
| 42 | - | |
| 43 | - @ExcelProperty("最后登录时间") | |
| 44 | - private LocalDateTime loginDate; | |
| 45 | - | |
| 46 | - @ExcelProperty("部门名称") | |
| 47 | - private String deptName; | |
| 48 | - | |
| 49 | - @ExcelProperty("部门负责人") | |
| 50 | - private String deptLeaderNickname; | |
| 51 | - | |
| 52 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserExportReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.AllArgsConstructor; | |
| 5 | -import lombok.Data; | |
| 6 | -import lombok.NoArgsConstructor; | |
| 7 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | - | |
| 9 | -import java.time.LocalDateTime; | |
| 10 | - | |
| 11 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 12 | - | |
| 13 | -@Schema(description = "管理后台 - 用户导出 Request VO,参数和 UserPageReqVO 是一致的") | |
| 14 | -@Data | |
| 15 | -@NoArgsConstructor | |
| 16 | -@AllArgsConstructor | |
| 17 | -public class UserExportReqVO { | |
| 18 | - | |
| 19 | - @Schema(description = "用户账号,模糊匹配", example = "yudao") | |
| 20 | - private String username; | |
| 21 | - | |
| 22 | - @Schema(description = "手机号码,模糊匹配", example = "yudao") | |
| 23 | - private String mobile; | |
| 24 | - | |
| 25 | - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1") | |
| 26 | - private Integer status; | |
| 27 | - | |
| 28 | - @Schema(description = "创建时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") | |
| 29 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 30 | - private LocalDateTime[] createTime; | |
| 31 | - | |
| 32 | - @Schema(description = "部门编号,同时筛选子部门", example = "1024") | |
| 33 | - private Long deptId; | |
| 34 | - | |
| 35 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserPageItemRespVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.AllArgsConstructor; | |
| 5 | -import lombok.Data; | |
| 6 | -import lombok.EqualsAndHashCode; | |
| 7 | -import lombok.NoArgsConstructor; | |
| 8 | - | |
| 9 | -@Schema(description = "管理后台 - 用户分页时的信息 Response VO,相比用户基本信息来说,会多部门信息") | |
| 10 | -@Data | |
| 11 | -@NoArgsConstructor | |
| 12 | -@AllArgsConstructor | |
| 13 | -@EqualsAndHashCode(callSuper = true) | |
| 14 | -public class UserPageItemRespVO extends UserRespVO { | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * 所在部门 | |
| 18 | - */ | |
| 19 | - private Dept dept; | |
| 20 | - | |
| 21 | - @Schema(description = "部门") | |
| 22 | - @Data | |
| 23 | - public static class Dept { | |
| 24 | - | |
| 25 | - @Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 26 | - private Long id; | |
| 27 | - | |
| 28 | - @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "研发部") | |
| 29 | - private String name; | |
| 30 | - | |
| 31 | - } | |
| 32 | - | |
| 33 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | |
| 6 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 7 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 3 | 8 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.*; | |
| 9 | +import lombok.Data; | |
| 5 | 10 | |
| 6 | 11 | import java.time.LocalDateTime; |
| 7 | - | |
| 12 | +import java.util.Set; | |
| 8 | 13 | |
| 9 | 14 | @Schema(description = "管理后台 - 用户信息 Response VO") |
| 10 | 15 | @Data |
| 11 | -@NoArgsConstructor | |
| 12 | -@AllArgsConstructor | |
| 13 | -@EqualsAndHashCode(callSuper = true) | |
| 14 | -public class UserRespVO extends UserBaseVO { | |
| 16 | +@ExcelIgnoreUnannotated | |
| 17 | +public class UserRespVO{ | |
| 15 | 18 | |
| 16 | 19 | @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 20 | + @ExcelProperty("用户编号") | |
| 17 | 21 | private Long id; |
| 18 | 22 | |
| 23 | + @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") | |
| 24 | + @ExcelProperty("用户名称") | |
| 25 | + private String username; | |
| 26 | + | |
| 27 | + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | |
| 28 | + @ExcelProperty("用户昵称") | |
| 29 | + private String nickname; | |
| 30 | + | |
| 31 | + @Schema(description = "备注", example = "我是一个用户") | |
| 32 | + private String remark; | |
| 33 | + | |
| 34 | + @Schema(description = "部门ID", example = "我是一个用户") | |
| 35 | + private Long deptId; | |
| 36 | + @Schema(description = "部门名称", example = "IT 部") | |
| 37 | + @ExcelProperty("部门名称") | |
| 38 | + private String deptName; | |
| 39 | + | |
| 40 | + @Schema(description = "岗位编号数组", example = "1") | |
| 41 | + private Set<Long> postIds; | |
| 42 | + | |
| 43 | + @Schema(description = "用户邮箱", example = "yudao@iocoder.cn") | |
| 44 | + @ExcelProperty("用户邮箱") | |
| 45 | + private String email; | |
| 46 | + | |
| 47 | + @Schema(description = "手机号码", example = "15601691300") | |
| 48 | + @ExcelProperty("手机号码") | |
| 49 | + private String mobile; | |
| 50 | + | |
| 51 | + @Schema(description = "用户性别,参见 SexEnum 枚举类", example = "1") | |
| 52 | + @ExcelProperty(value = "用户性别", converter = DictConvert.class) | |
| 53 | + @DictFormat(DictTypeConstants.USER_SEX) | |
| 54 | + private Integer sex; | |
| 55 | + | |
| 56 | + @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") | |
| 57 | + private String avatar; | |
| 58 | + | |
| 19 | 59 | @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 60 | + @ExcelProperty(value = "帐号状态", converter = DictConvert.class) | |
| 61 | + @DictFormat(DictTypeConstants.COMMON_STATUS) | |
| 20 | 62 | private Integer status; |
| 21 | 63 | |
| 22 | 64 | @Schema(description = "最后登录 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "192.168.1.1") |
| 65 | + @ExcelProperty("最后登录IP") | |
| 23 | 66 | private String loginIp; |
| 24 | 67 | |
| 25 | 68 | @Schema(description = "最后登录时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") |
| 69 | + @ExcelProperty("最后登录时间") | |
| 26 | 70 | private LocalDateTime loginDate; |
| 27 | 71 | |
| 28 | 72 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserBaseVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserSaveReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.ObjectUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.validation.Mobile; |
| 5 | +import com.fasterxml.jackson.annotation.JsonIgnore; | |
| 4 | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 7 | import lombok.Data; |
| 8 | +import org.hibernate.validator.constraints.Length; | |
| 6 | 9 | |
| 7 | -import javax.validation.constraints.Email; | |
| 8 | -import javax.validation.constraints.NotBlank; | |
| 9 | -import javax.validation.constraints.Pattern; | |
| 10 | -import javax.validation.constraints.Size; | |
| 10 | +import javax.validation.constraints.*; | |
| 11 | 11 | import java.util.Set; |
| 12 | 12 | |
| 13 | -/** | |
| 14 | - * 用户 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 15 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 16 | - */ | |
| 13 | +@Schema(description = "管理后台 - 用户创建/修改 Request VO") | |
| 17 | 14 | @Data |
| 18 | -public class UserBaseVO { | |
| 15 | +public class UserSaveReqVO { | |
| 16 | + | |
| 17 | + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 18 | + @NotNull(message = "用户编号不能为空") | |
| 19 | + private Long id; | |
| 19 | 20 | |
| 20 | 21 | @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") |
| 21 | 22 | @NotBlank(message = "用户账号不能为空") |
| ... | ... | @@ -51,4 +52,17 @@ public class UserBaseVO { |
| 51 | 52 | @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") |
| 52 | 53 | private String avatar; |
| 53 | 54 | |
| 55 | + // ========== 仅【创建】时,需要传递的字段 ========== | |
| 56 | + | |
| 57 | + @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") | |
| 58 | + @Length(min = 4, max = 16, message = "密码长度为 4-16 位") | |
| 59 | + private String password; | |
| 60 | + | |
| 61 | + @AssertTrue(message = "密码不能为空") | |
| 62 | + @JsonIgnore | |
| 63 | + public boolean isPasswordValid() { | |
| 64 | + return id != null // 修改时,不需要传递 | |
| 65 | + || (ObjectUtil.isAllNotEmpty(password)); // 新增时,必须都传递 password | |
| 66 | + } | |
| 67 | + | |
| 54 | 68 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserSimpleRespVO.java
| ... | ... | @@ -17,4 +17,9 @@ public class UserSimpleRespVO { |
| 17 | 17 | @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") |
| 18 | 18 | private String nickname; |
| 19 | 19 | |
| 20 | + @Schema(description = "部门ID", example = "我是一个用户") | |
| 21 | + private Long deptId; | |
| 22 | + @Schema(description = "部门名称", example = "IT 部") | |
| 23 | + private String deptName; | |
| 24 | + | |
| 20 | 25 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | - | |
| 7 | -import javax.validation.constraints.NotNull; | |
| 8 | - | |
| 9 | -@Schema(description = "管理后台 - 用户更新 Request VO") | |
| 10 | -@Data | |
| 11 | -@EqualsAndHashCode(callSuper = true) | |
| 12 | -public class UserUpdateReqVO extends UserBaseVO { | |
| 13 | - | |
| 14 | - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 15 | - @NotNull(message = "用户编号不能为空") | |
| 16 | - private Long id; | |
| 17 | - | |
| 18 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.system.convert.tenant; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserCreateReqVO; | |
| 4 | +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO; | |
| 5 | 5 | import org.mapstruct.Mapper; |
| 6 | 6 | import org.mapstruct.factory.Mappers; |
| 7 | 7 | |
| ... | ... | @@ -15,8 +15,8 @@ public interface TenantConvert { |
| 15 | 15 | |
| 16 | 16 | TenantConvert INSTANCE = Mappers.getMapper(TenantConvert.class); |
| 17 | 17 | |
| 18 | - default UserCreateReqVO convert02(TenantSaveReqVO bean) { | |
| 19 | - UserCreateReqVO reqVO = new UserCreateReqVO(); | |
| 18 | + default UserSaveReqVO convert02(TenantSaveReqVO bean) { | |
| 19 | + UserSaveReqVO reqVO = new UserSaveReqVO(); | |
| 20 | 20 | reqVO.setUsername(bean.getUsername()); |
| 21 | 21 | reqVO.setPassword(bean.getPassword()); |
| 22 | 22 | reqVO.setNickname(bean.getContactName()).setMobile(bean.getContactMobile()); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/user/UserConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.system.convert.user; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | |
| 3 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 4 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; | |
| 7 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSimpleRespVO; | |
| 8 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSimpleRespVO; | |
| 4 | 9 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileRespVO; |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; | |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*; | |
| 10 | +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserRespVO; | |
| 11 | +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSimpleRespVO; | |
| 8 | 12 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| 9 | 13 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| 10 | 14 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| ... | ... | @@ -14,42 +18,41 @@ import org.mapstruct.Mapper; |
| 14 | 18 | import org.mapstruct.factory.Mappers; |
| 15 | 19 | |
| 16 | 20 | import java.util.List; |
| 21 | +import java.util.Map; | |
| 17 | 22 | |
| 18 | 23 | @Mapper |
| 19 | 24 | public interface UserConvert { |
| 20 | 25 | |
| 21 | 26 | UserConvert INSTANCE = Mappers.getMapper(UserConvert.class); |
| 22 | 27 | |
| 23 | - UserPageItemRespVO convert(AdminUserDO bean); | |
| 24 | - | |
| 25 | - UserPageItemRespVO.Dept convert(DeptDO bean); | |
| 26 | - | |
| 27 | - AdminUserDO convert(UserCreateReqVO bean); | |
| 28 | - | |
| 29 | - AdminUserDO convert(UserUpdateReqVO bean); | |
| 30 | - | |
| 31 | - UserExcelVO convert02(AdminUserDO bean); | |
| 32 | - | |
| 33 | - AdminUserDO convert(UserImportExcelVO bean); | |
| 34 | - | |
| 35 | - UserProfileRespVO convert03(AdminUserDO bean); | |
| 36 | - | |
| 37 | - List<UserProfileRespVO.Role> convertList(List<RoleDO> list); | |
| 38 | - | |
| 39 | - UserProfileRespVO.Dept convert02(DeptDO bean); | |
| 40 | - | |
| 41 | - AdminUserDO convert(UserProfileUpdateReqVO bean); | |
| 42 | - | |
| 43 | - AdminUserDO convert(UserProfileUpdatePasswordReqVO bean); | |
| 44 | - | |
| 45 | - List<UserProfileRespVO.Post> convertList02(List<PostDO> list); | |
| 46 | - | |
| 47 | - List<UserProfileRespVO.SocialUser> convertList03(List<SocialUserDO> list); | |
| 48 | - | |
| 49 | - List<UserSimpleRespVO> convertList04(List<AdminUserDO> list); | |
| 50 | - | |
| 51 | - AdminUserRespDTO convert4(AdminUserDO bean); | |
| 52 | - | |
| 53 | - List<AdminUserRespDTO> convertList4(List<AdminUserDO> users); | |
| 28 | + default List<UserRespVO> convertList(List<AdminUserDO> list, Map<Long, DeptDO> deptMap) { | |
| 29 | + return CollectionUtils.convertList(list, user -> convert(user, deptMap.get(user.getDeptId()))); | |
| 30 | + } | |
| 31 | + | |
| 32 | + default UserRespVO convert(AdminUserDO user, DeptDO dept) { | |
| 33 | + UserRespVO userVO = BeanUtils.toBean(user, UserRespVO.class); | |
| 34 | + if (dept != null) { | |
| 35 | + userVO.setDeptName(dept.getName()); | |
| 36 | + } | |
| 37 | + return userVO; | |
| 38 | + } | |
| 39 | + | |
| 40 | + default List<UserSimpleRespVO> convertSimpleList(List<AdminUserDO> list, Map<Long, DeptDO> deptMap) { | |
| 41 | + return CollectionUtils.convertList(list, user -> { | |
| 42 | + UserSimpleRespVO userVO = BeanUtils.toBean(user, UserSimpleRespVO.class); | |
| 43 | + MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> userVO.setDeptName(dept.getName())); | |
| 44 | + return userVO; | |
| 45 | + }); | |
| 46 | + } | |
| 47 | + | |
| 48 | + default UserProfileRespVO convert(AdminUserDO user, List<RoleDO> userRoles, | |
| 49 | + DeptDO dept, List<PostDO> posts, List<SocialUserDO> socialUsers) { | |
| 50 | + UserProfileRespVO userVO = BeanUtils.toBean(user, UserProfileRespVO.class); | |
| 51 | + userVO.setRoles(BeanUtils.toBean(userRoles, RoleSimpleRespVO.class)); | |
| 52 | + userVO.setDept(BeanUtils.toBean(dept, DeptSimpleRespVO.class)); | |
| 53 | + userVO.setPosts(BeanUtils.toBean(posts, PostSimpleRespVO.class)); | |
| 54 | + userVO.setSocialUsers(BeanUtils.toBean(socialUsers, UserProfileRespVO.SocialUser.class)); | |
| 55 | + return userVO; | |
| 56 | + } | |
| 54 | 57 | |
| 55 | 58 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java
| ... | ... | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.dal.mysql.user; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserExportReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO; |
| 8 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 9 | 8 | import org.apache.ibatis.annotations.Mapper; |
| ... | ... | @@ -36,15 +35,6 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> { |
| 36 | 35 | .orderByDesc(AdminUserDO::getId)); |
| 37 | 36 | } |
| 38 | 37 | |
| 39 | - default List<AdminUserDO> selectList(UserExportReqVO reqVO, Collection<Long> deptIds) { | |
| 40 | - return selectList(new LambdaQueryWrapperX<AdminUserDO>() | |
| 41 | - .likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername()) | |
| 42 | - .likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile()) | |
| 43 | - .eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus()) | |
| 44 | - .betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getCreateTime()) | |
| 45 | - .inIfPresent(AdminUserDO::getDeptId, deptIds)); | |
| 46 | - } | |
| 47 | - | |
| 48 | 38 | default List<AdminUserDO> selectListByNickname(String nickname) { |
| 49 | 39 | return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getNickname, nickname)); |
| 50 | 40 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java
| ... | ... | @@ -22,17 +22,17 @@ public interface AdminUserService { |
| 22 | 22 | /** |
| 23 | 23 | * 创建用户 |
| 24 | 24 | * |
| 25 | - * @param reqVO 用户信息 | |
| 25 | + * @param createReqVO 用户信息 | |
| 26 | 26 | * @return 用户编号 |
| 27 | 27 | */ |
| 28 | - Long createUser(@Valid UserCreateReqVO reqVO); | |
| 28 | + Long createUser(@Valid UserSaveReqVO createReqVO); | |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * 修改用户 |
| 32 | 32 | * |
| 33 | - * @param reqVO 用户信息 | |
| 33 | + * @param updateReqVO 用户信息 | |
| 34 | 34 | */ |
| 35 | - void updateUser(@Valid UserUpdateReqVO reqVO); | |
| 35 | + void updateUser(@Valid UserSaveReqVO updateReqVO); | |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * 更新用户的最后登陆信息 |
| ... | ... | @@ -168,14 +168,6 @@ public interface AdminUserService { |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
| 171 | - * 获得用户列表 | |
| 172 | - * | |
| 173 | - * @param reqVO 列表请求 | |
| 174 | - * @return 用户列表 | |
| 175 | - */ | |
| 176 | - List<AdminUserDO> getUserList(UserExportReqVO reqVO); | |
| 177 | - | |
| 178 | - /** | |
| 179 | 171 | * 获得用户列表,基于昵称模糊匹配 |
| 180 | 172 | * |
| 181 | 173 | * @param nickname 昵称 |
| ... | ... | @@ -209,10 +201,4 @@ public interface AdminUserService { |
| 209 | 201 | */ |
| 210 | 202 | boolean isPasswordMatch(String rawPassword, String encodedPassword); |
| 211 | 203 | |
| 212 | - /** | |
| 213 | - * 获取所有用户列表 | |
| 214 | - * | |
| 215 | - * @return 用户列表 | |
| 216 | - */ | |
| 217 | - List<AdminUserDO> getUserList(); | |
| 218 | 204 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
| ... | ... | @@ -8,12 +8,15 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 11 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 11 | 12 | import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils; |
| 12 | 13 | import cn.iocoder.yudao.module.infra.api.file.FileApi; |
| 13 | 14 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; |
| 14 | 15 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; |
| 15 | -import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*; | |
| 16 | -import cn.iocoder.yudao.module.system.convert.user.UserConvert; | |
| 16 | +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportExcelVO; | |
| 17 | +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRespVO; | |
| 18 | +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO; | |
| 19 | +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO; | |
| 17 | 20 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| 18 | 21 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; |
| 19 | 22 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| ... | ... | @@ -76,7 +79,7 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 76 | 79 | |
| 77 | 80 | @Override |
| 78 | 81 | @Transactional(rollbackFor = Exception.class) |
| 79 | - public Long createUser(UserCreateReqVO reqVO) { | |
| 82 | + public Long createUser(UserSaveReqVO createReqVO) { | |
| 80 | 83 | // 校验账户配合 |
| 81 | 84 | tenantService.handleTenantInfo(tenant -> { |
| 82 | 85 | long count = userMapper.selectCount(); |
| ... | ... | @@ -85,12 +88,12 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 85 | 88 | } |
| 86 | 89 | }); |
| 87 | 90 | // 校验正确性 |
| 88 | - validateUserForCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | |
| 89 | - reqVO.getDeptId(), reqVO.getPostIds()); | |
| 91 | + validateUserForCreateOrUpdate(null, createReqVO.getUsername(), | |
| 92 | + createReqVO.getMobile(), createReqVO.getEmail(), createReqVO.getDeptId(), createReqVO.getPostIds()); | |
| 90 | 93 | // 插入用户 |
| 91 | - AdminUserDO user = UserConvert.INSTANCE.convert(reqVO); | |
| 94 | + AdminUserDO user = BeanUtils.toBean(createReqVO, AdminUserDO.class); | |
| 92 | 95 | user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 |
| 93 | - user.setPassword(encodePassword(reqVO.getPassword())); // 加密密码 | |
| 96 | + user.setPassword(encodePassword(createReqVO.getPassword())); // 加密密码 | |
| 94 | 97 | userMapper.insert(user); |
| 95 | 98 | // 插入关联岗位 |
| 96 | 99 | if (CollectionUtil.isNotEmpty(user.getPostIds())) { |
| ... | ... | @@ -102,18 +105,19 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 102 | 105 | |
| 103 | 106 | @Override |
| 104 | 107 | @Transactional(rollbackFor = Exception.class) |
| 105 | - public void updateUser(UserUpdateReqVO reqVO) { | |
| 108 | + public void updateUser(UserSaveReqVO updateReqVO) { | |
| 109 | + updateReqVO.setPassword(null); // 特殊:此处不更新密码 | |
| 106 | 110 | // 校验正确性 |
| 107 | - validateUserForCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | |
| 108 | - reqVO.getDeptId(), reqVO.getPostIds()); | |
| 111 | + validateUserForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getUsername(), | |
| 112 | + updateReqVO.getMobile(), updateReqVO.getEmail(), updateReqVO.getDeptId(), updateReqVO.getPostIds()); | |
| 109 | 113 | // 更新用户 |
| 110 | - AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO); | |
| 114 | + AdminUserDO updateObj = BeanUtils.toBean(updateReqVO, AdminUserDO.class); | |
| 111 | 115 | userMapper.updateById(updateObj); |
| 112 | 116 | // 更新岗位 |
| 113 | - updateUserPost(reqVO, updateObj); | |
| 117 | + updateUserPost(updateReqVO, updateObj); | |
| 114 | 118 | } |
| 115 | 119 | |
| 116 | - private void updateUserPost(UserUpdateReqVO reqVO, AdminUserDO updateObj) { | |
| 120 | + private void updateUserPost(UserSaveReqVO reqVO, AdminUserDO updateObj) { | |
| 117 | 121 | Long userId = reqVO.getId(); |
| 118 | 122 | Set<Long> dbPostIds = convertSet(userPostMapper.selectListByUserId(userId), UserPostDO::getPostId); |
| 119 | 123 | // 计算新增和删除的岗位编号 |
| ... | ... | @@ -142,7 +146,7 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 142 | 146 | validateEmailUnique(id, reqVO.getEmail()); |
| 143 | 147 | validateMobileUnique(id, reqVO.getMobile()); |
| 144 | 148 | // 执行更新 |
| 145 | - userMapper.updateById(UserConvert.INSTANCE.convert(reqVO).setId(id)); | |
| 149 | + userMapper.updateById(BeanUtils.toBean(reqVO, AdminUserDO.class).setId(id)); | |
| 146 | 150 | } |
| 147 | 151 | |
| 148 | 152 | @Override |
| ... | ... | @@ -156,7 +160,7 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 156 | 160 | } |
| 157 | 161 | |
| 158 | 162 | @Override |
| 159 | - public String updateUserAvatar(Long id, InputStream avatarFile) throws Exception { | |
| 163 | + public String updateUserAvatar(Long id, InputStream avatarFile) { | |
| 160 | 164 | validateUserExists(id); |
| 161 | 165 | // 存储文件 |
| 162 | 166 | String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile)); |
| ... | ... | @@ -272,11 +276,6 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 272 | 276 | } |
| 273 | 277 | |
| 274 | 278 | @Override |
| 275 | - public List<AdminUserDO> getUserList(UserExportReqVO reqVO) { | |
| 276 | - return userMapper.selectList(reqVO, getDeptCondition(reqVO.getDeptId())); | |
| 277 | - } | |
| 278 | - | |
| 279 | - @Override | |
| 280 | 279 | public List<AdminUserDO> getUserListByNickname(String nickname) { |
| 281 | 280 | return userMapper.selectListByNickname(nickname); |
| 282 | 281 | } |
| ... | ... | @@ -415,7 +414,7 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 415 | 414 | // 判断如果不存在,在进行插入 |
| 416 | 415 | AdminUserDO existUser = userMapper.selectByUsername(importUser.getUsername()); |
| 417 | 416 | if (existUser == null) { |
| 418 | - userMapper.insert(UserConvert.INSTANCE.convert(importUser) | |
| 417 | + userMapper.insert(BeanUtils.toBean(importUser, AdminUserDO.class) | |
| 419 | 418 | .setPassword(encodePassword(userInitPassword)).setPostIds(new HashSet<>())); // 设置默认密码及空岗位编号数组 |
| 420 | 419 | respVO.getCreateUsernames().add(importUser.getUsername()); |
| 421 | 420 | return; |
| ... | ... | @@ -425,7 +424,7 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 425 | 424 | respVO.getFailureUsernames().put(importUser.getUsername(), USER_USERNAME_EXISTS.getMsg()); |
| 426 | 425 | return; |
| 427 | 426 | } |
| 428 | - AdminUserDO updateUser = UserConvert.INSTANCE.convert(importUser); | |
| 427 | + AdminUserDO updateUser = BeanUtils.toBean(importUser, AdminUserDO.class); | |
| 429 | 428 | updateUser.setId(existUser.getId()); |
| 430 | 429 | userMapper.updateById(updateUser); |
| 431 | 430 | respVO.getUpdateUsernames().add(importUser.getUsername()); |
| ... | ... | @@ -444,16 +443,6 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 444 | 443 | } |
| 445 | 444 | |
| 446 | 445 | /** |
| 447 | - * 获取所有用户列表 | |
| 448 | - * | |
| 449 | - * @return 用户列表 | |
| 450 | - */ | |
| 451 | - @Override | |
| 452 | - public List<AdminUserDO> getUserList() { | |
| 453 | - return userMapper.selectList(); | |
| 454 | - } | |
| 455 | - | |
| 456 | - /** | |
| 457 | 446 | * 对密码进行加密 |
| 458 | 447 | * |
| 459 | 448 | * @param password 密码 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImplTest.java
| ... | ... | @@ -80,11 +80,11 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { |
| 80 | 80 | @Test |
| 81 | 81 | public void testCreatUser_success() { |
| 82 | 82 | // 准备参数 |
| 83 | - UserCreateReqVO reqVO = randomPojo(UserCreateReqVO.class, o -> { | |
| 83 | + UserSaveReqVO reqVO = randomPojo(UserSaveReqVO.class, o -> { | |
| 84 | 84 | o.setSex(RandomUtil.randomEle(SexEnum.values()).getSex()); |
| 85 | 85 | o.setMobile(randomString()); |
| 86 | 86 | o.setPostIds(asSet(1L, 2L)); |
| 87 | - }); | |
| 87 | + }).setId(null); // 避免 id 被赋值 | |
| 88 | 88 | // mock 账户额度充足 |
| 89 | 89 | TenantDO tenant = randomPojo(TenantDO.class, o -> o.setAccountCount(1)); |
| 90 | 90 | doNothing().when(tenantService).handleTenantInfo(argThat(handler -> { |
| ... | ... | @@ -111,7 +111,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { |
| 111 | 111 | Long userId = userService.createUser(reqVO); |
| 112 | 112 | // 断言 |
| 113 | 113 | AdminUserDO user = userMapper.selectById(userId); |
| 114 | - assertPojoEquals(reqVO, user, "password"); | |
| 114 | + assertPojoEquals(reqVO, user, "password", "id"); | |
| 115 | 115 | assertEquals("yudaoyuanma", user.getPassword()); |
| 116 | 116 | assertEquals(CommonStatusEnum.ENABLE.getStatus(), user.getStatus()); |
| 117 | 117 | // 断言关联岗位 |
| ... | ... | @@ -123,7 +123,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { |
| 123 | 123 | @Test |
| 124 | 124 | public void testCreatUser_max() { |
| 125 | 125 | // 准备参数 |
| 126 | - UserCreateReqVO reqVO = randomPojo(UserCreateReqVO.class); | |
| 126 | + UserSaveReqVO reqVO = randomPojo(UserSaveReqVO.class); | |
| 127 | 127 | // mock 账户额度不足 |
| 128 | 128 | TenantDO tenant = randomPojo(TenantDO.class, o -> o.setAccountCount(-1)); |
| 129 | 129 | doNothing().when(tenantService).handleTenantInfo(argThat(handler -> { |
| ... | ... | @@ -143,7 +143,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { |
| 143 | 143 | userPostMapper.insert(new UserPostDO().setUserId(dbUser.getId()).setPostId(1L)); |
| 144 | 144 | userPostMapper.insert(new UserPostDO().setUserId(dbUser.getId()).setPostId(2L)); |
| 145 | 145 | // 准备参数 |
| 146 | - UserUpdateReqVO reqVO = randomPojo(UserUpdateReqVO.class, o -> { | |
| 146 | + UserSaveReqVO reqVO = randomPojo(UserSaveReqVO.class, o -> { | |
| 147 | 147 | o.setId(dbUser.getId()); |
| 148 | 148 | o.setSex(RandomUtil.randomEle(SexEnum.values()).getSex()); |
| 149 | 149 | o.setMobile(randomString()); |
| ... | ... | @@ -167,7 +167,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { |
| 167 | 167 | userService.updateUser(reqVO); |
| 168 | 168 | // 断言 |
| 169 | 169 | AdminUserDO user = userMapper.selectById(reqVO.getId()); |
| 170 | - assertPojoEquals(reqVO, user); | |
| 170 | + assertPojoEquals(reqVO, user, "password"); | |
| 171 | 171 | // 断言关联岗位 |
| 172 | 172 | List<UserPostDO> userPosts = userPostMapper.selectListByUserId(user.getId()); |
| 173 | 173 | assertEquals(2L, userPosts.get(0).getPostId()); |
| ... | ... | @@ -355,28 +355,6 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { |
| 355 | 355 | assertPojoEquals(dbUser, pageResult.getList().get(0)); |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - @Test | |
| 359 | - public void testGetUserList_export() { | |
| 360 | - // mock 数据 | |
| 361 | - AdminUserDO dbUser = initGetUserPageData(); | |
| 362 | - // 准备参数 | |
| 363 | - UserExportReqVO reqVO = new UserExportReqVO(); | |
| 364 | - reqVO.setUsername("tu"); | |
| 365 | - reqVO.setMobile("1560"); | |
| 366 | - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 367 | - reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24)); | |
| 368 | - reqVO.setDeptId(1L); // 其中,1L 是 2L 的父部门 | |
| 369 | - // mock 方法 | |
| 370 | - List<DeptDO> deptList = newArrayList(randomPojo(DeptDO.class, o -> o.setId(2L))); | |
| 371 | - when(deptService.getChildDeptList(eq(reqVO.getDeptId()))).thenReturn(deptList); | |
| 372 | - | |
| 373 | - // 调用 | |
| 374 | - List<AdminUserDO> list = userService.getUserList(reqVO); | |
| 375 | - // 断言 | |
| 376 | - assertEquals(1, list.size()); | |
| 377 | - assertPojoEquals(dbUser, list.get(0)); | |
| 378 | - } | |
| 379 | - | |
| 380 | 358 | /** |
| 381 | 359 | * 初始化 getUserPage 方法的测试数据 |
| 382 | 360 | */ | ... | ... |