Parcourir la source

新预案提交2

hanzhiwei il y a 3 ans
Parent
commit
6125af6db9
22 fichiers modifiés avec 406 ajouts et 141 suppressions
  1. 20 0
      zd-api/zd-laboratory-api/src/main/java/com/zd/laboratory/api/entity/OneClickFireDTO.java
  2. 6 0
      zd-api/zd-laboratory-api/src/main/java/com/zd/laboratory/api/feign/RemoteLaboratoryService.java
  3. 6 0
      zd-api/zd-laboratory-api/src/main/java/com/zd/laboratory/api/feign/fallback/RemoteLaboratoryFallbackFactory.java
  4. 3 0
      zd-model/src/main/java/com/zd/model/constant/MqttConstants.java
  5. 56 7
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/LabRiskPlanController.java
  6. 5 5
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/LabRiskPlanLevelController.java
  7. 14 0
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/LabRiskPlan.java
  8. 33 0
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/dto/LabBuildFloorLayoutDTO.java
  9. 20 0
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/dto/OneClickFireDTO.java
  10. 4 1
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/vo/LabRiskPlanSubVoInfo.java
  11. 3 1
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/mapper/LabBuildFloorLayoutMapper.java
  12. 1 1
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/mapper/LabRiskPlanjoinsubMapper.java
  13. 1 1
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/mapper/LabSensorMapper.java
  14. 12 0
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/mqtt/service/impl/SubMessageSendManager.java
  15. 8 2
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/ILabRiskPlanService.java
  16. 1 1
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/ILabSensorService.java
  17. 1 1
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/LabRiskPlanLevelService.java
  18. 174 114
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabRiskPlanServiceImpl.java
  19. 1 1
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabSensorServiceImpl.java
  20. 20 3
      zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabBuildFloorLayoutMapper.xml
  21. 16 2
      zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabRiskPlanMapper.xml
  22. 1 1
      zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabSensorMapper.xml

+ 20 - 0
zd-api/zd-laboratory-api/src/main/java/com/zd/laboratory/api/entity/OneClickFireDTO.java

@@ -0,0 +1,20 @@
+package com.zd.laboratory.api.entity;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @Description 一键灭火传输类
+ * @Author hzw
+ * @Date 2022/12/12 16:52
+ * @Version 2.0
+ */
+@Data
+public class OneClickFireDTO {
+
+    @ApiModelProperty("硬件编号")
+    private String hardwareNum;
+
+    @ApiModelProperty("是否火灾 0否 1是")
+    private Integer ifFire;
+}

+ 6 - 0
zd-api/zd-laboratory-api/src/main/java/com/zd/laboratory/api/feign/RemoteLaboratoryService.java

@@ -3,6 +3,8 @@ package com.zd.laboratory.api.feign;
 import com.zd.laboratory.api.entity.LabGradeManageRecord;
 import com.zd.laboratory.api.entity.LabMessageContent;
 import com.zd.laboratory.api.entity.LabSubjectEntityVO;
+import com.zd.laboratory.api.entity.OneClickFireDTO;
+import com.zd.model.domain.ResultData;
 import com.zd.model.entity.RemoteLabHardware;
 import com.zd.laboratory.api.feign.fallback.RemoteLaboratoryFallbackFactory;
 import com.zd.laboratory.api.vo.LabGradeManageWorkVO;
@@ -463,4 +465,8 @@ public interface RemoteLaboratoryService {
     @ApiOperation(value = "修改识别器状态")
     @PutMapping("/hardware/update")
     R<Integer> update(@RequestParam("operate") HardwareOperate operate, @RequestParam("ipAddress") String ipAddress);
+
+    @ApiOperation(value = "一件灭火接受火焰预警")
+    @PutMapping("/plan/oneClickFire")
+    ResultData oneClickFire(@RequestBody OneClickFireDTO oneClickFireDTO);
 }

+ 6 - 0
zd-api/zd-laboratory-api/src/main/java/com/zd/laboratory/api/feign/fallback/RemoteLaboratoryFallbackFactory.java

@@ -3,6 +3,8 @@ package com.zd.laboratory.api.feign.fallback;
 import com.zd.laboratory.api.entity.LabGradeManageRecord;
 import com.zd.laboratory.api.entity.LabMessageContent;
 import com.zd.laboratory.api.entity.LabSubjectEntityVO;
+import com.zd.laboratory.api.entity.OneClickFireDTO;
+import com.zd.model.domain.ResultData;
 import com.zd.model.entity.RemoteLabHardware;
 import com.zd.laboratory.api.feign.RemoteLaboratoryService;
 import com.zd.laboratory.api.vo.LabGradeManageWorkVO;
@@ -421,6 +423,10 @@ public class RemoteLaboratoryFallbackFactory implements FallbackFactory<RemoteLa
                 return R.fail("RFID设备状态修改失败:" + cause.getMessage());
             }
 
+            @Override
+            public ResultData oneClickFire(OneClickFireDTO oneClickFireDTO) {
+                return ResultData.fail("一键灭火触发预案失败!"+ cause.getMessage());
+            }
         };
     }
 }

+ 3 - 0
zd-model/src/main/java/com/zd/model/constant/MqttConstants.java

@@ -95,6 +95,9 @@ public interface MqttConstants {
     //灭火设备异常通知
     String TOPIC_FIRE_DEVICE_WARN = "lab/fireDevice/Warn/";
 
+    //预案配置
+    String TOPIC_RISKPLAN_TRIGGER_NOTICE = "lab/riskPlan/trigger/notice";
+
     //灭火设备是否在线
     String TOPIC_FIRE_DEVICE_ONLINE = "lab/fireDevice/isOnline/";
 

+ 56 - 7
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/LabRiskPlanController.java

@@ -10,6 +10,7 @@ import com.zd.common.core.redis.RedisService;
 import com.zd.common.core.utils.ExcelUtil;
 import com.zd.common.core.utils.StringUtils;
 import com.zd.common.core.web.controller.BaseController;
+import com.zd.laboratory.api.entity.BasicFunctionStatus;
 import com.zd.laboratory.api.entity.SensorFunctionStatus;
 import com.zd.laboratory.api.vo.SubFunction;
 import com.zd.laboratory.domain.LabRiskPlan;
@@ -17,7 +18,9 @@ import com.zd.laboratory.domain.LabRiskPlanAbnormalGroup;
 import com.zd.laboratory.domain.LabRiskPlanAbnormalLog;
 import com.zd.laboratory.domain.LabRiskPlanjoinsub;
 import com.zd.laboratory.domain.dto.LabRiskPlanDTO;
+import com.zd.laboratory.domain.dto.OneClickFireDTO;
 import com.zd.laboratory.domain.vo.LabRiskPlanSubVo;
+import com.zd.laboratory.domain.vo.LabRiskPlanSubVoInfo;
 import com.zd.laboratory.domain.vo.LabSubjectVO;
 import com.zd.laboratory.domain.vo.RiskPlanVo;
 import com.zd.laboratory.mapper.LabRiskPlanjoinsubMapper;
@@ -35,10 +38,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 
 /**
  * 风险预案Controller
@@ -180,8 +180,8 @@ public class LabRiskPlanController extends BaseController {
     @Log(title = "预案关联实验室提交", businessType = BusinessType.INSERT)
     @PreAuthorize(hasPermi = PerPrefix.LABORATORY_PLANJOIN + PerFun.EDIT)
     @PostMapping("/riskPlanJoinSub")
-    public ResultData riskPlanJoinSub(@RequestBody List<LabRiskPlanSubVo> labRiskPlanSubVos) {
-        return ResultData.success(labRiskPlanService.riskPlanJoinSub(labRiskPlanSubVos));
+    public ResultData riskPlanJoinSub(@RequestBody LabRiskPlanSubVoInfo labRiskPlanSubVoInfo) {
+        return labRiskPlanService.riskPlanJoinSub(labRiskPlanSubVoInfo);
     }
 
     /**
@@ -209,11 +209,58 @@ public class LabRiskPlanController extends BaseController {
      */
     @PreAuthorize(hasPermi = PerPrefix.LABORATORY_PLAN + PerFun.QUERY)
     @Log(title = "查询当前触发预案的信息", businessType = BusinessType.OTHER)
-    @DeleteMapping("/selectTriggerInfo")
+    @GetMapping("/selectTriggerInfo")
     public ResultData selectTriggerInfo() {
         return ResultData.success(labRiskPlanService.selectTriggerInfo());
     }
 
+    /**
+     * 查询用户是否进入过预案
+     */
+    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_PLAN + PerFun.QUERY)
+    @Log(title = "查询用户是否进入过预案", businessType = BusinessType.OTHER)
+    @GetMapping("/checkEnterRiskPlan")
+    public ResultData checkEnterRiskPlan(Long riskPlanId) {
+        return ResultData.success(labRiskPlanService.checkEnterRiskPlan(riskPlanId));
+    }
+
+    /**
+     * 写入用户进入预案数据
+     */
+    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_PLAN + PerFun.QUERY)
+    @Log(title = "写入用户进入预案数据", businessType = BusinessType.OTHER)
+    @GetMapping("/writerEnterRiskPlan")
+    public ResultData writerEnterRiskPlan(Long riskPlanId,Integer ifcheck) {
+        labRiskPlanService.writerEnterRiskPlan(riskPlanId,ifcheck);
+        return ResultData.success();
+    }
+
+    /**
+     * 一件灭火接受火焰预警
+     */
+    @Log(title = "一件灭火触发火焰预警")
+    @PostMapping("/oneClickFire")
+    public ResultData oneClickFire(@RequestBody OneClickFireDTO oneClickFireDTO){
+        logger.info("一件灭火触发火焰预警,入参={}",oneClickFireDTO.toString());
+        if (StringUtils.isNotBlank(oneClickFireDTO.getHardwareNum())) {
+            if (oneClickFireDTO.getIfFire() == 1) {
+                Long subId = labHardwareService.querySubIdByNum(oneClickFireDTO.getHardwareNum());
+                SubFunction subFunction = new SubFunction();
+                List<BasicFunctionStatus> basicFunctionStatuses = new ArrayList<>();
+                BasicFunctionStatus basicFunctionStatus = new BasicFunctionStatus();
+                basicFunctionStatus.setFuncName("火焰");
+                basicFunctionStatus.setHardwareNum(oneClickFireDTO.getHardwareNum());
+                basicFunctionStatus.setFunNum("huoyan");
+                basicFunctionStatus.setDescribe("火焰");
+                basicFunctionStatuses.add(basicFunctionStatus);
+                subFunction.setSubId(subId);
+                subFunction.setFunctionStatuses(basicFunctionStatuses);
+                triggerRiskPlan(subFunction);
+                return ResultData.success();
+            }
+        }
+        return ResultData.fail("设备编号为空!");
+    }
 
     /**
      * 执行传感器对应的风险预案
@@ -241,6 +288,8 @@ public class LabRiskPlanController extends BaseController {
 //                                    redisService.setCacheObject("subjectByHuoyan"+subFunction.getSubId(), subFunction.getSubId());
                                     labRiskPlanService.triggerRiskPlan(subFunction);
                                 }
+                                //如果是温度,烟感 则走正常逻辑
+                                labRiskPlanService.triggerRiskPlan(subFunction);
                             });
                 }
             }

+ 5 - 5
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/LabRiskPlanLevelController.java

@@ -25,7 +25,7 @@ import java.util.List;
 public class LabRiskPlanLevelController extends BaseController {
 
     @Autowired
-    private LabRiskPlanLevelService LabRiskPlanLevelService;
+    private LabRiskPlanLevelService labRiskPlanLevelService;
 
     /**
      * 新增预案级别信息信息
@@ -33,7 +33,7 @@ public class LabRiskPlanLevelController extends BaseController {
     @PreAuthorize(hasPermi = PerPrefix.LABORATORY_PLAN + PerFun.ADD)
     @PostMapping("/add")
     public ResultData insert(@RequestBody LabRiskPlanLevel labRiskPlanLevel) {
-        return LabRiskPlanLevelService.insertLabRiskPlanLevel(labRiskPlanLevel);
+        return labRiskPlanLevelService.insertLabRiskPlanLevel(labRiskPlanLevel);
     }
 
     /**
@@ -42,7 +42,7 @@ public class LabRiskPlanLevelController extends BaseController {
     @PreAuthorize(hasPermi = PerPrefix.LABORATORY_PLAN + PerFun.EDIT)
     @PutMapping("/update")
     public ResultData updateById(@RequestBody LabRiskPlanLevel labRiskPlanLevel) {
-        return LabRiskPlanLevelService.updateLabRiskPlanLevel(labRiskPlanLevel);
+        return labRiskPlanLevelService.updateLabRiskPlanLevel(labRiskPlanLevel);
     }
 
     /**
@@ -51,7 +51,7 @@ public class LabRiskPlanLevelController extends BaseController {
     @PreAuthorize(hasPermi = PerPrefix.LABORATORY_PLAN + PerFun.REMOVE)
     @DeleteMapping("/delete")
     public ResultData delete(@RequestBody LabRiskPlanLevel labRiskPlanLevel) {
-        return ResultData.result(LabRiskPlanLevelService.deleteById(labRiskPlanLevel));
+        return ResultData.result(labRiskPlanLevelService.deleteById(labRiskPlanLevel));
     }
 
     /**
@@ -60,7 +60,7 @@ public class LabRiskPlanLevelController extends BaseController {
     @PreAuthorize(hasPermi = PerPrefix.LABORATORY_PLAN + PerFun.QUERY)
     @GetMapping("/selectRiskPlanLeveList/{riskPlanId}")
     public ResultData selectRiskPlanLeveList(@PathVariable Long riskPlanId) {
-        List<LabRiskPlanLevel> labRiskPlanLevelList = LabRiskPlanLevelService.queryRiskPlanLevelList(riskPlanId);
+        List<LabRiskPlanLevel> labRiskPlanLevelList = labRiskPlanLevelService.queryRiskPlanLevelList(riskPlanId);
         return ResultData.success(labRiskPlanLevelList);
     }
 }

+ 14 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/LabRiskPlan.java

@@ -129,6 +129,12 @@ public class LabRiskPlan extends BaseEntity {
     private Long floorId;
 
     /**
+     * 是否查询预案
+     */
+    @ApiModelProperty(value = "是否查询预案")
+    private Integer ifCheck;
+
+    /**
      * 预案级别列表
      */
     private List<LabRiskPlanLevel> labRiskPlanLevels;
@@ -347,4 +353,12 @@ public class LabRiskPlan extends BaseEntity {
     public void setRiskPlanSensorList(List<LabRiskPlanSensorRelation> riskPlanSensorList) {
         this.riskPlanSensorList = riskPlanSensorList;
     }
+
+    public Integer getIfCheck() {
+        return ifCheck;
+    }
+
+    public void setIfCheck(Integer ifCheck) {
+        this.ifCheck = ifCheck;
+    }
 }

+ 33 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/dto/LabBuildFloorLayoutDTO.java

@@ -0,0 +1,33 @@
+package com.zd.laboratory.domain.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @Description TODO
+ * @Author hzw
+ * @Date 2022/12/11 18:15
+ * @Version 2.0
+ */
+@Data
+public class LabBuildFloorLayoutDTO {
+
+    /**
+     * 预案id
+     */
+    @ApiModelProperty(value = "预案id")
+    private Long riskPlanId;
+
+    /** 楼栋id */
+    @ApiModelProperty(value = "楼栋id")
+    private Long buildId;
+
+    /** 楼层id */
+    @ApiModelProperty(value = "楼层id")
+    private Long floorId;
+
+    /** 实验室id */
+    @ApiModelProperty(value = "实验室id")
+    private Long subId;
+
+}

+ 20 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/dto/OneClickFireDTO.java

@@ -0,0 +1,20 @@
+package com.zd.laboratory.domain.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @Description 一键灭火传输类
+ * @Author hzw
+ * @Date 2022/12/12 16:52
+ * @Version 2.0
+ */
+@Data
+public class OneClickFireDTO {
+
+    @ApiModelProperty("硬件编号")
+    private String hardwareNum;
+
+    @ApiModelProperty("是否火灾 0否 1是")
+    private Integer ifFire;
+}

+ 4 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/vo/LabRiskPlanSubVoInfo.java

@@ -14,7 +14,10 @@ import java.util.List;
 @Data
 public class LabRiskPlanSubVoInfo {
 
-    @ApiModelProperty("是否覆盖传感器重复区间预案")
+    @ApiModelProperty(name = "预案id")
+    private Long riskPlanId;
+
+    @ApiModelProperty("是否覆盖传感器重复区间预案 0否1是")
     private Integer yesOrNo;
 
     private List<LabRiskPlanSubVo> labRiskPlanSubVos;

+ 3 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/mapper/LabBuildFloorLayoutMapper.java

@@ -1,7 +1,9 @@
 package com.zd.laboratory.mapper;
 
 import com.zd.laboratory.domain.LabBuildFloorLayout;
+import com.zd.laboratory.domain.dto.LabBuildFloorLayoutDTO;
 import com.zd.laboratory.domain.vo.LabBuildFloorLayoutVo;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -67,5 +69,5 @@ public interface LabBuildFloorLayoutMapper {
     /**
      * 根据实验室id 查询 楼栋 楼层 实验室信息
      */
-    LabBuildFloorLayoutVo selectBuildInfoBySubId(Long subjectId);
+    LabBuildFloorLayoutDTO selectBuildInfoBySubIdAndUser(@Param("subjectId") Long subjectId, @Param("userId") Long userId);
 }

+ 1 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/mapper/LabRiskPlanjoinsubMapper.java

@@ -95,7 +95,7 @@ public interface LabRiskPlanjoinsubMapper
      * @param ids 需要删除的数据主键集合
      * @return 结果
      */
-    public int deleteLabRiskPlanjoinsubByIds(Long[] ids);
+    public int deleteLabRiskPlanjoinsubByIds(long[] ids);
 
     /**
      * 删除

+ 1 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/mapper/LabSensorMapper.java

@@ -93,5 +93,5 @@ public interface LabSensorMapper {
 
     List<LabSensor> getSensorListBySubId(@Param("id") Long id);
 
-    List<Long> getSensorTypesBySubId(@Param("id") Long id);
+    List<Integer> getSensorTypesBySubId(@Param("id") Long id);
 }

+ 12 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/mqtt/service/impl/SubMessageSendManager.java

@@ -79,6 +79,18 @@ public class SubMessageSendManager {
     }
 
     /**
+     * 预案触发通知
+     *
+     */
+    public void riskPlanTriggerNotice() {
+        logger.info("预案触发,发送前段mqtt信息");
+        MessageBody messageBody = new MessageBody();
+        messageBody.setData(1);
+        //仅发送一次
+        commonSend.send(MqttConstants.TOPIC_RISKPLAN_TRIGGER_NOTICE, messageBody, SendMode.ONCE);
+    }
+
+    /**
      * 发送一体机预警测点
      *
      * @param id 实验室ID

+ 8 - 2
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/ILabRiskPlanService.java

@@ -6,8 +6,10 @@ import com.zd.laboratory.api.entity.SensorFunctionStatus;
 import com.zd.laboratory.api.vo.SubFunction;
 import com.zd.laboratory.domain.LabRiskPlan;
 import com.zd.laboratory.domain.LabRiskPlanjoinsub;
+import com.zd.laboratory.domain.dto.LabBuildFloorLayoutDTO;
 import com.zd.laboratory.domain.dto.LabRiskPlanDTO;
 import com.zd.laboratory.domain.vo.*;
+import com.zd.model.domain.ResultData;
 
 import java.util.List;
 import java.util.Map;
@@ -148,11 +150,15 @@ public interface ILabRiskPlanService  extends IService<LabRiskPlan> {
 
     Page<LabSubjectVO> getLabRiskPlanNoJoinSub(LabRiskPlanSubVo labRiskPlanSubVo);
 
-    Map<String, Object> riskPlanJoinSub(List<LabRiskPlanSubVo> labRiskPlanSubVoList);
+    ResultData riskPlanJoinSub(LabRiskPlanSubVoInfo labRiskPlanSubVoInfo);
 
     int deleteRiskPlanJoinSub(LabRiskPlanSubVo labRiskPlanSubVo);
 
     int riskPlanBatchJoinSub(LabRiskPlanSubVo labRiskPlanSubVo);
 
-    List<LabBuildFloorLayoutVo> selectTriggerInfo();
+    List<LabBuildFloorLayoutDTO> selectTriggerInfo();
+
+    Integer checkEnterRiskPlan(Long riskPlanId);
+
+    void writerEnterRiskPlan(Long riskPlanId,Integer ifcheck);
 }

+ 1 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/ILabSensorService.java

@@ -98,5 +98,5 @@ public interface ILabSensorService {
      * @param id
      * @return
      */
-    List<Long> getSensorTypesBySubId(Long id);
+    List<Integer> getSensorTypesBySubId(Long id);
 }

+ 1 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/LabRiskPlanLevelService.java

@@ -38,7 +38,7 @@ public interface LabRiskPlanLevelService extends IService<LabRiskPlanLevel> {
 
     /**
      * 根据预案id删除预案级别数据
-     * @Param [id 预案id]
+     * @Param [id 预案ids]
      * @Return int
      **/
     int deleteByRiskPlanId(String riskPlanIds);

+ 174 - 114
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabRiskPlanServiceImpl.java

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zd.algorithm.api.camera.feign.RemoteCameraService;
 import com.zd.algorithm.api.speaker.entity.ParamVo;
 import com.zd.algorithm.api.speaker.entity.PlayVo;
 import com.zd.algorithm.api.speaker.feign.RemoteSpeakService;
@@ -18,10 +19,10 @@ import com.zd.common.core.utils.StringUtils;
 import com.zd.laboratory.api.entity.FunctionStatus;
 import com.zd.laboratory.api.entity.LabMessageContent;
 import com.zd.laboratory.api.entity.SensorFunctionStatus;
-import com.zd.laboratory.api.vo.SenseValVO;
 import com.zd.laboratory.api.vo.SubFunction;
 import com.zd.laboratory.config.HardwareFunctionStatusConfig;
 import com.zd.laboratory.domain.*;
+import com.zd.laboratory.domain.dto.LabBuildFloorLayoutDTO;
 import com.zd.laboratory.domain.dto.LabRiskPlanDTO;
 import com.zd.laboratory.domain.vo.*;
 import com.zd.laboratory.mapper.*;
@@ -37,6 +38,7 @@ import com.zd.model.enums.HardwareTypeEnum;
 import com.zd.model.enums.SenseType;
 import com.zd.model.enums.WarnMessageTypeEnum;
 import org.apache.commons.collections4.CollectionUtils;
+import org.jetbrains.annotations.NotNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -124,6 +126,12 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
     @Autowired
     private LabBuildFloorLayoutMapper labBuildFloorLayoutMapper;
 
+    @Autowired
+    private ILabRiskPlanAbnormalGroupService labRiskPlanAbnormalGroupService;
+
+    @Autowired
+    private RemoteCameraService remoteCameraService;
+
     private static final Logger log = LoggerFactory.getLogger(LabRiskPlanServiceImpl.class);
 
 
@@ -595,6 +603,8 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
         if (i > 0) {
             throw new ServiceException("该预案已经绑定实验室,请先解除绑定关系再删除!");
         }
+        //删除预案级别以下信息
+        labRiskPlanLevelService.deleteByRiskPlanId(ids);
         return labRiskPlanMapper.deleteLabRiskPlanByIds(ids);
     }
 
@@ -1009,13 +1019,8 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
 
         //根据实验室Id查询 云盒传入数据是否落入传感器区间。有则返回分级信息
         LabRiskPlanLevel labRiskPlanLevel = matchingRiskPlan(subFunction);
-        LabRiskPlan labRiskPlan = labRiskPlanMapper.selectLabRiskPlanByRiskPlanId(labRiskPlanLevel.getRiskPlanId());
-        labRiskPlanLevel.setFloorId(labRiskPlan.getFloorId());
-        labRiskPlanLevel.setTopName(labRiskPlan.getTopName());
-
+        // 云盒传入数据如果没有落入传感器区间 有可能是之前预案关闭
 
-//        LabRiskPlan newRiskPlan = new LabRiskPlan();
-//        newRiskPlan.setId(labRiskPlanLevel.getRiskPlanId());
 
         //获取通知配置信息
         List<LabNoticeconfig> noticeconfigList = labNoticeconfigMapper.selectLabNoticeconfigList(new LabNoticeconfig());
@@ -1026,17 +1031,6 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
         labRiskPlanLevel.setVoicebroadcast(labNoticeconfig.getRiskVoice());
         labRiskPlanLevel.setInformation(labNoticeconfig.getRiskPhone());
 
-
-//        if (noticeconfigList.size() > 0 && newRiskPlan != null) {
-            //语音播报 短信 电话内容
-//            LabNoticeconfig labNoticeconfig = noticeconfigList.get(0);
-//            newRiskPlan.setVoicebroadcast(labNoticeconfig.getRiskVoice());
-//            newRiskPlan.setMessage(labNoticeconfig.getRiskMessage());
-//            newRiskPlan.setInformation(labNoticeconfig.getRiskPhone());
-            //预案广播通知
-
-//        }
-
         //将风险预案写入归属组级表里面
         LabRiskPlanAbnormalGroup labRiskPlanAbnormalGroup = new LabRiskPlanAbnormalGroup();
         labRiskPlanAbnormalGroup.setSubjectId(subFunction.getSubId());
@@ -1045,7 +1039,11 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
         List<LabRiskPlanAbnormalGroupVO> groupList = labRiskPlanAbnormalGroupMapper.selectLabRiskPlanAbnormalGroupList(labRiskPlanAbnormalGroup);
 
         //如果预案里面配置传感器都达标,需要执行预案对应的硬件操作
-        if (labRiskPlanLevel != null) {
+        if (labRiskPlanLevel.getRiskPlanId() != null) {
+            LabRiskPlan labRiskPlan = labRiskPlanMapper.selectLabRiskPlanByRiskPlanId(labRiskPlanLevel.getRiskPlanId());
+            labRiskPlanLevel.setFloorId(labRiskPlan.getFloorId());
+            labRiskPlanLevel.setTopName(labRiskPlan.getTopName());
+
             //这里处理,如果是火焰预案,需要redis额外缓存
             Optional.ofNullable(subFunction.getFunctionStatuses()).orElseGet(Collections::emptyList).stream().filter(a -> "huoyan".equals(a.getFunNum())).forEach(a -> {
                 if (redisService.getCacheObject("subjectByHuoyan" + subFunction.getSubId()) == null) {
@@ -1054,15 +1052,18 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
             });
             //有效预案延长一分钟
 //            if(redisService.getCacheObject("subjectByYa"+subFunction.getSubId())==null){
-            redisService.setCacheObject("subjectByYa" + subFunction.getSubId(), subFunction.getSubId(), 3L, TimeUnit.MINUTES);
+//            redisService.setCacheObject("subjectByYa" + subFunction.getSubId(), subFunction.getSubId(), 2L, TimeUnit.MINUTES);
+            redisService.setCacheObject("subjectByYa" + subFunction.getSubId(), subFunction.getSubId(), 10L, TimeUnit.SECONDS);
             log.info("@@@@@@@@@@@@@@@@@@@@预案延长3分钟@@@@@@@@@@@@@@@@@@@@");
 //            }
+            Map<SenseType, List<SensorFunctionStatus>> sensorFunctionStatusListMap = hardwareFunctionStatusConfig.getSensorFunctionStatusListMap();
             //处理预案下的传感器翻译
             JSONArray riskPlanJson = new JSONArray();
             for (LabRiskPlanSensorRelation rps : labRiskPlanLevel.getRiskPlanSensorList()) {
                 //硬件社保统一传入的传感器设备列表
                 for (SensorFunctionStatus sensorFunc : subFunction.getFunctionStatuses()) {
-                    if (rps.getFunNum().equals(sensorFunc.getFunNum())) {
+                    String funNum1 = sensorFunctionStatusListMap.get(SenseType.getByCode(rps.getSensorType())).get(0).getFunNum();
+                    if (funNum1.equals(sensorFunc.getFunNum())) {
                         getJsonStr(riskPlanJson, sensorFunc);
                         labRiskPlanLevel.setTopName(labRiskPlanLevel.getTopName() + " " + sensorFunc.getDescribe());
                     }
@@ -1073,6 +1074,12 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
             Long groupId = insertPlanAbnormalLog(labRiskPlanLevel, riskPlanJson, groupList, 1L, subFunction);
             log.info("####################groupId:" + groupId);
             if (groupId != null) {
+                //开始录制视频
+//                remoteCameraService.startRecord("192.168.1.14");
+
+                //向前端发送mqtt预案触发提示
+                messageSendService.riskPlanTriggerNotice();
+
                 log.error("这里记录预警消息记录开始=======================================================");
                 insertWarnPushMessageByOnePc(labRiskPlanLevel, subFunction.getSubId(), groupId);
                 log.error("这里记录预警消息记录结束=======================================================");
@@ -1244,6 +1251,12 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
                 newGroupOP.setId(groupVo.getId());
                 newGroupOP.setStatus(0L);
                 labRiskPlanAbnormalGroupMapper.updateLabRiskPlanAbnormalGroup(newGroupOP);
+                // todo 操作人和视频结束时候的 url
+                R r = remoteCameraService.stopRecord("192.168.1.14");
+//                if (r.getCode().equals(HttpStatus.SUCCESS)){
+//
+//                }
+//                labRiskPlanAbnormalGroupService.doneRiskExeRecord(groupVo.getId(), "handledPerson", "recordVideo");
                 //插入预案结束日志
                 insertPlanAbnormalLogByOver(groupVo, allRiskPlanJson, subFunction);
                 //向一体机传感器预警
@@ -1391,7 +1404,9 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
         labRiskPlanAbnormalLog.setRiskStatus(riskStatus);
         labRiskPlanAbnormalLog.setSubjectId(subFunction.getSubId());
         if (groupList == null || groupList.size() == 0) {
+            // todo
             labRiskPlanAbnormalGroup = insertPlanAbnormalGroup(labRiskPlanLevel, subFunction.getSubId());
+//            labRiskPlanAbnormalGroupService.addRiskExeRecord(riskPlanName, subjectId, subjectName, riskAttribute, riskReason, riskLevel);
             groupId = labRiskPlanAbnormalGroup.getId();
             //给风险日志表关联组
             labRiskPlanAbnormalLog.setGroupId(labRiskPlanAbnormalGroup.getId());
@@ -1640,25 +1655,29 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
         List<LabRiskPlanSensorRelation> labRiskPlanSensorRelations = labRiskPlanSensorRelationMapper.selectSensorListBySubId(subFunction.getSubId());
         LinkedHashMap<Long, List<LabRiskPlanSensorRelation>> collect = Optional.ofNullable(labRiskPlanSensorRelations).orElseGet(Collections::emptyList).stream().collect(Collectors.groupingBy(LabRiskPlanSensorRelation::getRiskPlanLevelId, LinkedHashMap::new, Collectors.toList()));
         List<Long> list = new ArrayList<>();
-        collect.forEach((key,value)->{
-                Integer count = 0;
+        collect.forEach((key, value) -> {
+            Integer count = 0;
+
+            Map<SenseType, List<SensorFunctionStatus>> sensorFunctionStatusListMap = hardwareFunctionStatusConfig.getSensorFunctionStatusListMap();
             //预案级别下传感器列表
             for (LabRiskPlanSensorRelation labRiskPlanSensorRelation : value) {
-                    //云台发送的传感器数据
-                    for (SensorFunctionStatus functionStatus : subFunction.getFunctionStatuses()) {
-                        if (functionStatus.getFunNum().equals(labRiskPlanSensorRelation.getFunNum())) {
-                            Float senseVal = null;
-                            try {
-                                senseVal = Float.parseFloat(functionStatus.getVal());
-                            } catch (NumberFormatException e) {
-                                return;
-                            }
-                            //判断值范围  在范围内存储预案ID和类型名称 (火焰,温度,湿度)
-                            if ((senseVal >= labRiskPlanSensorRelation.getMinMonitor().floatValue()) && (senseVal <= labRiskPlanSensorRelation.getMaxMonitor().floatValue())) {
-                                count++;
-                            }
+                List<SensorFunctionStatus> sensorFunctionStatuses = sensorFunctionStatusListMap.get(SenseType.getByCode(labRiskPlanSensorRelation.getSensorType()));
+                String funNum = sensorFunctionStatuses.get(0).getFunNum();
+                //云台发送的传感器数据
+                for (SensorFunctionStatus functionStatus : subFunction.getFunctionStatuses()) {
+                    if (functionStatus.getFunNum().equals(funNum)) {
+                        Float senseVal = null;
+                        try {
+                            senseVal = Float.parseFloat(functionStatus.getVal());
+                        } catch (NumberFormatException e) {
+                            return;
+                        }
+                        //判断值范围  在范围内存储预案ID和类型名称 (火焰,温度,湿度)
+                        if ((senseVal >= labRiskPlanSensorRelation.getMinMonitor().floatValue()) && (senseVal <= labRiskPlanSensorRelation.getMaxMonitor().floatValue())) {
+                            count++;
                         }
                     }
+                }
             }
             if (value.size() == count) {
                 list.add(key);
@@ -1666,13 +1685,15 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
         });
         StringBuilder sb = new StringBuilder();
         list.forEach(aLong -> {
-            sb.append(aLong);
-            sb.append(",");
+            sb.append(aLong+",");
         });
         //根据预案级别查询预案信息
 //        LabRiskPlanLevel labRiskPlanLevel = labRiskPlanLevelService.getOne(new LambdaQueryWrapper<LabRiskPlanLevel>().in(LabRiskPlanLevel::getId, sb.substring(0, sb.length() - 1)).orderByDesc(LabRiskPlanLevel::getRiskPlanLevel).last(" limit 1"));
-        LabRiskPlanLevel labRiskPlanLevel = labRiskPlanLevelService.queryRiskPlanLevelByLevelIds(sb.substring(0, sb.length() - 1));
-        return labRiskPlanLevel;
+        if(StringUtils.isNotBlank(sb.toString())){
+            LabRiskPlanLevel labRiskPlanLevel = labRiskPlanLevelService.queryRiskPlanLevelByLevelIds(sb.substring(0, sb.length() - 1));
+            return labRiskPlanLevel;
+        }
+        return new LabRiskPlanLevel();
 
 //        //预案列表循环
 //        int maxCount = 0;
@@ -1818,11 +1839,11 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
         if (null != labRiskPlanSubVo.getRiskPlanId()) {
             for (LabSubjectVO labSubjectVO : labSubjectVOS.getRecords()) {
                 List<LabSensorHazardRelation> labSensorHazardRelations = labSensorHazardRelationService.getSensorHazardList(labRiskPlanSubVo.getRiskPlanId(), labSubjectVO.getId());
-                List<Long> list = labSensorService.getSensorTypesBySubId(labSubjectVO.getId());
+                List<Integer> list = labSensorService.getSensorTypesBySubId(labSubjectVO.getId());
                 if (isListEqual(collect, list)) {
                     labSubjectVO.setSenseState("正常");
                 } else {
-                    labSubjectVO.setSenseState("传感器不一致");
+                    labSubjectVO.setSenseState("已失效");
                 }
                 labSubjectVO.setLabSensorHazardRelations(labSensorHazardRelations);
             }
@@ -1925,17 +1946,96 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
     }
 
     @Override
-    public Map<String, Object> riskPlanJoinSub(List<LabRiskPlanSubVo> labRiskPlanSubs) {
-
-        Map<SenseType, List<SensorFunctionStatus>> sensorFunctionStatusListMap = hardwareFunctionStatusConfig.getSensorFunctionStatusListMap();
-        List<SenseValVO> senseValVOS = hardwareFunctionStatusConfig.getSenseValVOS();
-        SenseType byCode = SenseType.getByCode(4);
-        List<SensorFunctionStatus> sensorFunctionStatuses = sensorFunctionStatusListMap.get(byCode);
-        //当前预案信息根据预案级别分组
-        List<LabRiskPlanSensorRelation> labRiskPlanSensorRelations = labRiskPlanSensorRelationMapper.selectList(new LambdaQueryWrapper<LabRiskPlanSensorRelation>().eq(LabRiskPlanSensorRelation::getRiskPlanId, labRiskPlanSubs.get(0).getRiskPlanId()).select());
+    public ResultData riskPlanJoinSub(LabRiskPlanSubVoInfo labRiskPlanSubVoInfo) {
+        List<LabRiskPlanSubVo> labRiskPlanSubs = labRiskPlanSubVoInfo.getLabRiskPlanSubVos();
+        //获取现有预案和选定预案有冲突 预案ids
+        Set<Long> riskplanIds = getConflictRiskplanIds(labRiskPlanSubs);
+        Map<String,String> map = new HashMap<>();
+        if (!riskplanIds.isEmpty()) {
+            Object[] objects = riskplanIds.toArray();
+            //根据预案id和实验室id查询当前用户是否有冲突的预案
+            List<LabRiskPlanjoinsubVO> riskPlanjoinsubList = new ArrayList<>();
+            Optional.ofNullable(labRiskPlanSubs).orElseGet(Collections::emptyList).stream().forEach(a -> {
+                LabRiskPlanjoinsubVO labRiskPlanjoinsubVO = new LabRiskPlanjoinsubVO();
+                labRiskPlanjoinsubVO.setSubjectId(a.getSubjectId());
+                for (int i = 0; i < objects.length; i++) {
+                    labRiskPlanjoinsubVO.getRiskPlanIds().add((Long) objects[i]);
+                }
+                if (labRiskPlanjoinsubVO.getRiskPlanIds().size() > 0) {
+                    riskPlanjoinsubList.addAll(labRiskPlanjoinsubMapper.getLabRiskPlanjoinsubList(labRiskPlanjoinsubVO));
+                }
+            });
+
+            StringBuffer tipsStr = new StringBuffer();
+            StringBuffer riskRelationIdStr = new StringBuffer();
+            if (riskPlanjoinsubList.size() > 0) {
+                //有现有关联实验室与当前绑定实验室冲突
+                Optional.ofNullable(riskPlanjoinsubList).orElseGet(Collections::emptyList).stream().forEach(a -> {
+                    if (tipsStr.indexOf(a.getSubName()) == -1) {
+                        tipsStr.append(a.getSubName()).append("、");
+                    }
+                    //收集冲突关联id
+                    riskRelationIdStr.append(a.getId()).append(",");
+                });
+
+                if (labRiskPlanSubVoInfo.getYesOrNo() == 1) {
+                    //删除预案实验室绑定关系
+                    long[] longs = StrUtil.splitToLong(riskRelationIdStr, ",");
+                    labRiskPlanjoinsubMapper.deleteLabRiskPlanjoinsubByIds(longs);
+                    relationSubject(labRiskPlanSubs);
+                    map.put("ifConflict","0");
+                    return ResultData.success(map);
+                }
+                map.put("ifConflict","1");
+                map.put("message",tipsStr.substring(1) + "已关联预案与当前预案有传感器数值冲突,是否绑定到当前预案");
+                return ResultData.success(map);
+            }
+        }
+        //无冲突预案ids 直接关联实验室
+        relationSubject(labRiskPlanSubs);
+        map.put("ifConflict","0");
+        return ResultData.success(map);
+    }
+
+    private void relationSubject(List<LabRiskPlanSubVo> labRiskPlanSubs) {
+        //直接关联
+        for (LabRiskPlanSubVo labRiskPlanSub : labRiskPlanSubs) {
+            List<LabSensorHazardRelation> labSensorHazardRelations = labRiskPlanSub.getLabSensorHazardRelations();
+            //建立预案和实验室的关联数据
+            LabRiskPlanjoinsub labRiskPlanjoinsub = new LabRiskPlanjoinsub();
+            labRiskPlanjoinsub.setSubjectId(labRiskPlanSub.getSubjectId());
+            labRiskPlanjoinsub.setRiskPlanId(labRiskPlanSub.getRiskPlanId());
+            labRiskPlanjoinsub.setUserId(tokenService.getLoginUser().getSysUser().getUserId());
+            labRiskPlanjoinsub.setCreateBy(tokenService.getLoginUser().getSysUser().getNickName());
+            labRiskPlanjoinsub.setCreateTime(DateUtils.getNowDate());
+            labRiskPlanjoinsubMapper.insertLabRiskPlanjoinsub(labRiskPlanjoinsub);
+            for (LabSensorHazardRelation labSensorHazardRelation : labSensorHazardRelations) {
+                labSensorHazardRelation.setRiskPlanId(labRiskPlanSub.getRiskPlanId());
+                labSensorHazardRelation.setSubjectId(labRiskPlanSub.getSubjectId());
+            }
+            labSensorHazardRelationService.saveBatch(labSensorHazardRelations);
+
+            //插入分配记录日志信息
+            LabRiskPlanDistribution labRiskPlanDistribution = new LabRiskPlanDistribution();
+            labRiskPlanDistribution.setRiskPlanId(labRiskPlanSub.getRiskPlanId());
+            labRiskPlanDistribution.setSubId(labRiskPlanSub.getSubjectId());
+            labRiskPlanDistribution.setGroupDeptId(tokenService.getLoginUser().getSysUser().getDeptId());
+            labRiskPlanDistribution.setUserId(tokenService.getLoginUser().getSysUser().getUserId());
+            labRiskPlanDistribution.setDistrStatus(1L);
+            labRiskPlanDistribution.setCreateTime(DateUtils.getNowDate());
+            labRiskPlanDistribution.setCreateBy(tokenService.getLoginUser().getSysUser().getNickName());
+            labRiskPlanDistributionMapper.insertLabRiskPlanDistribution(labRiskPlanDistribution);
+        }
+    }
+
+    @NotNull
+    private Set<Long> getConflictRiskplanIds(List<LabRiskPlanSubVo> labRiskPlanSubs) {
+        List<LabRiskPlanSensorRelation> labRiskPlanSensorRelations = labRiskPlanSensorRelationMapper.selectLabRiskPlanSensorRelationByRiskPlanIdId(labRiskPlanSubs.get(0).getRiskPlanId());
         LinkedHashMap<Long, List<LabRiskPlanSensorRelation>> enterRisk = Optional.ofNullable(labRiskPlanSensorRelations).orElseGet(Collections::emptyList).stream().collect(Collectors.groupingBy(LabRiskPlanSensorRelation::getRiskPlanLevelId, LinkedHashMap::new, Collectors.toList()));
         //去除当前预案Id的所有传感器根据预案级别分组
-        List<LabRiskPlanSensorRelation> labRiskPlanSensorRelationsRemove = labRiskPlanSensorRelationMapper.selectList(new LambdaQueryWrapper<LabRiskPlanSensorRelation>().ne(LabRiskPlanSensorRelation::getRiskPlanId, labRiskPlanSubs.get(0).getRiskPlanId()));
+        LabRiskPlanSensorRelation labRiskPlanSensorRelation = new LabRiskPlanSensorRelation();
+        labRiskPlanSensorRelation.setRiskPlanId(labRiskPlanSubs.get(0).getRiskPlanId());
+        List<LabRiskPlanSensorRelation> labRiskPlanSensorRelationsRemove = labRiskPlanSensorRelationMapper.selectLabRiskPlanSensorRelationListNoSelf(labRiskPlanSensorRelation);
         LinkedHashMap<Long, List<LabRiskPlanSensorRelation>> oldRisk = Optional.ofNullable(labRiskPlanSensorRelationsRemove).orElseGet(Collections::emptyList).stream().collect(Collectors.groupingBy(LabRiskPlanSensorRelation::getRiskPlanLevelId, LinkedHashMap::new, Collectors.toList()));
         Set<Long> riskplanIds = new HashSet<>();
         //传入预案传感器信息
@@ -1965,80 +2065,40 @@ public class LabRiskPlanServiceImpl extends ServiceImpl<LabRiskPlanMapper, LabRi
                     }
                 }
             });
-
-//            for (LabRiskPlanSubVo labRiskPlanSub : labRiskPlanSubs) {
-//                List<LabSensorHazardRelation> labSensorHazardRelations = labRiskPlanSub.getLabSensorHazardRelations();
-//                //建立预案和实验室的关联数据
-//                LabRiskPlanjoinsub labRiskPlanjoinsub = new LabRiskPlanjoinsub();
-//                labRiskPlanjoinsub.setSubjectId(labRiskPlanSub.getSubjectId());
-//                labRiskPlanjoinsub.setRiskPlanId(labRiskPlanSub.getRiskPlanId());
-//                labRiskPlanjoinsub.setUserId(tokenService.getLoginUser().getSysUser().getUserId());
-//                labRiskPlanjoinsub.setCreateBy(tokenService.getLoginUser().getSysUser().getNickName());
-//                labRiskPlanjoinsub.setCreateTime(DateUtils.getNowDate());
-//                labRiskPlanjoinsubMapper.insertLabRiskPlanjoinsub(labRiskPlanjoinsub);
-//                for (LabSensorHazardRelation labSensorHazardRelation : labSensorHazardRelations) {
-//                    labSensorHazardRelation.setRiskPlanId(labRiskPlanSub.getRiskPlanId());
-//                    labSensorHazardRelation.setSubjectId(labRiskPlanSub.getSubjectId());
-//                }
-//                labSensorHazardRelationService.saveBatch(labSensorHazardRelations);
-//
-//                //插入分配记录日志信息
-//                LabRiskPlanDistribution labRiskPlanDistribution = new LabRiskPlanDistribution();
-//                labRiskPlanDistribution.setRiskPlanId(labRiskPlanSub.getRiskPlanId());
-//                labRiskPlanDistribution.setSubId(labRiskPlanSub.getSubjectId());
-//                labRiskPlanDistribution.setGroupDeptId(tokenService.getLoginUser().getSysUser().getDeptId());
-//                labRiskPlanDistribution.setUserId(tokenService.getLoginUser().getSysUser().getUserId());
-//                labRiskPlanDistribution.setDistrStatus(1L);
-//                labRiskPlanDistribution.setCreateTime(DateUtils.getNowDate());
-//                labRiskPlanDistribution.setCreateBy(tokenService.getLoginUser().getSysUser().getNickName());
-//                labRiskPlanDistributionMapper.insertLabRiskPlanDistribution(labRiskPlanDistribution);
-//            }
-
-        });
-
-        Long[] objects =(Long[]) riskplanIds.toArray();
-        //根据预案id和实验室id查询当前用户是否有冲突的预案
-        List<LabRiskPlanjoinsubVO> riskPlanjoinsubList = new ArrayList<>();
-        Optional.ofNullable(labRiskPlanSubs).orElseGet(Collections::emptyList).stream().forEach(a -> {
-            LabRiskPlanjoinsubVO labRiskPlanjoinsubVO = new LabRiskPlanjoinsubVO();
-            labRiskPlanjoinsubVO.setSubjectId(a.getSubjectId());
-            for (int i = 0; i < objects.length; i++) {
-                labRiskPlanjoinsubVO.getRiskPlanIds().add(objects[i]);
-            }
-            if (labRiskPlanjoinsubVO.getRiskPlanIds().size() > 0) {
-                riskPlanjoinsubList.addAll(labRiskPlanjoinsubMapper.getLabRiskPlanjoinsubList(labRiskPlanjoinsubVO));
-            }
         });
-        Map<String, Object> resultStr = new HashMap<>();
-        StringBuffer tipsStr = new StringBuffer();
-        if (riskPlanjoinsubList.size() > 0) {
-            Optional.ofNullable(riskPlanjoinsubList).orElseGet(Collections::emptyList).stream().forEach(a -> {
-                tipsStr.append("," + a.getSubName());
-            });
-            resultStr.put("tipsStr", tipsStr.substring(1) + "实验室已经关联了预案,是否绑定到当前预案");
-            resultStr.put("riskPlanjoinsubList", riskPlanjoinsubList);
-            resultStr.put("repeat", true);
-        } else {
-            resultStr.put("tipsStr", "");
-            resultStr.put("riskPlanjoinsubList", "");
-            resultStr.put("repeat", false);
-        }
-        return resultStr;
+        return riskplanIds;
     }
 
     @Override
-    public List<LabBuildFloorLayoutVo> selectTriggerInfo() {
-        List<LabBuildFloorLayoutVo> labBuilder = new ArrayList<>();
+    public List<LabBuildFloorLayoutDTO> selectTriggerInfo() {
+        List<LabBuildFloorLayoutDTO> labBuilder = new ArrayList<>();
         LabRiskPlanAbnormalGroup labRiskPlanAbnormalGroup = new LabRiskPlanAbnormalGroup();
         labRiskPlanAbnormalGroup.setStatus(1L);
-        List <LabRiskPlanAbnormalGroupVO> groupList = labRiskPlanAbnormalGroupMapper.selectLabRiskPlanAbnormalGroupList(labRiskPlanAbnormalGroup);
+        List<LabRiskPlanAbnormalGroupVO> groupList = labRiskPlanAbnormalGroupMapper.selectLabRiskPlanAbnormalGroupList(labRiskPlanAbnormalGroup);
         for (LabRiskPlanAbnormalGroupVO labRiskPlanAbnormalGroupVO : groupList) {
-            LabBuildFloorLayoutVo labBuildFloorLayoutVo  = labBuildFloorLayoutMapper.selectBuildInfoBySubId(labRiskPlanAbnormalGroupVO.getSubjectId());
-            labBuilder.add(labBuildFloorLayoutVo);
+            LabBuildFloorLayoutDTO labBuildFloorLayoutDTO = labBuildFloorLayoutMapper.selectBuildInfoBySubIdAndUser(labRiskPlanAbnormalGroupVO.getSubjectId(), tokenService.getLoginUser().getUserid());
+            if (!Objects.isNull(labBuildFloorLayoutDTO)){
+                labBuildFloorLayoutDTO.setRiskPlanId(labRiskPlanAbnormalGroupVO.getRiskPlanId());
+                labBuilder.add(labBuildFloorLayoutDTO);
+            }
         }
         return labBuilder;
     }
 
+    @Override
+    public Integer checkEnterRiskPlan(Long riskPlanId) {
+        LabRiskPlan labRiskPlan = labRiskPlanMapper.selectLabRiskPlanById(riskPlanId);
+        return labRiskPlan.getIfCheck();
+    }
+
+    @Override
+    public void writerEnterRiskPlan(Long riskPlanId,Integer ifcheck) {
+        LabRiskPlan labRiskPlan = new LabRiskPlan();
+        labRiskPlan.setId(riskPlanId);
+        labRiskPlan.setIfCheck(ifcheck);
+        labRiskPlanMapper.updateById(labRiskPlan);
+    }
+
     public static boolean isListEqual(List l0, List l1) {
         boolean flag = false;
         if (l0 == null && l1 == null) return true;

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

@@ -320,7 +320,7 @@ public class LabSensorServiceImpl implements ILabSensorService {
     }
 
     @Override
-    public List<Long> getSensorTypesBySubId(Long id) {
+    public List<Integer> getSensorTypesBySubId(Long id) {
         return labSensorMapper.getSensorTypesBySubId(id);
     }
 }

+ 20 - 3
zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabBuildFloorLayoutMapper.xml

@@ -58,9 +58,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where id = #{id}
     </select>
 
-    <select id="selectBuildInfoBySubId" resultType="com.zd.laboratory.domain.vo.LabBuildFloorLayoutVo">
-        <include refid="selectLabBuildFloorLayoutListVo"/>
-        where subId = #{subjectId}
+    <select id="selectBuildInfoBySubIdAndUser" resultType="com.zd.laboratory.domain.dto.LabBuildFloorLayoutDTO">
+        SELECT
+            t.build_id,
+            t.floor_id,
+            t.sub_id
+        FROM
+            lab_build_floor_layout AS t
+            LEFT JOIN lab_subject ls on t.sub_id = ls.id
+            where t.sub_id = #{subjectId}
+            and FIND_IN_SET (#{userId},ls.safe_user_id)
+        union
+        SELECT
+            t.build_id,
+            t.floor_id,
+            t.sub_id
+        FROM
+            lab_build_floor_layout AS t
+            LEFT JOIN lab_subject ls on t.sub_id = ls.id
+            where t.sub_id = #{subjectId}
+            and ls.admin_id = (#{userId})
     </select>
 
     <insert id="insertLabBuildFloorLayout" parameterType="com.zd.laboratory.domain.LabBuildFloorLayout" useGeneratedKeys="true" keyProperty="id">

+ 16 - 2
zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabRiskPlanMapper.xml

@@ -22,6 +22,7 @@
         <result property="information" column="information"/>
         <result property="level" column="level"/>
         <result property="evacuation" column="evacuation"/>
+        <result property="ifCheck" column="if_check"/>
     </resultMap>
 
     <resultMap type="com.zd.laboratory.domain.LabRiskPlan" id="LabRiskPlanAndRelationResult">
@@ -43,6 +44,7 @@
         <result property="information" column="information"/>
         <result property="level" column="level"/>
         <result property="evacuation" column="evacuation"/>
+        <result property="ifCheck" column="if_check"/>
         <collection property="riskPlanHardwareList" column="id"
                     ofType="com.zd.laboratory.domain.LabRiskPlanHardwareRelation"
                     select="com.zd.laboratory.mapper.LabRiskPlanHardwareRelationMapper.selectLabRiskPlanHardwareRelationByRiskPlanIdId"/>
@@ -71,7 +73,8 @@
                voicebroadcast,
                information,
                level,
-               evacuation
+               evacuation,
+               if_check
         from lab_risk_plan
     </sql>
 
@@ -144,7 +147,8 @@
                rp.create_by,
                rp.create_time,
                rp.user_id,
-               rp.evacuation
+               rp.evacuation,
+               rp.if_check
         from lab_risk_plan rp
                      INNER JOIN sys_user ur ON rp.user_id = ur.user_id
         <where>
@@ -320,6 +324,9 @@
             <if test="evacuation != null">
                 evacuation,
             </if>
+            <if test="ifCheck != null">
+                if_check,
+            </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">
@@ -373,6 +380,9 @@
             <if test="evacuation != null">
                 #{evacuation},
             </if>
+            <if test="ifCheck != null">
+                #{ifCheck},
+            </if>
         </trim>
     </insert>
 
@@ -427,6 +437,9 @@
             <if test="evacuation != null">
                 evacuation = #{evacuation},
             </if>
+            <if test="ifCheck != null">
+                if_check = #{ifCheck},
+            </if>
         </trim>
         where id = #{id}
     </update>
@@ -536,6 +549,7 @@
                         p.information,
                         p.level,
                         p.evacuation,
+                        p.if_check,
                         (CONCAT(d.dept_class_name, d.`dept_name`, s.`name`)) topName,
                         s.`floor_id`                                         floorId
         FROM lab_risk_plan p

+ 1 - 1
zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabSensorMapper.xml

@@ -304,7 +304,7 @@
         from lab_sensor
         where subject_id = #{id}
     </select>
-    <select id="getSensorTypesBySubId" resultType="java.lang.Long">
+    <select id="getSensorTypesBySubId" resultType="java.lang.Integer">
         select type
         from lab_sensor
         where subject_id = #{id}