fix:修复因地理信息确实导致无法审批的问题

This commit is contained in:
lulz1 2024-07-04 19:47:25 +08:00
parent d97da29c2f
commit c166e430d5
7 changed files with 122 additions and 38 deletions

View File

@ -168,7 +168,9 @@ public class OrderQuery {
.skip((long) (pageNum - 1) * pageSize) .skip((long) (pageNum - 1) * pageSize)
.limit(pageSize) .limit(pageSize)
.map(routeOrder -> { .map(routeOrder -> {
legDomainService.queryLocation(routeOrder.getLegItems()); if (legDomainService.checkLocation(routeOrder.getLegItems())) {
routeRepository.reloadRouteOrderInCache(routeOrder);
}
User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId()); User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId());
return getRouteOrderPageRes(routeOrder, user); return getRouteOrderPageRes(routeOrder, user);
}) })
@ -179,7 +181,6 @@ public class OrderQuery {
orderDomainService.finishOrder(it); orderDomainService.finishOrder(it);
} }
}); });
return new PageResult<>(total, orders); return new PageResult<>(total, orders);
} }
@ -535,7 +536,9 @@ public class OrderQuery {
if (routeOrder.getApprovalStatusCode() != APPROVAL_EVENT_PREPARE) { if (routeOrder.getApprovalStatusCode() != APPROVAL_EVENT_PREPARE) {
legItems.forEach(leg -> legDomainService.legCheckOrder(leg)); legItems.forEach(leg -> legDomainService.legCheckOrder(leg));
} }
legDomainService.queryLocation(legItems); if (legDomainService.checkLocation(legItems)) {
routeRepository.reloadRouteOrderInCache(routeOrder);
}
List<LegRes> list = legItems.stream().map(LegRes::copyFrom).toList(); List<LegRes> list = legItems.stream().map(LegRes::copyFrom).toList();
routeOrderRes.setLegResList(list); routeOrderRes.setLegResList(list);
} }

View File

@ -429,14 +429,18 @@ public class Leg implements Serializable, EventManageable {
public String generateLegString() { public String generateLegString() {
return DateTimeUtil.timeToStrCommon(startTime) + "|" + String generateStr = DateTimeUtil.timeToStrCommon(startTime) + "|" +
DateTimeUtil.timeToStrCommon(endTime) + "|" + DateTimeUtil.timeToStrCommon(endTime) + "|" +
originId + "|" + destinationId + "|" + estimateAmount; originId + "|" + destinationId + "|" + estimateAmount;
if (this.legType.equals(LEG_TYPE_TAXI)) {
return generateStr + "|" + this.getLegExtensionField().getLocationIds();
}
return generateStr;
} }
public Leg restoreFromLegString(String legString) { public Leg restoreFromLegString(String legString) {
String[] parts = legString.split("\\|"); 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.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.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; 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 { } else {
throw new IllegalArgumentException("Invalid legString format."); 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; return this;
} }

View File

@ -13,6 +13,8 @@ public interface RouteRepository {
RouteOrder queryById(Long orderId, boolean ifUpdateCache); RouteOrder queryById(Long orderId, boolean ifUpdateCache);
RouteOrder reloadRouteOrderInCache(RouteOrder routeOrder);
List<RouteOrder> queryByIdIn(List<Long> routeIds); List<RouteOrder> queryByIdIn(List<Long> routeIds);
List<RouteOrder> queryAllInOneDayAndEffective(LocalDateTime start, LocalDateTime end); List<RouteOrder> queryAllInOneDayAndEffective(LocalDateTime start, LocalDateTime end);

View File

@ -156,35 +156,55 @@ public class LegDomainService {
return leg; return leg;
} }
public List<Leg> queryLocation(List<Leg> list) { public List<Leg> queryLocation(List<Leg> list) {
list.forEach(leg -> { list.forEach(this::updateLegLocation);
return list;
}
public boolean checkLocation(List<Leg> 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(); LegExtensionField legExtensionField = leg.getLegExtensionField();
if (legExtensionField != null && legExtensionField.getLocationIds() != null) { if (legExtensionField != null && legExtensionField.getLocationIds() != null) {
List<Long> locationIdsAsLong; List<Long> locationIdsAsLong = getLocationIdsAsLong(legExtensionField);
if (legExtensionField.getLocationIds().startsWith("[")) {
locationIdsAsLong = legExtensionField.getLocationIdsAsLongFromArray();
} else {
locationIdsAsLong = legExtensionField.getLocationIdsAsLong();
}
List<Location> locationList = legExtensionField.getLocationList(); List<Location> locationList = legExtensionField.getLocationList();
if (locationList == null || locationList.size() != locationIdsAsLong.size() || if (locationList == null || locationList.size() != locationIdsAsLong.size() ||
checkIfSameLocationList(locationList, locationIdsAsLong)) { checkIfSameLocationList(locationList, locationIdsAsLong)) {
List<Location> byNameList = locationRepository.findByNameList(locationIdsAsLong); List<Location> byNameList = locationRepository.findByNameList(locationIdsAsLong);
legExtensionField.setLocationList(byNameList); legExtensionField.setLocationList(byNameList);
updated = true;
} }
} }
if (leg.getOriginId() != null && (leg.getOriginLocation() == null || if (leg.getOriginId() != null && (leg.getOriginLocation() == null ||
!Objects.equals(leg.getOriginLocation().getLocationId(), leg.getOriginId()))) { !Objects.equals(leg.getOriginLocation().getLocationId(), leg.getOriginId()))) {
leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId())); leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId()));
updated = true;
} }
if (leg.getDestinationId() != null && (leg.getDestinationLocation() == null || if (leg.getDestinationId() != null && (leg.getDestinationLocation() == null ||
!Objects.equals(leg.getDestinationLocation().getLocationId(), leg.getDestinationId()))) { !Objects.equals(leg.getDestinationLocation().getLocationId(), leg.getDestinationId()))) {
leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId())); leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId()));
updated = true;
}
return updated;
}
private List<Long> getLocationIdsAsLong(LegExtensionField legExtensionField) {
if (legExtensionField.getLocationIds().startsWith("[")) {
return legExtensionField.getLocationIdsAsLongFromArray();
} else {
return legExtensionField.getLocationIdsAsLong();
} }
});
return list;
} }
private boolean checkIfSameLocationList(List<Location> locationList, List<Long> locationIdsAsLong) { private boolean checkIfSameLocationList(List<Location> locationList, List<Long> locationIdsAsLong) {
@ -212,7 +232,6 @@ public class LegDomainService {
if (leg.getOriginId() != null && leg.getOriginLocation() == null) { if (leg.getOriginId() != null && leg.getOriginLocation() == null) {
leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId())); leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId()));
} }
if (leg.getDestinationId() != null && leg.getDestinationLocation() == null) { if (leg.getDestinationId() != null && leg.getDestinationLocation() == null) {
leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId())); leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId()));
} }
@ -245,10 +264,19 @@ public class LegDomainService {
.toList(); .toList();
List<Leg> 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) return supplierRepository.findBySupplierName(supplierName)
.map(supplier -> { .map(supplier -> {
List<Leg> syncAbleLegItems = ifCanSync(filteredLegItems, routeOrder, supplier); List<Leg> syncAbleLegItems = ifCanSync(legs, routeOrder, supplier);
syncAbleLegItems.forEach(Leg::reloadStatus); syncAbleLegItems.forEach(Leg::reloadStatus);
return syncAbleLegItems; return syncAbleLegItems;
}) })

View File

@ -1,6 +1,8 @@
package com.chint.domain.service; package com.chint.domain.service;
import com.chint.application.dtos.LegApprovalParam; 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.ApprovalResultData;
import com.chint.domain.aggregates.approval.ApprovalSubmit; import com.chint.domain.aggregates.approval.ApprovalSubmit;
import com.chint.domain.aggregates.base.PermissionConfig; 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.domain.value_object.enums.RoutePermission;
import com.chint.infrastructure.util.StringCheck; import com.chint.infrastructure.util.StringCheck;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -46,6 +49,7 @@ public class RouteApprovalDomainService {
@Autowired @Autowired
private ApprovalSubmit approvalSubmit; private ApprovalSubmit approvalSubmit;
public void legApprovalResponse() { public void legApprovalResponse() {
} }
@ -64,13 +68,41 @@ public class RouteApprovalDomainService {
List<Leg> legItems = routeOrder.getLegItems(); List<Leg> legItems = routeOrder.getLegItems();
legDomainService.queryLocation(legItems); legDomainService.queryLocation(legItems);
String approvalPlatformMark = getApprovalPlatformMark(routeOrder); String approvalPlatformMark = getApprovalPlatformMark(routeOrder);
ApprovalSubmit.of(LEG_ADD_CHANGE_BATCH, approvalPlatformMark) ApprovalProcess approvalProcess = ApprovalSubmit.of(LEG_ADD_CHANGE_BATCH, approvalPlatformMark)
.approveData(routeOrder) .approveData(routeOrder);
.record(it -> it.setApprovalReason(param.getApprovalReason())) checkApprovalData(approvalProcess.getApprovalData());
approvalProcess.record(it -> it.setApprovalReason(param.getApprovalReason()))
.submitToBpm(); .submitToBpm();
routeRepository.save(routeOrder); routeRepository.save(routeOrder);
} }
private void checkApprovalData(ApprovalData approvalData) {
List<Leg> 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<Leg, Leg> pair : approvalData.getChangeLegList()) {
allLegs.add(pair.getFirst());
allLegs.add(pair.getSecond());
}
}
legDomainService.checkLocation(allLegs);
}
public List<RouteOrder> checkApprovalPermissions(List<RouteOrder> routeOrderList) { public List<RouteOrder> checkApprovalPermissions(List<RouteOrder> routeOrderList) {
// 提取所有 approveOrderNo sysCode // 提取所有 approveOrderNo sysCode
Set<String> accountCompanyCodes = routeOrderList.stream() Set<String> accountCompanyCodes = routeOrderList.stream()
@ -140,11 +172,13 @@ public class RouteApprovalDomainService {
} }
return routeOrder; return routeOrder;
} }
private String findApprovalType(ApproveOrderNo approveOrderNo) { private String findApprovalType(ApproveOrderNo approveOrderNo) {
return systemOrganizationRepository.findByOrgCodeContainingOrOrgNameContaining(approveOrderNo.getAccountCompany(), approveOrderNo.getAccountCompany()) return systemOrganizationRepository.findByOrgCodeContainingOrOrgNameContaining(approveOrderNo.getAccountCompany(), approveOrderNo.getAccountCompany())
.map(SystemOrganization::getApprovalType) .map(SystemOrganization::getApprovalType)
.orElseGet(() -> systemCodeRepository.findBySysCode(approveOrderNo.getSysCode()).getApprovalType()); .orElseGet(() -> systemCodeRepository.findBySysCode(approveOrderNo.getSysCode()).getApprovalType());
} }
private Set<RoutePermission> findRoutePermissions(String approvalType) { private Set<RoutePermission> findRoutePermissions(String approvalType) {
return permissionConfigRepository.findByPermissionName(approvalType) return permissionConfigRepository.findByPermissionName(approvalType)
.map(permissionConfig -> permissionConfig.permissions().stream() .map(permissionConfig -> permissionConfig.permissions().stream()

View File

@ -50,6 +50,11 @@ public class RouteCacheService {
return routeOrders; return routeOrders;
} }
public RouteOrder reloadRouteOrderInCache(RouteOrder routeOrder) {
routeCacheManage.invalidateRouteCache(routeOrder.getRouteId());
routeCacheManage.cacheRouteOrder(routeOrder);
return routeOrder;
}
public List<RouteOrder> getUserRoutes(String employeeNo) { public List<RouteOrder> getUserRoutes(String employeeNo) {
//获取当前用户所有的订单id //获取当前用户所有的订单id

View File

@ -49,6 +49,11 @@ public class RouteRepositoryImpl implements RouteRepository {
return null; return null;
} }
@Override
public RouteOrder reloadRouteOrderInCache(RouteOrder routeOrder) {
return routeCacheService.reloadRouteOrderInCache(routeOrder);
}
@Override @Override
public List<RouteOrder> queryByIdIn(List<Long> routeIds) { public List<RouteOrder> queryByIdIn(List<Long> routeIds) {
List<RouteOrder> routeOrders = new java.util.ArrayList<>(routeCacheService.queryByIdIn(routeIds) List<RouteOrder> routeOrders = new java.util.ArrayList<>(routeCacheService.queryByIdIn(routeIds)