Commit df20c5d598aba5edc6531ecf4b27a16a1d1d1e15

Authored by wangqian
1 parent 4d77af8a

机械费用增加开始时间和结束时间筛选

urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/mechanicalcost/vo/MechanicalCostPageReqVO.java
1 1 package com.zteits.urbanops.module.garden.controller.admin.mechanicalcost.vo;
2 2  
3 3 import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
  4 +import com.fasterxml.jackson.annotation.JsonFormat;
4 5 import com.zteits.urbanops.framework.common.pojo.PageParam;
5 6 import com.zteits.urbanops.module.garden.dal.dataobject.mechanicalcost.MechanicalCostDO;
6 7 import io.swagger.v3.oas.annotations.media.Schema;
  8 +import jakarta.validation.constraints.AssertTrue;
7 9 import lombok.Data;
8 10 import org.springframework.format.annotation.DateTimeFormat;
9 11  
... ... @@ -47,15 +49,17 @@ public class MechanicalCostPageReqVO extends PageParam {
47 49 private String vehicleType;
48 50  
49 51 @Schema(description = "开始使用时间")
50   - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
51   - private LocalDate[] startUseTime;
  52 + @JsonFormat(pattern = "yyyy-MM-dd", shape = JsonFormat.Shape.STRING)
  53 + @DateTimeFormat(pattern = "yyyy-MM-dd")
  54 + private LocalDate startUseTime;
52 55  
53 56 @Schema(description = "使用年限")
54 57 private Long serviceLife;
55 58  
56 59 @Schema(description = "结束使用时间")
57   - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
58   - private LocalDate[] endUseTime;
  60 + @JsonFormat(pattern = "yyyy-MM-dd", shape = JsonFormat.Shape.STRING)
  61 + @DateTimeFormat(pattern = "yyyy-MM-dd")
  62 + private LocalDate endUseTime;
59 63  
60 64 @Schema(description = "归属公司", example = "张三")
61 65 private String companyName;
... ... @@ -70,7 +74,6 @@ public class MechanicalCostPageReqVO extends PageParam {
70 74 private String remark;
71 75  
72 76 @Schema(description = "创建时间")
73   - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
74 77 private LocalDateTime[] createTime;
75 78  
76 79 //对应前端排序字段
... ... @@ -82,4 +85,23 @@ public class MechanicalCostPageReqVO extends PageParam {
82 85 "startUseTime", MechanicalCostDO::getStartUseTime,
83 86 "endUseTime" , MechanicalCostDO::getEndUseTime
84 87 );
  88 +
  89 + @AssertTrue(message = "结束时间不能小于开始时间")
  90 + @Schema(hidden = true)
  91 + public boolean isStartTimeNotAfterEndTime() {
  92 + // 1. 两个时间都为空:校验通过(分页查询条件可选)
  93 + if (startUseTime == null && endUseTime == null) {
  94 + return true;
  95 + }
  96 + // 2. 仅开始时间为空:校验通过(可根据业务调整为false强制要求)
  97 + if (startUseTime == null) {
  98 + return true;
  99 + }
  100 + // 3. 仅结束时间为空:校验通过(分页查询条件可选)
  101 + if (endUseTime == null) {
  102 + return true;
  103 + }
  104 + // 4. 两个时间都不为空:核心判断 - 开始时间 <= 结束时间
  105 + return !startUseTime.isAfter(endUseTime);
  106 + }
85 107 }
... ...
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/rentalmechanicalcost/vo/RentalMechanicalCostPageReqVO.java
1 1 package com.zteits.urbanops.module.garden.controller.admin.rentalmechanicalcost.vo;
2 2  
3 3 import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
  4 +import com.fasterxml.jackson.annotation.JsonFormat;
4 5 import com.zteits.urbanops.framework.common.pojo.PageParam;
5 6 import com.zteits.urbanops.module.garden.dal.dataobject.rentalmechanicalcost.RentalMechanicalCostDO;
6 7 import io.swagger.v3.oas.annotations.media.Schema;
  8 +import jakarta.validation.constraints.AssertTrue;
7 9 import lombok.Data;
8 10 import org.springframework.format.annotation.DateTimeFormat;
9 11  
... ... @@ -25,13 +27,16 @@ public class RentalMechanicalCostPageReqVO extends PageParam {
25 27 @Schema(description = "租赁总价格", example = "316")
26 28 private BigDecimal rentalTotalPriceMax;
27 29 @Schema(description = "开始使用时间")
  30 + @JsonFormat(pattern = "yyyy-MM-dd", shape = JsonFormat.Shape.STRING)
28 31 @DateTimeFormat(pattern = "yyyy-MM-dd")
29   - private Date startUseTime;
  32 + private LocalDate startUseTime;
30 33  
31 34 @Schema(description = "使用时长(天)")
32 35 private Integer useDuration;
33 36  
34 37 @Schema(description = "结束日期")
  38 + @JsonFormat(pattern = "yyyy-MM-dd", shape = JsonFormat.Shape.STRING)
  39 + @DateTimeFormat(pattern = "yyyy-MM-dd")
35 40 private LocalDate endUseTime;
36 41  
37 42 @Schema(description = "数量")
... ... @@ -48,4 +53,23 @@ public class RentalMechanicalCostPageReqVO extends PageParam {
48 53 "startUseTime", RentalMechanicalCostDO::getStartUseTime,
49 54 "endUseTime", RentalMechanicalCostDO::getEndUseTime
50 55 );
  56 +
  57 + @AssertTrue(message = "结束时间不能小于开始时间")
  58 + @Schema(hidden = true)
  59 + public boolean isStartTimeNotAfterEndTime() {
  60 + // 1. 两个时间都为空:校验通过(分页查询条件可选)
  61 + if (startUseTime == null && endUseTime == null) {
  62 + return true;
  63 + }
  64 + // 2. 仅开始时间为空:校验通过(可根据业务调整为false强制要求)
  65 + if (startUseTime == null) {
  66 + return true;
  67 + }
  68 + // 3. 仅结束时间为空:校验通过(分页查询条件可选)
  69 + if (endUseTime == null) {
  70 + return true;
  71 + }
  72 + // 4. 两个时间都不为空:核心判断 - 开始时间 <= 结束时间
  73 + return !startUseTime.isAfter(endUseTime);
  74 + }
51 75 }
... ...
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&lt;MechanicalCostDO&gt; {
29 29 .eqIfPresent(MechanicalCostDO::getLicensePlate, reqVO.getLicensePlate())
30 30 .eqIfPresent(MechanicalCostDO::getVehicleCategory, reqVO.getVehicleCategory())
31 31 .eqIfPresent(MechanicalCostDO::getVehicleType, reqVO.getVehicleType())
32   - .betweenIfPresent(MechanicalCostDO::getStartUseTime, reqVO.getStartUseTime())
  32 + .geIfPresent(MechanicalCostDO::getStartUseTime, reqVO.getStartUseTime())
33 33 .eqIfPresent(MechanicalCostDO::getServiceLife, reqVO.getServiceLife())
34   - .betweenIfPresent(MechanicalCostDO::getEndUseTime, reqVO.getEndUseTime())
  34 + .leIfPresent(MechanicalCostDO::getEndUseTime, reqVO.getEndUseTime())
35 35 .likeIfPresent(MechanicalCostDO::getCompanyName, reqVO.getCompanyName())
36 36 .eqIfPresent(MechanicalCostDO::getCompanyId, reqVO.getCompanyId())
37 37 .eqIfPresent(MechanicalCostDO::getDeptId, reqVO.getDeptId())
... ...
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&lt;RentalMechanical
28 28 //.eqIfPresent(RentalMechanicalCostDO::getVehicleCategory, reqVO.getVehicleCategory())
29 29 // .eqIfPresent(RentalMechanicalCostDO::getVehicleType, reqVO.getVehicleType())
30 30 //.betweenIfPresent(RentalMechanicalCostDO::getStartUseTime, reqVO.getStartUseTime())
31   - .eqIfPresent(RentalMechanicalCostDO::getStartUseTime, reqVO.getStartUseTime())
  31 + .geIfPresent(RentalMechanicalCostDO::getStartUseTime, reqVO.getStartUseTime())
32 32 .eqIfPresent(RentalMechanicalCostDO::getUseDuration, reqVO.getUseDuration())
33   - //.betweenIfPresent(RentalMechanicalCostDO::getEndUseTime, reqVO.getEndUseTime())
  33 + .leIfPresent(RentalMechanicalCostDO::getEndUseTime, reqVO.getEndUseTime())
34 34 //.likeIfPresent(RentalMechanicalCostDO::getCompanyName, reqVO.getCompanyName())
35 35 .eqIfPresent(RentalMechanicalCostDO::getCompanyId, reqVO.getCompanyId())
36 36 //.eqIfPresent(RentalMechanicalCostDO::getDeptId, reqVO.getDeptId())
... ...