diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/mechanicalcost/vo/MechanicalCostPageReqVO.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/mechanicalcost/vo/MechanicalCostPageReqVO.java index 4bab068..49efbec 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/mechanicalcost/vo/MechanicalCostPageReqVO.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/mechanicalcost/vo/MechanicalCostPageReqVO.java @@ -1,9 +1,11 @@ package com.zteits.urbanops.module.garden.controller.admin.mechanicalcost.vo; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; +import com.fasterxml.jackson.annotation.JsonFormat; import com.zteits.urbanops.framework.common.pojo.PageParam; import com.zteits.urbanops.module.garden.dal.dataobject.mechanicalcost.MechanicalCostDO; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.AssertTrue; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; @@ -47,15 +49,17 @@ public class MechanicalCostPageReqVO extends PageParam { private String vehicleType; @Schema(description = "开始使用时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDate[] startUseTime; + @JsonFormat(pattern = "yyyy-MM-dd", shape = JsonFormat.Shape.STRING) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate startUseTime; @Schema(description = "使用年限") private Long serviceLife; @Schema(description = "结束使用时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDate[] endUseTime; + @JsonFormat(pattern = "yyyy-MM-dd", shape = JsonFormat.Shape.STRING) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate endUseTime; @Schema(description = "归属公司", example = "张三") private String companyName; @@ -70,7 +74,6 @@ public class MechanicalCostPageReqVO extends PageParam { private String remark; @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; //对应前端排序字段 @@ -82,4 +85,23 @@ public class MechanicalCostPageReqVO extends PageParam { "startUseTime", MechanicalCostDO::getStartUseTime, "endUseTime" , MechanicalCostDO::getEndUseTime ); + + @AssertTrue(message = "结束时间不能小于开始时间") + @Schema(hidden = true) + public boolean isStartTimeNotAfterEndTime() { + // 1. 两个时间都为空:校验通过(分页查询条件可选) + if (startUseTime == null && endUseTime == null) { + return true; + } + // 2. 仅开始时间为空:校验通过(可根据业务调整为false强制要求) + if (startUseTime == null) { + return true; + } + // 3. 仅结束时间为空:校验通过(分页查询条件可选) + if (endUseTime == null) { + return true; + } + // 4. 两个时间都不为空:核心判断 - 开始时间 <= 结束时间 + return !startUseTime.isAfter(endUseTime); + } } diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/rentalmechanicalcost/vo/RentalMechanicalCostPageReqVO.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/rentalmechanicalcost/vo/RentalMechanicalCostPageReqVO.java index a574a8c..588053d 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/rentalmechanicalcost/vo/RentalMechanicalCostPageReqVO.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/rentalmechanicalcost/vo/RentalMechanicalCostPageReqVO.java @@ -1,9 +1,11 @@ package com.zteits.urbanops.module.garden.controller.admin.rentalmechanicalcost.vo; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; +import com.fasterxml.jackson.annotation.JsonFormat; import com.zteits.urbanops.framework.common.pojo.PageParam; import com.zteits.urbanops.module.garden.dal.dataobject.rentalmechanicalcost.RentalMechanicalCostDO; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.AssertTrue; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; @@ -25,13 +27,16 @@ public class RentalMechanicalCostPageReqVO extends PageParam { @Schema(description = "租赁总价格", example = "316") private BigDecimal rentalTotalPriceMax; @Schema(description = "开始使用时间") + @JsonFormat(pattern = "yyyy-MM-dd", shape = JsonFormat.Shape.STRING) @DateTimeFormat(pattern = "yyyy-MM-dd") - private Date startUseTime; + private LocalDate startUseTime; @Schema(description = "使用时长(天)") private Integer useDuration; @Schema(description = "结束日期") + @JsonFormat(pattern = "yyyy-MM-dd", shape = JsonFormat.Shape.STRING) + @DateTimeFormat(pattern = "yyyy-MM-dd") private LocalDate endUseTime; @Schema(description = "数量") @@ -48,4 +53,23 @@ public class RentalMechanicalCostPageReqVO extends PageParam { "startUseTime", RentalMechanicalCostDO::getStartUseTime, "endUseTime", RentalMechanicalCostDO::getEndUseTime ); + + @AssertTrue(message = "结束时间不能小于开始时间") + @Schema(hidden = true) + public boolean isStartTimeNotAfterEndTime() { + // 1. 两个时间都为空:校验通过(分页查询条件可选) + if (startUseTime == null && endUseTime == null) { + return true; + } + // 2. 仅开始时间为空:校验通过(可根据业务调整为false强制要求) + if (startUseTime == null) { + return true; + } + // 3. 仅结束时间为空:校验通过(分页查询条件可选) + if (endUseTime == null) { + return true; + } + // 4. 两个时间都不为空:核心判断 - 开始时间 <= 结束时间 + return !startUseTime.isAfter(endUseTime); + } } diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/mechanicalcost/MechanicalCostMapper.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/mechanicalcost/MechanicalCostMapper.java index 25ea3eb..03b1040 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/mechanicalcost/MechanicalCostMapper.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/mechanicalcost/MechanicalCostMapper.java @@ -29,9 +29,9 @@ public interface MechanicalCostMapper extends BaseMapperX { .eqIfPresent(MechanicalCostDO::getLicensePlate, reqVO.getLicensePlate()) .eqIfPresent(MechanicalCostDO::getVehicleCategory, reqVO.getVehicleCategory()) .eqIfPresent(MechanicalCostDO::getVehicleType, reqVO.getVehicleType()) - .betweenIfPresent(MechanicalCostDO::getStartUseTime, reqVO.getStartUseTime()) + .geIfPresent(MechanicalCostDO::getStartUseTime, reqVO.getStartUseTime()) .eqIfPresent(MechanicalCostDO::getServiceLife, reqVO.getServiceLife()) - .betweenIfPresent(MechanicalCostDO::getEndUseTime, reqVO.getEndUseTime()) + .leIfPresent(MechanicalCostDO::getEndUseTime, reqVO.getEndUseTime()) .likeIfPresent(MechanicalCostDO::getCompanyName, reqVO.getCompanyName()) .eqIfPresent(MechanicalCostDO::getCompanyId, reqVO.getCompanyId()) .eqIfPresent(MechanicalCostDO::getDeptId, reqVO.getDeptId()) diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/rentalmechanicalcost/RentalMechanicalCostMapper.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/rentalmechanicalcost/RentalMechanicalCostMapper.java index 3fc3a66..b22a52f 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/rentalmechanicalcost/RentalMechanicalCostMapper.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/rentalmechanicalcost/RentalMechanicalCostMapper.java @@ -28,9 +28,9 @@ public interface RentalMechanicalCostMapper extends BaseMapperX