Commit 1ba58916 by 叶立庆

出险日期 / 出险时间(内部) / 报案日期 不能是将来时间 checkImportDate 解析成功后统一校验 date.after(new Date()),…

…报「XX不能晚于当前时间」,三个日期列共用
出险日期	必须 <= 报案日期	两日期均解析成功时比较,报「出险日期不能晚于报案日期」
报案人	末尾不能有数字、回车、空格或换行	正则 .*[\d\r\n\s ]$(\s 覆盖空格/回车/换行/制表符,另含全角空格)
报案人联系号码	有效11位手机号	正则从 1\d{10} 收紧为 1[3-9]\d{9}(第二位限 3-9,排除 12x 等无效号段)
出险详细地址	最多200字符	非空后校验 length() > 200
定损批准金额 / 申请金额	1~200000	checkImportAmount 从「≥0」改为「>0 且 ≤200000」(新增常量 IMPORT_AMOUNT_MAX),错误文案同步更新
1 parent cf0b5814
...@@ -4498,13 +4498,21 @@ public class ServiceEquityClaimsService { ...@@ -4498,13 +4498,21 @@ public class ServiceEquityClaimsService {
Date reimbursementDate = checkImportDate("出险日期", row.getReimbursementDate(), errors); Date reimbursementDate = checkImportDate("出险日期", row.getReimbursementDate(), errors);
Date internalReimbursementDate = checkImportDate("出险时间(内部)", row.getInternalReimbursementDate(), errors); Date internalReimbursementDate = checkImportDate("出险时间(内部)", row.getInternalReimbursementDate(), errors);
Date reportDate = checkImportDate("报案日期", row.getReportDate(), errors); Date reportDate = checkImportDate("报案日期", row.getReportDate(), errors);
if (StringUtils.isBlank(row.getReporterName())) { //出险日期必须早于或等于报案日期
if (reimbursementDate != null && reportDate != null && reimbursementDate.after(reportDate)) {
errors.add("出险日期不能晚于报案日期");
}
String reporterName = row.getReporterName();
if (StringUtils.isBlank(reporterName)) {
errors.add("报案人数据值为空"); errors.add("报案人数据值为空");
} else if (reporterName.matches(".*[\\d\\r\\n\\s ]$")) {
//末尾不能有数字、回车、空格或换行
errors.add("报案人末尾不能有数字、回车、空格或换行");
} }
String reporterPhone = StringUtils.trimToNull(row.getReporterPhone()); String reporterPhone = StringUtils.trimToNull(row.getReporterPhone());
if (reporterPhone == null) { if (reporterPhone == null) {
errors.add("报案人联系号码数据值为空"); errors.add("报案人联系号码数据值为空");
} else if (!reporterPhone.matches("1\\d{10}")) { } else if (!reporterPhone.matches("1[3-9]\\d{9}")) {
errors.add("报案人联系号码非正确手机号"); errors.add("报案人联系号码非正确手机号");
} }
//出险地点:按"省/市/区"格式拆分并匹配字典 //出险地点:按"省/市/区"格式拆分并匹配字典
...@@ -4533,6 +4541,8 @@ public class ServiceEquityClaimsService { ...@@ -4533,6 +4541,8 @@ public class ServiceEquityClaimsService {
} }
if (StringUtils.isBlank(row.getReimbursementAddr())) { if (StringUtils.isBlank(row.getReimbursementAddr())) {
errors.add("出险详细地址数据值为空"); errors.add("出险详细地址数据值为空");
} else if (row.getReimbursementAddr().length() > 200) {
errors.add("出险详细地址最多200字符");
} }
BigDecimal approveAmount = checkImportAmount("定损批准金额", row.getApproveAmount(), errors); BigDecimal approveAmount = checkImportAmount("定损批准金额", row.getApproveAmount(), errors);
BigDecimal applyAmount = checkImportAmount("申请金额", row.getApplyAmount(), errors); BigDecimal applyAmount = checkImportAmount("申请金额", row.getApplyAmount(), errors);
...@@ -4752,6 +4762,11 @@ public class ServiceEquityClaimsService { ...@@ -4752,6 +4762,11 @@ public class ServiceEquityClaimsService {
}; };
/** /**
* 导入金额上限:200000(元)
*/
private static final BigDecimal IMPORT_AMOUNT_MAX = new BigDecimal(200000);
/**
* 导入日期校验:非空 + 兼容 yyyy/MM/dd HH:mm:ss、yyyy-MM-dd HH:mm:ss、yyyy/MM/dd HH:mm、yyyy-MM-dd HH:mm 四种格式 * 导入日期校验:非空 + 兼容 yyyy/MM/dd HH:mm:ss、yyyy-MM-dd HH:mm:ss、yyyy/MM/dd HH:mm、yyyy-MM-dd HH:mm 四种格式
*/ */
private Date checkImportDate(String fieldName, String value, List<String> errors) { private Date checkImportDate(String fieldName, String value, List<String> errors) {
...@@ -4765,6 +4780,10 @@ public class ServiceEquityClaimsService { ...@@ -4765,6 +4780,10 @@ public class ServiceEquityClaimsService {
ParsePosition pos = new ParsePosition(0); ParsePosition pos = new ParsePosition(0);
Date date = new SimpleDateFormat(pattern).parse(v, pos); Date date = new SimpleDateFormat(pattern).parse(v, pos);
if (date != null && pos.getIndex() == v.length()) { if (date != null && pos.getIndex() == v.length()) {
if (date.after(new Date())) {
errors.add(fieldName + "不能晚于当前时间");
return null;
}
return date; return date;
} }
} }
...@@ -4773,7 +4792,7 @@ public class ServiceEquityClaimsService { ...@@ -4773,7 +4792,7 @@ public class ServiceEquityClaimsService {
} }
/** /**
* 导入金额校验:非空 + 大于等于0的数字 * 导入金额校验:非空 + 1~200000的数字
*/ */
private BigDecimal checkImportAmount(String fieldName, String value, List<String> errors) { private BigDecimal checkImportAmount(String fieldName, String value, List<String> errors) {
String v = StringUtils.trimToNull(value); String v = StringUtils.trimToNull(value);
...@@ -4783,13 +4802,13 @@ public class ServiceEquityClaimsService { ...@@ -4783,13 +4802,13 @@ public class ServiceEquityClaimsService {
} }
try { try {
BigDecimal amount = new BigDecimal(v); BigDecimal amount = new BigDecimal(v);
if (amount.compareTo(BigDecimal.ZERO) < 0) { if (amount.compareTo(BigDecimal.ZERO) <= 0 || amount.compareTo(IMPORT_AMOUNT_MAX) > 0) {
errors.add(fieldName + "仅允许输入大于等于0的数字"); errors.add(fieldName + "仅允许输入1~200000的数字");
return null; return null;
} }
return amount; return amount;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
errors.add(fieldName + "仅允许输入大于等于0的数字"); errors.add(fieldName + "仅允许输入1~200000的数字");
return null; return null;
} }
} }
......
  • @wangxw1
    commented
    Owner

    一、关键问题与优化建议(Top 3)

    1. 逻辑实现与提示文案不一致(功能正确性)

    • 问题描述:在 checkImportAmount 金额校验中,代码逻辑为 amount.compareTo(BigDecimal.ZERO) <= 0(即必须大于 0),这意味着输入 0.01 或 0.5 等小数是可以通过校验的。但抛出的错误提示文案以及常量定义注释却写着“仅允许输入1~200000的数字”。
    • 影响分析:会给用户造成困扰。如果业务真实诉求是最低为 1,则当前代码存在漏洞(放过了0.01~0.99的数据);如果业务允许小数,则错误提示文案会误导用户以为只能输入整数或大于等于1的数。
    • 优化建议:
      • 若业务要求最小值严格为 1:应修改代码为 amount.compareTo(BigDecimal.ONE) < 0。
      • 若业务允许大于 0 的小数:应修改错误提示文案为“仅允许输入大于0且不超过200000的数字”。

    2. 批处理场景下的严重性能隐患(性能与资源利用)

    • 问题描述:在 checkImportDate 方法中,针对传入的多种日期格式,使用了 new SimpleDateFormat(pattern) 进行循环解析。在 Excel 批量导入场景下,每一行的每一个日期字段都会触发多次 SimpleDateFormat 对象的创建与销毁。
    • 影响分析:SimpleDateFormat 是重量级对象,在批量导入场景中高频实例化会导致极大的 CPU 开销,并引发频繁的 Young GC,严重拖慢导入性能。
    • 优化建议:建议升级为 Java 8 的 DateTimeFormatter(线程安全,可复用),或者在方法外通过静态常量定义好 DateTimeFormatter 数组进行遍历。 java // 推荐示例 (Java 8+) private static final DateTimeFormatter[] FORMATTERS = { DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"), // ... 其他格式 }; // 解析时使用 LocalDateTime.parse(v, formatter)

    3. 正则表达式存在冗余字符(最佳实践)

    • 问题描述:报案人名称校验的正则表达式 .*[\d\r\n\s ]$ 中存在冗余。元字符 \s 已经包含了空格、制表符、回车符(\r)和换行符(\n)。
    • 影响分析:虽然不会导致功能错误,但显得不够专业,降低了代码的可读性。
    • 优化建议:移除冗余的 \r 和 \n,简化正则表达式。 java // 优化前 } else if (reporterName.matches(".*[\\d\\r\\n\\s ]$")) { // 优化后 } else if (reporterName.matches(".*[\\d\\s ]$")) {

    二、评分明细

    • 功能实现的正确性与健壮性(36 / 40分) 理由:基础的边界校验(如手机号正则收紧、地址长度限制、日期先后顺序对比)实现得当,逻辑清晰。扣分点在于金额校验逻辑(>0)与文案(1~200000)存在明显的语义冲突,可能导致业务数据边界模糊。

    • 安全性与潜在风险(30 / 30分) 理由:未发现 SQL 注入、越权等高危安全漏洞。对外部输入的金额、日期都进行了妥善的异常捕获和格式化校验,手机号正则收紧有效防止了脏数据。

    • 最佳实践与可维护性(17 / 20分) 理由:代码结构清晰,常量抽取(如 IMPORT_AMOUNT_MAX)符合规范。扣分点在于正则表达式存在冗余,以及 new BigDecimal(200000) 虽无 bug,但更推荐使用 BigDecimal.valueOf(200000) 这种更标准的工厂方法。

    • 性能与资源利用(2 / 5分) 理由:在导入(通常是批处理)场景的底层校验方法中,循环内高频 new SimpleDateFormat() 和 new Date() 是典型的性能反模式,会造成不必要的资源浪费。

    • 提交信息质量(5 / 5分) 理由:Commit 信息非常优秀,清晰地列出了每个字段的变更点、校验规则及修改原因,具备极高的可追溯性。

    总分:90分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!