增加了流程完结钉钉和短信通知

This commit is contained in:
459816669@qq.com 2021-03-06 18:52:04 +08:00
parent 0192b6a07e
commit 220efe669c
16 changed files with 402 additions and 44 deletions

View File

@ -6,9 +6,9 @@ spring:
druid:
# 主库数据源
master:
url: jdbc:mysql://localhost:3306/snow?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
url: jdbc:mysql://rm-bp1j1554xv1qs04295o.mysql.rds.aliyuncs.com:3306/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: cloud_root
password: Jin!152377
# 从库数据源
slave:
# 从数据源开关/默认关闭

View File

@ -136,4 +136,6 @@ public class Constants
* 邮件消息类型
*/
public static final Integer NEWS_EMAIL_TYPE=2;
}

View File

@ -0,0 +1,29 @@
package com.snow.common.constant;
/**
* @program: snow
* @description
* @author: 没用的阿吉
* @create: 2021-03-06 16:27
**/
public class MessageConstants {
/**
*发起流程通知
*/
public static final String PROCESS_STARTED_CODE="1367475870205353984";
/**
* 待办消息通知
*/
public static final String TASK_CREATED_CODE="1365961987292536832";
/**
* 流程完结通知
*/
public static final String PROCESS_COMPLETED_CODE="1368128438703104000";
}

View File

@ -26,6 +26,12 @@ public enum DingTalkListenerType {
CALL_BACK_FAILED_RESULT(23,10, "获取回调失败结果"),
WORK_RECODE_CREATE(1,20, "创建待办"),
GET_WORK_RECORD_USER(2,20,"获取用户待办"),
WORK_RECORD_UPDATE(3,20,"更新待办"),
ASYNCSEND_V2(10,20,"发送消息")
;

View File

@ -0,0 +1,33 @@
package com.snow.common.enums;
/**
* @author qimingjin
* @Title: 交易类型枚举
* @Description:
* @date 2021/2/26 11:25
*/
public enum DingTalkMessageType {
TEXT(1, "text"),
LINK(2, "link");
private final Integer code;
private final String info;
DingTalkMessageType(Integer code, String info)
{
this.code = code;
this.info = info;
}
public Integer getCode()
{
return code;
}
public String getInfo()
{
return info;
}
}

View File

@ -1,6 +1,7 @@
package com.snow.common.utils;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -27,6 +28,8 @@ public class PatternUtils {
StringBuffer sb = new StringBuffer();
while (m.find()) {
if(null==m)
continue;
String group = m.group(1);
m.appendReplacement(sb, map.get(group));
}

View File

@ -57,6 +57,9 @@ public class ServletUtils
*/
public static HttpServletRequest getRequest()
{
if(getRequestAttributes()==null){
return null;
}
return getRequestAttributes().getRequest();
}

View File

@ -23,7 +23,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.Optional;
/**
* 操作日志记录处理
@ -99,8 +101,7 @@ public class SyncLogAspect
// 返回参数
sysDingtalkSyncLog.setJsonResult(StringUtils.substring(JSON.marshal(jsonResult), 0, 2000));
sysDingtalkSyncLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
Optional.ofNullable(ServletUtils.getRequest()).ifPresent(t->sysDingtalkSyncLog.setOperUrl(ServletUtils.getRequest().getRequestURI()));
if (e != null)
{
if(e instanceof SyncDataException){
@ -123,7 +124,8 @@ public class SyncLogAspect
sysDingtalkSyncLog.setMethod(className + "." + methodName + "()");
// 设置请求方式
sysDingtalkSyncLog.setRequestMethod(ServletUtils.getRequest().getMethod());
Optional.ofNullable(ServletUtils.getRequest()).ifPresent(t->sysDingtalkSyncLog.setRequestMethod(ServletUtils.getRequest().getMethod()));
// 处理设置注解上的参数
getControllerMethodDescription(controllerLog,joinPoint, sysDingtalkSyncLog);
// 保存数据库

View File

@ -82,6 +82,9 @@ public class BaseConstantUrl {
public static final String CALL_BACK_FAILED_RESULT = "https://oapi.dingtalk.com/call_back/get_call_back_failed_result";
/**
* 发送普通消息
*/
public static final String ASYNCSEND_V2="https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2";
}

View File

@ -5,6 +5,7 @@ import com.snow.common.enums.DingTalkListenerType;
import com.snow.common.utils.spring.SpringUtils;
import com.snow.dingtalk.model.WorkrecordAddRequest;
import com.snow.dingtalk.service.impl.WorkRecodeServiceImpl;
import com.snow.framework.web.domain.common.SysSendMessageDTO;
import com.snow.system.event.SyncEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -26,9 +27,16 @@ public class WorkRecodeService implements ISyncDingTalkInfo {
log.info("调用工作通知传入的原始参数:{}",JSON.toJSONString(syncEvent));
DingTalkListenerType eventType =(DingTalkListenerType) syncEvent.getT();
Integer code = eventType.getCode();
//钉钉创建待办
if(code.equals(DingTalkListenerType.WORK_RECODE_CREATE.getCode())){
WorkrecordAddRequest workrecordAddRequest=(WorkrecordAddRequest)syncEvent.getSource();
workRecodeService.create(workrecordAddRequest);
}
//钉钉发送普通消息
else if(code.equals(DingTalkListenerType.ASYNCSEND_V2.getCode())){
SysSendMessageDTO sysSendMessageDTO=(SysSendMessageDTO)syncEvent.getSource();
workRecodeService.sendCommonMessage(sysSendMessageDTO);
}
}
}

View File

@ -0,0 +1,56 @@
package com.snow.dingtalk.model;
import com.snow.common.enums.DingTalkMessageType;
import lombok.Data;
import java.io.Serializable;
/**
* @program: snow
* @description 发送消息请求类
* @author: 没用的阿吉
* @create: 2021-03-06 15:54
**/
@Data
public class SendCommonMessageRequest implements Serializable {
/**
* 模板Code
*/
private String templateByCode;
/**
* 消息
*/
private String msg;
/**
* 是否发给所有人
*/
private Boolean toAllUser=false;
/**
* 钉钉用户id
*/
private String userIdList;
/**
* 消息类型
*/
private DingTalkMessageType dingTalkMessageType;
/**
* 消息URL
*/
private String messageUrl;
/**
* 图片url
*/
private String picUrl;
/**
* 标题
*/
private String title;
}

View File

@ -1,22 +1,9 @@
package com.snow.dingtalk.service;
import com.alibaba.fastjson.JSON;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiWorkrecordAddRequest;
import com.dingtalk.api.request.OapiWorkrecordGetbyuseridRequest;
import com.dingtalk.api.request.OapiWorkrecordUpdateRequest;
import com.dingtalk.api.response.OapiWorkrecordAddResponse;
import com.dingtalk.api.response.OapiWorkrecordGetbyuseridResponse;
import com.dingtalk.api.response.OapiWorkrecordUpdateResponse;
import com.snow.dingtalk.common.BaseConstantUrl;
import com.snow.dingtalk.common.BaseService;
import com.snow.dingtalk.model.WorkrecordAddRequest;
import com.snow.dingtalk.model.WorkrecordGetbyuseridRequest;
import com.snow.system.service.ISysConfigService;
import com.taobao.api.ApiException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.snow.framework.web.domain.common.SysSendMessageDTO;
import org.springframework.stereotype.Service;
/**
@ -49,4 +36,10 @@ public interface WorkRecodeService {
* @return
*/
Boolean update(String userId,String recordId);
/**
* 钉钉发送消息
* @param sysSendMessageDTO
*/
Long sendCommonMessage(SysSendMessageDTO sysSendMessageDTO);
}

View File

@ -3,24 +3,34 @@ package com.snow.dingtalk.service.impl;
import com.alibaba.fastjson.JSON;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
import com.dingtalk.api.request.OapiWorkrecordAddRequest;
import com.dingtalk.api.request.OapiWorkrecordGetbyuseridRequest;
import com.dingtalk.api.request.OapiWorkrecordUpdateRequest;
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
import com.dingtalk.api.response.OapiWorkrecordAddResponse;
import com.dingtalk.api.response.OapiWorkrecordGetbyuseridResponse;
import com.dingtalk.api.response.OapiWorkrecordUpdateResponse;
import com.snow.common.annotation.SyncLog;
import com.snow.common.constant.Constants;
import com.snow.common.enums.DingTalkListenerType;
import com.snow.common.enums.DingTalkMessageType;
import com.snow.common.exception.SyncDataException;
import com.snow.common.utils.PatternUtils;
import com.snow.common.utils.spring.SpringUtils;
import com.snow.dingtalk.common.BaseConstantUrl;
import com.snow.dingtalk.common.BaseService;
import com.snow.dingtalk.model.WorkrecordAddRequest;
import com.snow.dingtalk.model.WorkrecordGetbyuseridRequest;
import com.snow.system.service.ISysConfigService;
import com.snow.dingtalk.service.WorkRecodeService;
import com.snow.framework.web.domain.common.SysSendMessageDTO;
import com.snow.system.domain.SysMessageTemplate;
import com.snow.system.service.ISysMessageTemplateService;
import com.snow.system.service.impl.SysConfigServiceImpl;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@ -31,13 +41,19 @@ import org.springframework.stereotype.Service;
*/
@Slf4j
@Service
public class WorkRecodeServiceImpl extends BaseService {
public class WorkRecodeServiceImpl extends BaseService implements WorkRecodeService {
private SysConfigServiceImpl isysConfigService=SpringUtils.getBean(SysConfigServiceImpl.class);
private ISysMessageTemplateService sysMessageTemplateService=SpringUtils.getBean(ISysMessageTemplateService.class);
/**
* 创建工作待办
* @param workrecordAddRequest
* @return
*/
@SyncLog(dingTalkListenerType = DingTalkListenerType.WORK_RECODE_CREATE,dingTalkUrl=BaseConstantUrl.WORK_RECORD_CREATE)
@Override
public String create(WorkrecordAddRequest workrecordAddRequest){
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.WORK_RECORD_CREATE);
OapiWorkrecordAddRequest req = new OapiWorkrecordAddRequest();
@ -62,6 +78,8 @@ public class WorkRecodeServiceImpl extends BaseService {
* @param workrecordGetbyuseridRequest
* @return
*/
@Override
@SyncLog(dingTalkListenerType = DingTalkListenerType.GET_WORK_RECORD_USER,dingTalkUrl=BaseConstantUrl.GET_WORK_RECORD_USER_ID_)
public OapiWorkrecordGetbyuseridResponse.PageResult getWorkRecordByUserId(WorkrecordGetbyuseridRequest workrecordGetbyuseridRequest){
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.GET_WORK_RECORD_USER_ID_);
OapiWorkrecordGetbyuseridRequest req = new OapiWorkrecordGetbyuseridRequest();
@ -72,16 +90,14 @@ public class WorkRecodeServiceImpl extends BaseService {
try {
OapiWorkrecordGetbyuseridResponse rsp = client.execute(req, getDingTalkToken());
if(rsp.getErrcode()==0){
syncDingTalkErrorOperLog(BaseConstantUrl.GET_WORK_RECORD_USER_ID_,rsp.getMessage(),"WorkrecordGetbyuseridRequest",JSON.toJSONString(req));
return rsp.getRecords();
}else {
syncDingTalkErrorOperLog(BaseConstantUrl.GET_WORK_RECORD_USER_ID_,rsp.getErrmsg(),"WorkrecordGetbyuseridRequest",JSON.toJSONString(req));
throw new SyncDataException(JSON.toJSONString(req),rsp.getErrmsg());
}
} catch (ApiException e) {
e.printStackTrace();
syncDingTalkErrorOperLog(BaseConstantUrl.GET_WORK_RECORD_USER_ID_,e.getMessage(),"WorkrecordGetbyuseridRequest",JSON.toJSONString(req));
log.error("钉钉workRecordAddRequest异常{}",e.getErrMsg());
throw new SyncDataException(JSON.toJSONString(req),e.getErrMsg());
}
return null;
}
/**
@ -90,6 +106,8 @@ public class WorkRecodeServiceImpl extends BaseService {
* @param recordId
* @return
*/
@Override
@SyncLog(dingTalkListenerType = DingTalkListenerType.WORK_RECORD_UPDATE,dingTalkUrl=BaseConstantUrl.WORK_RECORD_UPDATE)
public Boolean update(String userId,String recordId){
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.WORK_RECORD_UPDATE);
OapiWorkrecordUpdateRequest req = new OapiWorkrecordUpdateRequest();
@ -99,15 +117,64 @@ public class WorkRecodeServiceImpl extends BaseService {
try {
rsp = client.execute(req, getDingTalkToken());
if(rsp.getErrcode()==0){
syncDingTalkErrorOperLog(BaseConstantUrl.WORK_RECORD_UPDATE,rsp.getMessage(),"WorkrecordUpdateRequest",JSON.toJSONString(req));
return rsp.getResult();
}else {
syncDingTalkErrorOperLog(BaseConstantUrl.WORK_RECORD_UPDATE,rsp.getErrmsg(),"WorkrecordUpdateRequest",JSON.toJSONString(req));
throw new SyncDataException(JSON.toJSONString(req),rsp.getErrmsg());
}
} catch (ApiException e) {
e.printStackTrace();
syncDingTalkErrorOperLog(BaseConstantUrl.WORK_RECORD_UPDATE,e.getMessage(),"WorkrecordUpdateRequest",JSON.toJSONString(req));
log.error("钉钉workRecordAddRequest异常{}",e.getErrMsg());
throw new SyncDataException(JSON.toJSONString(req),e.getErrMsg());
}
}
@Override
@SyncLog(dingTalkListenerType = DingTalkListenerType.ASYNCSEND_V2,dingTalkUrl=BaseConstantUrl.ASYNCSEND_V2)
public Long sendCommonMessage(SysSendMessageDTO sysSendMessageDTO) {
SysMessageTemplate sysMessageTemplate= sysMessageTemplateService.getSysMessageTemplateByCode(sysSendMessageDTO.getTemplateByCode());
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.ASYNCSEND_V2);
OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request();
request.setAgentId(Long.parseLong(isysConfigService.selectConfigByKey(Constants.AGENT_ID)));
String userIdList = StringUtils.join(sysSendMessageDTO.getReceiverSet(), ",");
request.setUseridList(userIdList);
request.setToAllUser(sysSendMessageDTO.getToAllUser());
OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
if(sysSendMessageDTO.getDingTalkMessageType().equals(DingTalkMessageType.LINK)){
msg.setMsgtype(DingTalkMessageType.LINK.getInfo());
msg.setLink(new OapiMessageCorpconversationAsyncsendV2Request.Link());
msg.getLink().setTitle(sysMessageTemplate.getTemplateName());
String content= PatternUtils.builderTemplateBody(sysSendMessageDTO.getParamMap(), sysMessageTemplate.getTemplateBody());
msg.getLink().setText(content);
msg.getLink().setMessageUrl(sysSendMessageDTO.getFilePath());
msg.getLink().setPicUrl(sysSendMessageDTO.getFilePath());
}
if(sysSendMessageDTO.getDingTalkMessageType().equals(DingTalkMessageType.TEXT)){
msg.setMsgtype(DingTalkMessageType.TEXT.getInfo());
msg.setText(new OapiMessageCorpconversationAsyncsendV2Request.Text());
String content= PatternUtils.builderTemplateBody(sysSendMessageDTO.getParamMap(), sysMessageTemplate.getTemplateBody());
msg.getText().setContent(content);
}
request.setMsg(msg);
OapiMessageCorpconversationAsyncsendV2Response rsp = null;
try {
rsp = client.execute(request, getDingTalkToken());
if(rsp.getErrcode()==0){
return rsp.getTaskId();
}else {
throw new SyncDataException(JSON.toJSONString(request),rsp.getErrmsg());
}
} catch (ApiException e) {
log.error("钉钉workRecordAddRequest异常{}",e.getErrMsg());
throw new SyncDataException(JSON.toJSONString(request),e.getErrMsg());
}
return false;
}
}

View File

@ -1,10 +1,14 @@
package com.snow.flowable.listener.common;
import cn.hutool.core.date.BetweenFormater;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ExecutorBuilder;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.snow.common.constant.MessageConstants;
import com.snow.common.enums.DingTalkListenerType;
import com.snow.common.enums.DingTalkMessageType;
import com.snow.common.utils.PatternUtils;
import com.snow.dingtalk.model.WorkrecordAddRequest;
import com.snow.flowable.common.SpringContextUtil;
@ -22,9 +26,11 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.event.FlowableProcessStartedEvent;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.Execution;
@ -61,7 +67,9 @@ public class SendMessageEventLister extends AbstractEventListener {
super(
new HashSet<>(Arrays.asList(
FlowableEngineEventType.TASK_CREATED,
FlowableEngineEventType.PROCESS_STARTED
FlowableEngineEventType.PROCESS_STARTED,
FlowableEngineEventType.PROCESS_COMPLETED,
FlowableEngineEventType.TASK_OWNER_CHANGED
)),
new HashSet<>(Arrays.asList(
FlowDefEnum.SNOW_OA_LEAVE,
@ -84,7 +92,7 @@ public class SendMessageEventLister extends AbstractEventListener {
boolean emailOnOff = newsTriggerService.getEmailOnOff(execution.getProcessDefinitionKey(),FlowableEngineEventType.TASK_CREATED.name());
//钉钉通知
if(dingTalkOnOff){
// sendDingTalkMessage(event);
sendProcessStartedDingTalkMessage(event);
}
// 邮件通知
if(emailOnOff){
@ -92,6 +100,28 @@ public class SendMessageEventLister extends AbstractEventListener {
}
}
/**
* 流程已结束
* @param event
*/
protected void processCompleted(FlowableEngineEntityEvent event) {
log.info("ManagerTaskEventListener----processCompleted流程创建监听{}",JSON.toJSONString(event));
HistoricProcessInstance hisProcessInstance = getHisProcessInstance(event.getProcessInstanceId());
NewsTriggerService newsTriggerService = (NewsTriggerService)SpringContextUtil.getBean(NewsTriggerService.class);
boolean dingTalkOnOff = newsTriggerService.getDingTalkOnOff(hisProcessInstance.getProcessDefinitionKey(),FlowableEngineEventType.PROCESS_COMPLETED.name());
boolean emailOnOff = newsTriggerService.getEmailOnOff(hisProcessInstance.getProcessDefinitionKey(),FlowableEngineEventType.PROCESS_COMPLETED.name());
//钉钉通知
if(dingTalkOnOff){
sendProcessCompletedDingTalkMessage(event);
}
// 邮件通知
if(emailOnOff){
sendProcessCompletedEmailMessage(event);
}
}
/**
* 任务创建(待办)
* @param event
@ -165,7 +195,7 @@ public class SendMessageEventLister extends AbstractEventListener {
map.put("processInstance",processInstance.getProcessDefinitionName());
map.put("url","http://localhost/flow/getMyHistoricProcessInstance");
map.put("datetime",DateUtil.formatDateTime(new Date()));
SysSendMessageDTO sysSendMessageDTO = SysSendMessageDTO.builder().templateByCode("1367475870205353984")
SysSendMessageDTO sysSendMessageDTO = SysSendMessageDTO.builder().templateByCode(MessageConstants.PROCESS_STARTED_CODE)
.receiver(getUserInfo(processInstance.getStartUserId()).getEmail())
.paramMap(map)
.build();
@ -203,7 +233,7 @@ public class SendMessageEventLister extends AbstractEventListener {
map.put("processInstance",processDefinition.getName());
map.put("url","http://localhost/flow/findTasksByUserId");
map.put("datetime",DateUtil.formatDateTime(new Date()));
SysSendMessageDTO sysSendMessageDTO = SysSendMessageDTO.builder().templateByCode("1365961987292536832")
SysSendMessageDTO sysSendMessageDTO = SysSendMessageDTO.builder().templateByCode(MessageConstants.TASK_CREATED_CODE)
.receiver(t.getEmail())
.paramMap(map)
.build();
@ -215,6 +245,109 @@ public class SendMessageEventLister extends AbstractEventListener {
}
}
/**
* 发送钉钉通知
* @param event
*/
public void sendProcessStartedDingTalkMessage(FlowableProcessStartedEvent event){
ThreadPoolExecutor executor = ExecutorBuilder.create().setCorePoolSize(5)
.setMaxPoolSize(10)
.setWorkQueue(new LinkedBlockingQueue<>(100))
.build();
executor.execute(() -> {
ExecutionEntity execution = (ExecutionEntity)event.getEntity();
ProcessInstance processInstance = execution.getProcessInstance();
Map<String,String> map=new HashMap<>();
map.put("toUser",getUserInfo(processInstance.getStartUserId()).getUserName());
map.put("starttime",DateUtil.formatDateTime(processInstance.getStartTime()));
map.put("processInstance",processInstance.getProcessDefinitionName());
map.put("url","http://localhost/flow/getMyHistoricProcessInstance");
map.put("datetime",DateUtil.formatDateTime(new Date()));
SysSendMessageDTO sysSendMessageDTO = SysSendMessageDTO.builder().templateByCode(MessageConstants.PROCESS_STARTED_CODE)
.receiverSet(Sets.newHashSet(getUserInfo(processInstance.getStartUserId()).getDingUserId()))
.paramMap(map)
.dingTalkMessageType(DingTalkMessageType.TEXT)
.build();
SyncEvent syncEventGroup = new SyncEvent(sysSendMessageDTO, DingTalkListenerType.ASYNCSEND_V2);
applicationContext.publishEvent(syncEventGroup);
});
executor.shutdown();
}
/**
* 流程完结发送邮件通知
* @param event
*/
public void sendProcessCompletedEmailMessage(FlowableEngineEntityEvent event){
MailService mailService = (MailService) SpringContextUtil.getBean(MailService.class);
ThreadPoolExecutor executor = ExecutorBuilder.create().setCorePoolSize(5)
.setMaxPoolSize(10)
.setWorkQueue(new LinkedBlockingQueue<>(100))
.build();
executor.execute(() -> {
HistoricProcessInstance hisProcessInstance = getHisProcessInstance(event.getProcessInstanceId());
Map<String, String> map = buildSendProcessCompletedParam(hisProcessInstance);
SysSendMessageDTO sysSendMessageDTO = SysSendMessageDTO.builder().templateByCode(MessageConstants.PROCESS_COMPLETED_CODE)
.receiver(getUserInfo(hisProcessInstance.getStartUserId()).getEmail())
.paramMap(map)
.build();
mailService.sendSimpleMail(sysSendMessageDTO);
});
executor.shutdown();
}
/**
* 流程完结发送钉钉通知
* @param event
*/
public void sendProcessCompletedDingTalkMessage(FlowableEngineEntityEvent event){
ThreadPoolExecutor executor = ExecutorBuilder.create().setCorePoolSize(5)
.setMaxPoolSize(10)
.setWorkQueue(new LinkedBlockingQueue<>(100))
.build();
executor.execute(() -> {
HistoricProcessInstance hisProcessInstance = getHisProcessInstance(event.getProcessInstanceId());
Map<String, String> map = buildSendProcessCompletedParam(hisProcessInstance);
SysSendMessageDTO sysSendMessageDTO = SysSendMessageDTO.builder().templateByCode(MessageConstants.PROCESS_COMPLETED_CODE)
.receiverSet(Sets.newHashSet(getUserInfo(hisProcessInstance.getStartUserId()).getDingUserId()))
.paramMap(map)
.dingTalkMessageType(DingTalkMessageType.TEXT)
.build();
SyncEvent syncEventGroup = new SyncEvent(sysSendMessageDTO, DingTalkListenerType.ASYNCSEND_V2);
applicationContext.publishEvent(syncEventGroup);
});
executor.shutdown();
}
/**
* 组建流程完结参数
* @param hisProcessInstance
*/
private Map<String,String> buildSendProcessCompletedParam(HistoricProcessInstance hisProcessInstance){
Map<String,String> map=new HashMap<>();
map.put("toUser",getUserInfo(hisProcessInstance.getStartUserId()).getUserName());
map.put("starttime",DateUtil.formatDateTime(hisProcessInstance.getStartTime()));
map.put("orderNo",hisProcessInstance.getBusinessKey());
map.put("processInstance",hisProcessInstance.getProcessDefinitionName());
String spendTime = DateUtil.formatBetween(hisProcessInstance.getStartTime(), new Date(), BetweenFormater.Level.SECOND);
map.put("time",spendTime);
map.put("url","http://localhost/flow/getMyHistoricProcessInstance");
map.put("datetime",DateUtil.formatDateTime(new Date()));
return map;
}
/**
* 组装参数
* @param userId 需要发送通知的人
@ -271,6 +404,18 @@ public class SendMessageEventLister extends AbstractEventListener {
.singleResult();
}
/**
* 获取历史流程实例
* @param processInstanceId
* @return
*/
protected HistoricProcessInstance getHisProcessInstance(String processInstanceId) {
HistoryService historyService = (HistoryService)SpringContextUtil.getBean(HistoryService.class);
return historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstanceId)
.singleResult();
}
/**
* 获取用户信息
* @param userId

View File

@ -1,5 +1,6 @@
package com.snow.framework.web.domain.common;
import com.snow.common.enums.DingTalkMessageType;
import lombok.*;
import java.io.Serializable;
@ -52,8 +53,20 @@ public class SysSendMessageDTO implements Serializable {
private String filePath;
/**
* 邮件发送时间
* 发送时间
*/
private Date sentDate;
/**
* 是否发给所有人
*/
private Boolean toAllUser=false;
/**
* 消息类型
*/
private DingTalkMessageType dingTalkMessageType;
}

View File

@ -1,6 +1,5 @@
package com.snow.framework.web.service;
import cn.hutool.core.thread.ExecutorBuilder;
import com.snow.common.utils.PatternUtils;
import com.snow.common.utils.StringUtils;
import com.snow.framework.web.domain.common.SysSendMessageDTO;
@ -8,10 +7,8 @@ import com.snow.system.domain.SysMessageTemplate;
import com.snow.system.service.ISysMessageTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
@ -22,8 +19,6 @@ import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @program: snow