From 4d53ece9f8ac9eb83d485d9b9b8bcc3e6cb6aaf2 Mon Sep 17 00:00:00 2001 From: xuhaihui <2098865055@qq.com> Date: Tue, 5 Aug 2025 14:10:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=AE=E6=97=85=E6=8A=A5=E9=94=80=E5=8D=95?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=8C=89=E9=92=AE=E6=93=8D=E4=BD=9C=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TravelItineraryTimeValidatorSubOp.java | 80 +++++++++++++++---- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/TravelItineraryTimeValidatorSubOp.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/TravelItineraryTimeValidatorSubOp.java index 74378d6..3934e30 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/TravelItineraryTimeValidatorSubOp.java +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/TravelItineraryTimeValidatorSubOp.java @@ -29,6 +29,8 @@ public class TravelItineraryTimeValidatorSubOp extends AbstractOperationServiceP e.getFieldKeys().add("tripentry");//行程信息分录 e.getFieldKeys().add("startdate");//行程开始时间 e.getFieldKeys().add("enddate");//行程结束时间 + e.getFieldKeys().add("from");//出发地 + e.getFieldKeys().add("to");//目的地 } @Override @@ -49,26 +51,76 @@ public class TravelItineraryTimeValidatorSubOp extends AbstractOperationServiceP if (OrgCheckUtils.isKS(companyId)) { //仅针对矿山下组织下的逻辑 DynamicObjectCollection tripEntryCollection = dataEntity.getDynamicObjectCollection("tripentry");//行程信息 - Set startDateSet = new HashSet<>(); - Set endDateSet = new HashSet<>(); + Set startDateSet = new HashSet<>();//开始时间 + Set endDateSet = new HashSet<>();//结束时间 + Set fromStartCombinationSet = new HashSet<>(); // 出发地+开始时间组合 + Set toEndCombinationSet = new HashSet<>(); // 目的地+结束时间组合 + Set matchedFromStartCombinations = new HashSet<>(); + Set matchedToEndCombinations = new HashSet<>(); for (DynamicObject tripEntry : tripEntryCollection) { Date startDate = tripEntry.getDate("startdate");//开始日期 Date endDate = tripEntry.getDate("enddate");//结束日期 - // 校验开始日期是否重复 - if (startDate != null) { - if (startDateSet.contains(startDate)) { - this.addFatalErrorMessage(extendedDataEntity, "存在相同的行程开始日期,请检查行程信息!"); - return; - } - startDateSet.add(startDate); + DynamicObject from = tripEntry.getDynamicObject("from");//出发地 + DynamicObject to = tripEntry.getDynamicObject("to");//目的地 + + // 构建组合键 + String fromStartKey = null; + String toEndKey = null; + + if (from != null && startDate != null) { + Long fromId = from.getLong("id"); + fromStartKey = fromId + "_" + startDate.getTime(); } - // 校验结束日期是否重复 - if (endDate != null) { - if (endDateSet.contains(endDate)) { - this.addFatalErrorMessage(extendedDataEntity, "存在相同的行程结束日期,请检查行程信息!"); + + if (to != null && endDate != null) { + Long toId = to.getLong("id"); + toEndKey = toId + "_" + endDate.getTime(); + } + + // 检查是否存在"出发地+开始时间"与"目的地+结束时间"相同的组合 + if (fromStartKey != null && toEndKey != null && fromStartKey.equals(toEndKey)) { + matchedFromStartCombinations.add(fromStartKey); + matchedToEndCombinations.add(toEndKey); + } + +// // 分别校验开始日期是否重复 +// if (startDate != null) { +// if (startDateSet.contains(startDate)) { +// this.addFatalErrorMessage(extendedDataEntity, "存在相同的行程开始日期,请检查行程信息!"); +// return; +// } +// startDateSet.add(startDate); +// } +// +// // 分别校验结束日期是否重复 +// if (endDate != null) { +// if (endDateSet.contains(endDate)) { +// this.addFatalErrorMessage(extendedDataEntity, "存在相同的行程结束日期,请检查行程信息!"); +// return; +// } +// endDateSet.add(endDate); +// } + + // 校验出发地+开始时间组合是否重复(排除与目的地+结束时间相同的组合) + if (fromStartKey != null) { + // 如果这个组合在matchedFromStartCombinations中,则允许重复 + if (fromStartCombinationSet.contains(fromStartKey) + && !matchedFromStartCombinations.contains(fromStartKey)) { + this.addFatalErrorMessage(extendedDataEntity, "存在相同的出发地和开始时间组合,请检查行程信息!"); return; } - endDateSet.add(endDate); + fromStartCombinationSet.add(fromStartKey); + } + + // 校验目的地+结束时间组合是否重复(排除与出发地+开始时间相同的组合) + if (toEndKey != null) { + // 如果这个组合在matchedToEndCombinations中,则允许重复 + if (toEndCombinationSet.contains(toEndKey) + && !matchedToEndCombinations.contains(toEndKey)) { + this.addFatalErrorMessage(extendedDataEntity, "存在相同的目的地和结束时间组合,请检查行程信息!"); + return; + } + toEndCombinationSet.add(toEndKey); } } }