|
@@ -2,17 +2,21 @@ package com.fire.dist.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
|
+import com.alibaba.nacos.common.utils.StringUtils;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
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.*;
|
|
import com.fire.dto.*;
|
|
|
|
+import com.fire.dto.enums.DistributePolicy;
|
|
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.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -38,18 +42,18 @@ public class DistOrderServiceImpl implements DistOrderService {
|
|
Long orderId = orderInfo.getOrderId();
|
|
Long orderId = orderInfo.getOrderId();
|
|
if (flowAppInfo == null) {
|
|
if (flowAppInfo == null) {
|
|
log.error("客户信息为空,请检查缓存机制,本次订单号为:" + orderId);
|
|
log.error("客户信息为空,请检查缓存机制,本次订单号为:" + orderId);
|
|
- //todo 入回调队列
|
|
|
|
|
|
+ //todo 入待发送
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
CustomerInfo customerInfo = flowAppInfo.getCustomerInfo();
|
|
CustomerInfo customerInfo = flowAppInfo.getCustomerInfo();
|
|
if (customerInfo == null) {
|
|
if (customerInfo == null) {
|
|
log.error("客户信息为空,请检查缓存机制,本次订单号为:" + orderId);
|
|
log.error("客户信息为空,请检查缓存机制,本次订单号为:" + orderId);
|
|
- //todo 入回调队列
|
|
|
|
|
|
+ //todo 入待发送
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//客户是否暂停
|
|
//客户是否暂停
|
|
if (SUSPEND.status().equals(customerInfo.getStatus())) {
|
|
if (SUSPEND.status().equals(customerInfo.getStatus())) {
|
|
- //todo 放入待发送db
|
|
|
|
|
|
+ //todo 入待发送
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//下单时间
|
|
//下单时间
|
|
@@ -61,7 +65,7 @@ public class DistOrderServiceImpl implements DistOrderService {
|
|
int timeOut = flowAppInfo.getTime() * 1000;
|
|
int timeOut = flowAppInfo.getTime() * 1000;
|
|
long now = System.currentTimeMillis();
|
|
long now = System.currentTimeMillis();
|
|
if (now - applyDate.getTime() > timeOut) {
|
|
if (now - applyDate.getTime() > timeOut) {
|
|
- //todo 超时回调 入回调队列
|
|
|
|
|
|
+ //todo 入回调队列
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//取分发记录
|
|
//取分发记录
|
|
@@ -83,34 +87,67 @@ public class DistOrderServiceImpl implements DistOrderService {
|
|
//找到通道组
|
|
//找到通道组
|
|
ChannelGroup channelGroup = DataPool.channelGroupMap.get(flowAppInfo.getChannelId());
|
|
ChannelGroup channelGroup = DataPool.channelGroupMap.get(flowAppInfo.getChannelId());
|
|
if (channelGroup == null) {
|
|
if (channelGroup == null) {
|
|
- //todo 回调队列 直接失败
|
|
|
|
|
|
+ //todo 入待发送
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//提取通道下面的分发组
|
|
//提取通道下面的分发组
|
|
Map<Integer, List<DistributeGroup>> distributeGroupsMap = channelGroup.getDistributeGroupsMap();
|
|
Map<Integer, List<DistributeGroup>> distributeGroupsMap = channelGroup.getDistributeGroupsMap();
|
|
if (distributeGroupsMap == null) {
|
|
if (distributeGroupsMap == null) {
|
|
- //todo 回调队列 直接失败
|
|
|
|
|
|
+ //todo 入待发送
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//找到对应运营商的分发组列表
|
|
//找到对应运营商的分发组列表
|
|
List<DistributeGroup> distributeGroups = distributeGroupsMap.get(orderInfo.getPhoneOperator());
|
|
List<DistributeGroup> distributeGroups = distributeGroupsMap.get(orderInfo.getPhoneOperator());
|
|
if (CollectionUtils.isEmpty(distributeGroups)) {
|
|
if (CollectionUtils.isEmpty(distributeGroups)) {
|
|
- //todo 回调队列 直接失败
|
|
|
|
|
|
+ //todo 入待发送
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- //分发组已经按权重排序
|
|
|
|
- distributeGroups.forEach(a -> {
|
|
|
|
-
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- //当取不到分发记录时
|
|
|
|
- if (childOrder == null) {
|
|
|
|
- childOrder = new MobileFlowDispatchRec();
|
|
|
|
- childOrder.setRecId(orderId + nowSendCount);
|
|
|
|
-
|
|
|
|
|
|
+ //分发组发送次数 这里当分发组找不到合适的产品时 分发组发送次数才加1
|
|
|
|
+ int batchCount = orderInfo.getBatchCount() == null ? 1 : orderInfo.getBatchCount();
|
|
|
|
+ //对分发次数取模确定选择分发组
|
|
|
|
+ int distributeGroupSize = distributeGroups.size();
|
|
|
|
+ //分发组下标 由分发组发送次数-1 取模
|
|
|
|
+ int distributeIndex = (batchCount - 1) % distributeGroupSize;
|
|
|
|
+ //提取到分发组
|
|
|
|
+ DistributeGroup distributeGroup = distributeGroups.get(distributeIndex);
|
|
|
|
+ List<ChannelInfo> channelInfos = distributeGroup.getChannelInfos();
|
|
|
|
+ if (CollectionUtils.isEmpty(channelInfos)) {
|
|
|
|
+ //todo 入待发送
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
+ //根据分发组策略进行不同的分发操作
|
|
|
|
+ DistributePolicy policy = DistributePolicy.getByCode(distributeGroup.getPolicy());
|
|
|
|
+ //分发记录中存的分发日志
|
|
|
|
+ Map<Integer, Map<Long, Integer>> recordLog = new HashMap<>();
|
|
|
|
+ if (childOrder != null && StringUtils.isEmpty(childOrder.getRecordLog())) {
|
|
|
|
+ try {
|
|
|
|
+ recordLog = om.readValue(childOrder.getRecordLog(), new TypeReference<>() {
|
|
|
|
+ });
|
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
|
+ log.error("分发记录日志转换异常", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ChannelInfo change = null;
|
|
|
|
+ //策略
|
|
|
|
+ switch (policy) {
|
|
|
|
+ case COST_PRIOR -> channelInfos.forEach(a -> {
|
|
|
|
+ //根据产品价格提取通道
|
|
|
|
+ Map<String, Map<Long, ChannelProductInfo>> productListMap = a.getProductListMap();
|
|
|
|
+ if (productListMap != null) {
|
|
|
|
+ //根据区域提取产品
|
|
|
|
+ Map<Long, ChannelProductInfo> longListMap = productListMap.get(orderInfo.getAreaCode());
|
|
|
|
+ if (longListMap != null) {
|
|
|
|
+ ChannelProductInfo productInfo = longListMap.get(orderInfo.getFlowAmount());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ case SPEED_PRIOR -> channelInfos.forEach(a -> {
|
|
|
|
+ a.getChannelId();
|
|
|
|
+ });
|
|
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+}
|