From 7a81b68b9b030b54c222c247994763b9629a8391 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Tue, 14 May 2024 13:47:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=9B=E5=BA=94=E5=95=86=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=9B=9E=E6=8E=A8=E5=87=BA=E7=8E=B0=E6=8A=A5=E9=94=99=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E4=BF=9D=E5=AD=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SupplierCallBackErrorCommand.java | 18 ++++++ .../out/OrderDetailController.java | 4 +- .../supplier/SupplierCallBackLog.java | 49 ++++++++++++++++ .../system/SupplierCallBackLog.java | 34 ----------- .../SupplierCallBackLogRepository.java | 3 +- .../domain/service/SupplierDomainService.java | 16 ++++- .../SupplierCallBackLogRepositoryImpl.java | 3 +- .../JdbcSupplierCallBackLogRepository.java | 2 +- .../jdbc/JdbcSupplierRepository.java | 1 - .../rest/amap/in/AmapNoteController.java | 36 +++++++----- .../rest/ctrip/in/CTripNoteController.java | 57 +++++++----------- .../rest/ly/in/CommonController.java | 36 ++++++++---- .../rest/ly/in/LYETAController.java | 58 +++++++++++-------- 13 files changed, 189 insertions(+), 128 deletions(-) create mode 100644 src/main/java/com/chint/application/commands/SupplierCallBackErrorCommand.java create mode 100644 src/main/java/com/chint/domain/aggregates/supplier/SupplierCallBackLog.java delete mode 100644 src/main/java/com/chint/domain/aggregates/system/SupplierCallBackLog.java diff --git a/src/main/java/com/chint/application/commands/SupplierCallBackErrorCommand.java b/src/main/java/com/chint/application/commands/SupplierCallBackErrorCommand.java new file mode 100644 index 00000000..20b06ab9 --- /dev/null +++ b/src/main/java/com/chint/application/commands/SupplierCallBackErrorCommand.java @@ -0,0 +1,18 @@ +package com.chint.application.commands; + +import com.chint.infrastructure.echo_framework.command.Command; +import lombok.Data; + +@Data +public class SupplierCallBackErrorCommand extends Command { + private Exception e; + private String supplierName; + private String requestBody; + + public SupplierCallBackErrorCommand info(String supplierName, String requestBody, Exception e) { + this.setSupplierName(supplierName); + this.setRequestBody(requestBody); + this.setE(e); + return this; + } +} diff --git a/src/main/java/com/chint/application/out/OrderDetailController.java b/src/main/java/com/chint/application/out/OrderDetailController.java index a076d530..4a12b35d 100644 --- a/src/main/java/com/chint/application/out/OrderDetailController.java +++ b/src/main/java/com/chint/application/out/OrderDetailController.java @@ -10,11 +10,9 @@ import com.chint.domain.repository.ClientRepository; import com.chint.domain.repository.OrderDetailRepository; import com.chint.domain.repository.RouteRepository; import com.chint.domain.service.auth.AuthenticateService; -import com.chint.domain.value_object.OrderQueryData; import com.chint.domain.value_object.RouteOrderDetail; import com.chint.infrastructure.echo_framework.annotation.TransitionTo; import com.chint.infrastructure.export.OrderDetailExportFactory; -import com.chint.infrastructure.export.OrderDetailWriter; import com.chint.infrastructure.util.Digest; import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.Result; @@ -81,7 +79,6 @@ public class OrderDetailController { private OrderDetailExportFactory orderDetailExportFactory; - @ApiOperation("订单明细认证接口") @PostMapping("/public/authentication") public Result queryAuthentication(@RequestBody AuthenticationDto authenticationDto) { @@ -232,6 +229,7 @@ public class OrderDetailController { addOrderEvent(orderDetail, command.getType(), LocalDateTime.now()); orderDetail.setPrice(command.getAmount()); + orderDetail.setCreateTime(LocalDateTime.now()); processProductSpecificDetails(orderDetail, command, newOrderNo); diff --git a/src/main/java/com/chint/domain/aggregates/supplier/SupplierCallBackLog.java b/src/main/java/com/chint/domain/aggregates/supplier/SupplierCallBackLog.java new file mode 100644 index 00000000..25cc9def --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/supplier/SupplierCallBackLog.java @@ -0,0 +1,49 @@ +package com.chint.domain.aggregates.supplier; + + +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.PrintWriter; +import java.io.StringWriter; +import java.time.LocalDateTime; + +@Data +@Table("supplier_call_back_log") +public class SupplierCallBackLog { + @Id + private Long id; + private String supplierName; + private LocalDateTime happenTime; + private String callBackJson; + + public static SupplierCallBackLog start() { + SupplierCallBackLog supplierCallBackLog = new SupplierCallBackLog(); + supplierCallBackLog.setHappenTime(LocalDateTime.now()); + return supplierCallBackLog; + } + + public SupplierCallBackLog supplier(String supplierName) { + this.supplierName = supplierName; + return this; + } + + public SupplierCallBackLog callBackJson(String callBackJson) { + this.callBackJson = callBackJson; + return this; + } + + public static SupplierCallBackLog fromException(String supplierName, String requestBody, Exception e) { + SupplierCallBackLog log = SupplierCallBackLog.start(); + log.setSupplierName(supplierName); + + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw)); + String exceptionDetails = sw.toString(); + + log.setCallBackJson("Exception: " + e.getMessage() + "\nRequestBody:\n" + requestBody + "\nStack Trace:\n" + exceptionDetails); + return log; + } +} diff --git a/src/main/java/com/chint/domain/aggregates/system/SupplierCallBackLog.java b/src/main/java/com/chint/domain/aggregates/system/SupplierCallBackLog.java deleted file mode 100644 index bf74cb5a..00000000 --- a/src/main/java/com/chint/domain/aggregates/system/SupplierCallBackLog.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.chint.domain.aggregates.system; - - -import lombok.Data; -import org.springframework.data.annotation.Id; -import org.springframework.data.relational.core.mapping.Table; - -import java.time.LocalDateTime; - -@Data -@Table("supplier_call_back_log") -public class SupplierCallBackLog { - @Id - private Long id; - private String supplierName; - private LocalDateTime happenTime; - private String callBackJson; - - public static SupplierCallBackLog start(){ - SupplierCallBackLog supplierCallBackLog = new SupplierCallBackLog(); - supplierCallBackLog.setHappenTime(LocalDateTime.now()); - return supplierCallBackLog; - } - - public SupplierCallBackLog supplier(String supplierName){ - this.supplierName = supplierName; - return this; - } - - public SupplierCallBackLog callBackJson(String callBackJson){ - this.callBackJson = callBackJson; - return this; - } -} diff --git a/src/main/java/com/chint/domain/repository/SupplierCallBackLogRepository.java b/src/main/java/com/chint/domain/repository/SupplierCallBackLogRepository.java index 423d56aa..f18347ba 100644 --- a/src/main/java/com/chint/domain/repository/SupplierCallBackLogRepository.java +++ b/src/main/java/com/chint/domain/repository/SupplierCallBackLogRepository.java @@ -1,10 +1,9 @@ package com.chint.domain.repository; -import com.chint.domain.aggregates.system.SupplierCallBackLog; +import com.chint.domain.aggregates.supplier.SupplierCallBackLog; public interface SupplierCallBackLogRepository { SupplierCallBackLog save(SupplierCallBackLog supplierCallBackLog); - } diff --git a/src/main/java/com/chint/domain/service/SupplierDomainService.java b/src/main/java/com/chint/domain/service/SupplierDomainService.java index d62e8e39..f629a1c4 100644 --- a/src/main/java/com/chint/domain/service/SupplierDomainService.java +++ b/src/main/java/com/chint/domain/service/SupplierDomainService.java @@ -1,9 +1,13 @@ package com.chint.domain.service; +import com.chint.application.commands.SupplierCallBackErrorCommand; import com.chint.domain.aggregates.order.Leg; import com.chint.domain.aggregates.supplier.Supplier; +import com.chint.domain.aggregates.supplier.SupplierCallBackLog; import com.chint.domain.aggregates.supplier.SupplierProduct; +import com.chint.domain.repository.SupplierCallBackLogRepository; import com.chint.domain.repository.SupplierRepository; +import com.chint.infrastructure.echo_framework.annotation.ListenTo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,6 +20,9 @@ public class SupplierDomainService { @Autowired private SupplierRepository supplierRepository; + @Autowired + private SupplierCallBackLogRepository supplierCallBackLogRepository; + public boolean ifCanCancel(Leg leg, String supplierName) { Optional supplierOptional = supplierRepository.findBySupplierName(supplierName); if (supplierOptional.isPresent()) { @@ -43,7 +50,7 @@ public class SupplierDomainService { List productTypes = supplier .getSupplierProductList() .stream() - .filter(it->it.getIfCanOrder().equals(1)) + .filter(it -> it.getIfCanOrder().equals(1)) .map(SupplierProduct::getProductType) .toList(); return legs.stream().filter(it -> productTypes.contains(it.getLegType())).toList(); @@ -51,4 +58,11 @@ public class SupplierDomainService { return legs; } } + + @ListenTo(command = "SupplierCallBackErrorCommand", order = 0) + public void supplierCallBackError(SupplierCallBackErrorCommand command) { + SupplierCallBackLog supplierCallBackLog = SupplierCallBackLog + .fromException(command.getSupplierName(), command.getRequestBody(), command.getE()); + supplierCallBackLogRepository.save(supplierCallBackLog); + } } diff --git a/src/main/java/com/chint/infrastructure/repository/SupplierCallBackLogRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/SupplierCallBackLogRepositoryImpl.java index 5534e9ca..90b6d505 100644 --- a/src/main/java/com/chint/infrastructure/repository/SupplierCallBackLogRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/SupplierCallBackLogRepositoryImpl.java @@ -1,10 +1,9 @@ package com.chint.infrastructure.repository; -import com.chint.domain.aggregates.system.SupplierCallBackLog; +import com.chint.domain.aggregates.supplier.SupplierCallBackLog; import com.chint.domain.repository.SupplierCallBackLogRepository; import com.chint.infrastructure.repository.jdbc.JdbcSupplierCallBackLogRepository; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.annotation.Id; import org.springframework.stereotype.Repository; @Repository diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSupplierCallBackLogRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSupplierCallBackLogRepository.java index c4738737..c9fe3a86 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSupplierCallBackLogRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSupplierCallBackLogRepository.java @@ -1,6 +1,6 @@ package com.chint.infrastructure.repository.jdbc; -import com.chint.domain.aggregates.system.SupplierCallBackLog; +import com.chint.domain.aggregates.supplier.SupplierCallBackLog; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSupplierRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSupplierRepository.java index bef19dc9..2077de3c 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSupplierRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcSupplierRepository.java @@ -1,7 +1,6 @@ package com.chint.infrastructure.repository.jdbc; import com.chint.domain.aggregates.supplier.Supplier; -import com.chint.domain.aggregates.system.SupplierCallBackLog; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/com/chint/interfaces/rest/amap/in/AmapNoteController.java b/src/main/java/com/chint/interfaces/rest/amap/in/AmapNoteController.java index 37b925e0..f4e76d02 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/in/AmapNoteController.java +++ b/src/main/java/com/chint/interfaces/rest/amap/in/AmapNoteController.java @@ -1,6 +1,7 @@ package com.chint.interfaces.rest.amap.in; import com.chint.application.commands.OrderStatusChangeCommand; +import com.chint.application.commands.SupplierCallBackErrorCommand; import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.service.supplier.SupplierService; import com.chint.domain.value_object.SupplierCallbackData; @@ -21,6 +22,7 @@ import org.springframework.web.util.UriUtils; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.CompletableFuture; import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_TAXI; import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_AMAP; @@ -42,6 +44,7 @@ public class AmapNoteController { @PostMapping("/status") public AmapNoteResponse statusEvent(@RequestBody String in) { + String requestBody = in; String[] split = in.split("="); in = UriUtils.decode(split[1], StandardCharsets.UTF_8); // 拆分成键值对 @@ -69,21 +72,28 @@ public class AmapNoteController { if (checkCarStatus(data.getShowStatus())) { - Integer eventType = mapCarStatus(data.getShowStatus()); + try { + Integer eventType = mapCarStatus(data.getShowStatus()); - SupplierCallbackData supplierCallbackData = SupplierCallbackData.of(SUPPLIER_AMAP) - .data(response) - .productType(LEG_TYPE_TAXI) - .outOrderStatus(String.valueOf(data.getShowStatus())) - .selfOrderStatus(eventType); - OrderDetail orderDetail = supplierService.handleSupplierCallback(supplierCallbackData); + SupplierCallbackData supplierCallbackData = SupplierCallbackData.of(SUPPLIER_AMAP) + .data(response) + .productType(LEG_TYPE_TAXI) + .outOrderStatus(String.valueOf(data.getShowStatus())) + .selfOrderStatus(eventType); + OrderDetail orderDetail = supplierService.handleSupplierCallback(supplierCallbackData); - Command.of(OrderStatusChangeCommand.class) - .orderDetail(orderDetail) - .orderNo(data.getAmapOrderId()) - .outStatus(String.valueOf(data.getShowStatus())) - .eventType(eventType) - .sendToQueue(); + Command.of(OrderStatusChangeCommand.class) + .orderDetail(orderDetail) + .orderNo(data.getAmapOrderId()) + .outStatus(String.valueOf(data.getShowStatus())) + .eventType(eventType) + .sendToQueue(); + } catch (Exception e) { + //如果推送异常,将异常信息保存到数据库 + CompletableFuture.runAsync(() -> Command.of(SupplierCallBackErrorCommand.class) + .info(SUPPLIER_AMAP, requestBody, e).sendToQueue()); + e.printStackTrace(); + } return AmapNoteResponse.success("接收成功"); } else { 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 d3c6f0cc..180914e8 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 @@ -2,16 +2,15 @@ package com.chint.interfaces.rest.ctrip.in; import cn.hutool.core.bean.BeanUtil; import com.chint.application.commands.OrderStatusChangeCommand; +import com.chint.application.commands.SupplierCallBackErrorCommand; import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.repository.SupplierCallBackLogRepository; import com.chint.domain.service.supplier.SupplierService; import com.chint.domain.value_object.SupplierCallbackData; -import com.chint.infrastructure.constant.CTripConstant; import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.util.Digest; import com.chint.infrastructure.util.Result; import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest; -import com.chint.interfaces.rest.ctrip.dto.ctrip.CtripBack; import com.chint.interfaces.rest.ctrip.dto.put.CTripStatusNotification; import com.chint.interfaces.rest.ctrip.dto.search.ItineraryEntity; import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse; @@ -32,8 +31,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import static com.chint.infrastructure.constant.CTripConstant.C_TRIP_BACK; import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_REFUND; import static com.chint.infrastructure.constant.OrderConstant.ORDER_STATUS_REFUSE_MSG; @@ -64,26 +65,6 @@ public class CTripNoteController { private Gson gson = new Gson(); -// @PostMapping("/event") -// public CTripNoteResponse noteEvent(@RequestBody CTripNotification cTripNotification) { -// String putCTripEventSign = Digest.getPutCTripEventSign(cTripNotification); -// if (!putCTripEventSign.equals(cTripNotification.getSign())) { -// return new CTripNoteResponse("1", "sign错误"); -// } -// -// if (cTripNotification.getContent() != null && cTripNotification.getPreEmployeeID() != null) { -// //成功触发消息,需要查询对于的订单信息,調用订单查询的服务来查询该订单详情 -// SupplierCallbackData supplierCallbackData = -// SupplierCallbackData.of(SUPPLIER_C_TRIP, cTripNotification.getPreEmployeeID()); -// SearchOrderResponse response = cTripOrderSearchRequest -// .searchOrderResponseByOrderId(cTripNotification.getBusinessId()); -// supplierCallbackData.data(response); -// supplierService.handleSupplierCallback(supplierCallbackData); -// return new CTripNoteResponse("0", "成功收到消息"); -// } -// return new CTripNoteResponse("1", "未收到消息"); -// } - @PostMapping("/status") public Result statusEvent(@RequestBody CTripStatusNotification cTripStatusNotification) { @@ -111,15 +92,10 @@ public class CTripNoteController { return Result.error("sign错误"); } if (orderStatus != null && orderId != null) { - CtripBack notification = new CtripBack(); - notification.setOrderStatus(orderStatus); - notification.setOrderId(orderId); - notification.setLegType(legType); - String ctripBack = gson.toJson(notification); - log.info("存入Redis{}", ctripBack); - redisTemplate.opsForList().leftPush(CTripConstant.C_TRIP_BACK, ctripBack); + String note = gson.toJson(cTripStatusNotification); + log.info("存入Redis{}", note); + redisTemplate.opsForList().leftPush(C_TRIP_BACK, note); return Result.Success("成功收到消息"); -// return handlerData(orderId, orderStatus, legType); } return Result.error("未收到消息"); } @@ -130,22 +106,33 @@ public class CTripNoteController { public void scanCtripPendingMsg() { int i = 0; while (true) { - Object object = redisTemplate.opsForList().rightPop(CTripConstant.C_TRIP_BACK, 1, TimeUnit.SECONDS); + Object object = redisTemplate.opsForList().rightPop(C_TRIP_BACK, 1, TimeUnit.SECONDS); if (null == object) { return; } - CtripBack notification = gson.fromJson(String.valueOf(object), CtripBack.class); - handlerData(notification.getOrderId(), notification.getOrderStatus(), notification.getLegType()); + CTripStatusNotification notification = gson.fromJson(String.valueOf(object), CTripStatusNotification.class); + try { + handlerData(notification); + } catch (Exception e) { + //如果推送异常,将异常信息保存到数据库 + CompletableFuture.runAsync(() -> Command.of(SupplierCallBackErrorCommand.class) + .info(SUPPLIER_C_TRIP, gson.toJson(notification), e).sendToQueue()); + e.printStackTrace(); + } i++; if (i > 5) { - log.info("CtripBack处理结束"); return; } } } - public Result handlerData(String orderId, String orderStatus, Integer legType) { + public Result handlerData(CTripStatusNotification cTripStatusNotification) { + String productType = cTripStatusNotification.getProductType(); + Integer legType = translateLegType(productType); + String orderStatus = cTripStatusNotification.getOrderStatus(); + String orderId = cTripStatusNotification.getOrderId(); + SupplierCallbackData supplierCallbackData = SupplierCallbackData.of(SUPPLIER_C_TRIP); SearchOrderResponse response = cTripOrderSearchRequest diff --git a/src/main/java/com/chint/interfaces/rest/ly/in/CommonController.java b/src/main/java/com/chint/interfaces/rest/ly/in/CommonController.java index c083defe..68df41d3 100644 --- a/src/main/java/com/chint/interfaces/rest/ly/in/CommonController.java +++ b/src/main/java/com/chint/interfaces/rest/ly/in/CommonController.java @@ -3,9 +3,11 @@ package com.chint.interfaces.rest.ly.in; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.chint.application.commands.SupplierCallBackErrorCommand; import com.chint.domain.aggregates.order.OrderTravel; import com.chint.domain.repository.SupplierCallBackLogRepository; import com.chint.infrastructure.constant.CommonMessageConstant; +import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.repository.jdbc.JdbcOrderTravelRepository; import com.chint.interfaces.rest.base.PostRequest; import com.chint.interfaces.rest.ly.LYNoteResponse; @@ -20,6 +22,7 @@ import com.chint.interfaces.rest.ly.dto.strokepush.StrokePushResult; import com.chint.interfaces.rest.ly.dto.strokepush.TrainChange.TrainChangeParam; import com.chint.interfaces.rest.ly.dto.strokepush.TrainChange.TrainChangeRequest; import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -37,6 +40,9 @@ import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP; +import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_L_Y; + @Slf4j @RestController @RequestMapping("/public/common") @@ -113,17 +119,25 @@ public class CommonController { if (null == object) { return; } -// String msg = JSON.toJSONString(object); - Notification notification = gson.fromJson(String.valueOf(object), Notification.class); - int notifyType = notification.getNotifyType(); - switch (notifyType) { - //进行订单数据回推 - case 1 -> getOrderFlight(notification); - case 3 -> getOrderHotel(notification); - case 5 -> getOrderTrain(notification); - case 6 -> getOrderCar(notification); - default -> LYNoteResponse.success(); - }; + + try { + Notification notification = gson.fromJson(String.valueOf(object), Notification.class); + int notifyType = notification.getNotifyType(); + switch (notifyType) { + //进行订单数据回推 + case 1 -> getOrderFlight(notification); + case 3 -> getOrderHotel(notification); + case 5 -> getOrderTrain(notification); + case 6 -> getOrderCar(notification); + default -> LYNoteResponse.success(); + } + } catch (Exception e) { + //如果推送异常,将异常信息保存到数据库 + CompletableFuture.runAsync(() -> Command.of(SupplierCallBackErrorCommand.class) + .info(SUPPLIER_L_Y, String.valueOf(object), e).sendToQueue()); + e.printStackTrace(); + } + i++; if (i > 5) { log.info("CommonBack处理结束"); diff --git a/src/main/java/com/chint/interfaces/rest/ly/in/LYETAController.java b/src/main/java/com/chint/interfaces/rest/ly/in/LYETAController.java index 703a6e0c..e4e3f744 100644 --- a/src/main/java/com/chint/interfaces/rest/ly/in/LYETAController.java +++ b/src/main/java/com/chint/interfaces/rest/ly/in/LYETAController.java @@ -2,6 +2,7 @@ package com.chint.interfaces.rest.ly.in; import cn.hutool.core.bean.BeanUtil; import com.chint.application.commands.OrderStatusChangeCommand; +import com.chint.application.commands.SupplierCallBackErrorCommand; import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.aggregates.order.OrderTravel; import com.chint.domain.exceptions.NotFoundException; @@ -86,34 +87,41 @@ public class LYETAController { } - List supplierCallbackDataList = handlerETACallBackData(lyETAPush); + try { + List supplierCallbackDataList = handlerETACallBackData(lyETAPush); - for (SupplierCallbackData supplierCallbackData : supplierCallbackDataList) { - OrderDetail orderDetail = supplierService.handleSupplierCallback(supplierCallbackData); - orderTravelRepository.save(OrderTravel.of(orderDetail.getOrderNo(), approvalOrderId)); + for (SupplierCallbackData supplierCallbackData : supplierCallbackDataList) { + OrderDetail orderDetail = supplierService.handleSupplierCallback(supplierCallbackData); + orderTravelRepository.save(OrderTravel.of(orderDetail.getOrderNo(), approvalOrderId)); - if (supplierCallbackData.getExtension() != null) { - //发送超标事件 - Command.of(OrderStatusChangeCommand.class) - .orderDetail(orderDetail) - .outStatus("超标") - .extension(supplierCallbackData.getExtension()) - .eventType(ORDER_EVENT_ETA) - .orderNo(orderDetail.getOrderNo()) - .sendToQueue(); - } - - int subNotifyType = lyETAPush.getSubNotifyType(); - if (subNotifyType == 2 || subNotifyType == 4 || subNotifyType == 6) { - //如果推送类是2,4,6还要触发改签事件 - Command.of(OrderStatusChangeCommand.class) - .orderDetail(orderDetail) - .outStatus("改签") - .extension(supplierCallbackData.getExtension()) - .eventType(ORDER_EVENT_CHANGE) - .orderNo(orderDetail.getOrderNo()) - .sendToQueue(); + if (supplierCallbackData.getExtension() != null) { + //发送超标事件 + Command.of(OrderStatusChangeCommand.class) + .orderDetail(orderDetail) + .outStatus("超标") + .extension(supplierCallbackData.getExtension()) + .eventType(ORDER_EVENT_ETA) + .orderNo(orderDetail.getOrderNo()) + .sendToQueue(); + } + + int subNotifyType = lyETAPush.getSubNotifyType(); + if (subNotifyType == 2 || subNotifyType == 4 || subNotifyType == 6) { + //如果推送类是2,4,6还要触发改签事件 + Command.of(OrderStatusChangeCommand.class) + .orderDetail(orderDetail) + .outStatus("改签") + .extension(supplierCallbackData.getExtension()) + .eventType(ORDER_EVENT_CHANGE) + .orderNo(orderDetail.getOrderNo()) + .sendToQueue(); + } } + } catch (Exception e) { + //如果推送异常,将异常信息保存到数据库 + CompletableFuture.runAsync(() -> Command.of(SupplierCallBackErrorCommand.class) + .info(SUPPLIER_L_Y, gson.toJson(lyETAPush), e).sendToQueue()); + e.printStackTrace(); } return LYNoteResponse.success(); }