diff --git a/src/main/java/com/cmhi/cf/authentication/pojo/vo/UserListPagedResp.java b/src/main/java/com/cmhi/cf/authentication/pojo/vo/UserListPagedResp.java new file mode 100644 index 0000000..3a56f47 --- /dev/null +++ b/src/main/java/com/cmhi/cf/authentication/pojo/vo/UserListPagedResp.java @@ -0,0 +1,14 @@ +package com.cmhi.cf.authentication.pojo.vo; + +import com.cmhi.cf.restapi.pojo.base.BaseRespStatus; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"operationLog", "status", "message"}) +public class UserListPagedResp extends BaseRespStatus { +} diff --git a/src/main/java/com/cmhi/cf/controller/UserManagerApi.java b/src/main/java/com/cmhi/cf/controller/UserManagerApi.java index 6e490cb..40f3b8d 100644 --- a/src/main/java/com/cmhi/cf/controller/UserManagerApi.java +++ b/src/main/java/com/cmhi/cf/controller/UserManagerApi.java @@ -10,8 +10,11 @@ import com.cmhi.cf.misc.HelperUtils; import com.cmhi.cf.restapi.annotation.DecryptionProtocol; import com.cmhi.cf.restapi.annotation.EncryptionProtocol; import com.cmhi.cf.restapi.annotation.OperationLogAnnotation; +import com.cmhi.cf.restapi.pojo.base.BasePageResultResp; +import com.cmhi.cf.restapi.pojo.base.BasePagedReq; import com.cmhi.cf.restapi.pojo.base.BaseRespStatus; import com.cmhi.cf.restapi.pojo.dto.ProtocolReq; +import com.cmhi.cf.restapi.pojo.po.PageResults; import com.cmhi.cf.restapi.pojo.vo.ProtocolResp; import com.cmhi.cf.validation.group.ValidGroups; import io.swagger.v3.oas.annotations.tags.Tag; @@ -42,8 +45,7 @@ public class UserManagerApi { @DecryptionProtocol @OperationLogAnnotation(OperationModule = "用户管理模块", OperationType = "读取", OperationDesc = "获取用户信息") public ProtocolResp getUserInfoById(@RequestBody ProtocolReq mr) { - List validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, - ValidGroups.OperationLogReqValid.class); + List validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.OperationLogReqValid.class); // 如果校验通过,validate为空;否则,validate包含未校验通过项 if (validate.isEmpty()) { UserInfo ui = userService.getUserInfoByUid(mr.getMsgContent().getUid()); @@ -58,12 +60,33 @@ public class UserManagerApi { } } + @PostMapping("/userList") + @ResponseBody + @EncryptionProtocol + @DecryptionProtocol + @OperationLogAnnotation(OperationModule = "用户管理模块", OperationType = "读取", OperationDesc = "获取用户列表") + public ProtocolResp getAllUserInfoPaged(@RequestBody ProtocolReq mr) { + List validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.BasePagedReqValid.class); + // 如果校验通过,validate为空;否则,validate包含未校验通过项 + if (validate.isEmpty()) { + BasePagedReq req = mr.getMsgContent(); + PageResults ui = userService.getAllUserInfo(req.getPageNumber(), req.getPageSize(), req.getTotalSize()); + + return ProtocolResp.result(BasePageResultResp.builder() + .items(ui) + .status(ErrorCode.ERR_OK.getCode()) + .message(new String[] {ErrorCode.ERR_OK.getDescription()}) + .build()); + } else { + return ProtocolResp.result(ErrorCode.ERR_PARAMEXCEPTION, ErrorCode.ERR_PARAMEXCEPTION.getHttpCode(), + validate.toArray(new String[0])); + } + } + @GetMapping("/userInfo") @ResponseBody @EncryptionProtocol - @OperationLogAnnotation(OperationModule = "用户管理模块", - OperationType = "读取", - OperationDesc = "获取当前用户信息") + @OperationLogAnnotation(OperationModule = "用户管理模块", OperationType = "读取", OperationDesc = "获取当前用户信息") public ProtocolResp getCurrentUserInfo() { return ProtocolResp.result(GetUserInfoResp.builder() .userInfo(userService.getCurrentUserInfo()) @@ -78,8 +101,7 @@ public class UserManagerApi { @DecryptionProtocol @OperationLogAnnotation(OperationModule = "用户管理模块", OperationType = "创建", OperationDesc = "创建新用户") public ProtocolResp createNewUser(@RequestBody ProtocolReq mr) { - List validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, - ValidGroups.UserReqValid.class); + List validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.UserReqValid.class); // 如果校验通过,validate为空;否则,validate包含未校验通过项 if (validate.isEmpty()) { RegisterUserReq ui = mr.getMsgContent(); @@ -106,8 +128,7 @@ public class UserManagerApi { @DecryptionProtocol @OperationLogAnnotation(OperationModule = "用户管理模块", OperationType = "删除", OperationDesc = "删除用户") public ProtocolResp removeUser(@RequestBody ProtocolReq mr) { - List validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, - ValidGroups.UserIdReqValid.class); + List validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.UserIdReqValid.class); // 如果校验通过,validate为空;否则,validate包含未校验通过项 if (validate.isEmpty()) { UserIdReq ui = mr.getMsgContent(); diff --git a/src/main/java/com/cmhi/cf/database/authentication/service/UserService.java b/src/main/java/com/cmhi/cf/database/authentication/service/UserService.java index 0787fc4..a2bd2ac 100644 --- a/src/main/java/com/cmhi/cf/database/authentication/service/UserService.java +++ b/src/main/java/com/cmhi/cf/database/authentication/service/UserService.java @@ -6,6 +6,7 @@ import com.cmhi.cf.authentication.pojo.po.ResourceInfo; import com.cmhi.cf.authentication.pojo.po.UserInfo; import com.cmhi.cf.common.ErrorCode; import com.cmhi.cf.database.authentication.entity.User; +import com.cmhi.cf.restapi.pojo.po.PageResults; import com.mybatisflex.core.service.IService; import java.util.List; @@ -31,6 +32,8 @@ public interface UserService extends IService { UserInfo getCurrentUserInfo(); + PageResults getAllUserInfo(Long pageNumber, Long pageSize, Long totalSize); + List getCurrentUserResourcePerm(); List getUserResourcePerm(Long userId); diff --git a/src/main/java/com/cmhi/cf/database/authentication/service/impl/UserServiceImpl.java b/src/main/java/com/cmhi/cf/database/authentication/service/impl/UserServiceImpl.java index 16be343..3b908d1 100644 --- a/src/main/java/com/cmhi/cf/database/authentication/service/impl/UserServiceImpl.java +++ b/src/main/java/com/cmhi/cf/database/authentication/service/impl/UserServiceImpl.java @@ -21,6 +21,8 @@ import com.cmhi.cf.database.authentication.service.UserService; import com.cmhi.cf.exception.CommonErrorCodeException; import com.cmhi.cf.misc.HelperUtils; import com.cmhi.cf.restapi.misc.ApiContextUtils; +import com.cmhi.cf.restapi.pojo.po.PageResults; +import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.Db; import com.mybatisflex.spring.service.impl.ServiceImpl; @@ -102,7 +104,7 @@ public class UserServiceImpl extends ServiceImpl implements Us } // 低优先级用户不能获取高优先级用户信息 - if (verifyCurrentHasPermission(user)) { + if (verifyCurrentExceedPermission(user)) { throw new CommonErrorCodeException(ErrorCode.ERR_PERMISSION); } @@ -122,7 +124,7 @@ public class UserServiceImpl extends ServiceImpl implements Us } // 低优先级用户不能获取高优先级用户信息 - if (verifyCurrentHasPermission(user)) { + if (verifyCurrentExceedPermission(user)) { throw new CommonErrorCodeException(ErrorCode.ERR_PERMISSION); } @@ -158,6 +160,33 @@ public class UserServiceImpl extends ServiceImpl implements Us user.getUsername()).roleId(user.getRoleId()).userStatus(user.getUserCredential().getState()).build(); } + @Override + public PageResults getAllUserInfo(Long pageNumber, Long pageSize, Long totalSize) { + QueryWrapper wrapper = QueryWrapper.create().from(USER).select(); + List ui = new ArrayList<>(); + + Page user = userMapper.paginateWithRelations(pageNumber, pageSize, totalSize, wrapper); + + user.getRecords().forEach(k -> { + ui.add(UserInfo.builder() + .uid(k.getUid()) + .createdTime(k.getCreatedTime()) + .gender(k.getGender()) + .username(k.getUsername()) + .roleId(k.getRoleId()) + .userStatus(k.getUserCredential().getState()) + .build()); + }); + + return PageResults.builder() + .items(ui) + .pageNumber(user.getPageNumber()) + .pageSize(user.getPageSize()) + .totalPage(user.getTotalPage()) + .totalRow(user.getTotalRow()) + .build(); + } + @Override public List getCurrentUserResourcePerm() { List res; @@ -208,7 +237,7 @@ public class UserServiceImpl extends ServiceImpl implements Us } // 低优先级用户不能获取高优先级用户信息 - if (verifyCurrentHasPermission(user)) { + if (verifyCurrentExceedPermission(user)) { throw new CommonErrorCodeException(ErrorCode.ERR_PERMISSION); } @@ -396,7 +425,7 @@ public class UserServiceImpl extends ServiceImpl implements Us }); } - private boolean verifyCurrentHasPermission(User accessUser) { + private boolean verifyCurrentExceedPermission(User accessUser) { String loginUsername = ApiContextUtils.get().getUsername(); if (!HelperUtils.stringNotEmptyOrNull(loginUsername)) { diff --git a/src/main/java/com/cmhi/cf/validation/group/ValidGroups.java b/src/main/java/com/cmhi/cf/validation/group/ValidGroups.java index 86a4861..1d4c1fd 100644 --- a/src/main/java/com/cmhi/cf/validation/group/ValidGroups.java +++ b/src/main/java/com/cmhi/cf/validation/group/ValidGroups.java @@ -8,6 +8,9 @@ public interface ValidGroups { interface BaseProtocolValid extends ProtocolCommonValid { } + interface BasePagedReqValid extends BaseProtocolValid { + } + interface LoginReqValid extends BaseProtocolValid { } diff --git a/src/main/resources/rbac/data.sql b/src/main/resources/rbac/data.sql index a26080d..629acd2 100644 --- a/src/main/resources/rbac/data.sql +++ b/src/main/resources/rbac/data.sql @@ -37,6 +37,7 @@ INSERT IGNORE INTO rbac_resource_data VALUES (300, '58e36be5-f725-4d98-bd7d-8f73 INSERT IGNORE INTO rbac_resource_data VALUES (301, 'fa2b3740-8672-49d3-9792-25976b767ade', '/api/user/userInfo', '获取用户信息', 'POST', 0); INSERT IGNORE INTO rbac_resource_data VALUES (302, '221c8d8e-c47a-4200-88a8-34d374a76d01', '/api/user/register', '注册新用户', 'PUT', 0); INSERT IGNORE INTO rbac_resource_data VALUES (303, '8adf6875-2be4-459e-9c1d-3bb87114cb08', '/api/user/remove', '删除用户', 'DELETE', 0); +INSERT IGNORE INTO rbac_resource_data VALUES (304, '4c6c859b-2625-45eb-83b8-1426ff96dbe6', '/api/user/userList', '分页获取当前所有用户', 'POST', 0); INSERT IGNORE INTO rbac_resource_data VALUES (400, '8ac928d8-5a6a-47c7-8697-0fb9ebd7249d', '/api/dict/allDictionary', '获取当前字典列表', 'GET', 0); INSERT IGNORE INTO rbac_resource_data VALUES (401, '9ecf1662-f891-4829-8d3e-81c42bf22e2a', '/api/dict/allDictionaryContent', '获取当前字典详细内容', 'GET', 0); -- ---------------------------- @@ -56,6 +57,7 @@ INSERT IGNORE INTO rbac_role_resource VALUES (1, 300, 1); INSERT IGNORE INTO rbac_role_resource VALUES (1, 301, 1); INSERT IGNORE INTO rbac_role_resource VALUES (1, 302, 1); INSERT IGNORE INTO rbac_role_resource VALUES (1, 303, 1); +INSERT IGNORE INTO rbac_role_resource VALUES (1, 304, 1); INSERT IGNORE INTO rbac_role_resource VALUES (1, 400, 1); INSERT IGNORE INTO rbac_role_resource VALUES (1, 401, 1);