Commit 7831941b authored by wujiang's avatar wujiang

提交

parent 34102153
...@@ -34,9 +34,7 @@ import java.net.HttpURLConnection; ...@@ -34,9 +34,7 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -62,6 +60,8 @@ public class JxiopCarIotListerServiceImpl { ...@@ -62,6 +60,8 @@ public class JxiopCarIotListerServiceImpl {
private EmqKeeper emqkeeper; private EmqKeeper emqkeeper;
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@Autowired
private static Map<String,Object> cache = new HashMap<>();
// @Async("equipAsyncExecutor") // @Async("equipAsyncExecutor")
...@@ -72,9 +72,11 @@ public class JxiopCarIotListerServiceImpl { ...@@ -72,9 +72,11 @@ public class JxiopCarIotListerServiceImpl {
String iotCode = measurement + deviceName; String iotCode = measurement + deviceName;
JSONObject jsonObject = JSONObject.parseObject(message.toString()); JSONObject jsonObject = JSONObject.parseObject(message.toString());
//判断是否有效坐标 //判断是否有效坐标
if (!ObjectUtils.isEmpty(jsonObject.get("FireCar_Longitude")) && !ObjectUtils.isEmpty(jsonObject.get("FireCar_Latitude"))) { if (!ObjectUtils.isEmpty(jsonObject.get("FireCar_Longitude")) && !ObjectUtils.isEmpty(jsonObject.get("FireCar_Latitude"))
&&cache.get(iotCode)==null) {
//判断是否存在未结束进程,如果不存在,则进入判断插入开始节点 //判断是否存在未结束进程,如果不存在,则进入判断插入开始节点
if (iWlCarMileageService.getUncompleteMileagByIotCode(iotCode)) { if (iWlCarMileageService.getUncompleteMileagByIotCode(iotCode)&&cache.get(iotCode)==null) {
cache.put(iotCode,iotCode);
WlCarMileage wlCarMileage = new WlCarMileage(); WlCarMileage wlCarMileage = new WlCarMileage();
wlCarMileage.setIotCode(iotCode); wlCarMileage.setIotCode(iotCode);
wlCarMileage.setDate(new Date()); wlCarMileage.setDate(new Date());
...@@ -97,15 +99,16 @@ public class JxiopCarIotListerServiceImpl { ...@@ -97,15 +99,16 @@ public class JxiopCarIotListerServiceImpl {
e.printStackTrace(); e.printStackTrace();
iWlCarMileageService.save(wlCarMileage); iWlCarMileageService.save(wlCarMileage);
} }
cache.remove(iotCode);
} }
this.updateCarLocation(jsonObject, iotCode); this.updateCarLocation(jsonObject, iotCode);
String coordinate = jsonObject.getString("FireCar_Longitude") + "," + jsonObject.getString("FireCar_Latitude"); String coordinate = jsonObject.getString("FireCar_Longitude") + "," + jsonObject.getString("FireCar_Latitude");
if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get(iotCode))) { if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get(iotCode))) {
redisTemplate.opsForValue().set(iotCode, coordinate, 5, TimeUnit.MINUTES); redisTemplate.opsForValue().set(iotCode, coordinate, 5, TimeUnit.MINUTES);
logger.info("首次入库redis:{}", iotCode); //logger.info("首次入库redis:{}", iotCode);
} else { } else {
if (!String.valueOf(redisTemplate.opsForValue().get(iotCode)).equals(coordinate)) { if (!String.valueOf(redisTemplate.opsForValue().get(iotCode)).equals(coordinate)) {
logger.info("更新入库redis:{},旧:{},新:{}", iotCode, redisTemplate.opsForValue().get(iotCode), coordinate); // logger.info("更新入库redis:{},旧:{},新:{}", iotCode, redisTemplate.opsForValue().get(iotCode), coordinate);
redisTemplate.opsForValue().set(iotCode, coordinate, 5, TimeUnit.MINUTES); redisTemplate.opsForValue().set(iotCode, coordinate, 5, TimeUnit.MINUTES);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment