Procházet zdrojové kódy

预案报警,自动关闭时长,广播打开提交

hanzhiwei před 2 roky
rodič
revize
98b64ccc0c

+ 2 - 1
zd-model/src/main/java/com/zd/model/enums/HardwareTypeEnum.java

@@ -22,7 +22,8 @@ public enum HardwareTypeEnum implements BaseEnum<Integer>, HardwareType {
     AI_ALARM(8, "智能报警器", ""),
     AI_CABINETLOCK(9, "智能柜锁", ""),
     AI_OUTFIRE(10, "一键灭火", ""),
-    HK_DOOR(11, "海康门禁", "");
+    HK_DOOR(11, "海康门禁", ""),
+    LOUDSPEAKER(12,"喇叭","");
 
 
     private final Integer code;

+ 18 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/LabRiskPlanLevel.java

@@ -82,6 +82,20 @@ public class LabRiskPlanLevel implements Serializable {
     private String deptName;
 
     /**
+     * 报警类型(1电话 2短信 3电话和短信)
+     */
+    @TableField(value = "alarm_type")
+    @ApiModelProperty(value="报警类型(1电话 2短信)")
+    private String alarmType;
+
+    /**
+     * 预案自动关闭时长(秒)
+     */
+    @TableField(value = "risk_auto_off")
+    @ApiModelProperty(value="预案自动关闭时长(秒)")
+    private Integer riskAutoOff;
+
+    /**
      * 创建人(用于数据权限)
      */
     @TableField(value = "user_id")
@@ -194,6 +208,10 @@ public class LabRiskPlanLevel implements Serializable {
 
     public static final String COL_DEPT_ID = "dept_id";
 
+    public static final String COL_ALARM_TYPE = "alarm_type";
+
+    public static final String COL_RISK_AUTO_OFF = "risk_auto_off";
+
     public static final String COL_CREATE_TIME = "create_time";
 
     public static final String COL_DEPT_NAME = "dept_name";

+ 13 - 14
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabControlServiceImpl.java

@@ -1,33 +1,32 @@
 package com.zd.laboratory.service.impl;
 
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.atomic.LongAdder;
-
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.zd.model.domain.per.PerPrefix;
+import com.zd.common.core.annotation.DataScope;
 import com.zd.common.core.utils.DateUtils;
+import com.zd.common.core.utils.SaveUtil;
 import com.zd.common.core.utils.SecurityUtils;
 import com.zd.common.core.utils.StringUtils;
-import com.zd.common.core.annotation.DataScope;
-import com.zd.common.core.utils.SaveUtil;
+import com.zd.laboratory.domain.LabControl;
 import com.zd.laboratory.domain.LabHardware;
 import com.zd.laboratory.domain.LabSubject;
 import com.zd.laboratory.domain.vo.LabBigViewGroupVO;
 import com.zd.laboratory.domain.vo.LabControlVO;
-import com.zd.laboratory.domain.vo.LabHardwareVO;
 import com.zd.laboratory.domain.vo.LabRiskPlanListVO;
+import com.zd.laboratory.mapper.LabControlMapper;
+import com.zd.laboratory.service.ILabControlService;
 import com.zd.laboratory.service.ILabSubjectService;
 import com.zd.laboratory.socket.command.Symbol;
+import com.zd.model.domain.per.PerPrefix;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.zd.laboratory.mapper.LabControlMapper;
-import com.zd.laboratory.domain.LabControl;
-import com.zd.laboratory.service.ILabControlService;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.atomic.LongAdder;
 
 /**
  * 控制记录Service业务层处理
@@ -76,7 +75,7 @@ public class LabControlServiceImpl implements ILabControlService {
     public void  manualCreateLabControlAndSave(LabHardware hardwareVO,Symbol.order order , Symbol.command command)
     {
         LabControl lab = createLab(hardwareVO, order, command);
-        lab.setTriggerModes(2);
+        lab.setTriggerModes(1);
         String userName=SecurityUtils.getUsername();
         if(StringUtils.isNotEmpty(userName)){
             SaveUtil.setCommonAttr(lab);

+ 14 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabMessageContentServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.zd.algorithm.api.alarm.entity.AlarmEntrty;
 import com.zd.algorithm.api.alarm.entity.Routes;
+import com.zd.algorithm.api.alarm.entity.SendTypes;
 import com.zd.algorithm.api.alarm.feign.RemoteAlarmService;
 import com.zd.chemical.api.fegin.RemoteStockService;
 import com.zd.common.core.annotation.DataScope;
@@ -43,6 +44,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
@@ -96,6 +98,9 @@ public class LabMessageContentServiceImpl implements ILabMessageContentService {
     @Autowired
     RemoteStockService remoteStockService;
 
+    private final String callType = "1";
+
+    private final String smsType = "2";
 
     private final String smsFormat = "{}: {},发生风险预案,{}";
     private final String smsFormatString = "【实验室安全智能】{}发生{}{}";
@@ -234,7 +239,15 @@ public class LabMessageContentServiceImpl implements ILabMessageContentService {
         //todo 这里判断电话类型,如果是0,发送短信,如果是1,是四医大内部短信接口。
         if (phoneMode == 0) {
             if (strings != null) {
-                AlarmEntrty alarmEntrty = new AlarmEntrty(Routes.NoticePush, strings, format);
+                AlarmEntrty alarmEntrty = new AlarmEntrty();
+                List<String> alarms = Arrays.asList(labRiskPlanLevel.getAlarmType().split(","));
+                if (alarms.contains(smsType) && alarms.contains(smsType)) {
+                    alarmEntrty = new AlarmEntrty(Routes.NoticePush, strings, format);
+                }else if(alarms.contains(callType)){
+                    alarmEntrty = new AlarmEntrty(Routes.NoticePush, strings, SendTypes.Call.toString(),format);
+                }else if(alarms.contains(smsType)) {
+                    alarmEntrty = new AlarmEntrty(Routes.NoticePush, strings, SendTypes.SMS.toString(),format);
+                }
                 MessageBody messageBody = new MessageBody();
                 messageBody.setData(alarmEntrty);
                 commonSend.send(MqttConstants.TOPIC_ALERT + labRiskPlanLevel.getRiskPlanId() + "/" + subject.getId(), messageBody, SendMode.DISTINCT);

+ 45 - 39
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabRiskPlanServiceImpl.java

@@ -642,7 +642,7 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
         if (labRiskPlanLevel.getRiskPlanId() != null) {
             log.info("触发预案具体信息={}", JSON.toJSONString(labRiskPlanLevel));
             //预案缓存信息处理
-            riskPlanRedisCache(subFunction);
+            riskPlanRedisCache(subFunction,labRiskPlanLevel);
             //获取系统配置通知模板
             getConfigNoticeTemplate(labRiskPlanLevel);
             //获取园区和楼层信息(新楼栋)
@@ -658,7 +658,7 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
                 //记录通知
                 recordNotice(subFunction, labRiskPlanLevel, groupId);
                 //打开喇叭
-                openLoudSpeaker(subFunction.getSubId(), labRiskPlanLevel.getFloorId(), labRiskPlanLevel.getRiskPlanId());
+                openLoudSpeaker(subFunction.getSubId(), labRiskPlanLevel);
                 //远程调用开始录制视频接口
                 startVideo(subFunction.getSubId());
                 //向前端发送mqtt预案触发提示
@@ -851,9 +851,9 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
      * @Param [subFunction]
      * @Return void
      **/
-    private void riskPlanRedisCache(SubFunction<SensorFunctionStatus> subFunction) {
-        //有效预案延长2分钟
-        redisService.setCacheObject("subjectByYa" + subFunction.getSubId(), subFunction.getSubId(), 2L, TimeUnit.MINUTES);
+    private void riskPlanRedisCache(SubFunction<SensorFunctionStatus> subFunction,LabRiskPlanLevel labRiskPlanLevel) {
+        //有效预案设置自动关闭时间
+        redisService.setCacheObject("subjectByYa" + subFunction.getSubId(), subFunction.getSubId(), Long.valueOf(labRiskPlanLevel.getRiskAutoOff()), TimeUnit.SECONDS);
         //这里处理,如果是火焰预案,需要redis额外缓存
         Optional.ofNullable(subFunction.getFunctionStatuses()).orElseGet(Collections::emptyList).stream().filter(a -> "huoyan".equals(a.getFunNum())).forEach(a -> {
             if (StringUtils.isNotBlank(a.getVal()) && a.getVal().equals("1") && redisService.getCacheObject("subjectByHuoyan" + subFunction.getSubId()) == null) {
@@ -992,46 +992,52 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
      * @Param [subjectId 实验室id, floorId 楼层id, riskPlanId 预案id]
      * @Return void
      **/
-    private void openLoudSpeaker(Long subjectId, Long floorId, Long riskPlanId) {
+    private void openLoudSpeaker(Long subjectId,LabRiskPlanLevel labRiskPlanLevel) {
         //查询合成音乐,喇叭列表,调用喇叭
         try {
-            //这里查询预案下的合成音乐
-            LabAudioSynthesis labAudioSynthesis = new LabAudioSynthesis();
-            labAudioSynthesis.setRiskPlanId(riskPlanId);
-            List<LabAudioSynthesis> audioSyntheses = labAudioSynthesisMapper.selectLabAudioSynthesisList(labAudioSynthesis);
-            log.info("打开喇叭-查询的音乐列表信息 audioSyntheses= {}", JSON.toJSONString(audioSyntheses));
-            if (audioSyntheses != null && audioSyntheses.size() > 0) {
-                //预案调用喇叭
-                log.info("打开喇叭-远程调用查询喇叭列表,楼层id={},实验室id={}", floorId, subjectId);
-                Integer count = labSparseHardwareService.selectSpeakerCount();
-                R deviceList = remoteSpeakService.getDeviceList(1, count + 10, -99L, subjectId);
-                log.info("打开喇叭-远程调用喇叭列表返回内容: deviceList={}", JSON.toJSONString(deviceList));
-                if (deviceList.getCode() == 200) {
-                    List<PlayVo> playVoList = new ArrayList<>();
-                    List<Map<String, Object>> mapList = (List<Map<String, Object>>) deviceList.getData();
-                    for (Map<String, Object> map : mapList) {
-                        if (StringUtils.isNotNull(map.get("deviceSn")) && StringUtils.isNotNull(map.get("port"))) {
-                            PlayVo playVo = new PlayVo();
-                            playVo.setSn(map.get("deviceSn") + "");
-                            playVo.setDeviceIp(map.get("deviceIp") + "");
-                            playVo.setPort(Integer.parseInt(map.get("port") + ""));
-                            ParamVo paramVo = new ParamVo();
-                            paramVo.setVol(Integer.parseInt(map.get("deviceVol").toString()));
-                            playVo.setParams(paramVo);
-                            playVoList.add(playVo);
+            //查询喇叭是否配置在预案中
+            List<LabRiskPlanHardwareRelation> riskPlanHardwareList = labRiskPlanLevel.getRiskPlanHardwareList();
+            riskPlanHardwareList.forEach(labRiskPlanHardwareRelation -> {
+                if (labRiskPlanHardwareRelation.getHardwareType().equals(HardwareTypeEnum.LOUDSPEAKER.getCode())) {
+                    //这里查询预案下的合成音乐
+                    LabAudioSynthesis labAudioSynthesis = new LabAudioSynthesis();
+                    labAudioSynthesis.setRiskPlanId(labRiskPlanLevel.getRiskPlanId());
+                    List<LabAudioSynthesis> audioSyntheses = labAudioSynthesisMapper.selectLabAudioSynthesisList(labAudioSynthesis);
+                    log.info("打开喇叭-查询的音乐列表信息 audioSyntheses= {}", JSON.toJSONString(audioSyntheses));
+                    if (audioSyntheses != null && audioSyntheses.size() > 0) {
+                        //预案调用喇叭
+                        log.info("打开喇叭-远程调用查询喇叭列表,实验室id={}", subjectId);
+                        Integer count = labSparseHardwareService.selectSpeakerCount();
+                        R deviceList = remoteSpeakService.getDeviceList(1, count + 10, -99L, subjectId);
+                        log.info("打开喇叭-远程调用喇叭列表返回内容: deviceList={}", JSON.toJSONString(deviceList));
+                        if (deviceList.getCode() == 200) {
+                            List<PlayVo> playVoList = new ArrayList<>();
+                            List<Map<String, Object>> mapList = (List<Map<String, Object>>) deviceList.getData();
+                            for (Map<String, Object> map : mapList) {
+                                if (StringUtils.isNotNull(map.get("deviceSn")) && StringUtils.isNotNull(map.get("port"))) {
+                                    PlayVo playVo = new PlayVo();
+                                    playVo.setSn(map.get("deviceSn") + "");
+                                    playVo.setDeviceIp(map.get("deviceIp") + "");
+                                    playVo.setPort(Integer.parseInt(map.get("port") + ""));
+                                    ParamVo paramVo = new ParamVo();
+                                    paramVo.setVol(Integer.parseInt(map.get("deviceVol").toString()));
+                                    playVo.setParams(paramVo);
+                                    playVoList.add(playVo);
+                                } else {
+                                    log.info("打开喇叭-喇叭deviceSn/port为空!");
+                                }
+                            }
+                            log.info("打开喇叭-远程调用喇叭播放音乐!url={},playVoList={}", audioSyntheses.get(0).getNewMusicUrl(), JSON.toJSONString(playVoList));
+                            R r = remoteSpeakService.textMoreParseUrlAppIps(audioSyntheses.get(0).getNewMusicUrl(), playVoList, 100);
+                            log.info("打开喇叭-远程调用喇叭播放音乐返回信息:{}", JSON.toJSONString(r));
                         } else {
-                            log.info("打开喇叭-喇叭deviceSn/port为空!");
+                            log.info("打开喇叭-远程查询喇叭信息错误!");
                         }
+                    } else {
+                        log.info("打开喇叭-合成音乐列表为空,此预案不触发音乐!riskPlanId={}", labRiskPlanLevel.getRiskPlanId());
                     }
-                    log.info("打开喇叭-远程调用喇叭播放音乐!url={},playVoList={}", audioSyntheses.get(0).getNewMusicUrl(), JSON.toJSONString(playVoList));
-                    R r = remoteSpeakService.textMoreParseUrlAppIps(audioSyntheses.get(0).getNewMusicUrl(), playVoList,100);
-                    log.info("打开喇叭-远程调用喇叭播放音乐返回信息:{}", JSON.toJSONString(r));
-                } else {
-                    log.info("打开喇叭-远程查询喇叭信息错误!");
                 }
-            } else {
-                log.info("打开喇叭-合成音乐列表为空,此预案不触发音乐!riskPlanId={}", riskPlanId);
-            }
+            });
         } catch (Exception e) {
             log.error("开启喇叭异常!{}", e);
         }

+ 5 - 3
zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabRiskPlanLevelMapper.xml

@@ -9,6 +9,8 @@
     <result column="risk_plan_level" jdbcType="TINYINT" property="riskPlanLevel"/>
     <result column="if_exit" jdbcType="TINYINT" property="ifExit"/>
     <result column="dept_id" jdbcType="BIGINT" property="deptId"/>
+    <result column="alarm_type" jdbcType="VARCHAR" property="alarmType"/>
+    <result column="risk_auto_off" jdbcType="INTEGER" property="riskAutoOff"/>
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
     <result column="dept_name" jdbcType="VARCHAR" property="deptName"/>
     <result column="user_id" jdbcType="BIGINT" property="userId"/>
@@ -19,18 +21,18 @@
   </resultMap>
   <sql id="Base_Column_List">
     <!--@mbg.generated-->
-    id, risk_plan_id, risk_plan_level, if_exit, dept_id, create_time, dept_name, user_id,
+    id, risk_plan_id, risk_plan_level, if_exit, dept_id, alarm_type, risk_auto_off, create_time, dept_name, user_id,
     create_by, update_time, update_by, remark
   </sql>
   <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
     <!--@mbg.generated-->
     insert into lab_risk_plan_level
-    (risk_plan_id, risk_plan_level, if_exit, dept_id, create_time, dept_name, user_id,
+    (risk_plan_id, risk_plan_level, if_exit, dept_id,  alarm_type, risk_auto_off, create_time, dept_name, user_id,
       create_by, update_time, update_by, remark)
     values
     <foreach collection="list" item="item" separator=",">
       (#{item.riskPlanId,jdbcType=BIGINT}, #{item.riskPlanLevel,jdbcType=TINYINT}, #{item.ifExit,jdbcType=TINYINT},
-        #{item.deptId,jdbcType=BIGINT}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.deptName,jdbcType=VARCHAR}, 
+        #{item.deptId,jdbcType=BIGINT}, #{item.alarmType,jdbcType=VARCHAR},#{item.riskAutoOff,jdbcType=INTEGER},#{item.createTime,jdbcType=TIMESTAMP}, #{item.deptName,jdbcType=VARCHAR},
         #{item.userId,jdbcType=BIGINT}, #{item.createBy,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP}, 
         #{item.updateBy,jdbcType=VARCHAR}, #{item.remark,jdbcType=VARCHAR})
     </foreach>