🔧 简化 user 模块的 VO
This commit is contained in:
parent
5cce6a510e
commit
b93ed9efbb
@ -1,8 +1,8 @@
|
||||
package cn.iocoder.yudao.module.system.api.user;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import cn.iocoder.yudao.module.system.convert.user.UserConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -25,25 +25,25 @@ public class AdminUserApiImpl implements AdminUserApi {
|
||||
@Override
|
||||
public CommonResult<AdminUserRespDTO> getUser(Long id) {
|
||||
AdminUserDO user = userService.getUser(id);
|
||||
return success(UserConvert.INSTANCE.convert4(user));
|
||||
return success(BeanUtils.toBean(user, AdminUserRespDTO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<AdminUserRespDTO>> getUserList(Collection<Long> ids) {
|
||||
List<AdminUserDO> users = userService.getUserList(ids);
|
||||
return success(UserConvert.INSTANCE.convertList4(users));
|
||||
return success(BeanUtils.toBean(users, AdminUserRespDTO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<AdminUserRespDTO>> getUserListByDeptIds(Collection<Long> deptIds) {
|
||||
List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds);
|
||||
return success(UserConvert.INSTANCE.convertList4(users));
|
||||
return success(BeanUtils.toBean(users, AdminUserRespDTO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<AdminUserRespDTO>> getUserListByPostIds(Collection<Long> postIds) {
|
||||
List<AdminUserDO> users = userService.getUserListByPostIds(postIds);
|
||||
return success(UserConvert.INSTANCE.convertList4(users));
|
||||
return success(BeanUtils.toBean(users, AdminUserRespDTO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,23 +1,23 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*;
|
||||
import cn.iocoder.yudao.module.system.convert.user.UserConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.enums.common.SexEnum;
|
||||
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import cn.iocoder.yudao.module.system.enums.common.SexEnum;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -27,11 +27,12 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Tag(name = "管理后台 - 用户")
|
||||
@ -48,7 +49,7 @@ public class UserController {
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "新增用户")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:create')")
|
||||
public CommonResult<Long> createUser(@Valid @RequestBody UserCreateReqVO reqVO) {
|
||||
public CommonResult<Long> createUser(@Valid @RequestBody UserSaveReqVO reqVO) {
|
||||
Long id = userService.createUser(reqVO);
|
||||
return success(id);
|
||||
}
|
||||
@ -56,7 +57,7 @@ public class UserController {
|
||||
@PutMapping("update")
|
||||
@Operation(summary = "修改用户")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:update')")
|
||||
public CommonResult<Boolean> updateUser(@Valid @RequestBody UserUpdateReqVO reqVO) {
|
||||
public CommonResult<Boolean> updateUser(@Valid @RequestBody UserSaveReqVO reqVO) {
|
||||
userService.updateUser(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
@ -89,33 +90,27 @@ public class UserController {
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得用户分页列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:list')")
|
||||
public CommonResult<PageResult<UserPageItemRespVO>> getUserPage(@Valid UserPageReqVO reqVO) {
|
||||
public CommonResult<PageResult<UserRespVO>> getUserPage(@Valid UserPageReqVO pageReqVO) {
|
||||
// 获得用户分页列表
|
||||
PageResult<AdminUserDO> pageResult = userService.getUserPage(reqVO);
|
||||
PageResult<AdminUserDO> pageResult = userService.getUserPage(pageReqVO);
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return success(new PageResult<>(pageResult.getTotal())); // 返回空
|
||||
return success(new PageResult<>(pageResult.getTotal()));
|
||||
}
|
||||
// 拼接数据
|
||||
Map<Long, DeptDO> deptMap = deptService.getDeptMap(
|
||||
convertList(pageResult.getList(), AdminUserDO::getDeptId));
|
||||
return success(new PageResult<>(UserConvert.INSTANCE.convertList(pageResult.getList(), deptMap),
|
||||
pageResult.getTotal()));
|
||||
}
|
||||
|
||||
// 获得拼接需要的数据
|
||||
Collection<Long> deptIds = convertList(pageResult.getList(), AdminUserDO::getDeptId);
|
||||
Map<Long, DeptDO> deptMap = deptService.getDeptMap(deptIds);
|
||||
// 拼接结果返回
|
||||
List<UserPageItemRespVO> userList = new ArrayList<>(pageResult.getList().size());
|
||||
pageResult.getList().forEach(user -> {
|
||||
UserPageItemRespVO respVO = UserConvert.INSTANCE.convert(user);
|
||||
respVO.setDept(UserConvert.INSTANCE.convert(deptMap.get(user.getDeptId())));
|
||||
userList.add(respVO);
|
||||
});
|
||||
return success(new PageResult<>(userList, pageResult.getTotal()));
|
||||
}
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@GetMapping({"/list-all-simple", "/simple-list"})
|
||||
@Operation(summary = "获取用户精简信息列表", description = "只包含被开启的用户,主要用于前端的下拉选项")
|
||||
public CommonResult<List<UserSimpleRespVO>> getSimpleUserList() {
|
||||
// 获用户列表,只要开启状态的
|
||||
List<AdminUserDO> list = userService.getUserListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
// 排序后,返回给前端
|
||||
return success(UserConvert.INSTANCE.convertList04(list));
|
||||
// 拼接数据
|
||||
Map<Long, DeptDO> deptMap = deptService.getDeptMap(
|
||||
convertList(list, AdminUserDO::getDeptId));
|
||||
return success(UserConvert.INSTANCE.convertSimpleList(list, deptMap));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ -124,41 +119,24 @@ public class UserController {
|
||||
@PreAuthorize("@ss.hasPermission('system:user:query')")
|
||||
public CommonResult<UserRespVO> getUser(@RequestParam("id") Long id) {
|
||||
AdminUserDO user = userService.getUser(id);
|
||||
// 获得部门数据
|
||||
// 拼接数据
|
||||
DeptDO dept = deptService.getDept(user.getDeptId());
|
||||
return success(UserConvert.INSTANCE.convert(user).setDept(UserConvert.INSTANCE.convert(dept)));
|
||||
return success(UserConvert.INSTANCE.convert(user, dept));
|
||||
}
|
||||
|
||||
@GetMapping("/export")
|
||||
@Operation(summary = "导出用户")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportUserList(@Validated UserExportReqVO reqVO,
|
||||
public void exportUserList(@Validated UserPageReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
// 获得用户列表
|
||||
List<AdminUserDO> users = userService.getUserList(reqVO);
|
||||
|
||||
// 获得拼接需要的数据
|
||||
Collection<Long> deptIds = convertList(users, AdminUserDO::getDeptId);
|
||||
Map<Long, DeptDO> deptMap = deptService.getDeptMap(deptIds);
|
||||
Map<Long, AdminUserDO> deptLeaderUserMap = userService.getUserMap(
|
||||
convertSet(deptMap.values(), DeptDO::getLeaderUserId));
|
||||
// 拼接数据
|
||||
List<UserExcelVO> excelUsers = new ArrayList<>(users.size());
|
||||
users.forEach(user -> {
|
||||
UserExcelVO excelVO = UserConvert.INSTANCE.convert02(user);
|
||||
// 设置部门
|
||||
MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> {
|
||||
excelVO.setDeptName(dept.getName());
|
||||
// 设置部门负责人的名字
|
||||
MapUtils.findAndThen(deptLeaderUserMap, dept.getLeaderUserId(),
|
||||
deptLeaderUser -> excelVO.setDeptLeaderNickname(deptLeaderUser.getNickname()));
|
||||
});
|
||||
excelUsers.add(excelVO);
|
||||
});
|
||||
|
||||
// 输出
|
||||
ExcelUtils.write(response, "用户数据.xls", "用户列表", UserExcelVO.class, excelUsers);
|
||||
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<AdminUserDO> list = userService.getUserPage(exportReqVO).getList();
|
||||
// 输出 Excel
|
||||
Map<Long, DeptDO> deptMap = deptService.getDeptMap(
|
||||
convertList(list, AdminUserDO::getDeptId));
|
||||
ExcelUtils.write(response, "用户数据.xls", "数据", UserRespVO.class,
|
||||
UserConvert.INSTANCE.convertList(list, deptMap));
|
||||
}
|
||||
|
||||
@GetMapping("/get-import-template")
|
||||
@ -171,7 +149,6 @@ public class UserController {
|
||||
UserImportExcelVO.builder().username("yuanma").deptId(2L).email("yuanma@iocoder.cn").mobile("15601701300")
|
||||
.nickname("源码").status(CommonStatusEnum.DISABLE.getStatus()).sex(SexEnum.FEMALE.getSex()).build()
|
||||
);
|
||||
|
||||
// 输出
|
||||
ExcelUtils.write(response, "用户导入模板.xls", "用户列表", UserImportExcelVO.class, list);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.controller.admin.user;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileRespVO;
|
||||
@ -20,8 +19,8 @@ import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
||||
import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
||||
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -59,27 +58,18 @@ public class UserProfileController {
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得登录用户信息")
|
||||
@DataPermission(enable = false) // 关闭数据权限,避免只查看自己时,查询不到部门。
|
||||
public CommonResult<UserProfileRespVO> profile() {
|
||||
public CommonResult<UserProfileRespVO> getUserProfile() {
|
||||
// 获得用户基本信息
|
||||
AdminUserDO user = userService.getUser(getLoginUserId());
|
||||
UserProfileRespVO resp = UserConvert.INSTANCE.convert03(user);
|
||||
// 获得用户角色
|
||||
List<RoleDO> userRoles = roleService.getRoleListFromCache(permissionService.getUserRoleIdListByUserId(user.getId()));
|
||||
resp.setRoles(UserConvert.INSTANCE.convertList(userRoles));
|
||||
// 获得部门信息
|
||||
if (user.getDeptId() != null) {
|
||||
DeptDO dept = deptService.getDept(user.getDeptId());
|
||||
resp.setDept(UserConvert.INSTANCE.convert02(dept));
|
||||
}
|
||||
DeptDO dept = user.getDeptId() != null ? deptService.getDept(user.getDeptId()) : null;
|
||||
// 获得岗位信息
|
||||
if (CollUtil.isNotEmpty(user.getPostIds())) {
|
||||
List<PostDO> posts = postService.getPostList(user.getPostIds());
|
||||
resp.setPosts(UserConvert.INSTANCE.convertList02(posts));
|
||||
}
|
||||
List<PostDO> posts = CollUtil.isNotEmpty(user.getPostIds()) ? postService.getPostList(user.getPostIds()) : null;
|
||||
// 获得社交用户信息
|
||||
List<SocialUserDO> socialUsers = socialService.getSocialUserList(user.getId(), UserTypeEnum.ADMIN.getValue());
|
||||
resp.setSocialUsers(UserConvert.INSTANCE.convertList03(socialUsers));
|
||||
return success(resp);
|
||||
return success(UserConvert.INSTANCE.convert(user, userRoles, dept, posts, socialUsers));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ -96,7 +86,8 @@ public class UserProfileController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/update-avatar", method = {RequestMethod.POST, RequestMethod.PUT}) // 解决 uni-app 不支持 Put 上传文件的问题
|
||||
@RequestMapping(value = "/update-avatar",
|
||||
method = {RequestMethod.POST, RequestMethod.PUT}) // 解决 uni-app 不支持 Put 上传文件的问题
|
||||
@Operation(summary = "上传用户个人头像")
|
||||
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception {
|
||||
if (file.isEmpty()) {
|
||||
|
@ -1,28 +1,38 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user.vo.profile;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserBaseVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSimpleRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSimpleRespVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "管理后台 - 用户个人中心信息 Response VO")
|
||||
public class UserProfileRespVO extends UserBaseVO {
|
||||
public class UserProfileRespVO {
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer status;
|
||||
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "用户邮箱", example = "yudao@iocoder.cn")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "手机号码", example = "15601691300")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "用户性别,参见 SexEnum 枚举类", example = "1")
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
|
||||
private String avatar;
|
||||
|
||||
@Schema(description = "最后登录 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "192.168.1.1")
|
||||
private String loginIp;
|
||||
@ -36,58 +46,20 @@ public class UserProfileRespVO extends UserBaseVO {
|
||||
/**
|
||||
* 所属角色
|
||||
*/
|
||||
private List<Role> roles;
|
||||
|
||||
private List<RoleSimpleRespVO> roles;
|
||||
/**
|
||||
* 所在部门
|
||||
*/
|
||||
private Dept dept;
|
||||
|
||||
private DeptSimpleRespVO dept;
|
||||
/**
|
||||
* 所属岗位数组
|
||||
*/
|
||||
private List<Post> posts;
|
||||
private List<PostSimpleRespVO> posts;
|
||||
/**
|
||||
* 社交用户数组
|
||||
*/
|
||||
private List<SocialUser> socialUsers;
|
||||
|
||||
@Schema(description = "角色")
|
||||
@Data
|
||||
public static class Role {
|
||||
|
||||
@Schema(description = "角色编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "普通角色")
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
@Schema(description = "部门")
|
||||
@Data
|
||||
public static class Dept {
|
||||
|
||||
@Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "研发部")
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
@Schema(description = "岗位")
|
||||
@Data
|
||||
public static class Post {
|
||||
|
||||
@Schema(description = "岗位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "开发")
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
@Schema(description = "社交用户")
|
||||
@Data
|
||||
public static class SocialUser {
|
||||
|
@ -7,6 +7,7 @@ import org.hibernate.validator.constraints.Length;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
|
||||
@Schema(description = "管理后台 - 用户个人信息更新 Request VO")
|
||||
@Data
|
||||
public class UserProfileUpdateReqVO {
|
||||
|
@ -1,21 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user.vo.user;
|
||||
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
@Schema(description = "管理后台 - 用户创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class UserCreateReqVO extends UserBaseVO {
|
||||
|
||||
@Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
|
||||
@NotEmpty(message = "密码不能为空")
|
||||
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
|
||||
private String password;
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user.vo.user;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户 Excel 导出 VO
|
||||
*/
|
||||
@Data
|
||||
public class UserExcelVO {
|
||||
|
||||
@ExcelProperty("用户编号")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("用户名称")
|
||||
private String username;
|
||||
|
||||
@ExcelProperty("用户昵称")
|
||||
private String nickname;
|
||||
|
||||
@ExcelProperty("用户邮箱")
|
||||
private String email;
|
||||
|
||||
@ExcelProperty("手机号码")
|
||||
private String mobile;
|
||||
|
||||
@ExcelProperty(value = "用户性别", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.USER_SEX)
|
||||
private Integer sex;
|
||||
|
||||
@ExcelProperty(value = "帐号状态", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.COMMON_STATUS)
|
||||
private Integer status;
|
||||
|
||||
@ExcelProperty("最后登录IP")
|
||||
private String loginIp;
|
||||
|
||||
@ExcelProperty("最后登录时间")
|
||||
private LocalDateTime loginDate;
|
||||
|
||||
@ExcelProperty("部门名称")
|
||||
private String deptName;
|
||||
|
||||
@ExcelProperty("部门负责人")
|
||||
private String deptLeaderNickname;
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user.vo.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 用户导出 Request VO,参数和 UserPageReqVO 是一致的")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserExportReqVO {
|
||||
|
||||
@Schema(description = "用户账号,模糊匹配", example = "yudao")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "手机号码,模糊匹配", example = "yudao")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "创建时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
@Schema(description = "部门编号,同时筛选子部门", example = "1024")
|
||||
private Long deptId;
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user.vo.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Schema(description = "管理后台 - 用户分页时的信息 Response VO,相比用户基本信息来说,会多部门信息")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class UserPageItemRespVO extends UserRespVO {
|
||||
|
||||
/**
|
||||
* 所在部门
|
||||
*/
|
||||
private Dept dept;
|
||||
|
||||
@Schema(description = "部门")
|
||||
@Data
|
||||
public static class Dept {
|
||||
|
||||
@Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "研发部")
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +1,72 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user.vo.user;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Set;
|
||||
|
||||
@Schema(description = "管理后台 - 用户信息 Response VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class UserRespVO extends UserBaseVO {
|
||||
@ExcelIgnoreUnannotated
|
||||
public class UserRespVO{
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty("用户编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao")
|
||||
@ExcelProperty("用户名称")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@ExcelProperty("用户昵称")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "备注", example = "我是一个用户")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "部门ID", example = "我是一个用户")
|
||||
private Long deptId;
|
||||
@Schema(description = "部门名称", example = "IT 部")
|
||||
@ExcelProperty("部门名称")
|
||||
private String deptName;
|
||||
|
||||
@Schema(description = "岗位编号数组", example = "1")
|
||||
private Set<Long> postIds;
|
||||
|
||||
@Schema(description = "用户邮箱", example = "yudao@iocoder.cn")
|
||||
@ExcelProperty("用户邮箱")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "手机号码", example = "15601691300")
|
||||
@ExcelProperty("手机号码")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "用户性别,参见 SexEnum 枚举类", example = "1")
|
||||
@ExcelProperty(value = "用户性别", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.USER_SEX)
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
|
||||
private String avatar;
|
||||
|
||||
@Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty(value = "帐号状态", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.COMMON_STATUS)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "最后登录 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "192.168.1.1")
|
||||
@ExcelProperty("最后登录IP")
|
||||
private String loginIp;
|
||||
|
||||
@Schema(description = "最后登录时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
|
||||
@ExcelProperty("最后登录时间")
|
||||
private LocalDateTime loginDate;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
|
||||
|
@ -1,21 +1,22 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user.vo.user;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.validation.Mobile;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Schema(description = "管理后台 - 用户创建/修改 Request VO")
|
||||
@Data
|
||||
public class UserBaseVO {
|
||||
public class UserSaveReqVO {
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao")
|
||||
@NotBlank(message = "用户账号不能为空")
|
||||
@ -51,4 +52,17 @@ public class UserBaseVO {
|
||||
@Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
|
||||
private String avatar;
|
||||
|
||||
// ========== 仅【创建】时,需要传递的字段 ==========
|
||||
|
||||
@Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
|
||||
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
|
||||
private String password;
|
||||
|
||||
@AssertTrue(message = "密码不能为空")
|
||||
@JsonIgnore
|
||||
public boolean isPasswordValid() {
|
||||
return id != null // 修改时,不需要传递
|
||||
|| (ObjectUtil.isAllNotEmpty(password)); // 新增时,必须都传递 password
|
||||
}
|
||||
|
||||
}
|
@ -17,4 +17,9 @@ public class UserSimpleRespVO {
|
||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "部门ID", example = "我是一个用户")
|
||||
private Long deptId;
|
||||
@Schema(description = "部门名称", example = "IT 部")
|
||||
private String deptName;
|
||||
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.user.vo.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 用户更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class UserUpdateReqVO extends UserBaseVO {
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.system.convert.tenant;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@ -15,8 +15,8 @@ public interface TenantConvert {
|
||||
|
||||
TenantConvert INSTANCE = Mappers.getMapper(TenantConvert.class);
|
||||
|
||||
default UserCreateReqVO convert02(TenantSaveReqVO bean) {
|
||||
UserCreateReqVO reqVO = new UserCreateReqVO();
|
||||
default UserSaveReqVO convert02(TenantSaveReqVO bean) {
|
||||
UserSaveReqVO reqVO = new UserSaveReqVO();
|
||||
reqVO.setUsername(bean.getUsername());
|
||||
reqVO.setPassword(bean.getPassword());
|
||||
reqVO.setNickname(bean.getContactName()).setMobile(bean.getContactMobile());
|
||||
|
@ -1,10 +1,14 @@
|
||||
package cn.iocoder.yudao.module.system.convert.user;
|
||||
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSimpleRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSimpleRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSimpleRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
||||
@ -21,36 +25,34 @@ public interface UserConvert {
|
||||
|
||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
||||
|
||||
UserPageItemRespVO convert(AdminUserDO bean);
|
||||
default List<UserRespVO> convertList(List<AdminUserDO> list, Map<Long, DeptDO> deptMap) {
|
||||
return CollectionUtils.convertList(list, user -> convert(user, deptMap.get(user.getDeptId())));
|
||||
}
|
||||
|
||||
UserPageItemRespVO.Dept convert(DeptDO bean);
|
||||
default UserRespVO convert(AdminUserDO user, DeptDO dept) {
|
||||
UserRespVO userVO = BeanUtils.toBean(user, UserRespVO.class);
|
||||
if (dept != null) {
|
||||
userVO.setDeptName(dept.getName());
|
||||
}
|
||||
return userVO;
|
||||
}
|
||||
|
||||
AdminUserDO convert(UserCreateReqVO bean);
|
||||
default List<UserSimpleRespVO> convertSimpleList(List<AdminUserDO> list, Map<Long, DeptDO> deptMap) {
|
||||
return CollectionUtils.convertList(list, user -> {
|
||||
UserSimpleRespVO userVO = BeanUtils.toBean(user, UserSimpleRespVO.class);
|
||||
MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> userVO.setDeptName(dept.getName()));
|
||||
return userVO;
|
||||
});
|
||||
}
|
||||
|
||||
AdminUserDO convert(UserUpdateReqVO bean);
|
||||
|
||||
UserExcelVO convert02(AdminUserDO bean);
|
||||
|
||||
AdminUserDO convert(UserImportExcelVO bean);
|
||||
|
||||
UserProfileRespVO convert03(AdminUserDO bean);
|
||||
|
||||
List<UserProfileRespVO.Role> convertList(List<RoleDO> list);
|
||||
|
||||
UserProfileRespVO.Dept convert02(DeptDO bean);
|
||||
|
||||
AdminUserDO convert(UserProfileUpdateReqVO bean);
|
||||
|
||||
AdminUserDO convert(UserProfileUpdatePasswordReqVO bean);
|
||||
|
||||
List<UserProfileRespVO.Post> convertList02(List<PostDO> list);
|
||||
|
||||
List<UserProfileRespVO.SocialUser> convertList03(List<SocialUserDO> list);
|
||||
|
||||
List<UserSimpleRespVO> convertList04(List<AdminUserDO> list);
|
||||
|
||||
AdminUserRespDTO convert4(AdminUserDO bean);
|
||||
|
||||
List<AdminUserRespDTO> convertList4(List<AdminUserDO> users);
|
||||
default UserProfileRespVO convert(AdminUserDO user, List<RoleDO> userRoles,
|
||||
DeptDO dept, List<PostDO> posts, List<SocialUserDO> socialUsers) {
|
||||
UserProfileRespVO userVO = BeanUtils.toBean(user, UserProfileRespVO.class);
|
||||
userVO.setRoles(BeanUtils.toBean(userRoles, RoleSimpleRespVO.class));
|
||||
userVO.setDept(BeanUtils.toBean(dept, DeptSimpleRespVO.class));
|
||||
userVO.setPosts(BeanUtils.toBean(posts, PostSimpleRespVO.class));
|
||||
userVO.setSocialUsers(BeanUtils.toBean(socialUsers, UserProfileRespVO.SocialUser.class));
|
||||
return userVO;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.dal.mysql.user;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserExportReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -36,15 +35,6 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
|
||||
.orderByDesc(AdminUserDO::getId));
|
||||
}
|
||||
|
||||
default List<AdminUserDO> selectList(UserExportReqVO reqVO, Collection<Long> deptIds) {
|
||||
return selectList(new LambdaQueryWrapperX<AdminUserDO>()
|
||||
.likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername())
|
||||
.likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile())
|
||||
.eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus())
|
||||
.betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getCreateTime())
|
||||
.inIfPresent(AdminUserDO::getDeptId, deptIds));
|
||||
}
|
||||
|
||||
default List<AdminUserDO> selectListByNickname(String nickname) {
|
||||
return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getNickname, nickname));
|
||||
}
|
||||
|
@ -1,16 +1,22 @@
|
||||
package cn.iocoder.yudao.module.system.service.user;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportExcelVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 后台用户 Service 接口
|
||||
@ -22,17 +28,17 @@ public interface AdminUserService {
|
||||
/**
|
||||
* 创建用户
|
||||
*
|
||||
* @param reqVO 用户信息
|
||||
* @param createReqVO 用户信息
|
||||
* @return 用户编号
|
||||
*/
|
||||
Long createUser(@Valid UserCreateReqVO reqVO);
|
||||
Long createUser(@Valid UserSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*
|
||||
* @param reqVO 用户信息
|
||||
* @param updateReqVO 用户信息
|
||||
*/
|
||||
void updateUser(@Valid UserUpdateReqVO reqVO);
|
||||
void updateUser(@Valid UserSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 更新用户的最后登陆信息
|
||||
@ -167,14 +173,6 @@ public interface AdminUserService {
|
||||
return CollectionUtils.convertMap(getUserList(ids), AdminUserDO::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得用户列表
|
||||
*
|
||||
* @param reqVO 列表请求
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<AdminUserDO> getUserList(UserExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得用户列表,基于昵称模糊匹配
|
||||
*
|
||||
|
@ -8,12 +8,15 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
|
||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*;
|
||||
import cn.iocoder.yudao.module.system.convert.user.UserConvert;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportExcelVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
@ -76,7 +79,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createUser(UserCreateReqVO reqVO) {
|
||||
public Long createUser(UserSaveReqVO createReqVO) {
|
||||
// 校验账户配合
|
||||
tenantService.handleTenantInfo(tenant -> {
|
||||
long count = userMapper.selectCount();
|
||||
@ -85,12 +88,12 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
});
|
||||
// 校验正确性
|
||||
validateUserForCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
|
||||
reqVO.getDeptId(), reqVO.getPostIds());
|
||||
validateUserForCreateOrUpdate(null, createReqVO.getUsername(),
|
||||
createReqVO.getMobile(), createReqVO.getEmail(), createReqVO.getDeptId(), createReqVO.getPostIds());
|
||||
// 插入用户
|
||||
AdminUserDO user = UserConvert.INSTANCE.convert(reqVO);
|
||||
AdminUserDO user = BeanUtils.toBean(createReqVO, AdminUserDO.class);
|
||||
user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
|
||||
user.setPassword(encodePassword(reqVO.getPassword())); // 加密密码
|
||||
user.setPassword(encodePassword(createReqVO.getPassword())); // 加密密码
|
||||
userMapper.insert(user);
|
||||
// 插入关联岗位
|
||||
if (CollectionUtil.isNotEmpty(user.getPostIds())) {
|
||||
@ -102,18 +105,19 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateUser(UserUpdateReqVO reqVO) {
|
||||
public void updateUser(UserSaveReqVO updateReqVO) {
|
||||
updateReqVO.setPassword(null); // 特殊:此处不更新密码
|
||||
// 校验正确性
|
||||
validateUserForCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
|
||||
reqVO.getDeptId(), reqVO.getPostIds());
|
||||
validateUserForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getUsername(),
|
||||
updateReqVO.getMobile(), updateReqVO.getEmail(), updateReqVO.getDeptId(), updateReqVO.getPostIds());
|
||||
// 更新用户
|
||||
AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO);
|
||||
AdminUserDO updateObj = BeanUtils.toBean(updateReqVO, AdminUserDO.class);
|
||||
userMapper.updateById(updateObj);
|
||||
// 更新岗位
|
||||
updateUserPost(reqVO, updateObj);
|
||||
updateUserPost(updateReqVO, updateObj);
|
||||
}
|
||||
|
||||
private void updateUserPost(UserUpdateReqVO reqVO, AdminUserDO updateObj) {
|
||||
private void updateUserPost(UserSaveReqVO reqVO, AdminUserDO updateObj) {
|
||||
Long userId = reqVO.getId();
|
||||
Set<Long> dbPostIds = convertSet(userPostMapper.selectListByUserId(userId), UserPostDO::getPostId);
|
||||
// 计算新增和删除的岗位编号
|
||||
@ -142,7 +146,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
validateEmailUnique(id, reqVO.getEmail());
|
||||
validateMobileUnique(id, reqVO.getMobile());
|
||||
// 执行更新
|
||||
userMapper.updateById(UserConvert.INSTANCE.convert(reqVO).setId(id));
|
||||
userMapper.updateById(BeanUtils.toBean(reqVO, AdminUserDO.class).setId(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -156,7 +160,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String updateUserAvatar(Long id, InputStream avatarFile) throws Exception {
|
||||
public String updateUserAvatar(Long id, InputStream avatarFile) {
|
||||
validateUserExists(id);
|
||||
// 存储文件
|
||||
String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));
|
||||
@ -271,11 +275,6 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserDO> getUserList(UserExportReqVO reqVO) {
|
||||
return userMapper.selectList(reqVO, getDeptCondition(reqVO.getDeptId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserDO> getUserListByNickname(String nickname) {
|
||||
return userMapper.selectListByNickname(nickname);
|
||||
@ -415,7 +414,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
// 判断如果不存在,在进行插入
|
||||
AdminUserDO existUser = userMapper.selectByUsername(importUser.getUsername());
|
||||
if (existUser == null) {
|
||||
userMapper.insert(UserConvert.INSTANCE.convert(importUser)
|
||||
userMapper.insert(BeanUtils.toBean(importUser, AdminUserDO.class)
|
||||
.setPassword(encodePassword(userInitPassword)).setPostIds(new HashSet<>())); // 设置默认密码及空岗位编号数组
|
||||
respVO.getCreateUsernames().add(importUser.getUsername());
|
||||
return;
|
||||
@ -425,7 +424,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
respVO.getFailureUsernames().put(importUser.getUsername(), USER_USERNAME_EXISTS.getMsg());
|
||||
return;
|
||||
}
|
||||
AdminUserDO updateUser = UserConvert.INSTANCE.convert(importUser);
|
||||
AdminUserDO updateUser = BeanUtils.toBean(importUser, AdminUserDO.class);
|
||||
updateUser.setId(existUser.getId());
|
||||
userMapper.updateById(updateUser);
|
||||
respVO.getUpdateUsernames().add(importUser.getUsername());
|
||||
|
@ -10,7 +10,10 @@ import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportExcelVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO;
|
||||
@ -80,11 +83,11 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
||||
@Test
|
||||
public void testCreatUser_success() {
|
||||
// 准备参数
|
||||
UserCreateReqVO reqVO = randomPojo(UserCreateReqVO.class, o -> {
|
||||
UserSaveReqVO reqVO = randomPojo(UserSaveReqVO.class, o -> {
|
||||
o.setSex(RandomUtil.randomEle(SexEnum.values()).getSex());
|
||||
o.setMobile(randomString());
|
||||
o.setPostIds(asSet(1L, 2L));
|
||||
});
|
||||
}).setId(null); // 避免 id 被赋值
|
||||
// mock 账户额度充足
|
||||
TenantDO tenant = randomPojo(TenantDO.class, o -> o.setAccountCount(1));
|
||||
doNothing().when(tenantService).handleTenantInfo(argThat(handler -> {
|
||||
@ -111,7 +114,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
||||
Long userId = userService.createUser(reqVO);
|
||||
// 断言
|
||||
AdminUserDO user = userMapper.selectById(userId);
|
||||
assertPojoEquals(reqVO, user, "password");
|
||||
assertPojoEquals(reqVO, user, "password", "id");
|
||||
assertEquals("yudaoyuanma", user.getPassword());
|
||||
assertEquals(CommonStatusEnum.ENABLE.getStatus(), user.getStatus());
|
||||
// 断言关联岗位
|
||||
@ -123,7 +126,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
||||
@Test
|
||||
public void testCreatUser_max() {
|
||||
// 准备参数
|
||||
UserCreateReqVO reqVO = randomPojo(UserCreateReqVO.class);
|
||||
UserSaveReqVO reqVO = randomPojo(UserSaveReqVO.class);
|
||||
// mock 账户额度不足
|
||||
TenantDO tenant = randomPojo(TenantDO.class, o -> o.setAccountCount(-1));
|
||||
doNothing().when(tenantService).handleTenantInfo(argThat(handler -> {
|
||||
@ -143,7 +146,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
||||
userPostMapper.insert(new UserPostDO().setUserId(dbUser.getId()).setPostId(1L));
|
||||
userPostMapper.insert(new UserPostDO().setUserId(dbUser.getId()).setPostId(2L));
|
||||
// 准备参数
|
||||
UserUpdateReqVO reqVO = randomPojo(UserUpdateReqVO.class, o -> {
|
||||
UserSaveReqVO reqVO = randomPojo(UserSaveReqVO.class, o -> {
|
||||
o.setId(dbUser.getId());
|
||||
o.setSex(RandomUtil.randomEle(SexEnum.values()).getSex());
|
||||
o.setMobile(randomString());
|
||||
@ -167,7 +170,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
||||
userService.updateUser(reqVO);
|
||||
// 断言
|
||||
AdminUserDO user = userMapper.selectById(reqVO.getId());
|
||||
assertPojoEquals(reqVO, user);
|
||||
assertPojoEquals(reqVO, user, "password");
|
||||
// 断言关联岗位
|
||||
List<UserPostDO> userPosts = userPostMapper.selectListByUserId(user.getId());
|
||||
assertEquals(2L, userPosts.get(0).getPostId());
|
||||
@ -355,28 +358,6 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
||||
assertPojoEquals(dbUser, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserList_export() {
|
||||
// mock 数据
|
||||
AdminUserDO dbUser = initGetUserPageData();
|
||||
// 准备参数
|
||||
UserExportReqVO reqVO = new UserExportReqVO();
|
||||
reqVO.setUsername("tu");
|
||||
reqVO.setMobile("1560");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24));
|
||||
reqVO.setDeptId(1L); // 其中,1L 是 2L 的父部门
|
||||
// mock 方法
|
||||
List<DeptDO> deptList = newArrayList(randomPojo(DeptDO.class, o -> o.setId(2L)));
|
||||
when(deptService.getChildDeptList(eq(reqVO.getDeptId()))).thenReturn(deptList);
|
||||
|
||||
// 调用
|
||||
List<AdminUserDO> list = userService.getUserList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbUser, list.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 getUserPage 方法的测试数据
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user