feat(asset): 添加参数校验注解

停车场模块:
- 经度:-180~180,最多6位小数
- 纬度:-90~90,最多6位小数
- 手机号:1开头的11位数字
- 容量:必须大于0
- 已停车辆数:不能为负数

车型参数模块:
- 氢瓶容量、里程数:不能为负数
- 储电量、材料费、工时费:不能为负数
- 轮胎数量:必须大于0
- 保养周期:必须大于0

防止用户输入非法数据导致展示错乱
This commit is contained in:
k kfluous
2026-03-12 09:32:48 +08:00
parent 8defb1411b
commit eb9eaf3810
3 changed files with 21 additions and 2 deletions

View File

@@ -4,6 +4,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Min;
import java.time.LocalDate; import java.time.LocalDate;
/** /**
@@ -22,7 +24,7 @@ public class ParkingBaseVO {
private String address; private String address;
@Schema(description = "容量", example = "100") @Schema(description = "容量", example = "100")
@jakarta.validation.constraints.Min(value = 1, message = "容量必须大于0") @Min(value = 1, message = "容量必须大于0")
private Integer capacity; private Integer capacity;
@Schema(description = "省份", example = "浙江省") @Schema(description = "省份", example = "浙江省")
@@ -41,19 +43,21 @@ public class ParkingBaseVO {
private String managerName; private String managerName;
@Schema(description = "负责人联系方式", example = "13800138000") @Schema(description = "负责人联系方式", example = "13800138000")
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
private String managerPhone; private String managerPhone;
@Schema(description = "停车场联系人", example = "李四") @Schema(description = "停车场联系人", example = "李四")
private String contactName; private String contactName;
@Schema(description = "停车场联系方式", example = "13900139000") @Schema(description = "停车场联系方式", example = "13900139000")
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
private String contactPhone; private String contactPhone;
@Schema(description = "公司负责人", example = "王五") @Schema(description = "公司负责人", example = "王五")
private String principal; private String principal;
@Schema(description = "已停车辆数", example = "50") @Schema(description = "已停车辆数", example = "50")
@jakarta.validation.constraints.Min(value = 0, message = "已停车辆数不能为负数") @Min(value = 0, message = "已停车辆数不能为负数")
private Integer parkedAmount; private Integer parkedAmount;
@Schema(description = "库存区域(字典)", example = "1") @Schema(description = "库存区域(字典)", example = "1")
@@ -63,9 +67,11 @@ public class ParkingBaseVO {
private Integer unusualActionCity; private Integer unusualActionCity;
@Schema(description = "经度", example = "120.123456") @Schema(description = "经度", example = "120.123456")
@Pattern(regexp = "^-?((0|[1-9]\\d?|1[0-7]\\d)(\\.\\d{1,6})?|180(\\.0{1,6})?)$", message = "经度格式不正确,范围:-180~180")
private String longitude; private String longitude;
@Schema(description = "纬度", example = "30.123456") @Schema(description = "纬度", example = "30.123456")
@Pattern(regexp = "^-?((0|[1-8]?\\d)(\\.\\d{1,6})?|90(\\.0{1,6})?)$", message = "纬度格式不正确,范围:-90~90")
private String latitude; private String latitude;
@Schema(description = "备注", example = "备注信息") @Schema(description = "备注", example = "备注信息")

View File

@@ -5,6 +5,8 @@ import lombok.Data;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.DecimalMin;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
@@ -37,15 +39,19 @@ public class VehicleModelBaseVO {
private Integer hydrogenUnit; private Integer hydrogenUnit;
@Schema(description = "氢瓶容量(L)", example = "165") @Schema(description = "氢瓶容量(L)", example = "165")
@Min(value = 0, message = "氢瓶容量不能为负数")
private Integer hydrogenCapacity; private Integer hydrogenCapacity;
@Schema(description = "电池公告可行驶里程(KM)", example = "300") @Schema(description = "电池公告可行驶里程(KM)", example = "300")
@Min(value = 0, message = "电池公告可行驶里程不能为负数")
private Integer electricityMileage; private Integer electricityMileage;
@Schema(description = "储电量(kwh)", example = "80.00") @Schema(description = "储电量(kwh)", example = "80.00")
@DecimalMin(value = "0.0", message = "储电量不能为负数")
private BigDecimal reserveElectricity; private BigDecimal reserveElectricity;
@Schema(description = "氢气公告可行驶里程(KM)", example = "400") @Schema(description = "氢气公告可行驶里程(KM)", example = "400")
@Min(value = 0, message = "氢气公告可行驶里程不能为负数")
private Integer hydrogenMileage; private Integer hydrogenMileage;
@Schema(description = "燃料种类(字典)", example = "1") @Schema(description = "燃料种类(字典)", example = "1")
@@ -55,6 +61,7 @@ public class VehicleModelBaseVO {
private String tireSize; private String tireSize;
@Schema(description = "轮胎数量", example = "6") @Schema(description = "轮胎数量", example = "6")
@Min(value = 1, message = "轮胎数量必须大于0")
private Integer tireNumber; private Integer tireNumber;
@Schema(description = "车辆尺寸", example = "5995×2100×2850") @Schema(description = "车辆尺寸", example = "5995×2100×2850")

View File

@@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.asset.controller.admin.vehiclemodel.vo;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Min;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
@@ -27,15 +29,19 @@ public class VehicleModelMaintainItemVO {
private String maintainContent; private String maintainContent;
@Schema(description = "材料费", example = "200.00") @Schema(description = "材料费", example = "200.00")
@DecimalMin(value = "0.0", message = "材料费不能为负数")
private BigDecimal materialsExpenses; private BigDecimal materialsExpenses;
@Schema(description = "工时费", example = "100.00") @Schema(description = "工时费", example = "100.00")
@DecimalMin(value = "0.0", message = "工时费不能为负数")
private BigDecimal hourFee; private BigDecimal hourFee;
@Schema(description = "保养公里周期(KM)", example = "5000") @Schema(description = "保养公里周期(KM)", example = "5000")
@Min(value = 1, message = "保养公里周期必须大于0")
private Integer kilometerCycle; private Integer kilometerCycle;
@Schema(description = "保养时间周期(月)", example = "6") @Schema(description = "保养时间周期(月)", example = "6")
@Min(value = 1, message = "保养时间周期必须大于0")
private Integer timeCycle; private Integer timeCycle;
} }