Browse Source

新增排序字段

shuiqilin
lihao 1 year ago
parent
commit
1d0f994ec6

+ 15
- 1
src/main/java/com/qtzl/alterSales/manager/handler/refund/RefundStatisticsPageHandler.java View File

import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
if (ObjectUtils.isEmpty(type)) { if (ObjectUtils.isEmpty(type)) {
throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException(String.format("操作失败,操作范围[%s]不合法", exportOrQuery)); throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException(String.format("操作失败,操作范围[%s]不合法", exportOrQuery));
} }
// 排序参数 是否合法
String sort = request.getSort();
if(!ObjectUtils.isEmpty(sort)){
try {
Sort.Direction.fromString(sort);
}catch (IllegalArgumentException e){
throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException(String.format("操作失败,排序值[%s]不合法", sort));
}
}
boolean is = FunctionalityConfigExportOrQuery.QUERY.equals(type); boolean is = FunctionalityConfigExportOrQuery.QUERY.equals(type);
// 2 根据操作类型 决定数据大小 // 2 根据操作类型 决定数据大小
if (is) { if (is) {
* @return 整合数据 * @return 整合数据
*/ */
public RefundStatsPageResponse toResponse(RefundStatisticsPageRequest request) throws ServiceHandleException { public RefundStatsPageResponse toResponse(RefundStatisticsPageRequest request) throws ServiceHandleException {
// 排序
String sortParam = request.getSort();

Sort sort = Sort.by(new Sort.Order( ObjectUtils.isEmpty(sortParam) ? Sort.Direction.DESC : Sort.Direction.fromString(sortParam),"insertTime"));
// 创建分页对象 // 创建分页对象
Pageable pageable = PageRequest.of(request.getPageNo() - 1, request.getPageSize());
Pageable pageable = PageRequest.of(request.getPageNo() - 1, request.getPageSize(),sort);
// 创建Specification // 创建Specification
Specification<RefundStats> spec = createSpecification(request); Specification<RefundStats> spec = createSpecification(request);
// 执行查询 // 执行查询

+ 11
- 0
src/main/java/com/qtzl/alterSales/manager/model/protocol/refund/RefundStatisticsPageRequest.java View File

@NotBlank(message = "导入或查询_操作不能为空,可选值(EXPORT/QUERY)") @NotBlank(message = "导入或查询_操作不能为空,可选值(EXPORT/QUERY)")
private String exportOrQuery; private String exportOrQuery;


/** 排序 DESC ASC */
private String sort;

public String getSort() {
return sort;
}

public void setSort(String sort) {
this.sort = sort;
}

public String getQdId() { public String getQdId() {
return qdId; return qdId;
} }

Loading…
Cancel
Save