|
@@ -0,0 +1,124 @@
|
|
|
|
+package com.fire.setcallback.service.impl;
|
|
|
|
+
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
+import com.fire.common.auth.SupplierAuth;
|
|
|
|
+import com.fire.common.redis.RedisPriorityQueueScript;
|
|
|
|
+import com.fire.dto.ChannelSupplier;
|
|
|
|
+import com.fire.dto.FlowOrderInfo;
|
|
|
|
+import com.fire.dto.MobileFlowDispatchRec;
|
|
|
|
+import com.fire.setcallback.data.DataPool;
|
|
|
|
+import com.fire.setcallback.request.SetCallbackParam;
|
|
|
|
+import com.fire.setcallback.service.SetCallbackService;
|
|
|
|
+import com.fire.supplier.dto.RequestHeader;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import redis.clients.jedis.JedisCluster;
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.Date;
|
|
|
|
+
|
|
|
|
+import static com.fire.dto.enums.RedisKey.CHILD_ORDER_INFO;
|
|
|
|
+import static com.fire.dto.enums.RedisKey.ORDER_INFO;
|
|
|
|
+import static com.fire.dto.enums.OrderStatus.ORDER_FAIL;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 客户查询定单状态
|
|
|
|
+ *
|
|
|
|
+ * @author QGC 2021年6月23日17:13:54
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+@Slf4j
|
|
|
|
+public class SetCallbackServiceImpl implements SetCallbackService {
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private RedisPriorityQueueScript redisPriorityQueueScript;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private JedisCluster jedisCluster;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private SupplierAuth supplierAuth;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String setCallback(SetCallbackParam setCallbackParam) {
|
|
|
|
+ //查询redis 获取数据
|
|
|
|
+ String orderNo = setCallbackParam.getOrderNo();
|
|
|
|
+ long hKey = Long.valueOf(orderNo) / 10000000;
|
|
|
|
+ String childStr = jedisCluster.hget(CHILD_ORDER_INFO.key() + hKey, orderNo);
|
|
|
|
+ ObjectMapper om = new ObjectMapper();
|
|
|
|
+ MobileFlowDispatchRec mobileFlowDispatchRec = null;
|
|
|
|
+ try {
|
|
|
|
+ mobileFlowDispatchRec = om.readValue(childStr, MobileFlowDispatchRec.class);
|
|
|
|
+ Long ChannelId = mobileFlowDispatchRec.getChannelId();
|
|
|
|
+ //查询运营商
|
|
|
|
+ ChannelSupplier channelSupplier = DataPool.supplierHashMap.get(ChannelId);
|
|
|
|
+ String pwd = channelSupplier.getPasswd();
|
|
|
|
+ //校验参数 创建Header
|
|
|
|
+ RequestHeader header = new RequestHeader();
|
|
|
|
+ header.setOrgCode(channelSupplier.getAppKey());
|
|
|
|
+ header.setPartnerId(Long.valueOf(channelSupplier.getAccount()));
|
|
|
|
+ header.setTimestamp(setCallbackParam.getTimestamp());
|
|
|
|
+ header.setSign("MD5");
|
|
|
|
+ String sign = setCallbackParam.getSign();
|
|
|
|
+ String version1Sign = supplierAuth.version1Sign(pwd, header);
|
|
|
|
+ //校验失败
|
|
|
|
+ if (!sign.equals(version1Sign)){
|
|
|
|
+ return "failed";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return "failed";
|
|
|
|
+ }
|
|
|
|
+ //查询订单信息
|
|
|
|
+ Long orderId = mobileFlowDispatchRec.getOrderId();
|
|
|
|
+ hKey = orderId / 10000000;
|
|
|
|
+ String orderStr = jedisCluster.hget(ORDER_INFO.key() + hKey,String.valueOf(orderId));
|
|
|
|
+ ObjectMapper orderOm = new ObjectMapper();
|
|
|
|
+ FlowOrderInfo flowOrderInfo = null;
|
|
|
|
+ try {
|
|
|
|
+ flowOrderInfo = orderOm.readValue(orderStr, FlowOrderInfo.class);
|
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return "failed";
|
|
|
|
+ }
|
|
|
|
+ //状态失败 主订单重入队列 分发订单置状态失败
|
|
|
|
+ if ("FAILED".equals(setCallbackParam.getStatus())){
|
|
|
|
+ mobileFlowDispatchRec.setSendStatus(ORDER_FAIL.status());
|
|
|
|
+ mobileFlowDispatchRec.setCallbackTime(new Date(setCallbackParam.getTimestamp()* 1000L));
|
|
|
|
+ //TODO 其他错误信息置状态
|
|
|
|
+
|
|
|
|
+ //重加入优先级队列 准备重试
|
|
|
|
+ redisPriorityQueueScript.addContent(orderId,orderStr);
|
|
|
|
+ //rides分发订单改状态
|
|
|
|
+ hKey = Long.valueOf(orderNo) / 10000000;
|
|
|
|
+ try {
|
|
|
|
+ childStr = om.writeValueAsString(mobileFlowDispatchRec);
|
|
|
|
+ jedisCluster.hset(CHILD_ORDER_INFO.key() + hKey, orderNo, childStr);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return "failed";
|
|
|
|
+ }
|
|
|
|
+ //rocketMq发送消息
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //状态成功 主订单置成功 分发订单置成功
|
|
|
|
+ }else if("SUCCESS".equals(setCallbackParam.getStatus())){
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+ return "failed";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return "success";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|