新增了病例交流
This commit is contained in:
+88
@@ -0,0 +1,88 @@
|
||||
package com.example.caseData.request.caseExchangeRequest;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import lombok.Data;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class getCaseExchangeSearchPage {
|
||||
// ✅ 分页参数
|
||||
@Min(value = 1,message = "页码最小为 1")
|
||||
private Integer page = 1;
|
||||
|
||||
@JsonProperty("page_size")
|
||||
@Min(value = 1, message = "每页个数最小为 1")
|
||||
private Integer pageSize = 20;
|
||||
|
||||
// 标题/作者名称/疾病名称
|
||||
@JsonProperty("keyword")
|
||||
private String keyword;
|
||||
|
||||
// 用户id
|
||||
@JsonProperty("user_id")
|
||||
private String userId;
|
||||
|
||||
// 排序字段
|
||||
private OrderRequest order;
|
||||
|
||||
/**
|
||||
* 排序字段嵌套结构体
|
||||
*/
|
||||
@Data
|
||||
public static class OrderRequest {
|
||||
@JsonProperty("created_at")
|
||||
private String createdAt; // 创建时间
|
||||
|
||||
@JsonProperty("read_num")
|
||||
private String readNum; // 阅读量
|
||||
|
||||
@JsonProperty("push_date")
|
||||
private String pushDate; // 发表时间
|
||||
|
||||
public Map<String, String> toMap() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (StringUtils.hasText(createdAt)) {
|
||||
map.put("a.created_at", createdAt);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(readNum)) {
|
||||
map.put("a.read_num", readNum);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(pushDate)) {
|
||||
map.put("a.push_date", pushDate);
|
||||
}
|
||||
|
||||
// 默认排序(如果用户未传递任何排序字段)
|
||||
if (map.isEmpty()) {
|
||||
map.put("a.updated_at", "desc");
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取排序字段,若无用户输入则使用默认排序
|
||||
*/
|
||||
public Map<String, String> handleOrder() {
|
||||
return order != null ? order.toMap() : new OrderRequest().toMap();
|
||||
}
|
||||
|
||||
// ✅ 校验分页参数
|
||||
public void validateForPage() {
|
||||
// 如果 page 为空,设为默认值 1
|
||||
if (page == null) {
|
||||
page = 1;
|
||||
}
|
||||
|
||||
if (pageSize == null) {
|
||||
pageSize = 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user