diff --git a/src/main/java/com/chint/application/commands/LegSyncCommand.java b/src/main/java/com/chint/application/commands/LegSyncCommand.java index f43c51f4..60ab5c35 100644 --- a/src/main/java/com/chint/application/commands/LegSyncCommand.java +++ b/src/main/java/com/chint/application/commands/LegSyncCommand.java @@ -10,6 +10,7 @@ import static com.chint.infrastructure.constant.LegConstant.LEG_EVENT_NOT_ORDERE public class LegSyncCommand extends Command { private Integer LegEventType = LEG_EVENT_NOT_ORDERED; private SyncLegData data; + private Integer ifRouteRequestSync; //是否是差旅申请单同步方式 // public LegSyncCommand legId(Long LegId) { // this.setLegId(LegId); diff --git a/src/main/java/com/chint/application/in/RouteRequestController.java b/src/main/java/com/chint/application/in/RouteRequestController.java new file mode 100644 index 00000000..7cf17e05 --- /dev/null +++ b/src/main/java/com/chint/application/in/RouteRequestController.java @@ -0,0 +1,23 @@ +package com.chint.application.in; + +import com.chint.domain.value_object.SyncLegData; +import com.chint.infrastructure.util.Result; +import io.swagger.annotations.ApiOperation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/route/request") +public class RouteRequestController { + + @Transactional + @ApiOperation("根据整个行程规划单到差旅平台") + @PostMapping("/sync/whole") + public Result syncByWholeRouterOrder(@RequestBody SyncLegData syncLegData) { + + return null; + } +} diff --git a/src/main/java/com/chint/application/queryies/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index 0a0ab8d4..022e02ba 100644 --- a/src/main/java/com/chint/application/queryies/OrderQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderQuery.java @@ -432,11 +432,6 @@ public class OrderQuery { .nightCount(leg.nightCount().toString()); } -// if (leg.getLegType().equals(LEG_TYPE_OTHER) && leg.getLegExtensionField().getAmountType().equals(LEG_OTHER_AMOUNT_TYPE_VISA)) { -// scheduleDetailBuilder.expenseTypeId("6770f575013211eabce29fde958f48e4") -// .travelType("LOCAL_OTHER"); -// } - if (leg.getCurrencyType() != null) { scheduleDetailBuilder .currencyName(leg.getCurrencyType().getDescription()) @@ -461,8 +456,15 @@ public class OrderQuery { } } + if (leg.getLegType().equals(LEG_TYPE_OTHER) && Objects.requireNonNull(leg.getLegExtensionField()).getAmountType().equals(LEG_OTHER_AMOUNT_TYPE_VISA)) { + scheduleDetailBuilder.expenseTypeId("6770f575013211eabce29fde958f48e4") + .travelType("LOCAL_OTHER") + .scheduleType("visa"); + } else { + scheduleDetailBuilder.scheduleType(translateLegType(leg.getLegType())); + } + return scheduleDetailBuilder - .scheduleType(translateLegType(leg.getLegType())) .scheduleNum(leg.getLegNo()) .startDate(simpleFormatter.format(leg.getStartTime())) .endDate(simpleFormatter.format(leg.getEndTime())) diff --git a/src/main/java/com/chint/domain/aggregates/base/BaseEvent.java b/src/main/java/com/chint/domain/aggregates/base/BaseEvent.java index 6da859ab..715f2312 100644 --- a/src/main/java/com/chint/domain/aggregates/base/BaseEvent.java +++ b/src/main/java/com/chint/domain/aggregates/base/BaseEvent.java @@ -1,6 +1,7 @@ package com.chint.domain.aggregates.base; import lombok.Data; +import org.springframework.data.annotation.Transient; import java.io.Serial; import java.io.Serializable; @@ -15,6 +16,7 @@ public abstract class BaseEvent implements Serializable { private Integer eventType; + @Transient private transient String eventName; private LocalDateTime happenTime = LocalDateTime.now(); diff --git a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java index d4d41ccb..2267a8fb 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java @@ -159,6 +159,14 @@ public class RouteOrder implements Serializable { return this; } + public RouteOrder addRouteRequest(RouteRequest routeRequest) { + if (this.routeRequestList == null) { + this.routeRequestList = new ArrayList<>(); + } + this.routeRequestList.add(routeRequest); + return this; + } + public RouteOrder deleteLeg(String legNo) { if (this.legItems == null || this.legItems.isEmpty()) { return this; diff --git a/src/main/java/com/chint/domain/aggregates/order/RouteRequest.java b/src/main/java/com/chint/domain/aggregates/order/RouteRequest.java index 3dc86a58..fd55321a 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteRequest.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteRequest.java @@ -1,5 +1,6 @@ package com.chint.domain.aggregates.order; +import com.chint.domain.aggregates.base.BaseEvent; import com.chint.domain.aggregates.base.EventManageable; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; @@ -31,6 +32,7 @@ public class RouteRequest implements Serializable, EventManageable { private String RouteRequestNo; + private String supplier; @MappedCollection(idColumn = "route_request_id", keyColumn = "route_request_key") private List routeRequestLegList; @@ -40,8 +42,7 @@ public class RouteRequest implements Serializable, EventManageable { @MappedCollection(idColumn = "route_request_id") private RouteRequestFields routeRequestFields; - @Transient - private String supplier; + @Transient private Integer status; @Transient @@ -61,4 +62,17 @@ public class RouteRequest implements Serializable, EventManageable { public List getEvents() { return this.eventList; } + + public RouteRequest reloadStatus() { + BaseEvent lastEvent = this.getLastEvent().reloadStatus(); + this.status = lastEvent.getEventType(); + this.statusName = lastEvent.getEventName(); + return this; + } + + public RouteRequest reloadGenerateRequestLegs(List legList) { + List routeRequestLegs = legList.stream().map(RouteRequestLeg::ofLeg).toList(); + this.setRouteRequestLegList(routeRequestLegs); + return this; + } } diff --git a/src/main/java/com/chint/domain/aggregates/order/RouteRequestEvent.java b/src/main/java/com/chint/domain/aggregates/order/RouteRequestEvent.java index eab2d678..c5026ab3 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteRequestEvent.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteRequestEvent.java @@ -30,4 +30,24 @@ public class RouteRequestEvent extends BaseEvent implements Serializable { ROUTE_REQUEST_STATUS_SYNC, ROUTE_REQUEST_STATUS_SYNC_NAME, ROUTE_REQUEST_STATUS_CANCEL, ROUTE_REQUEST_STATUS_CANCEL_NAME); } + + public static RouteRequestEvent prepare(){ + RouteRequestEvent routeRequestEvent = new RouteRequestEvent(); + routeRequestEvent.setEventType(ROUTE_REQUEST_STATUS_PREPARE); + return routeRequestEvent; + } + + public static RouteRequestEvent sync(String supplierName){ + RouteRequestEvent routeRequestEvent = new RouteRequestEvent(); + routeRequestEvent.setEventType(ROUTE_REQUEST_STATUS_SYNC); + routeRequestEvent.setExtension(supplierName); + return routeRequestEvent; + } + + public static RouteRequestEvent cancel(String supplierName){ + RouteRequestEvent routeRequestEvent = new RouteRequestEvent(); + routeRequestEvent.setEventType(ROUTE_REQUEST_STATUS_CANCEL); + routeRequestEvent.setExtension(supplierName); + return routeRequestEvent; + } } diff --git a/src/main/java/com/chint/domain/aggregates/order/RouteRequestFields.java b/src/main/java/com/chint/domain/aggregates/order/RouteRequestFields.java index a7e3a081..11000c6c 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteRequestFields.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteRequestFields.java @@ -29,6 +29,8 @@ public class RouteRequestFields implements Serializable { private String accountCompanyName; @ApiModelProperty("入账公司64位编码") private String accountCompanyCode; + @ApiModelProperty("费用归属部门") + private String belongDeptCode; @ApiModelProperty("项目名称") private String projectName; @ApiModelProperty("成本中心") diff --git a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java index 3d169756..6311d637 100644 --- a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java +++ b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java @@ -79,13 +79,17 @@ public class OrderCarRecord extends OrderBaseRecord { public OrderCarRecord loadTravelInfo(String startTime, String arriveTime, String fromCity, - String toCity + String toCity, + String fromStationName, + String toStationName ) { // 行程信息 this.setFromCity(fromCity); this.setToCity(toCity); this.setStartTime(startTime); this.setArriveTime(arriveTime); + this.setFromStationName(fromStationName); + this.setToStationName(toStationName); return this; } @@ -165,10 +169,10 @@ public class OrderCarRecord extends OrderBaseRecord { // 加载超标信息 public OrderCarRecord loadComplianceInfo(OrderDetail orderDetail) { - orderDetail.getETAEvent().ifPresentOrElse(it->{ + orderDetail.getETAEvent().ifPresentOrElse(it -> { this.setOverStandard("是"); this.setOverStandardReason(it.getExtension()); - },()->{ + }, () -> { this.setOverStandard("否"); this.setOverStandardReason(""); }); diff --git a/src/main/java/com/chint/domain/aggregates/order/order_record/ctrip_order_record/CTripCarRecord.java b/src/main/java/com/chint/domain/aggregates/order/order_record/ctrip_order_record/CTripCarRecord.java index aad7ebd4..dad4db00 100644 --- a/src/main/java/com/chint/domain/aggregates/order/order_record/ctrip_order_record/CTripCarRecord.java +++ b/src/main/java/com/chint/domain/aggregates/order/order_record/ctrip_order_record/CTripCarRecord.java @@ -20,6 +20,7 @@ public class CTripCarRecord implements Serializable { private String recordId; private LocalDateTime createTime; private String routeOrderNo; + private String orderDate; @MappedCollection(idColumn = "c_trip_car_record_id") private CTripCarRecordBase cTripCarRecordBase; @MappedCollection(idColumn = "c_trip_car_record_id") diff --git a/src/main/java/com/chint/domain/factoriy/order/OrderFactory.java b/src/main/java/com/chint/domain/factoriy/order/OrderFactory.java index b914d47a..7e4a31c4 100644 --- a/src/main/java/com/chint/domain/factoriy/order/OrderFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order/OrderFactory.java @@ -6,11 +6,19 @@ import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.RouteRequest; import com.chint.domain.value_object.OrderSaveData; +import java.util.List; + public interface OrderFactory { RouteOrder createRoute(OrderSaveData orderData); + RouteOrder createRoute(OrderCreateCommand command); + ApprovalEvent createApprovalEvent(Integer eventType); + RouteRequest createRequestWithLeg(RouteOrder routeOrder, List legIds); + + RouteRequest createRequestWithAllLeg(RouteOrder routeOrder); + RouteRequest createRequestByRoute(RouteOrder routeOrder); } diff --git a/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java b/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java index b752d15f..b0d331a8 100644 --- a/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java @@ -1,5 +1,6 @@ package com.chint.domain.factoriy.order; +import cn.hutool.core.bean.BeanUtil; import com.chint.application.commands.OrderCreateCommand; import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.user.User; @@ -26,7 +27,6 @@ public class RouteOrderFactory implements OrderFactory { private String envMark; - @Override public RouteOrder createRoute(OrderSaveData orderData) { User currentUser = BaseContext.getCurrentUser(); @@ -82,10 +82,42 @@ public class RouteOrderFactory implements OrderFactory { return approvalEvent; } + @Override + public RouteRequest createRequestWithLeg(RouteOrder routeOrder, List legIds) { + RouteRequest requestByRoute = createRequestByRoute(routeOrder); + List routeRequestLegs = routeOrder + .getLegItems() + .stream() + .filter(it -> legIds.contains(it.getLegId())) + .map(RouteRequestLeg::ofLeg) + .toList(); + requestByRoute.setRouteRequestLegList(routeRequestLegs); + return requestByRoute; + } + + @Override + public RouteRequest createRequestWithAllLeg(RouteOrder routeOrder) { + RouteRequest requestByRoute = createRequestByRoute(routeOrder); + List routeRequestLegs = routeOrder + .getLegItems() + .stream() + .map(RouteRequestLeg::ofLeg) + .toList(); + requestByRoute.setRouteRequestLegList(routeRequestLegs); + return requestByRoute; + } + @Override public RouteRequest createRequestByRoute(RouteOrder routeOrder) { RouteRequest routeRequest = new RouteRequest(); routeRequest.setRouteRequestNo(OrderNo.generateRouteRequestNo(routeOrder.getRouteOrderNo())); - return null; + RouteRequestFields routeRequestFields = BeanUtil.copyProperties(routeOrder.getApproveOrderNo(), + RouteRequestFields.class); + routeRequestFields.setUserId(routeOrder.getUserId()); + routeRequestFields.setBelongDeptCode(routeOrder.getRouterOrderExtensionField().getBelongDeptCode()); + routeRequestFields.setStandardLevel(routeOrder.getStandardLevel()); + routeRequest.setRouteRequestFields(routeRequestFields); + routeRequest.addEvent(RouteRequestEvent.prepare()); + return routeRequest; } } diff --git a/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java b/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java index 0af4dde0..d8e2d885 100644 --- a/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java @@ -109,7 +109,10 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac } orderCarRecord.loadTravelInfo(startTime, endTime, cTripCarQuickInfo.getDepartureCityName(), - cTripCarQuickInfo.getArrivalCityName()); + cTripCarQuickInfo.getArrivalCityName(), + cTripCarQuickInfo.getDepartureCityName() + cTripCarQuickInfo.getDepartureAddressDetail(), + cTripCarQuickInfo.getArrivalCityName() + cTripCarQuickInfo.getArrivalAddressDetail() + ); // 加载车型和运行信息,车类型,时间,里程 orderCarRecord.loadVehicleAndTravelInfo(cTripCarQuickInfo.getVehicleName(), @@ -120,7 +123,7 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac String batchNo = cTripCarRecordBase.getBatchNoStartDate().substring(0, 6); orderCarRecord.loadFinancialInfo(batchNo, cTripCarRecordBase.getSubAccCheckBatchNo(), - String.valueOf(cTripCarRecordBase.getAmount()), + String.valueOf(cTripCarRecordBase.getRealAmount()), String.valueOf(cTripCarRecordBase.getRealAmountHasPost())); // 加载费用细节, 未税金额,税费,服务费,取消费,额外费用,额外费用名称 , 携程马上用车产品没有税费和额外费用字段 @@ -172,7 +175,7 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac carOrderDetail.getOriginalOrderNo()) .loadBasicOrderInfo(carOrderDetail.getOrderNo(), carOrderDetail.getOrderStatus(), - carOrderDetail.getCreateTime()); + cTripCarRecord.getOrderDate()); }, () -> orderCarRecord.loadComplianceInfoNot() .loadRelatedOrderInfo(cTripCarRecordBase.getOrderId(), cTripCarRecord.getRecordId(), @@ -182,7 +185,7 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac String.valueOf(cTripCarRecordBase.getOrderId())) .loadBasicOrderInfo(String.valueOf(cTripCarRecordBase.getOrderId()), "", - cTripCarRecordBase.getCreateTime())); + cTripCarRecord.getOrderDate())); //这里添加归属部门编号 , 这里兼容测试环境 , 如果行程规划单已经有这个值 , 那么直接取, 没有的话,查找用户的部门获取 Optional routerOrderExtensionField = byOrderNo diff --git a/src/main/java/com/chint/domain/repository/LegRepository.java b/src/main/java/com/chint/domain/repository/LegRepository.java index c14a8c13..78049183 100644 --- a/src/main/java/com/chint/domain/repository/LegRepository.java +++ b/src/main/java/com/chint/domain/repository/LegRepository.java @@ -8,6 +8,8 @@ import java.util.List; public interface LegRepository { Leg save(Leg leg); + List findByIds(List legIds); + void deleteById(Leg leg); void deleteByLegNo(String legNo); diff --git a/src/main/java/com/chint/domain/service/LegDomainService.java b/src/main/java/com/chint/domain/service/LegDomainService.java index ca45fc3c..07743b13 100644 --- a/src/main/java/com/chint/domain/service/LegDomainService.java +++ b/src/main/java/com/chint/domain/service/LegDomainService.java @@ -1,12 +1,10 @@ package com.chint.domain.service; -import com.chint.domain.aggregates.order.Leg; -import com.chint.domain.aggregates.order.LegEvent; -import com.chint.domain.aggregates.order.OrderDetail; -import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.aggregates.order.*; import com.chint.domain.exceptions.LegEventException; import com.chint.domain.factoriy.leg_event.LegEventFactory; import com.chint.domain.repository.LegRepository; +import com.chint.domain.repository.LocationRepository; import com.chint.domain.repository.OrderDetailRepository; import com.chint.domain.repository.RouteRepository; import com.chint.infrastructure.constant.LegConstant; @@ -34,6 +32,9 @@ public class LegDomainService { @Autowired private RouteRepository routeRepository; + @Autowired + private LocationRepository locationRepository; + public Leg legCheckOrder(Leg leg) { List orderDetailList = orderDetailRepository.findByLegId(leg.getLegId()); orderDetailList.forEach(OrderDetail::reloadStatus); @@ -115,4 +116,29 @@ 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 byNameList = locationRepository.findByNameList(locationIdsAsLong); + legExtensionField.setLocationList(byNameList); + } + if (leg.getOriginId() != null) { + leg.setOriginLocation(locationRepository.findByLocationId(leg.getOriginId())); + } + + if (leg.getDestinationId() != null) { + leg.setDestinationLocation(locationRepository.findByLocationId(leg.getDestinationId())); + } + + }); + return list; + } } diff --git a/src/main/java/com/chint/domain/service/RouteRequestDomainService.java b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java new file mode 100644 index 00000000..48da6015 --- /dev/null +++ b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java @@ -0,0 +1,88 @@ +package com.chint.domain.service; + +import com.chint.domain.aggregates.order.Leg; +import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.aggregates.order.RouteRequest; +import com.chint.domain.aggregates.order.RouteRequestEvent; +import com.chint.domain.factoriy.order.RouteOrderFactory; +import com.chint.domain.repository.LegRepository; +import com.chint.domain.repository.RouteRepository; +import com.chint.domain.service.order_sync.SyncAdapter; +import com.chint.domain.value_object.SyncLegData; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +import static com.chint.infrastructure.constant.RouteRequestConstant.ROUTE_REQUEST_STATUS_PREPARE; + +@Service +public class RouteRequestDomainService { + + @Autowired + private SyncAdapter syncAdapter; + + @Autowired + private RouteOrderFactory routeOrderFactory; + + @Autowired + private RouteRepository routeRepository; + + @Autowired + private LegDomainService legDomainService; + + @Autowired + private LegRepository legRepository; + + + public RouteRequest syncRouteRequestToSupplier(SyncLegData syncLegData) { + RouteOrder routeOrder = routeRepository.queryById(syncLegData.getRouteId()); + List legIds = syncLegData.getLegIds(); + RouteRequest routeRequest = getRouteRequest(routeOrder, legIds, syncLegData.getSupplierName()); + if (routeRequest.getStatus().equals(ROUTE_REQUEST_STATUS_PREPARE)) { + //如果是刚生成的订单需要加入行程规划单当中 + //保存供应商信息 + routeRequest.setSupplier(syncLegData.getSupplierName()); + routeOrder.addRouteRequest(routeRequest); + } else { + //如果是不是刚生成的,需要调整差旅申请单的行程 + loadLegInfo(routeRequest, routeOrder, legIds); + } + syncAdapter.of(syncLegData.getSupplierName()).syncRouteRequest(routeRequest); + routeRequest.addEvent(RouteRequestEvent.sync(syncLegData.getSupplierName())); + //通过保存聚合根来保存差旅申请单 + routeRepository.save(routeOrder); + return routeRequest; + } + + + //获取目前已经同步到供应商的差旅申请单 + private RouteRequest getRouteRequest(RouteOrder routeOrder, List legIds, String supplier) { + Optional optionalRouteRequest = routeOrder + .getRouteRequestList() + .stream() + .filter(it -> it.getSupplier().equals(supplier)) + .findFirst(); + if (legIds == null || legIds.isEmpty()) { + List allLegIds = routeOrder.getLegItems().stream().map(Leg::getLegId).toList(); + return optionalRouteRequest + .orElseGet(() -> routeOrderFactory.createRequestWithLeg(routeOrder, allLegIds)).reloadStatus(); + } else { + return optionalRouteRequest + .orElseGet(() -> routeOrderFactory.createRequestWithLeg(routeOrder, legIds)).reloadStatus(); + } + } + + //获取目前已经同步到供应商的差旅申请单 + private RouteRequest loadLegInfo(RouteRequest routeRequest, RouteOrder routeOrder, List legIds) { + List legItems = routeOrder.getLegItems(); + routeRequest.getRouteRequestLegList().forEach(it -> + legItems.stream() + .filter(leg -> legIds.contains(leg.getLegId())) + .filter(leg -> leg.getLegId().equals(it.getLegId())) + .findFirst() + .ifPresent(it::setLeg)); + return routeRequest; + } +} diff --git a/src/main/java/com/chint/domain/service/order_sync/CTripOrderSyncAdapter.java b/src/main/java/com/chint/domain/service/order_sync/CTripOrderSyncAdapter.java index 49fac8f3..fe0f06d9 100644 --- a/src/main/java/com/chint/domain/service/order_sync/CTripOrderSyncAdapter.java +++ b/src/main/java/com/chint/domain/service/order_sync/CTripOrderSyncAdapter.java @@ -65,16 +65,15 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync { @Override public boolean syncSupplierOrder(RouteOrder order) { - log.info("开始同步协程订单"); + log.info("开始同步携程订单"); ApprovalRequest approvalRequestParam = getApprovalRequestParam(order); ApprovalResult approval = approvalRequest.approval(approvalRequestParam); return approval.getSetApprovalResult().getStatus().getSuccess(); } - @Override public boolean cancelSyncSupplierOrder(RouteOrder order) { - log.info("开始取消协程订单"); + log.info("开始取消携程订单"); ApprovalRequest approvalRequestParam = getApprovalRequestParam(order); ApprovalResult approval = approvalRequest.cancelApprovalOrder(approvalRequestParam); return approval.getSetApprovalResult().getStatus().getSuccess(); @@ -82,30 +81,43 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync { @Override public boolean syncRouteRequest(RouteRequest routeRequest) { - return false; + log.info("开始同步携程订单"); + ApprovalRequest approvalRequestParam = getApprovalRequestParam(routeRequest); + ApprovalResult approval = approvalRequest.approval(approvalRequestParam); + return approval.getSetApprovalResult().getStatus().getSuccess(); } @Override public boolean cancelRouteRequest(RouteRequest routeRequest) { - return false; + log.info("开始取消携程订单"); + ApprovalRequest approvalRequestParam = getApprovalRequestParam(routeRequest); + ApprovalResult approval = approvalRequest.cancelApprovalOrder(approvalRequestParam); + return approval.getSetApprovalResult().getStatus().getSuccess(); } - private ApprovalRequest getApprovalRequestParam(RouteOrder order) { - ApproveOrderNo approveOrderNo = order.getApproveOrderNo(); - RankInfo rankInfo = RankInfo.of(order.getStandardLevel()); - String employeeNo = String.valueOf(order.getUserId()); + private ApprovalRequest getApprovalRequestParam(RouteRequest routeRequest) { + RouteRequestFields routeRequestFields = routeRequest.getRouteRequestFields(); + List routeRequestLegList = routeRequest.getRouteRequestLegList(); + String employeeNo = routeRequestFields.getUserId(); ApprovalRequest approvalRequestParam = ApprovalRequest - .buildApproval(order.getRouteOrderNo(), String.valueOf(employeeNo), rankInfo) - .addExtendField(approveOrderNo.getAccountCompanyCode()) - .addExtendField(approveOrderNo.getAccountCompanyName()) - .addExtendField(approveOrderNo.getSysCode()) + .buildApproval(routeRequest.getRouteRequestNo(), employeeNo, + RankInfo.of(routeRequestFields.getStandardLevel())) + .addExtendField(routeRequestFields.getAccountCompanyCode()) + .addExtendField(routeRequestFields.getAccountCompanyName()) + .addExtendField(routeRequestFields.getSysCode()) .addExtendField("暂无") - .addExtendField(approveOrderNo.getProjectName()); + .addExtendField(routeRequestFields.getProjectName()); + List legList = routeRequestLegList.stream().map(RouteRequestLeg::getLeg).toList(); + return generateApprovalRequestLegInfo(legList, employeeNo, approvalRequestParam); + } + + private ApprovalRequest generateApprovalRequestLegInfo(List legList, String employeeNo, ApprovalRequest approvalRequestParam) { Map> collect = orderDomainService.queryLocation( - order.getLegItems() - .stream() - .filter(leg -> leg.getLegType().equals(LEG_TYPE_HOTEL) || leg.getLegType().equals(LEG_TYPE_AIRPLANE) || leg.getLegType().equals(LEG_TYPE_TAXI)) + legList.stream() + .filter(leg -> leg.getLegType().equals(LEG_TYPE_HOTEL) || + leg.getLegType().equals(LEG_TYPE_AIRPLANE) || + leg.getLegType().equals(LEG_TYPE_TAXI)) .toList() ) .stream().collect(Collectors.groupingBy(Leg::getLegType)); @@ -120,6 +132,21 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync { return approvalRequestParam; } + private ApprovalRequest getApprovalRequestParam(RouteOrder order) { + ApproveOrderNo approveOrderNo = order.getApproveOrderNo(); + RankInfo rankInfo = RankInfo.of(order.getStandardLevel()); + String employeeNo = String.valueOf(order.getUserId()); + ApprovalRequest approvalRequestParam = ApprovalRequest + .buildApproval(order.getRouteOrderNo(), String.valueOf(employeeNo), rankInfo) + .addExtendField(approveOrderNo.getAccountCompanyCode()) + .addExtendField(approveOrderNo.getAccountCompanyName()) + .addExtendField(approveOrderNo.getSysCode()) + .addExtendField("暂无") + .addExtendField(approveOrderNo.getProjectName()); + List legList = order.getLegItems(); + return generateApprovalRequestLegInfo(legList, employeeNo, approvalRequestParam); + } + private List generateHotelList(List legs, String employeeNo) { List hotelList = new ArrayList<>(); legs.forEach(leg -> { diff --git a/src/main/java/com/chint/domain/value_object/SyncLegData.java b/src/main/java/com/chint/domain/value_object/SyncLegData.java index cf09311c..1d21f6c7 100644 --- a/src/main/java/com/chint/domain/value_object/SyncLegData.java +++ b/src/main/java/com/chint/domain/value_object/SyncLegData.java @@ -8,6 +8,7 @@ import java.util.List; public class SyncLegData { private Long routeId; private List routeIds; + private List legIds; private String supplierName; public static SyncLegData of( Long routeId,String supplierName){ SyncLegData syncLegData = new SyncLegData(); diff --git a/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java index aed8da4f..3b62808f 100644 --- a/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java @@ -29,6 +29,11 @@ public class LegRepositoryImpl implements LegRepository { return leg; } + @Override + public List findByIds(List legIds) { + return null; + } + @Override public void deleteById(Leg leg) { routeCacheService.invalidateRouteCache(leg.getRouteId()); diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderRecordAutoSave.java b/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderRecordAutoSave.java index ece19103..f4573720 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderRecordAutoSave.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderRecordAutoSave.java @@ -2,6 +2,7 @@ package com.chint.interfaces.rest.ctrip.order; import com.chint.domain.aggregates.order.order_record.ctrip_order_record.*; import com.chint.domain.repository.CTripOrderDetailRepository; +import com.chint.infrastructure.util.DateTimeUtil; import com.chint.interfaces.rest.ctrip.dto.order.OrderCarResponse; import com.chint.interfaces.rest.ctrip.dto.order.OrderFlightResponse; import com.chint.interfaces.rest.ctrip.dto.order.OrderHotelResponse; @@ -81,7 +82,7 @@ public class CTripOrderRecordAutoSave { OrderFlightResponse.FlightOrderBaseInfo orderBaseInfo = it.getOrderBaseInfo(); record.setRouteOrderNo(orderBaseInfo.getJourneyID()); OrderFlightResponse.FlightOrderPassenger orderPassengerInfo = it.getOrderPassengerInfo(); - if(orderPassengerInfo != null){ + if (orderPassengerInfo != null) { record.setTicketNo(orderPassengerInfo.getTicketNo()); } return record; @@ -190,6 +191,8 @@ public class CTripOrderRecordAutoSave { //补充额外的字段 OrderCarResponse.CarOrderCorpInfo corpInfo = it.getOrderDetail().getCorpInfo(); record.setRouteOrderNo(corpInfo.getJouneryId()); + String orderDate = it.getOrderDetail().getOrderBaseInfo().getOrderDate(); + record.setOrderDate(DateTimeUtil.timeToStrCommon(DateTimeUtil.strToTime(orderDate))); return record; }).toList(); cTripOrderDetailRepository.saveAllCTripCarRecord(list);