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 15b88fdc..c40ccfd8 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 @@ -20,6 +20,7 @@ import com.chint.domain.value_object.SyncLegData; import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.constant.RouteConstant; +import com.chint.infrastructure.echo_framework.dispatch.ResultContainer; import com.chint.infrastructure.util.BaseContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -27,6 +28,8 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Optional; +import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL; + @Service public class LegEventHandler implements LegEventService { @@ -129,7 +132,7 @@ public class LegEventHandler implements LegEventService { @Transactional @Override - public void routeUpdateOrder(RouteUpdateOrderCommand command) { + public ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command) { OrderLegData data = command.getData(); String orderNo = data.getSelfOrderNo(); RouteOrder routeOrder = routeRepository.findByOrderNo(orderNo); @@ -137,14 +140,15 @@ public class LegEventHandler implements LegEventService { Long employeeNo = routeOrder.getUserId(); User byUserEmployeeNo = userRepository.findByUserEmployeeNo(employeeNo); BaseContext.setCurrentUser(byUserEmployeeNo); + OrderDetail orderDetail; //首先查询到行程规划订单 , 从routOrder当中查询是否以及存在该订单 Optional byOrderNo = routeOrder.getOrderDetails() .stream() - .filter(orderDetail -> orderDetail.getOrderNo().equals(data.getOutOrderNo())) + .filter(it -> it.getOrderNo().equals(data.getOutOrderNo())) .findFirst(); if (byOrderNo.isEmpty()) { //否则创建新的订单添加到routeOrder - OrderDetail orderDetail = orderDetailFactory.create(data) + orderDetail = orderDetailFactory.create(data) .price(data.getPrice()).productType(data.getProductType()); routeOrder.addOrderDetail(orderDetail); routeOrder = routeRepository.save(routeOrder); @@ -155,7 +159,10 @@ public class LegEventHandler implements LegEventService { // .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)); //为订单添加订单已下单事件,这里需要发出额外的命令进行处理 routeOrder.matchOrderWithLeg(orderDetail); + } else { + orderDetail = byOrderNo.get(); } + 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 a1bfd78c..f30cf536 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 @@ -2,6 +2,7 @@ package com.chint.domain.service.leg_event; import com.chint.application.commands.*; +import com.chint.infrastructure.echo_framework.dispatch.ResultContainer; public interface LegEventService { void prepareLeg(LegPrepareCommand command); @@ -14,7 +15,7 @@ public interface LegEventService { //下单事件 void orderLeg(LegOrderedCommand command); - void routeUpdateOrder(RouteUpdateOrderCommand command); + ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command); //付款 void payForLeg(LegPayedCommand 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 dc4c0594..d41b7015 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 @@ -3,6 +3,7 @@ package com.chint.domain.service.leg_event; import com.chint.application.commands.*; import com.chint.infrastructure.echo_framework.annotation.ListenTo; import com.chint.infrastructure.echo_framework.annotation.TransitionTo; +import com.chint.infrastructure.echo_framework.dispatch.ResultContainer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -13,7 +14,6 @@ public class LegEventServiceImpl implements LegEventService { private LegEventHandler legEventHandler; - @TransitionTo(command = "LegPrepareCommand", order = 0) @Override public void prepareLeg(LegPrepareCommand command) { @@ -45,8 +45,9 @@ public class LegEventServiceImpl implements LegEventService { @ListenTo(command = "RouteUpdateOrderCommand", order = 0) @Override - public void routeUpdateOrder(RouteUpdateOrderCommand command) { + public ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command) { legEventHandler.routeUpdateOrder(command); + return null; } @Override 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 479e4f0e..5f5a5ca8 100644 --- a/src/main/java/com/chint/domain/service/supplier/SupplierServiceImpl.java +++ b/src/main/java/com/chint/domain/service/supplier/SupplierServiceImpl.java @@ -1,25 +1,72 @@ package com.chint.domain.service.supplier; import com.chint.application.commands.RouteUpdateOrderCommand; +import com.chint.domain.aggregates.order.OrderDetail; +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.SupplierCallbackData; +import com.chint.infrastructure.constant.LegConstant; 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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL; + @Service public class SupplierServiceImpl implements SupplierService { @Autowired private OrderDataAdapterSelector orderDataAdapterSelector; + @Autowired + private OrderExtensionCreator orderExtensionCreator; + + @Autowired + private OrderDetailRepository orderDetailRepository; + @Override public void handleSupplierCallback(SupplierCallbackData callbackData) { + String supplierName = callbackData.getSupplierName(); orderDataAdapterSelector - .of(callbackData.getSupplierName()) + .of(supplierName) .adapt(callbackData) .ifPresent(data -> { + System.out.println(data); - Command.of(RouteUpdateOrderCommand.class).data(data).sendToQueue(); + //获取使用RouteUpdateOrderCommand命令创建的orderDetail + Properties properties = Command.of(RouteUpdateOrderCommand.class).data(data).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(); + + //根据产品的不同类型添加不同的扩展字段 + 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); }); } } diff --git a/src/main/java/com/chint/infrastructure/constant/UtilConstant.java b/src/main/java/com/chint/infrastructure/constant/UtilConstant.java index d2cedffc..37f440f0 100644 --- a/src/main/java/com/chint/infrastructure/constant/UtilConstant.java +++ b/src/main/java/com/chint/infrastructure/constant/UtilConstant.java @@ -3,4 +3,6 @@ package com.chint.infrastructure.constant; public class UtilConstant { // 金额 public static final String KEEP_TWO_DECIMAL_ZERO = "0.00"; + + public static final String RESULT_ORDER_DETAIL = "ResultContainer"; } diff --git a/src/main/java/com/chint/infrastructure/echo_framework/dispatch/ResultContainer.java b/src/main/java/com/chint/infrastructure/echo_framework/dispatch/ResultContainer.java index 6ce764a6..a48d4c78 100644 --- a/src/main/java/com/chint/infrastructure/echo_framework/dispatch/ResultContainer.java +++ b/src/main/java/com/chint/infrastructure/echo_framework/dispatch/ResultContainer.java @@ -9,4 +9,16 @@ public class ResultContainer { private Object source; private String propertyName; private Object value; + + public static ResultContainer of(String propertyName) { + ResultContainer resultContainer = new ResultContainer(); + resultContainer.setPropertyName(propertyName); + return resultContainer; + } + + public ResultContainer value(Object value) { + this.value = value; + return this; + } + } \ No newline at end of file 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 c67a10a5..a94f4dcc 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java @@ -9,11 +9,10 @@ import com.chint.domain.aggregates.standards.Ranks; import com.chint.domain.aggregates.user.User; import com.chint.domain.service.RankDomainService; import com.chint.infrastructure.constant.SFConstant; +import com.chint.infrastructure.util.BaseContext; +import com.chint.infrastructure.util.StringCheck; import com.chint.interfaces.rest.base.PostRequest; -import com.chint.interfaces.rest.user.dto.AccessKeyDTO; -import com.chint.interfaces.rest.user.dto.TravelRankDTO; -import com.chint.interfaces.rest.user.dto.TravelRankParam; -import com.chint.interfaces.rest.user.dto.TravelRankResponseDTO; +import com.chint.interfaces.rest.user.dto.*; import com.google.gson.Gson; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; @@ -22,6 +21,9 @@ import org.apache.http.util.EntityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.LinkedHashMap; +import java.util.List; + @Service public class UserHttpRequestImpl implements UserHttpRequest { @@ -85,8 +87,6 @@ public class UserHttpRequestImpl implements UserHttpRequest { // Type type = new TypeToken>() { // }.getType(); // if (result.getData() != null) { -//// List fromJson = gson.fromJson(result.getData().toString(), type); -//// UserDataDTO userDataDTO = fromJson.get(0); // String companyCode = user.getCompanyCode(); // if (companyCode == null) { // companyCode = BaseContext.getCurrentUser().getUserLoginParam().getCompanyCode();