SysMessagePushService.java
6.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.skua.modules.util;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.util.DateUtils;
import com.skua.core.util.push.IPushService;
import com.skua.core.util.push.MessageEntity;
import com.skua.core.util.push.PushMessageFactory;
import com.skua.modules.alarmtmp.entity.AlarmRecordHistory;
import com.skua.modules.alarmtmp.entity.AlarmRuleLevelConfigTemplate;
import com.skua.modules.alarmtmp.enums.AlarmRecordStatusEnum;
import com.skua.modules.alarmtmp.service.AlarmRecordHistoryService;
import com.skua.modules.alarmtmp.service.AlarmRuleConfigService;
import com.skua.modules.flow.business.service.FlowBusinessService;
import com.skua.modules.flow.business.service.IFlowService;
import com.skua.modules.flow.core.constant.ProcessConstant;
import com.skua.modules.flow.core.entity.BladeFlow;
import com.skua.modules.flow.core.utils.FlowUtil;
import com.skua.modules.flow.support.Kv;
import com.skua.modules.flow.utils.Func;
import com.skua.modules.system.entity.SysUser;
import com.skua.modules.system.service.ISysDictService;
import com.skua.modules.system.service.ISysPermissionService;
import com.skua.modules.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.TaskService;
import org.flowable.identitylink.api.IdentityLink;
import org.flowable.identitylink.api.IdentityLinkType;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* 系统数据推送
*/
@Service
@Slf4j
public class SysMessagePushService {
@Autowired
private AlarmRecordHistoryService alarmRecordHistoryService;
@Autowired
AlarmRuleConfigService alarmRuleConfigService;
@Autowired
ISysPermissionService permissionService;
@Autowired
ISysUserService userService;
@Autowired
ISysDictService dictService;
@Autowired
private IFlowService flowService;
@Autowired
private FlowBusinessService flowBusinessService;
@Autowired
private TaskService taskService;
/**
* <pre>
* 消息推送,不发起工作流
* </pre>
* @param recordHistory
* @author Li Yuanyuan,2023/6/21 15:09
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
public void pushAlarmRecordMsgNoProcess(AlarmRecordHistory recordHistory) {
//只推送重要级别的告警
if(recordHistory == null || !SysWarningLevelEnums.WARNING_LEVEL_1.getValue().equals(recordHistory.getAlarmRuleLevelName())){
return;
}
Map<String, String> alarmTypeMap = dictService.getDictMapByCode("alarm_type");
//获取报警数据对应的报警配置
AlarmRuleLevelConfigTemplate alarmRuleLevelConfig = getAlarm(recordHistory);
if (alarmRuleLevelConfig == null) return;
//判断是否需要发送系统通知 (内容跟报警记录信息相同)
if ("1".equals(alarmRuleLevelConfig.getIsSendNotice())) {
//推送 app & web
List<SysUser> sysUserList = userService.getUserByUserIds(alarmRuleLevelConfig.getAlarmNoticeRecipient());
pushMsgNoProcess(recordHistory, alarmTypeMap, sysUserList);
}
}
private void pushMsgNoProcess(AlarmRecordHistory recordHistory, Map<String, String> alarmTypeMap, List<SysUser> sysUserList) {
List<String> userCidList = sysUserList.stream().map(SysUser::getCid).filter(v -> StringUtils.isNotBlank(v)).collect(Collectors.toList());
List<String> userIdList = sysUserList.stream().map(SysUser::getId).collect(Collectors.toList());
if (userCidList.size()>0||userIdList.size()>0) {
MessageEntity messageEntity = new MessageEntity();
messageEntity.setMessageTitle("发生数据报警");
messageEntity.setMessageBody("报警信息");
messageEntity.setReceiveUser(userIdList);
messageEntity.setReceiveUserCid(userCidList);
messageEntity.setSendUser(BaseContextHandler.getUserName());
messageEntity.setForwardTag("historyRecordRemind");//消息提醒类型 保持唯一
List<Map<String, Object>> extMapList = new ArrayList();
//报警类型
Map<String, Object> extMap = new HashMap<>();
extMap.put("key","warningType");
extMap.put("value",alarmTypeMap.get(recordHistory.getAlarmRuleType()));
extMapList.add(extMap);
//报警级别
extMap = new HashMap<>();
extMap.put("key","level");
extMap.put("value", recordHistory.getAlarmRuleLevelName());
extMapList.add(extMap);
//报警时间
extMap = new HashMap<>();
extMap.put("key","recordTime");
extMap.put("value", recordHistory.getRecordTime() == null ? "" : DateUtils.format(recordHistory.getRecordTime(),"yyyy-MM-dd HH:mm:ss"));
extMapList.add(extMap);
//报警id
extMap = new HashMap<>();
extMap.put("key","id");
extMap.put("value",recordHistory.getId());
extMapList.add(extMap);
extMap = new HashMap<>();
extMap.put("key","alarmType");
extMap.put("value",recordHistory.getAlarmRuleType());
extMapList.add(extMap);
extMap = new HashMap<>();
extMap.put("key","processInstanceId");
extMap.put("value",recordHistory.getProcessInstanceId());
extMapList.add(extMap);
extMap = new HashMap<>();
extMap.put("key","processDefinitionId");
extMap.put("value",recordHistory.getProcessDefinitionId());
extMapList.add(extMap);
messageEntity.setExtMapList(extMapList);
IPushService appPushService = PushMessageFactory.getPushService("MOB");
IPushService webPushService = PushMessageFactory.getPushService("WEB");
appPushService.pushMessage(messageEntity);
webPushService.pushMessage(messageEntity);
}
}
private AlarmRuleLevelConfigTemplate getAlarm(AlarmRecordHistory recordHistory) {
List<AlarmRuleLevelConfigTemplate> alarmRuleList = alarmRuleConfigService.getAlarmConfigTemplateByAlarmType(recordHistory.getAlarmRuleType(), "af880d6a13404a67825e94bc0f2f3808");
if (alarmRuleList == null) {
return null;
}
for (AlarmRuleLevelConfigTemplate alarmRuleLevelConfigTemplate : alarmRuleList) {
if (alarmRuleLevelConfigTemplate.getAlarmTemplateLevelName().equals(recordHistory.getAlarmRuleLevelName())) {
return alarmRuleLevelConfigTemplate;
}
}
return null;
}
}