完成超标状态回推bpm代码

This commit is contained in:
Superdandan 2024-02-25 22:04:02 +08:00
parent dfa050cbff
commit 07685dbd35
7 changed files with 84 additions and 14 deletions

View File

@ -20,6 +20,7 @@ import com.chint.domain.value_object.SyncLegData;
import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.constant.CommonMessageConstant;
import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.constant.LegConstant;
import com.chint.infrastructure.constant.RouteConstant; import com.chint.infrastructure.constant.RouteConstant;
import com.chint.infrastructure.echo_framework.dispatch.ResultContainer;
import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.BaseContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -27,6 +28,8 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Optional; import java.util.Optional;
import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL;
@Service @Service
public class LegEventHandler implements LegEventService { public class LegEventHandler implements LegEventService {
@ -129,7 +132,7 @@ public class LegEventHandler implements LegEventService {
@Transactional @Transactional
@Override @Override
public void routeUpdateOrder(RouteUpdateOrderCommand command) { public ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command) {
OrderLegData data = command.getData(); OrderLegData data = command.getData();
String orderNo = data.getSelfOrderNo(); String orderNo = data.getSelfOrderNo();
RouteOrder routeOrder = routeRepository.findByOrderNo(orderNo); RouteOrder routeOrder = routeRepository.findByOrderNo(orderNo);
@ -137,14 +140,15 @@ public class LegEventHandler implements LegEventService {
Long employeeNo = routeOrder.getUserId(); Long employeeNo = routeOrder.getUserId();
User byUserEmployeeNo = userRepository.findByUserEmployeeNo(employeeNo); User byUserEmployeeNo = userRepository.findByUserEmployeeNo(employeeNo);
BaseContext.setCurrentUser(byUserEmployeeNo); BaseContext.setCurrentUser(byUserEmployeeNo);
OrderDetail orderDetail;
//首先查询到行程规划订单 从routOrder当中查询是否以及存在该订单 //首先查询到行程规划订单 从routOrder当中查询是否以及存在该订单
Optional<OrderDetail> byOrderNo = routeOrder.getOrderDetails() Optional<OrderDetail> byOrderNo = routeOrder.getOrderDetails()
.stream() .stream()
.filter(orderDetail -> orderDetail.getOrderNo().equals(data.getOutOrderNo())) .filter(it -> it.getOrderNo().equals(data.getOutOrderNo()))
.findFirst(); .findFirst();
if (byOrderNo.isEmpty()) { if (byOrderNo.isEmpty()) {
//否则创建新的订单添加到routeOrder //否则创建新的订单添加到routeOrder
OrderDetail orderDetail = orderDetailFactory.create(data) orderDetail = orderDetailFactory.create(data)
.price(data.getPrice()).productType(data.getProductType()); .price(data.getPrice()).productType(data.getProductType());
routeOrder.addOrderDetail(orderDetail); routeOrder.addOrderDetail(orderDetail);
routeOrder = routeRepository.save(routeOrder); routeOrder = routeRepository.save(routeOrder);
@ -155,7 +159,10 @@ public class LegEventHandler implements LegEventService {
// .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)); // .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND));
//为订单添加订单已下单事件,这里需要发出额外的命令进行处理 //为订单添加订单已下单事件,这里需要发出额外的命令进行处理
routeOrder.matchOrderWithLeg(orderDetail); routeOrder.matchOrderWithLeg(orderDetail);
} else {
orderDetail = byOrderNo.get();
} }
return ResultContainer.of(RESULT_ORDER_DETAIL).value(orderDetail);
} }
@Transactional @Transactional

View File

@ -2,6 +2,7 @@ package com.chint.domain.service.leg_event;
import com.chint.application.commands.*; import com.chint.application.commands.*;
import com.chint.infrastructure.echo_framework.dispatch.ResultContainer;
public interface LegEventService { public interface LegEventService {
void prepareLeg(LegPrepareCommand command); void prepareLeg(LegPrepareCommand command);
@ -14,7 +15,7 @@ public interface LegEventService {
//下单事件 //下单事件
void orderLeg(LegOrderedCommand command); void orderLeg(LegOrderedCommand command);
void routeUpdateOrder(RouteUpdateOrderCommand command); ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command);
//付款 //付款
void payForLeg(LegPayedCommand command); void payForLeg(LegPayedCommand command);

View File

@ -3,6 +3,7 @@ package com.chint.domain.service.leg_event;
import com.chint.application.commands.*; import com.chint.application.commands.*;
import com.chint.infrastructure.echo_framework.annotation.ListenTo; import com.chint.infrastructure.echo_framework.annotation.ListenTo;
import com.chint.infrastructure.echo_framework.annotation.TransitionTo; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -13,7 +14,6 @@ public class LegEventServiceImpl implements LegEventService {
private LegEventHandler legEventHandler; private LegEventHandler legEventHandler;
@TransitionTo(command = "LegPrepareCommand", order = 0) @TransitionTo(command = "LegPrepareCommand", order = 0)
@Override @Override
public void prepareLeg(LegPrepareCommand command) { public void prepareLeg(LegPrepareCommand command) {
@ -45,8 +45,9 @@ public class LegEventServiceImpl implements LegEventService {
@ListenTo(command = "RouteUpdateOrderCommand", order = 0) @ListenTo(command = "RouteUpdateOrderCommand", order = 0)
@Override @Override
public void routeUpdateOrder(RouteUpdateOrderCommand command) { public ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command) {
legEventHandler.routeUpdateOrder(command); legEventHandler.routeUpdateOrder(command);
return null;
} }
@Override @Override

View File

@ -1,25 +1,72 @@
package com.chint.domain.service.supplier; package com.chint.domain.service.supplier;
import com.chint.application.commands.RouteUpdateOrderCommand; 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.domain.value_object.SupplierCallbackData;
import com.chint.infrastructure.constant.LegConstant;
import com.chint.infrastructure.echo_framework.command.Command; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import static com.chint.infrastructure.constant.UtilConstant.RESULT_ORDER_DETAIL;
@Service @Service
public class SupplierServiceImpl implements SupplierService { public class SupplierServiceImpl implements SupplierService {
@Autowired @Autowired
private OrderDataAdapterSelector orderDataAdapterSelector; private OrderDataAdapterSelector orderDataAdapterSelector;
@Autowired
private OrderExtensionCreator orderExtensionCreator;
@Autowired
private OrderDetailRepository orderDetailRepository;
@Override @Override
public void handleSupplierCallback(SupplierCallbackData callbackData) { public void handleSupplierCallback(SupplierCallbackData callbackData) {
String supplierName = callbackData.getSupplierName();
orderDataAdapterSelector orderDataAdapterSelector
.of(callbackData.getSupplierName()) .of(supplierName)
.adapt(callbackData) .adapt(callbackData)
.ifPresent(data -> { .ifPresent(data -> {
System.out.println(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);
}); });
} }
} }

View File

@ -3,4 +3,6 @@ package com.chint.infrastructure.constant;
public class UtilConstant { public class UtilConstant {
// 金额 // 金额
public static final String KEEP_TWO_DECIMAL_ZERO = "0.00"; public static final String KEEP_TWO_DECIMAL_ZERO = "0.00";
public static final String RESULT_ORDER_DETAIL = "ResultContainer";
} }

View File

@ -9,4 +9,16 @@ public class ResultContainer {
private Object source; private Object source;
private String propertyName; private String propertyName;
private Object value; 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;
}
} }

View File

@ -9,11 +9,10 @@ import com.chint.domain.aggregates.standards.Ranks;
import com.chint.domain.aggregates.user.User; import com.chint.domain.aggregates.user.User;
import com.chint.domain.service.RankDomainService; import com.chint.domain.service.RankDomainService;
import com.chint.infrastructure.constant.SFConstant; 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.base.PostRequest;
import com.chint.interfaces.rest.user.dto.AccessKeyDTO; import com.chint.interfaces.rest.user.dto.*;
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.google.gson.Gson; import com.google.gson.Gson;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.LinkedHashMap;
import java.util.List;
@Service @Service
public class UserHttpRequestImpl implements UserHttpRequest { public class UserHttpRequestImpl implements UserHttpRequest {
@ -85,8 +87,6 @@ public class UserHttpRequestImpl implements UserHttpRequest {
// Type type = new TypeToken<List<UserDataDTO>>() { // Type type = new TypeToken<List<UserDataDTO>>() {
// }.getType(); // }.getType();
// if (result.getData() != null) { // if (result.getData() != null) {
//// List<UserDataDTO> fromJson = gson.fromJson(result.getData().toString(), type);
//// UserDataDTO userDataDTO = fromJson.get(0);
// String companyCode = user.getCompanyCode(); // String companyCode = user.getCompanyCode();
// if (companyCode == null) { // if (companyCode == null) {
// companyCode = BaseContext.getCurrentUser().getUserLoginParam().getCompanyCode(); // companyCode = BaseContext.getCurrentUser().getUserLoginParam().getCompanyCode();