Commit 1e0b6525 by 水库浪子

修改图文群发;群发记录;客户打标签;离职客户按时间查询报错;群发消息同步等相关BUG

1 parent 7db6a9a9
......@@ -53,9 +53,7 @@ public class WeCustomerMessagePushController extends BaseController {
@PostMapping(value = "add")
public AjaxResult add(@RequestBody CustomerMessagePushDto customerMessagePushDto) {
try {
SecurityContext context = SecurityContextHolder.getContext();
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
SecurityContextHolder.setContext(context);
weCustomerMessagePushService.addWeCustomerMessagePush(customerMessagePushDto);
} catch (JsonProcessingException | ParseException | CloneNotSupportedException e) {
......
......@@ -27,7 +27,7 @@ public interface WeCustomerMessagePushClient {
/**
* 获取企业群发消息发送结果
* <a href="https://work.weixin.qq.com/api/doc/90000/90135/92136">API文档地址</a>
* <a href="https://work.weixin.qq.com/api/doc/90000/90135/93338#%E8%8E%B7%E5%8F%96%E4%BC%81%E4%B8%9A%E7%BE%A4%E5%8F%91%E6%88%90%E5%91%98%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9E%9C">API文档地址</a>
*
* @param queryCustomerMessageStatusResultDataObjectDto{msgid} <a href="https://work.weixin.qq.com/api/doc/90000/90135/92135">添加企业群发消息任务返回的msgid</a>
*/
......@@ -37,4 +37,7 @@ public interface WeCustomerMessagePushClient {
QueryCustomerMessageStatusResultDto queryCustomerMessageStatus(@Body QueryCustomerMessageStatusResultDataObjectDto queryCustomerMessageStatusResultDataObjectDto);
}
package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
......@@ -34,6 +35,7 @@ public class WeFlowerCustomerRel
/** 添加了此外部联系人的企业成员userid */
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String userId;
/** 外部联系人名称 */
......
......@@ -84,7 +84,7 @@ public class CustomerMessagePushDto implements Cloneable{
public String content() {
if (this.getMessageType()!=null) {
// 消息类型 0 文本消息 1 图片消息 2 链接消息 3 小程序消息
// 消息类型 0 文本消息 1 图片消息 2 链接消息 3 小程序消息 4 图文
if ( this.getMessageType().equals("0")) {
return this.getTextMessage().getContent();
}
......@@ -103,6 +103,12 @@ public class CustomerMessagePushDto implements Cloneable{
return this.getMiniprogramMessage().getTitle() + ":" + this.getMiniprogramMessage().getPage();
}
if(this.getMessageType().equals("4")){
return this.getTextMessage().getContent()+","+this.getImageMessage().getPic_url();
}
}
return null;
......@@ -115,19 +121,6 @@ public class CustomerMessagePushDto implements Cloneable{
}
public List<CustomerMessagePushDto> handleImageAndText() throws CloneNotSupportedException {
List<CustomerMessagePushDto> customerMessagePushDtos=new ArrayList<>();
CustomerMessagePushDto cloneOne = this.clone();
cloneOne.setMessageType("0");
customerMessagePushDtos.add(cloneOne);
CustomerMessagePushDto cloneTwo = this.clone();
cloneTwo.setMessageType("1");
customerMessagePushDtos.add(cloneTwo);
return customerMessagePushDtos;
}
}
......@@ -8,4 +8,8 @@ public class QueryCustomerMessageStatusResultDataObjectDto {
* 群发消息的id,通过<a href=“https://work.weixin.qq.com/api/doc/90000/90135/92135”>创建企业群发接口</a>返回
*/
private String msgid;
}
......@@ -17,6 +17,7 @@ public class QueryCustomerMessageStatusResultDto extends WeResultDto {
private String check_status;
}
......@@ -2,8 +2,11 @@ package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeCustomerMessage;
import com.linkwechat.wecom.domain.dto.message.DetailMessageStatusResultDto;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 群发消息 微信消息表Mapper接口
*
......@@ -30,4 +33,6 @@ public interface WeCustomerMessageMapper extends BaseMapper<WeCustomerMessage> {
*/
int updateWeCustomerMessageCheckStatusById(@Param("messageId") Long messageId,@Param("status") String status);
}
......@@ -19,6 +19,7 @@ import com.linkwechat.wecom.service.IWeCustomerMessageOriginalService;
import com.linkwechat.wecom.service.IWeCustomerMessageService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.List;
......@@ -131,14 +132,16 @@ public class WeCustomerMessageOriginalServiceImpl extends ServiceImpl<WeCustomer
List<DetailMessageStatusResultDto> detailList = queryCustomerMessageStatusResultDto.getDetail_list();
detailList.forEach(d -> {
if (d.getStatus().equals(WeConstans.sendMessageStatusEnum.SEND.getStatus())) {
atomicInteger.incrementAndGet();
//更新消息发送状态
customerMessageMapper.updateWeCustomerMessageCheckStatusById(messageId,WeConstans.sendMessageStatusEnum.SEND.getStatus());
}
detailList.forEach(d -> {
// if (d.getStatus().equals(WeConstans.sendMessageStatusEnum.SEND.getStatus())) {
//
// atomicInteger.incrementAndGet();
// //更新消息发送状态
// customerMessageMapper.updateWeCustomerMessageCheckStatusById(messageId,WeConstans.sendMessageStatusEnum.SEND.getStatus());
// }
weCustomerMessgaeResultMapper.updateWeCustomerMessgaeResult(messageId, d.getChat_id(), d.getExternal_userid(), d.getStatus(), d.getSend_time());
......
......@@ -81,97 +81,78 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
@Override
@Transactional(rollbackFor = Exception.class)
public void addWeCustomerMessagePush(CustomerMessagePushDto customerMessagePush) throws JsonProcessingException, ParseException, CloneNotSupportedException {
public void addWeCustomerMessagePush(CustomerMessagePushDto customerMessagePushDto) throws JsonProcessingException, ParseException, CloneNotSupportedException {
if(StrUtil.isNotBlank(customerMessagePush.getSettingTime())){
if(DateUtils.diffTime(new Date(), DateUtil.parse(customerMessagePush.getSettingTime(), "yyyy-MM-dd HH:mm")) > 0){
if(StrUtil.isNotBlank(customerMessagePushDto.getSettingTime())){
if(DateUtils.diffTime(new Date(), DateUtil.parse(customerMessagePushDto.getSettingTime(), "yyyy-MM-dd HH:mm")) > 0){
throw new WeComException("发送时间不能小于当前时间");
}
}
List<CustomerMessagePushDto> customerMessagePushDtos=new ArrayList<>();
if(customerMessagePush.getMessageType().equals("4")){
if(customerMessagePushDto.getMessageType().equals("1")){//等于图片或者图文,根据图片URL,获取新的media_id
customerMessagePushDtos=customerMessagePush.handleImageAndText();
ImageMessageDto imageMessage = customerMessagePushDto.getImageMessage();
}else{
customerMessagePushDtos.add(customerMessagePush);
}
for(CustomerMessagePushDto customerMessagePushDto:customerMessagePushDtos){
if(customerMessagePush.getMessageType().equals("1")){//等于图片或者图文,根据图片URL,获取新的media_id
ImageMessageDto imageMessage = customerMessagePushDto.getImageMessage();
if(null != imageMessage && StrUtil.isNotBlank(imageMessage.getPic_url())){
WeMediaDto weMediaDto = materialService.uploadTemporaryMaterial(imageMessage.getPic_url(),
MediaType.IMAGE.getMediaType()
,imageMessage.getPic_url());
if(StrUtil.isNotBlank(weMediaDto.getMedia_id())){
imageMessage.setMedia_id(weMediaDto.getMedia_id());
}
}
if(null != imageMessage && StrUtil.isNotBlank(imageMessage.getPic_url())){
WeMediaDto weMediaDto = materialService.uploadTemporaryMaterial(imageMessage.getPic_url(),
MediaType.IMAGE.getMediaType()
,imageMessage.getPic_url());
if(StrUtil.isNotBlank(weMediaDto.getMedia_id())){
imageMessage.setMedia_id(weMediaDto.getMedia_id());
}
}
List<WeCustomer> customers = Lists.newArrayList();
List<WeGroup> groups = new ArrayList<>();
// 0 发给客户
if (customerMessagePushDto.getPushType().equals(WeConstans.SEND_MESSAGE_CUSTOMER)) {
//查询客户信息列表
if ("all".equals(customerMessagePushDto.getTag())) {
customers = externalUserIds(WeConstans.SEND_MESSAGE_CUSTOMER_ALL, customerMessagePushDto.getStaffId(), customerMessagePushDto.getDepartment(), customerMessagePushDto.getTag());
} else {
customers = externalUserIds(customerMessagePushDto.getPushRange(), customerMessagePushDto.getStaffId()
, customerMessagePushDto.getDepartment(), customerMessagePushDto.getTag());
}
if (CollectionUtils.isEmpty(customers)) {
throw new WeComException("没有外部联系人");
}
}
// 1 发给客户群
if (customerMessagePushDto.getPushType().equals(WeConstans.SEND_MESSAGE_GROUP)) {
if (customerMessagePushDto.getStaffId() == null || customerMessagePushDto.getStaffId().equals("")) {
throw new WeComException("请选择人员!");
}
//通过员工id查询群列表
WeGroup weGroup = new WeGroup();
weGroup.setUserIds(customerMessagePushDto.getStaffId());
groups = weGroupService.selectWeGroupList(weGroup);
if (CollectionUtils.isEmpty(groups)) {
throw new WeComException("没有客户群!");
}
}
}
//保存原始数据信息表
long messageOriginalId = weCustomerMessageOriginalService.saveWeCustomerMessageOriginal(customerMessagePushDto);
long messageId = SnowFlakeUtil.nextId();
List<WeCustomer> customers = Lists.newArrayList();
List<WeGroup> groups = new ArrayList<>();
// 0 发给客户
if (customerMessagePushDto.getPushType().equals(WeConstans.SEND_MESSAGE_CUSTOMER)) {
//查询客户信息列表
if ("all".equals(customerMessagePushDto.getTag())) {
customers = externalUserIds(WeConstans.SEND_MESSAGE_CUSTOMER_ALL, customerMessagePushDto.getStaffId(), customerMessagePushDto.getDepartment(), customerMessagePushDto.getTag());
} else {
customers = externalUserIds(customerMessagePushDto.getPushRange(), customerMessagePushDto.getStaffId()
, customerMessagePushDto.getDepartment(), customerMessagePushDto.getTag());
}
//保存映射信息
int size = weCustomerMessgaeResultService.workerMappingCustomer(customerMessagePushDto, messageId, customers, groups);
//保存微信消息
weCustomerMessageService.saveWeCustomerMessage(messageId, messageOriginalId, customerMessagePushDto, size, customerMessagePushDto.content());
if (CollectionUtils.isEmpty(customers)) {
throw new WeComException("没有外部联系人");
}
}
//保存分类消息信息
weCustomerSeedMessageService.saveSeedMessage(customerMessagePushDto, messageId);
// 1 发给客户群
if (customerMessagePushDto.getPushType().equals(WeConstans.SEND_MESSAGE_GROUP)) {
if (customerMessagePushDto.getStaffId() == null || customerMessagePushDto.getStaffId().equals("")) {
throw new WeComException("请选择人员!");
}
//通过员工id查询群列表
WeGroup weGroup = new WeGroup();
weGroup.setUserIds(customerMessagePushDto.getStaffId());
groups = weGroupService.selectWeGroupList(weGroup);
if (CollectionUtils.isEmpty(groups)) {
throw new WeComException("没有客户群!");
}
}
//保存原始数据信息表
long messageOriginalId = weCustomerMessageOriginalService.saveWeCustomerMessageOriginal(customerMessagePushDto);
long messageId = SnowFlakeUtil.nextId();
this.sendMessage(customerMessagePushDto,messageId,customers,groups);
//保存映射信息
int size = weCustomerMessgaeResultService.workerMappingCustomer(customerMessagePushDto, messageId, customers, groups);
//保存微信消息
weCustomerMessageService.saveWeCustomerMessage(messageId, messageOriginalId, customerMessagePushDto, size, customerMessagePushDto.content());
//保存分类消息信息
weCustomerSeedMessageService.saveSeedMessage(customerMessagePushDto, messageId);
}
this.sendMessage(customerMessagePushDto,messageId,customers,groups);
}
......
......@@ -15,10 +15,7 @@ import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerMessage;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.WeMediaDto;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
import com.linkwechat.wecom.domain.dto.message.ImageMessageDto;
import com.linkwechat.wecom.domain.dto.message.SendMessageResultDto;
import com.linkwechat.wecom.domain.dto.message.WeCustomerMessagePushDto;
import com.linkwechat.wecom.domain.dto.message.*;
import com.linkwechat.wecom.mapper.WeCustomerMessageMapper;
import com.linkwechat.wecom.service.IWeCustomerMessageService;
import com.linkwechat.wecom.service.IWeMaterialService;
......@@ -89,7 +86,9 @@ public class WeCustomerMessageServiceImpl extends ServiceImpl<WeCustomerMessageM
//通过messageId更新msgIds
WeCustomerMessage weCustomerMessage = new WeCustomerMessage();
weCustomerMessage.setMessageId(messageId);
weCustomerMessage.setMsgid(objectMapper.writeValueAsString(msgIds));
// String result = msgIds.stream().map(String::valueOf).collect(Collectors.joining(","));
weCustomerMessage.setMsgid(msgIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
// weCustomerMessage.setMsgid(objectMapper.writeValueAsString(msgIds));
weCustomerMessageMapper.updateWeCustomerMessageMsgIdById(weCustomerMessage);
}
......@@ -102,6 +101,7 @@ public class WeCustomerMessageServiceImpl extends ServiceImpl<WeCustomerMessageM
if (customerMessagePushDto.getPushType().equals(WeConstans.SEND_MESSAGE_CUSTOMER)) {
WeCustomerMessagePushDto messagePushDto = new WeCustomerMessagePushDto();
messagePushDto.setChat_type(ChatType.of(customerMessagePushDto.getPushType()).getName());
List<String> externalUserIds = customers.stream().map(WeCustomer::getExternalUserid).collect(Collectors.toList());
......@@ -135,6 +135,7 @@ public class WeCustomerMessageServiceImpl extends ServiceImpl<WeCustomerMessageM
}
this.updateMsgId(messageId, msgid);
}
......@@ -182,9 +183,11 @@ public class WeCustomerMessageServiceImpl extends ServiceImpl<WeCustomerMessageM
if(customerMessagePushDto.getMessageType().equals(GroupMessageType.TEXT_IMAGE.getType())){
JSONObject jsonObject = new JSONObject();
jsonObject.put("msgtype","text_image");
jsonObject.put("text_image",customerMessagePushDto.getTextMessage());
jsonObject.put("msgtype","image");
jsonObject.put("image",customerMessagePushDto.getImageMessage());
list.add(jsonObject);
weCustomerMessagePushDto.setText(customerMessagePushDto.getTextMessage());
}
if(customerMessagePushDto.getMessageType().equals(GroupMessageType.VIDEO.getType())){
......
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.constant.Constants;
......@@ -349,10 +350,16 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
@Transactional(rollbackFor = Exception.class)
public void makeLabel(WeMakeCustomerTag weMakeCustomerTag) {
LambdaQueryWrapper<WeFlowerCustomerRel> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(WeFlowerCustomerRel::getExternalUserid, weMakeCustomerTag.getExternalUserid());
if(StrUtil.isNotBlank(weMakeCustomerTag.getUserId())){
wrapper.eq(WeFlowerCustomerRel::getUserId,weMakeCustomerTag.getUserId());
}
//查询出当前用户对应的
List<WeFlowerCustomerRel> flowerCustomerRels = iWeFlowerCustomerRelService.list(new LambdaQueryWrapper<WeFlowerCustomerRel>()
.eq(WeFlowerCustomerRel::getExternalUserid, weMakeCustomerTag.getExternalUserid())
.eq(WeFlowerCustomerRel::getUserId,weMakeCustomerTag.getUserId())
List<WeFlowerCustomerRel> flowerCustomerRels = iWeFlowerCustomerRelService.list(
wrapper
);
if (CollectionUtil.isNotEmpty(flowerCustomerRels)) {
......
......@@ -21,6 +21,7 @@
message_id=#{messageId}
</where>
</update>
<update id="updateWeCustomerMessageCheckStatusById">
UPDATE we_customer_message
<set>
......@@ -31,4 +32,6 @@
</where>
</update>
</mapper>
......@@ -65,8 +65,10 @@
AND external_userid=#{externalUserid}
</if>
</where>
</update>
<select id="customerMessagePushs" resultType="com.linkwechat.wecom.domain.vo.WeCustomerMessageResultVo">
SELECT
user_name,
......
......@@ -237,7 +237,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where>
<if test="handoverUserId != null and handoverUserId !=''">and wac.handover_userid=#{handoverUserId}</if>
<if test="beginTime != null and beginTime !='' and endTime != null and endTime !=''">
DATE_FORMAT(wu.dimission_time,'%Y-%m-%d') BETWEEN #{beginTime} AND #{endTime}
and DATE_FORMAT(wu.dimission_time,'%Y-%m-%d') BETWEEN #{beginTime} AND #{endTime}
</if>
</where>
</select>
......@@ -258,7 +258,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where>
<if test="oldOwner != null and oldOwner !=''">and wag.old_owner=#{oldOwner}</if>
<if test="beginTime != null and beginTime !='' and endTime != null and endTime !=''">
DATE_FORMAT(wu.dimission_time,'%Y-%m-%d') BETWEEN #{beginTime} AND #{endTime}
and DATE_FORMAT(wu.dimission_time,'%Y-%m-%d') BETWEEN #{beginTime} AND #{endTime}
</if>
</where>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!