diff --git a/src/main/java/com/chint/application/dtos/response/LegRes.java b/src/main/java/com/chint/application/dtos/response/LegRes.java index f1a1d49d..b0b1898e 100644 --- a/src/main/java/com/chint/application/dtos/response/LegRes.java +++ b/src/main/java/com/chint/application/dtos/response/LegRes.java @@ -70,8 +70,10 @@ public class LegRes { if (legExtensionField.getLocationIds() != null) { List locationResList = new ArrayList<>(); List locationList = legExtensionField.getLocationList(); - for (Location location : locationList) { - locationResList.add(LocationRes.copyFrom(location)); + if(locationList != null && !locationList.isEmpty()){ + for (Location location : locationList) { + locationResList.add(LocationRes.copyFrom(location)); + } } legRes.setOtherLocationList(locationResList); } diff --git a/src/main/java/com/chint/application/in/OrderPublicController.java b/src/main/java/com/chint/application/in/OrderPublicController.java index 160780a0..5fa4436f 100644 --- a/src/main/java/com/chint/application/in/OrderPublicController.java +++ b/src/main/java/com/chint/application/in/OrderPublicController.java @@ -81,4 +81,5 @@ public class OrderPublicController { return Result.Success(SUCCESS); } + } diff --git a/src/main/java/com/chint/application/in/RouteRequestController.java b/src/main/java/com/chint/application/in/RouteRequestController.java index 7cf17e05..5f6094ba 100644 --- a/src/main/java/com/chint/application/in/RouteRequestController.java +++ b/src/main/java/com/chint/application/in/RouteRequestController.java @@ -1,23 +1,42 @@ package com.chint.application.in; +import com.chint.domain.service.RouteRequestDomainService; import com.chint.domain.value_object.SyncLegData; import com.chint.infrastructure.util.Result; import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; 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; +import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; + @RestController @RequestMapping("/route/request") public class RouteRequestController { - @Transactional - @ApiOperation("根据整个行程规划单到差旅平台") - @PostMapping("/sync/whole") - public Result syncByWholeRouterOrder(@RequestBody SyncLegData syncLegData) { + @Autowired + private RouteRequestDomainService routeRequestDomainService; - return null; + @Transactional + @ApiOperation("同步行程规划单到差旅平台") + @PostMapping("/sync") + public Result syncRouterOrder(@RequestBody SyncLegData syncLegData) { + routeRequestDomainService.syncRouteRequestToSupplier(syncLegData); + return Result.Success(SUCCESS); } + + @Transactional + @ApiOperation("取消行程规划单到差旅平台") + @PostMapping("/cancel") + public Result cancelWholeRouterOrder(@RequestBody SyncLegData syncLegData) { + routeRequestDomainService.cancelRouteRequest(syncLegData); + return Result.Success(SUCCESS); + } + + + + } diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index 01173faa..0f0e611e 100644 --- a/src/main/java/com/chint/application/out/OrderOutController.java +++ b/src/main/java/com/chint/application/out/OrderOutController.java @@ -1,12 +1,15 @@ package com.chint.application.out; +import com.chint.application.dtos.response.LegRes; import com.chint.application.dtos.response.RouteOrderPageRes; import com.chint.application.dtos.response.RouteOrderRes; import com.chint.application.dtos.trip.TripCallback; import com.chint.application.queryies.OrderQuery; import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.repository.RouteRepository; import com.chint.domain.repository.UserRepository; +import com.chint.domain.service.LegDomainService; import com.chint.domain.service.OrderDomainService; import com.chint.domain.value_object.*; import com.chint.infrastructure.cache.RouteCacheService; @@ -16,7 +19,6 @@ import com.google.gson.Gson; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.Cacheable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -44,6 +46,12 @@ public class OrderOutController { @Autowired private RouteCacheService routeCacheService; + @Autowired + private LegDomainService legDomainService; + + @Autowired + private RouteRepository routeRepository; + @ApiOperation("根据临时单号和系统编码查询订单") @PostMapping("/query/billcode") public Result queryOrderByBillCodeAndSysCode(@RequestBody OrderQueryData queryData) { @@ -75,7 +83,6 @@ public class OrderOutController { } - @ApiOperation("查询飞机估算价格") @PostMapping("/estimate/flight") public Result estimateFlightPrice(@RequestBody PriceQueryData priceQueryData) { @@ -107,4 +114,13 @@ public class OrderOutController { return Result.Success(SUCCESS, orderQuery.queryNotSubmit(queryData)); } + + @ApiOperation("查询能够同步的行程节点") + @PostMapping("/query/legs") + public Result> queryLegs(@RequestBody OrderQueryData queryData) { + RouteOrder routeOrder = routeRepository.queryById(queryData.getRouteId()); + return Result.Success(SUCCESS, legDomainService + .queryLegsCanSync(routeOrder, queryData.getSupplierName()).stream().map(LegRes::copyFrom).toList()); + } + } diff --git a/src/main/java/com/chint/application/queryies/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index 022e02ba..371cf390 100644 --- a/src/main/java/com/chint/application/queryies/OrderQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderQuery.java @@ -456,16 +456,17 @@ 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())); - } +// 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 +// } return scheduleDetailBuilder .scheduleNum(leg.getLegNo()) + .scheduleType(translateLegType(leg.getLegType())) .startDate(simpleFormatter.format(leg.getStartTime())) .endDate(simpleFormatter.format(leg.getEndTime())) .systemStatus(FSSCConstant.TRIP_CALLBACK_RECEIPT_STATUS) 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 fd55321a..d64bf337 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteRequest.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteRequest.java @@ -15,6 +15,7 @@ import org.springframework.data.relational.core.mapping.Table; import java.io.Serial; import java.io.Serializable; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; @Data @@ -30,7 +31,7 @@ public class RouteRequest implements Serializable, EventManageable { private Long routeOrderKey; - private String RouteRequestNo; + private String routeRequestNo; private String supplier; @@ -60,6 +61,9 @@ public class RouteRequest implements Serializable, EventManageable { @Override public List getEvents() { + if( this.eventList == null){ + this.eventList = new ArrayList<>(); + } return this.eventList; } 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 b0d331a8..ccd80e2d 100644 --- a/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java @@ -92,6 +92,8 @@ public class RouteOrderFactory implements OrderFactory { .map(RouteRequestLeg::ofLeg) .toList(); requestByRoute.setRouteRequestLegList(routeRequestLegs); + requestByRoute.setCreateTime(LocalDateTime.now()); + requestByRoute.setUpdateTime(LocalDateTime.now()); return requestByRoute; } @@ -114,7 +116,9 @@ public class RouteOrderFactory implements OrderFactory { RouteRequestFields routeRequestFields = BeanUtil.copyProperties(routeOrder.getApproveOrderNo(), RouteRequestFields.class); routeRequestFields.setUserId(routeOrder.getUserId()); - routeRequestFields.setBelongDeptCode(routeOrder.getRouterOrderExtensionField().getBelongDeptCode()); + if(routeOrder.getRouterOrderExtensionField() != null){ + routeRequestFields.setBelongDeptCode(routeOrder.getRouterOrderExtensionField().getBelongDeptCode()); + } routeRequestFields.setStandardLevel(routeOrder.getStandardLevel()); routeRequest.setRouteRequestFields(routeRequestFields); routeRequest.addEvent(RouteRequestEvent.prepare()); diff --git a/src/main/java/com/chint/domain/factoriy/order_detail/CTripOrderExtensionFactoryImpl.java b/src/main/java/com/chint/domain/factoriy/order_detail/CTripOrderExtensionFactoryImpl.java index 13938da9..2ab599b9 100644 --- a/src/main/java/com/chint/domain/factoriy/order_detail/CTripOrderExtensionFactoryImpl.java +++ b/src/main/java/com/chint/domain/factoriy/order_detail/CTripOrderExtensionFactoryImpl.java @@ -3,10 +3,8 @@ package com.chint.domain.factoriy.order_detail; import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.user.User; import com.chint.domain.exceptions.NotFoundException; -import com.chint.domain.repository.LocationRepository; -import com.chint.domain.repository.OrderDetailRepository; -import com.chint.domain.repository.RouteRepository; -import com.chint.domain.repository.UserRepository; +import com.chint.domain.repository.*; +import com.chint.domain.service.RouteRequestDomainService; import com.chint.infrastructure.util.BigDecimalCalculator; import com.chint.interfaces.rest.ctrip.dto.search.car.*; import com.chint.interfaces.rest.ctrip.dto.search.flight.*; @@ -46,6 +44,13 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { @Autowired private OrderDetailFactory orderDetailFactory; + @Autowired + private RouteRequestRepository routeRequestRepository; + + @Autowired + private RouteRequestDomainService routeRequestDomainService; + + @Override public CarOrderDetail createCarOrderDetail(Object carOrderDetailData) { //获取基础信息数据 @@ -53,7 +58,7 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { CarBasicInfo carBasicInfo = carQuickOrderInfoEntity.getBasicInfo(); String orderNo = carBasicInfo.getOrderId(); String journeyNo = carBasicInfo.getJourneyID(); - RouteOrder routeOrder = routeRepository.findByOrderNo(journeyNo); + RouteOrder routeOrder = routeRequestDomainService.getRouteOrder(journeyNo); OrderDetail orderDetail = routeOrder.getOrderDetails() .stream() .filter(it -> it.getOrderNo().equals(orderNo)) @@ -76,7 +81,7 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { orderFeeList.forEach(it -> { if (it.getFeeName().equals("取消费")) { carOrderDetail.setCancellationFee(it.getAmount().toString()); - if(it.getAmount() > 0){ + if (it.getAmount() > 0) { carOrderDetail.setOrderStatus(FSSC_CAR_STATUS_REFUND); } else { carOrderDetail.setOrderStatus(FSSC_ORDER_STATUS_CANCEL); @@ -85,6 +90,7 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { }); } + carOrderDetail.setTrvaleSysType(TRAVAL_SYS_TYPE_CTRIP); return updateCarOrderDetailData(carOrderDetail, carOrderDetailData); } @@ -156,7 +162,7 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { BasicInfo flightOrderBasicInfo = flightOrderInfoEntity.getBasicInfo(); String orderNo = flightOrderBasicInfo.getOrderID(); String journeyNo = flightOrderBasicInfo.getJourneyID(); - RouteOrder routeOrder = routeRepository.findByOrderNo(journeyNo); + RouteOrder routeOrder = routeRequestDomainService.getRouteOrder(journeyNo); Optional first = routeOrder .getOrderDetails() @@ -180,6 +186,7 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { } }); + flightOrderDetail.setTrvaleSysType(TRAVAL_SYS_TYPE_CTRIP); updateFlightOrderDetailData(flightOrderDetail, flightOrderInfoEntity); return flightOrderDetail; } @@ -359,7 +366,7 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { Optional byOrderNo = orderDetailRepository.findByOrderNo(orderNo); String journeyNo = hotelOrderInfoEntity.getJourneyNo(); - RouteOrder routeOrder = routeRepository.findByOrderNo(journeyNo).reloadStatus(); + RouteOrder routeOrder = routeRequestDomainService.getRouteOrder(journeyNo).reloadStatus(); ApproveOrderNo approveOrderNo = null; User user = null; @@ -517,6 +524,7 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { .findFirst(); first1.ifPresent(orderEvent -> hotelOrderDetail.setOverStandardReason(orderEvent.getExtension())); + hotelOrderDetail.setTrvaleSysType(TRAVAL_SYS_TYPE_CTRIP); return hotelOrderDetail; } diff --git a/src/main/java/com/chint/domain/factoriy/order_detail/LYOrderExtensionFactoryImpl.java b/src/main/java/com/chint/domain/factoriy/order_detail/LYOrderExtensionFactoryImpl.java index c0bc8089..146dfc68 100644 --- a/src/main/java/com/chint/domain/factoriy/order_detail/LYOrderExtensionFactoryImpl.java +++ b/src/main/java/com/chint/domain/factoriy/order_detail/LYOrderExtensionFactoryImpl.java @@ -6,6 +6,7 @@ import com.chint.domain.aggregates.user.User; import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.repository.OrderDetailRepository; import com.chint.domain.repository.RouteRepository; +import com.chint.domain.repository.RouteRequestRepository; import com.chint.domain.repository.UserRepository; import com.chint.interfaces.rest.ly.dto.carorderdatapushback.PriceDetail; import com.chint.interfaces.rest.ly.dto.hotelorderdatapushbach.Resident; @@ -56,8 +57,12 @@ public class LYOrderExtensionFactoryImpl implements OrderExtensionFactory { @Autowired private OrderDetailFactory orderDetailFactory; + @Autowired + private RouteRequestRepository routeRequestRepository; + private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"); + @Override public CarOrderDetail createCarOrderDetail(Object carOrderDetailData) { CarDetailResponse.DataWrapper data = (CarDetailResponse.DataWrapper) carOrderDetailData; @@ -94,6 +99,8 @@ public class LYOrderExtensionFactoryImpl implements OrderExtensionFactory { } }); } + + carOrderDetail.setTrvaleSysType(TRAVAL_SYS_TYPE_LY); return updateCarOrderDetailData(carOrderDetail, data); } @@ -302,6 +309,8 @@ public class LYOrderExtensionFactoryImpl implements OrderExtensionFactory { //这里根据同程自带的字段进行状态映射 flightOrderDetail.setOrderStatus(FSSC_FLIGHT_STATUS_REFUND); } + + flightOrderDetail.setTrvaleSysType(TRAVAL_SYS_TYPE_LY); return updateFlightOrderDetailData(flightOrderDetail, flightOrderDetailData); } @@ -398,6 +407,8 @@ public class LYOrderExtensionFactoryImpl implements OrderExtensionFactory { hotelOrderDetail.setOrderStatus(FSSC_HOTEL_STATUS_SUCCESS); } + + hotelOrderDetail.setTrvaleSysType(TRAVAL_SYS_TYPE_LY); return updateHotelOrderDetailData(hotelOrderDetail, data); } @@ -497,156 +508,6 @@ public class LYOrderExtensionFactoryImpl implements OrderExtensionFactory { } - private HotelOrderDetail convertHotelOrderDetail(HotelDetailResponse.Data data) { - - - HotelDetailResponse.OrderInfo orderInfo = data.getOrderInfo(); - HotelDetailResponse.HotelInfo hotelInfo = data.getHotelInfo(); - List roomList = data.getRoomList(); - HotelDetailResponse.Room room = null; - if (!data.getRoomList().isEmpty()) { - room = roomList.get(0); - } - - OrderDetail orderDetail = orderDetailRepository.findByOrderNo(orderInfo.getOrderSerialNo()) - .orElseThrow(() -> new NotFoundException(NOT_FOUND)); - RouteOrder routeOrder = routeRepository.queryById(orderDetail.getRouteId()); - String standardLevel = routeOrder.getStandardLevel(); - - // PriceQueryData priceQueryData = new PriceQueryData(); - // priceQueryData.setDepartCity(hotelInfo.getCityName()); - // priceQueryData.setDepartDate(hotelInfo.getCheckInDate()); - // priceQueryData.setArriveDate(hotelInfo.getCheckOutDate()); - // HotelPriceData hotelPriceData = estimatePrice.queryHotelPrice(priceQueryData); - - String sysCode = routeOrder.getApproveOrderNo().getSysCode(); - - HotelOrderDetail hotelOrderDetail = new HotelOrderDetail(); - - hotelOrderDetail.setTrvaleSysType(TRAVAL_SYS_TYPE_LY); - if (sysCode != null) { - if (sysCode.equals(BELONG_SYS_CODE_FSSC)) { - hotelOrderDetail.setBelongSysType(BELONG_SYS_TYPE_FSSC); - } - if (sysCode.equals(BELONG_SYS_CODE_H3BPM)) { - hotelOrderDetail.setBelongSysType(BELONG_SYS_TYPE_H3BPM); - } - if (sysCode.equals(BELONG_SYS_CODE_XNFSSC)) { - hotelOrderDetail.setBelongSysType(BELONG_SYS_TYPE_XNFSSC); - } - if (sysCode.equals(BELONG_SYS_CODE_ANFSSC)) { - hotelOrderDetail.setBelongSysType(BELONG_SYS_TYPE_ANFSSC); - } - } - - String EmployeeNo = routeOrder.getUserId(); - User user = userRepository.findByUserEmployeeNo(EmployeeNo); - if (orderInfo != null) { - hotelOrderDetail.setOrderNo(orderInfo.getOrderSerialNo()) - .setDetailId(orderInfo.getOrderSerialNo()) -// .setSupplier(SUPPLIER_L_Y_EXTENSION_NAME) - .setReceiptsNum(routeOrder.getRouteOrderNo()) - .setOrderAmount(String.valueOf(orderInfo.getBusinessAmount())) - .setCreateTime(orderInfo.getCreateTime()) - .setCheckInCity(hotelInfo.getCityName()) - .setHotelName(hotelInfo.getHotelName()) - .setContactPhone(hotelInfo.getHotelTel()) - .setHotelAddress(hotelInfo.getHotelAddress()) - .setCheckInDate(hotelInfo.getCheckInDate()) - .setDepartureDate(hotelInfo.getCheckOutDate()) - .setNightCount(String.valueOf(hotelInfo.getNightNum())) - .setRoomCount(String.valueOf(hotelInfo.getRoomNum())) - .setRoomTypeName(hotelInfo.getRoomName()) - .setPaymentType(String.valueOf(orderInfo.getPaymentType())) - .setCompanyAmount(String.valueOf(orderInfo.getCompanyPrice())) - .setPersonalAmount(String.valueOf(orderInfo.getPersonalPrice())) - .setCompanyRefundAmount(String.valueOf(orderInfo.getCompanyRefundPrice())) - .setPersonalRefundAmount(String.valueOf(orderInfo.getPersonalRefundPrice())) - .setOrderAmount(String.valueOf(orderInfo.getTotalPrice())) - .setPreServiceFee(String.valueOf(orderInfo.getServicePrice())) - .setPostServiceFee(String.valueOf(orderInfo.getAfterSettlementServicePrice())) - .setRefundAmount(String.valueOf(orderInfo.getRefundPrice())) - .setAgreementHotel(orderInfo.getProtocolType() == 0 ? "否" : "是"); -// .setBookingName(orderInfo.getContactName()) //预订人名字和电话使用contact是否正确 -// .setBookingUserPhone(orderInfo.getContactPhone()) -// .setNightRates() //nightrates 是hotelInfo -// .setStarRate("4") -// .setBOOK_ORG_STRUCT_1("Org A") -// .setBOOK_ORG_STRUCT_2("Org B") -// .setBOOK_ORG_STRUCT_3("Org C") - } - - if (user != null) { - hotelOrderDetail.setBookingUserCode(user.getEmployeeNo()); - hotelOrderDetail.setBookingName(user.getName()); - hotelOrderDetail.setBookingUserPhone(user.getPhoneNumber()); - } - ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); - if (approveOrderNo != null) { -// hotelOrderDetail.setAccountCompanyId(approveOrderNo.getAccountCompany()); - hotelOrderDetail.setAccountCompanyId(approveOrderNo.getAccountCompanyCode()); - hotelOrderDetail.setAccountCompanyName(approveOrderNo.getAccountCompanyName()); - hotelOrderDetail.setCostCenter(approveOrderNo.getCostCenter()); - hotelOrderDetail.setProjectOrderNo(approveOrderNo.getProjectName()); - } - - Optional first1 = routeOrder - .getOrderDetails() - .stream() - .filter(it -> it.getOrderNo().equals(hotelOrderDetail.getOrderNo())) - .findFirst(); - - first1.ifPresent(it -> { - OrderEvent lastEvent = it.getLastEvent(); - if (lastEvent != null) { - hotelOrderDetail.setOrderStatus(lastEvent.mapToHotelOrderDetailStatus()); - } else { - //如果订单事件为空,那么就需要重新根据查询到的订单信息重新进行映射 - Integer orderStatus = orderInfo.getOrderStatus(); - hotelOrderDetail.setOrderStatus( - OrderEvent.mapToHotelOrderDetailStatus( - LYOrderUtil.mapHotelStatus(orderStatus.toString()) - ) - ); - } - } - ); - - Optional firstOrderEvent = orderDetail.getOrderEventList() - .stream() - .map(OrderEvent::getEventType) - .filter(it -> it.equals(ORDER_EVENT_ETA)) - .findFirst(); - - if (firstOrderEvent.isEmpty()) { - hotelOrderDetail.setOverStandard("否"); //无 - } else { - hotelOrderDetail.setOverStandard("是"); //无 - } - Optional first2 = orderDetail.getOrderEventList() - .stream() - .findFirst(); - first2.ifPresent(orderEvent -> hotelOrderDetail.setOverStandardReason(orderEvent.getExtension())); - - List residentList = data.getResidentList(); - if (residentList != null && !residentList.isEmpty()) { - for (Resident resident : residentList) { - HotelOrderDetailCustomer customer = new HotelOrderDetailCustomer(); - customer.setUserName(resident.getName()); - customer.setPhone(resident.getContactPhone()); - customer.setUserCode(resident.getEmployeeCode()); - hotelOrderDetail.addCustomer(customer); - } - } - - if (room != null) { - hotelOrderDetail.setStandardItems(room.getDayStandardPrice()); - } - - - return hotelOrderDetail; - } - @Override public TrainOrderDetail createTrainOrderDetail(Object trainOrderDetailData) { // 获取对象的Class对象 @@ -680,6 +541,7 @@ public class LYOrderExtensionFactoryImpl implements OrderExtensionFactory { } ); + trainOrderDetail.setTrvaleSysType(TRAVAL_SYS_TYPE_LY); return updateTrainOrderDetailData(trainOrderDetail, trainDetailData); } @@ -761,197 +623,6 @@ public class LYOrderExtensionFactoryImpl implements OrderExtensionFactory { } - private TrainOrderDetail convertTrainOrderDetail(TrainDetailResponse.TrainDetailData trainDetailData) { - -// TrainDetailResponse.TrainDetailData trainDetailData = trainDetailResponse.getData(); - List items = trainDetailData.getItems(); - TrainDetailResponse.Item item = null; - TrainDetailResponse.ChangeInfo changeInfo = null; - if (!trainDetailData.getItems().isEmpty()) { - item = items.get(0); - changeInfo = item.getChangeInfo(); - } - - TrainDetailResponse.ChangeItem changeItem = null; - if (changeInfo != null) { - changeItem = changeInfo.getChangeItem(); - } - - Optional byOrderNo = orderDetailRepository.findByOrderNo(trainDetailData.getOrderNo()); - - TrainOrderDetail trainOrderDetail; - if (byOrderNo.isPresent()) { - if (byOrderNo.get().getTrainOrderDetail() == null) { - trainOrderDetail = new TrainOrderDetail(); - } else { - return byOrderNo.get().getTrainOrderDetail(); - } - } else { - trainOrderDetail = new TrainOrderDetail(); - } - - OrderDetail orderDetail = byOrderNo.get(); - RouteOrder routeOrder = routeRepository.queryById(byOrderNo.get().getRouteId()); - String sysCode = routeOrder.getApproveOrderNo().getSysCode(); - - trainOrderDetail.setTrvaleSysType(TRAVAL_SYS_TYPE_LY); - if (sysCode != null) { - if (sysCode.equals(BELONG_SYS_CODE_FSSC)) { - trainOrderDetail.setBelongSysType(BELONG_SYS_TYPE_FSSC); - } - if (sysCode.equals(BELONG_SYS_CODE_H3BPM)) { - trainOrderDetail.setBelongSysType(BELONG_SYS_TYPE_H3BPM); - - } - if (sysCode.equals(BELONG_SYS_CODE_XNFSSC)) { - trainOrderDetail.setBelongSysType(BELONG_SYS_TYPE_XNFSSC); - } - if (sysCode.equals(BELONG_SYS_CODE_ANFSSC)) { - trainOrderDetail.setBelongSysType(BELONG_SYS_TYPE_ANFSSC); - } - } - - - if (trainDetailData != null) { - trainOrderDetail.setOrderNo(trainDetailData.getOrderNo()); - trainOrderDetail.setDetailId(trainDetailData.getOrderNo()); - trainOrderDetail.setParentOrderNo(trainDetailData.getParentOrderSerialNo()); - - Optional first1 = routeOrder - .getOrderDetails() - .stream() - .filter(it -> it.getOrderNo().equals(trainDetailData.getOrderNo())) - .findFirst(); - - first1.ifPresent(it -> { - OrderEvent lastEvent = it.getLastEvent(); - if (trainDetailData.getIsChangedOrder().equals(1)) { - trainOrderDetail.setOrderStatus(FSSC_TRAIN_STATUS_CHANGE); - } - if (lastEvent != null) { - trainOrderDetail.setOrderStatus(lastEvent.mapToTrainOrderDetailStatus()); - } else { - //如果订单事件为空,那么就需要重新根据查询到的订单信息重新进行映射 - String orderStatus = trainDetailData.getOrderStatus(); - trainOrderDetail.setOrderStatus( - OrderEvent.mapToTrainOrderDetailStatus( - LYOrderUtil.mapTrainStatus(orderStatus) - ) - ); - } - if (!trainOrderDetail.getOrderStatus().equals(FSSC_TRAIN_STATUS_CHANGE) - && !trainOrderDetail.getOrderStatus().equals(FSSC_ORDER_STATUS_CANCEL)) { - trainOrderDetail.setOrderStatus(FSSC_TRAIN_STATUS_SUCCESS); - } - } - ); - String EmployeeNo = routeOrder.getUserId(); - User user = userRepository.findByUserEmployeeNo(EmployeeNo); - if (user != null) { - trainOrderDetail.setBookingUserCode(user.getEmployeeNo()); - trainOrderDetail.setBookingName(user.getName()); - trainOrderDetail.setBookingUserPhone(user.getPhoneNumber()); - } - trainOrderDetail.setReceiptsNum(routeOrder.getRouteOrderNo()); - trainOrderDetail.setCreateTime(trainDetailData.getOutTicketTime()); - trainOrderDetail.setStartTime(trainDetailData.getPlanBeginDate()); - trainOrderDetail.setArriveTime(trainDetailData.getPlanEndDate()); - trainOrderDetail.setFromStationName(trainDetailData.getFromStation()); - trainOrderDetail.setToStationName(trainDetailData.getToStation()); - trainOrderDetail.setTrainNo(trainDetailData.getTrainNo()); - trainOrderDetail.setFromCity(trainDetailData.getDepartCity()); - trainOrderDetail.setToCity(trainDetailData.getArriveCity()); - trainOrderDetail.setOrderAmount(String.valueOf(trainDetailData.getTotalAmount())); - trainOrderDetail.setPersonalAmount(trainDetailData.getPersonalPrice().toString()); - trainOrderDetail.setCompanyAmount(trainDetailData.getCompanyPrice().toString()); - trainOrderDetail.setUserCode(trainDetailData.getEmployeeCode()); - trainOrderDetail.setPaymentType(trainDetailData.getPaymentType().toString()); - List submitItemList = - trainDetailData.getTravelData().getSubmitItemList(); - - ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); - if (approveOrderNo != null) { - trainOrderDetail.setAccountCompanyId(approveOrderNo.getAccountCompanyCode()); - trainOrderDetail.setAccountCompanyName(approveOrderNo.getAccountCompanyName()); - trainOrderDetail.setCostCenter(approveOrderNo.getCostCenter()); - trainOrderDetail.setProjectOrderNo(approveOrderNo.getProjectName()); - } - } - - if (item != null) { - trainOrderDetail.setPreServiceFee(String.valueOf(item.getServiceCharge())); - trainOrderDetail.setPostServiceFee(String.valueOf(item.getAfterServiceCharge())); - trainOrderDetail.setRefundAmount(String.valueOf(item.getRefundAmountCor())); - - if (item.getSeatClass().equals("secondseat")) { - trainOrderDetail.setSeatType("二等座"); - } - if (item.getSeatClass().equals("businessseat")) { - trainOrderDetail.setSeatType("商务座"); - } - if (item.getSeatClass().equals("hardseat")) { - trainOrderDetail.setSeatType("硬座"); - } - if (item.getSeatClass().equals("softsleeperup")) { - trainOrderDetail.setSeatType("软卧"); - } - if (item.getSeatClass().equals("hardsleeperup")) { - trainOrderDetail.setSeatType("硬卧"); - } - if (item.getSeatClass().equals("firstseat")) { - trainOrderDetail.setSeatType("一等座"); - } - - - trainOrderDetail.setSeatName(item.getSeatNo()); - trainOrderDetail.setTicketPrice(String.valueOf(item.getTicketPrice())); - trainOrderDetail.setRefundCost(String.valueOf(item.getRefundFee())); - trainOrderDetail.setRefundPrice(String.valueOf(item.getRefundAmountCor())); - trainOrderDetail.setChangeCost(String.valueOf(item.getServiceCharge())); - trainOrderDetail.setPhone(item.getPassengerPhone()); - trainOrderDetail.setUserName(item.getPassengerName()); - } - - if (changeItem != null) { - trainOrderDetail.setChangeDifference(String.valueOf(changeItem.getChangePrice())); - trainOrderDetail.setChangeDifference(String.valueOf(changeItem.getChangePrice())); - } -// trainOrderDetail.setSupplier(SUPPLIER_L_Y_EXTENSION_NAME); - - Optional firstOrderEvent = orderDetail.getOrderEventList() - .stream() - .map(OrderEvent::getEventType) - .filter(it -> it.equals(ORDER_EVENT_ETA)) - .findFirst(); - - if (firstOrderEvent.isEmpty()) { - trainOrderDetail.setOverStandard("否"); //无 - } else { - trainOrderDetail.setOverStandard("是"); //无 - } - - Optional first2 = orderDetail.getOrderEventList() - .stream() - .findFirst(); - first2.ifPresent(orderEvent -> trainOrderDetail.setOverStandardReason(orderEvent.getExtension())); - -// trainOrderDetail.setOriginalOrderNo("originalOrderNo"); //无 -// trainOrderDetail.setBookingUserPhone(trainDetailData.getContactInfo().getPersonMobile() != null ? -// trainDetailData.getContactInfo().getPersonMobile() : -// trainDetailData.getContactInfo().getPersonTelephone()); //不确定是否是这个字段(文档没写)猜测 -// trainOrderDetail.setScheduleNum(""); //无 -// trainOrderDetail.setRunTime(""); //无 -// trainOrderDetail.setTickets(trainDetailData.getTicketNo()); //ChangeInfo.changeItem里面的数据 -// trainOrderDetail.setStandardItems("policyName"); //无 -// trainOrderDetail.setBOOK_ORG_STRUCT_1(""); //无 -// trainOrderDetail.setBOOK_ORG_STRUCT_2(""); //无 -// trainOrderDetail.setBOOK_ORG_STRUCT_3(""); //无 -// trainOrderDetail.setInsuranceFee(""); //无 - - - return trainOrderDetail; - } - private String translateEnSeatToCnSeat(String seatEnName) { return switch (seatEnName) { case "secondseat" -> "二等座"; diff --git a/src/main/java/com/chint/domain/factoriy/order_detail/OrderDetailFactoryImpl.java b/src/main/java/com/chint/domain/factoriy/order_detail/OrderDetailFactoryImpl.java index 2b80e82b..2499df86 100644 --- a/src/main/java/com/chint/domain/factoriy/order_detail/OrderDetailFactoryImpl.java +++ b/src/main/java/com/chint/domain/factoriy/order_detail/OrderDetailFactoryImpl.java @@ -62,12 +62,12 @@ public class OrderDetailFactoryImpl implements OrderDetailFactory { baseOrderExtension.setBookingUserPhone(user.getPhoneNumber()); //配置供应商信息 - String supplierName = routeOrder.getSupplierName(); - if (supplierName.equals(SUPPLIER_C_TRIP)) { - baseOrderExtension.setTrvaleSysType(TRAVAL_SYS_TYPE_CTRIP); - } else { - baseOrderExtension.setTrvaleSysType(TRAVAL_SYS_TYPE_LY); - } +// String supplierName = routeOrder.getSupplierName(); +// if (supplierName.equals(SUPPLIER_C_TRIP)) { +// baseOrderExtension.setTrvaleSysType(TRAVAL_SYS_TYPE_CTRIP); +// } else { +// baseOrderExtension.setTrvaleSysType(TRAVAL_SYS_TYPE_LY); +// } ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); if (approveOrderNo != null) { diff --git a/src/main/java/com/chint/domain/factoriy/order_record/OrderRecordFactory.java b/src/main/java/com/chint/domain/factoriy/order_record/OrderRecordFactory.java index 83f99b58..8f0f2ff0 100644 --- a/src/main/java/com/chint/domain/factoriy/order_record/OrderRecordFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order_record/OrderRecordFactory.java @@ -17,52 +17,52 @@ public class OrderRecordFactory { @Autowired private UserRepository userRepository; - public OrderRecordBasic buildWithRouteOrder(RouteOrder routeOrder) { - routeOrder.reloadStatus(); - OrderRecordBasic orderRecordBasic = new OrderRecordBasic(); - - //完成身份信息 - String userId = routeOrder.getUserId(); - User user = userRepository.findByUserEmployeeNo(userId); - orderRecordBasic.loadBookingInfo(user.getEmployeeNo(), - user.getName(), - user.getPhoneNumber(), - user.getEmployeeNo(), - user.getPhoneNumber()); - - - //配置供应商信息 - String supplierName = routeOrder.getSupplierName(); - if (supplierName.equals(SUPPLIER_C_TRIP)) { - orderRecordBasic.setTrvaleSysType(TRAVAL_SYS_TYPE_CTRIP); - } else { - orderRecordBasic.setTrvaleSysType(TRAVAL_SYS_TYPE_LY); - } - - ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); - if (approveOrderNo != null) { - orderRecordBasic.setAccountCompanyId(approveOrderNo.getAccountCompanyCode()); - orderRecordBasic.setAccountCompanyName(approveOrderNo.getAccountCompanyName()); - orderRecordBasic.setProjectOrderNo(approveOrderNo.getProjectName()); - String sysCode = routeOrder.getApproveOrderNo().getSysCode(); - if (sysCode != null) { - if (sysCode.equals(BELONG_SYS_CODE_FSSC)) { - orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_FSSC); - } - if (sysCode.equals(BELONG_SYS_CODE_H3BPM)) { - orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_H3BPM); - } - if (sysCode.equals(BELONG_SYS_CODE_XNFSSC)) { - orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_XNFSSC); - } - if (sysCode.equals(BELONG_SYS_CODE_ANFSSC)) { - orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_ANFSSC); - } - } else { - orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_NOT); - } - } - return orderRecordBasic; - } +// public OrderRecordBasic buildWithRouteOrder(RouteOrder routeOrder) { +// routeOrder.reloadStatus(); +// OrderRecordBasic orderRecordBasic = new OrderRecordBasic(); +// +// //完成身份信息 +// String userId = routeOrder.getUserId(); +// User user = userRepository.findByUserEmployeeNo(userId); +// orderRecordBasic.loadBookingInfo(user.getEmployeeNo(), +// user.getName(), +// user.getPhoneNumber(), +// user.getEmployeeNo(), +// user.getPhoneNumber()); +// +// +// //配置供应商信息 +// String supplierName = routeOrder.getSupplierName(); +// if (supplierName.equals(SUPPLIER_C_TRIP)) { +// orderRecordBasic.setTrvaleSysType(TRAVAL_SYS_TYPE_CTRIP); +// } else { +// orderRecordBasic.setTrvaleSysType(TRAVAL_SYS_TYPE_LY); +// } +// +// ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); +// if (approveOrderNo != null) { +// orderRecordBasic.setAccountCompanyId(approveOrderNo.getAccountCompanyCode()); +// orderRecordBasic.setAccountCompanyName(approveOrderNo.getAccountCompanyName()); +// orderRecordBasic.setProjectOrderNo(approveOrderNo.getProjectName()); +// String sysCode = routeOrder.getApproveOrderNo().getSysCode(); +// if (sysCode != null) { +// if (sysCode.equals(BELONG_SYS_CODE_FSSC)) { +// orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_FSSC); +// } +// if (sysCode.equals(BELONG_SYS_CODE_H3BPM)) { +// orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_H3BPM); +// } +// if (sysCode.equals(BELONG_SYS_CODE_XNFSSC)) { +// orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_XNFSSC); +// } +// if (sysCode.equals(BELONG_SYS_CODE_ANFSSC)) { +// orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_ANFSSC); +// } +// } else { +// orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_NOT); +// } +// } +// return orderRecordBasic; +// } } diff --git a/src/main/java/com/chint/domain/repository/RouteRequestRepository.java b/src/main/java/com/chint/domain/repository/RouteRequestRepository.java new file mode 100644 index 00000000..71472b82 --- /dev/null +++ b/src/main/java/com/chint/domain/repository/RouteRequestRepository.java @@ -0,0 +1,8 @@ +package com.chint.domain.repository; + + +import com.chint.domain.aggregates.order.RouteRequest; + +public interface RouteRequestRepository { + RouteRequest findByRouteRequestNo(String routeRequestNo); +} diff --git a/src/main/java/com/chint/domain/service/LegDomainService.java b/src/main/java/com/chint/domain/service/LegDomainService.java index 07743b13..a948efab 100644 --- a/src/main/java/com/chint/domain/service/LegDomainService.java +++ b/src/main/java/com/chint/domain/service/LegDomainService.java @@ -7,7 +7,6 @@ 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; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,7 +15,9 @@ import java.util.List; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_CHANGE_MAX_ERROR; import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.OrderConstant.*; +import static com.chint.infrastructure.constant.RouteConstant.APPROVAL_EVENT_PREPARE; import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE; +import static com.chint.infrastructure.constant.RouteRequestConstant.ROUTE_REQUEST_STATUS_SYNC; @Service public class LegDomainService { @@ -35,6 +36,9 @@ public class LegDomainService { @Autowired private LocationRepository locationRepository; + @Autowired + private OrderDomainService orderDomainService; + public Leg legCheckOrder(Leg leg) { List orderDetailList = orderDetailRepository.findByLegId(leg.getLegId()); orderDetailList.forEach(OrderDetail::reloadStatus); @@ -70,8 +74,7 @@ public class LegDomainService { } - - if(leg.getLegStatus().equals(LEG_STATUS_CHANGE)){ + if (leg.getLegStatus().equals(LEG_STATUS_CHANGE)) { //如果发现该订单 LegEvent legEvent = legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL); leg.addEvent(legEvent); @@ -141,4 +144,36 @@ public class LegDomainService { }); return list; } + + public RouteOrder checkLegIfStartApproval(RouteOrder routeOrder) { + routeOrder.reloadStatus(); + List legItems = routeOrder.getLegItems(); + legItems.forEach(it -> { + if (!routeOrder.getApprovalStatusCode().equals(APPROVAL_EVENT_PREPARE) && it.getLegStatus().equals(LEG_STATUS_PREPARE)) { + it.addEvent(legEventFactory.creatLegEvent(LEG_EVENT_APPROVAL)); + } + }); + return routeOrder; + } + + public List queryLegsCanSync(RouteOrder routeOrder, String supplierName) { + List legItems = routeOrder.getLegItems(); + legItems = legItems.stream().filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)).toList(); + if (supplierName.equals("CTrip")) { + legItems = legItems.stream().filter(it -> !it.getLegType().equals(LEG_TYPE_TRAIN)).toList(); + } + + List alreadySyncLegIds = routeOrder.getRouteRequestList() + .stream() + .filter(it -> it.reloadStatus().getStatus().equals(ROUTE_REQUEST_STATUS_SYNC)) + .flatMap(it -> it.getRouteRequestLegList().stream().map(RouteRequestLeg::getLegId)) + .toList(); + + legItems = legItems.stream() + .filter(it -> !alreadySyncLegIds.contains(it.getLegId())) + .toList(); + + queryLocation(legItems); + return legItems; + } } diff --git a/src/main/java/com/chint/domain/service/RouteRequestDomainService.java b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java index 48da6015..0635eb57 100644 --- a/src/main/java/com/chint/domain/service/RouteRequestDomainService.java +++ b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java @@ -1,12 +1,12 @@ 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.aggregates.order.*; +import com.chint.domain.exceptions.CommandException; +import com.chint.domain.factoriy.leg_event.LegEventFactory; import com.chint.domain.factoriy.order.RouteOrderFactory; import com.chint.domain.repository.LegRepository; import com.chint.domain.repository.RouteRepository; +import com.chint.domain.repository.RouteRequestRepository; import com.chint.domain.service.order_sync.SyncAdapter; import com.chint.domain.value_object.SyncLegData; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +15,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; +import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.RouteRequestConstant.ROUTE_REQUEST_STATUS_PREPARE; @Service @@ -35,9 +36,30 @@ public class RouteRequestDomainService { @Autowired private LegRepository legRepository; + @Autowired + private RouteRequestRepository routeRequestRepository; + + @Autowired + private LegEventFactory legEventFactory; + + +// //这里增加一个判断 ,如果这个订单的行程为空,那么就返回给用户提示 +// if (legItems == null || legItems.isEmpty()) { +// throw new CommandException("订单的行程不能为空"); +// } +// List needSyncLegs = legItems.stream().filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)).toList(); +// if (needSyncLegs.isEmpty()) { +// throw new CommandException("有所选的行程规划单不存在需要同步的行程"); +// } +// +// //这里order所有的leg触发sync事件 +// legItems.forEach(leg -> leg.getEventList().add( +// legEventFactory.creatLegEvent(command.getLegEventType()) +// )); public RouteRequest syncRouteRequestToSupplier(SyncLegData syncLegData) { RouteOrder routeOrder = routeRepository.queryById(syncLegData.getRouteId()); + legDomainService.checkLegIfStartApproval(routeOrder); List legIds = syncLegData.getLegIds(); RouteRequest routeRequest = getRouteRequest(routeOrder, legIds, syncLegData.getSupplierName()); if (routeRequest.getStatus().equals(ROUTE_REQUEST_STATUS_PREPARE)) { @@ -49,13 +71,58 @@ public class RouteRequestDomainService { //如果是不是刚生成的,需要调整差旅申请单的行程 loadLegInfo(routeRequest, routeOrder, legIds); } + + List legs = routeRequest.getRouteRequestLegList() + .stream() + .map(RouteRequestLeg::getLeg) + .toList(); + + if (legs.isEmpty()) { + throw new CommandException("订单的行程不能为空"); + } + + List needSyncLegs = legs.stream().filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)).toList(); + if (needSyncLegs.isEmpty()) { + throw new CommandException("有所选的行程规划单不存在需要同步的行程"); + } + + legs.forEach(it -> it.addEvent(legEventFactory.creatLegEvent(LEG_EVENT_NOT_ORDERED))); + //这里执行同步 syncAdapter.of(syncLegData.getSupplierName()).syncRouteRequest(routeRequest); routeRequest.addEvent(RouteRequestEvent.sync(syncLegData.getSupplierName())); + //通过保存聚合根来保存差旅申请单 routeRepository.save(routeOrder); return routeRequest; } + public void cancelRouteRequest(SyncLegData syncLegData) { + Long routeId = syncLegData.getRouteId(); + RouteOrder routeOrder = routeRepository.queryById(routeId); + Optional optionalRouteRequest; + if (syncLegData.getRouteRequestId() != null) { + //如果指定的对应的差旅申请单 , 那么取消对应的差旅申请单 + optionalRouteRequest = routeOrder.getRouteRequestList() + .stream() + .filter(it -> it.getId().equals(syncLegData.getRouteRequestId())) + .findFirst(); + } else { + //如果指定的行程单号和供应商 , 该供应商对应的差旅申请单 + optionalRouteRequest = routeOrder.getRouteRequestList() + .stream() + .filter(it -> it.getSupplier().equals(syncLegData.getSupplierName())) + .findFirst(); + } + optionalRouteRequest.ifPresent(it -> { + 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); + } + //获取目前已经同步到供应商的差旅申请单 private RouteRequest getRouteRequest(RouteOrder routeOrder, List legIds, String supplier) { @@ -77,12 +144,40 @@ public class RouteRequestDomainService { //获取目前已经同步到供应商的差旅申请单 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)); + List list; + if (legIds != null && !legIds.isEmpty()) { + list = legItems.stream() + .filter(leg -> legIds.contains(leg.getLegId())) + .map(RouteRequestLeg::ofLeg) + .toList(); + } else { + list = legItems.stream() + .map(RouteRequestLeg::ofLeg) + .toList(); + } + routeRequest.setRouteRequestLegList(list); return routeRequest; } + + private RouteRequest getLegInfoFromRouteOrder(RouteRequest routeRequest, RouteOrder routeOrder) { + List legItems = routeOrder.getLegItems(); + routeRequest.getRouteRequestLegList().forEach(it -> { + for (Leg leg : legItems) { + if (leg.getLegId().equals(it.getLegId())) { + it.setLeg(leg); + } + } + }); + return routeRequest; + } + + + public RouteOrder getRouteOrder(String journeyNo) { + //先通过 + RouteRequest routeRequest = routeRequestRepository.findByRouteRequestNo(journeyNo); + if (routeRequest == null) { + return routeRepository.findByOrderNo(journeyNo); + } + return routeRepository.queryById(routeRequest.getRouteId()); + } } diff --git a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java index f6b272b6..f084a448 100644 --- a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java +++ b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java @@ -13,6 +13,7 @@ import com.chint.domain.factoriy.order.RouteOrderFactory; import com.chint.domain.factoriy.order_detail.OrderDetailFactory; import com.chint.domain.repository.*; import com.chint.domain.service.OrderDomainService; +import com.chint.domain.service.RouteRequestDomainService; import com.chint.domain.service.order_sync.SyncAdapter; import com.chint.domain.value_object.ApprovalSimpleData; import com.chint.domain.value_object.ApproveRouteData; @@ -88,6 +89,9 @@ public class LegEventHandler implements LegEventService { @Autowired private OrderDomainService orderDomainService; + @Autowired + private RouteRequestDomainService routeRequestDomainService; + @Value("${chint.envMark}") private String envMark; @@ -218,7 +222,7 @@ public class LegEventHandler implements LegEventService { public ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command) { OrderLegData data = command.getData(); String orderNo = data.getSelfOrderNo(); - RouteOrder routeOrder = routeRepository.findByOrderNo(orderNo); + RouteOrder routeOrder = routeRequestDomainService.getRouteOrder(orderNo); //获取行程规划单创建者作为该订单 String employeeNo = routeOrder.getUserId(); User byUserEmployeeNo = userRepository.findByUserEmployeeNo(employeeNo); @@ -317,8 +321,15 @@ public class LegEventHandler implements LegEventService { .stream() .filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)) .toList(); - if (!list.isEmpty() && !syncAdapter.of(routeOrder.getSupplierName()).cancelSyncSupplierOrder(routeOrder)) { - throw new CommandException("订单取消失败"); + + List routeRequestList = routeOrder.getRouteRequestList(); + + if(routeRequestList != null && !routeRequestList.isEmpty()) { + routeRequestList.forEach(it->syncAdapter.of(it.getSupplier()).cancelRouteRequest(it)); + } else { + if (!list.isEmpty() && !syncAdapter.of(routeOrder.getSupplierName()).cancelSyncSupplierOrder(routeOrder)) { + throw new CommandException("订单取消失败"); + } } } LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType()); diff --git a/src/main/java/com/chint/domain/value_object/OrderQueryData.java b/src/main/java/com/chint/domain/value_object/OrderQueryData.java index 164c3bb4..955351ee 100644 --- a/src/main/java/com/chint/domain/value_object/OrderQueryData.java +++ b/src/main/java/com/chint/domain/value_object/OrderQueryData.java @@ -1,6 +1,7 @@ package com.chint.domain.value_object; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -9,6 +10,7 @@ import java.util.List; @EqualsAndHashCode(callSuper = true) @Data public class OrderQueryData extends BaseQuery { + @ApiModelProperty("需要同步的行程规划单ID") private Long routeId; private String billcode; private String sysCode; @@ -17,5 +19,6 @@ public class OrderQueryData extends BaseQuery { private String orderNo; private String instructions; private String keywords; + @ApiModelProperty("供应商标识") private String supplierName; } 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 1d21f6c7..c3bd4df6 100644 --- a/src/main/java/com/chint/domain/value_object/SyncLegData.java +++ b/src/main/java/com/chint/domain/value_object/SyncLegData.java @@ -1,14 +1,21 @@ package com.chint.domain.value_object; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.List; @Data public class SyncLegData { + @ApiModelProperty("需要同步的行程规划单ID") private Long routeId; + @ApiModelProperty("差旅申请单ID") + private Long routeRequestId; + @ApiModelProperty("批量同步的行程规划单ID") private List routeIds; + @ApiModelProperty("需要同步的行程节点ID") private List legIds; + @ApiModelProperty("供应商标识") 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/RouteRequestRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/RouteRequestRepositoryImpl.java new file mode 100644 index 00000000..8b7f130f --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/RouteRequestRepositoryImpl.java @@ -0,0 +1,19 @@ +package com.chint.infrastructure.repository; + +import com.chint.domain.aggregates.order.RouteRequest; +import com.chint.domain.repository.RouteRequestRepository; +import com.chint.infrastructure.repository.jdbc.JdbcRouteRequestRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class RouteRequestRepositoryImpl implements RouteRequestRepository { + + @Autowired + private JdbcRouteRequestRepository jdbcRouteRequestRepository; + + @Override + public RouteRequest findByRouteRequestNo(String routeRequestNo) { + return jdbcRouteRequestRepository.findByRouteRequestNo(routeRequestNo); + } +} diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRouteRequestRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRouteRequestRepository.java new file mode 100644 index 00000000..189961dd --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRouteRequestRepository.java @@ -0,0 +1,11 @@ +package com.chint.infrastructure.repository.jdbc; + +import com.chint.domain.aggregates.order.RouteRequest; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface JdbcRouteRequestRepository extends CrudRepository { + RouteRequest findByRouteRequestNo(String routeRequestNo); + +} diff --git a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java index 7a03b032..fd4099d9 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java @@ -196,7 +196,7 @@ public class UserHttpRequestImpl implements UserHttpRequest { .findFirst() .ifPresent(it -> { User byUserEmployeeNo = userRepository.findByUserEmployeeNo(user.getEmployeeNo()); - if(byUserEmployeeNo == null){ + if (byUserEmployeeNo == null) { userRepository.save( getDataFromUserSFData(user, it) ); @@ -290,6 +290,12 @@ public class UserHttpRequestImpl implements UserHttpRequest { //根据入账公司没有找到部门编码的话,直接获取主岗编码 deptCode = user.lowestDeptCode(); } + + if (deptCode == null) { + //如果还是空的话 , 就返回null + return null; + } + //清除部门编码里面的字母 return deptCode.replaceAll("\\D", ""); } diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 0e552aab..f4381294 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -48,10 +48,10 @@ logging: #正式 ly: appId: zhengtai - account: ab9fe0c19dd64a99b936fded72c3bb94 - password: glHRJJ9JMUwNfQ8OwAQi - secret: MnghmYJpM1U2RaLx - baseUrl: https://api.dttrip.cn/openapi + account: 4f9cb1080b564dd0a94aa95f7a19c8b5 + password: 1fD3SutgzfS48qznYQiq + secret: WOHzCMvHd823iHgH + baseUrl: https://api.qa.dttrip.cn/openapi ifForwardRequest: false forwardRequestBaseUrl: https://secureqrdev-t.chint.com/llz