Commit c7cc3a61 by danmo

扫码发送欢迎语,添加扫码标签

1 parent 01efc6d8
......@@ -5,6 +5,10 @@ import lombok.Data;
@Data
public class WeEmpleCodeDto {
/**
* 活码id
*/
private String empleCodeId;
/**
* 欢迎语
*/
private String welcomeMsg;
......
......@@ -2,10 +2,6 @@ package com.linkwechat.wecom.domain.dto;
import lombok.Builder;
import lombok.Data;
import me.chanjar.weixin.cp.bean.external.msg.Image;
import me.chanjar.weixin.cp.bean.external.msg.Link;
import me.chanjar.weixin.cp.bean.external.msg.MiniProgram;
import me.chanjar.weixin.cp.bean.external.msg.Text;
/**
* @author admin
......@@ -23,4 +19,68 @@ public class WeWelcomeMsg {
private Link link;
private MiniProgram miniprogram;
@Data
@Builder
public static class Text {
/**
* 消息文本内容,最长为4000字节
*/
private String content;
}
@Data
@Builder
public static class Image {
/**
* 图片的media_id
*/
private String media_id;
/**
* 图片的链接,仅可使用上传图片接口得到的链接
*/
private String pic_url;
}
@Data
@Builder
public static class Link {
/**
* 图文消息标题,最长为128字节
*/
private String title;
/**
* 图文消息封面的url
*/
private String picurl;
/**
* 图文消息的描述,最长为512字节
*/
private String desc;
/**
* 图文消息的链接
*/
private String url;
}
@Data
@Builder
public static class MiniProgram {
/**
* 小程序消息标题,最长为64字节
*/
private String title;
/**
* 小程序消息封面的mediaid,封面图建议尺寸为520*416
*/
private String pic_media_id;
/**
* 小程序appid,必须是关联到企业的小程序应用
*/
private String appid;
/**
* 小程序page路径
*/
private String page;
}
}
package com.linkwechat.wecom.factory.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.dto.WeEmpleCodeDto;
import com.linkwechat.wecom.domain.dto.WeWelcomeMsg;
import com.linkwechat.wecom.domain.vo.WxCpXmlMessageVO;
import com.linkwechat.wecom.factory.WeCallBackEventFactory;
import com.linkwechat.wecom.service.IWeCustomerService;
import com.linkwechat.wecom.service.IWeEmpleCodeService;
import com.linkwechat.wecom.service.IWeFlowerCustomerRelService;
import com.linkwechat.wecom.service.IWeMsgTlpScopeService;
import com.linkwechat.wecom.service.*;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.bean.external.msg.Image;
import me.chanjar.weixin.cp.bean.external.msg.Text;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
/**
* @author sxw
* @description 外部联系人回调事件处理
......@@ -28,11 +37,13 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory
@Autowired
private IWeEmpleCodeService weEmpleCodeService;
@Autowired
private IWeMsgTlpScopeService weMsgTlpScopeService;
private IWeEmpleCodeTagService weEmpleCodeTagService;
@Autowired
private IWeCustomerService weCustomerService;
@Autowired
private IWeFlowerCustomerRelService weFlowerCustomerRelService;
@Autowired
private IWeFlowerCustomerTagRelService weFlowerCustomerTagRelService;
@Override
public void eventHandle(WxCpXmlMessageVO message) {
......@@ -97,6 +108,7 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory
}
private void addExternalContact(WxCpXmlMessageVO message) {
try {
Threads.SINGLE_THREAD_POOL.submit(new Runnable() {
@Override
......@@ -104,22 +116,43 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory
if (message.getExternalUserId() != null) {
weCustomerService.getCustomersInfoAndSynchWeCustomer(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());
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()));
//为外部联系人添加员工活码标签
List<WeFlowerCustomerTagRel> weFlowerCustomerTagRels = new ArrayList<>();
Optional.ofNullable(weFlowerCustomerRel).ifPresent(weFlowerCustomerRel1 -> {
Optional.ofNullable(tagList).orElseGet(ArrayList::new).forEach(tag ->{
weFlowerCustomerTagRels.add(
WeFlowerCustomerTagRel.builder()
.flowerCustomerRelId(weFlowerCustomerRel.getId())
.tagId(tag.getTagId())
.createTime(new Date())
.build()
);
});
weFlowerCustomerTagRelService.saveOrUpdateBatch(weFlowerCustomerTagRels);
});
log.debug(">>>>>>>>>欢迎语查询结果:{}", JSONObject.toJSONString(messageMap));
if (messageMap != null) {
if (StringUtils.isNotEmpty(messageMap.getWelcomeMsg())){
Text text = new Text();
text.setContent(messageMap.getWelcomeMsg());
weWelcomeMsgBuilder.text(text);
weWelcomeMsgBuilder.text(WeWelcomeMsg.Text.builder()
.content(messageMap.getWelcomeMsg()).build());
}
if(StringUtils.isNotEmpty(messageMap.getCategoryId())){
Image image = new Image();
image.setMediaId(messageMap.getCategoryId());
image.setPicUrl(messageMap.getMaterialUrl());
weWelcomeMsgBuilder.image(image);
weWelcomeMsgBuilder.image(WeWelcomeMsg.Image.builder().media_id(messageMap.getCategoryId())
.pic_url(messageMap.getMaterialUrl()).build());
}
weCustomerService.sendWelcomeMsg(weWelcomeMsgBuilder.build());
}
......
......@@ -489,12 +489,8 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
List<WeFlowerCustomerTagRel> weFlowerCustomerTagRels = new ArrayList<>();
List<WeFlowerCustomerRel> weFlowerCustomerRel = new ArrayList<>();
externalUserDetail.getFollow_user().stream().forEach(kk -> {
// WeFlowerCustomerRel weFlowerCustomerRelOne=new WeFlowerCustomerRel();
// BeanUtils.copyPropertiesignoreOther(kk,weFlowerCustomerRelOne);
Long weFlowerCustomerRelId = SnowFlakeUtil.nextId();
// weFlowerCustomerRelOne.setId(weFlowerCustomerRelId);
// weFlowerCustomerRelOne.setExternalUserid(weCustomer.getExternalUserid());
weFlowerCustomerRel.add(WeFlowerCustomerRel.builder()
.id(weFlowerCustomerRelId)
.userId(kk.getUserid())
......@@ -503,6 +499,7 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
.remarkMobiles(kk.getRemark_mobiles())
.operUserid(kk.getOper_userid())
.addWay(kk.getAdd_way())
.state("0")
.externalUserid(weCustomer.getExternalUserid())
.createTime(new Date(kk.getCreatetime() * 1000L))
.build());
......@@ -523,7 +520,7 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
WeTagGroup.builder()
.groupId(tagGroup.getGroup_id())
.gourpName(tagGroup.getGroup_name())
.createBy(SecurityUtils.getUsername())
.createBy(kk.getUserid())
.build()
);
......
......@@ -182,6 +182,7 @@
<select id="selectWelcomeMsgByActivityScene" parameterType="String"
resultType="com.linkwechat.wecom.domain.dto.WeEmpleCodeDto">
select
wecode.id as emple_code_id,
wecode.welcome_msg ,
wm.category_id,
wm.material_url,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!