|
@@ -1,19 +1,22 @@
|
|
package com.fire.dist.service.impl;
|
|
package com.fire.dist.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fire.dist.data.DataPool;
|
|
import com.fire.dist.data.DataPool;
|
|
import com.fire.dist.service.DistOrderService;
|
|
import com.fire.dist.service.DistOrderService;
|
|
-import com.fire.dto.CustomerInfo;
|
|
|
|
-import com.fire.dto.FlowAppInfo;
|
|
|
|
-import com.fire.dto.FlowOrderInfo;
|
|
|
|
-import com.fire.dto.MobileFlowDispatchRec;
|
|
|
|
|
|
+import com.fire.dto.*;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import redis.clients.jedis.JedisCluster;
|
|
import redis.clients.jedis.JedisCluster;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
+import static com.fire.dto.enums.RedisKey.CHILD_ORDER_INFO;
|
|
import static com.fire.dto.enums.ValidStatus.SUSPEND;
|
|
import static com.fire.dto.enums.ValidStatus.SUSPEND;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -30,16 +33,18 @@ public class DistOrderServiceImpl implements DistOrderService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void distOrder(FlowOrderInfo orderInfo) {
|
|
public void distOrder(FlowOrderInfo orderInfo) {
|
|
- //appId是否存在
|
|
|
|
|
|
+ //取客户信息,进行分发校验
|
|
FlowAppInfo flowAppInfo = DataPool.flowAppInfoMap.get(orderInfo.getAppId());
|
|
FlowAppInfo flowAppInfo = DataPool.flowAppInfoMap.get(orderInfo.getAppId());
|
|
Long orderId = orderInfo.getOrderId();
|
|
Long orderId = orderInfo.getOrderId();
|
|
if (flowAppInfo == null) {
|
|
if (flowAppInfo == null) {
|
|
log.error("客户信息为空,请检查缓存机制,本次订单号为:" + orderId);
|
|
log.error("客户信息为空,请检查缓存机制,本次订单号为:" + orderId);
|
|
|
|
+ //todo 入回调队列
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
CustomerInfo customerInfo = flowAppInfo.getCustomerInfo();
|
|
CustomerInfo customerInfo = flowAppInfo.getCustomerInfo();
|
|
if (customerInfo == null) {
|
|
if (customerInfo == null) {
|
|
log.error("客户信息为空,请检查缓存机制,本次订单号为:" + orderId);
|
|
log.error("客户信息为空,请检查缓存机制,本次订单号为:" + orderId);
|
|
|
|
+ //todo 入回调队列
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//客户是否暂停
|
|
//客户是否暂停
|
|
@@ -59,14 +64,52 @@ public class DistOrderServiceImpl implements DistOrderService {
|
|
//todo 超时回调 入回调队列
|
|
//todo 超时回调 入回调队列
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- //todo 取分发记录
|
|
|
|
|
|
+ //取分发记录
|
|
Integer sendCount = orderInfo.getSendCount();
|
|
Integer sendCount = orderInfo.getSendCount();
|
|
|
|
+ Integer nowSendCount = sendCount == null ? 1 : sendCount + 1;
|
|
MobileFlowDispatchRec childOrder = null;
|
|
MobileFlowDispatchRec childOrder = null;
|
|
- if(sendCount != null){
|
|
|
|
|
|
+ ObjectMapper om = new ObjectMapper();
|
|
|
|
+ if (sendCount != null) {
|
|
Long childId = orderId + sendCount;
|
|
Long childId = orderId + sendCount;
|
|
|
|
+ String obj = jedisCluster.hget(CHILD_ORDER_INFO.key(), String.valueOf(childId));
|
|
|
|
+ if (obj != null) {
|
|
|
|
+ try {
|
|
|
|
+ childOrder = om.readValue(obj, MobileFlowDispatchRec.class);
|
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
|
+ log.error("提取分发记录失败", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //找到通道组
|
|
|
|
+ ChannelGroup channelGroup = DataPool.channelGroupMap.get(flowAppInfo.getChannelId());
|
|
|
|
+ if (channelGroup == null) {
|
|
|
|
+ //todo 回调队列 直接失败
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //提取通道下面的分发组
|
|
|
|
+ Map<Integer, List<DistributeGroup>> distributeGroupsMap = channelGroup.getDistributeGroupsMap();
|
|
|
|
+ if (distributeGroupsMap == null) {
|
|
|
|
+ //todo 回调队列 直接失败
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //找到对应运营商的分发组列表
|
|
|
|
+ List<DistributeGroup> distributeGroups = distributeGroupsMap.get(orderInfo.getPhoneOperator());
|
|
|
|
+ if (CollectionUtils.isEmpty(distributeGroups)) {
|
|
|
|
+ //todo 回调队列 直接失败
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //分发组已经按权重排序
|
|
|
|
+ distributeGroups.forEach(a -> {
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ //当取不到分发记录时
|
|
|
|
+ if (childOrder == null) {
|
|
|
|
+ childOrder = new MobileFlowDispatchRec();
|
|
|
|
+ childOrder.setRecId(orderId + nowSendCount);
|
|
|
|
|
|
}
|
|
}
|
|
- //
|
|
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|