From 914a4cd959c8ff76a382a05eac14920745012079 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Fri, 1 Mar 2024 10:25:18 +0800 Subject: [PATCH 1/2] =?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 --- pom.xml | 10 +-- .../services/OrderApplicationService.java | 30 ++++++-- .../domain/value_object/SyncLegData.java | 6 ++ .../rest/bpm/XNBPM/ClientFactory.java | 27 +++---- src/test/java/com/chint/LYTest.java | 72 ++++++++++--------- 5 files changed, 90 insertions(+), 55 deletions(-) diff --git a/pom.xml b/pom.xml index d1d73028..ec7065af 100644 --- a/pom.xml +++ b/pom.xml @@ -82,11 +82,11 @@ 3.0.3 - - - - - + + com.authine.cloudpivot + cloudpivot-opensdk + 1.0 + diff --git a/src/main/java/com/chint/application/services/OrderApplicationService.java b/src/main/java/com/chint/application/services/OrderApplicationService.java index 2feac52a..e7fdef23 100644 --- a/src/main/java/com/chint/application/services/OrderApplicationService.java +++ b/src/main/java/com/chint/application/services/OrderApplicationService.java @@ -26,8 +26,9 @@ import java.time.format.DateTimeFormatter; import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.concurrent.CompletableFuture; -import static com.chint.infrastructure.constant.CommonMessageConstant.ORDER_STATUS_ERROR; +import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_NOT_ORDERED; import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE; @Service @@ -73,12 +74,20 @@ public class OrderApplicationService { RouteOrder order = Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId())) .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)); order.reloadStatus(); -// if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE)) { -// throw new OrderException(ORDER_STATUS_ERROR); -// } + List legs = processLegData(addLegData.getLegData(), order); RouteOrder routeOrder = orderDomainService.saveOrder(order); legs.forEach(leg -> Command.of(LegPrepareCommand.class).legId(leg.getLegId()).sendToQueue()); + + //异步操作-如果是当前的状态已经进行过匹配,那么就要订单同步到供应商一次 + if (order.getOrderStatus() >= ORDER_STATUS_NOT_ORDERED) { + CompletableFuture.runAsync(() -> { + Command + .of(LegSyncCommand.class) + .data(SyncLegData.of(routeOrder.getRouteId(), routeOrder.getSupplierName())) + .sendToQueue(); + }); + } return routeOrder; // 仅在所有操作完成后保存一次 } @@ -94,6 +103,19 @@ public class OrderApplicationService { byLegId.setOriginId(legData.getOriginId()); byLegId.setDestinationId(legData.getDestinationId()); legRepository.save(byLegId); + + //异步操作-如果是当前的状态已经进行过匹配,那么就要订单同步到供应商一次 + CompletableFuture.runAsync(() -> { + Long routeId = byLegId.getRouteId(); + RouteOrder order = Optional.ofNullable(routeRepository.queryById(routeId)) + .orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND)).reloadStatus(); + if (order.getOrderStatus() >= ORDER_STATUS_NOT_ORDERED) { + Command + .of(LegSyncCommand.class) + .data(SyncLegData.of(order.getRouteId(), order.getSupplierName())) + .sendToQueue(); + } + }); } private List processLegData(LegData legData, RouteOrder order) { diff --git a/src/main/java/com/chint/domain/value_object/SyncLegData.java b/src/main/java/com/chint/domain/value_object/SyncLegData.java index d3664a4a..cf09311c 100644 --- a/src/main/java/com/chint/domain/value_object/SyncLegData.java +++ b/src/main/java/com/chint/domain/value_object/SyncLegData.java @@ -9,4 +9,10 @@ public class SyncLegData { private Long routeId; private List routeIds; private String supplierName; + public static SyncLegData of( Long routeId,String supplierName){ + SyncLegData syncLegData = new SyncLegData(); + syncLegData.setSupplierName(supplierName); + syncLegData.setRouteId(routeId); + return syncLegData; + } } diff --git a/src/main/java/com/chint/interfaces/rest/bpm/XNBPM/ClientFactory.java b/src/main/java/com/chint/interfaces/rest/bpm/XNBPM/ClientFactory.java index 3921c55a..179d210b 100644 --- a/src/main/java/com/chint/interfaces/rest/bpm/XNBPM/ClientFactory.java +++ b/src/main/java/com/chint/interfaces/rest/bpm/XNBPM/ClientFactory.java @@ -1,6 +1,9 @@ package com.chint.interfaces.rest.bpm.XNBPM; +import com.authine.cloudpivot.opensdk.CloudpivotOpenClient; +import com.authine.cloudpivot.opensdk.client.impl.JdkHttpClient; +import com.authine.cloudpivot.opensdk.config.CloudpivotEnvConfig; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -11,7 +14,7 @@ import static com.chint.infrastructure.constant.BPMConstant.*; */ @Service public class ClientFactory { -// private static CloudpivotOpenClient client; + private static CloudpivotOpenClient client; private static String XNBPMUrl; @@ -21,15 +24,15 @@ public class ClientFactory { } -// public synchronized static CloudpivotOpenClient getInstance() { -// if (client == null) { -// synchronized (CloudpivotOpenClient.class) { -// if (client == null) { -// CloudpivotEnvConfig config = new CloudpivotEnvConfig(XNBPMUrl + "/api", CLIENT_ID, CLIENT_SECRET); -// client = new CloudpivotOpenClient(config, new JdkHttpClient()); -// } -// } -// } -// return client; -// } + public synchronized static CloudpivotOpenClient getInstance() { + if (client == null) { + synchronized (CloudpivotOpenClient.class) { + if (client == null) { + CloudpivotEnvConfig config = new CloudpivotEnvConfig(XNBPMUrl + "/api", CLIENT_ID, CLIENT_SECRET); + client = new CloudpivotOpenClient(config, new JdkHttpClient()); + } + } + } + return client; + } } \ No newline at end of file diff --git a/src/test/java/com/chint/LYTest.java b/src/test/java/com/chint/LYTest.java index 7adbc2fc..6956b640 100644 --- a/src/test/java/com/chint/LYTest.java +++ b/src/test/java/com/chint/LYTest.java @@ -3,6 +3,10 @@ package com.chint; import cn.hutool.core.lang.hash.Hash; import com.alibaba.fastjson.JSON; +import com.authine.cloudpivot.opensdk.ApiException; +import com.authine.cloudpivot.opensdk.CloudpivotOpenClient; +import com.authine.cloudpivot.opensdk.model.request.workflow.StartWorkflowRequest; +import com.authine.cloudpivot.opensdk.model.response.workflow.StartWorkflowResponse; import com.chint.domain.aggregates.user.User; import com.chint.infrastructure.constant.LYConstant; import com.chint.infrastructure.util.BaseContext; @@ -413,40 +417,40 @@ public class LYTest { */ @Test public void testDemo2() throws Exception { -// XNTokenDto xnTokenDto = httpPostRequest.get(XNBPMUrl + XNBPM_TOKEN_URL + "?code=" + "191107079", XNTokenDto.class); -// if (!"0".equals(xnTokenDto.getErrcode())) { -// throw new RuntimeException("用户不存在!"); -// } -// String userId = xnTokenDto.getUser_id(); -// CloudpivotOpenClient client = ClientFactory.getInstance(); -// StartWorkflowRequest request = new StartWorkflowRequest(); -// Gson gson = new Gson(); -// RescheduleDto rescheduleDto = new RescheduleDto(); -// rescheduleDto.setOrderType("机票改签")//内容选项:机票改签,机票退票,火车票改签,火车票退票 -// .setOrderSource("携程商旅")//携程商旅/同程商旅 -// .setOrderNo("00002")//订单号 -// .setStartTime("2024-02-22 10:00:00")//机票改签或火车票改签提供: 原时间 -// .setRebookStartTime("2024-02-23 10:00:00")//机票改签或火车票改签提供: 改签后时间 -// .setTrainNumber("")//火车票改签提供: 原车次 -// .setSeatingStandard("")//火车票改签提供: 原席别 -// .setRebookTrainNumber("")//火车票改签提供: 改签后车次 -// .setRebookSeatingStandard("")//火车票改签提供: 改签后席别 -// .setFee(BigDecimal.valueOf(100))//费用 -// .setReason("行程冲突");//原因 -// String entityParamValues = gson.toJson(rescheduleDto); -// Type type = new TypeToken>(){}.getType(); -// HashMap map = gson.fromJson(entityParamValues, type); -// request.setData(map);//数据 -// request.setDepartmentId("");//部门id,默认主部门 -// request.setFinishStart(true);//发起流程 -// request.setUserId(userId);//员工号 -// request.setWorkflowCode("JG_AS_CLGQSQ");//改签流程 -// try { -// StartWorkflowResponse response = client.startWorkflow(request); -// System.out.println("response = " + JSON.toJSONString(response)); -// } catch (ApiException e) { -// throw new RuntimeException(e.getMessage()); -// } + XNTokenDto xnTokenDto = httpPostRequest.get(XNBPMUrl + XNBPM_TOKEN_URL + "?code=" + "191107079", XNTokenDto.class); + if (!"0".equals(xnTokenDto.getErrcode())) { + throw new RuntimeException("用户不存在!"); + } + String userId = xnTokenDto.getUser_id(); + CloudpivotOpenClient client = ClientFactory.getInstance(); + StartWorkflowRequest request = new StartWorkflowRequest(); + Gson gson = new Gson(); + RescheduleDto rescheduleDto = new RescheduleDto(); + rescheduleDto.setOrderType("机票改签")//内容选项:机票改签,机票退票,火车票改签,火车票退票 + .setOrderSource("携程商旅")//携程商旅/同程商旅 + .setOrderNo("00002")//订单号 + .setStartTime("2024-02-22 10:00:00")//机票改签或火车票改签提供: 原时间 + .setRebookStartTime("2024-02-23 10:00:00")//机票改签或火车票改签提供: 改签后时间 + .setTrainNumber("")//火车票改签提供: 原车次 + .setSeatingStandard("")//火车票改签提供: 原席别 + .setRebookTrainNumber("")//火车票改签提供: 改签后车次 + .setRebookSeatingStandard("")//火车票改签提供: 改签后席别 + .setFee(BigDecimal.valueOf(100))//费用 + .setReason("行程冲突");//原因 + String entityParamValues = gson.toJson(rescheduleDto); + Type type = new TypeToken>(){}.getType(); + HashMap map = gson.fromJson(entityParamValues, type); + request.setData(map);//数据 + request.setDepartmentId("");//部门id,默认主部门 + request.setFinishStart(true);//发起流程 + request.setUserId(userId);//员工号 + request.setWorkflowCode("JG_AS_CLGQSQ");//改签流程 + try { + StartWorkflowResponse response = client.startWorkflow(request); + System.out.println("response = " + JSON.toJSONString(response)); + } catch (ApiException e) { + throw new RuntimeException(e.getMessage()); + } } } From 42174e9bce618f4e41b82091b778fe10fb3fcd76 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Fri, 1 Mar 2024 10:33:39 +0800 Subject: [PATCH 2/2] =?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 --- pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pom.xml b/pom.xml index ec7065af..f69df198 100644 --- a/pom.xml +++ b/pom.xml @@ -106,4 +106,11 @@ + + + central + 新正泰集团公共仓库 + https://newmaven.chint.com/repository/maven-public/ + +