Commit 86fec3e7 by danmo

群发任务重构

1 parent f4910866
......@@ -8,7 +8,6 @@ import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.wecom.domain.WeGroupMessageTemplate;
import com.linkwechat.wecom.domain.query.WeAddGroupMessageQuery;
import com.linkwechat.wecom.domain.vo.WeGroupMessageDetailVo;
import com.linkwechat.wecom.domain.vo.WeGroupMessageListVo;
import com.linkwechat.wecom.service.IWeGroupMessageTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -67,15 +66,27 @@ public class WeGroupMessageTemplateController extends BaseController {
return AjaxResult.success();
}
/**
* 同步消息发送结果
*/
//@PreAuthorize("@ss.hasPermi('linkwechat:template:remove')")
@ApiOperation(value = "同步消息发送结果", httpMethod = "GET")
@Log(title = "群发消息模板", businessType = BusinessType.OTHER)
@GetMapping("/sync/{ids}")
public AjaxResult sync(@PathVariable Long[] ids) {
iWeGroupMessageTemplateService.syncGroupMsgSendResultByIds(Arrays.asList(ids));
return AjaxResult.success();
}
/**
* 删除群发消息模板
* 取消定时发送
*/
//@PreAuthorize("@ss.hasPermi('linkwechat:template:remove')")
@ApiOperation(value = "取消发送", httpMethod = "DELETE")
@Log(title = "群发消息模板", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(iWeGroupMessageTemplateService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
@ApiOperation(value = "取消定时发送", httpMethod = "GET")
@Log(title = "群发消息模板", businessType = BusinessType.UPDATE)
@GetMapping("/cancel/{ids}")
public AjaxResult cancel(@PathVariable Long[] ids) {
iWeGroupMessageTemplateService.cancelByIds(Arrays.asList(ids));
return AjaxResult.success();
}
}
......@@ -10,7 +10,7 @@ import lombok.Data;
import java.util.List;
/**
* @author sxw
* @author danmo
* @description 添加群发消息入参
* @date 2021/10/24 12:14
**/
......
......@@ -10,7 +10,7 @@ import lombok.Data;
import java.util.List;
/**
* @author sxw
* @author danmo
* @description 群发详情出参
* @date 2021/10/23 15:09
**/
......
......@@ -10,7 +10,7 @@ import lombok.Data;
import java.util.List;
/**
* @author sxw
* @author danmo
* @description 群发详情出参
* @date 2021/10/23 15:09
**/
......
......@@ -13,7 +13,7 @@ import java.util.Date;
import java.util.List;
/**
* @author sxw
* @author danmo
* @description 群发成员任务出参
* @date 2021/10/23 15:09
**/
......
......@@ -32,4 +32,16 @@ public interface IWeGroupMessageTemplateService extends IService<WeGroupMessageT
* @param query
*/
void addGroupMsgTemplate(WeAddGroupMessageQuery query);
/**
* 取消定时发送
* @param asList
*/
void cancelByIds(List<Long> asList);
/**
* 同步消息发送结果
* @param asList
*/
void syncGroupMsgSendResultByIds(List<Long> asList);
}
......@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeCustomerMessagePushClient;
import com.linkwechat.wecom.domain.WeGroupMessageSendResult;
import com.linkwechat.wecom.domain.WeGroupMessageTask;
import com.linkwechat.wecom.domain.dto.message.WeGroupMsgListDto;
import com.linkwechat.wecom.domain.dto.message.WeGroupMsgSendDto;
import com.linkwechat.wecom.domain.query.WeGetGroupMsgListQuery;
......@@ -78,11 +79,15 @@ public class WeGroupMessageSendResultServiceImpl extends ServiceImpl<WeGroupMess
public void addOrUpdateBatchByCondition(List<WeGroupMessageSendResult> sendResultList) {
if (CollectionUtil.isNotEmpty(sendResultList)) {
sendResultList.forEach(item -> {
if (!this.update(item, new LambdaQueryWrapper<WeGroupMessageSendResult>()
.eq(WeGroupMessageSendResult::getMsgId, item.getMsgId())
LambdaQueryWrapper<WeGroupMessageSendResult> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(WeGroupMessageSendResult::getMsgId, item.getMsgId())
.eq(WeGroupMessageSendResult::getExternalUserid, item.getExternalUserid())
.eq(WeGroupMessageSendResult::getUserId, item.getUserId())
.eq(WeGroupMessageSendResult::getChatId, item.getChatId()))) {
.eq(WeGroupMessageSendResult::getChatId, item.getChatId());
if(item.getMsgTemplateId() != null){
wrapper.eq(WeGroupMessageSendResult::getMsgTemplateId,item.getMsgTemplateId());
}
if (!this.update(item, wrapper)) {
this.save(item);
}
});
......
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.utils.StringUtils;
......@@ -52,9 +53,12 @@ public class WeGroupMessageTaskServiceImpl extends ServiceImpl<WeGroupMessageTas
public void addOrUpdateBatchByCondition(List<WeGroupMessageTask> taskList) {
if (CollectionUtil.isNotEmpty(taskList)) {
taskList.forEach(item -> {
if (!this.update(item, new LambdaQueryWrapper<WeGroupMessageTask>()
.eq(WeGroupMessageTask::getMsgId, item.getMsgId())
.eq(WeGroupMessageTask::getUserId, item.getUserId()))) {
LambdaQueryWrapper<WeGroupMessageTask> wrapper = new LambdaQueryWrapper<>();
if(item.getMsgTemplateId() != null){
wrapper.eq(WeGroupMessageTask::getMsgTemplateId,item.getMsgTemplateId());
}
wrapper.eq(WeGroupMessageTask::getMsgId, item.getMsgId()).eq(WeGroupMessageTask::getUserId, item.getUserId());
if (!this.update(item,wrapper)){
this.save(item);
}
});
......
......@@ -11,6 +11,7 @@ import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.enums.MessageType;
import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.dto.message.WeGroupMsgListDto;
import com.linkwechat.wecom.domain.query.WeAddGroupMessageQuery;
import com.linkwechat.wecom.domain.vo.WeGroupMessageDetailVo;
import com.linkwechat.wecom.domain.vo.WeGroupMessageListVo;
......@@ -19,13 +20,11 @@ import com.linkwechat.wecom.mapper.WeGroupMessageTemplateMapper;
import com.linkwechat.wecom.service.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -215,29 +214,62 @@ public class WeGroupMessageTemplateServiceImpl extends ServiceImpl<WeGroupMessag
}
}
/*senderList.forEach(sender ->{
WeAddMsgTemplateQuery templateQuery = new WeAddMsgTemplateQuery();
templateQuery.setChat_type(query.getChatType());
templateQuery.setSender(sender.getUserId());
if(ObjectUtil.equal(1,query.getChatType())){
templateQuery.setExternal_userid(sender.getCustomerList());
}
templateQuery.setAttachments(query.getAttachmentsList());
if(StringUtils.isNotEmpty(query.getContent())){
WeAddMsgTemplateQuery.Text text = new WeAddMsgTemplateQuery.Text();
text.setContent(query.getContent());
templateQuery.setText(text);
}
SendMessageResultDto resultDto = customerMessagePushClient.addMsgTemplate(templateQuery);
if(resultDto != null && ObjectUtil.equal(WeConstans.WE_SUCCESS_CODE,resultDto.getErrcode())){
String msgid = resultDto.getMsgid();
Long msgTemplateId = weGroupMessageTemplate.getId();
WeGroupMessageList messageList = new WeGroupMessageList();
messageList.setMsgId(msgid);
messageList.setMsgTemplateId(msgTemplateId);
}
});*/
}
@Override
public void cancelByIds(List<Long> asList) {
List<WeGroupMessageTemplate> weGroupMessageTemplates = listByIds(asList);
if(CollectionUtil.isNotEmpty(weGroupMessageTemplates)){
weGroupMessageTemplates.forEach(weGroupMessageTemplate -> {
weGroupMessageTemplate.setStatus(2);
long time = weGroupMessageTemplate.getSendTime().getTime();
redisCache.removeRangeCacheZSet(WeConstans.WEGROUPMSGTIMEDTASK_KEY,time,time);
});
updateBatchById(weGroupMessageTemplates);
}
}
@Async
@Override
public void syncGroupMsgSendResultByIds(List<Long> asList) {
List<WeGroupMessageList> weGroupMessageLists = weGroupMessageListService.list(new LambdaQueryWrapper<WeGroupMessageList>()
.in(WeGroupMessageList::getMsgTemplateId, asList));
List<WeGroupMessageTask> taskList = new ArrayList<>();
List<WeGroupMessageSendResult> sendResultlist = new ArrayList<>();
if(CollectionUtil.isNotEmpty(weGroupMessageLists)){
weGroupMessageLists.forEach(weGroupMessageList -> {
WeGroupMsgListDto groupMsgTask = messageTaskService.getGroupMsgTask(weGroupMessageList.getMsgId(), null);
Optional.ofNullable(groupMsgTask).map(WeGroupMsgListDto::getTaskList).orElseGet(ArrayList::new).forEach(msgTask -> {
WeGroupMessageTask messageTask = new WeGroupMessageTask();
messageTask.setMsgId(weGroupMessageList.getMsgId());
messageTask.setUserId(msgTask.getUserId());
if(msgTask.getSendTime() != null){
messageTask.setSendTime(new Date(msgTask.getSendTime() * 1000));
}
messageTask.setMsgTemplateId(weGroupMessageList.getMsgTemplateId());
messageTask.setStatus(msgTask.getStatus());
taskList.add(messageTask);
WeGroupMsgListDto groupMsgSendResult = messageSendResultService.getGroupMsgSendResult(weGroupMessageList.getMsgId(), msgTask.getUserId(), null);
Optional.ofNullable(groupMsgSendResult).map(WeGroupMsgListDto::getSendList).orElseGet(ArrayList::new).forEach(sendResult -> {
WeGroupMessageSendResult messageSendResult = new WeGroupMessageSendResult();
messageSendResult.setMsgId(weGroupMessageList.getMsgId());
messageSendResult.setUserId(msgTask.getUserId());
messageSendResult.setChatId(sendResult.getChatId());
messageSendResult.setExternalUserid(sendResult.getExternalUserId());
if(sendResult.getSendTime() != null){
messageSendResult.setSendTime(new Date(sendResult.getSendTime() * 1000));
}
messageSendResult.setStatus(sendResult.getStatus());
messageSendResult.setMsgTemplateId(weGroupMessageList.getMsgTemplateId());
sendResultlist.add(messageSendResult);
});
});
});
}
messageTaskService.addOrUpdateBatchByCondition(taskList);
messageSendResultService.addOrUpdateBatchByCondition(sendResultlist);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!