Commit d8a2a9d2 by 林冲

feat:字段长度校验

1 parent 20f87916
...@@ -399,9 +399,13 @@ public class EvalElectronicContractService { ...@@ -399,9 +399,13 @@ public class EvalElectronicContractService {
if (row.getPlateNo().length() > 10) { if (row.getPlateNo().length() > 10) {
errors.add("车牌号不能超过10位"); errors.add("车牌号不能超过10位");
} }
// 车架号必须是17位,否则提示“车架号必须是17位” // 车架号必须是16位或17位
if (row.getVin().length() != 17) { if (row.getVin().length() != 16 && row.getVin().length() != 17) {
errors.add("车架号必须是17位"); errors.add("车架号必须是16位或17位");
}
// 车架号必须是大写英文字符+数字
if (!row.getVin().matches("^[A-Z0-9]{16,17}$")) {
errors.add("车架号必须由大写英文字符和数字组成");
} }
if (row.getBrand().length() > 20) { if (row.getBrand().length() > 20) {
errors.add("品牌不能超过20个字符"); errors.add("品牌不能超过20个字符");
...@@ -413,6 +417,53 @@ public class EvalElectronicContractService { ...@@ -413,6 +417,53 @@ public class EvalElectronicContractService {
errors.add("支付方式不能超过20个字符"); errors.add("支付方式不能超过20个字符");
} }
// 定金金额校验:最多10位数,不包含小数
if (row.getDepositAmount() != null) {
String depositAmountStr = row.getDepositAmount().toString();
if (depositAmountStr.contains(".")) {
errors.add("定金金额不能包含小数");
}
// 去除可能的负号再检查位数
String absDepositAmount = depositAmountStr.replace("-", "").replace(".", "");
if (absDepositAmount.length() > 10) {
errors.add("定金金额最多10位数");
}
}
// 尾款金额校验:最多10位数,不包含小数
if (row.getFinalAmount() != null) {
String finalAmountStr = row.getFinalAmount().toString();
if (finalAmountStr.contains(".")) {
errors.add("尾款金额不能包含小数");
}
// 去除可能的负号再检查位数
String absFinalAmount = finalAmountStr.replace("-", "").replace(".", "");
if (absFinalAmount.length() > 10) {
errors.add("尾款金额最多10位数");
}
}
// 收款人校验:1-20字符
if (StringUtils.isNotBlank(row.getPayeeName())) {
if (row.getPayeeName().length() < 1 || row.getPayeeName().length() > 20) {
errors.add("收款人长度必须在1-20字符之间");
}
}
// 开户行校验:1-20字符
if (StringUtils.isNotBlank(row.getBankName())) {
if (row.getBankName().length() < 1 || row.getBankName().length() > 20) {
errors.add("开户行长度必须在1-20字符之间");
}
}
// 收款银行账号校验:数字 1-20字符
if (StringUtils.isNotBlank(row.getBankAccountNo())) {
if (!row.getBankAccountNo().matches("^[0-9]{1,20}$")) {
errors.add("收款银行账号必须是1-20位数字");
}
}
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!