完善消息通知

This commit is contained in:
459816669@qq.com 2021-03-04 21:38:51 +08:00
parent b48d255e34
commit 32d9af80df
8 changed files with 48 additions and 31 deletions

View File

@ -95,9 +95,9 @@ public class SysNewsNodeController extends BaseController
@ResponseBody
public AjaxResult addSave(SysNewsNode sysNewsNode)
{
SysNewsNode sysNewsNodeKey = sysNewsNodeService.selectSysNewsNodeByKey(sysNewsNode.getNewsNodeKey());
SysNewsNode sysNewsNodeKey = sysNewsNodeService.selectSysNewsNodeByKey(sysNewsNode.getNewsNodeKey(),sysNewsNode.getParentId());
if (sysNewsNodeKey!=null) {
return AjaxResult.error("配置节点key已存在");
return AjaxResult.error("父节下配置节点key已存在");
}
SysUser sysUser = ShiroUtils.getSysUser();
sysNewsNode.setCreateBy(String.valueOf(sysUser.getUserId()));
@ -125,7 +125,7 @@ public class SysNewsNodeController extends BaseController
public AjaxResult editSave(SysNewsNode sysNewsNode)
{
String newsNodeKey = sysNewsNode.getNewsNodeKey();
SysNewsNode sysNewsNodeKey = sysNewsNodeService.selectSysNewsNodeByKey(newsNodeKey);
SysNewsNode sysNewsNodeKey = sysNewsNodeService.selectSysNewsNodeByKey(newsNodeKey,sysNewsNode.getParentId());
if (sysNewsNodeKey!=null&&!sysNewsNodeKey.getNewsNodeKey().equals(newsNodeKey)) {
return AjaxResult.error("该配置节点key已存在");
}

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

@ -14,6 +14,7 @@ import com.snow.flowable.service.FlowableService;
import com.snow.flowable.service.impl.FlowableUserServiceImpl;
import com.snow.framework.web.domain.common.SysSendMessageDTO;
import com.snow.framework.web.service.MailService;
import com.snow.framework.web.service.NewsTriggerService;
import com.snow.system.domain.SysUser;
import com.snow.system.event.SyncEvent;
import com.snow.system.service.impl.SysUserServiceImpl;
@ -70,10 +71,19 @@ public class SendMessageEventLister extends AbstractEventListener {
protected void taskCreated(FlowableEngineEntityEvent event) {
//任务创建可发送短信邮件通知接收人(代办人)
log.info("ManagerTaskEventListener----taskCreated任务创建监听{}",JSON.toJSONString(event));
//钉钉通知 TODO 是否开启通知
sendDingTalkMessage(event);
// 邮件通知 todo 是否开启通知
sendEmailMessage(event);
ProcessDefinition processDefinition = getProcessDefinition(event.getProcessDefinitionId());
NewsTriggerService newsTriggerService = (NewsTriggerService)SpringContextUtil.getBean(NewsTriggerService.class);
boolean dingTalkOnOff = newsTriggerService.getDingTalkOnOff(processDefinition.getKey(),FlowableEngineEventType.TASK_CREATED.name());
boolean emailOnOff = newsTriggerService.getEmailOnOff(processDefinition.getKey(),FlowableEngineEventType.TASK_CREATED.name());
//钉钉通知
if(dingTalkOnOff){
sendDingTalkMessage(event);
}
// 邮件通知
if(emailOnOff){
sendEmailMessage(event);
}
}
/**
@ -114,32 +124,33 @@ public class SendMessageEventLister extends AbstractEventListener {
FlowableService flowableService = (FlowableService)SpringContextUtil.getBean(FlowableService.class);
MailService mailService = (MailService) SpringContextUtil.getBean(MailService.class);
ProcessInstance processInstance = flowableService.getProcessInstanceById(event.getProcessInstanceId());
ProcessDefinition processDefinition = getProcessDefinition(event.getProcessDefinitionId());
//根据任务ID获取任务获选人
TaskEntity entity = (TaskEntity)event.getEntity();
Set<SysUser> flowCandidates = getFlowCandidates(entity);
if(CollectionUtils.isNotEmpty(flowCandidates)){
Set<String> emailSet = flowCandidates.stream().map(SysUser::getEmail).collect(Collectors.toSet());
// Set<String> emailSet = flowCandidates.stream().map(SysUser::getEmail).collect(Collectors.toSet());
ThreadPoolExecutor executor = ExecutorBuilder.create().setCorePoolSize(5)
.setMaxPoolSize(10)
.setWorkQueue(new LinkedBlockingQueue<>(100))
.build();
executor.execute(() ->{
emailSet.forEach(t->{
executor.execute(() ->
flowCandidates.forEach(t->{
Map<String,String> map=new HashMap<>();
map.put("toUser",t);
map.put("toUser",t.getUserName());
map.put("startUser",getUserInfo(processInstance.getStartUserId()).getUserName());
map.put("processInstance",processInstance.getProcessDefinitionName());
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")
.receiverSet(emailSet)
.receiver(t.getEmail())
.paramMap(map)
.build();
mailService.sendSimpleMail(sysSendMessageDTO);
});
});
})
);
executor.shutdown();
}
@ -244,4 +255,5 @@ public class SendMessageEventLister extends AbstractEventListener {
return sysUserSet;
}
}

View File

@ -19,7 +19,7 @@ import java.util.List;
* @Description:
* @date 2021/3/3 17:03
*/
@Service("newsTrigger")
@Service
public class NewsTriggerService {
@Autowired
@ -34,9 +34,9 @@ public class NewsTriggerService {
* @param nodeKey
* @return
*/
public boolean getEmailOnOff(String nodeKey)
public boolean getEmailOnOff(String parentNodeKey,String nodeKey)
{
return getNewsOnOff(nodeKey,Constants.NEWS_EMAIL_TYPE);
return getNewsOnOff(parentNodeKey,nodeKey,Constants.NEWS_EMAIL_TYPE);
}
@ -45,14 +45,18 @@ public class NewsTriggerService {
* @param nodeKey
* @return
*/
public boolean getDingTalkOnOff(String nodeKey)
public boolean getDingTalkOnOff(String parentNodeKey,String nodeKey)
{
return getNewsOnOff(nodeKey,Constants.NEWS_DINGDING_TYPE);
return getNewsOnOff(parentNodeKey,nodeKey,Constants.NEWS_DINGDING_TYPE);
}
private boolean getNewsOnOff(String nodeKey,Integer newsType){
SysNewsNode sysNewsNode = sysNewsNodeService.selectSysNewsNodeByKey(nodeKey);
private boolean getNewsOnOff(String parentNodeKey,String nodeKey,Integer newsType){
SysNewsNode sysNewsNodes=new SysNewsNode();
sysNewsNodes.setNewsNodeKey(parentNodeKey);
List<SysNewsNode> sysNewsNodeList = sysNewsNodeService.selectSysNewsNodeList(sysNewsNodes);
SysNewsNode sysNewsNode = sysNewsNodeService.selectSysNewsNodeByKey(nodeKey,sysNewsNodeList.get(0).getId().longValue());
if(null == sysNewsNode){
return false;
}

View File

@ -2,6 +2,7 @@ package com.snow.system.mapper;
import java.util.List;
import com.snow.system.domain.SysNewsNode;
import org.apache.ibatis.annotations.Param;
/**
* 消息配置节点Mapper接口
@ -24,7 +25,7 @@ public interface SysNewsNodeMapper
* @param newsNodeKey 配置节点key
* @return
*/
public SysNewsNode selectSysNewsNodeByKey(String newsNodeKey);
public SysNewsNode selectSysNewsNodeByKey(@Param("newsNodeKey") String newsNodeKey,@Param("parentId") Long parentId);
/**
* 查询消息配置节点列表

View File

@ -25,7 +25,7 @@ public interface ISysNewsNodeService
* @param newsNodeKey 配置节点key
* @return
*/
public SysNewsNode selectSysNewsNodeByKey(String newsNodeKey);
public SysNewsNode selectSysNewsNodeByKey(String newsNodeKey,Long parentId);
/**
* 查询消息配置节点列表

View File

@ -36,8 +36,8 @@ public class SysNewsNodeServiceImpl implements ISysNewsNodeService
}
@Override
public SysNewsNode selectSysNewsNodeByKey(String newsNodeKey) {
return sysNewsNodeMapper.selectSysNewsNodeByKey(newsNodeKey);
public SysNewsNode selectSysNewsNodeByKey(String newsNodeKey,Long parentId) {
return sysNewsNodeMapper.selectSysNewsNodeByKey(newsNodeKey,parentId);
}
/**

View File

@ -43,9 +43,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where t.id = #{id}
</select>
<select id="selectSysNewsNodeByKey" parameterType="String" resultMap="SysNewsNodeResult">
<select id="selectSysNewsNodeByKey" resultMap="SysNewsNodeResult">
<include refid="selectSysNewsNodeVo"/>
where news_node_key = #{newsNodeKey} and is_delete=0
where news_node_key = #{newsNodeKey} and parent_id = #{parentId} and is_delete=0
</select>
<insert id="insertSysNewsNode" parameterType="SysNewsNode" useGeneratedKeys="true" keyProperty="id">
insert into sys_news_node