diff --git a/src/main/java/com/chint/application/commands/OrderStatusChangeCommand.java b/src/main/java/com/chint/application/commands/OrderStatusChangeCommand.java index 7f57d3bf..e52034dc 100644 --- a/src/main/java/com/chint/application/commands/OrderStatusChangeCommand.java +++ b/src/main/java/com/chint/application/commands/OrderStatusChangeCommand.java @@ -1,5 +1,6 @@ package com.chint.application.commands; +import com.chint.domain.aggregates.order.OrderDetail; import com.chint.infrastructure.echo_framework.command.Command; import lombok.Data; import lombok.EqualsAndHashCode; @@ -11,6 +12,7 @@ public class OrderStatusChangeCommand extends Command { private String orderNo; private String outStatus; private Integer orderEventType; + private OrderDetail orderDetail; public OrderStatusChangeCommand eventType(Integer eventType) { this.orderEventType = eventType; @@ -26,4 +28,9 @@ public class OrderStatusChangeCommand extends Command { this.outStatus = outStatus; return this; } + + public OrderStatusChangeCommand orderDetail(OrderDetail orderDetail) { + this.orderDetail = orderDetail; + return this; + } } diff --git a/src/main/java/com/chint/application/dtos/trip/ExtendedFieldParam.java b/src/main/java/com/chint/application/dtos/trip/ExtendedFieldParam.java new file mode 100644 index 00000000..fbca439f --- /dev/null +++ b/src/main/java/com/chint/application/dtos/trip/ExtendedFieldParam.java @@ -0,0 +1,12 @@ +package com.chint.application.dtos.trip; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class ExtendedFieldParam implements Serializable { + @JsonProperty("isExceed") + private boolean isExceed; +} diff --git a/src/main/java/com/chint/application/dtos/trip/ScheduleDetail.java b/src/main/java/com/chint/application/dtos/trip/ScheduleDetail.java index b6847a1d..40901620 100644 --- a/src/main/java/com/chint/application/dtos/trip/ScheduleDetail.java +++ b/src/main/java/com/chint/application/dtos/trip/ScheduleDetail.java @@ -62,7 +62,7 @@ public class ScheduleDetail { protected String ParentScheduleNum; @JsonProperty("ExtendedField") - protected String ExtendedField; + protected ExtendedFieldParam ExtendedField; @JsonProperty("QuoteGroupNum") protected String QuoteGroupNum; @@ -114,6 +114,8 @@ public class ScheduleDetail { @JsonProperty("RealScheduleNum") protected String RealScheduleNum; + + // Constructor, getters and setters public static ScheduleDetailBuilder builder(){ @@ -213,10 +215,10 @@ public class ScheduleDetail { return this; } - public ScheduleDetailBuilder extendedField(String extendedField) { - scheduleDetail.setExtendedField(extendedField); - return this; - } +// public ScheduleDetailBuilder extendedField(String extendedField) { +// scheduleDetail.setExtendedField(extendedField); +// return this; +// } public ScheduleDetailBuilder quoteGroupNum(String quoteGroupNum) { scheduleDetail.setQuoteGroupNum(quoteGroupNum); @@ -312,6 +314,9 @@ public class ScheduleDetail { } public ScheduleDetail build() { + ExtendedFieldParam extendedFieldParam = new ExtendedFieldParam(); + extendedFieldParam.setExceed(false); + scheduleDetail.setExtendedField(extendedFieldParam); return scheduleDetail; } } diff --git a/src/main/java/com/chint/application/in/OrderController.java b/src/main/java/com/chint/application/in/OrderController.java index 314da0cc..943b5630 100644 --- a/src/main/java/com/chint/application/in/OrderController.java +++ b/src/main/java/com/chint/application/in/OrderController.java @@ -5,6 +5,7 @@ import com.chint.application.dtos.DeleteLegData; import com.chint.application.queryies.OrderQuery; import com.chint.application.services.OrderApplicationService; import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.service.OrderDetailDomainService; import com.chint.domain.value_object.*; import com.chint.infrastructure.util.Result; import io.swagger.annotations.ApiOperation; @@ -24,6 +25,9 @@ public class OrderController { @Autowired private OrderApplicationService orderApplicationService; + @Autowired + private OrderDetailDomainService orderDetailDomainService; + @Autowired private OrderQuery orderQuery; @@ -69,4 +73,12 @@ public class OrderController { orderApplicationService.deleteLegToOrder(deleteLegData); return Result.Success(SUCCESS); } + + @Transactional + @ApiOperation("同步行程规划单的订单状态") + @PostMapping("/sync/order") + public Result reloadOrderDetail(@RequestBody SyncLegData syncLegData) { + orderDetailDomainService.syncOrderDetailStatusByRouteId(syncLegData.getRouteId()); + return Result.Success(SUCCESS); + } } diff --git a/src/main/java/com/chint/application/in/OrderPublicController.java b/src/main/java/com/chint/application/in/OrderPublicController.java index c1ddb556..9a4926b5 100644 --- a/src/main/java/com/chint/application/in/OrderPublicController.java +++ b/src/main/java/com/chint/application/in/OrderPublicController.java @@ -2,6 +2,7 @@ package com.chint.application.in; import com.chint.application.queryies.OrderQuery; import com.chint.application.services.OrderApplicationService; +import com.chint.domain.service.SystemDomainService; import com.chint.domain.value_object.ApprovalLegData; import com.chint.domain.value_object.ApproveLegData; import com.chint.infrastructure.util.Result; @@ -22,6 +23,9 @@ public class OrderPublicController { @Autowired private OrderApplicationService orderApplicationService; + @Autowired + private SystemDomainService systemDomainService; + @Autowired private OrderQuery orderQuery; @@ -29,6 +33,7 @@ public class OrderPublicController { @ApiOperation("提交审批行程规划单") @PostMapping("/approve") public Result approveOrder(@RequestBody ApproveLegData approveLegData) { + systemDomainService.checkSystemCode(approveLegData.getSysCode()); orderApplicationService.approve(approveLegData); return Result.Success(SUCCESS); } @@ -49,4 +54,5 @@ public class OrderPublicController { return Result.Success(SUCCESS); } + } diff --git a/src/main/java/com/chint/application/out/LoginController.java b/src/main/java/com/chint/application/out/LoginController.java index ab438e3a..05ded168 100644 --- a/src/main/java/com/chint/application/out/LoginController.java +++ b/src/main/java/com/chint/application/out/LoginController.java @@ -4,6 +4,7 @@ package com.chint.application.out; import com.chint.application.commands.OrderCreateCommand; import com.chint.domain.aggregates.user.User; import com.chint.domain.exceptions.OrderException; +import com.chint.domain.service.SystemDomainService; import com.chint.domain.service.auth.AuthenticateService; import com.chint.domain.value_object.UserLoginParam; import com.chint.domain.value_object.UserLoginResult; @@ -41,6 +42,9 @@ public class LoginController { @Autowired private UserHttpRequest userHttpRequest; + @Autowired + private SystemDomainService systemDomainService; + @Transactional @GetMapping("/login") public Result login(@RequestParam("sfno") String sfno, @@ -53,15 +57,8 @@ public class LoginController { String originalString = sfno + syscode + billcode + companycode + AuthMessageConstant.LOGIN_SECRET_KEY + timespan; String generateSign = Digest.md5(originalString); if (generateSign.equals(sign)) { - //公司名称转为,中文转为编号 - /*if (StringCheck.isFirstCharacterChinese(companycode)) { - User user = new User(Long.valueOf(sfno)); - user.setUserLoginParam(new UserLoginParam()); - BaseContext.setCurrentUser(user); - userHttpRequest.loadUserInfo(user); - BaseContext.removeCurrentUser(); - companycode = user.getCompanyCode(); - }*/ + //创建订单先对sysCode进行检查 + systemDomainService.checkSystemCode(syscode); // 创建 UserLoginParam 对象 UserLoginParam userLoginParam = new UserLoginParam(sfno, syscode, billcode, companycode, timespan); diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index 05f37c87..a3f2a15e 100644 --- a/src/main/java/com/chint/application/out/OrderOutController.java +++ b/src/main/java/com/chint/application/out/OrderOutController.java @@ -11,7 +11,6 @@ import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.UserRepository; import com.chint.domain.value_object.*; -import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.Result; import com.google.gson.Gson; @@ -25,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; +import static com.chint.infrastructure.constant.OrderConstant.*; @RestController @RequestMapping("/order") @@ -61,6 +61,11 @@ public class OrderOutController { User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId()); routeOrderRes.setUserName(user.getName()); routeOrderRes.setOrderDetailRes(orderDetailResList); + routeOrderRes.setOrderDetailRes(routeOrderRes + .getOrderDetailRes() + .stream() + .filter(it -> !it.getOrderStatus().equals(ORDER_EVENT_CANCEL_NAME) && !it.getOrderStatus().equals(ORDER_EVENT_PREPARE_NAME)) + .toList()); return Result.Success(SUCCESS, routeOrderRes); } @@ -81,6 +86,7 @@ public class OrderOutController { public Result estimateFlightPrice(@RequestBody PriceQueryData priceQueryData) { return Result.Success(SUCCESS, orderQuery.queryFlightPrice(priceQueryData)); } + @ApiOperation("查询酒店估算价格") @PostMapping("/estimate/hotel") public Result estimateHotelPrice(@RequestBody PriceQueryData priceQueryData) { @@ -88,6 +94,7 @@ public class OrderOutController { } + @ApiOperation("根据Id查询行程规划单-元年数据") @PostMapping("/query/tripCallback") public Result queryTripCallbackData(@RequestBody OrderQueryData queryData) { diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index 06176b0f..07550796 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -17,6 +17,7 @@ import com.chint.infrastructure.constant.DataMessageConstant; import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.constant.RouteConstant; import com.chint.infrastructure.echo_framework.command.Command; +import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -44,6 +45,8 @@ public class OrderApplicationService { @Autowired private LegFactory legFactory; + + @Transactional public RouteOrder saveOrder(OrderSaveData orderSaveData) { RouteOrder order; @@ -142,4 +145,8 @@ public class OrderApplicationService { Command.of(OrderApprovalCommand.class).data(data).sendToQueue(); } + @Transactional + public void reloadOrderDetail(SyncLegData syncLegData) { + + } } diff --git a/src/main/java/com/chint/domain/aggregates/order/Leg.java b/src/main/java/com/chint/domain/aggregates/order/Leg.java index 356eb0ff..4a83322e 100644 --- a/src/main/java/com/chint/domain/aggregates/order/Leg.java +++ b/src/main/java/com/chint/domain/aggregates/order/Leg.java @@ -9,6 +9,7 @@ import com.chint.infrastructure.constant.LegConstant; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Transient; import org.springframework.data.relational.core.mapping.Column; @@ -19,7 +20,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; - +@Slf4j @Data @Table("leg") @NoArgsConstructor @@ -173,7 +174,8 @@ public class Leg { // 检查是否已存在此类型的事件 boolean exists = eventList.stream().anyMatch(e -> e.getEventType().equals(newEventType)); if (exists) { - throw new LegEventException("Event of this type already exists."); + log.info("Event of this type already exists."); + return this; } // 如果列表为空,且新事件不是准备事件,抛出异常 diff --git a/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java b/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java index 7d9f2a71..93b6acba 100644 --- a/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java +++ b/src/main/java/com/chint/domain/aggregates/order/OrderDetail.java @@ -2,7 +2,6 @@ package com.chint.domain.aggregates.order; import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.value_object.enums.CurrencyType; -import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.constant.OrderConstant; import lombok.Data; @@ -16,6 +15,8 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND; + @Data @Table("order_detail") public class OrderDetail { @@ -93,6 +94,13 @@ public class OrderDetail { return this; } + public OrderEvent getLastEvent() { + return this.orderEventList + .stream() + .max(Comparator.comparingLong(OrderEvent::getOrderEventId)) + .orElseThrow(() -> new NotFoundException(NOT_FOUND)); + } + public OrderDetail price(String price) { this.price = price; return this; @@ -105,7 +113,7 @@ public class OrderDetail { case LegConstant.LEG_TYPE_HOTEL -> this.hotelOrderDetail; case LegConstant.LEG_TYPE_TAXI -> this.carOrderDetail; case LegConstant.LEG_TYPE_OTHER -> this.otherOrderDetail; - default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND); + default -> throw new NotFoundException(NOT_FOUND); }; } 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 99df485d..5c5bb9e3 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java @@ -12,6 +12,8 @@ import com.chint.infrastructure.constant.RouteConstant; import com.chint.infrastructure.constant.SupplierNameConstant; import com.chint.infrastructure.constant.UtilConstant; import com.chint.infrastructure.echo_framework.command.Command; +import com.chint.infrastructure.echo_framework.dispatch.Properties; +import com.chint.infrastructure.echo_framework.dispatch.ResultContainer; import com.chint.infrastructure.util.BigDecimalCalculator; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; @@ -28,6 +30,8 @@ import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; +import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL; + @Data @Table("route_order") public class RouteOrder extends BaseEntity { @@ -192,6 +196,8 @@ public class RouteOrder extends BaseEntity { return this; } + + public RouteOrder reloadStatus(OrderSaveData orderSaveData) { // 重新加载所有Leg的状态 List legs = this.getLegItems(); @@ -340,13 +346,13 @@ public class RouteOrder extends BaseEntity { }; } - public void matchOrderWithLeg(OrderDetail orderDetail) { + public OrderDetail matchOrderWithLeg(OrderDetail orderDetail) { if (this.legItems.isEmpty()) { - return; + return orderDetail; } // 定义时间容差(例如1天) - long tolerance = Duration.ofDays(1).toMillis(); + long tolerance = Duration.ofDays(2).toMillis(); List potentialMatches = this.legItems.stream() .filter(leg -> leg.getLegType().equals(orderDetail.getProductType()) @@ -363,11 +369,14 @@ public class RouteOrder extends BaseEntity { // 如果找到最佳匹配项,执行相应操作 if (bestMatch != null) { - Command.of(LegOrderedCommand.class) + Properties properties = Command.of(LegOrderedCommand.class) .legId(bestMatch.getLegId()) .orderDetailId(orderDetail.getOrderId()) .sendToQueue(); + ResultContainer byPropertyName = properties.findByPropertyName(RESULT_ORDER_DETAIL); + return (OrderDetail) byPropertyName.getValue(); } + return orderDetail; } private double calculateMatchScore(Leg leg, OrderDetail orderDetail, long tolerance) { diff --git a/src/main/java/com/chint/domain/aggregates/system/SystemCode.java b/src/main/java/com/chint/domain/aggregates/system/SystemCode.java new file mode 100644 index 00000000..6096622b --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/system/SystemCode.java @@ -0,0 +1,12 @@ +package com.chint.domain.aggregates.system; + +import lombok.Data; +import org.springframework.data.relational.core.mapping.Table; + +@Data +@Table("system_code") +public class SystemCode { + private Long id; + private String systemName; + private String systemCode; +} diff --git a/src/main/java/com/chint/domain/repository/OrderDetailRepository.java b/src/main/java/com/chint/domain/repository/OrderDetailRepository.java index 3a58bb45..c441d947 100644 --- a/src/main/java/com/chint/domain/repository/OrderDetailRepository.java +++ b/src/main/java/com/chint/domain/repository/OrderDetailRepository.java @@ -14,4 +14,6 @@ public interface OrderDetailRepository { OrderDetail save(OrderDetail orderDetail); + void deleteById(Long id); + } diff --git a/src/main/java/com/chint/domain/repository/SystemCodeRepository.java b/src/main/java/com/chint/domain/repository/SystemCodeRepository.java new file mode 100644 index 00000000..960b7590 --- /dev/null +++ b/src/main/java/com/chint/domain/repository/SystemCodeRepository.java @@ -0,0 +1,13 @@ +package com.chint.domain.repository; + + +import com.chint.domain.aggregates.system.SystemCode; + +public interface SystemCodeRepository { + + SystemCode save(SystemCode systemCode); + + SystemCode findBySysCode(String sysCode); + + SystemCode findById(Long id); +} diff --git a/src/main/java/com/chint/domain/service/OrderDetailDomainService.java b/src/main/java/com/chint/domain/service/OrderDetailDomainService.java new file mode 100644 index 00000000..24f3c8e1 --- /dev/null +++ b/src/main/java/com/chint/domain/service/OrderDetailDomainService.java @@ -0,0 +1,65 @@ +package com.chint.domain.service; + +import com.chint.domain.aggregates.order.OrderDetail; +import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.factoriy.order_detail.OrderDetailFactory; +import com.chint.domain.repository.OrderDetailRepository; +import com.chint.domain.repository.RouteRepository; +import com.chint.domain.service.order_search.OrderSearchSelector; +import com.chint.domain.service.supplier.OrderDataAdapterSelector; +import com.chint.domain.value_object.OrderLegData; +import com.chint.domain.value_object.SupplierCallbackData; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_CANCEL; + +@Service +public class OrderDetailDomainService { + + @Autowired + private OrderDetailRepository orderDetailRepository; + + @Autowired + private OrderDetailFactory orderDetailFactory; + + @Autowired + private RouteRepository routeRepository; + + @Autowired + private OrderSearchSelector orderSearchSelector; + + @Autowired + private OrderDataAdapterSelector orderDataAdapterSelector; + + public void syncOrderDetailStatus(List orderLegDataList) { + for (OrderLegData orderLegData : orderLegDataList) { + orderDetailRepository.findByOrderNo(orderLegData.getOutOrderNo()).ifPresent( + it -> { + if (!it.getLastEvent().getEventType().equals(orderLegData.getOrderStatus())) { + it.addOrderEvent(orderDetailFactory.createEvent(orderLegData.getOrderStatus(), + orderLegData.getOriginOrderStatus())); + orderDetailRepository.save(it); + } + } + ); + } + } + + public void syncOrderDetailStatusByRouteId(Long RouteId) { + RouteOrder routeOrder = routeRepository.queryById(RouteId); + String supplierName = routeOrder.getSupplierName(); + List orderLegDataList = new ArrayList<>(); + List list = routeOrder.getOrderDetails().stream() + .filter(it -> it.getLastEvent().getEventType() != ORDER_EVENT_CANCEL) + .map(OrderDetail::getOrderNo).toList(); + for (String orderNo : list) { + SupplierCallbackData supplierCallbackData = orderSearchSelector.of(supplierName).searchOrderDetail(orderNo); + orderDataAdapterSelector.of(supplierName).adapt(supplierCallbackData).ifPresent(orderLegDataList::add); + } + syncOrderDetailStatus(orderLegDataList); + } +} diff --git a/src/main/java/com/chint/domain/service/OrderDomainService.java b/src/main/java/com/chint/domain/service/OrderDomainService.java index 6208d9ef..8d5ca9d8 100644 --- a/src/main/java/com/chint/domain/service/OrderDomainService.java +++ b/src/main/java/com/chint/domain/service/OrderDomainService.java @@ -104,26 +104,25 @@ public class OrderDomainService { @ListenTo(command = "OrderStatusChangeCommand", order = 0) public void orderDetailStatusChange(OrderStatusChangeCommand command) { - orderDetailRepository.findByOrderNo(command.getOrderNo()).ifPresent(orderDetail -> { - String outStatus = command.getOutStatus(); - Integer orderEventType = command.getOrderEventType(); - OrderEvent event = orderDetailFactory.createEvent(orderEventType, - outStatus); - orderDetail.addOrderEvent(event); - orderDetailRepository.save(orderDetail); + OrderDetail orderDetail = command.getOrderDetail(); + String outStatus = command.getOutStatus(); + Integer orderEventType = command.getOrderEventType(); + OrderEvent event = orderDetailFactory.createEvent(orderEventType, + outStatus); + orderDetail.addOrderEvent(event); + orderDetailRepository.save(orderDetail); - if (orderEventType.equals(OrderConstant.ORDER_EVENT_ETA)) { - //这里如果发现事件的状态为ORDER_EVENT_ETA - //需要根据发送审批给bpm - //根据订单类型获取不同的订单扩展明细 - orderDetail.getExtensionDataByProductType(); - Command.of(BPMAuditCommand.class) - .orderNo(orderDetail.getOrderNo()) - .productType(orderDetail.getProductType()) - .extensionData(orderDetail.getExtensionDataByProductType()) - .sendToQueue(); - } - }); + if (orderEventType.equals(OrderConstant.ORDER_EVENT_ETA)) { + //这里如果发现事件的状态为ORDER_EVENT_ETA + //需要根据发送审批给bpm + //根据订单类型获取不同的订单扩展明细 + orderDetail.getExtensionDataByProductType(); + Command.of(BPMAuditCommand.class) + .orderNo(orderDetail.getOrderNo()) + .productType(orderDetail.getProductType()) + .extensionData(orderDetail.getExtensionDataByProductType()) + .sendToQueue(); + }; } @ListenTo(command = "BPMAuditCommand", order = 0) diff --git a/src/main/java/com/chint/domain/service/SystemDomainService.java b/src/main/java/com/chint/domain/service/SystemDomainService.java new file mode 100644 index 00000000..5ea54d2e --- /dev/null +++ b/src/main/java/com/chint/domain/service/SystemDomainService.java @@ -0,0 +1,23 @@ +package com.chint.domain.service; + +import com.chint.domain.exceptions.NotFoundException; +import com.chint.domain.repository.SystemCodeRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import static com.chint.infrastructure.constant.DataMessageConstant.SYS_CODE_ERROR; + +@Service +public class SystemDomainService { + + @Autowired + private SystemCodeRepository systemCodeRepository; + + public boolean checkSystemCode(String sysCode) { + boolean b = systemCodeRepository.findBySysCode(sysCode) != null; + if(!b){ + throw new NotFoundException(SYS_CODE_ERROR); + } + return b; + } +} 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 c40ccfd8..8965ef34 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 @@ -28,6 +28,8 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Optional; +import static com.chint.infrastructure.constant.DataMessageConstant.ORDER_STATUS_ERROR; +import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE; import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL; @Service @@ -76,10 +78,10 @@ public class LegEventHandler implements LegEventService { if (routeOrder.getLegItems().isEmpty()) { throw new OrderException(CommonMessageConstant.LEG_ERROR); } - if (routeOrder.getOrderStatus().equals(RouteConstant.ORDER_STATUS_PREPARE)) { + if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) { ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); approveOrderNo.setActualOrderNo(data.getActualOrderNo()); - approveOrderNo.setAccountCompany(data.getAccountCompany()); +// approveOrderNo.setAccountCompany(data.getAccountCompany()); approveOrderNo.setInstructions(data.getInstructions()); approveOrderNo.setCreator(data.getCreator()); //这里order所有的leg触发approve事件 @@ -92,8 +94,10 @@ public class LegEventHandler implements LegEventService { routeOrder.addApprovalEvent(approvalEvent); //保存routeOrder的状态 routeRepository.save(routeOrder); + } else if (routeOrder.getOrderStatus() > ORDER_STATUS_PREPARE) { + throw new CommandException(ORDER_STATUS_ERROR); } else { - throw new CommandException("订单未初始化"); + throw new CommandException(ORDER_STATUS_ERROR); } } @@ -105,7 +109,7 @@ public class LegEventHandler implements LegEventService { if (routeOrder.getOrderStatus() > (RouteConstant.ORDER_STATUS_APPROVAL)) { throw new CommandException("订单已同步"); } - if (routeOrder.getOrderStatus().equals(RouteConstant.ORDER_STATUS_PREPARE)) { + if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) { throw new CommandException("订单未提交审批"); } if (routeOrder.getOrderStatus().equals(RouteConstant.ORDER_STATUS_APPROVAL)) { @@ -158,7 +162,7 @@ public class LegEventHandler implements LegEventService { // .max(Comparator.comparing(OrderDetail::getCreateTime)) // .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)); //为订单添加订单已下单事件,这里需要发出额外的命令进行处理 - routeOrder.matchOrderWithLeg(orderDetail); + orderDetail = routeOrder.matchOrderWithLeg(orderDetail); } else { orderDetail = byOrderNo.get(); } @@ -167,7 +171,7 @@ public class LegEventHandler implements LegEventService { @Transactional @Override - public void orderLeg(LegOrderedCommand command) { + public ResultContainer orderLeg(LegOrderedCommand command) { //如果筛选事件可能会是错误,需要用户手动添加并修改事件 , 因此会进行额外出发修改下单事件。 Leg leg = legRepository.findByLegId(Leg.of(command.getLegId())); //因为orderDetail已经进行持久化保存 ,只需要从数据库进行查询 @@ -178,6 +182,7 @@ public class LegEventHandler implements LegEventService { orderDetail.setLegId(leg.getLegId()); legRepository.save(leg); orderDetailRepository.save(orderDetail); + return ResultContainer.of(RESULT_ORDER_DETAIL).value(orderDetail); } @Transactional diff --git a/src/main/java/com/chint/domain/service/leg_event/LegEventService.java b/src/main/java/com/chint/domain/service/leg_event/LegEventService.java index f30cf536..fd11e376 100644 --- a/src/main/java/com/chint/domain/service/leg_event/LegEventService.java +++ b/src/main/java/com/chint/domain/service/leg_event/LegEventService.java @@ -13,7 +13,7 @@ public interface LegEventService { void syncLeg(LegSyncCommand command); //下单事件 - void orderLeg(LegOrderedCommand command); + ResultContainer orderLeg(LegOrderedCommand command); ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command); diff --git a/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java b/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java index d41b7015..5f1e4ef0 100644 --- a/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java +++ b/src/main/java/com/chint/domain/service/leg_event/LegEventServiceImpl.java @@ -39,15 +39,14 @@ public class LegEventServiceImpl implements LegEventService { //下单时间要求回传,需要付款的金额,以及生成对于的行程订单号,如果没有行程订单号根据地点和时间进行匹配 @ListenTo(command = "LegOrderedCommand", order = 0) @Override - public void orderLeg(LegOrderedCommand command) { - legEventHandler.orderLeg(command); + public ResultContainer orderLeg(LegOrderedCommand command) { + return legEventHandler.orderLeg(command); } @ListenTo(command = "RouteUpdateOrderCommand", order = 0) @Override public ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command) { - legEventHandler.routeUpdateOrder(command); - return null; + return legEventHandler.routeUpdateOrder(command); } @Override diff --git a/src/main/java/com/chint/domain/service/order_search/CTripOrderSearchImpl.java b/src/main/java/com/chint/domain/service/order_search/CTripOrderSearchImpl.java new file mode 100644 index 00000000..eb7b5185 --- /dev/null +++ b/src/main/java/com/chint/domain/service/order_search/CTripOrderSearchImpl.java @@ -0,0 +1,22 @@ +package com.chint.domain.service.order_search; + +import com.chint.domain.service.supplier.OrderDataAdapterSelector; +import com.chint.domain.value_object.SupplierCallbackData; +import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest; +import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP; + +@Service +public class CTripOrderSearchImpl implements OrderSearchRequest { + @Autowired + private CTripOrderSearchRequest cTripOrderSearchRequest; + + @Override + public SupplierCallbackData searchOrderDetail(String orderNo) { + SearchOrderResponse response = cTripOrderSearchRequest.searchOrderResponseByOrderId(orderNo); + return SupplierCallbackData.of(SUPPLIER_C_TRIP).data(response); + } +} diff --git a/src/main/java/com/chint/domain/service/order_search/LYOrderSearchImpl.java b/src/main/java/com/chint/domain/service/order_search/LYOrderSearchImpl.java new file mode 100644 index 00000000..5bf4c837 --- /dev/null +++ b/src/main/java/com/chint/domain/service/order_search/LYOrderSearchImpl.java @@ -0,0 +1,12 @@ +package com.chint.domain.service.order_search; + +import com.chint.domain.value_object.SupplierCallbackData; +import org.springframework.stereotype.Component; + +@Component +public class LYOrderSearchImpl implements OrderSearchRequest{ + @Override + public SupplierCallbackData searchOrderDetail(String orderNo) { + return null; + } +} diff --git a/src/main/java/com/chint/domain/service/order_search/OrderSearchRequest.java b/src/main/java/com/chint/domain/service/order_search/OrderSearchRequest.java new file mode 100644 index 00000000..640bb501 --- /dev/null +++ b/src/main/java/com/chint/domain/service/order_search/OrderSearchRequest.java @@ -0,0 +1,9 @@ +package com.chint.domain.service.order_search; + + +import com.chint.domain.value_object.SupplierCallbackData; + +public interface OrderSearchRequest { + SupplierCallbackData searchOrderDetail(String orderNo); + +} diff --git a/src/main/java/com/chint/domain/service/order_search/OrderSearchSelector.java b/src/main/java/com/chint/domain/service/order_search/OrderSearchSelector.java new file mode 100644 index 00000000..63529dc3 --- /dev/null +++ b/src/main/java/com/chint/domain/service/order_search/OrderSearchSelector.java @@ -0,0 +1,28 @@ +package com.chint.domain.service.order_search; + +import com.chint.domain.exceptions.NotFoundException; +import com.chint.domain.service.supplier.CTripOrderDataAdapter; +import com.chint.domain.service.supplier.LYOrderDataAdapter; +import com.chint.domain.service.supplier.OrderDataAdapter; +import com.chint.infrastructure.constant.CommonMessageConstant; +import com.chint.infrastructure.constant.SupplierNameConstant; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class OrderSearchSelector { + @Autowired + private CTripOrderSearchImpl cTripOrderSearch; + + @Autowired + private LYOrderSearchImpl lyOrderSearch; + + public OrderSearchRequest of(String supplierName) { + // 当找不到匹配的适配器时,抛出一个异常 + return switch (supplierName) { + case SupplierNameConstant.SUPPLIER_C_TRIP -> cTripOrderSearch; + case SupplierNameConstant.SUPPLIER_L_Y -> lyOrderSearch; + default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND); + }; + } +} diff --git a/src/main/java/com/chint/domain/service/supplier/SupplierService.java b/src/main/java/com/chint/domain/service/supplier/SupplierService.java index 2422df43..dfe44ee5 100644 --- a/src/main/java/com/chint/domain/service/supplier/SupplierService.java +++ b/src/main/java/com/chint/domain/service/supplier/SupplierService.java @@ -1,7 +1,8 @@ package com.chint.domain.service.supplier; +import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.value_object.SupplierCallbackData; public interface SupplierService { - void handleSupplierCallback(SupplierCallbackData callbackData); + OrderDetail handleSupplierCallback(SupplierCallbackData callbackData); } \ No newline at end of file diff --git a/src/main/java/com/chint/domain/service/supplier/SupplierServiceImpl.java b/src/main/java/com/chint/domain/service/supplier/SupplierServiceImpl.java index 5f5a5ca8..05ec2cb4 100644 --- a/src/main/java/com/chint/domain/service/supplier/SupplierServiceImpl.java +++ b/src/main/java/com/chint/domain/service/supplier/SupplierServiceImpl.java @@ -2,9 +2,11 @@ package com.chint.domain.service.supplier; import com.chint.application.commands.RouteUpdateOrderCommand; import com.chint.domain.aggregates.order.OrderDetail; +import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.factoriy.order_detail.OrderExtensionCreator; import com.chint.domain.factoriy.order_detail.OrderExtensionFactory; import com.chint.domain.repository.OrderDetailRepository; +import com.chint.domain.value_object.OrderLegData; import com.chint.domain.value_object.SupplierCallbackData; import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.echo_framework.command.Command; @@ -13,6 +15,9 @@ import com.chint.infrastructure.echo_framework.dispatch.ResultContainer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Optional; + +import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND; import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL; @Service @@ -28,45 +33,43 @@ public class SupplierServiceImpl implements SupplierService { private OrderDetailRepository orderDetailRepository; @Override - public void handleSupplierCallback(SupplierCallbackData callbackData) { + public OrderDetail handleSupplierCallback(SupplierCallbackData callbackData) { String supplierName = callbackData.getSupplierName(); - orderDataAdapterSelector - .of(supplierName) - .adapt(callbackData) - .ifPresent(data -> { - System.out.println(data); - //获取使用RouteUpdateOrderCommand命令创建的orderDetail - Properties properties = Command.of(RouteUpdateOrderCommand.class).data(data).sendToQueue(); - ResultContainer byPropertyName = properties.findByPropertyName(RESULT_ORDER_DETAIL); - OrderDetail orderDetail = (OrderDetail) byPropertyName.getValue(); + Optional data = orderDataAdapterSelector.of(supplierName).adapt(callbackData); + if (data.isPresent()) { + //获取使用RouteUpdateOrderCommand命令创建的orderDetail + Properties properties = Command.of(RouteUpdateOrderCommand.class).data(data.get()).sendToQueue(); + ResultContainer byPropertyName = properties.findByPropertyName(RESULT_ORDER_DETAIL); + OrderDetail orderDetail = (OrderDetail) byPropertyName.getValue(); - Integer productType = data.getProductType(); - OrderExtensionFactory orderExtensionFactory = orderExtensionCreator - .of(supplierName); - Object callbackDataData = callbackData.getData(); + Integer productType = data.get().getProductType(); + OrderExtensionFactory orderExtensionFactory = orderExtensionCreator + .of(supplierName); + Object callbackDataData = callbackData.getData(); - //根据产品的不同类型添加不同的扩展字段 - switch (productType) { - case LegConstant.LEG_TYPE_TRAIN -> orderDetail.addTrainOrderData( - orderExtensionFactory.createTrainOrderDetail(callbackDataData) - ); - case LegConstant.LEG_TYPE_AIRPLANE -> orderDetail.addFlightOrderData( - orderExtensionFactory.createFlightOrderDetail(callbackDataData) - ); - case LegConstant.LEG_TYPE_HOTEL -> orderDetail.addHotelOrderData( - orderExtensionFactory.createHotelOrderDetail(callbackDataData) - ); - case LegConstant.LEG_TYPE_TAXI -> orderDetail.addCarOrderData( - orderExtensionFactory.createCarOrderDetail(callbackDataData) - ); - case LegConstant.LEG_TYPE_OTHER -> orderDetail.addOtherOrderData( - orderExtensionFactory.createOtherOrderDetail(callbackDataData) - ); - } - - //对orderDetail进行保存 - orderDetailRepository.save(orderDetail); - }); + //根据产品的不同类型添加不同的扩展字段 + switch (productType) { + case LegConstant.LEG_TYPE_TRAIN -> orderDetail.addTrainOrderData( + orderExtensionFactory.createTrainOrderDetail(callbackDataData) + ); + case LegConstant.LEG_TYPE_AIRPLANE -> orderDetail.addFlightOrderData( + orderExtensionFactory.createFlightOrderDetail(callbackDataData) + ); + case LegConstant.LEG_TYPE_HOTEL -> orderDetail.addHotelOrderData( + orderExtensionFactory.createHotelOrderDetail(callbackDataData) + ); + case LegConstant.LEG_TYPE_TAXI -> orderDetail.addCarOrderData( + orderExtensionFactory.createCarOrderDetail(callbackDataData) + ); + case LegConstant.LEG_TYPE_OTHER -> orderDetail.addOtherOrderData( + orderExtensionFactory.createOtherOrderDetail(callbackDataData) + ); + } + //对orderDetail进行保存 + return orderDetailRepository.save(orderDetail); + } else { + throw new NotFoundException(NOT_FOUND); + } } } diff --git a/src/main/java/com/chint/domain/value_object/ApproveLegData.java b/src/main/java/com/chint/domain/value_object/ApproveLegData.java index 35b93a24..ccdcc89f 100644 --- a/src/main/java/com/chint/domain/value_object/ApproveLegData.java +++ b/src/main/java/com/chint/domain/value_object/ApproveLegData.java @@ -1,13 +1,20 @@ package com.chint.domain.value_object; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data public class ApproveLegData { + @ApiModelProperty("实际财务共享订单号") private String actualOrderNo; + @ApiModelProperty("临时财务共享订单号") private String fakeOrderNo; + @ApiModelProperty("入账公司") private String accountCompany; + @ApiModelProperty("系统标识") private String sysCode; + @ApiModelProperty("出差说明") private String instructions; + @ApiModelProperty("财务共享订单创建人") private String creator; } diff --git a/src/main/java/com/chint/infrastructure/constant/DataMessageConstant.java b/src/main/java/com/chint/infrastructure/constant/DataMessageConstant.java index 8e0f256e..b8520880 100644 --- a/src/main/java/com/chint/infrastructure/constant/DataMessageConstant.java +++ b/src/main/java/com/chint/infrastructure/constant/DataMessageConstant.java @@ -8,4 +8,6 @@ public class DataMessageConstant { public static final String DATA_DELETION_SUCCESS = "数据删除成功"; public static final String DATA_NOT_FOUND = "未找到数据"; public static final String DATA_INVALID = "数据不合法"; + public static final String SYS_CODE_ERROR = "系统标识字段错误"; + public static final String ORDER_STATUS_ERROR = "订单状态错误"; } diff --git a/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java index 982ac38e..9a3856fc 100644 --- a/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/OrderDetailRepositoryImpl.java @@ -36,4 +36,9 @@ public class OrderDetailRepositoryImpl implements OrderDetailRepository { public OrderDetail save(OrderDetail orderDetail) { return orderDetailRepository.save(orderDetail); } + + @Override + public void deleteById(Long id) { + orderDetailRepository.deleteById(id); + } } diff --git a/src/main/java/com/chint/infrastructure/repository/SystemCodeRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/SystemCodeRepositoryImpl.java new file mode 100644 index 00000000..22cf35c2 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/SystemCodeRepositoryImpl.java @@ -0,0 +1,32 @@ +package com.chint.infrastructure.repository; + +import com.chint.domain.aggregates.system.SystemCode; +import com.chint.domain.exceptions.NotFoundException; +import com.chint.domain.repository.SystemCodeRepository; +import com.chint.infrastructure.repository.jdbc.JdbcSystemCodeRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND; + +@Repository +public class SystemCodeRepositoryImpl implements SystemCodeRepository { + + @Autowired + private JdbcSystemCodeRepository jdbcSystemCodeRepository; + + @Override + public SystemCode save(SystemCode systemCode) { + return jdbcSystemCodeRepository.save(systemCode); + } + + @Override + public SystemCode findBySysCode(String sysCode) { + return jdbcSystemCodeRepository.findBySystemCode(sysCode); + } + + @Override + public SystemCode findById(Long id) { + return jdbcSystemCodeRepository.findById(id).orElseThrow(() -> new NotFoundException(NOT_FOUND)); + } +} diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemCodeRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemCodeRepository.java new file mode 100644 index 00000000..4585c0a9 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSystemCodeRepository.java @@ -0,0 +1,12 @@ +package com.chint.infrastructure.repository.jdbc; + +import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.aggregates.system.SystemCode; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface JdbcSystemCodeRepository extends CrudRepository { + + SystemCode findBySystemCode(String systemCode); +} diff --git a/src/main/java/com/chint/interfaces/rest/base/PostRequest.java b/src/main/java/com/chint/interfaces/rest/base/PostRequest.java index 51216c99..b9e04e59 100644 --- a/src/main/java/com/chint/interfaces/rest/base/PostRequest.java +++ b/src/main/java/com/chint/interfaces/rest/base/PostRequest.java @@ -1,6 +1,7 @@ package com.chint.interfaces.rest.base; import com.google.gson.Gson; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -14,6 +15,7 @@ import org.springframework.stereotype.Component; import java.io.IOException; @Component +@Slf4j public class PostRequest { private final Gson gson = new Gson(); private final HttpClient client = HttpClients.createDefault(); @@ -21,7 +23,7 @@ public class PostRequest { public T post(String url, Object jsonRequest, Class responseType) { HttpPost post = new HttpPost(url); String json = gson.toJson(jsonRequest); - System.out.println(json); + log.info(json); post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); String responseBody = null; HttpEntity responseEntity = null; @@ -40,7 +42,7 @@ public class PostRequest { HttpPost post = new HttpPost(url); post.addHeader(headName, headValue); String json = gson.toJson(jsonRequest); - System.out.println(json); + log.info(json); post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); String responseBody = null; HttpEntity responseEntity = null; diff --git a/src/main/java/com/chint/interfaces/rest/bpm/BPMParamFactory.java b/src/main/java/com/chint/interfaces/rest/bpm/BPMParamFactory.java index 51c7ce81..8fc612ea 100644 --- a/src/main/java/com/chint/interfaces/rest/bpm/BPMParamFactory.java +++ b/src/main/java/com/chint/interfaces/rest/bpm/BPMParamFactory.java @@ -6,6 +6,7 @@ import com.chint.infrastructure.constant.BPMConstant; import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.constant.SupplierNameConstant; import com.chint.interfaces.rest.bpm.dto.ExceedStandardDto; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Component; import java.math.BigDecimal; diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java b/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java index a9221fef..7b9472bb 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java @@ -1,6 +1,7 @@ package com.chint.interfaces.rest.ctrip.in; import com.chint.application.commands.OrderStatusChangeCommand; +import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.service.supplier.SupplierService; import com.chint.domain.value_object.SupplierCallbackData; import com.chint.infrastructure.constant.OrderConstant; @@ -13,6 +14,7 @@ import com.chint.interfaces.rest.ctrip.dto.put.CTripStatusResponse; import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +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; @@ -52,6 +54,7 @@ public class CTripNoteController { // return new CTripNoteResponse("1", "未收到消息"); // } + @Transactional @PostMapping("/status") public CTripStatusResponse statusEvent(@RequestBody CTripStatusNotification cTripStatusNotification) { String productType = cTripStatusNotification.getProductType(); @@ -62,45 +65,51 @@ public class CTripNoteController { return new CTripStatusResponse("1", "sign错误"); } if (orderStatus != null && orderId != null) { - SupplierCallbackData supplierCallbackData = - SupplierCallbackData.of(SupplierNameConstant.SUPPLIER_C_TRIP); - SearchOrderResponse response = cTripOrderSearchRequest - .searchOrderResponseByOrderId(orderId); - supplierCallbackData.data(response); - supplierService.handleSupplierCallback(supplierCallbackData); - - OrderStatusChangeCommand command = Command.of(OrderStatusChangeCommand.class) - .orderNo(orderId) - .outStatus(orderStatus); - switch (productType) { - case "FlightInternational": - case "FlightDomestic": - command.eventType(mapFlightStatus(orderStatus)); - break; - case "HotelMember": - case "HotelContract": - command.eventType(mapHotelStatus(orderStatus)); - break; - case "Train": - case "OverseaTrain": - command.eventType(mapTrainStatus(orderStatus)); - break; - case "CarPickUpInternational": - case "CarRentalDomestic": - case "CarImmediately": - case "CarPickUpDomesticNew": - case "CarCharterDomestic": - case "BusTicket": - command.eventType(mapCarStatus(orderStatus)); - break; - } - command.sendToQueue(); - return new CTripStatusResponse("0", "成功收到消息"); + return handlerData(orderId, orderStatus, productType); } return new CTripStatusResponse("1", "未收到消息"); } + public CTripStatusResponse handlerData(String orderId, String orderStatus, String productType) { + SupplierCallbackData supplierCallbackData = + SupplierCallbackData.of(SupplierNameConstant.SUPPLIER_C_TRIP); + SearchOrderResponse response = cTripOrderSearchRequest + .searchOrderResponseByOrderId(orderId); + supplierCallbackData.data(response); + OrderDetail orderDetail = supplierService.handleSupplierCallback(supplierCallbackData); + + OrderStatusChangeCommand command = Command.of(OrderStatusChangeCommand.class) + .orderDetail(orderDetail) + .orderNo(orderId) + .outStatus(orderStatus); + switch (productType) { + case "FlightInternational": + case "FlightDomestic": + command.eventType(mapFlightStatus(orderStatus)); + break; + case "HotelMember": + case "HotelContract": + command.eventType(mapHotelStatus(orderStatus)); + break; + case "Train": + case "OverseaTrain": + command.eventType(mapTrainStatus(orderStatus)); + break; + case "CarPickUpInternational": + case "CarRentalDomestic": + case "CarImmediately": + case "CarPickUpDomesticNew": + case "CarCharterDomestic": + case "BusTicket": + command.eventType(mapCarStatus(orderStatus)); + break; + } + command.sendToQueue(); + return new CTripStatusResponse("0", "成功收到消息"); + } + + public Integer mapFlightStatus(String status) { return switch (status) { case "Submitted" -> OrderConstant.ORDER_EVENT_PREPARE; // "已提交"映射到准备下单 diff --git a/src/main/java/com/chint/interfaces/rest/ly/LYUserRequest.java b/src/main/java/com/chint/interfaces/rest/ly/LYUserRequest.java index b62557ea..6fd6fcb3 100644 --- a/src/main/java/com/chint/interfaces/rest/ly/LYUserRequest.java +++ b/src/main/java/com/chint/interfaces/rest/ly/LYUserRequest.java @@ -4,14 +4,20 @@ import com.chint.domain.aggregates.user.User; import com.chint.infrastructure.util.BaseContext; import com.chint.interfaces.rest.ly.dto.user.EmployeeRequest; import com.chint.interfaces.rest.ly.dto.user.EmployeeEntity; +import com.chint.interfaces.rest.ly.dto.user.PreTravelPolicy; import com.chint.interfaces.rest.user.UserHttpRequest; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.chint.interfaces.rest.ly.dto.user.UserResponse; +import java.util.ArrayList; +import java.util.List; + import static com.chint.infrastructure.constant.LYConstant.L_Y_BASE_URL; import static com.chint.infrastructure.constant.LYConstant.L_Y_USER_PATH; +@Slf4j @Service public class LYUserRequest { @@ -27,7 +33,7 @@ public class LYUserRequest { private final String userUrl = L_Y_BASE_URL + L_Y_USER_PATH; public boolean saveCurrentUser() { - System.out.println("saveCurrentUser"); + log.info("saveCurrentUser"); User currentUser = BaseContext.getCurrentUser(); userHttpRequest.loadUserInfo(currentUser); EmployeeEntity employeeEntity = user2LYEmployee(currentUser); @@ -66,7 +72,17 @@ public class LYUserRequest { employeeEntity.setGender(translateGender(user.getGender())); employeeEntity.setWorkingState(translateWorkStatus(user.getWorkStatus())); employeeEntity.setReservationType(0); - employeeEntity.setPositionLevelName(user.getStandardLevel()); + String standardLevel = user.getStandardLevel(); + employeeEntity.setPositionLevelName(standardLevel); + List preTravelPolicyList = List.of( + new PreTravelPolicy(standardLevel,1), + new PreTravelPolicy(standardLevel,2), + new PreTravelPolicy(standardLevel,3), + new PreTravelPolicy(standardLevel,4), + new PreTravelPolicy(standardLevel,5), + new PreTravelPolicy(standardLevel,6) + ); + employeeEntity.setPreTravelPolicyList(preTravelPolicyList); return employeeEntity; } } diff --git a/src/main/java/com/chint/interfaces/rest/ly/dto/user/EmployeeEntity.java b/src/main/java/com/chint/interfaces/rest/ly/dto/user/EmployeeEntity.java index 96cec90a..705b224d 100644 --- a/src/main/java/com/chint/interfaces/rest/ly/dto/user/EmployeeEntity.java +++ b/src/main/java/com/chint/interfaces/rest/ly/dto/user/EmployeeEntity.java @@ -32,5 +32,5 @@ public class EmployeeEntity { private Map remarks; private String baseCity; - // Getters and setters + } \ No newline at end of file diff --git a/src/main/java/com/chint/interfaces/rest/ly/dto/user/PreTravelPolicy.java b/src/main/java/com/chint/interfaces/rest/ly/dto/user/PreTravelPolicy.java index 4700bd91..66b0c923 100644 --- a/src/main/java/com/chint/interfaces/rest/ly/dto/user/PreTravelPolicy.java +++ b/src/main/java/com/chint/interfaces/rest/ly/dto/user/PreTravelPolicy.java @@ -1,5 +1,10 @@ package com.chint.interfaces.rest.ly.dto.user; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor public class PreTravelPolicy { private String policyCode; private int productTypeId; 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 807101b8..baaba1bf 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java @@ -15,6 +15,7 @@ import com.chint.interfaces.rest.base.PostRequest; import com.chint.interfaces.rest.user.dto.*; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClients; @@ -31,6 +32,8 @@ import static com.chint.infrastructure.constant.RankConstant.STANDARD_LEVEL_THRE import static com.chint.infrastructure.constant.SFConstant.OPENAI_BASE_URL; import static com.chint.infrastructure.constant.SFConstant.USER_DATA_PATH; + +@Slf4j @Service public class UserHttpRequestImpl implements UserHttpRequest { @@ -113,7 +116,6 @@ public class UserHttpRequestImpl implements UserHttpRequest { user.setProfLevel(userData.getCust_profLevel()); } else { Optional first; - //这里进行判断如果是中文字段的CompanyCode需要用中文名进行匹配 if (StringCheck.isFirstCharacterChinese(newCompanyCode)) { first = fromJson.stream() diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 2e315c72..ab43f354 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -1,32 +1,33 @@ server: port: 8081 -chint: - datasource: - driver-class-name: com.mysql.cj.jdbc.Driver - host: rm-cn-jeo3lfy9q0006gso.rwlb.rds.aliyuncs.com - # host: 10.9.56.48 - port: 3306 - database: itinerary_booking - username: echo - password: R3nd0mP@ssw0rd! - url: https://gxdev03.chint.com/businesstravel/ - #chint: # datasource: # driver-class-name: com.mysql.cj.jdbc.Driver -# host: 10.10.24.44 +# host: rm-cn-jeo3lfy9q0006gso.rwlb.rds.aliyuncs.com # # host: 10.9.56.48 -# port: 6603 +# port: 3306 # database: itinerary_booking -# username: tripbook -# password: W@Xgf25d&lRk*L0X# +# username: echo +# password: R3nd0mP@ssw0rd! # url: https://gxdev03.chint.com/businesstravel/ +chint: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + host: 10.10.24.44 + # host: 10.9.56.48 + port: 6603 + database: itinerary_booking + username: tripbook + password: W@Xgf25d&lRk*L0X# + url: https://gxdev03.chint.com/businesstravel/ + logging: level: org.springframework.jdbc.core.JdbcTemplate: DEBUG org.springframework.jdbc.core.StatementCreatorUtils: TRACE + root: info cTrip: diff --git a/src/test/java/com/chint/CTripTest.java b/src/test/java/com/chint/CTripTest.java index 8a01106d..1af82acd 100644 --- a/src/test/java/com/chint/CTripTest.java +++ b/src/test/java/com/chint/CTripTest.java @@ -16,6 +16,7 @@ import com.chint.interfaces.rest.ctrip.dto.location.CTripCountry; import com.chint.interfaces.rest.ctrip.dto.login.CTripLoginParam; import com.chint.interfaces.rest.ctrip.dto.login.PCResponse; import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse; +import com.chint.interfaces.rest.ctrip.in.CTripNoteController; import com.google.gson.Gson; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -50,6 +51,9 @@ public class CTripTest { @Autowired private SupplierService supplierService; + @Autowired + private CTripNoteController cTripNoteController; + private User user = new User(1L, 230615020L, 1, "卢麟哲", "1033719135@qq.com", "15857193365"); //@Test @@ -158,4 +162,10 @@ public class CTripTest { supplierCallbackData.data(response); supplierService.handleSupplierCallback(supplierCallbackData); } + + @Test + void backData(){ + BaseContext.setCurrentUser(user); + cTripNoteController.handlerData("30607415392","Paid","HotelContract"); + } } diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 782a3f18..0488aa4d 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -4,9 +4,11 @@ import cn.hutool.extra.pinyin.PinyinUtil; import com.chint.domain.aggregates.order.Location; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.LocationRepository; +import com.chint.domain.repository.OrderDetailRepository; import com.chint.domain.repository.RouteRepository; import com.chint.infrastructure.util.Digest; import com.chint.interfaces.rest.user.UserHttpRequest; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -16,6 +18,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; +@Slf4j @SpringBootTest class RouteApplicationTests { @@ -28,6 +31,8 @@ class RouteApplicationTests { @Autowired private RouteRepository routeRepository; + @Autowired + private OrderDetailRepository orderDetailRepository; private User user = new User(1L, 230615020L, 1, "卢麟哲", "1033719135@qq.com", "15857193365"); @@ -45,14 +50,18 @@ class RouteApplicationTests { } @Test void loginSign() { - String sfno = "210901385"; + String sfno = "230615020"; String syscode = "FSSC"; - String billcode = "CLSQ240226000004"; + String billcode = "CLSQ240225000099"; String companycode = "正泰集团股份有限公司"; String sec = "Superdandan"; String timespan = "1708908662738"; String s = Digest.md5(sfno + syscode + billcode + companycode + sec + timespan); System.out.println(s); +// log.info("info"); +// log.trace("trace"); +// log.trace("trace"); +// log.trace("trace"); } // @Test @@ -92,4 +101,16 @@ class RouteApplicationTests { routeRepository.deleteById(19L); routeRepository.deleteById(19L); } + @Test + void deleteOrderDetail(){ + orderDetailRepository.deleteById(15L); + orderDetailRepository.deleteById(18L); + orderDetailRepository.deleteById(19L); + orderDetailRepository.deleteById(20L); + orderDetailRepository.deleteById(23L); + orderDetailRepository.deleteById(26L); + orderDetailRepository.deleteById(28L); + orderDetailRepository.deleteById(31L); + orderDetailRepository.deleteById(33L); + } }