SystemNoticeUtils.java
8.2 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package com.skua.modules.util;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.skua.modules.alarmtmp.vo.MeetNoticeVO;
import com.skua.modules.alarmtmp.vo.SystemNoticeVO;
import com.skua.common.constant.CommonSendStatus;
import com.skua.core.constant.CommonConstant;
import com.skua.core.util.UUIDGenerator;
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.system.entity.SysAnnouncement;
import com.skua.modules.system.entity.SysAnnouncementSend;
import com.skua.modules.system.service.ISysAnnouncementSendService;
import com.skua.modules.system.service.ISysAnnouncementService;
import com.skua.modules.system.service.ISysDictService;
import com.skua.modules.system.service.ISysUserService;
import com.skua.modules.websocket.WebSocket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @ClassName SystemNoticeUtils
* @Description 系统通知工具类
* @Author yangsong
* @Date 2021/4/21 15:58
* @Version 1.0
*/
@Slf4j
@Component
public class SystemNoticeUtils {
private static Map<String, String> tmp = Maps.newHashMap();
static {
tmp.put("重要报警", "H");//高
tmp.put("一般报警", "M");//中
tmp.put("提醒报警", "L");//低
}
@Autowired
private ISysAnnouncementService sysAnnouncementService;
@Autowired
private ISysAnnouncementSendService sysAnnouncementSendService;
@Autowired
private ISysDictService sysDictService;
@Autowired
private ISysUserService sysUserService;
@Resource
private WebSocket webSocket;
public void dealNoticeMessage(SystemNoticeVO systemNoticeVO) {
String userIds = systemNoticeVO.getUserIds();
Date refDate = new Date();
SysAnnouncement sysAnnouncement = new SysAnnouncement();
sysAnnouncement.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
sysAnnouncement.setSendStatus(CommonSendStatus.PUBLISHED_STATUS_1);//发布
sysAnnouncement.setMsgType("ALARM");
sysAnnouncement.setPriority(tmp.getOrDefault(systemNoticeVO.getAlarmRuleLevelName(), "H"));
sysAnnouncement.setId(UUIDGenerator.creatUUID());
sysAnnouncement.setSendTime(refDate);
sysAnnouncement.setMsgCategory("3");
//系统
sysAnnouncement.setSender("系统");
sysAnnouncement.setDepartId(systemNoticeVO.getDepartId());
sysAnnouncement.setMsgContent(systemNoticeVO.getContent());
//根据报警类型获取中文
String alarmRuleType = systemNoticeVO.getAlarmRuleType();
String alarmTypeName = sysDictService.queryDictTextByKey("alarm_type", alarmRuleType);
sysAnnouncement.setTitile(alarmTypeName + "通知");
sysAnnouncement.setAlarmType(alarmRuleType);
sysAnnouncement.setUserIds(userIds);
sysAnnouncementService.save(sysAnnouncement);
// 2.插入用户通告阅读标记表记录
String[] users = userIds.split(",");
String anntId = sysAnnouncement.getId();
for (int i = 0; i < users.length; i++) {
SysAnnouncementSend announcementSend = new SysAnnouncementSend();
announcementSend.setAnntId(anntId);
announcementSend.setUserId(users[i]);
announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
announcementSend.setReadTime(refDate);
sysAnnouncementSendService.save(announcementSend);
}
// 发送webSocket
JSONObject obj = new JSONObject();
obj.put("cmd", "historyRecordRemind");
obj.put("type", sysAnnouncement.getPriority());
obj.put("msgId", sysAnnouncement.getId());
obj.put("msgTxt", sysAnnouncement.getTitile());
webSocket.sendMoreMessage(users, obj.toJSONString());
log.info("系统通知发送成功" + userIds);
//移动端消息推送
//根据用户id查询cid
List<String> cidList = sysUserService.getCidByUserIds(userIds);
if (cidList != null && cidList.size() > 0) {
log.info("APP通知发送开始" + userIds);
try {
MessageEntity messageEntity = new MessageEntity();
messageEntity.setMessageTitle(alarmTypeName + "通知");
messageEntity.setMessageBody(systemNoticeVO.getContent());
messageEntity.setReceiveUserCid(cidList);
messageEntity.setForwardTag("");
IPushService appPushService = PushMessageFactory.getPushService("MOB");
appPushService.pushMessage(messageEntity);
} catch (Exception e) {
log.info("APP通知发送错误" + e);
}
log.info("APP通知发送成功" + userIds + ":" + alarmTypeName + "通知" + systemNoticeVO.getContent());
} else {
log.info("APP通知没有cid" + userIds);
}
}
/**
* 会议通知
* @param systemNoticeVO
*/
public void meetNoticeMessage(SystemNoticeVO systemNoticeVO,String meetId,String title,String meetType) {
String userIds = systemNoticeVO.getUserIds();
Date refDate = new Date();
SysAnnouncement sysAnnouncement = new SysAnnouncement();
sysAnnouncement.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
sysAnnouncement.setSendStatus(CommonSendStatus.PUBLISHED_STATUS_1);//发布
sysAnnouncement.setMsgType("USER");
sysAnnouncement.setPriority("M");
sysAnnouncement.setId(UUIDGenerator.creatUUID());
sysAnnouncement.setSendTime(refDate);
sysAnnouncement.setMsgCategory("4");//会议通知
//系统
sysAnnouncement.setSender("系统");
sysAnnouncement.setDepartId(systemNoticeVO.getDepartId());
sysAnnouncement.setMsgContent(systemNoticeVO.getContent());
//根据报警类型获取中文
sysAnnouncement.setTitile(title+"[会议通知]");
sysAnnouncement.setUserIds(userIds);
sysAnnouncementService.save(sysAnnouncement);
// 2.插入用户通告阅读标记表记录
String[] users = userIds.split(",");
String anntId = sysAnnouncement.getId();
for (int i = 0; i < users.length; i++) {
SysAnnouncementSend announcementSend = new SysAnnouncementSend();
announcementSend.setAnntId(anntId);
announcementSend.setUserId(users[i]);
announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
announcementSend.setReadTime(refDate);
sysAnnouncementSendService.save(announcementSend);
}
// 发送webSocket
JSONObject obj = new JSONObject();
obj.put("cmd", "meettingNotice");
obj.put("type", sysAnnouncement.getPriority());
obj.put("msgId", sysAnnouncement.getId());
obj.put("meetRecordId", meetId);
obj.put("meetType", meetType);
obj.put("msgTxt", sysAnnouncement.getTitile());
webSocket.sendMoreMessage(users, obj.toJSONString());
log.info("系统通知发送成功" + userIds);
//移动端消息推送
//根据用户id查询cid
List<String> cidList = sysUserService.getCidByUserIds(userIds);
if (cidList != null && cidList.size() > 0) {
log.info("APP通知发送开始" + userIds);
try {
MessageEntity messageEntity = new MessageEntity();
messageEntity.setMessageTitle(title+"[会议通知]");
messageEntity.setMessageBody(systemNoticeVO.getContent());
messageEntity.setReceiveUserCid(cidList);
messageEntity.setForwardTag("");
IPushService appPushService = PushMessageFactory.getPushService("MOB");
appPushService.pushMessage(messageEntity);
} catch (Exception e) {
log.info("APP通知发送错误" + e);
}
log.info("APP通知发送成功" + userIds + ":" + title + "[会议通知]" + systemNoticeVO.getContent());
} else {
log.info("APP通知没有cid" + userIds);
}
}
}