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

This commit is contained in:
lulz1 2024-07-04 17:03:36 +08:00
parent 38a66b1037
commit 546a07f008
2 changed files with 15 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.exceptions.CommandException;
import com.chint.domain.repository.ApprovalRecordRepository;
import com.chint.domain.repository.RouteRepository;
import com.chint.domain.service.LegDomainService;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
@ -31,6 +32,9 @@ public class ApprovalSubmit implements ApplicationListener<ApplicationReadyEvent
@Autowired
private RouteRepository routeRepository;
@Autowired
private LegDomainService legDomainService;
@Override
public void onApplicationEvent(@NotNull ApplicationReadyEvent event) {
@ -90,6 +94,7 @@ public class ApprovalSubmit implements ApplicationListener<ApplicationReadyEvent
ApprovalRecord.successApprovalStatus() :
ApprovalRecord.rejectApprovalStatus());
approvalRecord.setApprovalResponseDate(LocalDateTime.now());
legDomainService.queryLocation(routeOrder.getLegItems());
routeRepository.save(routeOrder);
}
}

View File

@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
@ -166,7 +167,9 @@ public class LegDomainService {
locationIdsAsLong = legExtensionField.getLocationIdsAsLong();
}
List<Location> locationList = legExtensionField.getLocationList();
if (locationList == null || locationList.size() != locationIdsAsLong.size()) {
if (locationList == null || locationList.size() != locationIdsAsLong.size() ||
checkIfSameLocationList(locationList, locationIdsAsLong)) {
List<Location> byNameList = locationRepository.findByNameList(locationIdsAsLong);
legExtensionField.setLocationList(byNameList);
}
@ -184,6 +187,12 @@ public class LegDomainService {
return list;
}
private boolean checkIfSameLocationList(List<Location> locationList, List<Long> locationIdsAsLong) {
List<Long> inIds = locationList.stream().map(Location::getLocationId).toList();
// 检查两个列表是否相互包含
return new HashSet<>(locationIdsAsLong).containsAll(inIds) && new HashSet<>(inIds).containsAll(locationIdsAsLong);
}
public List<LegItinerary> queryLocationByLeg(List<LegItinerary> list) {
list.forEach(leg -> {
LegExtensionField legExtensionField = leg.getLegExtensionField();