diff --git a/src/main/java/com/chint/application/dtos/LegApprovalParam.java b/src/main/java/com/chint/application/dtos/LegApprovalParam.java new file mode 100644 index 00000000..db6c7b3b --- /dev/null +++ b/src/main/java/com/chint/application/dtos/LegApprovalParam.java @@ -0,0 +1,9 @@ +package com.chint.application.dtos; + +import lombok.Data; + +@Data +public class LegApprovalParam { + private Long routeId; + private String extension; +} diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index 68bd15f4..305f2139 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -3,7 +3,9 @@ package com.chint.application.services; import com.chint.application.commands.*; import com.chint.application.dtos.AddLegData; import com.chint.application.dtos.DeleteLegData; +import com.chint.domain.aggregates.order.ApproveOrderNo; import com.chint.domain.aggregates.order.Leg; +import com.chint.domain.aggregates.order.LegApprovalEvent; import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.exceptions.OrderException; @@ -32,7 +34,8 @@ import java.util.Optional; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_TIME_ERROR; import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND; -import static com.chint.infrastructure.constant.RouteConstant.*; +import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_APPROVAL; +import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE; @Service public class OrderApplicationService { @@ -72,7 +75,6 @@ public class OrderApplicationService { throw new OrderException(DataMessageConstant.DATA_INVALID); } } else { -// order = orderFactory.createOrder(orderSaveData); throw new NotFoundException(NOT_FOUND); } RouteOrder routeOrder = orderDomainService.saveOrder(order); @@ -82,7 +84,7 @@ public class OrderApplicationService { } @Transactional - public RouteOrder addLegToOrder(AddLegData addLegData) { + public void addLegToOrder(AddLegData addLegData) { //这里也先去redis查询如果没有的话 ,再查询数据库 RouteOrder routeOrder = Optional.ofNullable(routeRepository .findTempRouteOrderBySysCodeAndBillCode(addLegData.getSysCode(), addLegData.getFakeOrderNo())) @@ -90,49 +92,16 @@ public class OrderApplicationService { .orElseThrow(() -> new NotFoundException(NOT_FOUND))).reloadStatus(); checkLegDataTime(addLegData, routeOrder); LegData legData = addLegData.getLegData(); - List legs = processLegData(legData, routeOrder); //创建差旅行程单 + List legs = processLegData(legData, routeOrder); //创建行程节点 legDomainService.queryLocation(legs); - legs.forEach(leg -> { - handleLegEvents(leg, addLegData.getLegData(), routeOrder); - routeOrder.addLeg(leg); - }); - if (routeOrder.getApprovalStatusCode().equals(APPROVAL_EVENT_PREPARE)) { - return routeRepository.saveTempRouteOrder(routeOrder, 24L); //如果是未审批状态的话 ,将行程规划单保存到redis + legs.forEach(leg -> handleLegEvents(leg, addLegData.getLegData(), routeOrder)); + if (routeOrder.getApproveOrderNo() != null && routeOrder.getApproveOrderNo().getActualOrderNo() == null) { + routeRepository.saveTempRouteOrder(routeOrder, 24L); //如果是未审批状态的话 ,将行程规划单保存到redis } else { - return routeRepository.save(routeOrder); // 仅在所有操作完成后保存一次 + routeRepository.save(routeOrder); // 仅在所有操作完成后保存一次 } - } - - private void handleLegEvents(Leg leg, LegData legData, RouteOrder routeOrder) { - legDomainService.addPreEvent(leg); - - if (legData.getChangeReason() != null) { - legDomainService.addChangeEvent(leg, legData.getChangeReason()); - } - - if (isOrderInApprovalState(routeOrder)) { - legDomainService.addApproveEvent(leg); - } - - leg.setRouteId(routeOrder.getRouteId()); - - if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) { - sendLegChangeCommand(leg, routeOrder); - } - } - - private boolean isOrderInApprovalState(RouteOrder routeOrder) { - return routeOrder.getApproveOrderNo().getActualOrderNo() != null - || routeOrder.getOrderStatus() >= ORDER_STATUS_APPROVAL; - } - - private void sendLegChangeCommand(Leg leg, RouteOrder routeOrder) { - Command.of(BPMLegChangeCommand.class) - .routeOrder(routeOrder) - .newleg(leg.reloadStatus()) - .routeId(routeOrder.getRouteId()) - .changeType(0) - .sendToQueue(); + //如果行程变更成功,自动执行同步功能 + Command.of(RouteAutoSyncCommand.class).route(routeOrder).async().sendToQueue(); } @Transactional @@ -145,7 +114,6 @@ public class OrderApplicationService { if (routeOrder == null) { throw new NotFoundException(NOT_FOUND); } - checkLegDataTime(addLegData, routeOrder); // 创建一个临时变量来避免 Lambda 表达式中的变量修改问题 final Long legId = leg.getLegId(); @@ -164,24 +132,28 @@ public class OrderApplicationService { // 对更新的行程补充地理信息 legDomainService.queryLocation(List.of(oldLeg, leg)); - handleLegChangeEvent(leg, legData); + handleLegChangeEvent(leg, legData, routeOrder); + + // 发送 BPM 保存结果 + ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); + if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && approveOrderNo.getSysCode().equals("ANFSSC")) { + //这里加入一个待审批事件, 变更加入旧行程数据, 用于回滚还原 + leg.addEvent(LegApprovalEvent.prepare(oldLeg)); + } + if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && !approveOrderNo.getSysCode().equals("ANFSSC")){ + sendLegChangeCommand(oldLeg, leg, + routeOrder, + addLegData.getLegData().getChangeReason(), + 1); + } + // 保存 routeOrder 并重新加载状态 routeRepository.save(routeOrder); - // 发送 BPM 保存结果 - Command.of(BPMLegChangeCommand.class) - .routeId(addLegData.getRouteId()) - .reason(addLegData.getLegData().getChangeReason()) - .oldLeg(oldLeg) - .routeOrder(routeOrder) - .newleg(leg) - .changeType(1) - .sendToQueue(); - //如果行程变更成功,自动执行同步功能 Command.of(RouteAutoSyncCommand.class).route(routeOrder).async().sendToQueue(); } - private Leg handleLegChangeEvent(Leg leg, LegData legData) { + private Leg handleLegChangeEvent(Leg leg, LegData legData, RouteOrder routeOrder) { // 保存变更事件理由 legDomainService.addChangeEvent(leg, legData.getChangeReason()); // 推送未同步事件 @@ -189,6 +161,52 @@ public class OrderApplicationService { return leg; } + private void handleLegEvents(Leg leg, LegData legData, RouteOrder routeOrder) { + legDomainService.addPreEvent(leg); + String changeReason = legData.getChangeReason(); + if (changeReason != null) { + legDomainService.addChangeEvent(leg, changeReason); + } + + if (isOrderInApprovalState(routeOrder)) { + legDomainService.addApproveEvent(leg); + } + + leg.setRouteId(routeOrder.getRouteId()); + ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); + if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && approveOrderNo.getSysCode().equals("ANFSSC")) { + //这里加入一个待审批事件 + leg.addEvent(LegApprovalEvent.prepare()); + } + + if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && !approveOrderNo.getSysCode().equals("ANFSSC")) { + leg.reloadStatus(); + sendLegChangeCommand(null, leg, routeOrder, changeReason, 0); + } + + routeOrder.addLeg(leg); + } + + private boolean isOrderInApprovalState(RouteOrder routeOrder) { + return routeOrder.getApproveOrderNo().getActualOrderNo() != null + || routeOrder.getOrderStatus() >= ORDER_STATUS_APPROVAL; + } + + private void sendLegChangeCommand(Leg oldLeg, Leg leg, + RouteOrder routeOrder, + String changeReason, + int changeType) { + Command.of(BPMLegChangeCommand.class) + .routeId(routeOrder.getRouteId()) + .reason(changeReason) + .oldLeg(oldLeg) + .routeOrder(routeOrder) + .newleg(leg.reloadStatus()) + .changeType(changeType) + .sendToQueue(); + } + + private List processLegData(LegData legData, RouteOrder order) { if (legData.getCurrencyType() == null) { legData.setCurrencyType(CurrencyType.RENMINBI.getCode()); @@ -200,19 +218,6 @@ public class OrderApplicationService { }; } -// public void deleteByLegNo(DeleteLegData deleteLegData) { -// String legNo = deleteLegData.getLegNo(); -// RouteOrder routeOrder = null; -// if (legNo.contains("&")) { -// String[] split = legNo.split("&"); -// routeOrder = routeRepository.findTempRouteOrderBySysCodeAndBillCode(split[1], split[2]); -// } -// if (routeOrder != null && routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)){ -// routeOrder.deleteLeg(legNo); -// routeRepository.saveTempRouteOrder(routeOrder, 24L); -// } -// } - public RouteOrder deleteLegToOrder(DeleteLegData deleteLegData) { String legNo = deleteLegData.getLegNo(); @@ -309,6 +314,9 @@ public class OrderApplicationService { } private boolean checkLegDataTime(AddLegData addLegData, RouteOrder order) { + if (order.getOrderStatus() == null) { + order.reloadStatus(); + } if (order.getStartTime() != null && order.getEndTime() != null) { LocalDateTime startTime = order.getStartTime(); LocalDateTime endTime = order.getEndTime(); diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalData.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalData.java new file mode 100644 index 00000000..9ba9adbd --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalData.java @@ -0,0 +1,20 @@ +package com.chint.domain.aggregates.approval; + + +import com.chint.domain.aggregates.order.Leg; +import com.chint.domain.aggregates.order.OrderDetail; +import com.chint.domain.aggregates.order.RouteOrder; +import lombok.Data; +import org.springframework.data.util.Pair; + +import java.util.List; + +@Data +public class ApprovalData { + private RouteOrder routeOrder; + private Leg leg; + private Leg oldLeg; + private List addLegList; + private List> changeLegList; + private OrderDetail orderDetail; +} diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegAdd.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegAdd.java new file mode 100644 index 00000000..e9c7c70a --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegAdd.java @@ -0,0 +1,40 @@ +package com.chint.domain.aggregates.approval; + +import com.chint.domain.aggregates.approval.platform.ApprovalPlatform; +import com.chint.domain.aggregates.order.OrderDetail; +import com.chint.domain.aggregates.order.RouteOrder; + +import static com.chint.domain.aggregates.approval.ApprovalProcess.ApprovalType.LEG_ADD; + +public class ApprovalLegAdd extends ApprovalProcess { + + public ApprovalLegAdd(ApprovalPlatform bpmPlatform) { + super(bpmPlatform); + this.approvalType = LEG_ADD; + } + + @Override + public ApprovalProcess approveData(RouteOrder routeOrder) { + return this; + } + + @Override + public ApprovalProcess approveData(RouteOrder routeOrder, OrderDetail orderDetail) { + return null; + } + + @Override + public boolean approve() { + return false; + } + + @Override + public void reject() { + + } + + @Override + public void submitToBpm() { + bpmPlatform.submitLegAddApproval(approvalData); + } +} diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegAddAndChangeBatch.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegAddAndChangeBatch.java new file mode 100644 index 00000000..943542a0 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegAddAndChangeBatch.java @@ -0,0 +1,61 @@ +package com.chint.domain.aggregates.approval; + +import com.chint.domain.aggregates.approval.platform.ApprovalPlatform; +import com.chint.domain.aggregates.order.Leg; +import com.chint.domain.aggregates.order.OrderDetail; +import com.chint.domain.aggregates.order.RouteOrder; +import com.google.gson.Gson; +import org.springframework.data.util.Pair; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static com.chint.domain.aggregates.approval.ApprovalProcess.ApprovalType.LEG_ADD_CHANGE_BATCH; +import static com.chint.infrastructure.constant.LegConstant.LEG_APPROVAL_STATUS_PREPARE; + +public class ApprovalLegAddAndChangeBatch extends ApprovalProcess { + + public ApprovalLegAddAndChangeBatch(ApprovalPlatform bpmPlatform) { + super(bpmPlatform); + this.approvalType = LEG_ADD_CHANGE_BATCH; + } + + @Override + public ApprovalProcess approveData(RouteOrder routeOrder) { + Map> legMap = routeOrder.getLegItems() + .stream() + .filter(it -> it.getLegApprovalStatus().equals(LEG_APPROVAL_STATUS_PREPARE)) + .collect(Collectors.partitioningBy(it -> it.getLastEvent().getExtension() == null + || it.getLastEvent().getExtension().isEmpty())); + ApprovalData approvalData = new ApprovalData(); + approvalData.setRouteOrder(routeOrder); + approvalData.setAddLegList(legMap.get(true)); + List> pairList = legMap.get(false).stream() + .map(leg -> { + Gson gson = new Gson(); + String extension = leg.getLastEvent().getExtension(); + Leg oldLeg = gson.fromJson(extension, Leg.class); + return Pair.of(leg, oldLeg); + }).toList(); + approvalData.setChangeLegList(pairList); + this.approvalData = approvalData; + return this; + } + + + @Override + public boolean approve() { + return false; + } + + @Override + public void reject() { + + } + + @Override + public void submitToBpm() { + bpmPlatform.submitLegAddOrChangeApproval(approvalData); + } +} diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegChange.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegChange.java new file mode 100644 index 00000000..3869a171 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalLegChange.java @@ -0,0 +1,36 @@ +package com.chint.domain.aggregates.approval; + + +import com.chint.domain.aggregates.approval.platform.ApprovalPlatform; +import com.chint.domain.aggregates.order.RouteOrder; + +import static com.chint.domain.aggregates.approval.ApprovalProcess.ApprovalType.LEG_ADD; +import static com.chint.domain.aggregates.approval.ApprovalProcess.ApprovalType.LEG_CHANGE; + +public class ApprovalLegChange extends ApprovalProcess{ + + public ApprovalLegChange(ApprovalPlatform bpmPlatform) { + super(bpmPlatform); + this.approvalType = LEG_CHANGE; + } + + @Override + public ApprovalProcess approveData(RouteOrder routeOrder) { + return this; + } + + @Override + public boolean approve() { + return false; + } + + @Override + public void reject() { + + } + + @Override + public void submitToBpm() { + bpmPlatform.submitLegChangeApproval(approvalData); + } +} diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalOrderChange.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalOrderChange.java new file mode 100644 index 00000000..b36bb5b7 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalOrderChange.java @@ -0,0 +1,34 @@ +package com.chint.domain.aggregates.approval; + +import com.chint.domain.aggregates.approval.platform.ApprovalPlatform; +import com.chint.domain.aggregates.order.RouteOrder; + +import static com.chint.domain.aggregates.approval.ApprovalProcess.ApprovalType.LEG_CHANGE; + +public class ApprovalOrderChange extends ApprovalProcess{ + + public ApprovalOrderChange(ApprovalPlatform bpmPlatform) { + super(bpmPlatform); + this.approvalType = LEG_CHANGE; + } + + @Override + public ApprovalProcess approveData(RouteOrder routeOrder) { + return this; + } + + @Override + public boolean approve() { + return false; + } + + @Override + public void reject() { + + } + + @Override + public void submitToBpm() { + bpmPlatform.submitOrderChangeApproval(approvalData); + } +} diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalOrderExpense.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalOrderExpense.java new file mode 100644 index 00000000..0a17a309 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalOrderExpense.java @@ -0,0 +1,35 @@ +package com.chint.domain.aggregates.approval; + +import com.chint.domain.aggregates.approval.platform.ApprovalPlatform; +import com.chint.domain.aggregates.order.RouteOrder; + +import static com.chint.domain.aggregates.approval.ApprovalProcess.ApprovalType.ORDER_EXPENSE; + +public class ApprovalOrderExpense extends ApprovalProcess{ + + public ApprovalOrderExpense(ApprovalPlatform bpmPlatform) { + super(bpmPlatform); + this.approvalType = ORDER_EXPENSE; + } + + @Override + public ApprovalProcess approveData(RouteOrder routeOrder) { + return this; + } + + @Override + public boolean approve() { + return false; + } + + @Override + public void reject() { + + } + + @Override + public void submitToBpm() { + bpmPlatform.submitOrderExpenseApproval(approvalData); + } +} + diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalOrderRefund.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalOrderRefund.java new file mode 100644 index 00000000..1c045b41 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalOrderRefund.java @@ -0,0 +1,35 @@ +package com.chint.domain.aggregates.approval; + +import com.chint.domain.aggregates.approval.platform.ApprovalPlatform; +import com.chint.domain.aggregates.order.RouteOrder; + +import static com.chint.domain.aggregates.approval.ApprovalProcess.ApprovalType.ORDER_REFUND; + +public class ApprovalOrderRefund extends ApprovalProcess{ + + public ApprovalOrderRefund(ApprovalPlatform bpmPlatform) { + super(bpmPlatform); + this.approvalType = ORDER_REFUND; + } + + @Override + public ApprovalProcess approveData(RouteOrder routeOrder) { + return this; + } + + @Override + public boolean approve() { + return false; + } + + @Override + public void reject() { + + } + + @Override + public void submitToBpm() { + bpmPlatform.submitOrderRefundApproval(approvalData); + } +} + diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalProcess.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalProcess.java new file mode 100644 index 00000000..0851411b --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalProcess.java @@ -0,0 +1,62 @@ +package com.chint.domain.aggregates.approval; + +import com.chint.domain.aggregates.approval.platform.ApprovalPlatform; +import com.chint.domain.aggregates.order.OrderDetail; +import com.chint.domain.aggregates.order.RouteOrder; + + +// 定义抽象类 ApprovalProcess +public abstract class ApprovalProcess { + + protected ApprovalPlatform bpmPlatform; + + public ApprovalData approvalData; + + public ApprovalType approvalType; + + public ApprovalProcess(ApprovalPlatform bpmPlatform) { + this.bpmPlatform = bpmPlatform; + } + + public ApprovalProcess approveData(RouteOrder routeOrder) { + approvalData = new ApprovalData(); + return this; + } + + public ApprovalProcess approveData(RouteOrder routeOrder, OrderDetail orderDetail) { + ApprovalData approvalData = new ApprovalData(); + approvalData.setRouteOrder(routeOrder); + approvalData.setOrderDetail(orderDetail); + this.approvalData = approvalData; + return this; + } + + // 审批流程的抽象方法 + public abstract boolean approve(); + + // 退回流程的抽象方法 + public abstract void reject(); + + // 通用的通知方法 + public void notifyUser(String message) { + // 发送通知的逻辑 + System.out.println("Notify user: " + message); + } + + // 提交审批到BPM平台的抽象方法 + public abstract void submitToBpm(); + + // 接收审批结果 + public void receiveApprovalResult(String resultData) { + bpmPlatform.receiveApprovalResult(resultData); + } + + public enum ApprovalType { + LEG_ADD, + LEG_CHANGE, + ORDER_EXPENSE, + ORDER_CHANGE, + ORDER_REFUND, + LEG_ADD_CHANGE_BATCH + } +} \ No newline at end of file diff --git a/src/main/java/com/chint/domain/aggregates/approval/ApprovalSubmit.java b/src/main/java/com/chint/domain/aggregates/approval/ApprovalSubmit.java new file mode 100644 index 00000000..7de7f720 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/ApprovalSubmit.java @@ -0,0 +1,50 @@ +package com.chint.domain.aggregates.approval; + +import com.chint.domain.aggregates.approval.platform.ApprovalPlatform; +import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; + +import java.util.Map; +import java.util.stream.Collectors; + +@Component +public class ApprovalSubmit implements ApplicationListener { + + @Autowired + private ApplicationContext applicationContext; + + + @Override + public void onApplicationEvent(@NotNull ApplicationReadyEvent event) { + approvalPlatformMap = applicationContext + .getBeansOfType(ApprovalPlatform.class) + .values() + .stream() + .collect(Collectors.toMap(ApprovalPlatform::getApprovalPlatformName, platform -> platform)); + } + + private static Map approvalPlatformMap; + + + // 静态工厂方法,根据类型和平台标识创建具体的 ApprovalProcess 实例 + public static ApprovalProcess of(ApprovalProcess.ApprovalType type, String platformMark) { + ApprovalPlatform bpmPlatform = approvalPlatformMap.get(platformMark); + if (bpmPlatform == null) { + throw new IllegalArgumentException("Invalid platform mark: " + platformMark); + } + return switch (type) { + case LEG_ADD -> new ApprovalLegAdd(bpmPlatform); + case LEG_CHANGE -> new ApprovalLegChange(bpmPlatform); + case ORDER_EXPENSE -> new ApprovalOrderExpense(bpmPlatform); + case ORDER_CHANGE -> new ApprovalOrderChange(bpmPlatform); + case ORDER_REFUND -> new ApprovalOrderRefund(bpmPlatform); + case LEG_ADD_CHANGE_BATCH -> new ApprovalLegAddAndChangeBatch(bpmPlatform); + // 其他类型... + default -> throw new IllegalArgumentException("Invalid approval type: " + type); + }; + } +} diff --git a/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatform.java b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatform.java new file mode 100644 index 00000000..70f8b852 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatform.java @@ -0,0 +1,29 @@ +package com.chint.domain.aggregates.approval.platform; + +import com.chint.domain.aggregates.approval.ApprovalData; +import com.chint.domain.aggregates.order.Leg; +import com.chint.domain.aggregates.order.OrderDetail; +import com.chint.domain.aggregates.order.RouteOrder; + +public interface ApprovalPlatform { + // 提交审批请求 + void submitApproval(ApprovalData approvalData); + + // 接收审批结果 + void receiveApprovalResult(String resultData); + + String getApprovalPlatformName(); + + // 特定审批流的方法 + void submitLegAddApproval(ApprovalData approvalData); + + void submitLegChangeApproval(ApprovalData approvalData); + + void submitOrderExpenseApproval(ApprovalData approvalData); + + void submitOrderChangeApproval(ApprovalData approvalData); + + void submitOrderRefundApproval(ApprovalData approvalData); + + void submitLegAddOrChangeApproval(ApprovalData approvalData); +} \ No newline at end of file diff --git a/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformAN.java b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformAN.java new file mode 100644 index 00000000..8b030fc6 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformAN.java @@ -0,0 +1,290 @@ +package com.chint.domain.aggregates.approval.platform; + + +import com.chint.domain.aggregates.approval.ApprovalData; +import com.chint.domain.aggregates.order.*; +import com.chint.domain.aggregates.supplier.Supplier; +import com.chint.domain.repository.ApprovalPlatformInfoRepository; +import com.chint.domain.repository.SupplierRepository; +import com.chint.infrastructure.constant.BPMConstant; +import com.chint.infrastructure.util.DateTimeUtil; +import com.chint.infrastructure.util.DelayDispatch; +import com.chint.interfaces.rest.base.PostRequest; +import com.chint.interfaces.rest.bpm.dto.ANExceedStandardDto; +import jakarta.annotation.PostConstruct; +import lombok.Data; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.util.Pair; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static com.chint.infrastructure.constant.LegConstant.*; + +@Component +public class ApprovalPlatformAN implements ApprovalPlatform { + + + @Autowired + private SupplierRepository supplierRepository; + + @Autowired + private ApprovalPlatformInfoRepository approvalPlatformInfoRepository; + + private ApprovalPlatformInfo approvalPlatformInfo; + + @Autowired + private PostRequest postRequest; + + public static final String platformMark = "AN"; + + @PostConstruct + void init() { + approvalPlatformInfoRepository.findByPlatformMark(platformMark) + .ifPresent(approvalPlatformInfo -> approvalPlatformInfo.setPlatformMark(platformMark)); + } + + @Override + public void submitApproval(ApprovalData approvalData) { + + } + + @Override + public void receiveApprovalResult(String resultData) { + + } + + @Override + public String getApprovalPlatformName() { + return platformMark; + } + + @Override + public void submitLegAddApproval(ApprovalData approvalData) { + + } + + @Override + public void submitLegChangeApproval(ApprovalData approvalData) { + + } + + @Override + public void submitOrderExpenseApproval(ApprovalData approvalData) { + approvalPlatformInfo.expenseUrl() + .ifPresent(url -> { + ANExceedStandardDto exceedStandardDto = createExceedStandardDto(approvalData.getRouteOrder(), approvalData.getOrderDetail()); + DelayDispatch.attemptToSend(() -> postRequest.post(url, exceedStandardDto, ANResponse.class).getSuccess(), 0); + }); + } + + @Override + public void submitOrderChangeApproval(ApprovalData approvalData) { + + } + + @Override + public void submitOrderRefundApproval(ApprovalData approvalData) { + + } + + @Override + public void submitLegAddOrChangeApproval(ApprovalData approvalData) { + approvalPlatformInfo.changeUrl() + .ifPresent(url -> { + ApprovalScheduleParam approvalScheduleParam = createApprovalScheduleParam(approvalData); + DelayDispatch.attemptToSend(() -> postRequest.post(url, approvalScheduleParam, ANResponse.class).getSuccess(), 0); + }); + } + + private ApprovalScheduleParam createApprovalScheduleParam(ApprovalData approvalData) { + ApprovalScheduleParam approvalScheduleParam = new ApprovalScheduleParam(); + approvalScheduleParam.setSourceSystem(systemNum()); + RouteOrder routeOrder = approvalData.getRouteOrder(); + ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); + approvalScheduleParam.setSourceSystemNum(legChangeTag() + routeOrder.getRouteOrderNo()); + approvalScheduleParam.setApplicant(routeOrder.getUserId()); + approvalScheduleParam.setApplicantDate(DateTimeUtil.timeToStr(LocalDateTime.now())); + approvalScheduleParam.setApplyNo(approveOrderNo.getActualOrderNo()); + List scheduleItemList = new ArrayList<>(); + for (Pair legPair : approvalData.getChangeLegList()) { + Leg newLeg = legPair.getFirst(); + Leg oldLeg = legPair.getSecond(); + ScheduleItem scheduleItem = new ScheduleItem(); + scheduleItem.orderType = ANProductType(newLeg.getLegType()); // 示例值,可根据需要动态分配 + scheduleItem.changeType = "2"; // 示例值,可根据需要动态分配 + scheduleItem.fromAddress = newLeg.getOriginLocation().getLocationName(); + scheduleItem.toAddress = newLeg.getDestinationLocation().getLocationName(); + scheduleItem.originalFromAddress = oldLeg.getOriginLocation().getLocationName(); + scheduleItem.originalToAddress = oldLeg.getDestinationLocation().getLocationName(); + scheduleItem.startTime = DateTimeUtil.timeToStrCommon(newLeg.getStartTime()); + scheduleItem.endTime = DateTimeUtil.timeToStrCommon(newLeg.getEndTime()); + scheduleItem.originalStartTime = DateTimeUtil.timeToStrCommon(oldLeg.getStartTime()); + scheduleItem.originalEndTime = DateTimeUtil.timeToStrCommon(oldLeg.getEndTime()); + scheduleItem.amount = new BigDecimal(newLeg.getEstimateAmount()); + scheduleItemList.add(scheduleItem); + } + for (Leg leg : approvalData.getAddLegList()) { + ScheduleItem scheduleItem = new ScheduleItem(); + scheduleItem.orderType = ANProductType(leg.getLegType()); // 示例值,可根据需要动态分配 + scheduleItem.changeType = "1"; // 示例值,可根据需要动态分配 + scheduleItem.fromAddress = leg.getOriginLocation().getLocationName(); + scheduleItem.toAddress = leg.getDestinationLocation().getLocationName(); + scheduleItem.startTime = DateTimeUtil.timeToStrCommon(leg.getStartTime()); + scheduleItem.endTime = DateTimeUtil.timeToStrCommon(leg.getEndTime()); + scheduleItem.amount = new BigDecimal(leg.getEstimateAmount()); + scheduleItemList.add(scheduleItem); + } + approvalScheduleParam.setScheduleList(scheduleItemList); + return approvalScheduleParam; + } + + private String ANProductType(Integer legType) { + return switch (legType) { + case LEG_TYPE_TRAIN -> "3"; + case LEG_TYPE_AIRPLANE -> "1"; + case LEG_TYPE_HOTEL -> "2"; + case LEG_TYPE_TAXI -> "4"; + default -> "0"; + }; + } + + private String systemNum() { + return extensionData()[0]; + } + + private String exceedTag() { + return extensionData()[1]; + } + + private String orderChangeTag() { + return extensionData()[2]; + } + + private String orderRefundTag() { + return extensionData()[3]; + } + + private String legChangeTag() { + return extensionData()[4]; + } + + private String[] extensionData() { + String platformExtension = this.approvalPlatformInfo.getPlatformExtension(); + return platformExtension.split("&"); + } + + public ANExceedStandardDto createExceedStandardDto(RouteOrder routeOrder, OrderDetail orderDetail) { + Integer productType = orderDetail.getProductType(); + return switch (productType) { + case LEG_TYPE_TRAIN -> ANCreatAuditParamByTrain(routeOrder, orderDetail); + case LEG_TYPE_AIRPLANE -> ANCreatAuditParamByFlight(routeOrder, orderDetail); + case LEG_TYPE_HOTEL -> ANCreatAuditParamByHotel(routeOrder, orderDetail); + case LEG_TYPE_TAXI -> ANCreatAuditParamByCar(routeOrder, orderDetail); + default -> throw new IllegalArgumentException("Unsupported product type: " + productType); + }; + } + + + public ANExceedStandardDto ANCreatAuditParamByTrain(RouteOrder routeOrder, OrderDetail orderDetail) { + TrainOrderDetail trainOrderDetail = orderDetail.getTrainOrderDetail(); + ANExceedStandardDto anExceedStandardDto = createCommonAuditParam(routeOrder, orderDetail); + anExceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_TRAIN) // 超标原因类型 + .setStartPlace(trainOrderDetail.getFromCity()) // 出发地 + .setEndPlace(trainOrderDetail.getToCity()) // 目的地 + .setOrderMoney(BigDecimal.valueOf(Double.parseDouble(trainOrderDetail.getOrderAmount()))); // 金额 + return anExceedStandardDto; + } + + public ANExceedStandardDto ANCreatAuditParamByFlight(RouteOrder routeOrder, OrderDetail orderDetail) { + FlightOrderDetail flightOrderDetail = orderDetail.getFlightOrderDetail(); + ANExceedStandardDto anExceedStandardDto = createCommonAuditParam(routeOrder, orderDetail); + anExceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_FLIGHT) // 超标原因类型 + .setStartPlace(flightOrderDetail.getStartCityName()) // 出发地 + .setEndPlace(flightOrderDetail.getEndCityName()) // 目的地 + .setOrderMoney(BigDecimal.valueOf(Double.parseDouble(flightOrderDetail.getOrderAmount()))); // 金额 + return anExceedStandardDto; + } + + public ANExceedStandardDto ANCreatAuditParamByHotel(RouteOrder routeOrder, OrderDetail orderDetail) { + HotelOrderDetail hotelOrderDetail = orderDetail.getHotelOrderDetail(); + ANExceedStandardDto anExceedStandardDto = createCommonAuditParam(routeOrder, orderDetail); + anExceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_HOTEL) // 超标原因类型 + .setStartPlace(hotelOrderDetail.getCheckInCity()) // 出发地 + .setEndPlace(hotelOrderDetail.getCheckInCity()) // 目的地 + .setOrderMoney(BigDecimal.valueOf(Double.parseDouble(hotelOrderDetail.getOrderAmount()))); // 金额 + return anExceedStandardDto; + } + + public ANExceedStandardDto ANCreatAuditParamByCar(RouteOrder routeOrder, OrderDetail orderDetail) { + CarOrderDetail carOrderDetail = orderDetail.getCarOrderDetail(); + ANExceedStandardDto anExceedStandardDto = createCommonAuditParam(routeOrder, orderDetail); + anExceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_CAR) // 超标原因类型 + .setStartPlace(carOrderDetail.getFromCity()) // 出发地 + .setEndPlace(carOrderDetail.getToCity()) // 目的地 + .setOrderMoney(BigDecimal.valueOf(Double.parseDouble(carOrderDetail.getOrderAmount()))); // 金额 + return anExceedStandardDto; + } + + private ANExceedStandardDto createCommonAuditParam(RouteOrder routeOrder, OrderDetail orderDetail) { + ANExceedStandardDto anExceedStandardDto = new ANExceedStandardDto(); + Optional legId = Optional.ofNullable(orderDetail.getLegId()); + anExceedStandardDto.setSourceSystemNum(exceedTag() + orderDetail.getOrderNo()) // 来源系统ID,唯一标识 + .setSourceSystem(systemNum()) // 系统标识 + .setApplicant(orderDetail.getEmployeeNo()) // 申请人 + .setOrderNo(orderDetail.getOrderNo()) // 商旅订单号 + .setOrderSource(getSupplierName(orderDetail.getSupplierName())) // 订单来源 + .setStartTime(orderDetail.getStartTime()) // 开始日期 + .setEndTime(orderDetail.getEndTime())// 结束日期 + .setApplyNo(routeOrder.getApproveOrderNo().getActualOrderNo());//申请单号 + legId.flatMap(it -> routeOrder.getLegItems() + .stream() + .filter(leg -> leg.getLegId().equals(it)).findFirst()) + .ifPresentOrElse(leg -> anExceedStandardDto.setLegNo(leg.getLegNo()), + () -> anExceedStandardDto.setLegNo("")); //行程编号 + return anExceedStandardDto; + } + + private String getSupplierName(String supplierName) { + return supplierRepository.findBySupplierName(supplierName) + .map(Supplier::getCnName) + .orElse("未知商旅平台"); + } + + @Data + public static class ANResponse { + private Object data; + private String message; + private String messageType; + private Boolean success; + } + + @Data + private static class ScheduleItem { + public String orderType; + public String changeType; + public String fromAddress; + public String toAddress; + public String originalFromAddress; + public String originalToAddress; + public String startTime; + public String endTime; + public String originalStartTime; + public String originalEndTime; + public BigDecimal amount; + } + + @Data + private static class ApprovalScheduleParam { + public String sourceSystem; + public String sourceSystemNum; + public String applicant; + public String applicantDate; + public String applyNo; + public List scheduleList; + } +} diff --git a/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformInfo.java b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformInfo.java new file mode 100644 index 00000000..6455bc53 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformInfo.java @@ -0,0 +1,62 @@ +package com.chint.domain.aggregates.approval.platform; + + +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.MappedCollection; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; +import java.util.List; +import java.util.Optional; + +@Data +@Table("approval_platform_info") +public class ApprovalPlatformInfo implements Serializable { + @Serial + private static final long serialVersionUID = 961923567112379812L; + + @Id + private Long id; + private String platformBaseUrl; + private String platformName; + private String platformMark; + private String platformVersion; + private String platformDescription; + private String platformExtension; + + @MappedCollection(idColumn = "approval_platform_info_id", keyColumn = "approval_platform_info_key") + private List approvalPlatformPathList; + + public Optional expenseUrl() { + return getUrlByType("EXPENSE"); + } + + public Optional changeUrl() { + return getUrlByType("CHANGE"); + } + + + public Optional addUrl() { + return getUrlByType("ADD"); + } + + public Optional refundOrderUrl() { + return getUrlByType("REFUND_ORDER"); + } + + public Optional changeOrderUrl() { + return getUrlByType("CHANGE_ORDER"); + } + + public Optional getUrlByType(String type) { + if (approvalPlatformPathList == null || approvalPlatformPathList.isEmpty()) { + return Optional.empty(); + } + return approvalPlatformPathList.stream() + .filter(it -> it.getApproval_platform_type().equals(type)) + .map(it -> this.platformBaseUrl + it.getApproval_platform_path()) + .findFirst(); + } +} diff --git a/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformPath.java b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformPath.java new file mode 100644 index 00000000..2a9310d8 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/approval/platform/ApprovalPlatformPath.java @@ -0,0 +1,22 @@ +package com.chint.domain.aggregates.approval.platform; + + +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; + +@Data +@Table("approval_platform_path") +public class ApprovalPlatformPath implements Serializable { + @Serial + private static final long serialVersionUID = 9133251198723578532L; + @Id + private Long id; + private Long approval_platform_info_id; + private String approval_platform_path; + private String approval_platform_type; + private String extension; +} 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 a84d7d20..0ea76243 100644 --- a/src/main/java/com/chint/domain/aggregates/order/Leg.java +++ b/src/main/java/com/chint/domain/aggregates/order/Leg.java @@ -1,6 +1,8 @@ package com.chint.domain.aggregates.order; +import com.chint.domain.aggregates.base.BaseEvent; +import com.chint.domain.aggregates.base.EventManageable; import com.chint.domain.exceptions.LegEventException; import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.value_object.LegData; @@ -33,7 +35,7 @@ import static com.chint.infrastructure.constant.LegConstant.*; @Data @Table("leg") @NoArgsConstructor -public class Leg implements Serializable { +public class Leg implements Serializable, EventManageable { @Serial private static final long serialVersionUID = 1127655864081547575L; @Id @@ -75,6 +77,10 @@ public class Leg implements Serializable { @Transient private String legStatusName; @Transient + private Integer legApprovalStatus; + @Transient + private String legApprovalStatusName; + @Transient private String changeReason; private CurrencyType currencyType; @@ -84,6 +90,9 @@ public class Leg implements Serializable { @MappedCollection(idColumn = "leg_id", keyColumn = "leg_key") private List eventList; + @MappedCollection(idColumn = "leg_id", keyColumn = "leg_key") + private List legApprovalEventList; + @MappedCollection(idColumn = "leg_id") private LegExtensionField legExtensionField; @@ -251,6 +260,14 @@ public class Leg implements Serializable { .max(Comparator.comparingLong(LegEvent::getLegEventId)) .ifPresent(legEvent -> this.changeReason = legEvent.getExtension()); + if (this.legApprovalEventList == null || this.legApprovalEventList.isEmpty()) { + this.legApprovalStatus = LEG_APPROVAL_STATUS_NOT; + this.legApprovalStatusName = LEG_APPROVAL_STATUS_NOT_NAME; + } else { + BaseEvent lastEvent = this.getLastEvent().reloadStatus(); + this.legApprovalStatus = lastEvent.getEventType(); + this.legApprovalStatusName = lastEvent.getEventName(); + } return this; } @@ -375,6 +392,23 @@ public class Leg implements Serializable { // 将天数差异转换为晚上数量 return (int) daysBetween; } + + @Override + public List getEvents() { + if (this.legApprovalEventList == null) { + this.legApprovalEventList = new ArrayList<>(); + } + return this.legApprovalEventList; + } + + @Override + public List get() { + if (this.legApprovalEventList == null) { + this.legApprovalEventList = new ArrayList<>(); + } + return this.legApprovalEventList; + } + // private Leg timeFormatter() { // DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // String string = this.startTime.toString(); diff --git a/src/main/java/com/chint/domain/aggregates/order/LegApprovalEvent.java b/src/main/java/com/chint/domain/aggregates/order/LegApprovalEvent.java new file mode 100644 index 00000000..e94c047e --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/order/LegApprovalEvent.java @@ -0,0 +1,68 @@ +package com.chint.domain.aggregates.order; + +import com.chint.domain.aggregates.base.BaseEvent; +import com.google.gson.Gson; +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Column; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Map; + +import static com.chint.infrastructure.constant.LegConstant.*; + +@Data +@Table("leg_approval_event") +public class LegApprovalEvent extends BaseEvent implements Serializable { + + @Serial + private static final long serialVersionUID = 1113987613221578925L; + @Id + private Long legEventId; + @Column("leg_id") + private Long legId; + + + @Override + protected Map getStatusMappings() { + return Map.of(LEG_APPROVAL_STATUS_NOT, LEG_APPROVAL_STATUS_NOT_NAME, + LEG_APPROVAL_STATUS_PREPARE, LEG_APPROVAL_STATUS_PREPARE_NAME, + LEG_APPROVAL_STATUS_SUBMIT, LEG_APPROVAL_STATUS_SUBMIT_NAME, + LEG_APPROVAL_STATUS_SUCCESS, LEG_APPROVAL_STATUS_SUCCESS_NAME, + LEG_APPROVAL_STATUS_REJECT, LEG_APPROVAL_STATUS_REJECT_NAME); + } + + public static LegApprovalEvent prepare() { + LegApprovalEvent event = new LegApprovalEvent(); + event.setEventType(LEG_APPROVAL_STATUS_PREPARE); + return event; + } + + public static LegApprovalEvent prepare(Leg oldLeg) { + Gson gson = new Gson(); + LegApprovalEvent event = new LegApprovalEvent(); + event.setEventType(LEG_APPROVAL_STATUS_PREPARE); + event.extension(gson.toJson(oldLeg)); + return event; + } + + public static LegApprovalEvent submit() { + LegApprovalEvent event = new LegApprovalEvent(); + event.setEventType(LEG_APPROVAL_STATUS_SUBMIT); + return event; + } + + public static LegApprovalEvent success() { + LegApprovalEvent event = new LegApprovalEvent(); + event.setEventType(LEG_APPROVAL_STATUS_SUCCESS); + return event; + } + + public static LegApprovalEvent reject() { + LegApprovalEvent event = new LegApprovalEvent(); + event.setEventType(LEG_APPROVAL_STATUS_REJECT); + return event; + } +} diff --git a/src/main/java/com/chint/domain/repository/ApprovalPlatformInfoRepository.java b/src/main/java/com/chint/domain/repository/ApprovalPlatformInfoRepository.java new file mode 100644 index 00000000..929ddb1c --- /dev/null +++ b/src/main/java/com/chint/domain/repository/ApprovalPlatformInfoRepository.java @@ -0,0 +1,9 @@ +package com.chint.domain.repository; + +import com.chint.domain.aggregates.approval.platform.ApprovalPlatformInfo; + +import java.util.Optional; + +public interface ApprovalPlatformInfoRepository { + Optional findByPlatformMark(String platformMark); +} diff --git a/src/main/java/com/chint/domain/service/LegDomainService.java b/src/main/java/com/chint/domain/service/LegDomainService.java index 19f16ca8..0a1ba8d2 100644 --- a/src/main/java/com/chint/domain/service/LegDomainService.java +++ b/src/main/java/com/chint/domain/service/LegDomainService.java @@ -17,7 +17,6 @@ import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_CHANGE import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.OrderConstant.*; import static com.chint.infrastructure.constant.RouteConstant.APPROVAL_EVENT_PREPARE; -import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE; import static com.chint.infrastructure.constant.RouteRequestConstant.ROUTE_REQUEST_STATUS_SYNC; @Service @@ -117,7 +116,7 @@ public class LegDomainService { .reloadStatus(); routeOrder.deleteLeg(split[0]); } - if (routeOrder != null){ + if (routeOrder != null) { routeRepository.saveTempRouteOrder(routeOrder, 24L); } } @@ -144,7 +143,7 @@ public class LegDomainService { } public Leg addPreEvent(Leg leg) { - if(leg.getEventList() == null){ + if (leg.getEventList() == null) { leg.setEventList(new ArrayList<>()); } if (leg.getEventList().isEmpty()) { @@ -200,6 +199,7 @@ public class LegDomainService { // 过滤Leg items List filteredLegItems = legItems.stream() .filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER) && it.legIsInternal()) + .filter(it -> it.getLegApprovalStatus().equals(LEG_APPROVAL_STATUS_NOT)) .toList(); // 根据供应商名称查找供应商并进行处理 diff --git a/src/main/java/com/chint/domain/service/RouteApprovalDomainService.java b/src/main/java/com/chint/domain/service/RouteApprovalDomainService.java new file mode 100644 index 00000000..a1f468b5 --- /dev/null +++ b/src/main/java/com/chint/domain/service/RouteApprovalDomainService.java @@ -0,0 +1,54 @@ +package com.chint.domain.service; + +import com.chint.application.dtos.LegApprovalParam; +import com.chint.domain.aggregates.approval.ApprovalSubmit; +import com.chint.domain.aggregates.order.ApproveOrderNo; +import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.aggregates.system.SystemOrganization; +import com.chint.domain.repository.RouteRepository; +import com.chint.domain.repository.SystemCodeRepository; +import com.chint.domain.repository.SystemOrganizationRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import static com.chint.domain.aggregates.approval.ApprovalProcess.ApprovalType.LEG_ADD_CHANGE_BATCH; + +@Service +public class RouteApprovalDomainService { + + @Autowired + private RouteRepository routeRepository; + + @Autowired + private SystemCodeRepository systemCodeRepository; + + @Autowired + private SystemOrganizationRepository systemOrganizationRepository; + + + public void legApprovalResponse(){ + + } + + public void orderDetailResponse(){ + + } + + public void approveRouteOfLegChangeAndAdd(LegApprovalParam param) { + RouteOrder routeOrder = routeRepository.queryById(param.getRouteId()); + String approvalPlatformMark = getApprovalPlatformMark(routeOrder); + ApprovalSubmit.of(LEG_ADD_CHANGE_BATCH,approvalPlatformMark) + .approveData(routeOrder) + .submitToBpm(); + } + + + private String getApprovalPlatformMark(RouteOrder routeOrder){ + ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); + //先查寻公司是否有关联的BPM,如果没有的话,查询sysCode关联的BPM + return systemOrganizationRepository.findByOrgCodeContainingOrOrgNameContaining(approveOrderNo.getAccountCompany(), + approveOrderNo.getAccountCompany()).map(SystemOrganization::getApprovalPlatformMark).orElseGet( + () -> systemCodeRepository.findBySysCode(approveOrderNo.getSysCode()).getApprovalPlatformMark() + ); + } +} 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 d31eebb6..d05a9a47 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 @@ -80,6 +80,9 @@ public class LegEventHandler implements LegEventService { @Autowired private SystemCodeRepository systemCodeRepository; + @Autowired + private SystemOrganizationRepository systemOrganizationRepository; + @Autowired private BPMRequest bpmRequest; @@ -130,9 +133,16 @@ public class LegEventHandler implements LegEventService { routeOrder = routeRepository.findTempRouteOrderBySysCodeAndBillCode(sysCode, fakeOrderNo); } routeOrder.reloadStatus(); + + //如果是已经提交审批了,就直接退出 + if(routeOrder.getApproveOrderNo().getActualOrderNo() != null){ + return; + } + if (routeOrder.getLegItems().isEmpty()) { throw new OrderException(CommonMessageConstant.LEG_ERROR); } + //保存提交审批所提供的资料 routeOrder.updateApprovalData(data); @@ -379,7 +389,6 @@ public class LegEventHandler implements LegEventService { bpmRequest.change(zwChangeDto, sysCode, userId, accountCompany); return; } - switch (bpmCode) { case H3_BPM -> { JTH3ChangeDto jth3ChangeDto = new JTH3ChangeDto(); @@ -430,6 +439,4 @@ public class LegEventHandler implements LegEventService { legEvent.setExtension(command.getReason()); legRepository.save(byLegId); } - - } diff --git a/src/main/java/com/chint/infrastructure/repository/ApprovalPlatformInfoRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/ApprovalPlatformInfoRepositoryImpl.java new file mode 100644 index 00000000..1e4d49d3 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/ApprovalPlatformInfoRepositoryImpl.java @@ -0,0 +1,21 @@ +package com.chint.infrastructure.repository; + +import com.chint.domain.aggregates.approval.platform.ApprovalPlatformInfo; +import com.chint.domain.repository.ApprovalPlatformInfoRepository; +import com.chint.infrastructure.repository.jdbc.JdbcApprovalPlatformInfoRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public class ApprovalPlatformInfoRepositoryImpl implements ApprovalPlatformInfoRepository { + + @Autowired + private JdbcApprovalPlatformInfoRepository jdbcApprovalPlatformInfoRepository; + + @Override + public Optional findByPlatformMark(String platformMark) { + return jdbcApprovalPlatformInfoRepository.findByPlatformMark(platformMark); + } +} diff --git a/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java index 3b62808f..7b602348 100644 --- a/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/LegRepositoryImpl.java @@ -25,7 +25,9 @@ public class LegRepositoryImpl implements LegRepository { @Override public Leg save(Leg leg) { jdbcLegRepository.save(leg); - routeCacheService.invalidateRouteCache(leg.getRouteId()); + if (leg.getRouteId() != null) { + routeCacheService.invalidateRouteCache(leg.getRouteId()); + } return leg; } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcApprovalPlatformInfoRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcApprovalPlatformInfoRepository.java new file mode 100644 index 00000000..9c2de663 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcApprovalPlatformInfoRepository.java @@ -0,0 +1,13 @@ +package com.chint.infrastructure.repository.jdbc; + +import com.chint.domain.aggregates.approval.platform.ApprovalPlatformInfo; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface JdbcApprovalPlatformInfoRepository extends CrudRepository { + + Optional findByPlatformMark(String platformMark); +} 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 a0678a55..e3f6baeb 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 @@ -107,21 +107,21 @@ public class CTripNoteController { return Result.error("sign错误"); } -// handlerData(cTripStatusNotification); + handlerData(cTripStatusNotification); - if (orderStatus != null && orderId != null) { - String note = gson.toJson(cTripStatusNotification); - log.info("存入Redis{}", note); - redisTemplate.opsForList().leftPush(C_TRIP_BACK, note); - return Result.Success("成功收到消息"); - } - return Result.error("未收到消息"); -// return Result.Success("成功收到消息"); +// if (orderStatus != null && orderId != null) { +// String note = gson.toJson(cTripStatusNotification); +// log.info("存入Redis{}", note); +// redisTemplate.opsForList().leftPush(C_TRIP_BACK, note); +// return Result.Success("成功收到消息"); +// } +// return Result.error("未收到消息"); + return Result.Success("成功收到消息"); } - @Scheduled(cron = "0/10 * * * * ?") - @Async +// @Scheduled(cron = "0/10 * * * * ?") +// @Async public void scanCtripPendingMsg() { int i = 0; while (true) { diff --git a/src/test/java/com/chint/CTripTest.java b/src/test/java/com/chint/CTripTest.java index 5d36ef96..45ae1f68 100644 --- a/src/test/java/com/chint/CTripTest.java +++ b/src/test/java/com/chint/CTripTest.java @@ -250,7 +250,7 @@ public class CTripTest { @Test void search() { BaseContext.setCurrentUser(user); - SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("31472498556"); + SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("32219551997"); System.out.println(response); } diff --git a/src/test/java/com/chint/LYTest.java b/src/test/java/com/chint/LYTest.java index 2c6b6f13..6f2273a5 100644 --- a/src/test/java/com/chint/LYTest.java +++ b/src/test/java/com/chint/LYTest.java @@ -812,15 +812,16 @@ public class LYTest { @Test void searchFlight() { - FlightOrderResponse flightOrderDetail = lySearchRequest.getFlightOrderDetail("DF24032968512339782"); + FlightOrderResponse flightOrderDetail = lySearchRequest.getFlightOrderDetail("DF24041870728743261"); Gson gson = new Gson(); String json = gson.toJson(flightOrderDetail); System.out.println(json); } + @Test void searchTrain() { - TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24050672496002495"); + TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24062278179087557"); Gson gson = new Gson(); String json = gson.toJson(trainOrderDetail); System.out.println(json); @@ -828,7 +829,7 @@ public class LYTest { @Test void searchHotel() { - HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240511131800297715"); + HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240406120100189791"); Gson gson = new Gson(); String json = gson.toJson(hotelOrderDetail); System.out.println(json); diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 5c66bac0..a847e029 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -24,6 +24,7 @@ import com.chint.infrastructure.repository.CTripOrderDetailImpl; import com.chint.infrastructure.util.DateTimeUtil; import com.chint.infrastructure.util.Digest; import com.chint.infrastructure.util.PinyinUtil; +import com.chint.interfaces.rest.amap.dto.note.AmapNoteResponse; import com.chint.interfaces.rest.base.PostRequest; import com.chint.interfaces.rest.ctrip.CTripAirportRequest; import com.chint.interfaces.rest.ctrip.CTripUserSaveRequest; @@ -310,7 +311,7 @@ class RouteApplicationTests { @Test void loginSign() { - String sfno = "230615020"; + String sfno = "011207001"; String syscode = "FSSC"; String billcode = "CLSQ240620004123"; String companycode = "正泰集团股份有限公司"; @@ -321,9 +322,9 @@ class RouteApplicationTests { @Test void loginSignProd() { - String sfno = "220921136"; + String sfno = "080301001"; String syscode = "FSSC"; - String billcode = "CLSQ240225000099"; + String billcode = "CLSQ240620099999"; String companycode = "正泰集团股份有限公司"; String timespan = "1708908662738"; String key = "ZhengTaiRoute"; @@ -420,6 +421,9 @@ class RouteApplicationTests { postRequest.post("https://trip.chint.com/api/public/CTrip/status", requestBody, CTripNoteResponse.class); } + + postRequest.post("https://trip.chint.com/api/public/amap/status", + requestBody, AmapNoteResponse.class); System.out.println("这是第" + requestCount + "次请求"); // 每发起10次请求后休息1秒 requestCount++; @@ -435,7 +439,7 @@ class RouteApplicationTests { public static List extractRequestBodies(String log) { List requestBodies = new ArrayList<>(); - String patternString = "RequestBody:\\s*(\\{.*?\\})\\s*Stack Trace:"; + String patternString = "RequestBody:\\s*(.*?)\\s*Stack Trace:"; Pattern pattern = Pattern.compile(patternString, Pattern.DOTALL); Matcher matcher = pattern.matcher(log); @@ -462,49 +466,19 @@ class RouteApplicationTests { } List success = new ArrayList<>(); List failure = new ArrayList<>(); - String[] needOrderNo = { - "32084225159", "32146746813", "32158752075", "32171383412", "32171512338", "32178719048", - "32184435651", "32215789350", "32219581453", "32222298409", "32224573377", "32226396102", - "32234662287", "32236304050", "32249070854", "32249772579", "32256946953", "32257117381", - "32258011903", "32258485761", "32258628404", "32258678990", "32259609786", "32259728098", - "32259781390", "32259806425", "32259824756", "32260438297", "32260601852", "32260765132", - "32260918908", "32261359069", "32262054662", "32262969529", "32263064974", "32263131986", - "32263163899", "32264006341", "32264130918", "32264561473", "32264785338", "32265546260", - "32266005429", "32266131393", "32268013049", "32268055712", "32268176915", "32268308281", - "32269115540", "32270724335", "32271011469", "32271086263", "32273877605", "32274807710", - "32275237919", "32275803493", "32276121134", "32277427136", "32277753936", "32277764902", - "32278120007", "32278129213", "32278787671", "32279091482", "32279135528", "32279550298", - "32279742078", "32279914591", "32280026153", "32280042005", "32280707540", "32281513196", - "32281736393", "32281753545", "32281800631", "32281831567", "32282235024", "32282547907", - "32282574686", "32283005299", "32283256774", "32283818445", "32284250781", "32284713828", - "32285389760", "32285680785", "32285827233", "32285895752", "32286738588", "32286848572", - "32261128581", "32289454249", "32289577730", "32290702118", "32291537835", "32291589719", - "32292443034", "32292713870", "32292957306", "32293623982", "32293658222", "32294810855", - "32295360889", "32295791259", "32296124914", "32296273961", "32296530130", "32296552044", - "32297009228", "32298292163", "32300058687", "32300097765", "32300165160", "32301184984", - "32301449163", "32301527392", "32301911881", "32302017763", "32302094571", "32302356214", - "32302398477", "32302531250", "31536497498", "32303760508", "32304027018", "32304128494", - "32304195143", "32304204941", "32304519525", "32304563178", "32304828902", "32306523636", - "32306705819", "32306742872", "32307278952", "32307743735", "32307903575", "32308615866", - "32308797484", "32308849402", "32308903835", "32309414246", "32309423691", "32309641453", - "32309984561", "32310336983", "32310353307", "32310606344", "32310886788", "32311322662", - "32311392807", "32342902938", "32343614712", "32343892746", "32344140321", "32345166666", - "32345783537", "32346370055", "32346496542", "32346541710", "32346631989", "32347053863", - "32347080012", "32347664410", "32348518682", "32350025042", "32350666398", "32350712248", - "32352701125", "32387079073", "32390632631", "32391847372", "32392700246", "32392856910", - "32393204906", "32393811821", "32394936177", "32396042544", "32397830994", "32398755780", - "32400401495", "32400777212", "32401284432", "32401356706" - }; - List list1 = Arrays.asList(needOrderNo); + int requestCount = 0; List alreadyPost = new ArrayList<>(); for (CTripStatusNotification cTripStatusNotification : cTripStatusNotifications) { if (!CTripUtils.checkHotelStatus(cTripStatusNotification.getOrderStatus())) { continue; } - if (!list1.contains(cTripStatusNotification.getOrderId()) || alreadyPost.contains(cTripStatusNotification.getOrderId())) { + if (alreadyPost.contains(cTripStatusNotification.getOrderId())) { continue; } + + + CTripNoteResponse post = postRequest.post("https://trip.chint.com/api/public/CTrip/status", cTripStatusNotification, CTripNoteResponse.class); alreadyPost.add(cTripStatusNotification.getOrderId()); if (post.getErrorMessage() != null || !Objects.equals(post.getErrorCode(), "0")) { @@ -1374,7 +1348,7 @@ class RouteApplicationTests { } - @Test + @Test void addRanks() { RanksData ranksData = new RanksData(); ranksData.setIndustry("浙江正泰汽车科技有限公司"); @@ -1479,7 +1453,7 @@ class RouteApplicationTests { } @Test - void exposedLocation(){ + void exposedLocation() { List locations = locationDomainService.queryLocationAndChildren(); // 将数据转换为JSON格式 Gson gson = new Gson();