同步代码
This commit is contained in:
parent
99bd01fe7b
commit
914a4cd959
10
pom.xml
10
pom.xml
|
@ -82,11 +82,11 @@
|
||||||
<version>3.0.3</version>
|
<version>3.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- <dependency>-->
|
<dependency>
|
||||||
<!-- <groupId>com.authine.cloudpivot</groupId>-->
|
<groupId>com.authine.cloudpivot</groupId>
|
||||||
<!-- <artifactId>cloudpivot-opensdk</artifactId>-->
|
<artifactId>cloudpivot-opensdk</artifactId>
|
||||||
<!-- <version>1.0</version>-->
|
<version>1.0</version>
|
||||||
<!-- </dependency>-->
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,9 @@ import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
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;
|
import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_PREPARE;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -73,12 +74,20 @@ public class OrderApplicationService {
|
||||||
RouteOrder order = Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId()))
|
RouteOrder order = Optional.ofNullable(routeRepository.queryById(addLegData.getRouteId()))
|
||||||
.orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND));
|
.orElseThrow(() -> new NotFoundException(CommonMessageConstant.NOT_FOUND));
|
||||||
order.reloadStatus();
|
order.reloadStatus();
|
||||||
// if (!order.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
|
|
||||||
// throw new OrderException(ORDER_STATUS_ERROR);
|
|
||||||
// }
|
|
||||||
List<Leg> legs = processLegData(addLegData.getLegData(), order);
|
List<Leg> legs = processLegData(addLegData.getLegData(), order);
|
||||||
RouteOrder routeOrder = orderDomainService.saveOrder(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());
|
||||||
|
|
||||||
|
//异步操作-如果是当前的状态已经进行过匹配,那么就要订单同步到供应商一次
|
||||||
|
if (order.getOrderStatus() >= ORDER_STATUS_NOT_ORDERED) {
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
Command
|
||||||
|
.of(LegSyncCommand.class)
|
||||||
|
.data(SyncLegData.of(routeOrder.getRouteId(), routeOrder.getSupplierName()))
|
||||||
|
.sendToQueue();
|
||||||
|
});
|
||||||
|
}
|
||||||
return routeOrder; // 仅在所有操作完成后保存一次
|
return routeOrder; // 仅在所有操作完成后保存一次
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +103,19 @@ public class OrderApplicationService {
|
||||||
byLegId.setOriginId(legData.getOriginId());
|
byLegId.setOriginId(legData.getOriginId());
|
||||||
byLegId.setDestinationId(legData.getDestinationId());
|
byLegId.setDestinationId(legData.getDestinationId());
|
||||||
legRepository.save(byLegId);
|
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<Leg> processLegData(LegData legData, RouteOrder order) {
|
private List<Leg> processLegData(LegData legData, RouteOrder order) {
|
||||||
|
|
|
@ -9,4 +9,10 @@ public class SyncLegData {
|
||||||
private Long routeId;
|
private Long routeId;
|
||||||
private List<Long> routeIds;
|
private List<Long> routeIds;
|
||||||
private String supplierName;
|
private String supplierName;
|
||||||
|
public static SyncLegData of( Long routeId,String supplierName){
|
||||||
|
SyncLegData syncLegData = new SyncLegData();
|
||||||
|
syncLegData.setSupplierName(supplierName);
|
||||||
|
syncLegData.setRouteId(routeId);
|
||||||
|
return syncLegData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package com.chint.interfaces.rest.bpm.XNBPM;
|
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.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -11,7 +14,7 @@ import static com.chint.infrastructure.constant.BPMConstant.*;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ClientFactory {
|
public class ClientFactory {
|
||||||
// private static CloudpivotOpenClient client;
|
private static CloudpivotOpenClient client;
|
||||||
|
|
||||||
private static String XNBPMUrl;
|
private static String XNBPMUrl;
|
||||||
|
|
||||||
|
@ -21,15 +24,15 @@ public class ClientFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// public synchronized static CloudpivotOpenClient getInstance() {
|
public synchronized static CloudpivotOpenClient getInstance() {
|
||||||
// if (client == null) {
|
if (client == null) {
|
||||||
// synchronized (CloudpivotOpenClient.class) {
|
synchronized (CloudpivotOpenClient.class) {
|
||||||
// if (client == null) {
|
if (client == null) {
|
||||||
// CloudpivotEnvConfig config = new CloudpivotEnvConfig(XNBPMUrl + "/api", CLIENT_ID, CLIENT_SECRET);
|
CloudpivotEnvConfig config = new CloudpivotEnvConfig(XNBPMUrl + "/api", CLIENT_ID, CLIENT_SECRET);
|
||||||
// client = new CloudpivotOpenClient(config, new JdkHttpClient());
|
client = new CloudpivotOpenClient(config, new JdkHttpClient());
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// return client;
|
return client;
|
||||||
// }
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,10 @@ package com.chint;
|
||||||
import cn.hutool.core.lang.hash.Hash;
|
import cn.hutool.core.lang.hash.Hash;
|
||||||
import com.alibaba.fastjson.JSON;
|
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.domain.aggregates.user.User;
|
||||||
import com.chint.infrastructure.constant.LYConstant;
|
import com.chint.infrastructure.constant.LYConstant;
|
||||||
import com.chint.infrastructure.util.BaseContext;
|
import com.chint.infrastructure.util.BaseContext;
|
||||||
|
@ -413,40 +417,40 @@ public class LYTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDemo2() throws Exception {
|
public void testDemo2() throws Exception {
|
||||||
// XNTokenDto xnTokenDto = httpPostRequest.get(XNBPMUrl + XNBPM_TOKEN_URL + "?code=" + "191107079", XNTokenDto.class);
|
XNTokenDto xnTokenDto = httpPostRequest.get(XNBPMUrl + XNBPM_TOKEN_URL + "?code=" + "191107079", XNTokenDto.class);
|
||||||
// if (!"0".equals(xnTokenDto.getErrcode())) {
|
if (!"0".equals(xnTokenDto.getErrcode())) {
|
||||||
// throw new RuntimeException("用户不存在!");
|
throw new RuntimeException("用户不存在!");
|
||||||
// }
|
}
|
||||||
// String userId = xnTokenDto.getUser_id();
|
String userId = xnTokenDto.getUser_id();
|
||||||
// CloudpivotOpenClient client = ClientFactory.getInstance();
|
CloudpivotOpenClient client = ClientFactory.getInstance();
|
||||||
// StartWorkflowRequest request = new StartWorkflowRequest();
|
StartWorkflowRequest request = new StartWorkflowRequest();
|
||||||
// Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
// RescheduleDto rescheduleDto = new RescheduleDto();
|
RescheduleDto rescheduleDto = new RescheduleDto();
|
||||||
// rescheduleDto.setOrderType("机票改签")//内容选项:机票改签,机票退票,火车票改签,火车票退票
|
rescheduleDto.setOrderType("机票改签")//内容选项:机票改签,机票退票,火车票改签,火车票退票
|
||||||
// .setOrderSource("携程商旅")//携程商旅/同程商旅
|
.setOrderSource("携程商旅")//携程商旅/同程商旅
|
||||||
// .setOrderNo("00002")//订单号
|
.setOrderNo("00002")//订单号
|
||||||
// .setStartTime("2024-02-22 10:00:00")//机票改签或火车票改签提供: 原时间
|
.setStartTime("2024-02-22 10:00:00")//机票改签或火车票改签提供: 原时间
|
||||||
// .setRebookStartTime("2024-02-23 10:00:00")//机票改签或火车票改签提供: 改签后时间
|
.setRebookStartTime("2024-02-23 10:00:00")//机票改签或火车票改签提供: 改签后时间
|
||||||
// .setTrainNumber("")//火车票改签提供: 原车次
|
.setTrainNumber("")//火车票改签提供: 原车次
|
||||||
// .setSeatingStandard("")//火车票改签提供: 原席别
|
.setSeatingStandard("")//火车票改签提供: 原席别
|
||||||
// .setRebookTrainNumber("")//火车票改签提供: 改签后车次
|
.setRebookTrainNumber("")//火车票改签提供: 改签后车次
|
||||||
// .setRebookSeatingStandard("")//火车票改签提供: 改签后席别
|
.setRebookSeatingStandard("")//火车票改签提供: 改签后席别
|
||||||
// .setFee(BigDecimal.valueOf(100))//费用
|
.setFee(BigDecimal.valueOf(100))//费用
|
||||||
// .setReason("行程冲突");//原因
|
.setReason("行程冲突");//原因
|
||||||
// String entityParamValues = gson.toJson(rescheduleDto);
|
String entityParamValues = gson.toJson(rescheduleDto);
|
||||||
// Type type = new TypeToken<HashMap<String, Object>>(){}.getType();
|
Type type = new TypeToken<HashMap<String, Object>>(){}.getType();
|
||||||
// HashMap<String, Object> map = gson.fromJson(entityParamValues, type);
|
HashMap<String, Object> map = gson.fromJson(entityParamValues, type);
|
||||||
// request.setData(map);//数据
|
request.setData(map);//数据
|
||||||
// request.setDepartmentId("");//部门id,默认主部门
|
request.setDepartmentId("");//部门id,默认主部门
|
||||||
// request.setFinishStart(true);//发起流程
|
request.setFinishStart(true);//发起流程
|
||||||
// request.setUserId(userId);//员工号
|
request.setUserId(userId);//员工号
|
||||||
// request.setWorkflowCode("JG_AS_CLGQSQ");//改签流程
|
request.setWorkflowCode("JG_AS_CLGQSQ");//改签流程
|
||||||
// try {
|
try {
|
||||||
// StartWorkflowResponse response = client.startWorkflow(request);
|
StartWorkflowResponse response = client.startWorkflow(request);
|
||||||
// System.out.println("response = " + JSON.toJSONString(response));
|
System.out.println("response = " + JSON.toJSONString(response));
|
||||||
// } catch (ApiException e) {
|
} catch (ApiException e) {
|
||||||
// throw new RuntimeException(e.getMessage());
|
throw new RuntimeException(e.getMessage());
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue