|
|
@@ -143,61 +143,70 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
|
|
|
Date date = new Date();
|
|
|
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
map.put("riskPlanTriggerTime",dateFormat.format(date));
|
|
|
- if(beaconStr[2]!=null){
|
|
|
- LabBuildFloorLayout labBuildFloorLayout = new LabBuildFloorLayout();
|
|
|
- labBuildFloorLayout.setSubId(Long.parseLong(beaconStr[2]));
|
|
|
- List <LabBuildFloorLayoutVo> layoutVoList = labBuildFloorLayoutService.selectLabBuildFloorLayoutList(labBuildFloorLayout);
|
|
|
- for(LabBuildFloorLayoutVo layoutVo:layoutVoList){
|
|
|
- map.put("buildId",layoutVo.getBuildId());
|
|
|
- map.put("floorId",layoutVo.getFloorId());
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("2------------------------------------》信标丢失:"+beaconStr[1]+",实验室id:"+beaconStr[2]);
|
|
|
- // todo 这里需要根据实验室id查询对应的网关,通过网关查询redis,排查是不是有网关掉线了,如果有,就不通知报警,如果没有,发出报警
|
|
|
- Boolean flag = Boolean.TRUE;
|
|
|
- ResultData<List<Map<String,Object>>> resultData = remoteAirBottleService.getBluetoothBySubId(Long.parseLong(beaconStr[2]));
|
|
|
- if(resultData.getCode()==200){
|
|
|
- List<Map<String,Object>> resultList = resultData.getData();
|
|
|
- for(Map mapGateway : resultList){
|
|
|
- if(redisService.getCacheObject(BaseConstants.BEACON_MAC+"~"+ mapGateway.get("gatewayMac"))==null){
|
|
|
- flag = Boolean.FALSE;
|
|
|
+
|
|
|
+ String key = BaseConstants.REDIS_LOCK + ""+beaconStr[2];
|
|
|
+ if (!redisService.isExistLock(key)) {
|
|
|
+ try{
|
|
|
+ redisService.lock(key,5);
|
|
|
+
|
|
|
+ if(beaconStr[2]!=null){
|
|
|
+ LabBuildFloorLayout labBuildFloorLayout = new LabBuildFloorLayout();
|
|
|
+ labBuildFloorLayout.setSubId(Long.parseLong(beaconStr[2]));
|
|
|
+ List <LabBuildFloorLayoutVo> layoutVoList = labBuildFloorLayoutService.selectLabBuildFloorLayoutList(labBuildFloorLayout);
|
|
|
+ for(LabBuildFloorLayoutVo layoutVo:layoutVoList){
|
|
|
+ map.put("buildId",layoutVo.getBuildId());
|
|
|
+ map.put("floorId",layoutVo.getFloorId());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("3------------------------------------》判别网关是否在线情况:"+flag);
|
|
|
- if(flag){
|
|
|
- List <Map<String,Object>> beaconNoticeList = redisService.getCacheObject(BaseConstants.BEACON_MATE_NOTICE+"~"+beaconStr[2]);
|
|
|
- if(beaconNoticeList != null && beaconNoticeList.size()>0){
|
|
|
- log.info("4------------------------------------》通知消息列表大小:"+beaconNoticeList.size());
|
|
|
- Boolean noticeFlag = Boolean.TRUE;
|
|
|
- for(Map notice:beaconNoticeList){
|
|
|
- if(map.get("beaconTag").equals(notice.get("beaconTag"))){
|
|
|
- noticeFlag = Boolean.FALSE;
|
|
|
+ log.info("2------------------------------------》信标丢失:"+beaconStr[1]+",实验室id:"+beaconStr[2]);
|
|
|
+ // todo 这里需要根据实验室id查询对应的网关,通过网关查询redis,排查是不是有网关掉线了,如果有,就不通知报警,如果没有,发出报警
|
|
|
+ Boolean flag = Boolean.TRUE;
|
|
|
+ ResultData<List<Map<String,Object>>> resultData = remoteAirBottleService.getBluetoothBySubId(Long.parseLong(beaconStr[2]));
|
|
|
+ if(resultData.getCode()==200){
|
|
|
+ List<Map<String,Object>> resultList = resultData.getData();
|
|
|
+ for(Map mapGateway : resultList){
|
|
|
+ if(redisService.getCacheObject(BaseConstants.BEACON_MAC+"~"+ mapGateway.get("gatewayMac"))==null){
|
|
|
+ flag = Boolean.FALSE;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- if(noticeFlag){
|
|
|
- beaconNoticeList.add(map);
|
|
|
- redisService.setCacheObject(BaseConstants.BEACON_MATE_NOTICE+"~"+ beaconStr[2],beaconNoticeList, 30L, TimeUnit.MINUTES);
|
|
|
+ log.info("3------------------------------------》判别网关是否在线情况:"+flag);
|
|
|
+ if(flag){
|
|
|
+ List <Map<String,Object>> beaconNoticeList = redisService.getCacheObject(BaseConstants.BEACON_MATE_NOTICE+"~"+beaconStr[2]);
|
|
|
+ if(beaconNoticeList != null && beaconNoticeList.size()>0){
|
|
|
+ log.info("4------------------------------------》通知消息列表大小:"+beaconNoticeList.size());
|
|
|
+ Boolean noticeFlag = Boolean.TRUE;
|
|
|
+ for(Map notice:beaconNoticeList){
|
|
|
+ if(map.get("beaconTag").equals(notice.get("beaconTag"))){
|
|
|
+ noticeFlag = Boolean.FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(noticeFlag){
|
|
|
+ beaconNoticeList.add(map);
|
|
|
+ redisService.setCacheObject(BaseConstants.BEACON_MATE_NOTICE+"~"+ beaconStr[2],beaconNoticeList, 30L, TimeUnit.MINUTES);
|
|
|
+ }
|
|
|
+ //下发通知,告诉前端页面,查询redis获取相关信息
|
|
|
+ messageSendService.bluetoothGatewayToMac(Long.parseLong(beaconStr[2]));
|
|
|
+ //向前端发送mqtt预案触发提示
|
|
|
+ messageSendService.riskPlanTriggerNotice();
|
|
|
+ }else{
|
|
|
+ log.info("5------------------------------------》新消息通知:"+map);
|
|
|
+ List<Map <String,Object>> beaconList = new ArrayList <>();
|
|
|
+ beaconList.add(map);
|
|
|
+ redisService.setCacheObject(BaseConstants.BEACON_MATE_NOTICE+"~"+ beaconStr[2],beaconList, 30L, TimeUnit.MINUTES);
|
|
|
+ //下发通知,告诉前端页面,查询redis获取相关信息
|
|
|
+ messageSendService.bluetoothGatewayToMac(Long.parseLong(beaconStr[2]));
|
|
|
+ //向前端发送mqtt预案触发提示
|
|
|
+ messageSendService.riskPlanTriggerNotice();
|
|
|
+ }
|
|
|
+ Map <String,String> tagMap = new HashMap<>();
|
|
|
+ tagMap.put("beaconTag",beaconStr[1]);
|
|
|
+ remoteAirBottleService.beaconAdd(tagMap);
|
|
|
}
|
|
|
- //下发通知,告诉前端页面,查询redis获取相关信息
|
|
|
- messageSendService.bluetoothGatewayToMac(Long.parseLong(beaconStr[2]));
|
|
|
- //向前端发送mqtt预案触发提示
|
|
|
- messageSendService.riskPlanTriggerNotice();
|
|
|
- }else{
|
|
|
- log.info("5------------------------------------》新消息通知:"+map);
|
|
|
- List<Map <String,Object>> beaconList = new ArrayList <>();
|
|
|
- beaconList.add(map);
|
|
|
- redisService.setCacheObject(BaseConstants.BEACON_MATE_NOTICE+"~"+ beaconStr[2],beaconList, 30L, TimeUnit.MINUTES);
|
|
|
- //下发通知,告诉前端页面,查询redis获取相关信息
|
|
|
- messageSendService.bluetoothGatewayToMac(Long.parseLong(beaconStr[2]));
|
|
|
- //向前端发送mqtt预案触发提示
|
|
|
- messageSendService.riskPlanTriggerNotice();
|
|
|
+ }finally {
|
|
|
+ redisService.unLock(key);
|
|
|
}
|
|
|
- Map <String,String> tagMap = new HashMap<>();
|
|
|
- tagMap.put("beaconTag",beaconStr[1]);
|
|
|
- remoteAirBottleService.beaconAdd(tagMap);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|