提交 7c9da8b7 作者: 沈振路

关回多图文替换获客链接

上级 3f0d92ba
...@@ -2,12 +2,15 @@ package com.yaoyaozw.customer.listener; ...@@ -2,12 +2,15 @@ package com.yaoyaozw.customer.listener;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaoyaozw.customer.constants.CustomerMaterialConstant;
import com.yaoyaozw.customer.dto.AcquisitionExceptionHandleParam; import com.yaoyaozw.customer.dto.AcquisitionExceptionHandleParam;
import com.yaoyaozw.customer.dto.WeChatTextDTO; import com.yaoyaozw.customer.dto.WeChatTextDTO;
import com.yaoyaozw.customer.entity.AuthorizerInfo; import com.yaoyaozw.customer.entity.AuthorizerInfo;
import com.yaoyaozw.customer.entity.CustomerFollowReply; import com.yaoyaozw.customer.entity.CustomerFollowReply;
import com.yaoyaozw.customer.entity.CustomerFollowReplyMultiNews;
import com.yaoyaozw.customer.entity.ReferralEntity; import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.event.AcquisitionExceptionEvent; import com.yaoyaozw.customer.event.AcquisitionExceptionEvent;
import com.yaoyaozw.customer.service.CustomerFollowReplyMultiNewsService;
import com.yaoyaozw.customer.service.CustomerFollowReplyService; import com.yaoyaozw.customer.service.CustomerFollowReplyService;
import com.yaoyaozw.customer.service.CustomerFollowReplyService; import com.yaoyaozw.customer.service.CustomerFollowReplyService;
import com.yaoyaozw.customer.service.ReferralEntityService; import com.yaoyaozw.customer.service.ReferralEntityService;
...@@ -31,6 +34,8 @@ public class FollowReplyAcquisitionListener implements ApplicationListener<Acqui ...@@ -31,6 +34,8 @@ public class FollowReplyAcquisitionListener implements ApplicationListener<Acqui
@Resource @Resource
private CustomerFollowReplyService customerFollowReplyService; private CustomerFollowReplyService customerFollowReplyService;
@Resource @Resource
private CustomerFollowReplyMultiNewsService customerFollowReplyMultiNewsService;
@Resource
private ReferralEntityService referralEntityService; private ReferralEntityService referralEntityService;
...@@ -49,18 +54,22 @@ public class FollowReplyAcquisitionListener implements ApplicationListener<Acqui ...@@ -49,18 +54,22 @@ public class FollowReplyAcquisitionListener implements ApplicationListener<Acqui
// 过滤出发送链接是 fromPath 或者发送文本中的跳转链接包含 fromPath 的延时客服配置 // 过滤出发送链接是 fromPath 或者发送文本中的跳转链接包含 fromPath 的延时客服配置
List<CustomerFollowReply> containsFromPathGraphicsList = allCustomerFollowReplyList.stream().filter(v -> (StringUtils.isNotBlank(v.getSourceUrl()) && v.getSourceUrl().contains(fromPath)) || (StringUtils.isNotBlank(v.getContent()) && v.getContent().contains(fromPath))).collect(Collectors.toList()); List<CustomerFollowReply> containsFromPathGraphicsList = allCustomerFollowReplyList.stream().filter(v -> (StringUtils.isNotBlank(v.getSourceUrl()) && v.getSourceUrl().contains(fromPath)) || (StringUtils.isNotBlank(v.getContent()) && v.getContent().contains(fromPath))).collect(Collectors.toList());
if (CollectionUtil.isEmpty(containsFromPathGraphicsList)) { // 多图文
log.info("公众号:{} 暂无使用获客链接:{} 的关回配置", authorizerInfo.getAppid(), fromPath); List<Long> multiNewsReplyIds = allCustomerFollowReplyList.stream().filter(v -> CustomerMaterialConstant.TENCENT_MEDIA_TYPE_MULTI_NEWS.equals(v.getType())).map(CustomerFollowReply::getId).collect(Collectors.toList());
return; List<CustomerFollowReplyMultiNews> customerFollowReplyMultiNewsList = new ArrayList<>();
if (CollectionUtil.isNotEmpty(multiNewsReplyIds)) {
customerFollowReplyMultiNewsList = customerFollowReplyMultiNewsService.list(new QueryWrapper<CustomerFollowReplyMultiNews>().in("reply_id", multiNewsReplyIds));
} }
List<Long> graphicsIds = containsFromPathGraphicsList.stream().map(CustomerFollowReply::getId).collect(Collectors.toList());
List<ReferralEntity> relatedReferralEntityList = referralEntityService.list(new QueryWrapper<ReferralEntity>().in(ReferralEntity.COL_MATERIAL_GRAPHICS_ID, graphicsIds));
List<CustomerFollowReply> updateGraphicsList = new ArrayList<>();
List<ReferralEntity> updateReferralList = new ArrayList<>();
// 查询链接配置
List<Long> graphicsIds = containsFromPathGraphicsList.stream().map(CustomerFollowReply::getId).collect(Collectors.toList());
customerFollowReplyMultiNewsList.forEach(v -> graphicsIds.add(v.getId()));
List<ReferralEntity> relatedReferralEntityList = new ArrayList<>();
if (CollectionUtil.isNotEmpty(graphicsIds)) {
relatedReferralEntityList = referralEntityService.list(new QueryWrapper<ReferralEntity>().in(ReferralEntity.COL_MATERIAL_GRAPHICS_ID, graphicsIds));
}
// 替换 graphics 和 referral 中的 fromPath 为 toPath // 替换 graphics 和 referral 中的 fromPath 为 toPath
allCustomerFollowReplyList.forEach(item -> { List<CustomerFollowReply> updateGraphicsList = allCustomerFollowReplyList.stream().filter(item -> {
boolean update = false; boolean update = false;
// 直跳链接 // 直跳链接
if (StringUtils.isNotBlank(item.getSourceUrl()) && item.getSourceUrl().contains(fromPath)) { if (StringUtils.isNotBlank(item.getSourceUrl()) && item.getSourceUrl().contains(fromPath)) {
...@@ -72,11 +81,19 @@ public class FollowReplyAcquisitionListener implements ApplicationListener<Acqui ...@@ -72,11 +81,19 @@ public class FollowReplyAcquisitionListener implements ApplicationListener<Acqui
item.setContent(item.getContent().replaceAll(fromPath, toPath)); item.setContent(item.getContent().replaceAll(fromPath, toPath));
update = true; update = true;
} }
if (update) { return update;
updateGraphicsList.add(item); }).collect(Collectors.toList());
List<CustomerFollowReplyMultiNews> updateMultiNewsList = customerFollowReplyMultiNewsList.stream().filter(item -> {
boolean update = false;
if (StringUtils.isNotBlank(item.getLinkUrl()) && item.getLinkUrl().contains(fromPath)) {
item.setLinkUrl(item.getLinkUrl().replaceAll(fromPath, toPath));
update = true;
} }
}); return update;
relatedReferralEntityList.forEach(item -> { }).collect(Collectors.toList());
List<ReferralEntity> updateReferralList = relatedReferralEntityList.stream().filter(item -> {
boolean update = false; boolean update = false;
// 直跳链接 // 直跳链接
if (StringUtils.isNotBlank(item.getReferral()) && item.getReferral().contains(fromPath)) { if (StringUtils.isNotBlank(item.getReferral()) && item.getReferral().contains(fromPath)) {
...@@ -88,28 +105,35 @@ public class FollowReplyAcquisitionListener implements ApplicationListener<Acqui ...@@ -88,28 +105,35 @@ public class FollowReplyAcquisitionListener implements ApplicationListener<Acqui
item.setTextContent(item.getTextContent().replaceAll(fromPath, toPath)); item.setTextContent(item.getTextContent().replaceAll(fromPath, toPath));
update = true; update = true;
} }
if (update) { return update;
updateReferralList.add(item); }).collect(Collectors.toList());
}
}); // 执行更新
boolean update = false; boolean update = false;
if (CollectionUtil.isNotEmpty(updateGraphicsList)) { if (CollectionUtil.isNotEmpty(updateGraphicsList)) {
// 更新主配置
customerFollowReplyService.updateBatchById(updateGraphicsList); customerFollowReplyService.updateBatchById(updateGraphicsList);
update = true; update = true;
customerFollowReplyService.putMaterialToRedis(authorizerInfo.getAppid(), null);
}
if (CollectionUtil.isNotEmpty(updateMultiNewsList)) {
// 更新多图文配置
customerFollowReplyMultiNewsService.updateBatchById(updateMultiNewsList);
update = true;
customerFollowReplyMultiNewsService.putMaterialToRedis(authorizerInfo.getAppid(), customerFollowReplyMultiNewsList);
} }
if (CollectionUtil.isNotEmpty(updateReferralList)) { if (CollectionUtil.isNotEmpty(updateReferralList)) {
// 更新链接配置
referralEntityService.updateBatchById(updateReferralList); referralEntityService.updateBatchById(updateReferralList);
update = true; update = true;
} }
// 刷新缓存数据
customerFollowReplyService.putMaterialToRedis(authorizerInfo.getAppid(), null);
if (update) { if (update) {
// 发送报警信息 // 发送报警信息
String msg = "【关回-获客链接替换】公众号:" + authorizerInfo.getNickName() + " 获客链接:" + fromPath + " 已被替换为:" + toPath; String msg = "【关回-获客链接替换】公众号:" + authorizerInfo.getNickName() + " 获客链接:" + fromPath + " 已被替换为:" + toPath;
WeChatTextDTO cover = new WeChatTextDTO().cover(msg, null, null); WeChatTextDTO cover = new WeChatTextDTO().cover(msg, null, null);
WeChatUtils.sendErrorMessage(cover, "9934244e-9694-4a0c-95dd-ddd6ca4bd959"); WeChatUtils.sendErrorMessage(cover, "9934244e-9694-4a0c-95dd-ddd6ca4bd959");
} else {
log.info("公众号:{} 暂无使用获客链接:{} 的关回配置", authorizerInfo.getAppid(), fromPath);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("公众号:{} 关回链接从:{} 替换为:{} 异常:{}", source.getAuthorizerInfo().getNickName(), source.getFromPath(), source.getToPath(), e.getMessage(), e); log.error("公众号:{} 关回链接从:{} 替换为:{} 异常:{}", source.getAuthorizerInfo().getNickName(), source.getFromPath(), source.getToPath(), e.getMessage(), e);
......
...@@ -21,4 +21,6 @@ public interface CustomerFollowReplyMultiNewsService extends IService<CustomerFo ...@@ -21,4 +21,6 @@ public interface CustomerFollowReplyMultiNewsService extends IService<CustomerFo
*/ */
void saveFollowReplyMultiNews(Long replyId, AuthInfoVO accountEntity, List<FollowReplyMultiNewsCreateDTO> multiNewsList); void saveFollowReplyMultiNews(Long replyId, AuthInfoVO accountEntity, List<FollowReplyMultiNewsCreateDTO> multiNewsList);
void putMaterialToRedis(String appId, List<? extends CustomerFollowReplyMultiNews> entityList);
} }
...@@ -11,7 +11,6 @@ import com.yaoyaozw.customer.constants.CustomerMaterialConstant; ...@@ -11,7 +11,6 @@ import com.yaoyaozw.customer.constants.CustomerMaterialConstant;
import com.yaoyaozw.customer.dto.follow.FollowReplyMultiNewsCreateDTO; import com.yaoyaozw.customer.dto.follow.FollowReplyMultiNewsCreateDTO;
import com.yaoyaozw.customer.dto.follow.NewsMessageReplyEntity; import com.yaoyaozw.customer.dto.follow.NewsMessageReplyEntity;
import com.yaoyaozw.customer.entity.CommonReferralBody; import com.yaoyaozw.customer.entity.CommonReferralBody;
import com.yaoyaozw.customer.entity.CustomerFollowReply;
import com.yaoyaozw.customer.entity.CustomerFollowReplyMultiNews; import com.yaoyaozw.customer.entity.CustomerFollowReplyMultiNews;
import com.yaoyaozw.customer.entity.ReferralEntity; import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.mapper.CustomerFollowReplyMultiNewsMapper; import com.yaoyaozw.customer.mapper.CustomerFollowReplyMultiNewsMapper;
...@@ -88,10 +87,15 @@ public class CustomerFollowReplyMultiNewsServiceImpl extends ServiceImpl<Custome ...@@ -88,10 +87,15 @@ public class CustomerFollowReplyMultiNewsServiceImpl extends ServiceImpl<Custome
referralEntityList.add(referralEntity); referralEntityList.add(referralEntity);
} }
localLog.info("generate multi news size {}, referral entity size {}", entityList.size(), referralEntityList.size()); localLog.info("generate multi news size {}, referral entity size {}", entityList.size(), referralEntityList.size());
// 将这些多图文信息转换到缓存 putMaterialToRedis(accountEntity.getAppId(), multiNewsList);
List<NewsMessageReplyEntity> cacheEntityList = JSONUtil.toList(JSONUtil.parseArray(multiNewsList), NewsMessageReplyEntity.class);
redisTemplate.opsForHash().put(CustomerMaterialConstant.FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY, accountEntity.getAppId(), JSONUtil.toJsonStr(cacheEntityList));
this.saveBatch(entityList); this.saveBatch(entityList);
referralEntityService.saveBatch(referralEntityList); referralEntityService.saveBatch(referralEntityList);
} }
@Override
public void putMaterialToRedis(String appId, List<? extends CustomerFollowReplyMultiNews> entityList) {
// 将这些多图文信息转换到缓存
List<NewsMessageReplyEntity> cacheEntityList = JSONUtil.toList(JSONUtil.parseArray(entityList), NewsMessageReplyEntity.class);
redisTemplate.opsForHash().put(CustomerMaterialConstant.FOLLOW_REPLY_MULTI_NEWS_CACHE_KEY, appId, JSONUtil.toJsonStr(cacheEntityList));
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论