提交 07770a53 作者: 沈振路

关回、关键词 替换获客链接监听器【未测试】

上级 cf0a3f4c
package com.yaoyaozw.customer.listener;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaoyaozw.customer.dto.AcquisitionExceptionHandleParam;
import com.yaoyaozw.customer.entity.AuthorizerInfo;
import com.yaoyaozw.customer.entity.CustomerFollowReply;
import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.event.AcquisitionExceptionEvent;
import com.yaoyaozw.customer.service.CustomerFollowReplyService;
import com.yaoyaozw.customer.service.CustomerFollowReplyService;
import com.yaoyaozw.customer.service.ReferralEntityService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Component
public class FollowReplyAcquisitionListener implements ApplicationListener<AcquisitionExceptionEvent> {
@Resource
private CustomerFollowReplyService customerFollowReplyService;
@Resource
private ReferralEntityService referralEntityService;
@Override
public void onApplicationEvent(AcquisitionExceptionEvent acquisitionExceptionEvent) {
AcquisitionExceptionHandleParam source = acquisitionExceptionEvent.getSource();
if (source == null) {
return;
}
AuthorizerInfo authorizerInfo = source.getAuthorizerInfo();
String fromPath = source.getFromPath();
String toPath = source.getToPath();
// 查询这个公众号延时客服用到了 fromPath 的地方,替换成 toPath
List<CustomerFollowReply> allCustomerFollowReplyList = customerFollowReplyService.list(new QueryWrapper<CustomerFollowReply>().eq("app_id", authorizerInfo.getAppid()));
// 过滤出发送链接是 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());
if (CollectionUtil.isEmpty(containsFromPathGraphicsList)) {
return;
}
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<>();
// 替换 graphics 和 referral 中的 fromPath 为 toPath
allCustomerFollowReplyList.forEach(item -> {
boolean update = false;
// 直跳链接
if (StringUtils.isNotBlank(item.getSourceUrl()) && item.getSourceUrl().contains(fromPath)) {
item.setSourceUrl(item.getSourceUrl().replaceAll(fromPath, toPath));
update = true;
}
// 文本链接
if (StringUtils.isNotBlank(item.getContent()) && item.getContent().contains(fromPath)) {
item.setContent(item.getContent().replaceAll(fromPath, toPath));
update = true;
}
if (update) {
updateGraphicsList.add(item);
}
});
relatedReferralEntityList.forEach(item -> {
boolean update = false;
// 直跳链接
if (StringUtils.isNotBlank(item.getReferral()) && item.getReferral().contains(fromPath)) {
item.setReferral(item.getReferral().replaceAll(fromPath, toPath));
update = true;
}
// 文本链接
if (StringUtils.isNotBlank(item.getTextContent()) && item.getTextContent().contains(fromPath)) {
item.setTextContent(item.getTextContent().replaceAll(fromPath, toPath));
update = true;
}
if (update) {
updateReferralList.add(item);
}
});
if (CollectionUtil.isNotEmpty(updateGraphicsList)) {
customerFollowReplyService.updateBatchById(updateGraphicsList);
}
if (CollectionUtil.isNotEmpty(updateReferralList)) {
referralEntityService.updateBatchById(updateReferralList);
}
// 刷新缓存数据
customerFollowReplyService.putMaterialToRedis(authorizerInfo.getAppid(), null);
}
}
package com.yaoyaozw.customer.listener;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaoyaozw.customer.dto.AcquisitionExceptionHandleParam;
import com.yaoyaozw.customer.entity.AuthorizerInfo;
import com.yaoyaozw.customer.entity.CustomerGraphicsDelay;
import com.yaoyaozw.customer.entity.CustomerKeyword;
import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.event.AcquisitionExceptionEvent;
import com.yaoyaozw.customer.service.CustomerKeywordService;
import com.yaoyaozw.customer.service.ReferralEntityService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Component
public class KeywordAcquisitionListener implements ApplicationListener<AcquisitionExceptionEvent> {
@Resource
private CustomerKeywordService customerKeywordService;
@Resource
private ReferralEntityService referralEntityService;
@Override
public void onApplicationEvent(AcquisitionExceptionEvent acquisitionExceptionEvent) {
AcquisitionExceptionHandleParam source = acquisitionExceptionEvent.getSource();
if (source == null) {
return;
}
AuthorizerInfo authorizerInfo = source.getAuthorizerInfo();
String fromPath = source.getFromPath();
String toPath = source.getToPath();
// 查询这个公众号延时客服用到了 fromPath 的地方,替换成 toPath
List<CustomerKeyword> allCustomerKeywordList = customerKeywordService.list(new QueryWrapper<CustomerKeyword>().eq("app_id", authorizerInfo.getAppid()));
// 过滤出发送链接是 fromPath 或者发送文本中的跳转链接包含 fromPath 的延时客服配置
List<CustomerKeyword> containsFromPathGraphicsList = allCustomerKeywordList.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)) {
return;
}
List<Long> graphicsIds = containsFromPathGraphicsList.stream().map(CustomerKeyword::getId).collect(Collectors.toList());
List<ReferralEntity> relatedReferralEntityList = referralEntityService.list(new QueryWrapper<ReferralEntity>().in(ReferralEntity.COL_MATERIAL_GRAPHICS_ID, graphicsIds));
List<CustomerKeyword> updateGraphicsList = new ArrayList<>();
List<ReferralEntity> updateReferralList = new ArrayList<>();
// 替换 graphics 和 referral 中的 fromPath 为 toPath
allCustomerKeywordList.forEach(item -> {
boolean update = false;
// 直跳链接
if (StringUtils.isNotBlank(item.getSourceUrl()) && item.getSourceUrl().contains(fromPath)) {
item.setSourceUrl(item.getSourceUrl().replaceAll(fromPath, toPath));
update = true;
}
// 文本链接
if (StringUtils.isNotBlank(item.getContent()) && item.getContent().contains(fromPath)) {
item.setContent(item.getContent().replaceAll(fromPath, toPath));
update = true;
}
if (update) {
updateGraphicsList.add(item);
}
});
relatedReferralEntityList.forEach(item -> {
boolean update = false;
// 直跳链接
if (StringUtils.isNotBlank(item.getReferral()) && item.getReferral().contains(fromPath)) {
item.setReferral(item.getReferral().replaceAll(fromPath, toPath));
update = true;
}
// 文本链接
if (StringUtils.isNotBlank(item.getTextContent()) && item.getTextContent().contains(fromPath)) {
item.setTextContent(item.getTextContent().replaceAll(fromPath, toPath));
update = true;
}
if (update) {
updateReferralList.add(item);
}
});
if (CollectionUtil.isNotEmpty(updateGraphicsList)) {
customerKeywordService.updateBatchById(updateGraphicsList);
}
if (CollectionUtil.isNotEmpty(updateReferralList)) {
referralEntityService.updateBatchById(updateReferralList);
}
// 刷新缓存数据
customerKeywordService.putMaterialToRedis(authorizerInfo.getAppid());
}
}
......@@ -74,4 +74,6 @@ public interface CustomerFollowReplyService extends IService<CustomerFollowReply
* @return {@link GenericsResult}<{@link FollowReplyInfoVO}>
*/
GenericsResult<FollowReplyInfoVO> getInfo(Long id);
void putMaterialToRedis(String appid, List<CustomerFollowReply> entityList);
}
......@@ -7,6 +7,7 @@ import com.yaoyaozw.customer.dto.keyword.CustomerKeywordCopyDTO;
import com.yaoyaozw.customer.dto.keyword.CustomerKeywordQueryDTO;
import com.yaoyaozw.customer.dto.keyword.CustomerKeywordSaveDTO;
import com.yaoyaozw.customer.entity.CommonReferralBody;
import com.yaoyaozw.customer.entity.CustomerFollowReply;
import com.yaoyaozw.customer.entity.CustomerKeyword;
import com.yaoyaozw.customer.vo.keyword.CustomerKeywordInfoVO;
import com.yaoyaozw.customer.vo.keyword.CustomerKeywordListVO;
......@@ -73,4 +74,7 @@ public interface CustomerKeywordService extends IService<CustomerKeyword> {
* @return {@link BaseResult}
*/
BaseResult copy(CustomerKeywordCopyDTO copyDto);
void putMaterialToRedis(String appid);
}
......@@ -425,7 +425,8 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
return null;
}
private void putMaterialToRedis(String appid, List<CustomerFollowReply> entityList) {
@Override
public void putMaterialToRedis(String appid, List<CustomerFollowReply> entityList) {
if (StringUtils.isNotEmpty(appid) && CollectionUtil.isEmpty(entityList)) {
// 传参没传实体, 现查
entityList = this.list(new QueryWrapper<CustomerFollowReply>().eq("appid", appid));
......
......@@ -382,7 +382,8 @@ public class CustomerKeywordServiceImpl extends ServiceImpl<CustomerKeywordMappe
return null;
}
private void putMaterialToRedis(String appid) {
@Override
public void putMaterialToRedis(String appid) {
if (StringUtils.isNotEmpty(appid)) {
// 传参没传实体, 现查
List<CustomerKeyword> entityList = this.list(new QueryWrapper<CustomerKeyword>().eq("appid", appid));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论