Przeglądaj źródła

定时任务多设备检测;

zlq 2 lat temu
rodzic
commit
c70790ec63

+ 1 - 1
src/main/java/com/unissoft/interaction/controller/DataController.java

@@ -55,7 +55,7 @@ public class DataController {
55 55
         teData.setEtime(new Date());
56 56
         //根据唯一的taskId(仓房id+自然增长id)获取仓房id
57 57
         String houseId = teData.getTaskID().split(",")[0];	
58
-        OrgInfo orgInfoHouse = orgInfoService.getById(Integer.parseInt(houseId));
58
+        OrgInfo orgInfoHouse = orgInfoService.getById(Long.parseLong(houseId));
59 59
         
60 60
         
61 61
         int inum = teDataService.saveTeData(teData); //打点数据返回

+ 5 - 5
src/main/java/com/unissoft/interaction/service/impl/SquareServiceImpl.java

@@ -84,7 +84,7 @@ public class SquareServiceImpl implements SquareService {
84 84
 
85 85
     	//根据仓房id 获取设备编号
86 86
   		QueryWrapper<HardwareParameter> queryWrapper = new QueryWrapper<>();
87
-        queryWrapper.eq("house_id", Integer.parseInt(cfId));
87
+        queryWrapper.eq("house_id", Long.parseLong(cfId));
88 88
         List<HardwareParameter> hardList = hardwareParameterMapper.selectList(queryWrapper);
89 89
         if(hardList.size()>0){
90 90
         	STask task = new STask();
@@ -136,11 +136,11 @@ public class SquareServiceImpl implements SquareService {
136 136
         	
137 137
         	//查询设备的ip和端口
138 138
             QueryWrapper<HardwareParameter> queryWrapper = new QueryWrapper<>();
139
-            queryWrapper.eq("house_id", Integer.parseInt(houseId));
139
+            queryWrapper.eq("house_id", Long.parseLong(houseId));
140 140
             List<HardwareParameter> hardList = hardwareParameterMapper.selectList(queryWrapper);
141 141
             
142 142
             if(hardList.size()>0){
143
-            	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Integer.parseInt(houseId));//--------------------待完
143
+            	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Long.parseLong(houseId));//--------------------待完
144 144
             	
145 145
             	/*double houseWideOn = 0;
146 146
                 double houseWideUnder = 0;
@@ -245,7 +245,7 @@ public class SquareServiceImpl implements SquareService {
245 245
         
246 246
         //根据仓房id查询其信息
247 247
     	String houseId = taskID.split(",")[0];//仓房id
248
-    	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Integer.parseInt(houseId));//--------------------
248
+    	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Long.parseLong(houseId));//--------------------
249 249
     	
250 250
     	/*double houseWideOn = 0;
251 251
         double houseWideUnder = 0;
@@ -280,7 +280,7 @@ public class SquareServiceImpl implements SquareService {
280 280
     	
281 281
     	String houseId = taskId.split(",")[0];//仓房id
282 282
         //获取仓房信息
283
-    	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Integer.parseInt(houseId));
283
+    	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Long.parseLong(houseId));
284 284
 		String high = orgInfoHouse.getHigh();//高
285 285
 		Double h = Double.parseDouble(high);
286 286
 		double houseWideOn = orgInfoHouse.getHouseWideOn().doubleValue();

+ 46 - 48
src/main/java/com/unissoft/interaction/service/impl/TeDataServiceImpl.java

@@ -33,10 +33,7 @@ import org.springframework.web.client.RestTemplate;
33 33
 
34 34
 import java.math.BigDecimal;
35 35
 import java.math.RoundingMode;
36
-import java.util.ArrayList;
37
-import java.util.Collections;
38
-import java.util.Date;
39
-import java.util.List;
36
+import java.util.*;
40 37
 
41 38
 import javax.annotation.Resource;
42 39
 
@@ -46,7 +43,8 @@ public class TeDataServiceImpl implements TeDataService {
46 43
     private static final Logger logger = LoggerFactory.getLogger(TeDataServiceImpl.class);
47 44
 
48 45
     //static String base_url = "http://192.168.0.61:4017/";
49
-    static boolean flag = true;
46
+    private static HashMap<String, Object> flag=new HashMap<>() ;
47
+//    static boolean flag = true;
50 48
     static double h1 = 6; //h1 圆锥的高
51 49
     static double h2 = 3; //h2 水平地面到圆锥尖的高
52 50
     private STaskMapper sTaskMapper;
@@ -113,7 +111,7 @@ public class TeDataServiceImpl implements TeDataService {
113 111
 
114 112
         postHelper(teData,base_url);
115 113
         //equipmentTestingEnd
116
-        flag = true;
114
+//        flag = true;
117 115
 
118 116
     }
119 117
     
@@ -126,7 +124,7 @@ public class TeDataServiceImpl implements TeDataService {
126 124
 		// TODO Auto-generated method stub
127 125
 		//根据仓房id 获取设备编号
128 126
 		QueryWrapper<HardwareParameter> queryWrapper = new QueryWrapper<>();
129
-        queryWrapper.eq("house_id", Integer.parseInt(cfId));
127
+        queryWrapper.eq("house_id", Long.parseLong(cfId));
130 128
         List<HardwareParameter> hardList = hardwareParameterMapper.selectList(queryWrapper);
131 129
         if(hardList.size()>0){
132 130
         	logger.info("圆筒{}仓第一次打点的直径和高: {},{}",cfId ,diameter,h);
@@ -150,8 +148,8 @@ public class TeDataServiceImpl implements TeDataService {
150 148
             
151 149
             //发送给硬件
152 150
             postHelper(teData,base_url);
153
-           
154
-            flag = true;
151
+
152
+//            flag = true;
155 153
             
156 154
         }
157 155
 	}
@@ -170,7 +168,7 @@ public class TeDataServiceImpl implements TeDataService {
170 168
             e.printStackTrace();
171 169
         }
172 170
         //只运行 发送一次。
173
-        if (flag) {
171
+
174 172
            
175 173
             // 第二次待打点
176 174
 
@@ -184,41 +182,41 @@ public class TeDataServiceImpl implements TeDataService {
184 182
             
185 183
             //查询设备的ip和端口
186 184
             QueryWrapper<HardwareParameter> queryWrapper = new QueryWrapper<>();
187
-            queryWrapper.eq("house_id", Integer.parseInt(houseId));
185
+            queryWrapper.eq("house_id", Long.parseLong(houseId));
188 186
             List<HardwareParameter> hardList = hardwareParameterMapper.selectList(queryWrapper);
189
-            
190
-            if(hardList.size()>0){
187
+        //判断是否已经进行过第二次打点,如果有设备信息,且设备flag中无此设备,即进行第二次打点;
188
+        if(hardList.size()>0&& !flag.containsKey(hardList.get(0).getIpAdress()) ){
191 189
             	
192
-            	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Integer.parseInt(houseId));
193
-            	String high = orgInfoHouse.getHigh();//仓房的高
194
-        		String radius = orgInfoHouse.getRadius();//仓房的半径
195
-        		Double diameter = Double.parseDouble(radius)*2;//直径
196
-        		Double h = Double.parseDouble(high);
197
-        		
198
-        		List<Double> zList = CylinderAlg.getValidZ(teData.getRotationxy(), diameter, h);
199
-        		double z = Collections.max(zList);//纵坐标的最大值
200
-        		double z1 = Collections.min(zList);//纵坐标的最小值
201
-        		//第二次打点的高
202
-        		//double secondH = h - z;//仓房的高-点的纵坐标
203
-        		double secondH = z;
204
-                logger.info("z {} ,z1 {},diameter {},secondH {}",z,z1,diameter,secondH);
205
-
206
-                //打点
207
-                String rotationxy = CylinderAlg.getAveragePosition1(diameter, secondH);
208
-                teData.setRotationxy(rotationxy);
209
-                teData.setStime(new Date());//第二次开始的时间
210
-                
211
-            	//IP地址
212
-                String base_url = "http://"+hardList.get(0).getIpAdress()+":"+hardList.get(0).getPort()+"/";
213
-                
214
-            	//发送给硬件打点数据
215
-                postHelper(teData,base_url);
216
-
217
-                flag = false;
218
-            }
219
-            
220
-            
221
-        } else { 
190
+            OrgInfo orgInfoHouse = orgInfoMapper.selectById(Long.parseLong(houseId));
191
+            String high = orgInfoHouse.getHigh();//仓房的高
192
+            String radius = orgInfoHouse.getRadius();//仓房的半径
193
+            Double diameter = Double.parseDouble(radius)*2;//直径
194
+            Double h = Double.parseDouble(high);
195
+
196
+            List<Double> zList = CylinderAlg.getValidZ(teData.getRotationxy(), diameter, h);
197
+            double z = Collections.max(zList);//纵坐标的最大值
198
+            double z1 = Collections.min(zList);//纵坐标的最小值
199
+            //第二次打点的高
200
+            //double secondH = h - z;//仓房的高-点的纵坐标
201
+            double secondH = z;
202
+            logger.info("z {} ,z1 {},diameter {},secondH {}",z,z1,diameter,secondH);
203
+
204
+            //打点
205
+            String rotationxy = CylinderAlg.getAveragePosition1(diameter, secondH);
206
+            teData.setRotationxy(rotationxy);
207
+            teData.setStime(new Date());//第二次开始的时间
208
+
209
+            //IP地址
210
+            String base_url = "http://"+hardList.get(0).getIpAdress()+":"+hardList.get(0).getPort()+"/";
211
+
212
+            //发送给硬件打点数据
213
+            postHelper(teData,base_url);
214
+            //已打点设备信息
215
+            flag.put(hardList.get(0).getIpAdress(),"");
216
+//           flag = false;
217
+
218
+        } else {
219
+            flag.remove(hardList.get(0).getIpAdress());
222 220
         	//打点两次完毕 计算体积
223 221
         	 logger.info("计算体积。。。。");
224 222
             double v = this.calculateVolume(teData.getTaskID());//两次数据
@@ -277,7 +275,7 @@ public class TeDataServiceImpl implements TeDataService {
277 275
         	
278 276
         	//获取直径
279 277
         	String houseId = taskID.split(",")[0];//仓房id
280
-        	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Integer.parseInt(houseId));
278
+        	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Long.parseLong(houseId));
281 279
     		String radius = orgInfoHouse.getRadius();//仓房的半径
282 280
     		Double diameter = Double.parseDouble(radius)*2;//直径
283 281
     		String high = orgInfoHouse.getHigh();//高
@@ -313,7 +311,7 @@ public class TeDataServiceImpl implements TeDataService {
313 311
         	String rotationxy = teDataList.get(0).getRotationxy();
314 312
         	//获取直径
315 313
         	String houseId = taskID.split(",")[0];//仓房id
316
-        	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Integer.parseInt(houseId));
314
+        	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Long.parseLong(houseId));
317 315
     		String radius = orgInfoHouse.getRadius();//仓房的半径
318 316
     		Double diameter = Double.parseDouble(radius)*2;//直径
319 317
     		String high = orgInfoHouse.getHigh();//高
@@ -366,7 +364,7 @@ public class TeDataServiceImpl implements TeDataService {
366 364
         
367 365
         
368 366
         //获取仓房信息
369
-    	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Integer.parseInt(houseId));
367
+    	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Long.parseLong(houseId));
370 368
     	
371 369
     	//获取其库名称
372 370
     	OrgInfo orgInfo = orgInfoMapper.selectById(orgInfoHouse.getParentId());
@@ -411,7 +409,7 @@ public class TeDataServiceImpl implements TeDataService {
411 409
     	
412 410
     	String houseId = taskId.split(",")[0];//仓房id
413 411
         //获取仓房信息
414
-    	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Integer.parseInt(houseId));
412
+    	OrgInfo orgInfoHouse = orgInfoMapper.selectById(Long.parseLong(houseId));
415 413
 		String radius = orgInfoHouse.getRadius();//仓房的半径
416 414
 		Double diameter = Double.parseDouble(radius)*2;//直径
417 415
 		String high = orgInfoHouse.getHigh();//高
@@ -491,7 +489,7 @@ public class TeDataServiceImpl implements TeDataService {
491 489
 		// TODO Auto-generated method stub
492 490
 		//根据仓房id 获取设备编号
493 491
 				QueryWrapper<HardwareParameter> queryWrapper = new QueryWrapper<>();
494
-		        queryWrapper.eq("house_id", Integer.parseInt(cfId));
492
+		        queryWrapper.eq("house_id", Long.parseLong(cfId));
495 493
 		        List<HardwareParameter> hardList = hardwareParameterMapper.selectList(queryWrapper);
496 494
 		        StringBuffer sb = new StringBuffer();
497 495
 		        if(hardList.size()>0){

+ 2 - 2
src/main/java/com/unissoft/mqConsumer/Consumer.java

@@ -33,7 +33,7 @@ public class Consumer {
33 33
     private final static String topicCloud="TOPIC_CLOUD";
34 34
 
35 35
 
36
-   /* @Component
36
+    @Component
37 37
     @RocketMQMessageListener(topic = topicLocal,consumerGroup = "local")
38 38
     public class HPSave implements RocketMQListener<String>{
39 39
         @Override
@@ -82,6 +82,6 @@ public class Consumer {
82 82
                     log.info("没有可用的业务类型!!{}",message);
83 83
             }
84 84
         }
85
-    }*/
85
+    }
86 86
 
87 87
 }

+ 8 - 8
src/main/java/com/unissoft/mqProducer/Producer.java

@@ -32,8 +32,8 @@ public class Producer {
32 32
     //云端topic,云端使用
33 33
     private final String topicCloud="TOPIC_CLOUD";
34 34
 
35
-//    @Autowired
36
-//    private RocketMQTemplate rocketMQTemplate;
35
+    @Autowired
36
+    private RocketMQTemplate rocketMQTemplate;
37 37
 
38 38
     /**
39 39
      *
@@ -41,12 +41,12 @@ public class Producer {
41 41
      * @param type  消息属性
42 42
      */
43 43
     public void send(Object body, MessageEnum type, ServiceEnum ser){
44
-        Map<String, Object> map = new HashMap<>();
45
-        map.put("type",type);
46
-        map.put("service",ser);
47
-        /*org.springframework.messaging.Message<Object> message = MessageBuilder.createMessage(body, new MessageHeaders(map));
48
-        rocketMQTemplate.convertAndSend(topicCloud,message);
49
-        log.info("发送消息:{}",message);*/
44
+//        Map<String, Object> map = new HashMap<>();
45
+//        map.put("type",type);
46
+//        map.put("service",ser);
47
+//        org.springframework.messaging.Message<Object> message = MessageBuilder.createMessage(body, new MessageHeaders(map));
48
+//        rocketMQTemplate.convertAndSend(topicCloud,message);
49
+//        log.info("发送消息:{}",message);
50 50
     }
51 51
 
52 52
     /**

+ 1 - 1
src/main/java/com/unissoft/parameter/service/impl/HardwareParameterServiceImpl.java

@@ -46,7 +46,7 @@ public class HardwareParameterServiceImpl extends ServiceImpl<HardwareParameterM
46 46
         if (!StringUtils.isEmpty(condition)) {
47 47
         	com.alibaba.fastjson.JSONObject jsStr = JSON.parseObject(condition);
48 48
     		String deviceName = jsStr.getString("deviceName");//设备名称
49
-    		Integer houseId = jsStr.getInteger("houseId");
49
+    		Long houseId = jsStr.getLong("houseId");
50 50
     		if(!StringUtils.isEmpty(houseId.toString())){
51 51
     			ew.eq("house_id", houseId);
52 52
     		}