Commit 4d364d69 by 孙喜旺

Merge remote-tracking branch 'origin/back_end_dev' into back_end_dev

2 parents 60da745f 3b226b7c
package com.linkwechat.common.enums;
import lombok.Getter;
/**
* @author leejoker <1056650571@qq.com>
* @version 1.0
* @date 2021/2/9 10:31
*/
@Getter
public enum TaskFissionType {
/**
* 任务宝
*/
USER_FISSION(1, "任务宝"),
/**
* 群裂变
*/
GROUP_FISSION(2, "群裂变");
private String value;
private Integer code;
TaskFissionType(Integer code, String value) {
this.code = code;
this.value = value;
}
}
......@@ -9,6 +9,7 @@ import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotBlank;
import java.util.Date;
import java.util.List;
......@@ -103,6 +104,7 @@ public class WeTaskFission extends BaseEntity {
* 任务裂变目标员工
*/
@Excel(name = "任务裂变目标id")
@NotBlank(message = "目标员工或群活码不能为空")
@ApiModelProperty(value = "任务裂变目标id, 目标员工或者群活码id")
private String fissionTargetId;
......
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.linkwechat.wecom.domain.WeCustomerMessageOriginal;
import com.linkwechat.wecom.domain.dto.message.AsyncResultDto;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
import com.linkwechat.wecom.domain.vo.CustomerMessagePushVo;
import java.util.List;
......@@ -15,12 +16,7 @@ import java.util.List;
* @date 2020-12-12
*/
public interface IWeCustomerMessageOriginalService extends IService<WeCustomerMessageOriginal> {
/**
* 保存原始数据信息
* @param weCustomerMessageOriginal 原始数据信息
* @return
*/
int saveWeCustomerMessageOriginal(WeCustomerMessageOriginal weCustomerMessageOriginal);
/**
* 群发消息列表
......@@ -49,4 +45,12 @@ public interface IWeCustomerMessageOriginalService extends IService<WeCustomerMe
*/
void asyncResult(AsyncResultDto asyncResultDto) throws JsonProcessingException;
/**
* 保存原始数据信息表 WeCustomerMessageOriginal 主键id
*
* @param customerMessagePushDto
* @return
*/
public long saveWeCustomerMessageOriginal(CustomerMessagePushDto customerMessagePushDto);
}
package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerMessage;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 群发消息 微信消息表service接口
*
......@@ -13,12 +19,6 @@ import org.apache.ibatis.annotations.Param;
public interface IWeCustomerMessageService extends IService<WeCustomerMessage> {
/**
* @param customerMessage
* @return
*/
int updateWeCustomerMessageMsgId(WeCustomerMessage customerMessage);
/**
*
* @param messageId 微信消息表主键id
* @param actualSend 实际发送消息数(客户对应多少人 客户群对应多个群)
......@@ -26,5 +26,30 @@ public interface IWeCustomerMessageService extends IService<WeCustomerMessage> {
*/
int updateWeCustomerMessageActualSend( Long messageId, Integer actualSend);
/**
* 保存微信消息 WeCustomerMessage
* @param messageId
* @param messageOriginalId
* @param customerMessagePushDto
* @param size
*/
void saveWeCustomerMessage(long messageId, long messageOriginalId, CustomerMessagePushDto customerMessagePushDto, int size,String content);
/**
*
* @param messageId
* @param msgIds
* @throws JsonProcessingException
*/
void updateMsgId(long messageId, List<String> msgIds) throws JsonProcessingException;
/**
* 发送消息
*
* @param customerMessagePushDto 消息信息
* @param messageId
* @throws JsonProcessingException
*/
public void sendMessgae(CustomerMessagePushDto customerMessagePushDto, long messageId,List<WeCustomer> customers,List<WeGroup> groups) throws JsonProcessingException;
}
package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerMessgaeResult;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
import com.linkwechat.wecom.domain.vo.WeCustomerMessageResultVo;
import org.apache.ibatis.annotations.Param;
......@@ -24,4 +27,13 @@ public interface IWeCustomerMessgaeResultService extends IService<WeCustomerMess
*/
List<WeCustomerMessageResultVo> customerMessagePushs(Long messageId, String status);
/**
* 保存映射关系
*
* @param customerMessagePushDto
* @param messageId
* @return
*/
int workerMappingCustomer(CustomerMessagePushDto customerMessagePushDto, long messageId, List<WeCustomer> customers, List<WeGroup> groups);
}
......@@ -5,13 +5,11 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeCustomerMessagePushClient;
import com.linkwechat.wecom.domain.WeCustomerMessageOriginal;
import com.linkwechat.wecom.domain.dto.message.AsyncResultDto;
import com.linkwechat.wecom.domain.dto.message.DetailMessageStatusResultDto;
import com.linkwechat.wecom.domain.dto.message.QueryCustomerMessageStatusResultDataObjectDto;
import com.linkwechat.wecom.domain.dto.message.QueryCustomerMessageStatusResultDto;
import com.linkwechat.wecom.domain.dto.message.*;
import com.linkwechat.wecom.domain.vo.CustomerMessagePushVo;
import com.linkwechat.wecom.mapper.WeCustomerMessageOriginalMapper;
import com.linkwechat.wecom.mapper.WeCustomerMessgaeResultMapper;
......@@ -50,11 +48,6 @@ public class WeCustomerMessageOriginalServiceImpl extends ServiceImpl<WeCustomer
private ObjectMapper objectMapper;
@Override
public int saveWeCustomerMessageOriginal(WeCustomerMessageOriginal weCustomerMessageOriginal) {
return weCustomerMessageOriginalMapper.insert(weCustomerMessageOriginal);
}
@Override
public List<CustomerMessagePushVo> customerMessagePushs(String sender, String content, String pushType, String beginTime, String endTime) {
return weCustomerMessageOriginalMapper.selectCustomerMessagePushs(sender, content, pushType, beginTime, endTime);
}
......@@ -80,6 +73,23 @@ public class WeCustomerMessageOriginalServiceImpl extends ServiceImpl<WeCustomer
syncSendResult(msgid, asyncResultDto.getMessageId());
}
@Override
public long saveWeCustomerMessageOriginal(CustomerMessagePushDto customerMessagePushDto) {
//保存原始数据信息表 WeCustomerMessageOriginal 主键id
long messageOriginalId = SnowFlakeUtil.nextId();
WeCustomerMessageOriginal original = new WeCustomerMessageOriginal();
original.setMessageOriginalId(messageOriginalId);
original.setStaffId(customerMessagePushDto.getStaffId());
original.setDepartment(customerMessagePushDto.getDepartment());
original.setPushType(customerMessagePushDto.getPushType());
original.setMessageType(customerMessagePushDto.getMessageType());
original.setPushRange(customerMessagePushDto.getPushRange());
original.setTag(customerMessagePushDto.getTag());
original.setDelFlag(0);
this.save(original);
return messageOriginalId;
}
public void syncSendResult(String msgid, Long messageId) {
AtomicInteger atomicInteger = new AtomicInteger();
......
package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.enums.ChatType;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeCustomerMessagePushClient;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerMessage;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
import com.linkwechat.wecom.domain.dto.message.SendMessageResultDto;
import com.linkwechat.wecom.domain.dto.message.WeCustomerMessagePushDto;
import com.linkwechat.wecom.mapper.WeCustomerMessageMapper;
import com.linkwechat.wecom.service.IWeCustomerMessageService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 群发消息 微信消息表service接口
*
......@@ -18,14 +36,148 @@ public class WeCustomerMessageServiceImpl extends ServiceImpl<WeCustomerMessageM
@Autowired
private WeCustomerMessageMapper weCustomerMessageMapper;
@Override
public int updateWeCustomerMessageMsgId(WeCustomerMessage customerMessage) {
return weCustomerMessageMapper.updateWeCustomerMessageMsgIdById(customerMessage);
}
@Autowired
private ObjectMapper objectMapper;
@Autowired
private WeCustomerMessagePushClient weCustomerMessagePushClient;
@Override
public int updateWeCustomerMessageActualSend(Long messageId, Integer actualSend) {
return weCustomerMessageMapper.updateWeCustomerMessageActualSend(messageId, actualSend);
}
@Override
public void saveWeCustomerMessage(long messageId, long messageOriginalId, CustomerMessagePushDto customerMessagePushDto, int size,String content) {
//保存微信消息
//微信群发消息表 WeCustomerMessage
WeCustomerMessage customerMessage = new WeCustomerMessage();
customerMessage.setOriginalId(messageOriginalId);
customerMessage.setMessageId(messageId);
customerMessage.setChatType(customerMessagePushDto.getPushType());
// customerMessage.setExternalUserid(objectMapper.writeValueAsString(customers));
// customerMessage.setSender(objectMapper.writeValueAsString(senders));
customerMessage.setCheckStatus("0");
customerMessage.setDelFlag(0);
customerMessage.setContent(content);
customerMessage.setCreateBy(SecurityUtils.getUsername());
customerMessage.setMsgid("");
if(StringUtils.isNotEmpty(customerMessagePushDto.getSettingTime())){
customerMessage.setSettingTime(customerMessagePushDto.getSettingTime());
customerMessage.setTimedTask(1);
}else {
customerMessage.setTimedTask(0);
}
customerMessage.setExpectSend(size);
customerMessage.setActualSend(0);
this.save(customerMessage);
}
@Override
public void updateMsgId(long messageId, List<String> msgIds) throws JsonProcessingException {
//通过messageId更新msgIds
WeCustomerMessage weCustomerMessage = new WeCustomerMessage();
weCustomerMessage.setMessageId(messageId);
weCustomerMessage.setMsgid(objectMapper.writeValueAsString(msgIds));
weCustomerMessageMapper.updateWeCustomerMessageMsgIdById(weCustomerMessage);
}
@Override
public void sendMessgae(CustomerMessagePushDto customerMessagePushDto, long messageId,List<WeCustomer> customers,List<WeGroup> groups) throws JsonProcessingException {
List<String> msgid = new ArrayList<>();
//发送群发消息
//发送类类型: 给单个客户发,群发
//发给客户
if (customerMessagePushDto.getPushType().equals("0")) {
WeCustomerMessagePushDto messagePushDto = new WeCustomerMessagePushDto();
messagePushDto.setChat_type(ChatType.of(customerMessagePushDto.getPushType()).getName());
List<String> externalUserIds = customers.stream().map(WeCustomer::getExternalUserid).collect(Collectors.toList());
messagePushDto.setExternal_userid(externalUserIds);
childMessage(messagePushDto, customerMessagePushDto);
SendMessageResultDto sendMessageResultDto = weCustomerMessagePushClient.sendCustomerMessageToUser(messagePushDto);
if (WeConstans.WE_SUCCESS_CODE.equals(sendMessageResultDto.getErrcode())) {
msgid.add(sendMessageResultDto.getMsgid());
}
}
//发给客户群
if (customerMessagePushDto.getPushType().equals("1")) {
if (CollectionUtils.isNotEmpty(groups)) {
List<String> owners = groups.stream().map(WeGroup::getOwner).collect(Collectors.toList());
for (String owner : owners) {
WeCustomerMessagePushDto messagePushDto = new WeCustomerMessagePushDto();
messagePushDto.setChat_type(ChatType.of(customerMessagePushDto.getPushType()).getName());
//客户群的员工id
messagePushDto.setSender(owner);
childMessage(messagePushDto, customerMessagePushDto);
SendMessageResultDto sendMessageResultDto = weCustomerMessagePushClient.sendCustomerMessageToUser(messagePushDto);
if (WeConstans.WE_SUCCESS_CODE.equals(sendMessageResultDto.getErrcode())) {
//发送的msgId
msgid.add(sendMessageResultDto.getMsgid());
}
}
}
}
this.updateMsgId(messageId, msgid);
}
/**
* 子消息体
*
* @param weCustomerMessagePushDto 群发消息体
* @param customerMessagePushDto 群发消息
*/
public void childMessage(WeCustomerMessagePushDto weCustomerMessagePushDto, CustomerMessagePushDto customerMessagePushDto) {
// 消息类型 0 文本消息 1 图片消息 2 链接消息 3 小程序消息
if (customerMessagePushDto.getMessageType().equals("0")) {
weCustomerMessagePushDto.setImage(null);
weCustomerMessagePushDto.setLink(null);
weCustomerMessagePushDto.setMiniprogram(null);
weCustomerMessagePushDto.setText(customerMessagePushDto.getTextMessage());
}
if (customerMessagePushDto.getMessageType().equals("1")) {
weCustomerMessagePushDto.setImage(customerMessagePushDto.getImageMessage());
weCustomerMessagePushDto.setLink(null);
weCustomerMessagePushDto.setMiniprogram(null);
weCustomerMessagePushDto.setText(null);
}
if (customerMessagePushDto.getMessageType().equals("2")) {
weCustomerMessagePushDto.setImage(null);
weCustomerMessagePushDto.setLink(customerMessagePushDto.getLinkMessage());
weCustomerMessagePushDto.setMiniprogram(null);
weCustomerMessagePushDto.setText(null);
}
if (customerMessagePushDto.getMessageType().equals("3")) {
weCustomerMessagePushDto.setImage(null);
weCustomerMessagePushDto.setLink(null);
weCustomerMessagePushDto.setMiniprogram(customerMessagePushDto.getMiniprogramMessage());
weCustomerMessagePushDto.setText(null);
}
if(customerMessagePushDto.getMessageType().equals("4")){
weCustomerMessagePushDto.setImage(customerMessagePushDto.getImageMessage());
weCustomerMessagePushDto.setLink(null);
weCustomerMessagePushDto.setMiniprogram(null);
weCustomerMessagePushDto.setText(customerMessagePushDto.getTextMessage());
}
}
}
package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerMessgaeResult;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
import com.linkwechat.wecom.domain.vo.WeCustomerMessageResultVo;
import com.linkwechat.wecom.mapper.WeCustomerMessgaeResultMapper;
import com.linkwechat.wecom.service.IWeCustomerMessgaeResultService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -27,4 +34,62 @@ public class WeCustomerMessgaeResultServiceImpl extends ServiceImpl<WeCustomerMe
return customerMessgaeResultMapper.customerMessagePushs(messageId, status);
}
@Override
public int workerMappingCustomer(CustomerMessagePushDto customerMessagePushDto, long messageId,List<WeCustomer> customers,List<WeGroup> groups) {
int size = 0;
// 0 发给客户
if (customerMessagePushDto.getPushType().equals("0")) {
if (CollectionUtils.isNotEmpty(customers)) {
size = customers.size();
customers.forEach(customer -> {
//微信消息发送结果、保存员工客户关系映射关系数据
WeCustomerMessgaeResult customerMessgaeResult = new WeCustomerMessgaeResult();
customerMessgaeResult.setMessgaeResultId(SnowFlakeUtil.nextId());
customerMessgaeResult.setMessageId(messageId);
//这个是实际发送时间
customerMessgaeResult.setSendTime(null);
customerMessgaeResult.setSendType(customerMessgaeResult.getSettingTime() == null ? customerMessagePushDto.getPushType() : "2");
customerMessgaeResult.setExternalUserid(customer.getExternalUserid());
customerMessgaeResult.setExternalName(customer.getName());
customerMessgaeResult.setUserid(customer.getUserId());
customerMessgaeResult.setUserName(customer.getUserName());
customerMessgaeResult.setStatus("0");
customerMessgaeResult.setSettingTime(customerMessagePushDto.getSettingTime());
customerMessgaeResult.setDelFlag(0);
this.save(customerMessgaeResult);
});
}
}
// 1 发给客户群
if (customerMessagePushDto.getPushType().equals("1")) {
if (CollectionUtils.isNotEmpty(groups)) {
size = groups.size();
groups.forEach(group -> {
//微信消息发送结果、保存员工客户关系映射关系数据
WeCustomerMessgaeResult customerMessgaeResult = new WeCustomerMessgaeResult();
customerMessgaeResult.setMessgaeResultId(SnowFlakeUtil.nextId());
customerMessgaeResult.setMessageId(messageId);
customerMessgaeResult.setSendTime(customerMessagePushDto.getSettingTime());
customerMessgaeResult.setSendType(customerMessgaeResult.getSettingTime() == null ? customerMessagePushDto.getPushType() : "2");
customerMessgaeResult.setSettingTime(customerMessagePushDto.getSettingTime());
customerMessgaeResult.setChatId(group.getChatId());
customerMessgaeResult.setChatName(group.getGroupName());
customerMessgaeResult.setStatus("0");
//群管理员id
customerMessgaeResult.setUserid(group.getGroupLeader());
//群管理员名称
customerMessgaeResult.setUserName(group.getGroupLeaderName());
customerMessgaeResult.setDelFlag(0);
this.save(customerMessgaeResult);
});
}
}
return size;
}
}
......@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.enums.TaskFissionType;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
......@@ -49,6 +50,8 @@ public class WeTaskFissionServiceImpl implements IWeTaskFissionService {
private WeExternalContactClient weExternalContactClient;
@Autowired
private IWePosterService wePosterService;
@Autowired
private IWeGroupCodeService weGroupCodeService;
@Value("${H5.url}")
private String pageUrl;
......@@ -85,6 +88,7 @@ public class WeTaskFissionServiceImpl implements IWeTaskFissionService {
public int insertWeTaskFission(WeTaskFission weTaskFission) {
weTaskFission.setCreateBy(SecurityUtils.getUsername());
weTaskFission.setCreateTime(DateUtils.getNowDate());
groupQrcodeHandler(weTaskFission);
int insertResult = weTaskFissionMapper.insertWeTaskFission(weTaskFission);
if (insertResult > 0) {
if (CollectionUtils.isNotEmpty(weTaskFission.getTaskFissionStaffs())) {
......@@ -108,6 +112,7 @@ public class WeTaskFissionServiceImpl implements IWeTaskFissionService {
@Override
public int updateWeTaskFission(WeTaskFission weTaskFission) {
weTaskFission.setUpdateTime(DateUtils.getNowDate());
weTaskFission.setUpdateBy(SecurityUtils.getUsername());
return weTaskFissionMapper.updateWeTaskFission(weTaskFission);
}
......@@ -191,12 +196,6 @@ public class WeTaskFissionServiceImpl implements IWeTaskFissionService {
if (user != null) {
WeTaskFissionRecord record = getTaskFissionRecordId(weTaskFissionPosterDTO.getTaskFissionId(), user.getUserId(), user.getName());
String qrcode = getPosterQRCode(weTaskFissionPosterDTO.getFissStaffId(), record);
//保存qrcode信息
WeTaskFission taskFission = weTaskFissionMapper.selectWeTaskFissionById(weTaskFissionPosterDTO.getTaskFissionId());
taskFission.setFissQrcode(qrcode);
weTaskFissionMapper.updateWeTaskFission(taskFission);
WePoster poster = wePosterService.selectOne(weTaskFissionPosterDTO.getPosterId());
poster.getPosterSubassemblyList().stream().filter(Objects::nonNull)
.filter(wePosterSubassembly -> wePosterSubassembly.getType() == 3).forEach(wePosterSubassembly -> {
......@@ -254,4 +253,16 @@ public class WeTaskFissionServiceImpl implements IWeTaskFissionService {
}
return recordInfo;
}
private void groupQrcodeHandler(WeTaskFission weTaskFission) {
String groupQrcodeId = weTaskFission.getFissionTargetId();
if (weTaskFission.getFissionType() != null && weTaskFission.getFissionType().equals(TaskFissionType.GROUP_FISSION.getCode())
&& StringUtils.isNotBlank(groupQrcodeId) && StringUtils.isBlank(weTaskFission.getFissQrcode())) {
WeGroupCode groupCode = weGroupCodeService.selectWeGroupCodeById(Long.parseLong(groupQrcodeId));
if (groupCode != null) {
String qrcodeUrl = groupCode.getCodeUrl();
weTaskFission.setFissQrcode(qrcodeUrl);
}
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!