Parcourir la source

2023-10-20 修改消息通知带楼栋楼层id,以及优化查询通知的redis。

chaiyunlong il y a 2 ans
Parent
commit
80f24cf583

+ 27 - 8
zd-modules/zd-airbottle/src/main/java/com/zd/airbottle/controller/DbBluetoothGatewayController.java

@@ -17,9 +17,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * Controller
@@ -140,11 +138,32 @@ public class DbBluetoothGatewayController extends BaseController {
      */
     @ApiOperation(value = "获取蓝牙信标提示语集合")
     @GetMapping(value = "/getBeaconNotice")
-    public ResultData getBeaconNotice(Long subId) {
-        List <Map <String,Object>> beaconNoticeList = redisService.getCacheObject(BaseConstants.BEACON_MATE_NOTICE+"~"+subId);
-        if(beaconNoticeList==null){
-            beaconNoticeList = new ArrayList <>();
+    public ResultData getBeaconNotice() {
+        Collection <String> cllKey = redisService.keys(BaseConstants.BEACON_MATE_NOTICE + "*");
+        List<Map <String,Object>> allList = new ArrayList <>();
+        for(String key:cllKey){
+            List <Map <String,Object>> beaconNoticeList = redisService.getCacheObject(key);
+            StringBuilder gasName = new StringBuilder();
+            StringBuilder beaconTag = new StringBuilder();
+            Map<String,Object> beaconStr = new HashMap <>();
+            for(int i=0;i<beaconNoticeList.size();i++){
+                if(i==0){
+                    beaconStr.put("subId",beaconNoticeList.get(i).get("subId"));
+                    beaconStr.put("riskPlanTriggerTime",beaconNoticeList.get(i).get("riskPlanTriggerTime"));
+                    beaconStr.put("buildId",beaconNoticeList.get(i).get("buildId"));
+                    beaconStr.put("floorId",beaconNoticeList.get(i).get("floorId"));
+                }
+                gasName.append("、"+beaconNoticeList.get(i).get("gasName"));
+                beaconTag.append("、"+beaconNoticeList.get(i).get("beaconTag"));
+            }
+            if(gasName.length()>0){
+                beaconStr.put("gasName",gasName.substring(1));
+            }
+            if(beaconTag.length()>0){
+                beaconStr.put("beaconTag",beaconTag.substring(1));
+            }
+            allList.add(beaconStr);
         }
-        return ResultData.success(beaconNoticeList);
+        return ResultData.success(allList);
     }
 }

+ 13 - 0
zd-modules/zd-airbottle/src/main/java/com/zd/airbottle/controller/DbStockController.java

@@ -301,6 +301,19 @@ public class DbStockController extends AbstractController {
         redisService.deleteObject(BaseConstants.BEACON_MATE_DET+"~"+ dbStock.getBeaconTag()+"~"+dbStock.getSubjectId()+"~"+dbStock.getGasName());
     }
 
+    /**
+     * 根据实验室ids查询库存列表
+     */
+    @ApiOperation(value = "根据实验室ids查询库存列表")
+    @GetMapping("/{ids}")
+    public ResultData getStockBySubIds(@PathVariable Long[] ids)
+    {
+        //查询库存信标列表,存入redis
+        LambdaQueryWrapper<DbStock> queryWrapper = new LambdaQueryWrapper();
+        queryWrapper.in(DbStock::getSubjectId, ids);
+        List<DbStock> list = dbStockService.list(queryWrapper);
+        return ResultData.success(list);
+    }
 
     /***
      *

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

@@ -6,12 +6,15 @@ import com.alibaba.fastjson.parser.Feature;
 import com.zd.airbottle.api.feign.RemoteAirBottleService;
 import com.zd.common.core.redis.RedisService;
 import com.zd.laboratory.config.TimeWaitConfigUtils;
+import com.zd.laboratory.domain.LabBuildFloorLayout;
 import com.zd.laboratory.domain.LabControl;
 import com.zd.laboratory.domain.LabHardware;
+import com.zd.laboratory.domain.vo.LabBuildFloorLayoutVo;
 import com.zd.laboratory.domain.vo.LabDealyNotifyVo;
 import com.zd.laboratory.domain.vo.LabHardwareVO;
 import com.zd.laboratory.mapper.LabHardwareMapper;
 import com.zd.laboratory.mqtt.service.impl.SubMessageSendManager;
+import com.zd.laboratory.service.ILabBuildFloorLayoutService;
 import com.zd.laboratory.service.ILabControlService;
 import com.zd.laboratory.socket.command.Symbol;
 import com.zd.laboratory.socket.service.SocketService;
@@ -27,6 +30,7 @@ import org.springframework.data.redis.listener.KeyExpirationEventMessageListener
 import org.springframework.data.redis.listener.RedisMessageListenerContainer;
 import org.springframework.stereotype.Component;
 
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 
@@ -71,6 +75,9 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
     @Autowired
     private SubMessageSendManager messageSendService;
 
+    @Autowired
+    private ILabBuildFloorLayoutService labBuildFloorLayoutService;
+
     private static final Logger log = LoggerFactory.getLogger(RedisExpiredAndWorkListener.class);
 
     public RedisExpiredAndWorkListener(RedisMessageListenerContainer listenerContainer)
@@ -133,6 +140,18 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
             map.put("beaconTag",beaconStr[1]);
             map.put("subId",beaconStr[2]);
             map.put("gasName",beaconStr[3]);
+            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("31.=====================================》信标丢失:"+beaconStr[1]+",实验室id:"+beaconStr[2]);
             // todo 这里需要根据实验室id查询对应的网关,通过网关查询redis,排查是不是有网关掉线了,如果有,就不通知报警,如果没有,发出报警
             Boolean flag = Boolean.TRUE;

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

@@ -28,7 +28,7 @@ public class BeaconMateImpl implements BeaconMate {
 
     private static Logger log = LoggerFactory.getLogger(BeaconMateImpl.class);
 
-    private static RedisService redisService = SpringUtils.getBean(RedisService.class);
+    private RedisService redisService = SpringUtils.getBean(RedisService.class);
 
     private RemoteAirBottleService remoteAirBottleService = SpringUtils.getBean(RemoteAirBottleService.class);