Commit f6badbca by 杨卫

feat:单边时间区间修改提交

1 parent da66ca3e
...@@ -143,28 +143,23 @@ public class VrAuditController { ...@@ -143,28 +143,23 @@ public class VrAuditController {
// 7. 场次时间区间 - EXISTS 子查询关联 AuctionVehicle(只查创建时间最晚的场次) // 7. 场次时间区间 - EXISTS 子查询关联 AuctionVehicle(只查创建时间最晚的场次)
if (queryVO.getAuctionStartTimeBegin() != null || queryVO.getAuctionStartTimeEnd() != null) { if (queryVO.getAuctionStartTimeBegin() != null || queryVO.getAuctionStartTimeEnd() != null) {
final LocalDate beginTime = queryVO.getAuctionStartTimeBegin(); final LocalDateTime beginDateTime = queryVO.getAuctionStartTimeBegin() != null ? queryVO.getAuctionStartTimeBegin().atStartOfDay() : null;
final LocalDate endTime = queryVO.getAuctionStartTimeEnd(); final LocalDateTime endDateTime = queryVO.getAuctionStartTimeEnd() != null ? queryVO.getAuctionStartTimeEnd().atTime(23, 59, 59) : null;
pagination.addCondition((root, query, builder) -> { pagination.addCondition((root, query, builder) -> {
// 子查询1:找该车辆创建时间最晚的场次ID(使用MAX) // 子查询:找该车辆拍卖开始时间最晚的时间
var latestSubquery = query.subquery(Integer.class); var maxStartSubquery = query.subquery(LocalDateTime.class);
var latestRoot = latestSubquery.from(AuctionVehicle.class); var maxStartRoot = maxStartSubquery.from(AuctionVehicle.class);
latestSubquery.select(builder.max(latestRoot.get(AuctionVehicle_.AUCVEH_ID))); maxStartSubquery.select(builder.greatest(maxStartRoot.get(AuctionVehicle_.AUCTION_START_TIME).as(LocalDateTime.class)));
latestSubquery.where( maxStartSubquery.where(
builder.equal(latestRoot.get(AuctionVehicle_.VEHICLE).get(Vehicle_.VEHICLE_ID), builder.equal(maxStartRoot.get(AuctionVehicle_.VEHICLE).get(Vehicle_.VEHICLE_ID),
root.get(VrAudit_.VEHICLE_ID)) root.get(VrAudit_.VEHICLE_ID))
); );
// 子查询2:验证最晚那场是否符合时间条件 // 直接比较最晚的拍卖开始时间是否在搜索范围内
var subquery = query.subquery(Integer.class); return builder.and(
var subRoot = subquery.from(AuctionVehicle.class); beginDateTime != null ? builder.greaterThanOrEqualTo(maxStartSubquery, beginDateTime) : builder.conjunction(),
subquery.select(subRoot.get(AuctionVehicle_.AUCVEH_ID)); endDateTime != null ? builder.lessThanOrEqualTo(maxStartSubquery, endDateTime) : builder.conjunction()
subquery.where(
builder.equal(subRoot.get(AuctionVehicle_.AUCVEH_ID), latestSubquery),
beginTime != null ? builder.greaterThanOrEqualTo(subRoot.get(AuctionVehicle_.AUCTION_START_TIME), beginTime) : builder.conjunction(),
endTime != null ? builder.lessThanOrEqualTo(subRoot.get(AuctionVehicle_.AUCTION_END_TIME), endTime) : builder.conjunction()
); );
return builder.exists(subquery);
}); });
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!