|
|
@@ -5,18 +5,20 @@ import cn.reghao.devops.manager.account.db.query.UserQuery;
|
|
|
import cn.reghao.devops.manager.account.model.po.Role;
|
|
|
import cn.reghao.devops.manager.account.model.po.User;
|
|
|
import cn.reghao.devops.manager.account.model.vo.UserVO;
|
|
|
+import cn.reghao.devops.manager.account.service.AccountSessionService;
|
|
|
import cn.reghao.devops.manager.account.service.UserContext;
|
|
|
import cn.reghao.devops.manager.util.db.PageSort;
|
|
|
+import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.security.core.session.SessionRegistry;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -30,25 +32,17 @@ import java.util.stream.Collectors;
|
|
|
public class UserPageController {
|
|
|
private final UserQuery userQuery;
|
|
|
private final RoleQuery roleQuery;
|
|
|
- private SessionRegistry sessionRegistry;
|
|
|
+ private final AccountSessionService accountSessionService;
|
|
|
|
|
|
- public UserPageController(UserQuery userQuery, RoleQuery roleQuery, SessionRegistry sessionRegistry) {
|
|
|
+ public UserPageController(UserQuery userQuery, RoleQuery roleQuery, AccountSessionService accountSessionService) {
|
|
|
this.userQuery = userQuery;
|
|
|
this.roleQuery = roleQuery;
|
|
|
- this.sessionRegistry = sessionRegistry;
|
|
|
+ this.accountSessionService = accountSessionService;
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "用户列表页面")
|
|
|
@GetMapping
|
|
|
public String userPage(@RequestParam(value = "screenName", required = false) String screenName, Model model) {
|
|
|
- List<Object> users = sessionRegistry.getAllPrincipals();
|
|
|
- List<User> userList = new ArrayList<>();
|
|
|
- for (Object obj : users) {
|
|
|
- if (obj instanceof User) {
|
|
|
- userList.add((User) obj);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
Page<UserVO> page;
|
|
|
if (screenName != null) {
|
|
|
List<UserVO> list = userQuery.getByMatchScreenName(screenName);
|
|
|
@@ -58,6 +52,15 @@ public class UserPageController {
|
|
|
page = userQuery.getUserVOByPage(pageRequest);
|
|
|
}
|
|
|
|
|
|
+ Map<Integer, LocalDateTime> map = accountSessionService.getLastRequest();
|
|
|
+ page.getContent().forEach(userVO -> {
|
|
|
+ int userId = userVO.getUserId();
|
|
|
+ LocalDateTime lastAccess = map.get(userId);
|
|
|
+ if (lastAccess != null) {
|
|
|
+ userVO.setLastAccess(DateTimeConverter.format(lastAccess));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
model.addAttribute("page", page);
|
|
|
model.addAttribute("list", page.getContent());
|
|
|
return "/rbac/user/index";
|