99 lines
2.5 KiB
Java
99 lines
2.5 KiB
Java
package com.example.caseData.request.clinicalRequest;
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
import jakarta.validation.constraints.Max;
|
|
import jakarta.validation.constraints.Min;
|
|
import jakarta.validation.constraints.NotNull;
|
|
import lombok.Data;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
@Data
|
|
public class getClinicalVideoSearchPage {
|
|
// ✅ 分页参数
|
|
@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("hospital_id")
|
|
private String hospitalId;
|
|
|
|
// 医生id
|
|
@JsonProperty("doctor_id")
|
|
private String doctorId;
|
|
|
|
// 是否需要数量(0:否 1:是)
|
|
@JsonProperty("is_need_num")
|
|
private Integer isNeedNum = 0;
|
|
|
|
// 排序字段
|
|
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;
|
|
}
|
|
}
|
|
}
|