同步功能添加对已下单的飞机不进行取消同步
This commit is contained in:
parent
af8a7d7a03
commit
7fdc0f79bf
|
@ -18,8 +18,9 @@ import java.io.Serializable;
|
|||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.chint.infrastructure.constant.SupplierNameConstant.*;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
@Table("route_request")
|
||||
|
@ -79,13 +80,49 @@ public class RouteRequest implements Serializable, EventManageable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public RouteRequest reloadGenerateRequestLegs(List<Leg> legList) {
|
||||
List<RouteRequestLeg> routeRequestLegs = legList.stream().map(RouteRequestLeg::ofLeg).toList();
|
||||
this.setRouteRequestLegList(routeRequestLegs);
|
||||
public RouteRequest loadLegInfoSelf(RouteOrder routeOrder) {
|
||||
if (this.routeRequestLegList != null && !this.routeRequestLegList.isEmpty()) {
|
||||
List<Leg> legItems = routeOrder.getLegItems();
|
||||
List<Long> list = this.routeRequestLegList.stream().map(RouteRequestLeg::getLegId).toList();
|
||||
List<Leg> legs = legItems.stream().filter(it -> list.contains(it.getLegId())).toList();
|
||||
return reloadGenerateRequestLegs(legs);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public RouteRequest reloadSupplierInfo(){
|
||||
public RouteRequest reloadGenerateRequestLegs(List<Leg> legList) {
|
||||
// 创建一个新的临时列表
|
||||
List<RouteRequestLeg> tempLegList = new ArrayList<>();
|
||||
|
||||
// 如果原列表为空,则初始化为空列表
|
||||
if (this.routeRequestLegList == null) {
|
||||
this.routeRequestLegList = new ArrayList<>();
|
||||
}
|
||||
|
||||
// 创建一个Map从legId到RouteRequestLeg进行快速查找
|
||||
Map<Long, RouteRequestLeg> existingLegsMap = this.routeRequestLegList.stream()
|
||||
.collect(Collectors.toMap(RouteRequestLeg::getLegId, Function.identity()));
|
||||
|
||||
// 遍历传入的leg列表
|
||||
for (Leg leg : legList) {
|
||||
RouteRequestLeg existingLeg = existingLegsMap.get(leg.getLegId());
|
||||
if (existingLeg != null) {
|
||||
// 如果leg已存在,更新非持久化的'leg'字段
|
||||
existingLeg.setLeg(leg);
|
||||
} else {
|
||||
// 如果是新的leg,创建一个新的RouteRequestLeg
|
||||
existingLeg = RouteRequestLeg.ofLeg(leg);
|
||||
}
|
||||
// 将更新或新创建的RouteRequestLeg添加到临时列表中
|
||||
tempLegList.add(existingLeg);
|
||||
}
|
||||
|
||||
// 使用新的临时列表替换旧的leg列表
|
||||
this.routeRequestLegList = tempLegList;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RouteRequest reloadSupplierInfo() {
|
||||
this.setSupplierName(SupplierConstantUtil.translateOrderSupplierName(this.supplier));
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.chint.infrastructure.constant.LegConstant.*;
|
||||
import static com.chint.infrastructure.constant.RouteRequestConstant.ROUTE_REQUEST_STATUS_PREPARE;
|
||||
|
@ -114,11 +116,30 @@ public class RouteRequestDomainService {
|
|||
.findFirst();
|
||||
}
|
||||
optionalRouteRequest.ifPresent(it -> {
|
||||
//这里的逻辑为发现 差旅申请单的机票行程节点 如果已经是 下单的状态, 就不进行取消, 因此实际上按照 该差旅申请单的 同步来进行
|
||||
List<Leg> legs = it.loadLegInfoSelf(routeOrder)
|
||||
.getRouteRequestLegList()
|
||||
.stream()
|
||||
.map(RouteRequestLeg::getLeg)
|
||||
.toList();
|
||||
|
||||
Map<Boolean, List<Leg>> collect = legs
|
||||
.stream()
|
||||
.collect(Collectors.partitioningBy(leg -> leg.reloadStatus().getLegStatus().equals(LEG_STATUS_ORDERED)));
|
||||
List<Leg> orderedLegs = collect.get(true);
|
||||
if (!orderedLegs.isEmpty()) {
|
||||
it.reloadGenerateRequestLegs(orderedLegs);
|
||||
syncAdapter.of(it.getSupplier()).syncRouteRequest(it);
|
||||
it.addEvent(RouteRequestEvent.sync(it.getSupplier()));
|
||||
List<Leg> notOrderLegs = collect.get(false);
|
||||
notOrderLegs.forEach(leg->leg.addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL)));
|
||||
} else {
|
||||
it.addEvent(RouteRequestEvent.cancel(it.getSupplier()));
|
||||
getLegInfoFromRouteOrder(it, routeOrder);
|
||||
syncAdapter.of(it.getSupplier()).cancelRouteRequest(it);
|
||||
it.getRouteRequestLegList()
|
||||
.forEach(requestLeg -> requestLeg.getLeg().addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL)));
|
||||
}
|
||||
});
|
||||
routeRepository.save(routeOrder);
|
||||
}
|
||||
|
@ -156,6 +177,7 @@ public class RouteRequestDomainService {
|
|||
return routeRequest.reloadGenerateRequestLegs(legItems);
|
||||
}
|
||||
|
||||
|
||||
private RouteRequest getLegInfoFromRouteOrder(RouteRequest routeRequest, RouteOrder routeOrder) {
|
||||
List<Leg> legItems = routeOrder.getLegItems();
|
||||
routeRequest.getRouteRequestLegList().forEach(it -> {
|
||||
|
|
Loading…
Reference in New Issue