Преглед изворни кода

集成良安的测温服务

fanxw пре 2 година
родитељ
комит
d020db843f

+ 2 - 0
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/grainsituation/service/TemperatureRecordService.java

@@ -23,6 +23,8 @@ public interface TemperatureRecordService {
23 23
     void insertBatch(List<TTestdata> testData);
24 24
 
25 25
     List<TTestdata> getByCodeAndTimes(List<String> cDcsCodes,List<Date> cTimes,List<String> lqTypes);
26
+    
27
+    List<TTestdata> findByConditions(String storehouseCode, Date cTimes, String lqTypes);
26 28
 
27 29
     String getOrgId (String cfCode);
28 30
 

+ 18 - 2
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/grainsituation/service/impl/TemperatureRecordServiceImpl.java

@@ -201,6 +201,20 @@ public class TemperatureRecordServiceImpl implements TemperatureRecordService {
201 201
     }
202 202
 
203 203
     @Override
204
+	public List<TTestdata> findByConditions(String storehouseCode, Date cTimes, String lqTypes) {
205
+    	TTestdataExample example = new TTestdataExample();
206
+    	TTestdataExample.Criteria criteria = example.createCriteria();
207
+    	if (StringUtils.isNotBlank(storehouseCode) && cTimes != null && StringUtils.isNotBlank(lqTypes)) {
208
+            criteria.andStorehouseEqualTo(storehouseCode);
209
+            criteria.andTimeEqualTo(cTimes);
210
+            criteria.andIlqYqEqualTo(lqTypes);
211
+            List<TTestdata> tTestdata = tTestdataMapper.selectByExample(example);
212
+            return tTestdata;
213
+        }
214
+        return null;
215
+	}
216
+
217
+    @Override
204 218
     public String getOrgId(String cfCode) {
205 219
         return tTestdataMapper.getOrgId(cfCode);
206 220
     }
@@ -287,9 +301,11 @@ public class TemperatureRecordServiceImpl implements TemperatureRecordService {
287 301
         } else {////给佳华发送指令
288 302
             DataGatherCenterService dataGatherCenterService = SendEntity.grainWs();
289 303
             if (StringUtils.isNotBlank(storeCode)) {
290
-            	s = dataGatherCenterService.sendTemperatureDetection("");
291
-            } else {
304
+            	logger.info("(嘉华)发送测温指令参数是:"+storeCode);
292 305
             	s = dataGatherCenterService.sendTemperatureDetection(storeCode);
306
+            } else {
307
+            	logger.info("(嘉华)发送测温指令参数是:空,为全仓检测");
308
+            	s = dataGatherCenterService.sendTemperatureDetection("");
293 309
             }
294 310
             logger.info("(嘉华)发送测温指令后返回结果:"+s);
295 311
             if (s.contains(":0")){

+ 30 - 15
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/utils/LongRangeUtils.java

@@ -12,13 +12,13 @@ import java.util.stream.Collectors;
12 12
 
13 13
 import javax.annotation.Resource;
14 14
 
15
+import org.apache.commons.lang3.StringUtils;
15 16
 import org.slf4j.Logger;
16 17
 import org.slf4j.LoggerFactory;
17 18
 import org.springframework.context.annotation.Configuration;
18 19
 import org.springframework.transaction.annotation.Transactional;
19 20
 
20 21
 import com.chinaitop.depot.intelligent.basicdata.model.SysSerial;
21
-import com.chinaitop.depot.intelligent.basicdata.model.TWarningThreshold;
22 22
 import com.chinaitop.depot.intelligent.basicdata.service.SysSerialService;
23 23
 import com.chinaitop.depot.intelligent.basicdata.service.WarningThresholdService;
24 24
 import com.chinaitop.depot.intelligent.grainsituation.mapper.TTestdataLayerMapper;
@@ -30,7 +30,6 @@ import com.chinaitop.depot.intelligent.grainsituation.model.TTestdata;
30 30
 import com.chinaitop.depot.intelligent.grainsituation.model.TTestdataLayer;
31 31
 import com.chinaitop.depot.intelligent.grainsituation.model.TTestdataLog;
32 32
 import com.chinaitop.depot.intelligent.grainsituation.model.TTestdataPoints;
33
-import com.chinaitop.depot.intelligent.grainsituation.model.TWarningThresholdHistory;
34 33
 import com.chinaitop.depot.intelligent.grainsituation.service.TemperatureRecordService;
35 34
 import com.google.common.collect.Lists;
36 35
 
@@ -110,16 +109,17 @@ public class LongRangeUtils {
110 109
             List<Date> cTimes = tts.stream().map(TTestdata::getTime).collect(Collectors.toList());
111 110
             List<String> lqTypes = tts.stream().map(TTestdata::getIlqYq).collect(Collectors.toList());
112 111
             //校验重复数据
113
-            List<TTestdata> byCodeAndTimes = temperatureRecordService.getByCodeAndTimes(cDcsCodes, cTimes, lqTypes);
114
-            if (byCodeAndTimes != null && byCodeAndTimes.size() > INT_ZERO) {
115
-                logger.info("上传数据重复!");
116
-                return;
117
-            }
118
-            String orgId = temperatureRecordService.getOrgId(cDcsCodes.get(INT_ZERO));
119
-            if (null != orgId && !"".equals(orgId)) {
120
-            	ts.forEach(obj -> {
112
+//            List<TTestdata> byCodeAndTimes = temperatureRecordService.getByCodeAndTimes(cDcsCodes, cTimes, lqTypes);
113
+//            if (byCodeAndTimes != null && byCodeAndTimes.size() > INT_ZERO) {
114
+//                logger.info("上传数据重复!");
115
+//                return;
116
+//            }
117
+//            String orgId = temperatureRecordService.getOrgId(cDcsCodes.get(INT_ZERO));
118
+//            if (null != orgId && !"".equals(orgId)) {
119
+            	for (int i = 0; i < ts.size(); i++) { 
120
+            	//ts.forEach(obj -> {
121 121
             		String testdataId = UuidUtils.getCode();
122
-            		TTestdata tTestdata = (TTestdata) obj;
122
+            		TTestdata tTestdata = (TTestdata) ts.get(i);
123 123
             		String house = tTestdata.getStorehouse();
124 124
             		Date time = tTestdata.getTime();
125 125
             		List<TPoints> ps = tTestdata.getPoints();
@@ -135,6 +135,20 @@ public class LongRangeUtils {
135 135
             				.replace("x:", "")
136 136
             				.replace("y:", "")
137 137
             				.replace("z:", "");
138
+
139
+            		//检查仓房编号是否可识别
140
+            		String orgId = temperatureRecordService.getOrgId(house);
141
+            		if (StringUtils.isBlank(orgId)) {
142
+            			logger.info("仓房编号为"+house+"的数据无法识别,所以跳过不保存!");
143
+            			continue;
144
+            		}
145
+            		//校验重复数据
146
+            		List<TTestdata> byCodeAndTimes = temperatureRecordService.findByConditions(house, time, tTestdata.getIlqYq());
147
+            		if (byCodeAndTimes != null && byCodeAndTimes.size() > INT_ZERO) {
148
+                        logger.info("storehouse为"+house+",time为"+ParameterUtil.date2YMDHMS(time)+",ilqYq为"+tTestdata.getIlqYq()+"的数据已存在,所以不保存!");
149
+                        continue;
150
+                    }
151
+            		
138 152
             		//获取报警阈值信息6972测温 6983温度高限 6982温度底限 6991温度预警
139 153
 //            		TWarningThreshold threshold = null; //温度高限
140 154
 //            		TWarningThreshold wLowest = null; //温度底限
@@ -396,7 +410,7 @@ public class LongRangeUtils {
396 410
             				}
397 411
             			}*/
398 412
             		}
399
-            	});
413
+            	}
400 414
             	if (tTestdataList.size() > INT_ZERO) {
401 415
             		temperatureRecordService.insertBatch(tTestdataList);
402 416
             	}
@@ -410,9 +424,10 @@ public class LongRangeUtils {
410 424
             		tTestdataPointsMapper.insertBatch(points_list);
411 425
             	}
412 426
             	logger.info("测温数据入库业务表成功");
413
-            } else {
414
-            	logger.info("返回数据后存储异常:未获取到orgId值,所以不保存数据!");
415
-            }
427
+//            }
428
+//            else {
429
+//            	logger.info("返回数据后存储异常:未获取到orgId值,所以不保存数据!");
430
+//            }
416 431
 
417 432
         } catch (Exception e) {
418 433
             logger.info("测温异常:" + e.getMessage());

+ 7 - 48
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/utils/ParameterUtil.java

@@ -79,6 +79,12 @@ public class ParameterUtil {
79 79
         return str;
80 80
     }
81 81
 
82
+    public static String date2YMDHMS(Date date){
83
+        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
84
+        String str=sdf.format(date);
85
+        return str;
86
+    }
87
+
82 88
     /**
83 89
      * 获取指定时间的时间戳
84 90
      * @param datatime
@@ -109,54 +115,7 @@ public class ParameterUtil {
109 115
     }
110 116
 
111 117
     public static void main(String[] args) {
112
-    	for (int l=0;l<3;l++) {
113
-    		String redisKey = "20230422";
114
-    		RedisUtil re = new RedisUtil();
115
-    		List<Object> values = null;
116
-    		boolean flag = re.hasKey("aa");
117
-    		if (!flag) {
118
-    			//缓存中的数据为空 则生成0000- 9999放到缓存
119
-    	        values = new ArrayList<>();
120
-    	        int i = 0;
121
-    	        while (i <= 5){
122
-    	            values.add(String.format("%1$04d", i));
123
-    	            i++;
124
-    	        }
125
-    	        //放入redis缓存
126
-    	        re.lSet(redisKey, values, getRemainSecondsOneDay(new Date()));
127
-    	        //设置键位redisKey的缓存在凌晨的时候过期
128
-    	        //re.expire(redisKey,getRemainSecondsOneDay(new Date()));
129
-    		} else {
130
-    			values = re.lGetAll(redisKey);
131
-    		}
132
-    		Random random = new Random();
133
-    		int index = random.nextInt(values.size() - 1);
134
-    	    String code = (String) values.get(index);
135
-    	    //删除已经使用的编号 
136
-    	    values.remove(index);
137
-    	    //重新更新
138
-    	    re.setRemove(redisKey, code);
139
-//    		List<Object> values = re.lGetAll(redisKey);
140
-//    	    if(CollectionUtils.isEmpty(values)){
141
-//    	        //缓存中的数据为空 则生成0000- 9999放到缓存
142
-//    	        values = new ArrayList<>();
143
-//    	        int i = 0;
144
-//    	        while (i <= 5){
145
-//    	            values.add(String.format("%1$04d", i));
146
-//    	            i++;
147
-//    	        }
148
-//    	    }
149
-//    	    //生成0 ~ values长度 随机数
150
-//    	    Random random = new Random();
151
-//    	    int index = random.nextInt(values.size() - 1);
152
-//    	    String code = (String) values.get(index);
153
-//    	    //删除已经使用的编号 更新到缓存中
154
-//    	    values.remove(index);
155
-//    	    re.setRemove(redisKey, code);
156
-
157
-    		//System.out.println(code);
158
-    	}
159
-		
118
+    	System.out.println(date2YMDHMS(new Date()));
160 119
     }
161 120
     
162 121
     public static Integer getRemainSecondsOneDay(Date currentDate) {

+ 2 - 1
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/utils/createKC.java

@@ -41,7 +41,8 @@ public class createKC {
41 41
 		JSONObject object = null;
42 42
 		try {
43 43
 			logger.info("准备请求webservice...");
44
-			logger.info(url);
44
+			logger.info("地址:"+url);
45
+			logger.info("参数:"+parameters);
45 46
 			res = client.invoke(opName, parameters);
46 47
 			object = JSONObject.fromObject(res[0]);
47 48
 			logger.info("调用webservice后返回结果:" + object.toString());