DataFillWarnJob.java
5.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
package com.skua.modules.alarm.quartz;
import com.alibaba.fastjson.JSONObject;
import com.skua.core.constant.CommonConstant;
import com.skua.core.util.DateUtils;
import com.skua.modules.message.websocket.WebSocket;
import com.skua.modules.report.service.IReportWaterDataService;
import com.skua.modules.system.entity.SysAnnouncement;
import com.skua.modules.system.entity.SysAnnouncementSend;
import com.skua.modules.system.entity.SysDepart;
import com.skua.modules.system.service.ISysAnnouncementSendService;
import com.skua.modules.system.service.ISysAnnouncementService;
import com.skua.modules.system.service.ISysDepartService;
import com.skua.modules.system.service.ISysUserDepartService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.util.*;
/**
* 数据填报报警
*/
@Slf4j
public class DataFillWarnJob implements Job {
@Autowired
private ISysDepartService sysDepartService;
@Autowired
private ISysAnnouncementService sysAnnouncementService;
@Autowired
private ISysAnnouncementSendService sysAnnouncementSendService;
@Autowired
private ISysUserDepartService iSysUserDepartService;
@Autowired
private IReportWaterDataService reportWaterDataService;
@Resource
private WebSocket webSocket;
@Override
public void execute(JobExecutionContext context) {
System.out.println("********工艺运行记录表填报监测服务开启********");
Date date = new Date();
int nowHour = date.getHours();
String today = DateUtils.format(date,"yyyy-MM-dd");
if(nowHour!=0){
String parentId = "ee0f983f190f4da4a2e19cba70370ea7";
List<SysDepart> list = sysDepartService.getFactoryListByParent(parentId);
sendMsgToWeb(list,today,nowHour);
}
System.out.println("********工艺运行记录表填报监测服务结束********");
}
private void sendMsgToWeb(List<SysDepart> list,String today,int hour) {
Double d = new Double(Math.floor((hour/2)+1));
int allCount = d.intValue();
if(list.size()>0){
for (SysDepart dept : list) {
String factoryId = dept.getId();
int haveCount = reportWaterDataService.getDataCount(factoryId,today);
if(allCount-haveCount > 0){
List<String> userIds= iSysUserDepartService.queryUserIdByfactoryId(factoryId);
sendMsg(userIds,factoryId,dept.getDepartName(),allCount-haveCount);
}
}
}
}
private void sendMsg(List<String> userIds,String factoryId,String factoryName,int count) {
String sendMsg = "截止当前时间"+factoryName+"存在"+count+"条未填报情况,请及时填写工艺运行记录表!";
String usersId = "";
for (int i = 0; i < userIds.size(); i++) {
String userId = userIds.get(i);
usersId = usersId + "," + userId;
}
//发送站内通知
SysAnnouncement sysAnnouncement = new SysAnnouncement();
//生成uuid
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
sysAnnouncement.setId(uuid);
sysAnnouncement.setTitile(factoryName+"工艺运行记录表填报通知");
sysAnnouncement.setMsgContent(sendMsg);
sysAnnouncement.setPriority(CommonConstant.PRIORITY_M);
sysAnnouncement.setMsgType(CommonConstant.MSG_TYPE_UESR);
sysAnnouncement.setSendStatus(CommonConstant.HAS_SEND);
sysAnnouncement.setSendTime(new Date());
sysAnnouncement.setStartTime(new Date());
sysAnnouncement.setEndTime(getDateByAdd(new Date(), 2));
sysAnnouncement.setUserIds(usersId);
sysAnnouncement.setFactoryId(factoryId);
sysAnnouncement.setMsgCategory(CommonConstant.MSG_CATEGORY_2);
sysAnnouncement.setDelFlag(String.valueOf(CommonConstant.DEL_FLAG_0));
sysAnnouncement.setSender("admin");
sysAnnouncementService.save(sysAnnouncement);
for (String userid : userIds) {
SysAnnouncementSend announcementSend = new SysAnnouncementSend();
announcementSend.setAnntId(sysAnnouncement.getId());
announcementSend.setUserId(userid);
announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
sysAnnouncementSendService.save(announcementSend);
}
com.alibaba.fastjson.JSONObject obj = new JSONObject();
obj.put("cmd", "topic");
obj.put("msgId", sysAnnouncement.getId());
obj.put("msgTxt", sysAnnouncement.getMsgContent());
// webSocket.sendOneMessage("e9ca23d68d884d4ebb19d07889727dae",obj.toJSONString());
webSocket.sendAllMessageByFactoryIds(userIds,obj.toJSONString());
}
/**
* @description 获取*单位后的时间
* @param num 时间单位数(如果num数为负数,说明是此日期前的天数)
*/
public static Date getDateByAdd(Date date, int num) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.HOUR, num);
return cal.getTime();
}
}