Просмотр исходного кода

蓝牙网关报文上报优化

zhb.dong 1 год назад
Родитель
Сommit
9d5321f802

+ 1 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/event/RedisExpiredAndWorkListener.java

@@ -88,6 +88,7 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
     @Override
     public void onMessage(Message message, byte[] bytes) {
         String expiredKey = new String(message.getBody());
+        log.info("The key has expired,key :{}",expiredKey);
         if(expiredKey.indexOf(BaseConstants.DELAY_QUEUE)!=-1){
             log.info("定时排风key失效后,需要执行对应的任务------------------"+expiredKey);
             String[] delayStr = expiredKey.split(BaseConstants.DELAY_QUEUE+"~");

+ 31 - 29
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/socket/service/impl/BeaconMateImpl.java

@@ -15,10 +15,7 @@ import com.zd.model.domain.ResultData;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -56,8 +53,8 @@ public class BeaconMateImpl implements BeaconMate {
 
                 ResultData<Map<String,Object>> resultData = remoteAirBottleService.getSubByMac(mac);
                 if(resultData.getCode()==200 && resultData.getData() != null){
-                    // redis存储蓝牙网关mac地址,用于在线离线问题。
-                    redisService.setCacheObject(BaseConstants.BEACON_MAC+"~"+ mac,mac, 60L, TimeUnit.SECONDS);
+                    // redis存储蓝牙网关mac地址,用于在线离线问题。 更新蓝牙网关缓存过期时间为15分钟
+                    redisService.setCacheObject(BaseConstants.BEACON_MAC+"~"+ mac,mac, 15L, TimeUnit.MINUTES);
                     log.info("{} 2=====================================》获取实验室id:"+resultData.getData().get("subId"),uuid);
                     Long subId = Long.parseLong(resultData.getData().get("subId")+"");
                     List <Map<String,Object>> beaconList = redisService.getCacheObject(BaseConstants.BEACON_MATE_INFO+"~"+subId);
@@ -78,33 +75,38 @@ public class BeaconMateImpl implements BeaconMate {
                             newNoticeList.addAll(beaconNoticeList);
                         }
                         StringBuilder beaconTagBuild = new StringBuilder();
-                        // 循环检查实验室的信标比对上报的信标,将配对好的信标重新设置默认时间
-                        for(int x=0;x<beaconList.size();x++){
-                            if(array.size()>0){
-                                // 这里需要比对redis存储的蓝牙信息列表和上报的列表信息 稍后补全这块
-                                for(int i=0;i<array.size();i++){
-                                    String beaconStr = array.getString(i);
-                                    //初步过滤只有b5的数据
-                                    if(beaconStr.endsWith("b5")){
-                                        // 这里需要处理信标字符串
-                                        beaconStr = checkBeacon(beaconStr);
-                                        if(beaconList.get(x).get("beaconTag").equals(beaconStr)){
-                                            log.info("{} 4.=====================================》上报的信标处理后返回信标编码:"+beaconStr+"; {} 实验室下匹配后的信标:"+beaconList.get(x).get("beaconTag"),uuid,subId);
-                                            // redis存储蓝牙信标编码和实验室id和mac地址
-                                            redisService.setCacheObject(BaseConstants.BEACON_MATE_DET+"~"+ beaconStr+"~"+subId+"~"+beaconList.get(x).get("gasName"),beaconStr, 30L, TimeUnit.MINUTES);
-                                            // 循环信标通知,把还回来的气瓶提示移除。
-                                            if(beaconNoticeList != null){
-                                                for(Map notice:beaconNoticeList){
-                                                    if(notice.get("beaconTag").equals(beaconStr)){
-                                                        log.info("{} 5.=====================================》 {} 移除返回来的信标提示语:"+notice,uuid,subId);
-                                                        newNoticeList.remove(notice);
-                                                        beaconTagBuild.append(",");
-                                                        beaconTagBuild.append(beaconStr);
+                        if(array.size()>0){
+                            // 这里需要比对redis存储的蓝牙信息列表和上报的列表信息 稍后补全这块
+                            for(int i=0;i<array.size();i++){
+                                String beaconStr = array.getString(i);
+                                //初步过滤只有b5的数据
+                                if(beaconStr.endsWith("b5")){
+                                    boolean flag = Boolean.FALSE;
+                                    // 循环检查实验室的信标比对上报的信标,将配对好的信标重新设置默认时间
+                                    for(int x=0;x<beaconList.size();x++){
+                                            // 这里需要处理信标字符串
+                                            beaconStr = checkBeacon(beaconStr);
+                                            if(beaconList.get(x).get("beaconTag").equals(beaconStr)){
+                                                log.info("{} 4.=====================================》上报的信标处理后返回信标编码:"+beaconStr+"; {} 实验室下匹配后的信标:"+beaconList.get(x).get("beaconTag"),uuid,subId);
+                                                flag=Boolean.TRUE;
+                                                // redis存储蓝牙信标编码和实验室id和mac地址
+                                                redisService.setCacheObject(BaseConstants.BEACON_MATE_DET+"~"+ beaconStr+"~"+subId+"~"+beaconList.get(x).get("gasName"),beaconStr, 30L, TimeUnit.MINUTES);
+                                                // 循环信标通知,把还回来的气瓶提示移除。
+                                                if(beaconNoticeList != null){
+                                                    for(Map notice:beaconNoticeList){
+                                                        if(notice.get("beaconTag").equals(beaconStr)){
+                                                            log.info("{} 5.=====================================》 {} 移除返回来的信标提示语:"+notice,uuid,subId);
+                                                            newNoticeList.remove(notice);
+                                                            beaconTagBuild.append(",");
+                                                            beaconTagBuild.append(beaconStr);
+                                                        }
                                                     }
                                                 }
                                             }
                                         }
-                                    }
+                                        if(!flag){
+                                            log.info("{} 4.1蓝牙网关串报,忽略信标.beaconStr:{}",uuid,beaconStr);
+                                        }
                                 }
                             }
                         }