From d6e6746f118502eb9e2c7fa24a7aebe3cfcafa01 Mon Sep 17 00:00:00 2001 From: nixj Date: Tue, 23 Apr 2024 13:21:45 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90update=E3=80=91ctrip=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9=E4=B8=BARedis=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E9=98=9F=E5=88=97=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/CTripConstant.java | 2 + .../rest/ctrip/dto/ctrip/CtripBack.java | 10 +++++ .../rest/ctrip/in/CTripNoteController.java | 41 ++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/chint/interfaces/rest/ctrip/dto/ctrip/CtripBack.java diff --git a/src/main/java/com/chint/infrastructure/constant/CTripConstant.java b/src/main/java/com/chint/infrastructure/constant/CTripConstant.java index ebcecc3c..7f6c1697 100644 --- a/src/main/java/com/chint/infrastructure/constant/CTripConstant.java +++ b/src/main/java/com/chint/infrastructure/constant/CTripConstant.java @@ -44,4 +44,6 @@ public class CTripConstant { public static final String C_TRIP_ORDER_TRAIN_PATH = "/switchapi/SettlementTrainOrder/SearchSettlementTrainOrderDetail"; public static final String C_TRIP_ORDER_CAR_PATH = "/switchapi/CarOrderSettlement/SearchSettlementCarOrderDetail"; + + public static final String C_TRIP_BACK="CtripBack"; } diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/dto/ctrip/CtripBack.java b/src/main/java/com/chint/interfaces/rest/ctrip/dto/ctrip/CtripBack.java new file mode 100644 index 00000000..db029d63 --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/ctrip/dto/ctrip/CtripBack.java @@ -0,0 +1,10 @@ +package com.chint.interfaces.rest.ctrip.dto.ctrip; + +import lombok.Data; + +@Data +public class CtripBack { + private String orderId; + private String orderStatus; + private Integer legType; +} 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 0545e20c..e0fdcb2d 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 @@ -5,10 +5,12 @@ 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; @@ -19,11 +21,16 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.concurrent.TimeUnit; + import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.OrderConstant.ORDER_STATUS_REFUSE_MSG; import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP; @@ -46,6 +53,9 @@ public class CTripNoteController { @Autowired private SupplierCallBackLogRepository supplierCallBackLogRepository; + @Autowired + public RedisTemplate redisTemplate; + private static final String NO_ETA_AVAILABLE = "暂无"; private Gson gson = new Gson(); @@ -98,12 +108,41 @@ public class CTripNoteController { return Result.error("sign错误"); } if (orderStatus != null && orderId != null) { - return handlerData(orderId, orderStatus, legType); + 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); + return Result.Success("成功收到消息"); +// return handlerData(orderId, orderStatus, legType); } return Result.error("未收到消息"); } + @Scheduled(cron="0/10 * * * * ?") + @Async + public void scanCtripPendingMsg() { + int i=0; + while (true) { + Object object = redisTemplate.opsForList().rightPop(CTripConstant.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()); + i++; + if (i>5){ + log.info("CtripBack处理结束"); + return; + } + } + + } + + public Result handlerData(String orderId, String orderStatus, Integer legType ) { SupplierCallbackData supplierCallbackData = SupplierCallbackData.of(SUPPLIER_C_TRIP);