|
|
@@ -264,17 +264,43 @@ public class DateUtil {
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ private static String extractDate(String text) {
|
|
|
+ java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("\\d{4}-\\d{2}-\\d{2}");
|
|
|
+ java.util.regex.Matcher matcher = pattern.matcher(text);
|
|
|
+ if (matcher.find()) {
|
|
|
+ return matcher.group();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
public static void main(String[] args) throws ParseException {
|
|
|
|
|
|
-// System.out.println(dayOfLastMonth(new Date()));
|
|
|
- System.err.println("前一年:"+gainFrontOneYear());
|
|
|
+ // 1. 获取错误信息
|
|
|
+ String errorMsg = "警告:号牌号码“晋J9U932”的保单发生重复投保,与其重复投保的其它公司的保单信息如下:投保确认码 02TSBX140025042205658922278833;保单号 211010303202025002156;起保日期 2025-04-29 00:00;终保日期 2026-04-29 00:00;号牌号码 晋JBG599;号牌种类 02;车架号 LDNBCTGZ0J0148207;发动机号 S2ML797;地区 山西。重复投保保单号:211010303362025001909;保险公司代码:TSBX;null:机动车第三者责任险,机动车车上人员责任险(司机),机动车车上人员责任险(乘客),医保外医疗费用责任险(第三者责任保险);号牌号码:晋JBG599;号牌种类代码:02;号牌底色:01;车辆识别代号:LDNBCTGZ0J0148207;发动机号:S2ML797;起保日期:2025-04-27 00:00:00;终保日期:2026-04-27 00:00:00;签单日期:2025-04-26 00:00:00;";
|
|
|
+
|
|
|
+ String firstStartDate = null; // 第一次起保日期
|
|
|
+ String secondStartDate = null; // 第二次起保日期
|
|
|
|
|
|
+ if (errorMsg != null) {
|
|
|
+ // ========== 提取 第一次 起保日期 ==========
|
|
|
+ int firstIndex = errorMsg.indexOf("起保日期");
|
|
|
+ if (firstIndex != -1) {
|
|
|
+ // 从关键词往后截取20个字符(足够拿到日期)
|
|
|
+ String firstSub = errorMsg.substring(firstIndex, firstIndex + 20);
|
|
|
+ // 简单正则提取 2025-xx-xx 格式日期
|
|
|
+ firstStartDate = extractDate(firstSub);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ========== 提取 第二次 起保日期 ==========
|
|
|
+ int secondIndex = errorMsg.indexOf("起保日期", firstIndex + 1);
|
|
|
+ if (secondIndex != -1) {
|
|
|
+ String secondSub = errorMsg.substring(secondIndex, secondIndex + 20);
|
|
|
+ secondStartDate = extractDate(secondSub);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //获取本月的第一天
|
|
|
- LocalDate now = LocalDate.now();
|
|
|
- LocalDate firstDayOfThisMonth = now.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
- System.out.println("firstDayOfThisMonth = " + firstDayOfThisMonth); //2018-09-01
|
|
|
+// 输出结果(你可以替换成业务逻辑)
|
|
|
+ System.out.println("第一次起保日期:" + firstStartDate);
|
|
|
+ System.out.println("第二次起保日期:" + secondStartDate);
|
|
|
}
|
|
|
}
|