1
0

feat(web): 调整界面类

This commit is contained in:
2024-11-20 18:32:59 +08:00
parent 9f0c122bae
commit 5ce66e1470
2 changed files with 57 additions and 58 deletions

View File

@@ -1,9 +1,11 @@
package com.eshore.gringotts.web.domain.user.controller; package com.eshore.gringotts.web.domain.user.controller;
import cn.hutool.core.util.ObjectUtil;
import com.eshore.gringotts.web.configuration.amis.AmisListResponse; import com.eshore.gringotts.web.configuration.amis.AmisListResponse;
import com.eshore.gringotts.web.configuration.amis.AmisResponse; import com.eshore.gringotts.web.configuration.amis.AmisResponse;
import com.eshore.gringotts.web.domain.user.entity.User; import com.eshore.gringotts.web.domain.user.entity.User;
import com.eshore.gringotts.web.domain.user.service.UserService; import com.eshore.gringotts.web.domain.user.service.UserService;
import java.time.LocalDateTime;
import lombok.Data; import lombok.Data;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -33,12 +35,12 @@ public class UserManagementController {
@GetMapping("/list") @GetMapping("/list")
public AmisListResponse list() { public AmisListResponse list() {
return AmisListResponse.responseListData(userService.list()); return AmisListResponse.responseListData(userService.list().collect(UserListItem::new));
} }
@GetMapping("/detail/{username}") @GetMapping("/detail/{username}")
public AmisResponse<UserService.UserDetail> detail(@PathVariable String username) { public AmisResponse<UserDetail> detail(@PathVariable String username) {
return AmisResponse.responseSuccess(userService.detail(username)); return AmisResponse.responseSuccess(new UserDetail(userService.detail(username)));
} }
@PostMapping("/register") @PostMapping("/register")
@@ -83,4 +85,52 @@ public class UserManagementController {
private String password; private String password;
private User.Role role; private User.Role role;
} }
@Data
public static final class UserListItem {
private Long id;
private String username;
private User.Role role;
private User.State state;
private LocalDateTime lastLoginTime;
private LocalDateTime createdTime;
public UserListItem(User user) {
this.id = user.getId();
this.username = user.getUsername();
this.role = user.getRole();
this.state = user.getState();
this.lastLoginTime = user.getLastLoginTime();
this.createdTime = user.getCreatedTime();
}
}
@Data
public static final class UserDetail {
private String username;
private User.Role role;
private User.State state;
private LocalDateTime lastLoginTime;
private LocalDateTime createdTime;
private String createdUsername;
private LocalDateTime modifiedTime;
private String modifiedUsername;
private LocalDateTime checkedTime;
private String checkedUsername;
public UserDetail(User user) {
this.username = user.getUsername();
this.role = user.getRole();
this.state = user.getState();
this.lastLoginTime = user.getLastLoginTime();
this.createdTime = user.getCreatedTime();
this.createdUsername = user.getCreatedUser().getUsername();
this.modifiedTime = user.getModifiedTime();
this.modifiedUsername = user.getModifiedUser().getUsername();
if (ObjectUtil.isNotNull(user.getCheckedUser())) {
this.checkedTime = user.getCheckedTime();
this.checkedUsername = user.getCheckedUser().getUsername();
}
}
}
} }

View File

@@ -184,10 +184,8 @@ public class UserService {
userRepository.save(user); userRepository.save(user);
} }
public ImmutableList<UserListItem> list() { public ImmutableList<User> list() {
List<User> users = userRepository.findAll(); return Lists.immutable.ofAll(userRepository.findAll());
return Lists.immutable.ofAll(users)
.collect(UserListItem::new);
} }
@Transactional @Transactional
@@ -203,9 +201,8 @@ public class UserService {
} }
} }
public UserDetail detail(String username) { public User detail(String username) {
User user = userRepository.findByUsername(username).orElseThrow(UserNotFoundException::new); return userRepository.findByUsername(username).orElseThrow(UserNotFoundException::new);
return new UserDetail(user);
} }
public static class UserNotFoundException extends RuntimeException { public static class UserNotFoundException extends RuntimeException {
@@ -272,52 +269,4 @@ public class UserService {
this.token = token.getTokenValue(); this.token = token.getTokenValue();
} }
} }
@Data
public static class UserListItem {
private Long id;
private String username;
private User.Role role;
private User.State state;
private LocalDateTime lastLoginTime;
private LocalDateTime createdTime;
public UserListItem(User user) {
this.id = user.getId();
this.username = user.getUsername();
this.role = user.getRole();
this.state = user.getState();
this.lastLoginTime = user.getLastLoginTime();
this.createdTime = user.getCreatedTime();
}
}
@Data
public static class UserDetail {
private String username;
private User.Role role;
private User.State state;
private LocalDateTime lastLoginTime;
private LocalDateTime createdTime;
private String createdUsername;
private LocalDateTime modifiedTime;
private String modifiedUsername;
private LocalDateTime checkedTime;
private String checkedUsername;
public UserDetail(User user) {
this.username = user.getUsername();
this.role = user.getRole();
this.state = user.getState();
this.lastLoginTime = user.getLastLoginTime();
this.createdTime = user.getCreatedTime();
this.createdUsername = user.getCreatedUser().getUsername();
this.modifiedTime = user.getModifiedTime();
this.modifiedUsername = user.getModifiedUser().getUsername();
if (ObjectUtil.isNotNull(user.getCheckedUser())) {
this.checkedTime = user.getCheckedTime();
this.checkedUsername = user.getCheckedUser().getUsername();
}
}
}
} }