111 lines
2.8 KiB
Java
111 lines
2.8 KiB
Java
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;
|
|
|
|
// 是否被精选(0:否 1:是)
|
|
@JsonProperty("is_selected")
|
|
private Integer isSelected;
|
|
|
|
// 疾病标签唯一标识
|
|
@JsonProperty("label_iden")
|
|
private String labelIden;
|
|
|
|
// 排序字段
|
|
private OrderRequest order;
|
|
|
|
/**
|
|
* 排序字段嵌套结构体
|
|
*/
|
|
@Data
|
|
public static class OrderRequest {
|
|
@JsonProperty("created_at")
|
|
private String createdAt; // 创建时间
|
|
|
|
@JsonProperty("read_num")
|
|
private String readNum; // 阅读量
|
|
|
|
@JsonProperty("comment_num")
|
|
private String commentNum; // 评论数
|
|
|
|
@JsonProperty("push_date")
|
|
private String pushDate; // 发表时间
|
|
|
|
@JsonProperty("last_comment_time")
|
|
private String lastCommentTime; // 最后评论时间
|
|
|
|
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(commentNum)) {
|
|
map.put("a.comment_num", commentNum);
|
|
}
|
|
|
|
if (StringUtils.hasText(pushDate)) {
|
|
map.put("a.push_date", pushDate);
|
|
}
|
|
|
|
if (StringUtils.hasText(lastCommentTime)) {
|
|
map.put("commentCreatedAt", lastCommentTime);
|
|
}
|
|
|
|
// 默认排序(如果用户未传递任何排序字段)
|
|
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;
|
|
}
|
|
}
|
|
}
|