Explorar o código

接口上传测温数据-已注释

hanqingsong %!s(int64=4) %!d(string=hai) anos
pai
achega
e4a3779d21

+ 6 - 0
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/utils/ConstUtils.java

@@ -22,6 +22,12 @@ import org.springframework.stereotype.Component;
22 22
 @Component
23 23
 @SuppressWarnings("all")
24 24
 public class ConstUtils {
25
+    // 库到云端同步数据接口
26
+    public static final String TEP_URL = "/testData/housesToCouldTemperData";
27
+    public static final String LAYER_URL = "/testDataLayer/housesToCouldTemperData";
28
+    public static final String WAINING_URL = "/testWarningData/housesToCouldTemperData";
29
+    public static final String URL = "http://localhost:8765";
30
+
25 31
 
26 32
     /**
27 33
      * 起始标志

+ 22 - 14
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/utils/LongRangeUtils.java

@@ -1,5 +1,6 @@
1 1
 package com.chinaitop.depot.intelligent.utils;
2 2
 
3
+import com.alibaba.fastjson.JSON;
3 4
 import com.chinaitop.depot.intelligent.basicdata.model.TWarningThreshold;
4 5
 import com.chinaitop.depot.intelligent.basicdata.service.WarningThresholdService;
5 6
 import com.chinaitop.depot.intelligent.grainsituation.mapper.TTestdataLayerMapper;
@@ -13,6 +14,7 @@ import org.slf4j.LoggerFactory;
13 14
 import org.springframework.context.annotation.Configuration;
14 15
 import org.springframework.scheduling.annotation.Async;
15 16
 import org.springframework.transaction.annotation.Transactional;
17
+import org.springframework.web.client.RestTemplate;
16 18
 
17 19
 import javax.annotation.Resource;
18 20
 import java.math.BigDecimal;
@@ -29,7 +31,7 @@ import java.util.stream.Collectors;
29 31
 
30 32
 @Configuration
31 33
 public class LongRangeUtils {
32
-    final static Logger logger = LoggerFactory.getLogger(LongRangeUtils.class);
34
+    private final static Logger logger = LoggerFactory.getLogger(LongRangeUtils.class);
33 35
 
34 36
     private final int TEMP = 250;
35 37
 
@@ -43,6 +45,7 @@ public class LongRangeUtils {
43 45
 
44 46
     private final BigDecimal BD_MINUS_THREE = new BigDecimal("-30");
45 47
 
48
+
46 49
     @Resource
47 50
     private TemperatureRecordService temperatureRecordService;
48 51
 
@@ -59,10 +62,9 @@ public class LongRangeUtils {
59 62
     private TTestdataLogMapper tTestdataLogMapper;
60 63
 
61 64
     @Resource
62
-    private UuidUtils uuidUtils;
63
-
64
-    @Resource
65 65
     private WarningMessage warningMessage;
66
+    /*@Resource
67
+    private RestTemplate restTemplate;*/
66 68
 
67 69
 
68 70
     @Transactional(rollbackFor = Exception.class)
@@ -98,7 +100,7 @@ public class LongRangeUtils {
98 100
             }
99 101
             String orgId = temperatureRecordService.getOrgId(cDcsCodes.get(INT_ZERO));
100 102
             ts.forEach(obj -> {
101
-                String testdataId = uuidUtils.getCode();
103
+                String testdataId = UuidUtils.getCode();
102 104
                 TTestdata tTestdata = (TTestdata) obj;
103 105
                 String house = tTestdata.getStorehouse();
104 106
                 Date time = tTestdata.getTime();
@@ -144,7 +146,7 @@ public class LongRangeUtils {
144 146
                     BigDecimal wh = threshold.getThreshold();
145 147
                     //-1 小于 0 等于 1 大于
146 148
                     if (wholeMax.compareTo(wh) == 1 && ilqYq.equals(STR_ZERO)) {
147
-                        String tid = uuidUtils.getCode();
149
+                        String tid = UuidUtils.getCode();
148 150
                         TWarningThresholdHistory tt = null;
149 151
                         StringBuffer desc = new StringBuffer();
150 152
                         if (!wholeMax.toString().equals(STR_TEMP)) {
@@ -161,7 +163,7 @@ public class LongRangeUtils {
161 163
                         BigDecimal ww = wWarning.getThreshold();
162 164
                         BigDecimal subtract = wh.subtract(ww).setScale(2, RoundingMode.HALF_UP); //高温减去阈值
163 165
                         if (wholeMax.compareTo(subtract) == 1 && ilqYq.equals(STR_ZERO)) {
164
-                            String tid = uuidUtils.getCode();
166
+                            String tid = UuidUtils.getCode();
165 167
                             StringBuffer desc = new StringBuffer();
166 168
                             String str = desc.append("整仓粮温(").append(wholeMax).append(")高于阈值(").append(subtract).append(")").toString();
167 169
                             TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, wholeMax, subtract, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
@@ -175,7 +177,7 @@ public class LongRangeUtils {
175 177
                     BigDecimal wl = wLowest.getThreshold().setScale(2, RoundingMode.HALF_UP);
176 178
                     //-1 小于 0 等于 1 大于
177 179
                     if (wMin.compareTo(wl) == -1 && !wMin.toString().equals(STR_TEMP00) && ilqYq.equals(STR_ZERO)) {
178
-                        String tid = uuidUtils.getCode();
180
+                        String tid = UuidUtils.getCode();
179 181
                         StringBuffer desc = new StringBuffer();
180 182
                         String str = desc.append("整仓粮温(").append(wMin).append(")低于阈值(").append(wl).append(")").toString();
181 183
                         TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wLowest, wMin, wl, time, str, dataSource2, STR_ZERO, STR_ZERO);
@@ -187,7 +189,7 @@ public class LongRangeUtils {
187 189
                         BigDecimal ww = wWarning.getThreshold();
188 190
                         BigDecimal wadd = wl.add(ww);//高温减去阈值
189 191
                         if (wMin.compareTo(wadd) == -1 && ilqYq.equals(STR_ZERO)) {
190
-                            String tid = uuidUtils.getCode();
192
+                            String tid = UuidUtils.getCode();
191 193
                             StringBuffer desc = new StringBuffer();
192 194
                             String str = desc.append("整仓粮温(").append(wMin).append(")低于阈值(").append(wadd).append(")").toString();
193 195
                             TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, wMin, wadd, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
@@ -223,7 +225,7 @@ public class LongRangeUtils {
223 225
                     tTestdataLayer.setLmin(lsyerMin);
224 226
                     tTestdataLayer.setLhouse(house);
225 227
                     tTestdataLayer.setLtime(time);
226
-                    tTestdataLayer.setId(uuidUtils.getCode());
228
+                    tTestdataLayer.setId(UuidUtils.getCode());
227 229
                     tTestdataLayer.setOrgId(orgId);
228 230
                     tTestdataLayer.setDataSource(dataSource2);
229 231
                     tTestdataLayer.setLqId(testdataId);
@@ -247,7 +249,7 @@ public class LongRangeUtils {
247 249
                                     //-1 小于 0 等于 1 大于
248 250
                                     if (te.compareTo(threshold1) == 1) {
249 251
                                         // tid id,cfCdoe 仓房编码,threshold 报警实体包括orgID,tthreshold 检测值,wThreshold 预警或报警设置值,date 检测时间,desc 描述信息,mode 0测温,1测虫,2测气,warning 0报警,1预警
250
-                                        String tid = uuidUtils.getCode();
252
+                                        String tid = UuidUtils.getCode();
251 253
                                         TWarningThresholdHistory tt = null;
252 254
                                         StringBuffer desc = new StringBuffer();
253 255
                                         if (!te.toString().equals(STR_TEMP00)) {
@@ -265,7 +267,7 @@ public class LongRangeUtils {
265 267
                                         BigDecimal ww = wWarning.getThreshold();
266 268
                                         BigDecimal subtract = threshold1.subtract(ww).setScale(2, RoundingMode.HALF_UP); //高温减去阈值
267 269
                                         if (te.compareTo(subtract) == 1 && ilqYq.equals(STR_ZERO)) {
268
-                                            String tid = uuidUtils.getCode();
270
+                                            String tid = UuidUtils.getCode();
269 271
                                             StringBuffer desc = new StringBuffer();
270 272
                                             String str = desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列粮温(").append(te).append(")高于阈值(").append(subtract).append(")").toString();
271 273
                                             TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, te, subtract, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
@@ -278,7 +280,7 @@ public class LongRangeUtils {
278 280
                                     BigDecimal wl = wLowest.getThreshold().setScale(2, RoundingMode.HALF_UP);
279 281
                                     //-1 小于 0 等于 1 大于
280 282
                                     if (te.compareTo(wl) == -1 && !te.toString().equals(STR_TEMP00)) {
281
-                                        String tid = uuidUtils.getCode();
283
+                                        String tid = UuidUtils.getCode();
282 284
                                         StringBuffer desc = new StringBuffer();
283 285
                                         String str = desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列粮温(").append(te).append(")低于阈值(").append(wl).append(")").toString();
284 286
                                         TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wLowest, te, wl, time, str, dataSource2, STR_ZERO, STR_ZERO);
@@ -290,7 +292,7 @@ public class LongRangeUtils {
290 292
                                         BigDecimal ww = wWarning.getThreshold();
291 293
                                         BigDecimal wadd = wl.add(ww).setScale(2, RoundingMode.HALF_UP);//高温减去阈值
292 294
                                         if (te.compareTo(wadd) == -1 && ilqYq.equals(STR_ZERO)) {
293
-                                            String tid = uuidUtils.getCode();
295
+                                            String tid = UuidUtils.getCode();
294 296
                                             StringBuffer desc = new StringBuffer();
295 297
                                             String str = desc.append("第").append(keyL).append("层,第").append(keyR).append("行,第").append(keyC).append("列粮温(").append(te).append(")低于阈值(").append(wadd).append(")").toString();
296 298
                                             TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, te, wadd, time, str, dataSource2, STR_ZERO, ConstUtils.STR_ONE);
@@ -305,13 +307,19 @@ public class LongRangeUtils {
305 307
             });
306 308
 
307 309
             if (tTestdataList.size() > INT_ZERO) {
310
+//                logger.info("tTestdataList: {}", JSON.toJSONString(tTestdataList));
308 311
                 temperatureRecordService.insertBatch(tTestdataList);
312
+//                restTemplate.postForObject(ConstUtils.URL + ConstUtils.TEP_URL, tTestdataList, Object.class);
309 313
             }
310 314
             if (tTestdataLayerArrayList.size() > INT_ZERO) {
315
+//                logger.info("tTestdataLayerArrayList: {}", JSON.toJSONString(tTestdataLayerArrayList));
311 316
                 tTestdataLayerMapper.insertBatch(tTestdataLayerArrayList);
317
+//                restTemplate.postForObject(ConstUtils.URL + ConstUtils.LAYER_URL, tTestdataLayerArrayList, Object.class);
312 318
             }
313 319
             if (tWarningThresholdHistorieList.size() > INT_ZERO) {
320
+//                logger.info("tWarningThresholdHistorieList: {}", JSON.toJSONString(tWarningThresholdHistorieList));
314 321
                 tWarningThresholdHistoryMapper.insertBatch(tWarningThresholdHistorieList);
322
+//                restTemplate.postForObject(ConstUtils.URL + ConstUtils.WAINING_URL, tWarningThresholdHistorieList, Object.class);
315 323
             }
316 324
             logger.info("测温数据入库成功2");
317 325
         } catch (Exception e) {