Skip to content

Commit

Permalink
refactor: 优化用户管理相关 API
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Apr 14, 2024
1 parent df59cee commit 5269608
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public class UserQuery implements Serializable {
private static final long serialVersionUID = 1L;

/**
* 用户名
* 关键词
*/
@Schema(description = "用户名", example = "zhangsan")
@Query(columns = {"username", "nickname"}, type = QueryType.LIKE)
private String username;
@Schema(description = "关键词", example = "zhangsan")
@Query(columns = {"username", "nickname", "description"}, type = QueryType.LIKE)
private String description;

/**
* 状态
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

package top.charles7c.continew.admin.system.model.resp;

import java.io.Serial;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;
import top.charles7c.continew.admin.common.enums.DataScopeEnum;
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
import top.charles7c.continew.starter.extension.crud.model.resp.BaseResp;
import top.charles7c.continew.starter.extension.crud.model.resp.BaseDetailResp;

import java.io.Serial;

/**
* 角色信息
Expand All @@ -34,7 +32,7 @@
*/
@Data
@Schema(description = "角色信息")
public class RoleResp extends BaseResp {
public class RoleResp extends BaseDetailResp {

@Serial
private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ public class UserDetailResp extends BaseDetailResp {
private List<Long> roleIds;

/**
* 所属角色
* 角色
*/
@Schema(description = "所属角色", example = "测试人员")
@ExcelProperty(value = "所属角色")
@Schema(description = "角色", example = "测试人员")
@ExcelProperty(value = "角色")
private String roleNames;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

package top.charles7c.continew.admin.system.model.resp;

import cn.crane4j.annotation.AssembleMethod;
import cn.crane4j.annotation.ContainerMethod;
import cn.crane4j.annotation.Mapping;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
import top.charles7c.continew.admin.common.enums.GenderEnum;
import top.charles7c.continew.admin.common.util.helper.LoginHelper;
import top.charles7c.continew.starter.extension.crud.model.resp.BaseResp;
import top.charles7c.continew.admin.system.service.DeptService;
import top.charles7c.continew.starter.extension.crud.model.resp.BaseDetailResp;
import top.charles7c.continew.starter.security.mask.annotation.JsonMask;
import top.charles7c.continew.starter.security.mask.enums.MaskType;

Expand All @@ -36,7 +40,7 @@
*/
@Data
@Schema(description = "用户信息")
public class UserResp extends BaseResp {
public class UserResp extends BaseDetailResp {

@Serial
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -97,6 +101,19 @@ public class UserResp extends BaseResp {
@Schema(description = "描述", example = "张三描述信息")
private String description;

/**
* 部门 ID
*/
@Schema(description = "部门 ID", example = "5")
@AssembleMethod(targetType = DeptService.class, method = @ContainerMethod(bindMethod = "get", resultType = DeptResp.class), props = @Mapping(src = "name", ref = "deptName"))
private Long deptId;

/**
* 所属部门
*/
@Schema(description = "所属部门", example = "测试部")
private String deptName;

@Override
public Boolean getDisabled() {
return this.getIsSystem() || Objects.equals(this.getId(), LoginHelper.getUserId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void update(UserReq req, Long id) {
.getNickname());
Collection<Long> disjunctionRoleIds = CollUtil.disjunction(req.getRoleIds(), userRoleService
.listRoleIdByUserId(id));
CheckUtils.throwIfNotEmpty(disjunctionRoleIds, "[{}] 是系统内置用户,不允许变更所属角色", oldUser.getNickname());
CheckUtils.throwIfNotEmpty(disjunctionRoleIds, "[{}] 是系统内置用户,不允许变更角色", oldUser.getNickname());
}
// 更新信息
super.update(req, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public R<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody UserReq
return R.ok("新增成功", id);
}

@Operation(summary = "重置密码", description = "重置用户登录密码为默认密码")
@Operation(summary = "重置密码", description = "重置用户登录密码")
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@SaCheckPermission("system:user:password:reset")
@PatchMapping("/{id}/password")
Expand Down

0 comments on commit 5269608

Please sign in to comment.