Sfoglia il codice sorgente

2023-10-19 蓝牙网关通知消息通知模板实现以及插入对应的数据。

chaiyunlong 2 anni fa
parent
commit
f0a57cc1b2

+ 7 - 0
zd-api/zd-airbottle-api/src/main/java/com/zd/airbottle/api/feign/RemoteAirBottleService.java

@@ -54,4 +54,11 @@ public interface RemoteAirBottleService {
      */
      */
     @GetMapping(value = "/stock/findBySubId")
     @GetMapping(value = "/stock/findBySubId")
     ResultData<List <Map<String,Object>>> findBySubId(@RequestParam("subId") Long subId);
     ResultData<List <Map<String,Object>>> findBySubId(@RequestParam("subId") Long subId);
+
+
+    /**
+     * 根据实验室id查询信标列表
+     */
+    @GetMapping(value = "/alarm/record/beacon/add")
+    ResultData<Integer> beaconAdd(@RequestBody Map <String,String> tagMap);
 }
 }

+ 5 - 0
zd-api/zd-airbottle-api/src/main/java/com/zd/airbottle/api/feign/fallback/RemoteAirBottleFallbackFactory.java

@@ -52,6 +52,11 @@ public class RemoteAirBottleFallbackFactory implements FallbackFactory<RemoteAir
             public ResultData <List <Map <String, Object>>> findBySubId(Long subId) {
             public ResultData <List <Map <String, Object>>> findBySubId(Long subId) {
                 return ResultData.fail("获取信标列表失败"+throwable.getMessage());
                 return ResultData.fail("获取信标列表失败"+throwable.getMessage());
             }
             }
+
+            @Override
+            public ResultData <Integer> beaconAdd(Map <String, String> tagMap) {
+                return ResultData.fail("蓝牙网关通知插入失败"+throwable.getMessage());
+            }
         };
         };
     }
     }
 }
 }

+ 26 - 1
zd-modules/zd-airbottle/src/main/java/com/zd/airbottle/ZdAirbottleApplication.java

@@ -1,15 +1,24 @@
 package com.zd.airbottle;
 package com.zd.airbottle;
 
 
 import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
 import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
+import com.zd.airbottle.domain.DbStock;
+import com.zd.airbottle.service.DbStockService;
 import com.zd.common.core.annotation.EnableCustomConfig;
 import com.zd.common.core.annotation.EnableCustomConfig;
 import com.zd.common.core.annotation.EnableZdFeignClients;
 import com.zd.common.core.annotation.EnableZdFeignClients;
 import com.zd.common.core.launch.ZdStartApplication;
 import com.zd.common.core.launch.ZdStartApplication;
+import com.zd.common.core.redis.RedisService;
 import com.zd.model.constant.ApplicationConstants;
 import com.zd.model.constant.ApplicationConstants;
 import com.zd.model.constant.BaseConstants;
 import com.zd.model.constant.BaseConstants;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
 
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
 /**
 /**
  * Controller
  * Controller
  *
  *
@@ -22,8 +31,24 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 @EnableScheduling
 @EnableScheduling
 @NacosPropertySource(dataId = "zd-airbottle", autoRefreshed = true)
 @NacosPropertySource(dataId = "zd-airbottle", autoRefreshed = true)
 @ComponentScan(basePackages = BaseConstants.BASE_PACKAGE)
 @ComponentScan(basePackages = BaseConstants.BASE_PACKAGE)
-public class ZdAirbottleApplication {
+public class ZdAirbottleApplication implements ApplicationRunner {
+
+    @Autowired
+    private DbStockService dbStockService;
+
+    @Autowired
+    private RedisService redisService;
+
     public static void main(String[] args) {
     public static void main(String[] args) {
         ZdStartApplication.run(ApplicationConstants.AIR_BOTTLE_SERVICE, ZdAirbottleApplication.class, args);
         ZdStartApplication.run(ApplicationConstants.AIR_BOTTLE_SERVICE, ZdAirbottleApplication.class, args);
     }
     }
+
+    @Override
+    public void run(ApplicationArguments args) throws Exception {
+        //TODO 启动气瓶服务的时候,需要把信标全部载入redis一次,(主要防止服务器断电重启后,被带离的气瓶无法知道)
+        List <DbStock> list = dbStockService.list();
+        for(DbStock db:list){
+            redisService.setCacheObject(BaseConstants.BEACON_MATE_DET+"~"+ db.getBeaconTag()+"~"+db.getSubjectId()+"~"+db.getGasName(),db.getBeaconTag(), 120L, TimeUnit.SECONDS);
+        }
+    }
 }
 }

+ 12 - 0
zd-modules/zd-airbottle/src/main/java/com/zd/airbottle/controller/AlarmRecordController.java

@@ -25,6 +25,7 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.IOException;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 /**
 /**
@@ -110,4 +111,15 @@ public class AlarmRecordController extends BaseController<AlarmRecord> {
         alarmRecordService.qpTimeOut();
         alarmRecordService.qpTimeOut();
         return ResultData.success();
         return ResultData.success();
     }
     }
+
+
+    /**
+     * 蓝牙信标非法带离报警记录
+     */
+    @ApiOperation(value = "蓝牙信标非法带离报警记录")
+    @Log(title = "蓝牙信标非法带离报警记录", businessType = BusinessType.INSERT)
+    @PostMapping("/beacon/add")
+    public R<Integer> beaconAdd(@RequestBody Map <String,String> tagMap) {
+        return R.ok(alarmRecordService.beaconAdd(tagMap));
+    }
 }
 }

+ 8 - 0
zd-modules/zd-airbottle/src/main/java/com/zd/airbottle/service/IAlarmRecordService.java

@@ -6,6 +6,7 @@ import com.zd.airbottle.domain.vo.BottleStorageInfoVo;
 import com.zd.model.entity.InventoryTag;
 import com.zd.model.entity.InventoryTag;
 
 
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 /**
 /**
  * 报警记录Service接口
  * 报警记录Service接口
@@ -52,6 +53,13 @@ public interface IAlarmRecordService {
     boolean remoteAdd(InventoryTag tag);
     boolean remoteAdd(InventoryTag tag);
 
 
     /**
     /**
+     * 蓝牙信标非法带离报警记录
+     *
+     * @param tagMap 标签值
+     */
+    Integer beaconAdd(Map <String,String> tagMap);
+
+    /**
      * 报警记录查询
      * 报警记录查询
      * @param alarmRecord
      * @param alarmRecord
      * @return
      * @return

+ 130 - 0
zd-modules/zd-airbottle/src/main/java/com/zd/airbottle/service/impl/AlarmRecordServiceImpl.java

@@ -6,7 +6,9 @@ import cn.hutool.core.date.LocalDateTimeUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zd.airbottle.domain.AlarmRecord;
 import com.zd.airbottle.domain.AlarmRecord;
+import com.zd.airbottle.domain.DbStock;
 import com.zd.airbottle.domain.QpAirBottle;
 import com.zd.airbottle.domain.QpAirBottle;
 import com.zd.airbottle.domain.QpUseRecord;
 import com.zd.airbottle.domain.QpUseRecord;
 import com.zd.airbottle.domain.vo.*;
 import com.zd.airbottle.domain.vo.*;
@@ -109,6 +111,9 @@ public class AlarmRecordServiceImpl implements IAlarmRecordService {
     @Resource
     @Resource
     private RedisTemplate<String, HardwareRfid> redisTemplate;
     private RedisTemplate<String, HardwareRfid> redisTemplate;
 
 
+    @Autowired
+    private DbStockService dbStockService;
+
     private static final String RFID_CODE = "RFID:";
     private static final String RFID_CODE = "RFID:";
 
 
     /**
     /**
@@ -438,6 +443,131 @@ public class AlarmRecordServiceImpl implements IAlarmRecordService {
     }
     }
 
 
     @Override
     @Override
+    public Integer beaconAdd(Map <String, String> tagMap) {
+        //根据信标查询库存信息
+        String beaconTag = tagMap.get("beaconTag");
+        LambdaQueryWrapper<DbStock> queryWrapper = new LambdaQueryWrapper();
+        queryWrapper.eq(DbStock::getBeaconTag, beaconTag);
+        DbStock dbStock = dbStockService.getOne(queryWrapper);
+        // 查询配置
+        ResultData<WarningConfigDto> byType = laboratoryService.getByType(3);
+        if (HttpStatus.SUCCESS != byType.getCode()) {
+            return 0;
+        }
+        //违规带离(1系统通知 2短信通知 3声光报警)
+        WarningConfigDto warningConfigDto = byType.getData();
+        String illegalRemoval = warningConfigDto.getIllegalRemoval();
+
+        WarningNoticeLogDto warningNoticeLogDto = new WarningNoticeLogDto();
+        warningNoticeLogDto.setKeyId(dbStock.getId());
+        warningNoticeLogDto.setName(dbStock.getGasName());
+        warningNoticeLogDto.setWarningType(3);
+        warningNoticeLogDto.setWarningSubType(1);
+        warningNoticeLogDto.setWarningContent("气瓶违规带离");
+        warningNoticeLogDto.setWarningTime(LocalDateTime.now());
+        warningNoticeLogDto.setWarningWay(illegalRemoval);
+//        warningNoticeLogDto.setHolder(storageRVo.getOwner());
+//        warningNoticeLogDto.setDeposit(storageRVo.getLocation());
+        warningNoticeLogDto.setMargin(new BigDecimal(dbStock.getGasPressure()));
+        warningNoticeLogDto.setSpecification(dbStock.getSize()+"");
+        warningNoticeLogDto.setEntryTime(LocalDateTimeUtil.of(dbStock.getCreateTime()));
+
+        //查询到实验室负责人id 安全责任人id
+        ResultData<List<CheckSubjectDto>> subjectInfoList = laboratoryService.findSubjectInfoList(String.valueOf(dbStock.getSubjectId()));
+        StringBuffer userIds = new StringBuffer();
+        StringBuffer phones = new StringBuffer();
+        if (HttpStatus.SUCCESS == subjectInfoList.getCode()) {
+            List<CheckSubjectDto> data = subjectInfoList.getData();
+            CheckSubjectDto i = data.get(0);
+            warningNoticeLogDto.setSubId(i.getSubId());
+            warningNoticeLogDto.setSubName(i.getSubjectName());
+            warningNoticeLogDto.setBuildName(i.getBuildName());
+            warningNoticeLogDto.setFloorId(i.getFloorId());
+            warningNoticeLogDto.setFloorName(i.getFloorName());
+            warningNoticeLogDto.setRoomNum(i.getRoomNumber());
+            userIds.append(i.getSafeUserId()).append(",").append(i.getAdminId());
+            phones.append(i.getAdminPhone()).append(",").append(i.getSafeUserPhone());
+        }
+        ResultData resultData = laboratoryService.addWarningNoticeLog(warningNoticeLogDto);
+        if (HttpStatus.SUCCESS != resultData.getCode()) {
+            return 0;
+        }
+        Long logId = (Long) resultData.getData();
+
+        //rfid门禁机报警
+//        R<Boolean> alarm = remoteRfidService.alarm(hardwareRfidDto);
+//        log.info("==================>{},{}",alarm.getCode(),alarm.getMsg());
+
+        //摄像头录像
+//        ResultData<LabHardwareDto> cameraHardware = remoteLabHardwareService.findHardwareByType(storageRVo.getSubjectId(), 4, null, "2");
+//        if (HttpStatus.SUCCESS == cameraHardware.getCode()) {
+//            String ip = String.valueOf(cameraHardware.getData().getIpAddress());
+//            startVideo(ip);
+//            scheduledExecutorService.schedule(new TimerTask() {
+//                @Override
+//                public void run() {
+//                    stopVideo(ip, logId);
+//                }
+//            }, 30, TimeUnit.SECONDS);
+//        }
+        //按照配置预警
+        if (illegalRemoval != null) {
+            String text = "【实验室安全系统】"+warningNoticeLogDto.getSubName()+"-实验人员违规携带"+warningNoticeLogDto.getName()+"气瓶离开房间,发生时间:" + LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss") + ",请尽快确认。";
+
+            //系统通知
+            if (illegalRemoval.contains("1")) {
+                LabMessageContent labMessageContent = new LabMessageContent();
+                labMessageContent.setSendMode(2);
+                labMessageContent.setSendRange(3);
+                labMessageContent.setMessClass(1);
+                labMessageContent.setMessType(13);
+                labMessageContent.setSubIds(String.valueOf(dbStock.getSubjectId()));
+                labMessageContent.setUserIds(userIds.toString());
+                labMessageContent.setContent(text);
+                remoteMessageContentService.sendMessage(labMessageContent);
+            }
+
+            //短信通知
+            if (illegalRemoval.contains("2")) {
+                String[] strings = Stream.of(phones.toString().split(",")).filter(a -> StrUtil.isNotBlank(a)).collect(Collectors.joining(",")).split(",");
+                if (strings != null) {
+                    //获取人员电话信息
+                    ResultData<List<UserPhoneInfo>> listResultData = laboratoryService.selectAdminAndSafeAdminById(warningNoticeLogDto.getSubId());
+                    if(HttpStatus.SUCCESS != listResultData.getCode()){
+                        log.info("获取实验室管理员和安全员信息失败!{}",JSON.toJSONString(listResultData));
+                    }
+                    List<UserPhoneInfo> userPhoneInfoList = listResultData.getData();
+                    AlarmEntrty alarmEntrty = new AlarmEntrty(Routes.NoticePush, strings, SendTypes.SMS.toString(), text);
+                    alarmEntrty.setLogId(logId);
+                    alarmEntrty.setUserPhoneInfo(userPhoneInfoList);
+                    remoteAlarmService.send(alarmEntrty);
+                    log.info("气瓶发送短信打电话消息推送完成!");
+                }
+            }
+
+            //声光报警
+            if (illegalRemoval.contains("3")) {
+                ResultData<LabHardwareDto> hardwareByType = remoteLabHardwareService.findHardwareByType(dbStock.getSubjectId(), 8, null, null);
+                if (HttpStatus.SUCCESS == hardwareByType.getCode()) {
+                    warningNoticeLogDto.setId(logId);
+                    warningNoticeLogDto.setVoiceBroadcast(1);
+                    laboratoryService.updateWarningNoticeLog(warningNoticeLogDto);
+                    Long id = hardwareByType.getData().getId();
+                    laboratoryService.controlDevice(id, 1);
+                    scheduledExecutorService.schedule(new TimerTask() {
+                        @Override
+                        public void run() {
+                            laboratoryService.controlDevice(id, 0);
+                        }
+                    }, 30, TimeUnit.SECONDS);
+                }
+            }
+        }
+
+        return 0;
+    }
+
+    @Override
     public List<BottleStorageInfoVo> setMasterIds(AlarmRecord alarmRecord) {
     public List<BottleStorageInfoVo> setMasterIds(AlarmRecord alarmRecord) {
         if (!StringUtils.isEmpty(alarmRecord.getSearchValue())) {
         if (!StringUtils.isEmpty(alarmRecord.getSearchValue())) {
             BottleStorageInfoVo storageInfoVo = new BottleStorageInfoVo();
             BottleStorageInfoVo storageInfoVo = new BottleStorageInfoVo();

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

@@ -170,6 +170,9 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
                     //下发通知,告诉前端页面,查询redis获取相关信息
                     //下发通知,告诉前端页面,查询redis获取相关信息
                     messageSendService.bluetoothGatewayToMac(Long.parseLong(beaconStr[2]));
                     messageSendService.bluetoothGatewayToMac(Long.parseLong(beaconStr[2]));
                 }
                 }
+                Map <String,String> tagMap = new HashMap<>();
+                tagMap.put("beaconTag",beaconStr[1]);
+                remoteAirBottleService.beaconAdd(tagMap);
             }
             }
 
 
         }
         }

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

@@ -46,12 +46,12 @@ public class BeaconMateImpl implements BeaconMate {
                 //todo 这里每次重启网关,或者第一次开启网关,需要把信标全部重新加载一次
                 //todo 这里每次重启网关,或者第一次开启网关,需要把信标全部重新加载一次
                 initFlag = Boolean.TRUE;
                 initFlag = Boolean.TRUE;
             }
             }
-            //todo redis存储蓝牙网关mac地址,用于在线离线问题。
-            redisService.setCacheObject(BaseConstants.BEACON_MAC+"~"+ mac,mac, 60L, TimeUnit.SECONDS);
-
 
 
             ResultData<Map<String,Object>> resultData = remoteAirBottleService.getSubByMac(mac);
             ResultData<Map<String,Object>> resultData = remoteAirBottleService.getSubByMac(mac);
             if(resultData.getCode()==200){
             if(resultData.getCode()==200){
+                //todo redis存储蓝牙网关mac地址,用于在线离线问题。
+                redisService.setCacheObject(BaseConstants.BEACON_MAC+"~"+ mac,mac, 60L, TimeUnit.SECONDS);
+
                 log.info("2.=====================================》获取实验室id:"+resultData.getData().get("subId"));
                 log.info("2.=====================================》获取实验室id:"+resultData.getData().get("subId"));
                 Long subId = Long.parseLong(resultData.getData().get("subId")+"");
                 Long subId = Long.parseLong(resultData.getData().get("subId")+"");
                 List <Map<String,Object>> beaconList = redisService.getCacheObject(BaseConstants.BEACON_MATE_INFO+"~"+subId);
                 List <Map<String,Object>> beaconList = redisService.getCacheObject(BaseConstants.BEACON_MATE_INFO+"~"+subId);