|
|
@@ -68,248 +68,254 @@ public class LongRangeUtils {
|
|
68
|
68
|
@Transactional(rollbackFor = Exception.class)
|
|
69
|
69
|
@Async("executor")
|
|
70
|
70
|
public void asyncMethodGrainData(String grainTemperatureData) {
|
|
71
|
|
- logger.info("测温异步接受!");
|
|
72
|
|
- tTestdataLogMapper.insertSelective(new TTestdataLog(DateUtils.getDate(), grainTemperatureData));
|
|
73
|
|
- String dataSource2 = "";
|
|
74
|
|
- //粮温元数据
|
|
75
|
|
- ArrayList<TTestdata> tTestdataList = Lists.newArrayList();
|
|
76
|
|
- //粮温每层数据
|
|
77
|
|
- ArrayList<TTestdataLayer> tTestdataLayerArrayList = Lists.newArrayList();
|
|
78
|
|
- //报警数据
|
|
79
|
|
- ArrayList<TWarningThresholdHistory> tWarningThresholdHistorieList = Lists.newArrayList();
|
|
|
71
|
+ try {
|
|
|
72
|
+ logger.info("测温异步接受!");
|
|
|
73
|
+ tTestdataLogMapper.insertSelective(new TTestdataLog(DateUtils.getDate(), grainTemperatureData));
|
|
|
74
|
+ logger.info("测温源数据已入库1!");
|
|
|
75
|
+ String dataSource2 = "";
|
|
|
76
|
+ //粮温元数据
|
|
|
77
|
+ ArrayList<TTestdata> tTestdataList = Lists.newArrayList();
|
|
|
78
|
+ //粮温每层数据
|
|
|
79
|
+ ArrayList<TTestdataLayer> tTestdataLayerArrayList = Lists.newArrayList();
|
|
|
80
|
+ //报警数据
|
|
|
81
|
+ ArrayList<TWarningThresholdHistory> tWarningThresholdHistorieList = Lists.newArrayList();
|
|
80
|
82
|
|
|
81
|
|
- String replace = grainTemperatureData.replace("\"Y\"", "\"y\"").replace("\"X\"", "\"x\"").replace("\"Z\"", "\"z\"");
|
|
82
|
|
- ArrayList<Object> ts = JsonToObjectUtils.jsonToObjects(replace, TTestdata.class);
|
|
83
|
|
- ArrayList<TTestdata> tts = Lists.newArrayList();
|
|
84
|
|
- ts.forEach(obj -> {
|
|
85
|
|
- TTestdata s = (TTestdata) obj;
|
|
86
|
|
- tts.add(s);
|
|
87
|
|
- });
|
|
88
|
|
- List<String> cDcsCodes = tts.stream().map(TTestdata::getStorehouse).collect(Collectors.toList());
|
|
89
|
|
- List<Date> cTimes = tts.stream().map(TTestdata::getTime).collect(Collectors.toList());
|
|
90
|
|
- List<String> lqTypes = tts.stream().map(TTestdata::getIlqYq).collect(Collectors.toList());
|
|
91
|
|
- //校验重复数据
|
|
92
|
|
- List<TTestdata> byCodeAndTimes = temperatureRecordService.getByCodeAndTimes(cDcsCodes, cTimes, lqTypes);
|
|
93
|
|
- if (byCodeAndTimes != null && byCodeAndTimes.size() > INT_ZERO) {
|
|
94
|
|
- logger.info("上传数据重复!");
|
|
95
|
|
- return;
|
|
96
|
|
- }
|
|
97
|
|
- String orgId = temperatureRecordService.getOrgId(cDcsCodes.get(INT_ZERO));
|
|
98
|
|
- ts.forEach(obj -> {
|
|
99
|
|
- String testdataId = uuidUtils.getCode();
|
|
100
|
|
- TTestdata tTestdata = (TTestdata) obj;
|
|
101
|
|
- String house = tTestdata.getStorehouse();
|
|
102
|
|
- Date time = tTestdata.getTime();
|
|
103
|
|
- List<TPoints> ps = tTestdata.getPoints();
|
|
104
|
|
- String sP = JsonToObjectUtils.listToString(ps);
|
|
105
|
|
- tTestdata.settPoints(sP);
|
|
106
|
|
- //获取报警阈值信息6972测温 6983温度高限 6982温度底限 6991温度预警
|
|
107
|
|
- TWarningThreshold threshold = null; //温度高限
|
|
108
|
|
- TWarningThreshold wLowest = null; //温度底限
|
|
109
|
|
- TWarningThreshold wWarning = null; //温度预警
|
|
110
|
|
- String ilqYq = tTestdata.getIlqYq();
|
|
111
|
|
- if (ilqYq.equals(STR_ZERO)) {
|
|
112
|
|
- threshold = warningThresholdService.getByCfCodeAndwName(house, INT_ZERO, "6972", "6983");
|
|
113
|
|
- wLowest = warningThresholdService.getByCfCodeAndwName(house, INT_ZERO, "6972", "6982");
|
|
114
|
|
- wWarning = warningThresholdService.getByCfCodeAndwName(house, INT_ZERO, "6972", "6991");
|
|
115
|
|
-
|
|
116
|
|
- }
|
|
117
|
|
- BigDecimal wholeSum = ps.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(TPoints::getTemp).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
118
|
|
- List<BigDecimal> collect = ps.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(t -> t.getTemp()).collect(Collectors.toList());
|
|
119
|
|
- double doubleValue = wholeSum.doubleValue();
|
|
120
|
|
- double wholeAvg = INT_ZERO;
|
|
121
|
|
- if (collect.size() > INT_ZERO) {
|
|
122
|
|
- wholeAvg = doubleValue / collect.size();
|
|
123
|
|
- }
|
|
124
|
|
- tTestdata.setAvg(new BigDecimal(wholeAvg == INT_ZERO ? TEMP : wholeAvg).setScale(2, RoundingMode.HALF_UP));
|
|
125
|
|
- BigDecimal wholeMax = ps.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(TPoints::getTemp).reduce(BD_MINUS_THREE, BigDecimal::max);
|
|
126
|
|
- tTestdata.setMax(new BigDecimal(wholeMax.toString()));
|
|
127
|
|
- List<Double> wholeMins = Lists.newArrayList();
|
|
128
|
|
- List<BigDecimal> bList = ps.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(t -> t.getTemp()).collect(Collectors.toList());
|
|
129
|
|
- bList.forEach(bigDecimal -> {
|
|
130
|
|
- wholeMins.add(bigDecimal.doubleValue());
|
|
|
83
|
+ String replace = grainTemperatureData.replace("\"Y\"", "\"y\"").replace("\"X\"", "\"x\"").replace("\"Z\"", "\"z\"");
|
|
|
84
|
+ ArrayList<Object> ts = JsonToObjectUtils.jsonToObjects(replace, TTestdata.class);
|
|
|
85
|
+ ArrayList<TTestdata> tts = Lists.newArrayList();
|
|
|
86
|
+ ts.forEach(obj -> {
|
|
|
87
|
+ TTestdata s = (TTestdata) obj;
|
|
|
88
|
+ tts.add(s);
|
|
131
|
89
|
});
|
|
132
|
|
- Double wholeMin = wholeMins.size() == INT_ZERO ? 250.0 : Collections.min(wholeMins);
|
|
133
|
|
- BigDecimal wMin = new BigDecimal(wholeMin).setScale(2, RoundingMode.HALF_UP);
|
|
134
|
|
- tTestdata.setMin(wMin);
|
|
135
|
|
- tTestdata.setId(testdataId);
|
|
136
|
|
- tTestdata.setOrgId(orgId);
|
|
137
|
|
- tTestdata.setDataSource(dataSource2);
|
|
138
|
|
- tTestdataList.add(tTestdata);
|
|
139
|
|
- if (threshold != null) {
|
|
140
|
|
- //用于判断是否已经报警
|
|
141
|
|
- boolean temp = false;
|
|
142
|
|
- BigDecimal wh = threshold.getThreshold();
|
|
143
|
|
- //-1 小于 0 等于 1 大于
|
|
144
|
|
- if (wholeMax.compareTo(wh) == 1 && ilqYq.equals(STR_ZERO)) {
|
|
145
|
|
- String tid = uuidUtils.getCode();
|
|
146
|
|
- TWarningThresholdHistory tt = null;
|
|
147
|
|
- StringBuffer desc = new StringBuffer();
|
|
148
|
|
- if (!wholeMax.toString().equals(STR_TEMP)) {
|
|
149
|
|
- String str = desc.append("整仓粮温(").append(wholeMax).append(")高于阈值(").append(wh).append(")").toString();
|
|
150
|
|
- tt = warningMessage.saveWThreshold(tid, house, threshold, wholeMax, wh, time, str, dataSource2, STR_ZERO, STR_ZERO);
|
|
151
|
|
- } else {
|
|
152
|
|
- tt = warningMessage.saveWThreshold(tid, house, wWarning, wholeMax, wh, time, "整仓设备异常", dataSource2, STR_ZERO, ConstUtils.STR_TWO);
|
|
153
|
|
- }
|
|
154
|
|
- tWarningThresholdHistorieList.add(tt);
|
|
155
|
|
- temp = true;
|
|
|
90
|
+ List<String> cDcsCodes = tts.stream().map(TTestdata::getStorehouse).collect(Collectors.toList());
|
|
|
91
|
+ List<Date> cTimes = tts.stream().map(TTestdata::getTime).collect(Collectors.toList());
|
|
|
92
|
+ List<String> lqTypes = tts.stream().map(TTestdata::getIlqYq).collect(Collectors.toList());
|
|
|
93
|
+ //校验重复数据
|
|
|
94
|
+ List<TTestdata> byCodeAndTimes = temperatureRecordService.getByCodeAndTimes(cDcsCodes, cTimes, lqTypes);
|
|
|
95
|
+ if (byCodeAndTimes != null && byCodeAndTimes.size() > INT_ZERO) {
|
|
|
96
|
+ logger.info("上传数据重复!");
|
|
|
97
|
+ return;
|
|
|
98
|
+ }
|
|
|
99
|
+ String orgId = temperatureRecordService.getOrgId(cDcsCodes.get(INT_ZERO));
|
|
|
100
|
+ ts.forEach(obj -> {
|
|
|
101
|
+ String testdataId = uuidUtils.getCode();
|
|
|
102
|
+ TTestdata tTestdata = (TTestdata) obj;
|
|
|
103
|
+ String house = tTestdata.getStorehouse();
|
|
|
104
|
+ Date time = tTestdata.getTime();
|
|
|
105
|
+ List<TPoints> ps = tTestdata.getPoints();
|
|
|
106
|
+ String sP = JsonToObjectUtils.listToString(ps);
|
|
|
107
|
+ tTestdata.settPoints(sP);
|
|
|
108
|
+ //获取报警阈值信息6972测温 6983温度高限 6982温度底限 6991温度预警
|
|
|
109
|
+ TWarningThreshold threshold = null; //温度高限
|
|
|
110
|
+ TWarningThreshold wLowest = null; //温度底限
|
|
|
111
|
+ TWarningThreshold wWarning = null; //温度预警
|
|
|
112
|
+ String ilqYq = tTestdata.getIlqYq();
|
|
|
113
|
+ if (ilqYq.equals(STR_ZERO)) {
|
|
|
114
|
+ threshold = warningThresholdService.getByCfCodeAndwName(house, INT_ZERO, "6972", "6983");
|
|
|
115
|
+ wLowest = warningThresholdService.getByCfCodeAndwName(house, INT_ZERO, "6972", "6982");
|
|
|
116
|
+ wWarning = warningThresholdService.getByCfCodeAndwName(house, INT_ZERO, "6972", "6991");
|
|
|
117
|
+
|
|
156
|
118
|
}
|
|
157
|
|
- if (wWarning != null && !temp && !wholeMax.toString().equals(TEMP) && ilqYq.equals(STR_ZERO)) {
|
|
|
119
|
+ BigDecimal wholeSum = ps.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(TPoints::getTemp).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
120
|
+ List<BigDecimal> collect = ps.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(t -> t.getTemp()).collect(Collectors.toList());
|
|
|
121
|
+ double doubleValue = wholeSum.doubleValue();
|
|
|
122
|
+ double wholeAvg = INT_ZERO;
|
|
|
123
|
+ if (collect.size() > INT_ZERO) {
|
|
|
124
|
+ wholeAvg = doubleValue / collect.size();
|
|
|
125
|
+ }
|
|
|
126
|
+ tTestdata.setAvg(new BigDecimal(wholeAvg == INT_ZERO ? TEMP : wholeAvg).setScale(2, RoundingMode.HALF_UP));
|
|
|
127
|
+ BigDecimal wholeMax = ps.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(TPoints::getTemp).reduce(BD_MINUS_THREE, BigDecimal::max);
|
|
|
128
|
+ tTestdata.setMax(new BigDecimal(wholeMax.toString()));
|
|
|
129
|
+ List<Double> wholeMins = Lists.newArrayList();
|
|
|
130
|
+ List<BigDecimal> bList = ps.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(t -> t.getTemp()).collect(Collectors.toList());
|
|
|
131
|
+ bList.forEach(bigDecimal -> {
|
|
|
132
|
+ wholeMins.add(bigDecimal.doubleValue());
|
|
|
133
|
+ });
|
|
|
134
|
+ Double wholeMin = wholeMins.size() == INT_ZERO ? 250.0 : Collections.min(wholeMins);
|
|
|
135
|
+ BigDecimal wMin = new BigDecimal(wholeMin).setScale(2, RoundingMode.HALF_UP);
|
|
|
136
|
+ tTestdata.setMin(wMin);
|
|
|
137
|
+ tTestdata.setId(testdataId);
|
|
|
138
|
+ tTestdata.setOrgId(orgId);
|
|
|
139
|
+ tTestdata.setDataSource(dataSource2);
|
|
|
140
|
+ tTestdataList.add(tTestdata);
|
|
|
141
|
+ if (threshold != null) {
|
|
|
142
|
+ //用于判断是否已经报警
|
|
|
143
|
+ boolean temp = false;
|
|
|
144
|
+ BigDecimal wh = threshold.getThreshold();
|
|
158
|
145
|
//-1 小于 0 等于 1 大于
|
|
159
|
|
- BigDecimal ww = wWarning.getThreshold();
|
|
160
|
|
- BigDecimal subtract = wh.subtract(ww).setScale(2, RoundingMode.HALF_UP); //高温减去阈值
|
|
161
|
|
- if (wholeMax.compareTo(subtract) == 1 && ilqYq.equals(STR_ZERO)) {
|
|
|
146
|
+ if (wholeMax.compareTo(wh) == 1 && ilqYq.equals(STR_ZERO)) {
|
|
162
|
147
|
String tid = uuidUtils.getCode();
|
|
|
148
|
+ TWarningThresholdHistory tt = null;
|
|
163
|
149
|
StringBuffer desc = new StringBuffer();
|
|
164
|
|
- String str = desc.append("整仓粮温(").append(wholeMax).append(")高于阈值(").append(subtract).append(")").toString();
|
|
165
|
|
- TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, wholeMax, subtract, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
|
|
|
150
|
+ if (!wholeMax.toString().equals(STR_TEMP)) {
|
|
|
151
|
+ String str = desc.append("整仓粮温(").append(wholeMax).append(")高于阈值(").append(wh).append(")").toString();
|
|
|
152
|
+ tt = warningMessage.saveWThreshold(tid, house, threshold, wholeMax, wh, time, str, dataSource2, STR_ZERO, STR_ZERO);
|
|
|
153
|
+ } else {
|
|
|
154
|
+ tt = warningMessage.saveWThreshold(tid, house, wWarning, wholeMax, wh, time, "整仓设备异常", dataSource2, STR_ZERO, ConstUtils.STR_TWO);
|
|
|
155
|
+ }
|
|
166
|
156
|
tWarningThresholdHistorieList.add(tt);
|
|
|
157
|
+ temp = true;
|
|
|
158
|
+ }
|
|
|
159
|
+ if (wWarning != null && !temp && !wholeMax.toString().equals(TEMP) && ilqYq.equals(STR_ZERO)) {
|
|
|
160
|
+ //-1 小于 0 等于 1 大于
|
|
|
161
|
+ BigDecimal ww = wWarning.getThreshold();
|
|
|
162
|
+ BigDecimal subtract = wh.subtract(ww).setScale(2, RoundingMode.HALF_UP); //高温减去阈值
|
|
|
163
|
+ if (wholeMax.compareTo(subtract) == 1 && ilqYq.equals(STR_ZERO)) {
|
|
|
164
|
+ String tid = uuidUtils.getCode();
|
|
|
165
|
+ StringBuffer desc = new StringBuffer();
|
|
|
166
|
+ String str = desc.append("整仓粮温(").append(wholeMax).append(")高于阈值(").append(subtract).append(")").toString();
|
|
|
167
|
+ TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, wholeMax, subtract, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
|
|
|
168
|
+ tWarningThresholdHistorieList.add(tt);
|
|
|
169
|
+ }
|
|
167
|
170
|
}
|
|
168
|
171
|
}
|
|
169
|
|
- }
|
|
170
|
|
- if (wLowest != null) {
|
|
171
|
|
- //用于判断是否已经报警
|
|
172
|
|
- boolean temp = false;
|
|
173
|
|
- BigDecimal wl = wLowest.getThreshold().setScale(2, RoundingMode.HALF_UP);
|
|
174
|
|
- //-1 小于 0 等于 1 大于
|
|
175
|
|
- if (wMin.compareTo(wl) == -1 && !wMin.toString().equals(STR_TEMP00) && ilqYq.equals(STR_ZERO)) {
|
|
176
|
|
- String tid = uuidUtils.getCode();
|
|
177
|
|
- StringBuffer desc = new StringBuffer();
|
|
178
|
|
- String str = desc.append("整仓粮温(").append(wMin).append(")低于阈值(").append(wl).append(")").toString();
|
|
179
|
|
- TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wLowest, wMin, wl, time, str, dataSource2, STR_ZERO, STR_ZERO);
|
|
180
|
|
- tWarningThresholdHistorieList.add(tt);
|
|
181
|
|
- temp = true;
|
|
182
|
|
- }
|
|
183
|
|
- if (wWarning != null && !temp && !wMin.toString().equals(STR_TEMP00) && ilqYq.equals(STR_ZERO)) {
|
|
|
172
|
+ if (wLowest != null) {
|
|
|
173
|
+ //用于判断是否已经报警
|
|
|
174
|
+ boolean temp = false;
|
|
|
175
|
+ BigDecimal wl = wLowest.getThreshold().setScale(2, RoundingMode.HALF_UP);
|
|
184
|
176
|
//-1 小于 0 等于 1 大于
|
|
185
|
|
- BigDecimal ww = wWarning.getThreshold();
|
|
186
|
|
- BigDecimal wadd = wl.add(ww);//高温减去阈值
|
|
187
|
|
- if (wMin.compareTo(wadd) == -1 && ilqYq.equals(STR_ZERO)) {
|
|
|
177
|
+ if (wMin.compareTo(wl) == -1 && !wMin.toString().equals(STR_TEMP00) && ilqYq.equals(STR_ZERO)) {
|
|
188
|
178
|
String tid = uuidUtils.getCode();
|
|
189
|
179
|
StringBuffer desc = new StringBuffer();
|
|
190
|
|
- String str = desc.append("整仓粮温(").append(wMin).append(")低于阈值(").append(wadd).append(")").toString();
|
|
191
|
|
- TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, wMin, wadd, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
|
|
|
180
|
+ String str = desc.append("整仓粮温(").append(wMin).append(")低于阈值(").append(wl).append(")").toString();
|
|
|
181
|
+ TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wLowest, wMin, wl, time, str, dataSource2, STR_ZERO, STR_ZERO);
|
|
192
|
182
|
tWarningThresholdHistorieList.add(tt);
|
|
|
183
|
+ temp = true;
|
|
|
184
|
+ }
|
|
|
185
|
+ if (wWarning != null && !temp && !wMin.toString().equals(STR_TEMP00) && ilqYq.equals(STR_ZERO)) {
|
|
|
186
|
+ //-1 小于 0 等于 1 大于
|
|
|
187
|
+ BigDecimal ww = wWarning.getThreshold();
|
|
|
188
|
+ BigDecimal wadd = wl.add(ww);//高温减去阈值
|
|
|
189
|
+ if (wMin.compareTo(wadd) == -1 && ilqYq.equals(STR_ZERO)) {
|
|
|
190
|
+ String tid = uuidUtils.getCode();
|
|
|
191
|
+ StringBuffer desc = new StringBuffer();
|
|
|
192
|
+ String str = desc.append("整仓粮温(").append(wMin).append(")低于阈值(").append(wadd).append(")").toString();
|
|
|
193
|
+ TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, wMin, wadd, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
|
|
|
194
|
+ tWarningThresholdHistorieList.add(tt);
|
|
|
195
|
+ }
|
|
193
|
196
|
}
|
|
194
|
197
|
}
|
|
195
|
|
- }
|
|
196
|
198
|
|
|
197
|
|
- Map<String, List<TPoints>> layerGroupV = ps.stream().collect(Collectors.groupingBy(t -> t.getZ()));
|
|
198
|
|
- int layerNumber = INT_ZERO;
|
|
199
|
|
- for (Map.Entry<String, List<TPoints>> entry : layerGroupV.entrySet()) {
|
|
200
|
|
- TTestdataLayer tTestdataLayer = new TTestdataLayer();
|
|
201
|
|
- tTestdataLayer.setLayernumber(++layerNumber);
|
|
202
|
|
- List<TPoints> points = entry.getValue();
|
|
203
|
|
- BigDecimal lsyerSums = points.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(TPoints::getTemp).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
204
|
|
- List<BigDecimal> collect1 = points.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(t -> t.getTemp()).collect(Collectors.toList());
|
|
205
|
|
- double lsyerSum = lsyerSums.doubleValue();
|
|
206
|
|
- tTestdataLayer.setLz(points.get(INT_ZERO).getZ());
|
|
207
|
|
- double lsyerAvg = INT_ZERO;
|
|
208
|
|
- if (collect1.size() > INT_ZERO) {
|
|
209
|
|
- lsyerAvg = lsyerSum / collect1.size();
|
|
210
|
|
- }
|
|
211
|
|
- tTestdataLayer.setLavg(new BigDecimal(lsyerAvg == INT_ZERO ? 250 : lsyerAvg));
|
|
212
|
|
- BigDecimal lsyerMax = points.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(TPoints::getTemp).reduce(BD_MINUS_THREE, BigDecimal::max);
|
|
213
|
|
- tTestdataLayer.setLmax(new BigDecimal(lsyerMax.toString()));
|
|
214
|
|
- List<Double> lsyerMins = Lists.newArrayList();
|
|
215
|
|
- List<BigDecimal> bigList = points.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(t -> t.getTemp()).collect(Collectors.toList());
|
|
216
|
|
- bigList.forEach(bigDecimal -> {
|
|
217
|
|
- lsyerMins.add(bigDecimal.doubleValue());
|
|
218
|
|
- });
|
|
219
|
|
- Double wlsyerMin = lsyerMins.size() == INT_ZERO ? 250.0 : Collections.min(lsyerMins);
|
|
220
|
|
- BigDecimal lsyerMin = new BigDecimal(wlsyerMin);
|
|
221
|
|
- tTestdataLayer.setLmin(lsyerMin);
|
|
222
|
|
- tTestdataLayer.setLhouse(house);
|
|
223
|
|
- tTestdataLayer.setLtime(time);
|
|
224
|
|
- tTestdataLayer.setId(uuidUtils.getCode());
|
|
225
|
|
- tTestdataLayer.setOrgId(orgId);
|
|
226
|
|
- tTestdataLayer.setDataSource(dataSource2);
|
|
227
|
|
- tTestdataLayer.setLqId(testdataId);
|
|
228
|
|
- tTestdataLayerArrayList.add(tTestdataLayer);
|
|
|
199
|
+ Map<String, List<TPoints>> layerGroupV = ps.stream().collect(Collectors.groupingBy(t -> t.getZ()));
|
|
|
200
|
+ int layerNumber = INT_ZERO;
|
|
|
201
|
+ for (Map.Entry<String, List<TPoints>> entry : layerGroupV.entrySet()) {
|
|
|
202
|
+ TTestdataLayer tTestdataLayer = new TTestdataLayer();
|
|
|
203
|
+ tTestdataLayer.setLayernumber(++layerNumber);
|
|
|
204
|
+ List<TPoints> points = entry.getValue();
|
|
|
205
|
+ BigDecimal lsyerSums = points.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(TPoints::getTemp).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
206
|
+ List<BigDecimal> collect1 = points.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(t -> t.getTemp()).collect(Collectors.toList());
|
|
|
207
|
+ double lsyerSum = lsyerSums.doubleValue();
|
|
|
208
|
+ tTestdataLayer.setLz(points.get(INT_ZERO).getZ());
|
|
|
209
|
+ double lsyerAvg = INT_ZERO;
|
|
|
210
|
+ if (collect1.size() > INT_ZERO) {
|
|
|
211
|
+ lsyerAvg = lsyerSum / collect1.size();
|
|
|
212
|
+ }
|
|
|
213
|
+ tTestdataLayer.setLavg(new BigDecimal(lsyerAvg == INT_ZERO ? 250 : lsyerAvg));
|
|
|
214
|
+ BigDecimal lsyerMax = points.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(TPoints::getTemp).reduce(BD_MINUS_THREE, BigDecimal::max);
|
|
|
215
|
+ tTestdataLayer.setLmax(new BigDecimal(lsyerMax.toString()));
|
|
|
216
|
+ List<Double> lsyerMins = Lists.newArrayList();
|
|
|
217
|
+ List<BigDecimal> bigList = points.stream().filter(TPoints -> !TPoints.getTemp().toString().equals(new BigDecimal(STR_TEMP).toString())).map(t -> t.getTemp()).collect(Collectors.toList());
|
|
|
218
|
+ bigList.forEach(bigDecimal -> {
|
|
|
219
|
+ lsyerMins.add(bigDecimal.doubleValue());
|
|
|
220
|
+ });
|
|
|
221
|
+ Double wlsyerMin = lsyerMins.size() == INT_ZERO ? 250.0 : Collections.min(lsyerMins);
|
|
|
222
|
+ BigDecimal lsyerMin = new BigDecimal(wlsyerMin);
|
|
|
223
|
+ tTestdataLayer.setLmin(lsyerMin);
|
|
|
224
|
+ tTestdataLayer.setLhouse(house);
|
|
|
225
|
+ tTestdataLayer.setLtime(time);
|
|
|
226
|
+ tTestdataLayer.setId(uuidUtils.getCode());
|
|
|
227
|
+ tTestdataLayer.setOrgId(orgId);
|
|
|
228
|
+ tTestdataLayer.setDataSource(dataSource2);
|
|
|
229
|
+ tTestdataLayer.setLqId(testdataId);
|
|
|
230
|
+ tTestdataLayerArrayList.add(tTestdataLayer);
|
|
229
|
231
|
|
|
230
|
|
- Map<Integer, Map<Integer, Map<Integer, List<TPoints>>>> pointsS = points.stream().collect(Collectors.groupingBy(t -> Integer.parseInt(t.getZ()), Collectors.groupingBy(t -> Integer.parseInt(t.getY()), Collectors.groupingBy(t -> Integer.parseInt(t.getX())))));
|
|
231
|
|
- for (Map.Entry<Integer, Map<Integer, Map<Integer, List<TPoints>>>> pS : pointsS.entrySet()) {
|
|
232
|
|
- //每层数据
|
|
233
|
|
- Integer keyL = pS.getKey();
|
|
234
|
|
- Map<Integer, Map<Integer, List<TPoints>>> layerPS = pS.getValue();
|
|
235
|
|
- for (Map.Entry<Integer, Map<Integer, List<TPoints>>> rows : layerPS.entrySet()) {
|
|
236
|
|
- //每一行数据
|
|
237
|
|
- Integer keyR = rows.getKey();
|
|
238
|
|
- Map<Integer, List<TPoints>> value = rows.getValue();
|
|
239
|
|
- for (Map.Entry<Integer, List<TPoints>> orws : value.entrySet()) {
|
|
240
|
|
- Integer keyC = orws.getKey();
|
|
241
|
|
- BigDecimal te = orws.getValue().get(INT_ZERO).getTemp().setScale(2, RoundingMode.HALF_UP);
|
|
242
|
|
- if (threshold != null && ilqYq.equals(STR_ZERO)) {
|
|
243
|
|
- boolean temp = false;
|
|
244
|
|
- BigDecimal threshold1 = threshold.getThreshold().setScale(2, RoundingMode.HALF_UP);
|
|
245
|
|
- //-1 小于 0 等于 1 大于
|
|
246
|
|
- if (te.compareTo(threshold1) == 1) {
|
|
247
|
|
- // tid id,cfCdoe 仓房编码,threshold 报警实体包括orgID,tthreshold 检测值,wThreshold 预警或报警设置值,date 检测时间,desc 描述信息,mode 0测温,1测虫,2测气,warning 0报警,1预警
|
|
248
|
|
- String tid = uuidUtils.getCode();
|
|
249
|
|
- TWarningThresholdHistory tt = null;
|
|
250
|
|
- StringBuffer desc = new StringBuffer();
|
|
251
|
|
- if (!te.toString().equals(STR_TEMP00)) {
|
|
252
|
|
- desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列粮温(").append(te).append(")高于阈值(").append(threshold1).append(")");
|
|
253
|
|
- tt = warningMessage.saveWThreshold(tid, house, threshold, te, threshold1, time, desc.toString(), dataSource2, STR_ZERO, STR_ZERO);
|
|
254
|
|
- } else {
|
|
255
|
|
- String s = desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列设备异常").toString();
|
|
256
|
|
- tt = warningMessage.saveWThreshold(tid, house, threshold, te, threshold1, time, s, dataSource2, STR_ZERO, ConstUtils.STR_TWO);
|
|
257
|
|
- }
|
|
258
|
|
- tWarningThresholdHistorieList.add(tt);
|
|
259
|
|
- temp = true;
|
|
260
|
|
- }
|
|
261
|
|
- if (wWarning != null && !temp && !te.toString().equals(STR_TEMP00)) {
|
|
|
232
|
+ Map<Integer, Map<Integer, Map<Integer, List<TPoints>>>> pointsS = points.stream().collect(Collectors.groupingBy(t -> Integer.parseInt(t.getZ()), Collectors.groupingBy(t -> Integer.parseInt(t.getY()), Collectors.groupingBy(t -> Integer.parseInt(t.getX())))));
|
|
|
233
|
+ for (Map.Entry<Integer, Map<Integer, Map<Integer, List<TPoints>>>> pS : pointsS.entrySet()) {
|
|
|
234
|
+ //每层数据
|
|
|
235
|
+ Integer keyL = pS.getKey();
|
|
|
236
|
+ Map<Integer, Map<Integer, List<TPoints>>> layerPS = pS.getValue();
|
|
|
237
|
+ for (Map.Entry<Integer, Map<Integer, List<TPoints>>> rows : layerPS.entrySet()) {
|
|
|
238
|
+ //每一行数据
|
|
|
239
|
+ Integer keyR = rows.getKey();
|
|
|
240
|
+ Map<Integer, List<TPoints>> value = rows.getValue();
|
|
|
241
|
+ for (Map.Entry<Integer, List<TPoints>> orws : value.entrySet()) {
|
|
|
242
|
+ Integer keyC = orws.getKey();
|
|
|
243
|
+ BigDecimal te = orws.getValue().get(INT_ZERO).getTemp().setScale(2, RoundingMode.HALF_UP);
|
|
|
244
|
+ if (threshold != null && ilqYq.equals(STR_ZERO)) {
|
|
|
245
|
+ boolean temp = false;
|
|
|
246
|
+ BigDecimal threshold1 = threshold.getThreshold().setScale(2, RoundingMode.HALF_UP);
|
|
262
|
247
|
//-1 小于 0 等于 1 大于
|
|
263
|
|
- BigDecimal ww = wWarning.getThreshold();
|
|
264
|
|
- BigDecimal subtract = threshold1.subtract(ww).setScale(2, RoundingMode.HALF_UP); //高温减去阈值
|
|
265
|
|
- if (te.compareTo(subtract) == 1 && ilqYq.equals(STR_ZERO)) {
|
|
|
248
|
+ if (te.compareTo(threshold1) == 1) {
|
|
|
249
|
+ // tid id,cfCdoe 仓房编码,threshold 报警实体包括orgID,tthreshold 检测值,wThreshold 预警或报警设置值,date 检测时间,desc 描述信息,mode 0测温,1测虫,2测气,warning 0报警,1预警
|
|
266
|
250
|
String tid = uuidUtils.getCode();
|
|
|
251
|
+ TWarningThresholdHistory tt = null;
|
|
267
|
252
|
StringBuffer desc = new StringBuffer();
|
|
268
|
|
- String str = desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列粮温(").append(te).append(")高于阈值(").append(subtract).append(")").toString();
|
|
269
|
|
- TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, te, subtract, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
|
|
|
253
|
+ if (!te.toString().equals(STR_TEMP00)) {
|
|
|
254
|
+ desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列粮温(").append(te).append(")高于阈值(").append(threshold1).append(")");
|
|
|
255
|
+ tt = warningMessage.saveWThreshold(tid, house, threshold, te, threshold1, time, desc.toString(), dataSource2, STR_ZERO, STR_ZERO);
|
|
|
256
|
+ } else {
|
|
|
257
|
+ String s = desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列设备异常").toString();
|
|
|
258
|
+ tt = warningMessage.saveWThreshold(tid, house, threshold, te, threshold1, time, s, dataSource2, STR_ZERO, ConstUtils.STR_TWO);
|
|
|
259
|
+ }
|
|
270
|
260
|
tWarningThresholdHistorieList.add(tt);
|
|
|
261
|
+ temp = true;
|
|
|
262
|
+ }
|
|
|
263
|
+ if (wWarning != null && !temp && !te.toString().equals(STR_TEMP00)) {
|
|
|
264
|
+ //-1 小于 0 等于 1 大于
|
|
|
265
|
+ BigDecimal ww = wWarning.getThreshold();
|
|
|
266
|
+ BigDecimal subtract = threshold1.subtract(ww).setScale(2, RoundingMode.HALF_UP); //高温减去阈值
|
|
|
267
|
+ if (te.compareTo(subtract) == 1 && ilqYq.equals(STR_ZERO)) {
|
|
|
268
|
+ String tid = uuidUtils.getCode();
|
|
|
269
|
+ StringBuffer desc = new StringBuffer();
|
|
|
270
|
+ String str = desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列粮温(").append(te).append(")高于阈值(").append(subtract).append(")").toString();
|
|
|
271
|
+ TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, te, subtract, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
|
|
|
272
|
+ tWarningThresholdHistorieList.add(tt);
|
|
|
273
|
+ }
|
|
271
|
274
|
}
|
|
272
|
275
|
}
|
|
273
|
|
- }
|
|
274
|
|
- if (wLowest != null && ilqYq.equals(STR_ZERO)) {
|
|
275
|
|
- boolean temp = false;
|
|
276
|
|
- BigDecimal wl = wLowest.getThreshold().setScale(2, RoundingMode.HALF_UP);
|
|
277
|
|
- //-1 小于 0 等于 1 大于
|
|
278
|
|
- if (te.compareTo(wl) == -1 && !te.toString().equals(STR_TEMP00)) {
|
|
279
|
|
- String tid = uuidUtils.getCode();
|
|
280
|
|
- StringBuffer desc = new StringBuffer();
|
|
281
|
|
- String str = desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列粮温(").append(te).append(")低于阈值(").append(wl).append(")").toString();
|
|
282
|
|
- TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wLowest, te, wl, time, str, dataSource2, STR_ZERO, STR_ZERO);
|
|
283
|
|
- tWarningThresholdHistorieList.add(tt);
|
|
284
|
|
- temp = true;
|
|
285
|
|
- }
|
|
286
|
|
- if (wWarning != null && !temp && !te.toString().equals(STR_TEMP00)) {
|
|
|
276
|
+ if (wLowest != null && ilqYq.equals(STR_ZERO)) {
|
|
|
277
|
+ boolean temp = false;
|
|
|
278
|
+ BigDecimal wl = wLowest.getThreshold().setScale(2, RoundingMode.HALF_UP);
|
|
287
|
279
|
//-1 小于 0 等于 1 大于
|
|
288
|
|
- BigDecimal ww = wWarning.getThreshold();
|
|
289
|
|
- BigDecimal wadd = wl.add(ww).setScale(2, RoundingMode.HALF_UP);//高温减去阈值
|
|
290
|
|
- if (te.compareTo(wadd) == -1 && ilqYq.equals(STR_ZERO)) {
|
|
|
280
|
+ if (te.compareTo(wl) == -1 && !te.toString().equals(STR_TEMP00)) {
|
|
291
|
281
|
String tid = uuidUtils.getCode();
|
|
292
|
282
|
StringBuffer desc = new StringBuffer();
|
|
293
|
|
- String str = desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列粮温(").append(te).append(")低于阈值(").append(wadd).append(")").toString();
|
|
294
|
|
- TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, te, wadd, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
|
|
|
283
|
+ String str = desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列粮温(").append(te).append(")低于阈值(").append(wl).append(")").toString();
|
|
|
284
|
+ TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wLowest, te, wl, time, str, dataSource2, STR_ZERO, STR_ZERO);
|
|
295
|
285
|
tWarningThresholdHistorieList.add(tt);
|
|
|
286
|
+ temp = true;
|
|
|
287
|
+ }
|
|
|
288
|
+ if (wWarning != null && !temp && !te.toString().equals(STR_TEMP00)) {
|
|
|
289
|
+ //-1 小于 0 等于 1 大于
|
|
|
290
|
+ BigDecimal ww = wWarning.getThreshold();
|
|
|
291
|
+ BigDecimal wadd = wl.add(ww).setScale(2, RoundingMode.HALF_UP);//高温减去阈值
|
|
|
292
|
+ if (te.compareTo(wadd) == -1 && ilqYq.equals(STR_ZERO)) {
|
|
|
293
|
+ String tid = uuidUtils.getCode();
|
|
|
294
|
+ StringBuffer desc = new StringBuffer();
|
|
|
295
|
+ String str = desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列粮温(").append(te).append(")低于阈值(").append(wadd).append(")").toString();
|
|
|
296
|
+ TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, te, wadd, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
|
|
|
297
|
+ tWarningThresholdHistorieList.add(tt);
|
|
|
298
|
+ }
|
|
296
|
299
|
}
|
|
297
|
300
|
}
|
|
298
|
301
|
}
|
|
299
|
302
|
}
|
|
300
|
303
|
}
|
|
301
|
304
|
}
|
|
302
|
|
- }
|
|
303
|
|
- });
|
|
|
305
|
+ });
|
|
304
|
306
|
|
|
305
|
|
- if (tTestdataList.size() > INT_ZERO) {
|
|
306
|
|
- temperatureRecordService.insertBatch(tTestdataList);
|
|
307
|
|
- }
|
|
308
|
|
- if (tTestdataLayerArrayList.size() > INT_ZERO) {
|
|
309
|
|
- tTestdataLayerMapper.insertBatch(tTestdataLayerArrayList);
|
|
310
|
|
- }
|
|
311
|
|
- if (tWarningThresholdHistorieList.size() > INT_ZERO) {
|
|
312
|
|
- tWarningThresholdHistoryMapper.insertBatch(tWarningThresholdHistorieList);
|
|
|
307
|
+ if (tTestdataList.size() > INT_ZERO) {
|
|
|
308
|
+ temperatureRecordService.insertBatch(tTestdataList);
|
|
|
309
|
+ }
|
|
|
310
|
+ if (tTestdataLayerArrayList.size() > INT_ZERO) {
|
|
|
311
|
+ tTestdataLayerMapper.insertBatch(tTestdataLayerArrayList);
|
|
|
312
|
+ }
|
|
|
313
|
+ if (tWarningThresholdHistorieList.size() > INT_ZERO) {
|
|
|
314
|
+ tWarningThresholdHistoryMapper.insertBatch(tWarningThresholdHistorieList);
|
|
|
315
|
+ }
|
|
|
316
|
+ logger.info("测温数据入库成功2");
|
|
|
317
|
+ } catch (Exception e) {
|
|
|
318
|
+ logger.info("测温异常:" + e.getMessage());
|
|
313
|
319
|
}
|
|
314
|
320
|
}
|
|
315
|
321
|
}
|