提交 1a96e807 编写于 作者: 孙喜旺

回调处理裂变客户

上级 7b6652fa
......@@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.enums.MediaType;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.Threads;
import com.linkwechat.wecom.domain.WeEmpleCodeTag;
import com.linkwechat.wecom.domain.WeFlowerCustomerRel;
import com.linkwechat.wecom.domain.WeFlowerCustomerTagRel;
import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.dto.WeEmpleCodeDto;
import com.linkwechat.wecom.domain.dto.WeMediaDto;
import com.linkwechat.wecom.domain.dto.WeWelcomeMsg;
......@@ -18,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -43,30 +41,73 @@ public class WeCallBackAddExternalContactImpl extends WeEventStrategy {
private IWeFlowerCustomerTagRelService weFlowerCustomerTagRelService;
@Autowired
private IWeMaterialService weMaterialService;
@Autowired
private IWeTaskFissionRecordService weTaskFissionRecordService;
@Autowired
private IWeTaskFissionService weTaskFissionService;
@Override
public void eventHandle(WxCpXmlMessageVO message) {
try {
if (message.getExternalUserId() != null) {
weCustomerService.getCustomersInfoAndSynchWeCustomer(message.getExternalUserId());
if (message.getExternalUserId() != null) {
weCustomerService.getCustomersInfoAndSynchWeCustomer(message.getExternalUserId());
}
if (message.getState() != null && message.getWelcomeCode() != null) {
if (isNumeric(message.getState())) {
taskFissionRecordHandle(message.getState(), message.getWelcomeCode(), message.getExternalUserId());
}
//向扫码客户发送欢迎语
if (message.getState() != null && message.getWelcomeCode() != null) {
log.info("执行发送欢迎语>>>>>>>>>>>>>>>");
WeWelcomeMsg.WeWelcomeMsgBuilder weWelcomeMsgBuilder = WeWelcomeMsg.builder().welcome_code(message.getWelcomeCode());
WeEmpleCodeDto messageMap = weEmpleCodeService.selectWelcomeMsgByActivityScene(message.getState(),message.getUserId());
empleCodeHandle(message.getState(), message.getWelcomeCode(), message.getUserId(), message.getExternalUserId());
}
}
//裂变任务处理
private void taskFissionRecordHandle(String state, String wecomCode, String externalUserId) {
//查询裂变客户任务记录
WeTaskFissionRecord weTaskFissionRecord = weTaskFissionRecordService
.selectWeTaskFissionRecordByIdAndCustomerId(Long.valueOf(state),externalUserId);
if (weTaskFissionRecord != null) {
weTaskFissionRecord.setFissNum(weTaskFissionRecord.getFissNum() + 1);
weTaskFissionRecordService.updateWeTaskFissionRecord(weTaskFissionRecord);
//查询裂变任务详情
WeTaskFission weTaskFission = weTaskFissionService
.selectWeTaskFissionById(weTaskFissionRecord.getTaskFissionId());
if (weTaskFission != null){
//发送欢迎语
String welcomeMsg = weTaskFission.getWelcomeMsg();
WeWelcomeMsg.WeWelcomeMsgBuilder weWelcomeMsgBuilder = JSONObject.parseObject(welcomeMsg, WeWelcomeMsg.WeWelcomeMsgBuilder.class);
weWelcomeMsgBuilder.welcome_code(wecomCode);
weCustomerService.sendWelcomeMsg(weWelcomeMsgBuilder.build());
}
}
}
/**
* 活码欢迎语发送
*
* @param state 渠道
* @param wecomCode 欢迎语code
* @param userId 成员id
* @param externalUserId 客户id
*/
private void empleCodeHandle(String state, String wecomCode, String userId, String externalUserId) {
try {
log.info("执行发送欢迎语>>>>>>>>>>>>>>>");
WeWelcomeMsg.WeWelcomeMsgBuilder weWelcomeMsgBuilder = WeWelcomeMsg.builder().welcome_code(wecomCode);
WeEmpleCodeDto messageMap = weEmpleCodeService.selectWelcomeMsgByActivityScene(state, userId);
if (messageMap != null) {
String empleCodeId = messageMap.getEmpleCodeId();
//查询活码对应标签
List<WeEmpleCodeTag> tagList = weEmpleCodeTagService.list(new LambdaQueryWrapper<WeEmpleCodeTag>()
.eq(WeEmpleCodeTag::getEmpleCodeId, empleCodeId));
//查询外部联系人与通讯录关系数据
WeFlowerCustomerRel weFlowerCustomerRel = weFlowerCustomerRelService.getOne(new LambdaQueryWrapper<WeFlowerCustomerRel>()
.eq(WeFlowerCustomerRel::getUserId, message.getUserId())
.eq(WeFlowerCustomerRel::getExternalUserid, message.getExternalUserId()));
.eq(WeFlowerCustomerRel::getUserId, userId)
.eq(WeFlowerCustomerRel::getExternalUserid, externalUserId));
//为外部联系人添加员工活码标签
List<WeFlowerCustomerTagRel> weFlowerCustomerTagRels = new ArrayList<>();
Optional.ofNullable(weFlowerCustomerRel).ifPresent(weFlowerCustomerRel1 -> {
Optional.ofNullable(tagList).orElseGet(ArrayList::new).forEach(tag ->{
Optional.ofNullable(tagList).orElseGet(ArrayList::new).forEach(tag -> {
weFlowerCustomerTagRels.add(
WeFlowerCustomerTagRel.builder()
.flowerCustomerRelId(weFlowerCustomerRel.getId())
......@@ -79,14 +120,14 @@ public class WeCallBackAddExternalContactImpl extends WeEventStrategy {
});
log.debug(">>>>>>>>>欢迎语查询结果:{}", JSONObject.toJSONString(messageMap));
if (messageMap != null) {
if (StringUtils.isNotEmpty(messageMap.getWelcomeMsg())){
if (StringUtils.isNotEmpty(messageMap.getWelcomeMsg())) {
weWelcomeMsgBuilder.text(WeWelcomeMsg.Text.builder()
.content(messageMap.getWelcomeMsg()).build());
}
if(StringUtils.isNotEmpty(messageMap.getCategoryId())){
if (StringUtils.isNotEmpty(messageMap.getCategoryId())) {
WeMediaDto weMediaDto = weMaterialService
.uploadTemporaryMaterial(messageMap.getMaterialUrl(),messageMap.getMaterialName(), MediaType.IMAGE.getMediaType());
Optional.ofNullable(weMediaDto).ifPresent(media ->{
.uploadTemporaryMaterial(messageMap.getMaterialUrl(), messageMap.getMaterialName(), MediaType.IMAGE.getMediaType());
Optional.ofNullable(weMediaDto).ifPresent(media -> {
weWelcomeMsgBuilder.image(WeWelcomeMsg.Image.builder().media_id(media.getMedia_id())
.pic_url(media.getUrl()).build());
});
......@@ -96,7 +137,19 @@ public class WeCallBackAddExternalContactImpl extends WeEventStrategy {
}
} catch (Exception e) {
e.printStackTrace();
log.error("执行发送欢迎语失败!",e);
log.error("执行发送欢迎语失败!", e);
}
}
private boolean isNumeric(String str) {
try {
new BigDecimal(str);
} catch (Exception e) {
//异常 说明包含非数字。
return false;
}
return true;
}
}
package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeTaskFissionRecord;
import java.util.List;
......@@ -10,7 +11,7 @@ import java.util.List;
* @author ruoyi
* @date 2021-01-27
*/
public interface WeTaskFissionRecordMapper {
public interface WeTaskFissionRecordMapper extends BaseMapper<WeTaskFissionRecord> {
/**
* 查询裂变任务记录
*
......
......@@ -58,4 +58,7 @@ public interface IWeTaskFissionRecordService {
* @return 结果
*/
public int deleteWeTaskFissionRecordById(Long id);
public WeTaskFissionRecord selectWeTaskFissionRecordByIdAndCustomerId(Long id, String customerId);
}
package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.wecom.domain.WeTaskFissionRecord;
import com.linkwechat.wecom.mapper.WeTaskFissionRecordMapper;
import com.linkwechat.wecom.service.IWeTaskFissionRecordService;
......@@ -15,7 +17,7 @@ import java.util.List;
* @date 2021-01-27
*/
@Service
public class WeTaskFissionRecordServiceImpl implements IWeTaskFissionRecordService {
public class WeTaskFissionRecordServiceImpl extends ServiceImpl<WeTaskFissionRecordMapper,WeTaskFissionRecord> implements IWeTaskFissionRecordService {
@Autowired
private WeTaskFissionRecordMapper weTaskFissionRecordMapper;
......@@ -84,4 +86,11 @@ public class WeTaskFissionRecordServiceImpl implements IWeTaskFissionRecordServi
public int deleteWeTaskFissionRecordById(Long id) {
return weTaskFissionRecordMapper.deleteWeTaskFissionRecordById(id);
}
@Override
public WeTaskFissionRecord selectWeTaskFissionRecordByIdAndCustomerId(Long id, String customerId) {
return weTaskFissionRecordMapper.selectOne(new LambdaQueryWrapper<WeTaskFissionRecord>()
.eq(WeTaskFissionRecord::getId,id)
.eq(WeTaskFissionRecord::getCustomerId,customerId));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册