|
|
@@ -4,27 +4,26 @@ import cn.reghao.bnt.web.admin.model.dto.AccountPassword;
|
|
|
import cn.reghao.bnt.web.admin.model.dto.AccountRole;
|
|
|
import cn.reghao.bnt.web.admin.model.dto.CreateAccountDto;
|
|
|
import cn.reghao.bnt.web.admin.model.po.Role;
|
|
|
-import cn.reghao.bnt.web.admin.model.po.User;
|
|
|
import cn.reghao.bnt.web.admin.model.vo.RoleVO;
|
|
|
import cn.reghao.bnt.web.admin.model.vo.UserSession;
|
|
|
import cn.reghao.bnt.web.admin.model.vo.UserVO;
|
|
|
import cn.reghao.bnt.web.admin.service.AccountService;
|
|
|
import cn.reghao.bnt.web.admin.service.AccountSessionService;
|
|
|
+import cn.reghao.bnt.web.admin.model.po.User;
|
|
|
import cn.reghao.bnt.web.admin.service.RoleService;
|
|
|
+import cn.reghao.jutil.jdk.web.db.PageList;
|
|
|
import cn.reghao.jutil.jdk.web.result.Result;
|
|
|
import cn.reghao.jutil.jdk.web.result.ResultStatus;
|
|
|
import cn.reghao.jutil.web.WebResult;
|
|
|
-import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.http.MediaType;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.ui.Model;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -38,7 +37,7 @@ public class UserController {
|
|
|
private final AccountService accountService;
|
|
|
private final RoleService roleService;
|
|
|
private final AccountSessionService accountSessionService;
|
|
|
- private int pageSize = 100;
|
|
|
+ private int pageSize = 10;
|
|
|
|
|
|
public UserController(AccountService accountService, RoleService roleService,
|
|
|
AccountSessionService accountSessionService) {
|
|
|
@@ -48,8 +47,8 @@ public class UserController {
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "帐号列表页面", description = "N")
|
|
|
- @GetMapping(value = "")
|
|
|
- public String userPage(Model model) {
|
|
|
+ @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String userPage() {
|
|
|
PageRequest pageRequest = PageRequest.of(0, pageSize);
|
|
|
Page<UserVO> page = accountService.getUserVOByPage(pageRequest);
|
|
|
page.getContent().forEach(userVO -> {
|
|
|
@@ -62,29 +61,28 @@ public class UserController {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- return WebResult.success(page.getContent());
|
|
|
+ PageList<UserVO> pageList = getPageList(page);
|
|
|
+ return WebResult.success(pageList);
|
|
|
}
|
|
|
|
|
|
- @Operation(summary = "新增帐号页面", description = "N")
|
|
|
- @GetMapping("/add")
|
|
|
- public String addUserPage(Model model) {
|
|
|
- List<RoleVO> allRoles = roleService.getAllRoles();
|
|
|
- model.addAttribute("list", allRoles);
|
|
|
- return "/admin/rbac/user/useradd";
|
|
|
+ private PageList<UserVO> getPageList(Page<UserVO> page) {
|
|
|
+ int pageNumber = page.getNumber() + 1;
|
|
|
+ int pageSize = page.getSize();
|
|
|
+ long total = page.getTotalElements();
|
|
|
+ List<UserVO> list = page.getContent();
|
|
|
+ return PageList.pageList(pageNumber, pageSize, (int) total, list);
|
|
|
}
|
|
|
|
|
|
- @Operation(summary = "重置帐号密码页面", description = "N")
|
|
|
- @GetMapping("/reset_passwd")
|
|
|
- public String updatePasswordPage(@RequestParam("id") Integer userId, Model model) {
|
|
|
- User user = accountService.getById(userId);
|
|
|
- model.addAttribute("username", user.getUsername());
|
|
|
- model.addAttribute("userId", userId);
|
|
|
- return "/admin/rbac/user/resetpasswd";
|
|
|
+ @Operation(summary = "新增帐号页面", description = "N")
|
|
|
+ @GetMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String addUserPage() {
|
|
|
+ List<String> allRoles = roleService.getAllRoles().stream().map(RoleVO::getName).collect(Collectors.toList());
|
|
|
+ return WebResult.success(allRoles);
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "用户会话列表页面", description = "N")
|
|
|
@GetMapping("/session")
|
|
|
- public String userSessionPage(@RequestParam("id") Integer userId, Model model) {
|
|
|
+ public String userSessionPage(@RequestParam("id") Integer userId) {
|
|
|
User user = accountService.getById(userId);
|
|
|
List<UserSession> userSessionList = accountSessionService.getUserSession(userId);
|
|
|
return WebResult.success(userSessionList);
|
|
|
@@ -92,18 +90,28 @@ public class UserController {
|
|
|
|
|
|
@Operation(summary = "帐号角色分配页面", description = "N")
|
|
|
@GetMapping("/role")
|
|
|
- public String updateRolePage(@RequestParam("id") Integer userId, Model model) {
|
|
|
- User user = accountService.getById(userId);
|
|
|
- List<RoleVO> allRoles = roleService.getAllRoles();
|
|
|
- List<Integer> userRoleIds = roleService.getRolesByUser(userId).stream()
|
|
|
- .map(Role::getId)
|
|
|
+ public String updateRolePage(@RequestParam("userId") Integer userId) {
|
|
|
+ List<String> allRoles = roleService.getAllRoles().stream()
|
|
|
+ .map(RoleVO::getName)
|
|
|
.collect(Collectors.toList());
|
|
|
+ List<String> userRoles = roleService.getRolesByUser(userId).stream()
|
|
|
+ .map(role -> role.getName().replace("ROLE_", "").toLowerCase(Locale.ROOT))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("allRoles", allRoles);
|
|
|
+ map.put("userRoles", userRoles);
|
|
|
+ return WebResult.success(map);
|
|
|
+ }
|
|
|
|
|
|
- model.addAttribute("username", user.getUsername());
|
|
|
- model.addAttribute("userId", userId);
|
|
|
- model.addAttribute("allRoles", allRoles);
|
|
|
- model.addAttribute("userRoleIds", userRoleIds);
|
|
|
- return "/admin/rbac/user/update_role";
|
|
|
+ @Operation(summary = "分配帐号角色", description = "N")
|
|
|
+ @PostMapping(value = "/role", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String updateRole(@Validated AccountRole accountRole) {
|
|
|
+ Result result = accountService.updateAccountRole(accountRole);
|
|
|
+ if (result.getCode() == ResultStatus.SUCCESS.getCode()) {
|
|
|
+ // 登出当前会话
|
|
|
+ accountSessionService.deactivateUserSession(accountRole.getUserId());
|
|
|
+ }
|
|
|
+ return WebResult.result(result);
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "创建帐号", description = "N")
|
|
|
@@ -134,15 +142,4 @@ public class UserController {
|
|
|
accountSessionService.deactivateUserSession(userId);
|
|
|
return WebResult.success();
|
|
|
}
|
|
|
-
|
|
|
- @Operation(summary = "分配帐号角色", description = "N")
|
|
|
- @PostMapping(value = "/role", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public String updateRole(@Validated AccountRole accountRole) {
|
|
|
- Result result = accountService.updateAccountRole(accountRole);
|
|
|
- if (result.getCode() == ResultStatus.SUCCESS.getCode()) {
|
|
|
- // 登出当前会话
|
|
|
- accountSessionService.deactivateUserSession(accountRole.getUserId());
|
|
|
- }
|
|
|
- return WebResult.result(result);
|
|
|
- }
|
|
|
}
|