DayDataSyncJob.java
4.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
package com.skua.modules.job;
import com.alibaba.fastjson.JSONObject;
import com.skua.core.util.DateUtils;
import com.skua.modules.alarmtmp.entity.SysFactoryDevice;
import com.skua.modules.alarmtmp.service.ISysFactoryDeviceService;
import com.skua.modules.report.service.IFReportItemvService;
import com.skua.modules.report.service.IReportDataService;
import com.skua.modules.system.datestandard.entity.SysMonitorMetricInfo;
import com.skua.modules.system.datestandard.service.ISysMonitorMetricInfoService;
import com.skua.modules.system.service.IPgService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 发送消息任务
*/
@Slf4j
public class DayDataSyncJob implements Job {
@Autowired
private IPgService pgService;
@Autowired
private ISysMonitorMetricInfoService sysMonitorMetricInfoService;
@Autowired
private ISysFactoryDeviceService sysFactoryDeviceService;
@Autowired
private IReportDataService reportDataService;
//水质水量报表ID
private static final String REPORT_ID = "2119ecbf53a1d2d0708258ff67cfd9e1";
@Override
public void execute(JobExecutionContext jobExecutionContext) {
log.info("开始同步昨天的数据入报表");
String yesterday = DateUtils.getYesterday();
List<SysFactoryDevice> deviceList = sysFactoryDeviceService.getList();
if(deviceList.size() > 0){
Map<String, String> tagMap = new HashMap<>();
List<SysMonitorMetricInfo> list = sysMonitorMetricInfoService.getTagDataList();
for (SysMonitorMetricInfo monitorMetricInfo : list) {
tagMap.put(monitorMetricInfo.getMetricUidTag(),monitorMetricInfo.getId());
}
for (SysFactoryDevice sysFactoryDevice : deviceList) {
String departId = sysFactoryDevice.getDepartId();
String deviceId = sysFactoryDevice.getDeviceId();
String fields = "";
for (SysMonitorMetricInfo monitorMetricInfo : list) {
if(departId.equals(monitorMetricInfo.getDepartId())){
fields = fields + monitorMetricInfo.getId().toString() + ",";
}
}
if(!"".equals(fields)){
Map<String, Object> dataMap = pgService.queryDayData(fields, deviceId, yesterday);
Map<String, String> data = new HashMap<>();
if(tagMap.get("CSLL")!=null){
data.put("CSL", String.valueOf(24*Double.parseDouble(dataMap.get(tagMap.get("CSLL")).toString())));
}else{
data.put("CSL", "");
}
if(tagMap.get("JSLL")!=null){
data.put("JSL", String.valueOf(24*Double.parseDouble(dataMap.get(tagMap.get("JSLL")).toString())));
}else{
data.put("JSL", "");
}
if(tagMap.get("CSAD")!=null){
data.put("CSAD", dataMap.get(tagMap.get("CSAD")).toString());
}else{
data.put("CSAD", "");
}
if(tagMap.get("CSCOD")!=null){
data.put("CSCOD", dataMap.get(tagMap.get("CSCOD")).toString());
}else{
data.put("CSCOD", "");
}
if(tagMap.get("CSPH")!=null){
data.put("CSPH", dataMap.get(tagMap.get("CSPH")).toString());
}else{
data.put("CSPH", "");
}
if(tagMap.get("CSSS")!=null){
data.put("CSSS", dataMap.get(tagMap.get("CSSS")).toString());
}else{
data.put("CSSS", "");
}
if(tagMap.get("CSTN")!=null){
data.put("CSTN", dataMap.get(tagMap.get("CSTN")).toString());
}else{
data.put("CSTN", "");
}
if(tagMap.get("CSZL")!=null){
data.put("CSZL", dataMap.get(tagMap.get("CSZL")).toString());
}else{
data.put("CSZL", "");
}
if(tagMap.get("JSAD")!=null){
data.put("JSAD", dataMap.get(tagMap.get("JSAD")).toString());
}else{
data.put("JSAD", "");
}
if(tagMap.get("JSCOD")!=null){
data.put("JSCOD", dataMap.get(tagMap.get("JSCOD")).toString());
}else{
data.put("JSCOD", "");
}
if(tagMap.get("JSPH")!=null){
data.put("JSPH", dataMap.get(tagMap.get("JSPH")).toString());
}else{
data.put("JSPH", "");
}
if(tagMap.get("JSSS")!=null){
data.put("JSSS", dataMap.get(tagMap.get("JSSS")).toString());
}else{
data.put("JSSS", "");
}
if(tagMap.get("JSZD")!=null){
data.put("JSZD", dataMap.get(tagMap.get("JSZD")).toString());
}else{
data.put("JSZD", "");
}
if(tagMap.get("JSZL")!=null){
data.put("JSZL", dataMap.get(tagMap.get("JSZL")).toString());
}else{
data.put("JSZL", "");
}
data.put("departId", departId);
data.put("reportId", REPORT_ID);
data.put("time",yesterday);
reportDataService.insertOrUpdateReportData(departId, yesterday, data, REPORT_ID);
}
}
log.info("同步昨天的数据入报表完成");
}else {
log.info("没有需要同步数据的水厂");
}
}
}