my-csc-config-file.git лет назад: 4
Родитель
Сommit
813b43d717

+ 2 - 0
depot-intelligent/src/main/java/com/DepotIntelligentApplication.java

@@ -6,10 +6,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
6 6
 import org.springframework.boot.web.servlet.ServletComponentScan;
7 7
 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
8 8
 import org.springframework.context.annotation.Bean;
9
+import org.springframework.scheduling.annotation.EnableAsync;
9 10
 import org.springframework.scheduling.annotation.EnableScheduling;
10 11
 import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
11 12
 import org.springframework.web.client.RestTemplate;
12 13
 
14
+@EnableAsync
13 15
 @EnableEurekaClient
14 16
 @SpringBootApplication
15 17
 @ServletComponentScan

+ 18 - 8
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/pushs/service/impl/GrainPushsServiceImpl.java

@@ -15,10 +15,7 @@ import com.chinaitop.depot.intelligent.grainsituation.model.TWarningThresholdHis
15 15
 import com.chinaitop.depot.intelligent.grainsituation.service.TWarningThresholdHistoryService;
16 16
 import com.chinaitop.depot.intelligent.grainsituation.service.TemperatureRecordService;
17 17
 import com.chinaitop.depot.intelligent.pushs.service.GrainPushsService;
18
-import com.chinaitop.depot.intelligent.utils.JsonToObjectUtils;
19
-import com.chinaitop.depot.intelligent.utils.UuidUtils;
20
-import com.chinaitop.depot.intelligent.utils.VerificationSourceUtils;
21
-import com.chinaitop.depot.intelligent.utils.WarningMessage;
18
+import com.chinaitop.depot.intelligent.utils.*;
22 19
 import com.google.common.collect.Lists;
23 20
 import com.unissoft.model.ResponseEntity;
24 21
 import com.unissoft.model.TypeEnum;
@@ -61,6 +58,9 @@ public class GrainPushsServiceImpl implements GrainPushsService {
61 58
     @Resource
62 59
     private TWarningThresholdHistoryService tWarningThresholdHistoryService;
63 60
 
61
+    @Resource
62
+    private LongRangeUtils longRangeUtils;
63
+
64 64
     @Transactional(rollbackFor = Exception.class)
65 65
     @Override
66 66
     public ResponseEntity uploadGrainTemperatureData(String dataSource, String grainTemperatureData) {
@@ -219,7 +219,8 @@ public class GrainPushsServiceImpl implements GrainPushsService {
219 219
                         });
220 220
                         Double lsyerMax = 250.0;
221 221
                         Double wlsyerMin = 250.0;
222
-                        BigDecimal lsyerAvg = new BigDecimal(250).setScale(2, RoundingMode.HALF_UP);;
222
+                        BigDecimal lsyerAvg = new BigDecimal(250).setScale(2, RoundingMode.HALF_UP);
223
+                        ;
223 224
                         if (bigList.size() > 0) {
224 225
                             lsyerAvg = bigList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(bigList.size()), 1, BigDecimal.ROUND_HALF_UP);
225 226
                             lsyerMax = lsyerMins.size() == 0 ? 0.0 : Collections.max(lsyerMins);
@@ -314,18 +315,27 @@ public class GrainPushsServiceImpl implements GrainPushsService {
314 315
                 }
315 316
                 if (tWarningThresholdHistorieList.size() > 0) {
316 317
                     tWarningThresholdHistoryMapper.insertBatch(tWarningThresholdHistorieList);
317
-                    List<TWarningThresholdHistory> collect = tWarningThresholdHistorieList.stream().filter(TWarningThresholdHistory -> TWarningThresholdHistory.getwWarning().equals("0")).collect(Collectors.toList());
318
+                   /* List<TWarningThresholdHistory> collect = tWarningThresholdHistorieList.stream().filter(TWarningThresholdHistory -> TWarningThresholdHistory.getwWarning().equals("0")).collect(Collectors.toList());
318 319
                     boolean alarmDetails = resolutionToSendAlarmService.getAlarmDetails(collect);
319 320
                     if (!alarmDetails) {
320 321
                         collect.forEach(obj -> {
321 322
                             obj.setIsSend("2");
322 323
                             tWarningThresholdHistoryService.updateById(obj);
323 324
                         });
324
-                    }
325
+                    }*/
326
+                }
327
+                //调用远程服务同步测温数据
328
+                if (tTestdataList.size() > 0) {
329
+                    longRangeUtils.asyncMethodGrainData(tTestdataList);
330
+                }
331
+                if (tTestdataLayerArrayList.size() > 0) {
332
+                    longRangeUtils.asyncMethodGrainLayerData(tTestdataLayerArrayList);
333
+                }
334
+                if (tWarningThresholdHistorieList.size() > 0) {
335
+                    longRangeUtils.asyncMethodWarningThresholdData(tWarningThresholdHistorieList);
325 336
                 }
326 337
             }
327 338
         } catch (Exception e) {
328
-            e.printStackTrace();
329 339
             logger.info(e.getMessage());
330 340
             throw new RuntimeException(TypeEnum.ED.getCode() + "  " + TypeEnum.ED.getDesc());
331 341
         }

+ 49 - 6
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/utils/JsonToObjectUtils.java

@@ -1,6 +1,9 @@
1 1
 package com.chinaitop.depot.intelligent.utils;
2 2
 
3 3
 import com.chinaitop.depot.intelligent.grainsituation.model.TPoints;
4
+import com.chinaitop.depot.intelligent.grainsituation.model.TTestdata;
5
+import com.chinaitop.depot.intelligent.grainsituation.model.TTestdataLayer;
6
+import com.chinaitop.depot.intelligent.grainsituation.model.TWarningThresholdHistory;
4 7
 import com.fasterxml.jackson.databind.JavaType;
5 8
 import com.fasterxml.jackson.databind.ObjectMapper;
6 9
 import org.slf4j.Logger;
@@ -28,7 +31,6 @@ public class JsonToObjectUtils {
28 31
             JavaType javaType = mapper.getTypeFactory().constructParametricType(ArrayList.class, Class.forName(packageName));
29 32
             object = mapper.readValue(str, javaType);
30 33
         } catch (Exception e) {
31
-            e.printStackTrace();
32 34
             logger.info("json转换异常  "+e.getMessage());
33 35
         }
34 36
         return object;
@@ -47,7 +49,6 @@ public class JsonToObjectUtils {
47 49
             JavaType javaType = mapper.getTypeFactory().constructParametricType(ArrayList.class, classs);
48 50
             object = mapper.readValue(str, javaType);
49 51
         } catch (Exception e) {
50
-            e.printStackTrace();
51 52
             logger.info("json转换异常  "+e.getMessage());
52 53
         }
53 54
         return object;
@@ -66,7 +67,6 @@ public class JsonToObjectUtils {
66 67
             mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
67 68
             object = mapper.readValue(str, Class.forName(packageName));
68 69
         } catch (Exception e) {
69
-            e.printStackTrace();
70 70
             logger.info("json转换异常  "+e.getMessage());
71 71
         }
72 72
         return object;
@@ -84,7 +84,6 @@ public class JsonToObjectUtils {
84 84
             mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
85 85
             object = mapper.readValue(str, classs);
86 86
         } catch (Exception e) {
87
-            e.printStackTrace();
88 87
             logger.info("json转换异常  "+e.getMessage());
89 88
         }
90 89
         return object;
@@ -105,7 +104,6 @@ public class JsonToObjectUtils {
105 104
             JavaType javaType = mapper.getTypeFactory().constructParametricType(ArrayList.class, classs);
106 105
             object = mapper.readValue(str, javaType);
107 106
         } catch (Exception e) {
108
-            e.printStackTrace();
109 107
             logger.info("json转换异常  "+e.getMessage());
110 108
         }
111 109
         return object;
@@ -121,7 +119,52 @@ public class JsonToObjectUtils {
121 119
             ObjectMapper mapper = new ObjectMapper();
122 120
             return mapper.writeValueAsString(points);
123 121
         } catch (Exception e) {
124
-            e.printStackTrace();
122
+            logger.info("json转换异常  "+e.getMessage());
123
+        }
124
+        return null;
125
+    }
126
+
127
+    /**
128
+     * list转换字符串
129
+     * @param tTestdatas list参数
130
+     * @return
131
+     */
132
+    public static String listToStrings(List<TTestdata> tTestdatas){
133
+        try {
134
+            ObjectMapper mapper = new ObjectMapper();
135
+            mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
136
+            return mapper.writeValueAsString(tTestdatas);
137
+        } catch (Exception e) {
138
+            logger.info("json转换异常  "+e.getMessage());
139
+        }
140
+        return null;
141
+    }
142
+    /**
143
+     * list转换字符串
144
+     * @param tTestdatas list参数
145
+     * @return
146
+     */
147
+    public static String listToLayerStrings(List<TTestdataLayer> tTestdatas){
148
+        try {
149
+            ObjectMapper mapper = new ObjectMapper();
150
+            mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
151
+            return mapper.writeValueAsString(tTestdatas);
152
+        } catch (Exception e) {
153
+            logger.info("json转换异常  "+e.getMessage());
154
+        }
155
+        return null;
156
+    }
157
+    /**
158
+     * list转换字符串
159
+     * @param tTestdatas list参数
160
+     * @return
161
+     */
162
+    public static String listToWarningThresholdStrings(List<TWarningThresholdHistory> tTestdatas){
163
+        try {
164
+            ObjectMapper mapper = new ObjectMapper();
165
+            mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
166
+            return mapper.writeValueAsString(tTestdatas);
167
+        } catch (Exception e) {
125 168
             logger.info("json转换异常  "+e.getMessage());
126 169
         }
127 170
         return null;

+ 68 - 0
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/utils/LongRangeUtils.java

@@ -0,0 +1,68 @@
1
+package com.chinaitop.depot.intelligent.utils;
2
+
3
+import com.chinaitop.depot.intelligent.grainsituation.model.TTestdata;
4
+import com.chinaitop.depot.intelligent.grainsituation.model.TTestdataLayer;
5
+import com.chinaitop.depot.intelligent.grainsituation.model.TWarningThresholdHistory;
6
+import org.slf4j.Logger;
7
+import org.slf4j.LoggerFactory;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.beans.factory.annotation.Value;
10
+import org.springframework.context.annotation.Configuration;
11
+import org.springframework.scheduling.annotation.Async;
12
+import org.springframework.web.client.RestTemplate;
13
+
14
+import java.util.ArrayList;
15
+
16
+/**
17
+ * 文件描述:远程调用类
18
+ *
19
+ * @author tongxi.xia
20
+ * @date 2020年01月11日 16:06
21
+ */
22
+
23
+@Configuration
24
+public class LongRangeUtils {
25
+    final static Logger logger = LoggerFactory.getLogger(LongRangeUtils.class);
26
+    @Value("${cloud_url}")
27
+    private String cloudUrl;
28
+    @Value("${cloud_url_layer}")
29
+    private String cloudUrlLayer;
30
+    @Value("${cloud_url_warning}")
31
+    private String cloudUrlWarning;
32
+
33
+    @Autowired
34
+    RestTemplate restTemplate;
35
+
36
+    @Async
37
+    public void asyncMethodGrainData(ArrayList<TTestdata> tTestdataList) {
38
+        try {
39
+            String grainJson = JsonToObjectUtils.listToStrings(tTestdataList);
40
+            restTemplate.postForLocation(cloudUrl, grainJson);
41
+            logger.info("向云端推送测温成功cloudUrl参数:" + grainJson);
42
+        } catch (Exception e) {
43
+            logger.info("向云端推送测温失败cloudUrl参数:" + e.getMessage());
44
+        }
45
+    }
46
+
47
+    @Async
48
+    public void asyncMethodGrainLayerData(ArrayList<TTestdataLayer> tTestdataLayerArrayList) {
49
+        try {
50
+            String grainJson = JsonToObjectUtils.listToLayerStrings(tTestdataLayerArrayList);
51
+            restTemplate.postForLocation(cloudUrlLayer, grainJson);
52
+            logger.info("向云端推送测温成功cloudUrlLayer参数:" + grainJson);
53
+        } catch (Exception e) {
54
+            logger.info("向云端推送测温失败cloudUrlLayer参数:" + e.getMessage());
55
+        }
56
+    }
57
+
58
+    @Async
59
+    public void asyncMethodWarningThresholdData(ArrayList<TWarningThresholdHistory> tWarningThresholdHistorieList) {
60
+        try {
61
+            String grainJson = JsonToObjectUtils.listToWarningThresholdStrings(tWarningThresholdHistorieList);
62
+            restTemplate.postForLocation(cloudUrlWarning, grainJson);
63
+            logger.info("向云端推送测温成功cloudUrlWarning参数:" + grainJson);
64
+        } catch (Exception e) {
65
+            logger.info("向云端推送测温失败cloudUrlWarning参数:" + e.getMessage());
66
+        }
67
+    }
68
+}

+ 8 - 0
depot-intelligent/src/main/resources/bootstrap.yml

@@ -63,6 +63,14 @@ gas-org-ids: 386,177,273,280,300,31,32,33,35,190,73,72,24,68,65,141
63 63
 # 数量检测版本区分version3
64 64
 num_version3: :20013
65 65
 
66
+# cloudUrl云端url
67
+#cloud_url: http://localhost:9029/depotGrain/acceptTemperatureData
68
+#cloud_url_layer: http://localhost:9029/depotGrain/acceptTemperatureDataLayer
69
+#cloud_url_warning: http://localhost:9029/depotGrain/acceptTemperatureDataWarning
70
+cloud_url: http://192.167.120.18:9025/depot-intelligent/depotGrain/acceptTemperatureData
71
+cloud_url_layer: http://192.167.120.18:9025/depot-intelligent/depotGrain/acceptTemperatureDataLayer
72
+cloud_url_warning: http://192.167.120.18:9025/depot-intelligent/depotGrain/acceptTemperatureDataWarning
73
+
66 74
 #logging:
67 75
 #    level:
68 76
 #      com.chinaitop.depot.intelligent.grainsituation.mapper: DEBUG