From 81f8299d6aec1c3392afe7efafe96489da70e223 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Mon, 8 Apr 2024 16:58:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E5=90=8C=E6=AD=A5=E5=B7=AE?= =?UTF-8?q?=E6=97=85=E7=94=B3=E8=AF=B7=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../in/RouteRequestController.java | 27 +++++++++++--- .../CTripOrderExtensionFactoryImpl.java | 21 +++++++---- .../LYOrderExtensionFactoryImpl.java | 5 +++ .../repository/RouteRequestRepository.java | 8 ++++ .../service/RouteRequestDomainService.java | 37 +++++++++++++++++++ .../service/leg_event/LegEventHandler.java | 6 ++- .../domain/value_object/SyncLegData.java | 1 + .../RouteRequestRepositoryImpl.java | 19 ++++++++++ .../jdbc/JdbcRouteRequestRepository.java | 11 ++++++ .../rest/user/UserHttpRequestImpl.java | 8 +++- 10 files changed, 128 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/chint/domain/repository/RouteRequestRepository.java create mode 100644 src/main/java/com/chint/infrastructure/repository/RouteRequestRepositoryImpl.java create mode 100644 src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRouteRequestRepository.java diff --git a/src/main/java/com/chint/application/in/RouteRequestController.java b/src/main/java/com/chint/application/in/RouteRequestController.java index 7cf17e05..fa87f14c 100644 --- a/src/main/java/com/chint/application/in/RouteRequestController.java +++ b/src/main/java/com/chint/application/in/RouteRequestController.java @@ -1,23 +1,40 @@ 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/whole") + public Result syncRouterOrder(@RequestBody SyncLegData syncLegData) { + routeRequestDomainService.syncRouteRequestToSupplier(syncLegData); + return Result.Success(SUCCESS); } + + @Transactional + @ApiOperation("取消行程规划单到差旅平台") + @PostMapping("/sync/whole") + public Result cancelWholeRouterOrder(@RequestBody SyncLegData syncLegData) { + routeRequestDomainService.cancelRouteRequest(syncLegData); + return Result.Success(SUCCESS); + } + + } 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..4dcad0b2 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); @@ -156,7 +161,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() @@ -359,7 +364,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; 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..1fa221a3 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; 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/RouteRequestDomainService.java b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java index 48da6015..1f09e8b7 100644 --- a/src/main/java/com/chint/domain/service/RouteRequestDomainService.java +++ b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java @@ -7,6 +7,7 @@ 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.repository.RouteRequestRepository; import com.chint.domain.service.order_sync.SyncAdapter; import com.chint.domain.value_object.SyncLegData; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +36,9 @@ public class RouteRequestDomainService { @Autowired private LegRepository legRepository; + @Autowired + private RouteRequestRepository routeRequestRepository; + public RouteRequest syncRouteRequestToSupplier(SyncLegData syncLegData) { RouteOrder routeOrder = routeRepository.queryById(syncLegData.getRouteId()); @@ -56,6 +60,30 @@ public class RouteRequestDomainService { 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())); + syncAdapter.of(it.getSupplier()).cancelRouteRequest(it); + }); + routeRepository.save(routeOrder); + } + //获取目前已经同步到供应商的差旅申请单 private RouteRequest getRouteRequest(RouteOrder routeOrder, List legIds, String supplier) { @@ -85,4 +113,13 @@ public class RouteRequestDomainService { .ifPresent(it::setLeg)); return routeRequest; } + + public RouteOrder getRouteOrder(String journeyNo) { + RouteOrder byOrderNo = routeRepository.findByOrderNo(journeyNo); + if (byOrderNo == null) { + RouteRequest byRouteRequestNo = routeRequestRepository.findByRouteRequestNo(journeyNo); + byOrderNo = routeRepository.queryById(byRouteRequestNo.getRouteId()); + } + return byOrderNo; + } } 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..e6a7202d 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); 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..9cf3460e 100644 --- a/src/main/java/com/chint/domain/value_object/SyncLegData.java +++ b/src/main/java/com/chint/domain/value_object/SyncLegData.java @@ -7,6 +7,7 @@ import java.util.List; @Data public class SyncLegData { private Long routeId; + private Long routeRequestId; private List routeIds; private List legIds; private String supplierName; 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", ""); }