From c166e430d587c3bffb3b2f2db90d8427f26ce59e Mon Sep 17 00:00:00 2001 From: lulz1 Date: Thu, 4 Jul 2024 19:47:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=9B=A0=E5=9C=B0?= =?UTF-8?q?=E7=90=86=E4=BF=A1=E6=81=AF=E7=A1=AE=E5=AE=9E=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=AE=A1=E6=89=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/queryies/OrderQuery.java | 9 +- .../chint/domain/aggregates/order/Leg.java | 11 ++- .../domain/repository/RouteRepository.java | 2 + .../domain/service/LegDomainService.java | 86 ++++++++++++------- .../service/RouteApprovalDomainService.java | 42 ++++++++- .../cache/RouteCacheService.java | 5 ++ .../repository/RouteRepositoryImpl.java | 5 ++ 7 files changed, 122 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/chint/application/queryies/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index c35e2736..279bd94a 100644 --- a/src/main/java/com/chint/application/queryies/OrderQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderQuery.java @@ -168,7 +168,9 @@ public class OrderQuery { .skip((long) (pageNum - 1) * pageSize) .limit(pageSize) .map(routeOrder -> { - legDomainService.queryLocation(routeOrder.getLegItems()); + if (legDomainService.checkLocation(routeOrder.getLegItems())) { + routeRepository.reloadRouteOrderInCache(routeOrder); + } User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId()); return getRouteOrderPageRes(routeOrder, user); }) @@ -179,7 +181,6 @@ public class OrderQuery { orderDomainService.finishOrder(it); } }); - return new PageResult<>(total, orders); } @@ -535,7 +536,9 @@ public class OrderQuery { if (routeOrder.getApprovalStatusCode() != APPROVAL_EVENT_PREPARE) { legItems.forEach(leg -> legDomainService.legCheckOrder(leg)); } - legDomainService.queryLocation(legItems); + if (legDomainService.checkLocation(legItems)) { + routeRepository.reloadRouteOrderInCache(routeOrder); + } List list = legItems.stream().map(LegRes::copyFrom).toList(); routeOrderRes.setLegResList(list); } diff --git a/src/main/java/com/chint/domain/aggregates/order/Leg.java b/src/main/java/com/chint/domain/aggregates/order/Leg.java index 4e14a468..778e1e91 100644 --- a/src/main/java/com/chint/domain/aggregates/order/Leg.java +++ b/src/main/java/com/chint/domain/aggregates/order/Leg.java @@ -429,14 +429,18 @@ public class Leg implements Serializable, EventManageable { public String generateLegString() { - return DateTimeUtil.timeToStrCommon(startTime) + "|" + + String generateStr = DateTimeUtil.timeToStrCommon(startTime) + "|" + DateTimeUtil.timeToStrCommon(endTime) + "|" + originId + "|" + destinationId + "|" + estimateAmount; + if (this.legType.equals(LEG_TYPE_TAXI)) { + return generateStr + "|" + this.getLegExtensionField().getLocationIds(); + } + return generateStr; } public Leg restoreFromLegString(String legString) { String[] parts = legString.split("\\|"); - if (parts.length == 5) { + if (parts.length >= 5) { this.startTime = parts[0] != null && !"null".equals(parts[0]) ? DateTimeUtil.strToTime(parts[0]) : null; this.endTime = parts[1] != null && !"null".equals(parts[1]) ? DateTimeUtil.strToTime(parts[1]) : null; this.originId = parts[2] != null && !"null".equals(parts[2]) ? Long.parseLong(parts[2]) : null; @@ -445,6 +449,9 @@ public class Leg implements Serializable, EventManageable { } else { throw new IllegalArgumentException("Invalid legString format."); } + if (parts.length >= 6 && parts[5] != null && !parts[5].isEmpty() && !"null".equals(parts[5])) { + this.getLegExtensionField().setLocationIds(parts[5]); + } return this; } diff --git a/src/main/java/com/chint/domain/repository/RouteRepository.java b/src/main/java/com/chint/domain/repository/RouteRepository.java index 5fab658e..4fb3f417 100644 --- a/src/main/java/com/chint/domain/repository/RouteRepository.java +++ b/src/main/java/com/chint/domain/repository/RouteRepository.java @@ -13,6 +13,8 @@ public interface RouteRepository { RouteOrder queryById(Long orderId, boolean ifUpdateCache); + RouteOrder reloadRouteOrderInCache(RouteOrder routeOrder); + List queryByIdIn(List routeIds); List queryAllInOneDayAndEffective(LocalDateTime start, LocalDateTime end); diff --git a/src/main/java/com/chint/domain/service/LegDomainService.java b/src/main/java/com/chint/domain/service/LegDomainService.java index 7b09c4b2..9d61f058 100644 --- a/src/main/java/com/chint/domain/service/LegDomainService.java +++ b/src/main/java/com/chint/domain/service/LegDomainService.java @@ -156,37 +156,57 @@ public class LegDomainService { return leg; } + public List queryLocation(List list) { - list.forEach(leg -> { - LegExtensionField legExtensionField = leg.getLegExtensionField(); - if (legExtensionField != null && legExtensionField.getLocationIds() != null) { - List locationIdsAsLong; - if (legExtensionField.getLocationIds().startsWith("[")) { - locationIdsAsLong = legExtensionField.getLocationIdsAsLongFromArray(); - } else { - locationIdsAsLong = legExtensionField.getLocationIdsAsLong(); - } - List locationList = legExtensionField.getLocationList(); - - if (locationList == null || locationList.size() != locationIdsAsLong.size() || - checkIfSameLocationList(locationList, locationIdsAsLong)) { - List byNameList = locationRepository.findByNameList(locationIdsAsLong); - legExtensionField.setLocationList(byNameList); - } - } - if (leg.getOriginId() != null && (leg.getOriginLocation() == null || - !Objects.equals(leg.getOriginLocation().getLocationId(), leg.getOriginId()))) { - leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId())); - } - - if (leg.getDestinationId() != null && (leg.getDestinationLocation() == null || - !Objects.equals(leg.getDestinationLocation().getLocationId(), leg.getDestinationId()))) { - leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId())); - } - }); + list.forEach(this::updateLegLocation); return list; } + public boolean checkLocation(List list) { + boolean flag = false; + for (Leg leg : list) { + boolean updated = updateLegLocation(leg); + if (updated) { + flag = true; + } + } + return flag; + } + + private boolean updateLegLocation(Leg leg) { + boolean updated = false; + LegExtensionField legExtensionField = leg.getLegExtensionField(); + if (legExtensionField != null && legExtensionField.getLocationIds() != null) { + List locationIdsAsLong = getLocationIdsAsLong(legExtensionField); + List locationList = legExtensionField.getLocationList(); + if (locationList == null || locationList.size() != locationIdsAsLong.size() || + checkIfSameLocationList(locationList, locationIdsAsLong)) { + List byNameList = locationRepository.findByNameList(locationIdsAsLong); + legExtensionField.setLocationList(byNameList); + updated = true; + } + } + if (leg.getOriginId() != null && (leg.getOriginLocation() == null || + !Objects.equals(leg.getOriginLocation().getLocationId(), leg.getOriginId()))) { + leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId())); + updated = true; + } + if (leg.getDestinationId() != null && (leg.getDestinationLocation() == null || + !Objects.equals(leg.getDestinationLocation().getLocationId(), leg.getDestinationId()))) { + leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId())); + updated = true; + } + return updated; + } + + private List getLocationIdsAsLong(LegExtensionField legExtensionField) { + if (legExtensionField.getLocationIds().startsWith("[")) { + return legExtensionField.getLocationIdsAsLongFromArray(); + } else { + return legExtensionField.getLocationIdsAsLong(); + } + } + private boolean checkIfSameLocationList(List locationList, List locationIdsAsLong) { List inIds = locationList.stream().map(Location::getLocationId).toList(); // 检查两个列表是否相互包含 @@ -212,7 +232,6 @@ public class LegDomainService { if (leg.getOriginId() != null && leg.getOriginLocation() == null) { leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId())); } - if (leg.getDestinationId() != null && leg.getDestinationLocation() == null) { leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId())); } @@ -245,10 +264,19 @@ public class LegDomainService { .toList(); + List legs = new ArrayList<>(); + for (Leg leg : legItems) { + if (!leg.getLegType().equals(LEG_TYPE_OTHER) && leg.legIsInternal()) { + leg.reloadStatus(); + // 不再过滤LegApprovalStatus + legs.add(leg); + } + } + // 根据供应商名称查找供应商并进行处理 return supplierRepository.findBySupplierName(supplierName) .map(supplier -> { - List syncAbleLegItems = ifCanSync(filteredLegItems, routeOrder, supplier); + List syncAbleLegItems = ifCanSync(legs, routeOrder, supplier); syncAbleLegItems.forEach(Leg::reloadStatus); return syncAbleLegItems; }) diff --git a/src/main/java/com/chint/domain/service/RouteApprovalDomainService.java b/src/main/java/com/chint/domain/service/RouteApprovalDomainService.java index 5f5bc73c..d8dda049 100644 --- a/src/main/java/com/chint/domain/service/RouteApprovalDomainService.java +++ b/src/main/java/com/chint/domain/service/RouteApprovalDomainService.java @@ -1,6 +1,8 @@ package com.chint.domain.service; import com.chint.application.dtos.LegApprovalParam; +import com.chint.domain.aggregates.approval.ApprovalData; +import com.chint.domain.aggregates.approval.ApprovalProcess; import com.chint.domain.aggregates.approval.ApprovalResultData; import com.chint.domain.aggregates.approval.ApprovalSubmit; import com.chint.domain.aggregates.base.PermissionConfig; @@ -13,6 +15,7 @@ import com.chint.domain.repository.*; import com.chint.domain.value_object.enums.RoutePermission; import com.chint.infrastructure.util.StringCheck; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.util.Pair; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -46,6 +49,7 @@ public class RouteApprovalDomainService { @Autowired private ApprovalSubmit approvalSubmit; + public void legApprovalResponse() { } @@ -64,18 +68,46 @@ public class RouteApprovalDomainService { List legItems = routeOrder.getLegItems(); legDomainService.queryLocation(legItems); String approvalPlatformMark = getApprovalPlatformMark(routeOrder); - ApprovalSubmit.of(LEG_ADD_CHANGE_BATCH, approvalPlatformMark) - .approveData(routeOrder) - .record(it -> it.setApprovalReason(param.getApprovalReason())) + ApprovalProcess approvalProcess = ApprovalSubmit.of(LEG_ADD_CHANGE_BATCH, approvalPlatformMark) + .approveData(routeOrder); + checkApprovalData(approvalProcess.getApprovalData()); + approvalProcess.record(it -> it.setApprovalReason(param.getApprovalReason())) .submitToBpm(); routeRepository.save(routeOrder); } + private void checkApprovalData(ApprovalData approvalData) { + List allLegs = new ArrayList<>(); + // 添加单个 leg 对象 + if (approvalData.getLeg() != null) { + allLegs.add(approvalData.getLeg()); + } + + // 添加单个 oldLeg 对象 + if (approvalData.getOldLeg() != null) { + allLegs.add(approvalData.getOldLeg()); + } + + // 添加 addLegList 中的 Leg 对象 + if (approvalData.getAddLegList() != null) { + allLegs.addAll(approvalData.getAddLegList()); + } + + // 添加 changeLegList 中的 Leg 对象 + if (approvalData.getChangeLegList() != null) { + for (Pair pair : approvalData.getChangeLegList()) { + allLegs.add(pair.getFirst()); + allLegs.add(pair.getSecond()); + } + } + legDomainService.checkLocation(allLegs); + } + public List checkApprovalPermissions(List routeOrderList) { // 提取所有 approveOrderNo 和 sysCode Set accountCompanyCodes = routeOrderList.stream() .map(routeOrder -> routeOrder.getApproveOrderNo().getAccountCompany()) - .filter(it-> !StringCheck.isFirstCharacterChinese(it)) + .filter(it -> !StringCheck.isFirstCharacterChinese(it)) .collect(Collectors.toSet()); Set sysCodes = routeOrderList.stream() @@ -140,11 +172,13 @@ public class RouteApprovalDomainService { } return routeOrder; } + private String findApprovalType(ApproveOrderNo approveOrderNo) { return systemOrganizationRepository.findByOrgCodeContainingOrOrgNameContaining(approveOrderNo.getAccountCompany(), approveOrderNo.getAccountCompany()) .map(SystemOrganization::getApprovalType) .orElseGet(() -> systemCodeRepository.findBySysCode(approveOrderNo.getSysCode()).getApprovalType()); } + private Set findRoutePermissions(String approvalType) { return permissionConfigRepository.findByPermissionName(approvalType) .map(permissionConfig -> permissionConfig.permissions().stream() diff --git a/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java b/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java index ef6fdaaf..17cf822e 100644 --- a/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java +++ b/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java @@ -50,6 +50,11 @@ public class RouteCacheService { return routeOrders; } + public RouteOrder reloadRouteOrderInCache(RouteOrder routeOrder) { + routeCacheManage.invalidateRouteCache(routeOrder.getRouteId()); + routeCacheManage.cacheRouteOrder(routeOrder); + return routeOrder; + } public List getUserRoutes(String employeeNo) { //获取当前用户所有的订单id diff --git a/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java index b5054264..62856dbb 100644 --- a/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/RouteRepositoryImpl.java @@ -49,6 +49,11 @@ public class RouteRepositoryImpl implements RouteRepository { return null; } + @Override + public RouteOrder reloadRouteOrderInCache(RouteOrder routeOrder) { + return routeCacheService.reloadRouteOrderInCache(routeOrder); + } + @Override public List queryByIdIn(List routeIds) { List routeOrders = new java.util.ArrayList<>(routeCacheService.queryByIdIn(routeIds)