OCT 1. 重构分页查询接口返回/请求数据结构

This commit is contained in:
黄昕 2024-02-02 15:53:53 +08:00
parent f92beb521a
commit 39cfe6d46d
5 changed files with 66 additions and 51 deletions

View File

@ -4,6 +4,7 @@ import com.cmhi.cf.common.ErrorCode;
import com.cmhi.cf.misc.HelperUtils;
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.BaseRespStatus;
import com.cmhi.cf.restapi.pojo.dto.OperationLogDetailsReq;
import com.cmhi.cf.restapi.pojo.dto.OperationLogReq;
@ -12,7 +13,6 @@ import com.cmhi.cf.restapi.pojo.po.OperationLogDetails;
import com.cmhi.cf.restapi.pojo.po.OperationLogSummary;
import com.cmhi.cf.restapi.pojo.po.PageResults;
import com.cmhi.cf.restapi.pojo.vo.OperationLogDetailsResp;
import com.cmhi.cf.restapi.pojo.vo.OperationLogSummaryResp;
import com.cmhi.cf.restapi.pojo.vo.ProtocolResp;
import com.cmhi.cf.service.OperationLogService;
import com.cmhi.cf.validation.group.ValidGroups;
@ -49,11 +49,11 @@ public class OperationLogApi {
PageResults<OperationLogSummary> ret = operationLogService.getOperationLogSummary(req.getPageNumber(), req.getPageSize(),
req.getTotalSize(), req.getUserName());
return ProtocolResp.result(OperationLogSummaryResp.<OperationLogSummary>builder()
.operationLog(ret)
.status(ErrorCode.ERR_OK.getCode())
.message(new String[] {ErrorCode.ERR_OK.getDescription()})
.build());
return ProtocolResp.result(BasePageResultResp.<OperationLogSummary>builder()
.items(ret)
.status(ErrorCode.ERR_OK.getCode())
.message(new String[] {ErrorCode.ERR_OK.getDescription()})
.build());
} else {
return ProtocolResp.result(ErrorCode.ERR_PARAMEXCEPTION,
ErrorCode.ERR_PARAMEXCEPTION.getHttpCode(),

View File

@ -0,0 +1,22 @@
package com.cmhi.cf.restapi.pojo.base;
import com.cmhi.cf.restapi.pojo.po.PageResults;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({"items", "status", "message"})
public class BasePageResultResp<T> extends BaseRespStatus {
private PageResults<T> items;
@Builder
public BasePageResultResp(PageResults<T> items, Integer status, String[] message) {
super(status, message);
this.items = items;
}
}

View File

@ -0,0 +1,34 @@
package com.cmhi.cf.restapi.pojo.base;
import com.cmhi.cf.validation.group.ValidGroups;
import com.cmhi.cf.validation.valids.ValidPageSize;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(name = "BasePagedReq", description = "分页请求基础参数")
public class BasePagedReq {
@Schema(description = "分页号最小值为1")
@NotNull(message = "pageNumber 必须指定分页配置", groups = ValidGroups.BasePagedReqValid.class)
@Min(value = 1, message = "pageNumber 最小值为1", groups = ValidGroups.BasePagedReqValid.class)
private Long pageNumber;
@Schema(description = "分页大小最小值为5 最大值100 取值必须为5的整数倍")
@NotNull(message = "pageSize 必须指定分页配置", groups = ValidGroups.BasePagedReqValid.class)
@ValidPageSize(message = "pageSize 取值必须为 5 的整数倍", groups = ValidGroups.BasePagedReqValid.class)
@Min(value = 5, message = "pageSize 最小值为5", groups = ValidGroups.BasePagedReqValid.class)
@Max(value = 100, message = "pageSize 最大值为100", groups = ValidGroups.BasePagedReqValid.class)
private Long pageSize;
@Schema(description = "数据总数未知时可以为空或者小于0 存在时可以加快后端数据库查询速度")
private Long totalSize;
}

View File

@ -1,41 +1,22 @@
package com.cmhi.cf.restapi.pojo.dto;
import com.cmhi.cf.validation.group.ValidGroups;
import com.cmhi.cf.validation.valids.ValidPageSize;
import com.cmhi.cf.restapi.pojo.base.BasePagedReq;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(name = "OperationLogReq", description = "操作日志摘要信息请求参数")
public class OperationLogReq {
@Schema(description = "分页号最小值为1")
@NotNull(message = "pageNumber 必须指定分页配置", groups = ValidGroups.OperationLogReqValid.class)
@Min(value = 1, message = "pageNumber 最小值为1", groups = ValidGroups.OperationLogReqValid.class)
private Long pageNumber;
@Schema(description = "分页大小最小值为5 最大值100 取值必须为5的整数倍")
@NotNull(message = "pageSize 必须指定分页配置", groups = ValidGroups.OperationLogReqValid.class)
@ValidPageSize(message = "pageSize 取值必须为 5 的整数倍", groups = ValidGroups.OperationLogReqValid.class)
@Min(value = 5, message = "pageSize 最小值为5", groups = ValidGroups.OperationLogReqValid.class)
@Max(value = 100, message = "pageSize 最大值为100", groups = ValidGroups.OperationLogReqValid.class)
private Long pageSize;
@Schema(description = "数据总数未知时可以为空或者小于0 存在时可以加快后端数据库查询速度")
private Long totalSize;
public class OperationLogReq extends BasePagedReq {
@Schema(description = "用户名, 需要查询指定用户的操作日志时指定用户, 支持同时指定多个用户, 分页查询过程中该参数不能改变")
private List<String> userName;
}

View File

@ -1,22 +0,0 @@
package com.cmhi.cf.restapi.pojo.vo;
import com.cmhi.cf.restapi.pojo.base.BaseRespStatus;
import com.cmhi.cf.restapi.pojo.po.PageResults;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({"operationLog", "status", "message"})
public class OperationLogSummaryResp<T> extends BaseRespStatus {
private PageResults<T> operationLog;
@Builder
public OperationLogSummaryResp(PageResults<T> operationLog, Integer status, String[] message) {
super(status, message);
this.operationLog = operationLog;
}
}