【update】ctrip回调接口修改为Redis消息队列存储
This commit is contained in:
parent
792c701eb4
commit
d6e6746f11
|
@ -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_TRAIN_PATH = "/switchapi/SettlementTrainOrder/SearchSettlementTrainOrderDetail";
|
||||||
|
|
||||||
public static final String C_TRIP_ORDER_CAR_PATH = "/switchapi/CarOrderSettlement/SearchSettlementCarOrderDetail";
|
public static final String C_TRIP_ORDER_CAR_PATH = "/switchapi/CarOrderSettlement/SearchSettlementCarOrderDetail";
|
||||||
|
|
||||||
|
public static final String C_TRIP_BACK="CtripBack";
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -5,10 +5,12 @@ import com.chint.domain.aggregates.order.OrderDetail;
|
||||||
import com.chint.domain.repository.SupplierCallBackLogRepository;
|
import com.chint.domain.repository.SupplierCallBackLogRepository;
|
||||||
import com.chint.domain.service.supplier.SupplierService;
|
import com.chint.domain.service.supplier.SupplierService;
|
||||||
import com.chint.domain.value_object.SupplierCallbackData;
|
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.echo_framework.command.Command;
|
||||||
import com.chint.infrastructure.util.Digest;
|
import com.chint.infrastructure.util.Digest;
|
||||||
import com.chint.infrastructure.util.Result;
|
import com.chint.infrastructure.util.Result;
|
||||||
import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest;
|
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.put.CTripStatusNotification;
|
||||||
import com.chint.interfaces.rest.ctrip.dto.search.ItineraryEntity;
|
import com.chint.interfaces.rest.ctrip.dto.search.ItineraryEntity;
|
||||||
import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse;
|
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.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
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.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
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.LegConstant.*;
|
||||||
import static com.chint.infrastructure.constant.OrderConstant.ORDER_STATUS_REFUSE_MSG;
|
import static com.chint.infrastructure.constant.OrderConstant.ORDER_STATUS_REFUSE_MSG;
|
||||||
import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP;
|
import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP;
|
||||||
|
@ -46,6 +53,9 @@ public class CTripNoteController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SupplierCallBackLogRepository supplierCallBackLogRepository;
|
private SupplierCallBackLogRepository supplierCallBackLogRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public RedisTemplate<String,String> redisTemplate;
|
||||||
|
|
||||||
private static final String NO_ETA_AVAILABLE = "暂无";
|
private static final String NO_ETA_AVAILABLE = "暂无";
|
||||||
|
|
||||||
private Gson gson = new Gson();
|
private Gson gson = new Gson();
|
||||||
|
@ -98,12 +108,41 @@ public class CTripNoteController {
|
||||||
return Result.error("sign错误");
|
return Result.error("sign错误");
|
||||||
}
|
}
|
||||||
if (orderStatus != null && orderId != null) {
|
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("未收到消息");
|
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<String> handlerData(String orderId, String orderStatus, Integer legType ) {
|
public Result<String> handlerData(String orderId, String orderStatus, Integer legType ) {
|
||||||
SupplierCallbackData supplierCallbackData =
|
SupplierCallbackData supplierCallbackData =
|
||||||
SupplierCallbackData.of(SUPPLIER_C_TRIP);
|
SupplierCallbackData.of(SUPPLIER_C_TRIP);
|
||||||
|
|
Loading…
Reference in New Issue