From b7425c7b80e222a05a19356fb58a5c62a8becc6e Mon Sep 17 00:00:00 2001 From: lulz1 Date: Fri, 1 Mar 2024 15:11:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/LegApprovalCommand.java | 11 ++------- .../commands/RouteApprovalCommand.java | 24 +++++++++++++++++++ .../services/OrderApplicationService.java | 14 +++++++---- .../service/leg_event/LegEventHandler.java | 9 ++++++- .../service/leg_event/LegEventService.java | 4 +++- .../leg_event/LegEventServiceImpl.java | 13 +++++++--- 6 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/chint/application/commands/RouteApprovalCommand.java diff --git a/src/main/java/com/chint/application/commands/LegApprovalCommand.java b/src/main/java/com/chint/application/commands/LegApprovalCommand.java index 552beef4..56e6a1a3 100644 --- a/src/main/java/com/chint/application/commands/LegApprovalCommand.java +++ b/src/main/java/com/chint/application/commands/LegApprovalCommand.java @@ -1,6 +1,5 @@ package com.chint.application.commands; -import com.chint.domain.value_object.ApproveLegData; import com.chint.infrastructure.echo_framework.command.Command; import lombok.Data; @@ -8,17 +7,11 @@ import static com.chint.infrastructure.constant.LegConstant.LEG_EVENT_APPROVAL; @Data public class LegApprovalCommand extends Command { - private Integer LegEventType = LEG_EVENT_APPROVAL; - private Long LegId; - private ApproveLegData data; + private Integer legEventType = LEG_EVENT_APPROVAL; + private Long legId; public LegApprovalCommand legId(Long LegId) { this.setLegId(LegId); return this; } - - public LegApprovalCommand data(ApproveLegData data) { - this.data = data; - return this; - } } diff --git a/src/main/java/com/chint/application/commands/RouteApprovalCommand.java b/src/main/java/com/chint/application/commands/RouteApprovalCommand.java new file mode 100644 index 00000000..2c1c7063 --- /dev/null +++ b/src/main/java/com/chint/application/commands/RouteApprovalCommand.java @@ -0,0 +1,24 @@ +package com.chint.application.commands; + +import com.chint.domain.value_object.ApproveLegData; +import com.chint.infrastructure.echo_framework.command.Command; +import lombok.Data; + +import static com.chint.infrastructure.constant.LegConstant.LEG_EVENT_APPROVAL; + +@Data +public class RouteApprovalCommand extends Command { + private Integer LegEventType = LEG_EVENT_APPROVAL; + private Long LegId; + private ApproveLegData data; + + public RouteApprovalCommand legId(Long LegId) { + this.setLegId(LegId); + return this; + } + + public RouteApprovalCommand data(ApproveLegData data) { + this.data = data; + return this; + } +} diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index e7fdef23..080ee19f 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -28,8 +28,7 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; -import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_NOT_ORDERED; -import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE; +import static com.chint.infrastructure.constant.RouteConstant.*; @Service public class OrderApplicationService { @@ -77,7 +76,14 @@ public class OrderApplicationService { List legs = processLegData(addLegData.getLegData(), order); RouteOrder routeOrder = orderDomainService.saveOrder(order); - legs.forEach(leg -> Command.of(LegPrepareCommand.class).legId(leg.getLegId()).sendToQueue()); + legs.forEach(leg -> { + Command.of(LegPrepareCommand.class).legId(leg.getLegId()).sendToQueue(); + //如果订单状态已经处于审批中, 那么为这个新增的leg也提交审批状态 + if (order.getOrderStatus() >= ORDER_STATUS_APPROVAL) { + Command.of(LegApprovalCommand.class).legId(leg.getLegId()).sendToQueue(); + } + }); + //异步操作-如果是当前的状态已经进行过匹配,那么就要订单同步到供应商一次 if (order.getOrderStatus() >= ORDER_STATUS_NOT_ORDERED) { @@ -142,7 +148,7 @@ public class OrderApplicationService { @Transactional public void approve(ApproveLegData approveLegData) { - Command.of(LegApprovalCommand.class).data(approveLegData).sendToQueue(); + Command.of(RouteApprovalCommand.class).data(approveLegData).sendToQueue(); } @Transactional 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 a71db450..25c9818d 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 @@ -72,7 +72,7 @@ public class LegEventHandler implements LegEventService { @Transactional @Override - public void approveLeg(LegApprovalCommand command) { + public void approveRoute(RouteApprovalCommand command) { ApproveLegData data = command.getData(); RouteOrder routeOrder = routeRepository.findByFakeOrderNoAndSysCode(data.getFakeOrderNo(), data.getSysCode()).reloadStatus(); if (routeOrder.getLegItems().isEmpty()) { @@ -135,6 +135,13 @@ public class LegEventHandler implements LegEventService { } } + @Override + public void approveLeg(LegApprovalCommand command) { + Leg leg = legRepository.findByLegId(command.getLegId()); + leg.addEvent(legEventFactory.creatLegEvent(command.getLegEventType())); + legRepository.save(leg); + } + @Transactional @Override public ResultContainer routeUpdateOrder(RouteUpdateOrderCommand command) { 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 fd11e376..c774ed8d 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 @@ -8,10 +8,12 @@ public interface LegEventService { void prepareLeg(LegPrepareCommand command); //审批事件要从bpm或其他平台接收到一个真实订单 - void approveLeg(LegApprovalCommand command); + void approveRoute(RouteApprovalCommand command); void syncLeg(LegSyncCommand command); + void approveLeg(LegApprovalCommand command); + //下单事件 ResultContainer orderLeg(LegOrderedCommand 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 2bf4328f..7fe9dea3 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 @@ -23,10 +23,10 @@ public class LegEventServiceImpl implements LegEventService { //因为审批是针对整个订单的,因此所有订单下属的行程节点触发审批事件 //出发审批提交事件 , 需要生成 差旅单 , 将差旅但提交到供应商 , //根据command里面选择的数据来讲差旅但提交到不同的实现类当中 - @ListenTo(command = "LegApprovalCommand", order = 0) + @ListenTo(command = "RouteApprovalCommand", order = 0) @Override - public void approveLeg(LegApprovalCommand command) { - legEventHandler.approveLeg(command); + public void approveRoute(RouteApprovalCommand command) { + legEventHandler.approveRoute(command); } //这里需要获取同步类,价格routeOrder同步到供应商 @@ -36,6 +36,13 @@ public class LegEventServiceImpl implements LegEventService { legEventHandler.syncLeg(command); } + + @ListenTo(command = "LegApprovalCommand", order = 0) + @Override + public void approveLeg(LegApprovalCommand command) { + legEventHandler.approveLeg(command); + } + //下单时间要求回传,需要付款的金额,以及生成对于的行程订单号,如果没有行程订单号根据地点和时间进行匹配 @ListenTo(command = "LegOrderedCommand", order = 0) @Override