release-专辑列表添加查询条件

release-2024-08-08
pikaqiudeshujia 7 months ago
parent 933db7a5f8
commit 32610bf1f6

@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDate;
/**
* @Author: yawei.huang
@ -16,10 +17,21 @@ import java.io.Serializable;
@Data
public class AlbumSearchDTO implements Serializable {
@ApiModelProperty("音乐人id")
private String artistId;
@ApiModelProperty("专辑状态")
private Integer state;
@ApiModelProperty("时间查询条件 null-全部时间1-今年2-最近一月3-最近一周4-最近24小时")
private Integer timeQuery;
@ApiModelProperty("专辑名称")
private String name;
@ApiModelProperty("时间范围-开始时间")
private LocalDate startTime;
@ApiModelProperty("时间范围-结束时间")
private LocalDate endTime;
}

@ -101,14 +101,17 @@ public class AlbumService {
return (Root<ArtistAlbum> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
List<Predicate> predicateList = new ArrayList<Predicate>();
if (StringUtils.isNotBlank(param.getArtistId())) {
// 音乐人id
predicateList.add(builder.equal(root.get("artistId"), param.getArtistId()));
}
if (param.getState() != null) {
// 专辑状态
predicateList.add(builder.equal(root.get("state"), param.getState()));
}
if (param.getTimeQuery() != null) {
// 时间范围,系统定义
switch (param.getTimeQuery()) {
case 1:
// 今年
@ -134,6 +137,21 @@ public class AlbumService {
}
}
if(StringUtils.isNotBlank(param.getName())) {
// 专辑名称
String likeExpression = "%" + param.getName() + "%";
predicateList.add(builder.and(builder.like(root.get("name"), likeExpression)));
}
if(param.getStartTime() != null) {
predicateList.add(builder.greaterThanOrEqualTo(root.get("createTime"), param.getStartTime()));
}
if(param.getEndTime() != null) {
predicateList.add(builder.lessThanOrEqualTo(root.get("createTime"), param.getEndTime()));
}
return builder.and(predicateList.toArray(new Predicate[predicateList.size()]));
};
}

Loading…
Cancel
Save