Refactor account management DTOs by removing displayName and role fields from AccountCreateRequest, AccountUpdateRequest, and AccountResponse, and updating related logic in AccountService. Adjust alwaysApply setting in zh.mdc to false.
This commit is contained in:
@@ -8,13 +8,11 @@ public class AccountCreateRequest {
|
||||
@NotBlank
|
||||
@Size(min = 3, max = 64)
|
||||
private String username;
|
||||
@Size(max = 100)
|
||||
private String displayName;
|
||||
private String role; // for ADMIN: SUPER | ADMIN
|
||||
|
||||
private String status = "ENABLED"; // ENABLED | DISABLED
|
||||
@NotBlank
|
||||
@Size(min = 6, max = 128)
|
||||
private String initialPassword;
|
||||
private String password;
|
||||
@Min(0)
|
||||
private Long pointsBalance = 0L; // for AGENT
|
||||
|
||||
@@ -22,14 +20,11 @@ public class AccountCreateRequest {
|
||||
public void setUserType(String userType) { this.userType = userType; }
|
||||
public String getUsername() { return username; }
|
||||
public void setUsername(String username) { this.username = username; }
|
||||
public String getDisplayName() { return displayName; }
|
||||
public void setDisplayName(String displayName) { this.displayName = displayName; }
|
||||
public String getRole() { return role; }
|
||||
public void setRole(String role) { this.role = role; }
|
||||
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
public String getInitialPassword() { return initialPassword; }
|
||||
public void setInitialPassword(String initialPassword) { this.initialPassword = initialPassword; }
|
||||
public String getPassword() { return password; }
|
||||
public void setPassword(String password) { this.password = password; }
|
||||
public Long getPointsBalance() { return pointsBalance; }
|
||||
public void setPointsBalance(Long pointsBalance) { this.pointsBalance = pointsBalance; }
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ public class AccountResponse {
|
||||
private Long id;
|
||||
private String userType;
|
||||
private String username;
|
||||
private String displayName;
|
||||
private String role;
|
||||
|
||||
private String status;
|
||||
private Long pointsBalance;
|
||||
private LocalDateTime createdAt;
|
||||
@@ -19,10 +18,7 @@ public class AccountResponse {
|
||||
public void setUserType(String userType) { this.userType = userType; }
|
||||
public String getUsername() { return username; }
|
||||
public void setUsername(String username) { this.username = username; }
|
||||
public String getDisplayName() { return displayName; }
|
||||
public void setDisplayName(String displayName) { this.displayName = displayName; }
|
||||
public String getRole() { return role; }
|
||||
public void setRole(String role) { this.role = role; }
|
||||
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
public Long getPointsBalance() { return pointsBalance; }
|
||||
|
||||
@@ -3,15 +3,10 @@ package com.gameplatform.server.model.dto.account;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
public class AccountUpdateRequest {
|
||||
@Size(max = 100)
|
||||
private String displayName;
|
||||
private String role; // SUPER | ADMIN (only for ADMIN)
|
||||
|
||||
private String status; // ENABLED | DISABLED
|
||||
|
||||
public String getDisplayName() { return displayName; }
|
||||
public void setDisplayName(String displayName) { this.displayName = displayName; }
|
||||
public String getRole() { return role; }
|
||||
public void setRole(String role) { this.role = role; }
|
||||
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ public class UserAccount {
|
||||
private Long id;
|
||||
private String userType; // ADMIN | AGENT
|
||||
private String username; // 登录名(admin/agent 共用)
|
||||
private String displayName; // 显示名称(agent 可用)
|
||||
|
||||
private String passwordHash; // BCrypt 或 PLAIN:xxx(初始化用)
|
||||
private String role; // 仅 ADMIN 使用:SUPER / ADMIN
|
||||
|
||||
private String status; // ENABLED / DISABLED
|
||||
private Long pointsBalance; // 仅 AGENT 使用
|
||||
private LocalDateTime createdAt;
|
||||
@@ -20,12 +20,10 @@ public class UserAccount {
|
||||
public void setUserType(String userType) { this.userType = userType; }
|
||||
public String getUsername() { return username; }
|
||||
public void setUsername(String username) { this.username = username; }
|
||||
public String getDisplayName() { return displayName; }
|
||||
public void setDisplayName(String displayName) { this.displayName = displayName; }
|
||||
|
||||
public String getPasswordHash() { return passwordHash; }
|
||||
public void setPasswordHash(String passwordHash) { this.passwordHash = passwordHash; }
|
||||
public String getRole() { return role; }
|
||||
public void setRole(String role) { this.role = role; }
|
||||
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
public Long getPointsBalance() { return pointsBalance; }
|
||||
|
||||
@@ -25,14 +25,14 @@ public class AccountService {
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
public Mono<PageResult<AccountResponse>> list(String userType, String status, String role, String keyword,
|
||||
public Mono<PageResult<AccountResponse>> list(String userType, String status, String keyword,
|
||||
Integer page, Integer size) {
|
||||
int p = (page == null || page < 1) ? 1 : page;
|
||||
int s = (size == null || size < 1 || size > 200) ? 20 : size;
|
||||
int offset = (p - 1) * s;
|
||||
return Mono.fromCallable(() -> {
|
||||
long total = mapper.countByFilter(userType, status, role, keyword);
|
||||
List<UserAccount> list = mapper.listByFilter(userType, status, role, keyword, s, offset);
|
||||
long total = mapper.countByFilter(userType, status, null, keyword);
|
||||
List<UserAccount> list = mapper.listByFilter(userType, status, null, keyword, s, offset);
|
||||
List<AccountResponse> items = list.stream().map(this::toResp).collect(Collectors.toList());
|
||||
return new PageResult<>(items, total, p, s);
|
||||
})
|
||||
@@ -54,16 +54,13 @@ public class AccountService {
|
||||
UserAccount acc = new UserAccount();
|
||||
acc.setUserType(type);
|
||||
acc.setUsername(req.getUsername());
|
||||
acc.setDisplayName(req.getDisplayName());
|
||||
acc.setStatus(req.getStatus() == null ? "ENABLED" : req.getStatus());
|
||||
if ("ADMIN".equals(type)) {
|
||||
acc.setRole(req.getRole() == null ? "ADMIN" : req.getRole());
|
||||
acc.setPointsBalance(0L);
|
||||
} else {
|
||||
acc.setRole(null);
|
||||
acc.setPointsBalance(req.getPointsBalance() == null ? 0L : req.getPointsBalance());
|
||||
}
|
||||
acc.setPasswordHash(passwordEncoder.encode(req.getInitialPassword()));
|
||||
acc.setPasswordHash(passwordEncoder.encode(req.getPassword()));
|
||||
mapper.insert(acc);
|
||||
return toResp(acc);
|
||||
})
|
||||
@@ -83,11 +80,7 @@ public class AccountService {
|
||||
if (db == null) return null;
|
||||
UserAccount patch = new UserAccount();
|
||||
patch.setId(id);
|
||||
patch.setDisplayName(req.getDisplayName());
|
||||
// Only ADMIN account may set role; AGENT's role must remain null
|
||||
if ("ADMIN".equalsIgnoreCase(db.getUserType())) {
|
||||
patch.setRole(req.getRole());
|
||||
}
|
||||
|
||||
patch.setStatus(req.getStatus());
|
||||
mapper.update(patch);
|
||||
return mapper.findById(id);
|
||||
@@ -119,8 +112,7 @@ public class AccountService {
|
||||
r.setId(a.getId());
|
||||
r.setUserType(a.getUserType());
|
||||
r.setUsername(a.getUsername());
|
||||
r.setDisplayName(a.getDisplayName());
|
||||
r.setRole(a.getRole());
|
||||
|
||||
r.setStatus(a.getStatus());
|
||||
r.setPointsBalance(a.getPointsBalance());
|
||||
r.setCreatedAt(a.getCreatedAt());
|
||||
|
||||
Reference in New Issue
Block a user