提交 a9342289 作者: 沈振路

客服消息适配“获客链接”newsType类型

上级 8eac6ad5
......@@ -2,14 +2,12 @@ package com.yaoyaozw.customer.components;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.yaoyaozw.customer.common.R;
import com.yaoyaozw.customer.constants.ApiResultConstant;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
......@@ -20,7 +18,6 @@ import com.yaoyaozw.customer.feigns.ReferralFeignClient;
import com.yaoyaozw.customer.mapper.CustomerGraphicsDelayMapper;
import com.yaoyaozw.customer.mapper.CustomerGraphicsMapper;
import com.yaoyaozw.customer.mapper.KanbanCommonMapper;
import com.yaoyaozw.customer.mapper.MaterialCommonMapper;
import com.yaoyaozw.customer.service.*;
import com.yaoyaozw.customer.vo.AuthInfoVO;
import com.yaoyaozw.customer.vo.kanban.CommonOptionResponseVO;
......@@ -28,10 +25,8 @@ import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
......@@ -39,7 +34,6 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
......@@ -159,8 +153,8 @@ public class CustomerServiceCommonAsyncComponent {
for (ReferralEntity referralEntity : referralEntityList) {
// 获取链接
if (CustomerCommonConstant.REMOTE_LINK_NEWS_TYPE_LIST.contains(referralEntity.getNewsType())) {
LOCAL_LOG.info("异步获取图文客服链接");
if (CustomerCommonConstant.REMOTE_LINK_NEWS_TYPE_LIST.contains(referralEntity.getNewsType()) ||
CustomerCommonConstant.ACQUISITION_LINK_NEWS_TYPE.equals(referralEntity.getNewsType())) {
getMessageAuthListLink(storeGroupMap, customerGraphics, referralEntity);
} else {
LOCAL_LOG.info("newsType: {}, 不需要获取链接", referralEntity.getNewsType());
......@@ -236,6 +230,9 @@ public class CustomerServiceCommonAsyncComponent {
} else if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(newsType)) {
// 常用链接
generateMessageUsualLink(storeGroupMap, customerReferral);
} else if (CustomerCommonConstant.ACQUISITION_LINK_NEWS_TYPE.equals(newsType)) {
// 获客链接
generateMessageAcquisitionLink(storeGroupMap, customerReferral);
}
}
......@@ -389,6 +386,90 @@ public class CustomerServiceCommonAsyncComponent {
});
}
private void generateMessageAcquisitionLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) {
LOCAL_LOG.info("开始处理获客链接");
Map<String, String> storeEntityMap = getStoreEntityMap(storeGroupMap.keySet());
// 缓存公众号appId对应的获客链接,避免重复查询数据库
Map<String, String> appIdAcquisitionLinkMap = new HashMap<>();
storeGroupMap.forEach((storeType, userVoList) -> {
LOCAL_LOG.info("当前处理书城: {}", storeType);
// 去重提取公众号
Set<String> accountSet = userVoList.stream().map(CrowdPackageUserVO::getAccountId).collect(Collectors.toSet());
List<AuthInfoVO> authInfoList = customerServiceCommonService.getAuthInfoList(accountSet);
// 定义
List<ReferralEntity> referralEntityList = new ArrayList<>(accountSet.size());
for (AuthInfoVO authInfoVo : authInfoList) {
ReferralEntity referralEntity = new ReferralEntity();
BeanUtil.copyProperties(customerReferral, referralEntity);
// 重新生成链接主键id
referralEntity.setId(snowflakeComponent.snowflakeId());
referralEntity.setAccountId(authInfoVo.getAccountId());
referralEntity.setStoreTypeName(storeEntityMap.get(storeType));
try {
// 获取获客链接
String acquisitionLink = getAcquisitionLinkFromCache(authInfoVo.getAppId(), appIdAcquisitionLinkMap);
if (StringUtils.isNotBlank(acquisitionLink)) {
referralEntity.setReferral(acquisitionLink);
LOCAL_LOG.info("公众号: {} 获取到获客链接: {}", authInfoVo.getAccountName(), acquisitionLink);
} else {
LOCAL_LOG.warn("公众号: {} 未找到可用的获客链接,设置为error", authInfoVo.getAccountName());
referralEntity.setReferral(CustomerCommonConstant.ERROR_LABEL);
}
} catch (Exception e) {
LOCAL_LOG.warn("公众号: {} 获取获客链接异常: {}", authInfoVo.getAccountName(), e.getMessage());
referralEntity.setReferral(CustomerCommonConstant.ERROR_LABEL);
}
referralEntityList.add(referralEntity);
}
// 批量新增
LOCAL_LOG.info("保存书城: {} 的获客链接实体, 数量:{}条", storeType, referralEntityList.size());
referralEntityService.saveBatch(referralEntityList);
});
}
/**
* 从缓存中获取获客链接,避免重复查询数据库
* @param appId 公众号appId
* @param appIdAcquisitionLinkMap 缓存Map
* @return 获客链接,如果没有则返回null
*/
private String getAcquisitionLinkFromCache(String appId, Map<String, String> appIdAcquisitionLinkMap) {
// 先从缓存中查找
if (appIdAcquisitionLinkMap.containsKey(appId)) {
return appIdAcquisitionLinkMap.get(appId);
}
// 缓存中没有,查询数据库
try {
List<String> acquisitionLinkList = companyAcquisitionLinkService.getAcquisitionLinksByAppId(appId, "OPERATE");
String acquisitionLink = null;
if (CollectionUtil.isNotEmpty(acquisitionLinkList)) {
// 取第一个可用的获客链接
acquisitionLink = acquisitionLinkList.get(0);
LOCAL_LOG.info("公众号: {} 查询到 {} 个可用获客链接,使用第一个: {}", appId, acquisitionLinkList.size(), acquisitionLink);
} else {
LOCAL_LOG.warn("公众号: {} 没有找到可用的获客链接", appId);
}
// 存入缓存(包括null值,避免重复查询)
appIdAcquisitionLinkMap.put(appId, acquisitionLink);
return acquisitionLink;
} catch (Exception e) {
LOCAL_LOG.error("查询公众号: {} 的获客链接时发生异常: {}", appId, e.getMessage(), e);
// 异常情况也存入缓存,避免重复查询
appIdAcquisitionLinkMap.put(appId, null);
return null;
}
}
/**
* 以下是延时客服 的方法
*/
......
......@@ -32,6 +32,7 @@ public class CustomerCommonConstant {
public final static List<Integer> REMOTE_LINK_NEWS_TYPE_LIST = Arrays.asList(1, 2, 3);
public final static List<Integer> COMMON_NEWS_TYPE_LIST = Collections.singletonList(4);
public final static Integer ACQUISITION_LINK_NEWS_TYPE = -2;
public final static String YW_LINK_LIMIT_REDIS_KEY = "YW_REFERRAL";
public final static String YANG_GUANG_ACCESS_LIMIT_REDIS_KEY = "YG_ACCESS_LIMIT_NUM";
......
......@@ -123,7 +123,8 @@ public class CustomerGraphicsTextServiceImpl extends ServiceImpl<CustomerGraphic
context = CustomerCommonConstant.CUSTOMER_TEXT_LINK_TEMPLATE
.replace(CustomerCommonConstant.CUSTOMER_TEXT_CONTENT_PLACEHOLDER, item.getTextContent())
.replace(CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER, CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER + idx);
} else if (CustomerCommonConstant.COMMON_NEWS_TYPE_LIST.contains(item.getNewsType())){
} else if (CustomerCommonConstant.COMMON_NEWS_TYPE_LIST.contains(item.getNewsType()) || CustomerCommonConstant.ACQUISITION_LINK_NEWS_TYPE.equals(item.getNewsType())){
// 纯文本或者获客链接
context = item.getTextContent();
}
if (ObjectUtil.isNotNull(context)) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论