提交 42445d1d 作者: 沈振路

延时客服

上级 b79b3207
......@@ -3,6 +3,7 @@ package com.yaoyaozw.customer.common;
import cn.hutool.core.util.ObjectUtil;
import com.yaoyaozw.customer.constants.ApiResultConstant;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
/**
* @author darker
......@@ -37,6 +38,14 @@ public class BaseResult {
}
return this;
}
public BaseResult success(String message) {
this.success = Boolean.TRUE;
this.code = ApiResultConstant.SUCCESS_CODE;
if (ObjectUtil.isNull(this.message)) {
this.message = StringUtils.isBlank(message) ? ApiResultConstant.SUCCESS_MSG : message;
}
return this;
}
/**
* 错误
......
......@@ -13,10 +13,7 @@ import com.yaoyaozw.customer.constants.ApiResultConstant;
import com.yaoyaozw.customer.constants.CrowdPackageCommonConstant;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.dto.customer.CustomerMessageSaveDTO;
import com.yaoyaozw.customer.entity.CustomerGraphics;
import com.yaoyaozw.customer.entity.CustomerGraphicsDelay;
import com.yaoyaozw.customer.entity.ReferralEntity;
import com.yaoyaozw.customer.entity.RegisterUserEntity;
import com.yaoyaozw.customer.entity.*;
import com.yaoyaozw.customer.enums.CustomerStoreTemplateEnum;
import com.yaoyaozw.customer.feigns.ReferralFeignClient;
import com.yaoyaozw.customer.mapper.CustomerGraphicsDelayMapper;
......@@ -24,6 +21,7 @@ import com.yaoyaozw.customer.mapper.CustomerGraphicsMapper;
import com.yaoyaozw.customer.mapper.KanbanCommonMapper;
import com.yaoyaozw.customer.mapper.MaterialCommonMapper;
import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService;
import com.yaoyaozw.customer.service.CustomerGraphicsDelayService;
import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.service.RegisterUserEntityService;
import com.yaoyaozw.customer.vo.AuthInfoVO;
......@@ -71,9 +69,11 @@ public class CustomerServiceCommonAsyncComponent {
private CustomerGraphicsMapper customerGraphicsMapper;
@Autowired
private KanbanCommonMapper kanbanCommonMapper;
@Autowired
private CustomerGraphicsDelayMapper customerGraphicsDelayMapper;
private CustomerGraphicsDelayService graphicsDelayService;
public void setGraphicsDelayService(CustomerGraphicsDelayService graphicsDelayService) {
this.graphicsDelayService = graphicsDelayService;
}
@Async("myExecutor")
public void addMatchUserIntoPackage(Long packageId, Boolean needRemove) {
......@@ -164,20 +164,25 @@ public class CustomerServiceCommonAsyncComponent {
}
@Async("myExecutor")
public void obtainDelayLink(Long materialId, CustomerGraphicsDelay customerGraphicsDelay, List<ReferralEntity> referralEntityList) {
public void obtainDelayGraphicsLink(List<CustomerGraphicsDelay> sourceCustomerList, AuthorizerInfo targetAuthInfo) {
String accountName = targetAuthInfo.getNickName();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
String dateStr = dateFormat.format(new Date());
LOCAL_LOG.info("延时客服复用--公众号【{}】, 要复制客服数量: {} 条", accountName, sourceCustomerList.size());
// 遍历客服素材进行处理
for (CustomerGraphicsDelay sourceGraphics : sourceCustomerList) {
generateDelayExtendLink(dateStr, sourceGraphics, targetAuthInfo);
}
}
/**
* 以下是客服消息模块的私有方法
*/
private void getMessageAuthListLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, CustomerGraphics customerMain, ReferralEntity customerReferral) {
Long packId = customerMain.getPackId();
LOCAL_LOG.info("开始异步处理客服链接, 客服标题: {}, 人群包主键: {}", customerMain.getName(), packId);
......@@ -187,18 +192,18 @@ public class CustomerServiceCommonAsyncComponent {
// 一个书城一个书城地处理
if (newsType.equals(CustomerCommonConstant.BOOK_NEWS_TYPE)) {
// 是推广链接
generateExtendLink(storeGroupMap, customerReferral);
generateMessageExtendLink(storeGroupMap, customerReferral);
} else if (CustomerCommonConstant.ACTIVITY_NEWS_TYPE.equals(newsType)) {
// 是活动链接
generateActivityLink(storeGroupMap, customerReferral);
generateMessageActivityLink(storeGroupMap, customerReferral);
} else if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(newsType)) {
// 常用链接
generateUsualLink(storeGroupMap, customerReferral);
generateMessageUsualLink(storeGroupMap, customerReferral);
}
}
private void generateExtendLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) {
private void generateMessageExtendLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
String dateStr = dateFormat.format(new Date());
......@@ -233,7 +238,7 @@ public class CustomerServiceCommonAsyncComponent {
});
}
private void generateActivityLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) {
private void generateMessageActivityLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
String dateStr = dateFormat.format(new Date());
......@@ -304,7 +309,7 @@ public class CustomerServiceCommonAsyncComponent {
});
}
private void generateUsualLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) {
private void generateMessageUsualLink(Map<String, List<CrowdPackageUserVO>> storeGroupMap, ReferralEntity customerReferral) {
Map<String, String> storeEntityMap = getStoreEntityMap(storeGroupMap.keySet());
storeGroupMap.forEach((storeType, userVoList) -> {
......@@ -334,6 +339,97 @@ public class CustomerServiceCommonAsyncComponent {
});
}
/**
* 以下是延时客服 的方法
*/
private void generateDelayExtendLink(String dateStr, CustomerGraphicsDelay sourceGraphics, AuthorizerInfo targetAuthInfo) {
List<ReferralEntity> targetReferralEntityList = new ArrayList<>();
// 新建新主体
CustomerGraphicsDelay targetCustomerGraphics = new CustomerGraphicsDelay();
long mainId = snowflakeComponent.snowflakeId();
targetCustomerGraphics.setId(mainId);
// 遍历链接数据进行处理
List<ReferralEntity> sourceReferralList = sourceGraphics.getBelongReferralList();
for (ReferralEntity sourceReferralEntity : sourceReferralList) {
ReferralEntity targetReferralEntity = new ReferralEntity();
BeanUtil.copyProperties(sourceReferralEntity, targetReferralEntity);
// 重新生成链接主键id
targetReferralEntity.setId(snowflakeComponent.snowflakeId());
targetReferralEntity.setMaterialGraphicsId(mainId);
targetReferralEntity.setAccountId(targetAuthInfo.getAccountId());
targetReferralEntity.setStoreTypeName(targetAuthInfo.getStoreTypeName());
try {
// 获取链接
AuthInfoVO authInfoVo = new AuthInfoVO();
authInfoVo.putPropertyValue(targetAuthInfo);
getCopyReferral(dateStr, authInfoVo, targetReferralEntity);
targetCustomerGraphics.setSourceUrl(targetReferralEntity.getReferral());
} catch (Exception e) {
LOCAL_LOG.warn("公众号: {} 获取链接异常: {}", targetAuthInfo.getNickName(), e.getMessage());
}
targetReferralEntityList.add(targetReferralEntity);
}
targetCustomerGraphics.setSendStatus(CustomerCommonConstant.SEND_STATUS_LINK_FINISH);
LOCAL_LOG.info("保存主体数据, 主体id: {}", mainId);
graphicsDelayService.save(targetCustomerGraphics);
LOCAL_LOG.info("准备保存, 共生成链接数据 : {} 条", targetReferralEntityList.size());
referralEntityService.saveBatch(targetReferralEntityList);
}
private void generateDelayActivityLink(String dateStr, CustomerGraphicsDelay sourceGraphics, AuthorizerInfo targetAuthInfo) {
List<ReferralEntity> targetReferralEntityList = new ArrayList<>();
// 新建新主体
CustomerGraphicsDelay targetCustomerGraphics = new CustomerGraphicsDelay();
long mainId = snowflakeComponent.snowflakeId();
targetCustomerGraphics.setId(mainId);
// 遍历链接数据进行处理
List<ReferralEntity> sourceReferralList = sourceGraphics.getBelongReferralList();
for (ReferralEntity sourceReferralEntity : sourceReferralList) {
ReferralEntity targetReferralEntity = new ReferralEntity();
BeanUtil.copyProperties(sourceReferralEntity, targetReferralEntity);
// 重新生成链接主键id
targetReferralEntity.setId(snowflakeComponent.snowflakeId());
targetReferralEntity.setMaterialGraphicsId(mainId);
targetReferralEntity.setAccountId(targetAuthInfo.getAccountId());
targetReferralEntity.setStoreTypeName(targetAuthInfo.getStoreTypeName());
try {
// 获取链接
AuthInfoVO authInfoVo = new AuthInfoVO();
authInfoVo.putPropertyValue(targetAuthInfo);
getCopyReferral(dateStr, authInfoVo, targetReferralEntity);
targetCustomerGraphics.setSourceUrl(targetReferralEntity.getReferral());
} catch (Exception e) {
LOCAL_LOG.warn("公众号: {} 获取链接异常: {}", targetAuthInfo.getNickName(), e.getMessage());
}
targetReferralEntityList.add(targetReferralEntity);
}
targetCustomerGraphics.setSendStatus(CustomerCommonConstant.SEND_STATUS_LINK_FINISH);
LOCAL_LOG.info("保存主体数据, 主体id: {}", mainId);
graphicsDelayService.save(targetCustomerGraphics);
LOCAL_LOG.info("准备保存, 共生成链接数据 : {} 条", targetReferralEntityList.size());
referralEntityService.saveBatch(targetReferralEntityList);
}
private void generateDelayUsualLink() {
}
/**
* 以下是公有方法
*/
private void getCopyReferral(String dateStr, AuthInfoVO authInfoVo, ReferralEntity referralEntity) {
referralEntity.setStoreType(authInfoVo.getStoreType());
// 非常用链接类型的name需要处理
......
......@@ -74,8 +74,8 @@ public class CustomerDelayGraphicsController {
@ApiOperation("所有公众号")
@GetMapping("/getAuthList")
public GenericsResult<List<AuthInfoVO>> getAuthList(@RequestParam(required = false) String keyword) {
return customerGraphicsDelayService.getAuthList(keyword);
public GenericsResult<List<AuthInfoVO>> getAuthList(@RequestParam(required = false) String keyword, @RequestParam(required = false) String appId) {
return customerGraphicsDelayService.getAuthList(keyword, appId);
}
@ApiOperation("时间间隔")
......
package com.yaoyaozw.customer.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
......@@ -60,6 +58,12 @@ public class CustomerGraphicsDelay implements Serializable {
private Integer sendStatus;
/**
* 原文链接
*/
@TableField(value = "source_url")
private String sourceUrl;
/**
* 是否是历史遗留
*/
@TableField(value = "is_history")
......@@ -105,6 +109,7 @@ public class CustomerGraphicsDelay implements Serializable {
* 逻辑删除
*/
@TableField(value = "is_deleted")
@TableLogic
private Integer isDeleted;
@TableField(exist = false)
......
......@@ -48,9 +48,11 @@ public interface CustomerGraphicsDelayMapper extends BaseMapper<CustomerGraphics
* 让时间间隔列表
*
* @param keyword 关键词
* @param keywordList 关键词拆分
* @param storeType 书城
* @return {@link List}<{@link AuthInfoVO}>
*/
List<AuthInfoVO> getAuthList(@Param("keyword") String keyword);
List<AuthInfoVO> getAuthList(@Param("keyword") String keyword, @Param("keywordList") List<String> keywordList, @Param("storeType") String storeType);
/**
* 让时间间隔列表
......
......@@ -85,9 +85,10 @@ public interface CustomerGraphicsDelayService extends IService<CustomerGraphicsD
* 获得认证列表
*
* @param keyword 关键字
* @param appId 公众号id
* @return {@link GenericsResult}<{@link List}<{@link AuthInfoVO}>>
*/
GenericsResult<List<AuthInfoVO>> getAuthList(String keyword);
GenericsResult<List<AuthInfoVO>> getAuthList(String keyword, String appId);
/**
* 让时间间隔列表
......
......@@ -3,15 +3,13 @@ package com.yaoyaozw.customer.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yaoyaozw.customer.common.BaseResult;
import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.components.CustomerServiceCommonAsyncComponent;
import com.yaoyaozw.customer.components.SnowflakeComponent;
import com.yaoyaozw.customer.components.TokenManager;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
......@@ -51,6 +49,8 @@ public class CustomerGraphicsDelayServiceImpl extends ServiceImpl<CustomerGraphi
private final static Logger localLog = LoggerFactory.getLogger(CustomerGraphicsDelayServiceImpl.class);
private final static String EMPTY_STR = " ";
@Autowired
private TokenManager tokenManager;
@Autowired
......@@ -61,6 +61,8 @@ public class CustomerGraphicsDelayServiceImpl extends ServiceImpl<CustomerGraphi
private AuthorizerInfoService authorizerInfoService;
@Autowired
private KanbanCommonMapper kanbanCommonMapper;
@Autowired
private CustomerServiceCommonAsyncComponent commonAsyncComponent;
@Override
......@@ -174,7 +176,7 @@ public class CustomerGraphicsDelayServiceImpl extends ServiceImpl<CustomerGraphi
// 找到号下面的所有的客服素材
List<CustomerGraphicsDelay> sourceCustomerList = super.list(new QueryWrapper<CustomerGraphicsDelay>().eq("app_id", appId));
List<Long> sourceMainIdList = sourceCustomerList.stream().map(CustomerGraphicsDelay::getId).collect(Collectors.toList());
// 获取原始链接素材
// 获取原始链接素材 图文只有一条、文本有多条
List<ReferralEntity> referralEntityList = referralEntityService.list(new QueryWrapper<ReferralEntity>().in("material_graphics_id", sourceMainIdList));
Map<Long, List<ReferralEntity>> referralGroupMap = referralEntityList.stream().collect(Collectors.groupingBy(ReferralEntity::getMaterialGraphicsId));
......@@ -186,36 +188,40 @@ public class CustomerGraphicsDelayServiceImpl extends ServiceImpl<CustomerGraphi
localLog.info("当前复用书城: {}", storeTypeName);
sourceAuthInfo.setStoreTypeName(storeTypeName);
for (String targetAppId : targetAppList) {
// 遍历要复用的素材
for (CustomerGraphicsDelay item : sourceCustomerList) {
// 设置所属链接
item.setBelongReferralList(referralGroupMap.get(item.getId()));
// 为公众号设置书城名
item.setAuthorizerInfo(sourceAuthInfo);
}
for (String targetAppId : targetAppList) {
// 构造目标公众号的信息
AuthorizerInfo targetAuthInfo = authMap.get(targetAppId);
if (ObjectUtil.isNull(targetAuthInfo)) {
localLog.info("appId: {} 找不到对应公众号", targetAppId);
// 执行下一个公众号
continue;
}
targetAuthInfo.setStoreTypeName(storeTypeName);
// 遍历要复用的素材
for (CustomerGraphicsDelay item : sourceCustomerList) {
// 设置所属链接
item.setBelongReferralList(referralGroupMap.get(item.getId()));
// 为公众号设置书城名
item.setAuthorizerInfo(sourceAuthInfo);
// 执行复用
}
// 异步复用
commonAsyncComponent.obtainDelayGraphicsLink(sourceCustomerList, targetAuthInfo);
}
return null;
return new BaseResult().success("复用进行中, 请等待");
}
@Override
public GenericsResult<List<AuthInfoVO>> getAuthList(String keyword) {
List<AuthInfoVO> authList = super.baseMapper.getAuthList(keyword);
public GenericsResult<List<AuthInfoVO>> getAuthList(String keyword, String appId) {
String storeType = null;
if (ObjectUtil.isNotNull(appId)) {
AuthorizerInfo authInfo = authorizerInfoService.getOne(new QueryWrapper<AuthorizerInfo>().eq("appid", appId));
storeType = authInfo.getStoreType();
}
List<String> keywordList = null;
// 拆分多关键词
if (ObjectUtil.isNotNull(keyword) && keyword.contains(EMPTY_STR)) {
String[] keywordSplit = keyword.split(EMPTY_STR);
keywordList = Arrays.asList(keywordSplit);
keyword = null;
}
List<AuthInfoVO> authList = super.baseMapper.getAuthList(keyword, keywordList, storeType);
return new GenericsResult<>(authList);
}
......
......@@ -2,6 +2,7 @@ package com.yaoyaozw.customer.vo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.yaoyaozw.customer.entity.AuthorizerInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -33,4 +34,13 @@ public class AuthInfoVO implements Serializable {
@ApiModelProperty("书城名")
private String storeTypeName;
public void putPropertyValue(AuthorizerInfo authorizerInfo) {
this.id = authorizerInfo.getId();
this.accountId = authorizerInfo.getAccountId();
this.appId = authorizerInfo.getAppid();
this.accountName = authorizerInfo.getNickName();
this.storeType = authorizerInfo.getStoreType();
this.storeTypeName = authorizerInfo.getStoreTypeName();
}
}
......@@ -97,8 +97,19 @@
nick_name as accountName,
store_type as storeType
from authorizer_info
<if test="keyword != null and keyword != ''">
where nick_name like concat('%', #{keyword}, '%')
</if>
<where>
<if test="keyword != null and keyword != ''">
and nick_name like concat('%', #{keyword}, '%')
</if>
<if test="keywordList != null and keywordList.size() != 0">
and nick_name in
<foreach collection="keywordList" separator="," open="(" close=")" item="splitKeyword">
#{splitKeyword}
</foreach>
</if>
<if test="storeType != null and storeType != ''">
and store_type = #{storeType}
</if>
</where>
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论