Commit dfe3bc73 by 18356073052

新增群发消息任务列表

1 parent adf256e0
...@@ -12,6 +12,7 @@ import com.linkwechat.common.utils.SnowFlakeUtil; ...@@ -12,6 +12,7 @@ import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.wecom.client.WeCustomerMessagePushClient; import com.linkwechat.wecom.client.WeCustomerMessagePushClient;
import com.linkwechat.wecom.domain.*; import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.dto.message.*; import com.linkwechat.wecom.domain.dto.message.*;
import com.linkwechat.wecom.domain.vo.CustomerMessagePushVo;
import com.linkwechat.wecom.service.*; import com.linkwechat.wecom.service.*;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -37,7 +38,6 @@ import java.util.stream.Collectors; ...@@ -37,7 +38,6 @@ import java.util.stream.Collectors;
public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushService { public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushService {
@Autowired @Autowired
private IWeCustomerMessageOriginalService weCustomerMessageOriginalService; private IWeCustomerMessageOriginalService weCustomerMessageOriginalService;
...@@ -102,16 +102,22 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS ...@@ -102,16 +102,22 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
} }
@Override
public List<CustomerMessagePushVo> customerMessagePushs(String sender, String content, String pushType, String beginTime, String endTime) {
return weCustomerMessageOriginalService.customerMessagePushs(sender, content, pushType, beginTime, endTime);
}
/** /**
* 发送消息 * 发送消息
*
* @param customerMessagePushDto 消息信息 * @param customerMessagePushDto 消息信息
* @throws JsonProcessingException * @throws JsonProcessingException
*/ */
public void sendMessgae(CustomerMessagePushDto customerMessagePushDto) throws JsonProcessingException{ public void sendMessgae(CustomerMessagePushDto customerMessagePushDto) throws JsonProcessingException {
//原始数据信息表 WeCustomerMessageOriginal 主键id //原始数据信息表 WeCustomerMessageOriginal 主键id
long messageOriginalId= SnowFlakeUtil.nextId(); long messageOriginalId = SnowFlakeUtil.nextId();
WeCustomerMessageOriginal original=new WeCustomerMessageOriginal(); WeCustomerMessageOriginal original = new WeCustomerMessageOriginal();
original.setMessageOriginalId(messageOriginalId); original.setMessageOriginalId(messageOriginalId);
original.setStaffId(customerMessagePushDto.getStaffId()); original.setStaffId(customerMessagePushDto.getStaffId());
original.setDepartment(customerMessagePushDto.getDepartment()); original.setDepartment(customerMessagePushDto.getDepartment());
...@@ -122,47 +128,54 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS ...@@ -122,47 +128,54 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
original.setDelFlag(0); original.setDelFlag(0);
weCustomerMessageOriginalService.save(original); weCustomerMessageOriginalService.save(original);
List<String> msgIds=Lists.newArrayList(); List<String> msgIds = Lists.newArrayList();
List<String> senders=Lists.newArrayList(); List<String> senders = Lists.newArrayList();
List<String> externalUserIds=Lists.newArrayList(); List<String> externalUserIds = Lists.newArrayList();
StringBuffer sendInfo = new StringBuffer();
//预计发送的人员和群的个数
int size = 0;
//发送群发消息 //发送群发消息
//发送类类型: 给单个客户发,群发 //发送类类型: 给单个客户发,群发
//发给客户 //发给客户
if(customerMessagePushDto.getPushType().equals("0")){ if (customerMessagePushDto.getPushType().equals("0")) {
WeCustomerMessagePushDto messagePushDto=new WeCustomerMessagePushDto(); WeCustomerMessagePushDto messagePushDto = new WeCustomerMessagePushDto();
messagePushDto.setChat_type(ChatType.of(customerMessagePushDto.getPushType()).getName()); messagePushDto.setChat_type(ChatType.of(customerMessagePushDto.getPushType()).getName());
externalUserIds = externalUserIds(customerMessagePushDto.getPushRange(), customerMessagePushDto.getStaffId() externalUserIds = externalUserIds(customerMessagePushDto.getPushRange(), customerMessagePushDto.getStaffId()
, customerMessagePushDto.getDepartment(), customerMessagePushDto.getTag()); , customerMessagePushDto.getDepartment(), customerMessagePushDto.getTag());
if (CollectionUtils.isNotEmpty(externalUserIds)) {
size = externalUserIds.size();
}
messagePushDto.setExternal_userid(externalUserIds); messagePushDto.setExternal_userid(externalUserIds);
seedMessage(messagePushDto,customerMessagePushDto); seedMessage(messagePushDto, customerMessagePushDto);
SendMessageResultDto sendMessageResultDto = weCustomerMessagePushClient.sendCustomerMessageToUser(messagePushDto); SendMessageResultDto sendMessageResultDto = weCustomerMessagePushClient.sendCustomerMessageToUser(messagePushDto);
if(WeConstans.WE_SUCCESS_CODE.equals(sendMessageResultDto.getErrcode())){ if (WeConstans.WE_SUCCESS_CODE.equals(sendMessageResultDto.getErrcode())) {
msgIds.add(sendMessageResultDto.getMsgid()); msgIds.add(sendMessageResultDto.getMsgid());
} }
} }
//发给客户群 //发给客户群
if(customerMessagePushDto.getPushType().equals("1")){ if (customerMessagePushDto.getPushType().equals("1")) {
if(customerMessagePushDto.getStaffId()==null || customerMessagePushDto.getStaffId().equals("")){ if (customerMessagePushDto.getStaffId() == null || customerMessagePushDto.getStaffId().equals("")) {
throw new WeComException("参数异常!"); throw new WeComException("参数异常!");
} }
//通过员工id查询群列表 //通过员工id查询群列表
WeGroup weGroup=new WeGroup(); WeGroup weGroup = new WeGroup();
weGroup.setUserIds(customerMessagePushDto.getStaffId()); weGroup.setUserIds(customerMessagePushDto.getStaffId());
List<WeGroup> groups = weGroupService.selectWeGroupList(weGroup); List<WeGroup> groups = weGroupService.selectWeGroupList(weGroup);
if(CollectionUtils.isNotEmpty(groups)){ if (CollectionUtils.isNotEmpty(groups)) {
size = groups.size();
List<String> owners = groups.stream().map(WeGroup::getOwner).collect(Collectors.toList()); List<String> owners = groups.stream().map(WeGroup::getOwner).collect(Collectors.toList());
for (String owner:owners) { for (String owner : owners) {
WeCustomerMessagePushDto messagePushDto=new WeCustomerMessagePushDto(); WeCustomerMessagePushDto messagePushDto = new WeCustomerMessagePushDto();
messagePushDto.setChat_type(ChatType.of(customerMessagePushDto.getPushType()).getType()); messagePushDto.setChat_type(ChatType.of(customerMessagePushDto.getPushType()).getType());
//客户群的员工id //客户群的员工id
messagePushDto.setSender(owner); messagePushDto.setSender(owner);
seedMessage(messagePushDto,customerMessagePushDto); seedMessage(messagePushDto, customerMessagePushDto);
SendMessageResultDto sendMessageResultDto = weCustomerMessagePushClient.sendCustomerMessageToUser(messagePushDto); SendMessageResultDto sendMessageResultDto = weCustomerMessagePushClient.sendCustomerMessageToUser(messagePushDto);
if(WeConstans.WE_SUCCESS_CODE.equals(sendMessageResultDto.getErrcode())){ if (WeConstans.WE_SUCCESS_CODE.equals(sendMessageResultDto.getErrcode())) {
//发送的msgId //发送的msgId
msgIds.add(sendMessageResultDto.getMsgid()); msgIds.add(sendMessageResultDto.getMsgid());
senders.add(owner); senders.add(owner);
...@@ -171,11 +184,11 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS ...@@ -171,11 +184,11 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
} }
} }
sendInfo(customerMessagePushDto, sendInfo, size);
//微信群发消息表 WeCustomerMessage //微信群发消息表 WeCustomerMessage
long messageId=SnowFlakeUtil.nextId(); long messageId = SnowFlakeUtil.nextId();
WeCustomerMessage customerMessage=new WeCustomerMessage(); WeCustomerMessage customerMessage = new WeCustomerMessage();
customerMessage.setOriginalId(messageOriginalId); customerMessage.setOriginalId(messageOriginalId);
customerMessage.setMessageId(messageId); customerMessage.setMessageId(messageId);
customerMessage.setChatType(customerMessagePushDto.getPushType()); customerMessage.setChatType(customerMessagePushDto.getPushType());
...@@ -184,63 +197,125 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS ...@@ -184,63 +197,125 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
customerMessage.setCheckStatus("0"); customerMessage.setCheckStatus("0");
customerMessage.setMsgid(objectMapper.writeValueAsString(msgIds)); customerMessage.setMsgid(objectMapper.writeValueAsString(msgIds));
customerMessage.setDelFlag(0); customerMessage.setDelFlag(0);
customerMessage.setContent(content(customerMessagePushDto));
customerMessage.setSendInfo(sendInfo.toString());
weCustomerMessageService.save(customerMessage); weCustomerMessageService.save(customerMessage);
//TODO 消息发送结果保存逻辑待定 到底是怎么保存
WeCustomerMessgaeResult weCustomerMessgaeResult=new WeCustomerMessgaeResult();
//保存分类消息信息 //保存分类消息信息
saveSeedMessage(customerMessagePushDto,messageId); saveSeedMessage(customerMessagePushDto, messageId);
}
private void sendInfo(CustomerMessagePushDto customerMessagePushDto, StringBuffer sendInfo, int size) {
if (null != customerMessagePushDto.getSettingTime() && !customerMessagePushDto.getSettingTime().equals("")) {
sendInfo.append("定时任务");
sendInfo.append("发送时间:");
sendInfo.append(customerMessagePushDto.getSettingTime());
} else {
if (customerMessagePushDto.getPushType().equals("0")) {
//预计发送3190人,已成功发送0人
sendInfo.append("预计发送");
sendInfo.append(size);
sendInfo.append("人,");
sendInfo.append("已成功发送0人");
}
if (customerMessagePushDto.getPushType().equals("1")) {
//预计发送2个群,已成功发送0个群
sendInfo.append("预计发送");
sendInfo.append(size);
sendInfo.append("个群,");
sendInfo.append("已成功发送0个群");
}
}
}
/**
* 消息内容
*
* @param customerMessagePushDto
* @return
*/
private String content(CustomerMessagePushDto customerMessagePushDto) {
if (customerMessagePushDto != null) {
// 消息类型 0 文本消息 1 图片消息 2 链接消息 3 小程序消息
if (customerMessagePushDto.getMessageType().equals("0")) {
return customerMessagePushDto.getTextMessage().getContent();
}
if (customerMessagePushDto.getMessageType().equals("1")) {
return customerMessagePushDto.getImageMessage().getPic_url();
}
if (customerMessagePushDto.getMessageType().equals("2")) {
return customerMessagePushDto.getLinkMessage().getTitle() + ":" + customerMessagePushDto.getLinkMessage().getPicurl()
+ ":" + customerMessagePushDto.getLinkMessage().getUrl() + "" + customerMessagePushDto.getLinkMessage().getDesc();
}
if (customerMessagePushDto.getMessageType().equals("3")) {
return customerMessagePushDto.getMiniprogramMessage().getTitle() + ":" + customerMessagePushDto.getMiniprogramMessage().getPage();
}
}
return null;
} }
/** /**
* 子消息体 * 子消息体
* *
* @param weCustomerMessagePushDto 群发消息体 * @param weCustomerMessagePushDto 群发消息体
* @param customerMessagePushDto 群发消息 * @param customerMessagePushDto 群发消息
*/ */
public void seedMessage(WeCustomerMessagePushDto weCustomerMessagePushDto,CustomerMessagePushDto customerMessagePushDto){ public String seedMessage(WeCustomerMessagePushDto weCustomerMessagePushDto, CustomerMessagePushDto customerMessagePushDto) {
String content = null;
// 消息类型 0 文本消息 1 图片消息 2 链接消息 3 小程序消息 // 消息类型 0 文本消息 1 图片消息 2 链接消息 3 小程序消息
if(customerMessagePushDto.getMessageType().equals("0")){ if (customerMessagePushDto.getMessageType().equals("0")) {
weCustomerMessagePushDto.setImage(null); weCustomerMessagePushDto.setImage(null);
weCustomerMessagePushDto.setLink(null); weCustomerMessagePushDto.setLink(null);
weCustomerMessagePushDto.setMiniprogram(null); weCustomerMessagePushDto.setMiniprogram(null);
weCustomerMessagePushDto.setText(customerMessagePushDto.getTextMessage()); weCustomerMessagePushDto.setText(customerMessagePushDto.getTextMessage());
content = customerMessagePushDto.getTextMessage().getContent();
} }
if(customerMessagePushDto.getMessageType().equals("1")){ if (customerMessagePushDto.getMessageType().equals("1")) {
weCustomerMessagePushDto.setImage(customerMessagePushDto.getImageMessage()); weCustomerMessagePushDto.setImage(customerMessagePushDto.getImageMessage());
weCustomerMessagePushDto.setLink(null); weCustomerMessagePushDto.setLink(null);
weCustomerMessagePushDto.setMiniprogram(null); weCustomerMessagePushDto.setMiniprogram(null);
weCustomerMessagePushDto.setText(null); weCustomerMessagePushDto.setText(null);
content = customerMessagePushDto.getImageMessage().getPic_url();
} }
if(customerMessagePushDto.getMessageType().equals("2")){ if (customerMessagePushDto.getMessageType().equals("2")) {
weCustomerMessagePushDto.setImage(null); weCustomerMessagePushDto.setImage(null);
weCustomerMessagePushDto.setLink(customerMessagePushDto.getLinkMessage()); weCustomerMessagePushDto.setLink(customerMessagePushDto.getLinkMessage());
weCustomerMessagePushDto.setMiniprogram(null); weCustomerMessagePushDto.setMiniprogram(null);
weCustomerMessagePushDto.setText(null); weCustomerMessagePushDto.setText(null);
content = customerMessagePushDto.getLinkMessage().getTitle() + ":" + customerMessagePushDto.getLinkMessage().getPicurl()
+ ":" + customerMessagePushDto.getLinkMessage().getUrl() + "" + customerMessagePushDto.getLinkMessage().getDesc();
} }
if(customerMessagePushDto.getMessageType().equals("3")){ if (customerMessagePushDto.getMessageType().equals("3")) {
weCustomerMessagePushDto.setImage(customerMessagePushDto.getImageMessage()); weCustomerMessagePushDto.setImage(null);
weCustomerMessagePushDto.setLink(customerMessagePushDto.getLinkMessage()); weCustomerMessagePushDto.setLink(null);
weCustomerMessagePushDto.setMiniprogram(customerMessagePushDto.getMiniprogramMessage()); weCustomerMessagePushDto.setMiniprogram(customerMessagePushDto.getMiniprogramMessage());
weCustomerMessagePushDto.setText(customerMessagePushDto.getTextMessage()); weCustomerMessagePushDto.setText(null);
content = customerMessagePushDto.getMiniprogramMessage().getTitle() + ":" + customerMessagePushDto.getMiniprogramMessage().getPage();
} }
return content;
} }
/** /**
* 各分类消息表 * 各分类消息表
*
* @param customerMessagePushDto 群发消息 * @param customerMessagePushDto 群发消息
* @param messageId 消息id * @param messageId 消息id
*/ */
public void saveSeedMessage(CustomerMessagePushDto customerMessagePushDto,long messageId){ public void saveSeedMessage(CustomerMessagePushDto customerMessagePushDto, long messageId) {
String messageType = customerMessagePushDto.getMessageType(); String messageType = customerMessagePushDto.getMessageType();
switch (messageType){ switch (messageType) {
case "0": case "0":
//文本消息 //文本消息
WeCustomerTextMessag textMessage=new WeCustomerTextMessag(); WeCustomerTextMessag textMessage = new WeCustomerTextMessag();
textMessage.setTextMessageId(SnowFlakeUtil.nextId()); textMessage.setTextMessageId(SnowFlakeUtil.nextId());
textMessage.setMessageId(messageId); textMessage.setMessageId(messageId);
TextMessageDto textMessageDto = customerMessagePushDto.getTextMessage(); TextMessageDto textMessageDto = customerMessagePushDto.getTextMessage();
...@@ -250,10 +325,10 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS ...@@ -250,10 +325,10 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
break; break;
case "1": case "1":
//图片消息 //图片消息
WeCustomerImageMessage imageMessage=new WeCustomerImageMessage(); WeCustomerImageMessage imageMessage = new WeCustomerImageMessage();
imageMessage.setImageMessageId(SnowFlakeUtil.nextId()); imageMessage.setImageMessageId(SnowFlakeUtil.nextId());
imageMessage.setMessageId(messageId); imageMessage.setMessageId(messageId);
ImageMessageDto imageMessageDto= customerMessagePushDto.getImageMessage(); ImageMessageDto imageMessageDto = customerMessagePushDto.getImageMessage();
imageMessage.setMediaId(imageMessageDto.getMedia_id()); imageMessage.setMediaId(imageMessageDto.getMedia_id());
imageMessage.setPicUrl(imageMessageDto.getPic_url()); imageMessage.setPicUrl(imageMessageDto.getPic_url());
imageMessage.setDelFlag(0); imageMessage.setDelFlag(0);
...@@ -261,7 +336,7 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS ...@@ -261,7 +336,7 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
break; break;
case "2": case "2":
//链接消息 //链接消息
WeCustomerLinkMessage linkMessage=new WeCustomerLinkMessage(); WeCustomerLinkMessage linkMessage = new WeCustomerLinkMessage();
linkMessage.setLinkMessageId(SnowFlakeUtil.nextId()); linkMessage.setLinkMessageId(SnowFlakeUtil.nextId());
linkMessage.setMessageId(messageId); linkMessage.setMessageId(messageId);
LinkMessageDto linkMessageDto = customerMessagePushDto.getLinkMessage(); LinkMessageDto linkMessageDto = customerMessagePushDto.getLinkMessage();
...@@ -274,7 +349,7 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS ...@@ -274,7 +349,7 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
break; break;
case "3": case "3":
//小程序消息 //小程序消息
WeCustomerMiniprogramMessage miniprogramMessage=new WeCustomerMiniprogramMessage(); WeCustomerMiniprogramMessage miniprogramMessage = new WeCustomerMiniprogramMessage();
miniprogramMessage.setMiniprogramMessageId(SnowFlakeUtil.nextId()); miniprogramMessage.setMiniprogramMessageId(SnowFlakeUtil.nextId());
miniprogramMessage.setMessageId(messageId); miniprogramMessage.setMessageId(messageId);
MiniprogramMessageDto miniprogramMessageDto = customerMessagePushDto.getMiniprogramMessage(); MiniprogramMessageDto miniprogramMessageDto = customerMessagePushDto.getMiniprogramMessage();
...@@ -291,31 +366,31 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS ...@@ -291,31 +366,31 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
/** /**
* 客户的外部联系人id列表,仅在chat_type为single时有效,不可与sender同时为空,最多可传入1万个客户 * 客户的外部联系人id列表,仅在chat_type为single时有效,不可与sender同时为空,最多可传入1万个客户
* *
* @param pushRange 消息范围 0 全部客户 1 指定客户 * @param pushRange 消息范围 0 全部客户 1 指定客户
* @param staffId 员工id * @param staffId 员工id
* @param department 部门id * @param department 部门id
* @param tag 客户标签id列表 * @param tag 客户标签id列表
* @return {@link List}s 客户的外部联系人id列表 * @return {@link List}s 客户的外部联系人id列表
*/ */
public List<String> externalUserIds(String pushRange, String staffId,String department,String tag){ public List<String> externalUserIds(String pushRange, String staffId, String department, String tag) {
List<String> customers= Lists.newArrayList(); List<String> customers = Lists.newArrayList();
if(pushRange.equals("0")){ if (pushRange.equals("0")) {
//查询系统所有客户 //查询系统所有客户
List<WeCustomer> weCustomers = weCustomerService.selectWeCustomerList(null); List<WeCustomer> weCustomers = weCustomerService.selectWeCustomerList(null);
if(CollectionUtils.isNotEmpty(weCustomers)){ if (CollectionUtils.isNotEmpty(weCustomers)) {
customers=weCustomers.stream().map(WeCustomer::getExternalUserid).distinct().collect(Collectors.toList()); customers = weCustomers.stream().map(WeCustomer::getExternalUserid).distinct().collect(Collectors.toList());
} }
}else { } else {
//按条件查询客户 //按条件查询客户
//通过部门id查询所有的员工 //通过部门id查询所有的员工
//通过员工列表查询该员工的外部联系人列表 //通过员工列表查询该员工的外部联系人列表
WeCustomer weCustomer=new WeCustomer(); WeCustomer weCustomer = new WeCustomer();
weCustomer.setUserIds(staffId); weCustomer.setUserIds(staffId);
weCustomer.setTagIds(tag); weCustomer.setTagIds(tag);
weCustomer.setDepartmentIds(department); weCustomer.setDepartmentIds(department);
List<WeCustomer> weCustomers = weCustomerService.selectWeCustomerList(weCustomer); List<WeCustomer> weCustomers = weCustomerService.selectWeCustomerList(weCustomer);
if(CollectionUtils.isNotEmpty(weCustomers)){ if (CollectionUtils.isNotEmpty(weCustomers)) {
customers=weCustomers.stream().map(WeCustomer::getExternalUserid).distinct().collect(Collectors.toList()); customers = weCustomers.stream().map(WeCustomer::getExternalUserid).distinct().collect(Collectors.toList());
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!