|
|
@@ -39,64 +39,66 @@ public class BeaconMateImpl implements BeaconMate {
|
|
|
private RemoteLaboratoryService remoteLaboratoryService = SpringUtils.getBean(RemoteLaboratoryService.class);
|
|
|
|
|
|
public void sendBeaconMate(String dataStr){
|
|
|
- log.info("1=====================================》上报蓝牙网关编码:"+dataStr);
|
|
|
- JSONObject jsonObject=JSONObject.parseObject(dataStr);
|
|
|
- String mac = jsonObject.getString("mac");
|
|
|
- if(mac!=null && !"".equals(mac)){
|
|
|
- // 这里用线程去修改网关的具体在线状态
|
|
|
- Boolean initFlag = Boolean.FALSE;
|
|
|
- if(redisService.getCacheObject(BaseConstants.BEACON_MAC+"~"+ mac)==null){
|
|
|
- setOpenBluetoothGateway(mac);
|
|
|
- // 这里每次重启网关,或者第一次开启网关,需要把信标全部重新加载一次
|
|
|
- initFlag = Boolean.TRUE;
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- log.info("2=====================================》获取实验室id:"+resultData.getData().get("subId"));
|
|
|
- Long subId = Long.parseLong(resultData.getData().get("subId")+"");
|
|
|
- List <Map<String,Object>> beaconList = redisService.getCacheObject(BaseConstants.BEACON_MATE_INFO+"~"+subId);
|
|
|
- if(beaconList==null || initFlag){
|
|
|
- log.info("2.1=====================================》初始化实验室信标列表和实验室下的所有信标生命周期");
|
|
|
- // 根据实验室id获取蓝牙信标列表
|
|
|
- remoteAirBottleService.setBeaconBySubId(subId);
|
|
|
+ try{
|
|
|
+ log.info("1=====================================》上报蓝牙网关编码:"+dataStr);
|
|
|
+ JSONObject jsonObject=JSONObject.parseObject(dataStr);
|
|
|
+ String mac = jsonObject.getString("mac");
|
|
|
+ if(mac!=null && !"".equals(mac)){
|
|
|
+ // 这里用线程去修改网关的具体在线状态
|
|
|
+ Boolean initFlag = Boolean.FALSE;
|
|
|
+ if(redisService.getCacheObject(BaseConstants.BEACON_MAC+"~"+ mac)==null){
|
|
|
+ setOpenBluetoothGateway(mac);
|
|
|
+ // 这里每次重启网关,或者第一次开启网关,需要把信标全部重新加载一次
|
|
|
+ initFlag = Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
- if(beaconList!=null){
|
|
|
- log.info("3=====================================》上报信标列表:"+jsonObject.getJSONArray("devices"));
|
|
|
- JSONArray array = jsonObject.getJSONArray("devices");
|
|
|
-
|
|
|
- // 这里需要查看信标通知列表,移除通知列表对应的信标气瓶数据
|
|
|
- List <Map<String,Object>> beaconNoticeList = redisService.getCacheObject(BaseConstants.BEACON_MATE_NOTICE+"~"+subId);
|
|
|
- List <Map<String,Object>> newNoticeList = new ArrayList <>();
|
|
|
- if(beaconNoticeList!=null){
|
|
|
- newNoticeList.addAll(beaconNoticeList);
|
|
|
+ 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);
|
|
|
+ log.info("2=====================================》获取实验室id:"+resultData.getData().get("subId"));
|
|
|
+ Long subId = Long.parseLong(resultData.getData().get("subId")+"");
|
|
|
+ List <Map<String,Object>> beaconList = redisService.getCacheObject(BaseConstants.BEACON_MATE_INFO+"~"+subId);
|
|
|
+ if(beaconList==null || initFlag){
|
|
|
+ log.info("2.1=====================================》初始化实验室信标列表和实验室下的所有信标生命周期");
|
|
|
+ // 根据实验室id获取蓝牙信标列表
|
|
|
+ remoteAirBottleService.setBeaconBySubId(subId);
|
|
|
}
|
|
|
- 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"));
|
|
|
- // redis存储蓝牙信标编码和实验室id和mac地址
|
|
|
- redisService.setCacheObject(BaseConstants.BEACON_MATE_DET+"~"+ beaconStr+"~"+subId+"~"+beaconList.get(x).get("gasName"),beaconStr, 120L, TimeUnit.SECONDS);
|
|
|
- // 循环信标通知,把还回来的气瓶提示移除。
|
|
|
- if(beaconNoticeList != null){
|
|
|
- for(Map notice:beaconNoticeList){
|
|
|
- if(notice.get("beaconTag").equals(beaconStr)){
|
|
|
- log.info("5.=====================================》移除返回来的信标提示语:"+notice);
|
|
|
- newNoticeList.remove(notice);
|
|
|
- beaconTagBuild.append(",");
|
|
|
- beaconTagBuild.append(beaconStr);
|
|
|
+
|
|
|
+ if(beaconList!=null){
|
|
|
+ log.info("3=====================================》上报信标列表:"+jsonObject.getJSONArray("devices"));
|
|
|
+ JSONArray array = jsonObject.getJSONArray("devices");
|
|
|
+
|
|
|
+ // 这里需要查看信标通知列表,移除通知列表对应的信标气瓶数据
|
|
|
+ List <Map<String,Object>> beaconNoticeList = redisService.getCacheObject(BaseConstants.BEACON_MATE_NOTICE+"~"+subId);
|
|
|
+ List <Map<String,Object>> newNoticeList = new ArrayList <>();
|
|
|
+ if(beaconNoticeList!=null){
|
|
|
+ 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"));
|
|
|
+ // redis存储蓝牙信标编码和实验室id和mac地址
|
|
|
+ redisService.setCacheObject(BaseConstants.BEACON_MATE_DET+"~"+ beaconStr+"~"+subId+"~"+beaconList.get(x).get("gasName"),beaconStr, 120L, TimeUnit.SECONDS);
|
|
|
+ // 循环信标通知,把还回来的气瓶提示移除。
|
|
|
+ if(beaconNoticeList != null){
|
|
|
+ for(Map notice:beaconNoticeList){
|
|
|
+ if(notice.get("beaconTag").equals(beaconStr)){
|
|
|
+ log.info("5.=====================================》移除返回来的信标提示语:"+notice);
|
|
|
+ newNoticeList.remove(notice);
|
|
|
+ beaconTagBuild.append(",");
|
|
|
+ beaconTagBuild.append(beaconStr);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -104,26 +106,29 @@ public class BeaconMateImpl implements BeaconMate {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- //下发通知,告诉前端页面,查询redis获取相关信息
|
|
|
- if(beaconNoticeList!=null && beaconNoticeList.size()!=newNoticeList.size()){
|
|
|
- //判断通知消息集合有数据,说明信标有变动,需要重新变更加通知
|
|
|
- redisService.setCacheObject(BaseConstants.BEACON_MATE_NOTICE+"~"+ subId,newNoticeList, 30L, TimeUnit.MINUTES);
|
|
|
- messageSendService.bluetoothGatewayToMac(subId);
|
|
|
- //向前端发送mqtt预案触发提示
|
|
|
- messageSendService.riskPlanTriggerNotice();
|
|
|
- //这里需要调用通知修改接口,把离位改成在位
|
|
|
- if(beaconTagBuild.length()>0){
|
|
|
- log.info("6.=====================================》带离气瓶归还后需要修改在位"+beaconTagBuild.substring(1));
|
|
|
- WarningNoticeLogDto warningNoticeLogDto = new WarningNoticeLogDto();
|
|
|
- warningNoticeLogDto.setBeaconTag(beaconTagBuild.substring(1));
|
|
|
- remoteLaboratoryService.updateLocationState(warningNoticeLogDto);
|
|
|
- }
|
|
|
+ //下发通知,告诉前端页面,查询redis获取相关信息
|
|
|
+ if(beaconNoticeList!=null && beaconNoticeList.size()!=newNoticeList.size()){
|
|
|
+ //判断通知消息集合有数据,说明信标有变动,需要重新变更加通知
|
|
|
+ redisService.setCacheObject(BaseConstants.BEACON_MATE_NOTICE+"~"+ subId,newNoticeList, 30L, TimeUnit.MINUTES);
|
|
|
+ messageSendService.bluetoothGatewayToMac(subId);
|
|
|
+ //向前端发送mqtt预案触发提示
|
|
|
+ messageSendService.riskPlanTriggerNotice();
|
|
|
+ //这里需要调用通知修改接口,把离位改成在位
|
|
|
+ if(beaconTagBuild.length()>0){
|
|
|
+ log.info("6.=====================================》带离气瓶归还后需要修改在位"+beaconTagBuild.substring(1));
|
|
|
+ WarningNoticeLogDto warningNoticeLogDto = new WarningNoticeLogDto();
|
|
|
+ warningNoticeLogDto.setBeaconTag(beaconTagBuild.substring(1));
|
|
|
+ remoteLaboratoryService.updateLocationState(warningNoticeLogDto);
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error(e.getMessage());
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//处理信标字符串
|