Pārlūkot izejas kodu

化学品 新需求 实验室危险指标功能开发

liubo 3 gadi atpakaļ
vecāks
revīzija
e1cd7b21a2

+ 10 - 0
zd-api/zd-api-system/src/main/java/com/zd/system/api/chemical/RemoteChemicalService.java

@@ -5,9 +5,15 @@ import com.zd.common.core.domain.R;
 import com.zd.system.api.factory.RemoteExamFallbackFactory;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
 /**
  * 化学品管理Feign调用接口
  */
@@ -20,4 +26,8 @@ public interface RemoteChemicalService {
     @ApiOperation(value = "修改 化学品设备管理状态")
     @PutMapping("/hxpSmartTerminal/update/status")
     R<Boolean> updateStatus(@RequestParam("ipAddress") String ipAddress,@RequestParam("terminalStatus")Integer terminalStatus);
+
+    @ApiOperation(value = "查询实验室化学品临界量风险指标")
+    @PostMapping("/hxpChemical/queryCriticaliBySubId")
+    R<Map<Long, BigDecimal>> queryCriticaliBySubId(@RequestBody List<Long> subIds);
 }

+ 17 - 2
zd-api/zd-api-system/src/main/java/com/zd/system/api/factory/RemoteChemicalFallbackFactory.java

@@ -1,4 +1,4 @@
-package com.zd.system.api.factory;
+package com.zd.system.api.chemical.factory;
 
 import com.zd.common.core.domain.R;
 import com.zd.system.api.chemical.RemoteChemicalService;
@@ -7,6 +7,10 @@ import org.slf4j.LoggerFactory;
 import org.springframework.cloud.openfeign.FallbackFactory;
 import org.springframework.stereotype.Component;
 
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
 /**
  * 考试服务降级处理
  *
@@ -19,6 +23,17 @@ public class RemoteChemicalFallbackFactory implements FallbackFactory<RemoteChem
     @Override
     public RemoteChemicalService create(Throwable throwable) {
         log.error("化学品管理调用失败:{}", throwable.getMessage());
-        return (ipAddress, terminalStatus) -> R.fail("化学品管理调用失败:" + throwable.getMessage());
+        return new RemoteChemicalService() {
+            @Override
+            public R<Boolean> updateStatus(String ipAddress, Integer terminalStatus) {
+                return R.fail("化学品管理调用失败:" + throwable.getMessage());
+            }
+
+            @Override
+            public R<Map<Long, BigDecimal>> queryCriticaliBySubId(List<Long> subIds) {
+
+                return R.fail("查询实验室化学品临界量风险指标失败:" + throwable.getMessage());
+            }
+        };
     }
 }

+ 23 - 4
zd-modules/zd-chemical/src/main/java/com/zd/chemical/controller/HxpChemicalController.java

@@ -1,16 +1,16 @@
 package com.zd.chemical.controller;
 
+import java.math.BigDecimal;
 import java.time.LocalDate;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 import java.io.IOException;
-import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import javax.servlet.http.HttpServletResponse;
 
+import cn.hutool.core.map.MapUtil;
 import com.zd.chemical.domain.vo.*;
 import com.zd.chemical.service.IHxpChemicalJoinCabinetService;
+import com.zd.common.core.domain.R;
 import com.zd.common.core.domain.per.PerFun;
 import com.zd.common.core.domain.per.PerPrefix;
 import com.zd.common.core.exception.ServiceException;
@@ -247,4 +247,23 @@ public class HxpChemicalController extends BaseController {
         List<HxpChemicalVo> list = hxpChemicalService.selectHxpChemicalList(hxpChemicalSearch);
         return getDataTable(list);
     }
+
+    @ApiOperation(value = "查询实验室化学品临界量风险指标")
+    @PostMapping("/queryCriticaliBySubId")
+    public R<Map<Long, BigDecimal>> queryCriticaliBySubId(@RequestBody List<Long> subIds) {
+        if(subIds.isEmpty()){
+            return R.ok(MapUtil.empty());
+        }
+        return R.ok(hxpChemicalService.queryCriticaliBySubId(subIds));
+    }
+
+
+    @ApiOperation(value = "定时监测实验室化学品存放风险指标")
+    @Log(title = "定时监测实验室化学品存放风险指标", businessType = BusinessType.OTHER)
+    @PostMapping("/indicatorMonitoring")
+    public void indicatorMonitoring() {
+        hxpChemicalService.indicatorMonitoring();
+    }
+
+
 }

+ 12 - 0
zd-modules/zd-chemical/src/main/java/com/zd/chemical/domain/HxpChemical.java

@@ -8,6 +8,8 @@ import io.swagger.annotations.ApiModelProperty;
 import com.zd.common.core.web.domain.BaseEntity;
 import org.hibernate.validator.constraints.Length;
 
+import java.math.BigDecimal;
+
 /**
  * 化学品信息对象 hxp_chemical
  *
@@ -140,6 +142,8 @@ public class HxpChemical extends BaseEntity {
     @ApiModelProperty(value = "关联危险源的id")
     private String anotherNameChar;
 
+    @ApiModelProperty(value = "临界量")
+    private BigDecimal criticality;
 
     public void setId(Long id) {
         this.id = id;
@@ -308,4 +312,12 @@ public class HxpChemical extends BaseEntity {
     public void setAnotherNameChar(String anotherNameChar) {
         this.anotherNameChar = anotherNameChar;
     }
+
+    public BigDecimal getCriticality() {
+        return criticality;
+    }
+
+    public void setCriticality(BigDecimal criticality) {
+        this.criticality = criticality;
+    }
 }

+ 3 - 0
zd-modules/zd-chemical/src/main/java/com/zd/chemical/mapper/HxpChemicalMapper.java

@@ -1,5 +1,6 @@
 package com.zd.chemical.mapper;
 
+import java.math.BigDecimal;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -130,4 +131,6 @@ public interface HxpChemicalMapper
      * @return 化学品信息集合
      */
     public List<LinkedHashMap <String,String>> joinOutCount(HxpStock hxpStock);
+
+    Map<Long, BigDecimal> queryCriticaliBySubId(List<Long> subIds);
 }

+ 5 - 0
zd-modules/zd-chemical/src/main/java/com/zd/chemical/service/IHxpChemicalService.java

@@ -1,5 +1,6 @@
 package com.zd.chemical.service;
 
+import java.math.BigDecimal;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -130,4 +131,8 @@ public interface IHxpChemicalService
      * @return 化学品信息集合
      */
     public List<LinkedHashMap <String,String>> joinOutCount(HxpStock hxpStock);
+
+    Map<Long, BigDecimal> queryCriticaliBySubId(List<Long> subIds);
+
+    void indicatorMonitoring();
 }

+ 46 - 2
zd-modules/zd-chemical/src/main/java/com/zd/chemical/service/impl/HxpChemicalServiceImpl.java

@@ -1,11 +1,14 @@
 package com.zd.chemical.service.impl;
 
+import com.zd.chemical.domain.HxpAlarmRecord;
 import com.zd.chemical.domain.HxpChemical;
 import com.zd.chemical.domain.HxpChemicalClassify;
 import com.zd.chemical.domain.HxpStock;
 import com.zd.chemical.domain.vo.*;
+import com.zd.chemical.mapper.HxpAlarmRecordMapper;
 import com.zd.chemical.mapper.HxpChemicalClassifyMapper;
 import com.zd.chemical.mapper.HxpChemicalMapper;
+import com.zd.chemical.mapper.HxpUserecordMapper;
 import com.zd.chemical.service.IHxpChemicalService;
 import com.zd.common.core.domain.per.PerPrefix;
 import com.zd.common.core.exception.ServiceException;
@@ -28,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.servlet.ServletException;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.atomic.DoubleAdder;
 import java.util.concurrent.atomic.LongAdder;
@@ -43,12 +47,14 @@ import java.util.stream.Collectors;
 public class HxpChemicalServiceImpl implements IHxpChemicalService {
     @Autowired
     private HxpChemicalMapper hxpChemicalMapper;
-
     @Autowired
     private HxpChemicalClassifyMapper hxpChemicalClassifyMapper;
-
     @Autowired
     private IHxpChemicalService hxpChemicalService;
+    @Autowired
+    private HxpUserecordMapper hxpUserecordMapper;
+    @Autowired
+    private HxpAlarmRecordMapper hxpAlarmRecordMapper;
 
     /**
      * 查询化学品信息
@@ -485,4 +491,42 @@ public class HxpChemicalServiceImpl implements IHxpChemicalService {
         List<LinkedHashMap <String,String>> stockCountList = hxpChemicalMapper.joinOutCount(hxpStock);
         return stockCountList;
     }
+
+    @Override
+    public Map<Long, BigDecimal> queryCriticaliBySubId(List<Long> subIds) {
+        return hxpChemicalMapper.queryCriticaliBySubId(subIds);
+    }
+
+    @Override
+    public void indicatorMonitoring() {
+        Map<Long, BigDecimal> map = hxpChemicalMapper.queryCriticaliBySubId(new ArrayList<>());
+        if(!map.isEmpty()){
+
+            map.entrySet().forEach(a -> {
+                if(BigDecimal.valueOf(1L).compareTo(a.getValue()) >= 0){
+
+                    Map<String,Object> subInfo = hxpUserecordMapper.selectSubInfoById(a.getKey());
+                    String safeUserId = "";
+                    if(subInfo != null){
+                        safeUserId = subInfo.get("safeUserId")==null?"":String.valueOf(subInfo.get("safeUserId"));
+                    }
+
+                    HxpAlarmRecord hxpAlarmRecord = new HxpAlarmRecord();
+                    hxpAlarmRecord.setAlarmContent("房间内危化品已定为重大危险源,请确认安全存放量!");
+                    hxpAlarmRecord.setAlarmType(2);
+                    hxpAlarmRecord.setHasValid(1);
+                    hxpAlarmRecord.setAlarmMode(3);
+                    hxpAlarmRecord.setAlarmTime(DateUtils.getNowDate());
+                    hxpAlarmRecord.setSubId(a.getKey());
+                    hxpAlarmRecord.setHandlingStatus(1);
+                    hxpAlarmRecord.setLiableUserIds(safeUserId);
+
+                    hxpAlarmRecordMapper.insertHxpAlarmRecord(hxpAlarmRecord);
+
+                    // TODO 此处需要发送短信通知
+                }
+            });
+
+        }
+    }
 }

+ 208 - 101
zd-modules/zd-chemical/src/main/resources/mapper/chemical/HxpChemicalMapper.xml

@@ -1,65 +1,120 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.zd.chemical.mapper.HxpChemicalMapper">
 
     <resultMap type="com.zd.chemical.domain.HxpChemical" id="HxpChemicalResult">
-        <result property="id"    column="id"    />
-        <result property="chemicalNum"    column="chemical_num"    />
-        <result property="chemicalName"    column="chemical_name"    />
-        <result property="chemicalClassify"    column="chemical_classify"    />
-        <result property="classifyAttribute"    column="classify_attribute"    />
-        <result property="chemicalShape"    column="chemical_shape"    />
-        <result property="labelType"    column="label_type"    />
-        <result property="measuringMethod"    column="measuring_method"    />
-        <result property="chemicalUnit"    column="chemical_unit"    />
-        <result property="verification"    column="verification"    />
-        <result property="anotherName"    column="another_name"    />
-        <result property="casNum"    column="cas_num"    />
-        <result property="factory"    column="factory"    />
-        <result property="purity"    column="purity"    />
-        <result property="collectHour"    column="collect_hour"    />
-        <result property="collectMinute"    column="collect_minute"    />
-        <result property="joinHazardId"    column="join_hazard_id"    />
-        <result property="userId"    column="user_id"    />
-        <result property="createBy"    column="create_by"    />
-        <result property="createTime"    column="create_time"    />
-        <result property="updateBy"    column="update_by"    />
-        <result property="updateTime"    column="update_time"    />
-        <result property="remark"    column="remark"    />
+        <result property="id" column="id"/>
+        <result property="chemicalNum" column="chemical_num"/>
+        <result property="chemicalName" column="chemical_name"/>
+        <result property="chemicalClassify" column="chemical_classify"/>
+        <result property="classifyAttribute" column="classify_attribute"/>
+        <result property="chemicalShape" column="chemical_shape"/>
+        <result property="labelType" column="label_type"/>
+        <result property="measuringMethod" column="measuring_method"/>
+        <result property="chemicalUnit" column="chemical_unit"/>
+        <result property="verification" column="verification"/>
+        <result property="anotherName" column="another_name"/>
+        <result property="casNum" column="cas_num"/>
+        <result property="factory" column="factory"/>
+        <result property="purity" column="purity"/>
+        <result property="collectHour" column="collect_hour"/>
+        <result property="collectMinute" column="collect_minute"/>
+        <result property="joinHazardId" column="join_hazard_id"/>
+        <result property="userId" column="user_id"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="remark" column="remark"/>
+
+        <result property="criticality" column="criticality"/>
     </resultMap>
 
     <sql id="selectHxpChemicalVo">
-        select id, chemical_num, chemical_name, chemical_classify, classify_attribute, chemical_shape, label_type, measuring_method, chemical_unit, verification, another_name, cas_num, factory, purity, collect_hour, collect_minute, user_id, create_by, create_time, update_by, update_time, remark from hxp_chemical
+        select id,
+               chemical_num,
+               chemical_name,
+               chemical_classify,
+               classify_attribute,
+               chemical_shape,
+               label_type,
+               measuring_method,
+               chemical_unit,
+               verification,
+               another_name,
+               cas_num,
+               factory,
+               purity,
+               collect_hour,
+               collect_minute,
+               user_id,
+               create_by,
+               create_time,
+               update_by,
+               update_time,
+               remark,
+               criticality
+        from hxp_chemical
     </sql>
     <sql id="selectHxpChemicalListVo">
-        select t.id, t.chemical_num, t.chemical_name, t.chemical_classify, classify_attribute, t.chemical_shape, t.label_type, t.measuring_method, t.chemical_unit, t.verification, t.another_name, t.cas_num, t.factory, t.purity, t.collect_hour, t.collect_minute, t.user_id, t.create_by, t.create_time, t.update_by, t.update_time, t.remark from hxp_chemical as t
+        select t.id,
+               t.chemical_num,
+               t.chemical_name,
+               t.chemical_classify,
+               classify_attribute,
+               t.chemical_shape,
+               t.label_type,
+               t.measuring_method,
+               t.chemical_unit,
+               t.verification,
+               t.another_name,
+               t.cas_num,
+               t.factory,
+               t.purity,
+               t.collect_hour,
+               t.collect_minute,
+               t.user_id,
+               t.create_by,
+               t.create_time,
+               t.update_by,
+               t.update_time,
+               t.remark,
+               t.criticality
+        from hxp_chemical as t
     </sql>
-    <select id="selectHxpChemicalList" parameterType="com.zd.chemical.domain.vo.HxpChemicalSearch" resultType="com.zd.chemical.domain.vo.HxpChemicalVo">
+    <select id="selectHxpChemicalList" parameterType="com.zd.chemical.domain.vo.HxpChemicalSearch"
+            resultType="com.zd.chemical.domain.vo.HxpChemicalVo">
         select hc.id, hc.chemical_num, hc.chemical_name, hc.chemical_classify,
         (select ccf.classify_name from hxp_chemical_classify ccf where ccf.id = hc.chemical_classify) classifyName,
-        (SELECT GROUP_CONCAT(dda.dict_label) FROM sys_dict_data dda WHERE dda.dict_type = 'hxp_classifyattribute' AND FIND_IN_SET(dda.dict_value, hc.classify_attribute)) classifyAttribute,
-        (SELECT GROUP_CONCAT(CONCAT(dda.dict_label,'(',hc.chemical_unit,')')) FROM sys_dict_data dda WHERE dda.dict_type = 'chemical_shape' AND dda.dict_value = hc.chemical_shape) chemicalShapeInfo,
-        (SELECT GROUP_CONCAT(dda.dict_label) FROM sys_dict_data dda WHERE dda.dict_type = 'chemical_shape' AND dda.dict_value = hc.chemical_shape) chemicalShapeInfo2,
+        (SELECT GROUP_CONCAT(dda.dict_label) FROM sys_dict_data dda WHERE dda.dict_type = 'hxp_classifyattribute' AND
+        FIND_IN_SET(dda.dict_value, hc.classify_attribute)) classifyAttribute,
+        (SELECT GROUP_CONCAT(CONCAT(dda.dict_label,'(',hc.chemical_unit,')')) FROM sys_dict_data dda WHERE dda.dict_type
+        = 'chemical_shape' AND dda.dict_value = hc.chemical_shape) chemicalShapeInfo,
+        (SELECT GROUP_CONCAT(dda.dict_label) FROM sys_dict_data dda WHERE dda.dict_type = 'chemical_shape' AND
+        dda.dict_value = hc.chemical_shape) chemicalShapeInfo2,
         case when hc.label_type=1 then 'RFID' else '二维码' end labelContent, hc.measuring_method, hc.chemical_unit,
-        case when hc.verification=1 then '单人验证' else '双人双卡' end verificationContent, hc.another_name, hc.cas_num, hc.factory, hc.purity, hc.collect_hour, hc.collect_minute, hc.user_id,
+        case when hc.verification=1 then '单人验证' else '双人双卡' end verificationContent, hc.another_name, hc.cas_num,
+        hc.factory, hc.purity, hc.collect_hour, hc.collect_minute, hc.user_id,
         (SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = hc.user_id) create_by, hc.create_time,
         hc.update_by, hc.update_time, hc.remark,
-        CASE WHEN hc.measuring_method = 1 THEN '重量' ELSE CASE WHEN hc.measuring_method = 2 THEN '体积' ELSE '个数' END END measuringMethodContent
+        CASE WHEN hc.measuring_method = 1 THEN '重量' ELSE CASE WHEN hc.measuring_method = 2 THEN '体积' ELSE '个数' END END
+        measuringMethodContent
         from hxp_chemical hc LEFT JOIN sys_user su ON hc.user_id = su.user_id
         <where>
             <if test="searchValue != null  and searchValue != ''">
-             and (hc.chemical_name like concat('%',#{searchValue},'%') or hc.another_name like concat('%',#{searchValue},'%') or hc.cas_num like concat('%',#{searchValue},'%'))
+                and (hc.chemical_name like concat('%',#{searchValue},'%') or hc.another_name like
+                concat('%',#{searchValue},'%') or hc.cas_num like concat('%',#{searchValue},'%'))
             </if>
-            <if test="chemicalClassify != null "> and hc.chemical_classify = #{chemicalClassify}</if>
-            <if test="classifyAttribute != null "> AND FIND_IN_SET(#{classifyAttribute}, hc.classify_attribute)</if>
-            <if test="labelType != null "> and hc.label_type = #{labelType}</if>
+            <if test="chemicalClassify != null ">and hc.chemical_classify = #{chemicalClassify}</if>
+            <if test="classifyAttribute != null ">AND FIND_IN_SET(#{classifyAttribute}, hc.classify_attribute)</if>
+            <if test="labelType != null ">and hc.label_type = #{labelType}</if>
             <if test="ids!=null and ids.size > 0">
                 AND hc.id IN
                 <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
             </if>
-            <if test="casNum != null "> and hc.cas_num = #{casNum}</if>
+            <if test="casNum != null ">and hc.cas_num = #{casNum}</if>
             <!-- 数据范围过滤 -->
             ${params.dataScope}
         </where>
@@ -79,50 +134,51 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
 
-    <insert id="insertHxpChemical" parameterType="com.zd.chemical.domain.HxpChemical" useGeneratedKeys="true" keyProperty="id">
+    <insert id="insertHxpChemical" parameterType="com.zd.chemical.domain.HxpChemical" useGeneratedKeys="true"
+            keyProperty="id">
         insert into hxp_chemical
         <trim prefix="(" suffix=")" suffixOverrides=",">
-    <if test="chemicalNum != null">chemical_num,</if>
+            <if test="chemicalNum != null">chemical_num,</if>
 
-    <if test="chemicalName != null">chemical_name,</if>
+            <if test="chemicalName != null">chemical_name,</if>
 
-    <if test="chemicalClassify != null">chemical_classify,</if>
+            <if test="chemicalClassify != null">chemical_classify,</if>
 
-    <if test="classifyAttribute != null">classify_attribute,</if>
+            <if test="classifyAttribute != null">classify_attribute,</if>
 
-    <if test="chemicalShape != null">chemical_shape,</if>
+            <if test="chemicalShape != null">chemical_shape,</if>
 
-    <if test="labelType != null">label_type,</if>
+            <if test="labelType != null">label_type,</if>
 
-    <if test="measuringMethod != null">measuring_method,</if>
+            <if test="measuringMethod != null">measuring_method,</if>
 
-    <if test="chemicalUnit != null">chemical_unit,</if>
+            <if test="chemicalUnit != null">chemical_unit,</if>
 
-    <if test="verification != null">verification,</if>
+            <if test="verification != null">verification,</if>
 
-    <if test="anotherName != null">another_name,</if>
+            <if test="anotherName != null">another_name,</if>
 
-    <if test="casNum != null">cas_num,</if>
+            <if test="casNum != null">cas_num,</if>
 
-    <if test="factory != null">factory,</if>
+            <if test="factory != null">factory,</if>
 
-    <if test="purity != null">purity,</if>
+            <if test="purity != null">purity,</if>
 
-    <if test="collectHour != null">collect_hour,</if>
+            <if test="collectHour != null">collect_hour,</if>
 
-    <if test="collectMinute != null">collect_minute,</if>
+            <if test="collectMinute != null">collect_minute,</if>
 
-    <if test="userId != null">user_id,</if>
+            <if test="userId != null">user_id,</if>
 
-    <if test="createBy != null">create_by,</if>
+            <if test="createBy != null">create_by,</if>
 
-    <if test="createTime != null">create_time,</if>
+            <if test="createTime != null">create_time,</if>
 
-    <if test="updateBy != null">update_by,</if>
+            <if test="updateBy != null">update_by,</if>
 
-    <if test="updateTime != null">update_time,</if>
+            <if test="updateTime != null">update_time,</if>
 
-    <if test="remark != null">remark,</if>
+            <if test="remark != null">remark,</if>
 
             <if test="chemicalNamePinyin != null">chemical_name_pinyin,</if>
 
@@ -132,29 +188,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
             <if test="anotherNameChar != null">another_name_char,</if>
 
-         </trim>
+            <if test="criticality != null">criticality,</if>
+        </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-    <if test="chemicalNum != null">#{chemicalNum},</if>
-    <if test="chemicalName != null">#{chemicalName},</if>
-    <if test="chemicalClassify != null">#{chemicalClassify},</if>
-    <if test="classifyAttribute != null">#{classifyAttribute},</if>
-    <if test="chemicalShape != null">#{chemicalShape},</if>
-    <if test="labelType != null">#{labelType},</if>
-    <if test="measuringMethod != null">#{measuringMethod},</if>
-    <if test="chemicalUnit != null">#{chemicalUnit},</if>
-    <if test="verification != null">#{verification},</if>
-    <if test="anotherName != null">#{anotherName},</if>
-    <if test="casNum != null">#{casNum},</if>
-    <if test="factory != null">#{factory},</if>
-    <if test="purity != null">#{purity},</if>
-    <if test="collectHour != null">#{collectHour},</if>
-    <if test="collectMinute != null">#{collectMinute},</if>
-    <if test="userId != null">#{userId},</if>
-    <if test="createBy != null">#{createBy},</if>
-    <if test="createTime != null">#{createTime},</if>
-    <if test="updateBy != null">#{updateBy},</if>
-    <if test="updateTime != null">#{updateTime},</if>
-    <if test="remark != null">#{remark},</if>
+            <if test="chemicalNum != null">#{chemicalNum},</if>
+            <if test="chemicalName != null">#{chemicalName},</if>
+            <if test="chemicalClassify != null">#{chemicalClassify},</if>
+            <if test="classifyAttribute != null">#{classifyAttribute},</if>
+            <if test="chemicalShape != null">#{chemicalShape},</if>
+            <if test="labelType != null">#{labelType},</if>
+            <if test="measuringMethod != null">#{measuringMethod},</if>
+            <if test="chemicalUnit != null">#{chemicalUnit},</if>
+            <if test="verification != null">#{verification},</if>
+            <if test="anotherName != null">#{anotherName},</if>
+            <if test="casNum != null">#{casNum},</if>
+            <if test="factory != null">#{factory},</if>
+            <if test="purity != null">#{purity},</if>
+            <if test="collectHour != null">#{collectHour},</if>
+            <if test="collectMinute != null">#{collectMinute},</if>
+            <if test="userId != null">#{userId},</if>
+            <if test="createBy != null">#{createBy},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateBy != null">#{updateBy},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+            <if test="remark != null">#{remark},</if>
             <if test="chemicalNamePinyin != null">#{chemicalNamePinyin},</if>
 
             <if test="chemicalNameChar != null">#{chemicalNameChar},</if>
@@ -162,7 +219,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="anotherNamePinyin != null">#{anotherNamePinyin},</if>
 
             <if test="anotherNameChar != null">#{anotherNameChar},</if>
-         </trim>
+
+            <if test="criticality != null">#{criticality},</if>
+        </trim>
     </insert>
 
     <update id="updateHxpChemical" parameterType="com.zd.chemical.domain.HxpChemical">
@@ -196,18 +255,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="anotherNamePinyin != null">another_name_pinyin = #{anotherNamePinyin},</if>
             <if test="anotherNameChar != null">another_name_char = #{anotherNameChar},</if>
 
+            <if test="criticality != null">criticality = #{criticality},</if>
+
         </trim>
         where id = #{id}
     </update>
 
     <update id="clearHxpChemicalByJoinHazard" parameterType="com.zd.chemical.domain.HxpChemical">
-        update hxp_chemical set
-        join_hazard_id = NULL
+        update hxp_chemical
+        set join_hazard_id = NULL
         where id = #{id}
     </update>
 
     <delete id="deleteHxpChemicalById" parameterType="Long">
-        delete from hxp_chemical where id = #{id}
+        delete
+        from hxp_chemical
+        where id = #{id}
     </delete>
 
     <delete id="deleteHxpChemicalByIds" parameterType="String">
@@ -218,7 +281,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
 
-    <select id="chemicalUsageCount" parameterType="com.zd.chemical.domain.HxpChemical" resultType="com.zd.chemical.domain.vo.HxpHomeChemicalVo">
+    <select id="chemicalUsageCount" parameterType="com.zd.chemical.domain.HxpChemical"
+            resultType="com.zd.chemical.domain.vo.HxpHomeChemicalVo">
         SELECT
         (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk
         LEFT JOIN sys_user ur ON sk.user_id = ur.user_id WHERE sk.status=1
@@ -241,7 +305,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ${params.dataScope}
         ) chemicalCancelNum,
         (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk INNER JOIN hxp_chemical_join_cabinet cjc ON sk.join_id = cjc.id
-        LEFT JOIN sys_user ur ON sk.user_id = ur.user_id WHERE  DATE_SUB(cjc.expire_time, INTERVAL 3 DAY)&lt;=NOW()
+        LEFT JOIN sys_user ur ON sk.user_id = ur.user_id WHERE DATE_SUB(cjc.expire_time, INTERVAL 3 DAY)&lt;=NOW()
         AND cjc.expire_time>NOW()
         <!-- 数据范围过滤 -->
         ${params.dataScope}
@@ -249,7 +313,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM DUAL
     </select>
 
-    <select id="chemicalUnusualCount" parameterType="com.zd.chemical.domain.HxpChemical" resultType="com.zd.chemical.domain.vo.HxpHomeChemicalUnusualVo">
+    <select id="chemicalUnusualCount" parameterType="com.zd.chemical.domain.HxpChemical"
+            resultType="com.zd.chemical.domain.vo.HxpHomeChemicalUnusualVo">
         SELECT
         (SELECT IFNULL(COUNT(1),0) FROM hxp_userecord rd
         LEFT JOIN sys_user ur ON rd.user_id = ur.user_id WHERE rd.use_status = 1
@@ -262,31 +327,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ${params.dataScope}
         ) overtimeReturn,
         (SELECT IFNULL(COUNT(1),0) FROM hxp_userecord rd
-        LEFT JOIN sys_user ur ON rd.user_id = ur.user_id WHERE DATE_FORMAT(rd.collect_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')
+        LEFT JOIN sys_user ur ON rd.user_id = ur.user_id WHERE DATE_FORMAT(rd.collect_time,'%Y-%m-%d') =
+        DATE_FORMAT(NOW(),'%Y-%m-%d')
         <!-- 数据范围过滤 -->
         ${params.dataScope}
         ) todayCollect,
         (SELECT IFNULL(COUNT(1),0) FROM hxp_userecord rd
-        LEFT JOIN sys_user ur ON rd.user_id = ur.user_id WHERE rd.use_status = 0 AND DATE_FORMAT(rd.collect_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')
+        LEFT JOIN sys_user ur ON rd.user_id = ur.user_id WHERE rd.use_status = 0 AND
+        DATE_FORMAT(rd.collect_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')
         <!-- 数据范围过滤 -->
         ${params.dataScope}
         ) todayReturn,
         (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk
-        LEFT JOIN sys_user ur ON sk.user_id = ur.user_id WHERE sk.status=2 AND DATE_FORMAT(sk.out_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')
+        LEFT JOIN sys_user ur ON sk.user_id = ur.user_id WHERE sk.status=2 AND DATE_FORMAT(sk.out_time,'%Y-%m-%d') =
+        DATE_FORMAT(NOW(),'%Y-%m-%d')
         <!-- 数据范围过滤 -->
         ${params.dataScope}
         ) todayOutNum,
         (SELECT IFNULL(COUNT(1),0) FROM hxp_stock sk
-        LEFT JOIN sys_user ur ON sk.user_id = ur.user_id WHERE sk.status=3 AND DATE_FORMAT(sk.out_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')
+        LEFT JOIN sys_user ur ON sk.user_id = ur.user_id WHERE sk.status=3 AND DATE_FORMAT(sk.out_time,'%Y-%m-%d') =
+        DATE_FORMAT(NOW(),'%Y-%m-%d')
         <!-- 数据范围过滤 -->
         ${params.dataScope}
         ) todayCancelNum
         FROM DUAL
     </select>
 
-    <select id="chemicalUsagesCount" parameterType="com.zd.chemical.domain.HxpChemical" resultType="com.zd.chemical.domain.vo.HxpHomeChemicalUsagesVo">
-        SELECT CONCAT(cl.`chemical_name`,'使用重量',CONCAT(SUM(sk.usages-sk.out_usages),cl.chemical_unit)) chemicalUsages, SUM(sk.usages-sk.out_usages)usages,
-        (SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = cl.user_id)  adminUser,
+    <select id="chemicalUsagesCount" parameterType="com.zd.chemical.domain.HxpChemical"
+            resultType="com.zd.chemical.domain.vo.HxpHomeChemicalUsagesVo">
+        SELECT CONCAT(cl.`chemical_name`,'使用重量',CONCAT(SUM(sk.usages-sk.out_usages),cl.chemical_unit)) chemicalUsages,
+        SUM(sk.usages-sk.out_usages)usages,
+        (SELECT ur.nick_name FROM sys_user ur WHERE ur.user_id = cl.user_id) adminUser,
         (SELECT cc.classify_name FROM hxp_chemical_classify cc WHERE cc.id = cl.chemical_classify) classifyName,
         (SELECT cc.hazard_level FROM hxp_chemical_classify cc WHERE cc.id = cl.chemical_classify) classifyLevel
         FROM hxp_stock sk
@@ -300,8 +371,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         GROUP BY cl.`id` ORDER BY usages DESC LIMIT 6
     </select>
 
-    <select id="chemicalClassifyMix" parameterType="com.zd.chemical.domain.HxpChemical" resultType="java.util.LinkedHashMap">
-        SELECT x1.dict_label classifyAttribute,CONCAT(CASE WHEN x2.chemical_name IS NULL THEN 0 ELSE COUNT(0) END,'') chemicalMix FROM (
+    <select id="chemicalClassifyMix" parameterType="com.zd.chemical.domain.HxpChemical"
+            resultType="java.util.LinkedHashMap">
+        SELECT x1.dict_label classifyAttribute,CONCAT(CASE WHEN x2.chemical_name IS NULL THEN 0 ELSE COUNT(0) END,'')
+        chemicalMix FROM (
         select xx1.* from(SELECT dda.`dict_label`,dda.dict_value
         FROM sys_dict_data dda
         WHERE dda.dict_type = 'hxp_classifyattribute'
@@ -312,7 +385,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         )x1
         LEFT JOIN
         (
-        select xx.chemical_name,case when xx.classify_attribute='' or xx.classify_attribute is null then 99 else xx.classify_attribute end classify_attribute from (
+        select xx.chemical_name,case when xx.classify_attribute='' or xx.classify_attribute is null then 99 else
+        xx.classify_attribute end classify_attribute from (
         SELECT cl.chemical_name,cl.classify_attribute
         FROM hxp_stock sk
         INNER JOIN hxp_chemical_join_cabinet cjc ON sk.join_id= cjc.id
@@ -355,14 +429,47 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         SELECT DATE_FORMAT(NOW(),'%Y-%m-%d') FROM DUAL
         )x1 LEFT JOIN hxp_stock sk
         <if test="status == 1">
-            ON DATE_FORMAT(x1.nowData,'%Y-%m-%d') = DATE_FORMAT(sk.join_time,'%Y-%m-%d') AND (sk.status=#{status} or sk.status=4)
+            ON DATE_FORMAT(x1.nowData,'%Y-%m-%d') = DATE_FORMAT(sk.join_time,'%Y-%m-%d') AND (sk.status=#{status} or
+            sk.status=4)
         </if>
         <if test="status == 2">
-            ON DATE_FORMAT(x1.nowData,'%Y-%m-%d') = DATE_FORMAT(sk.out_time,'%Y-%m-%d') AND (sk.status=#{status}  or sk.status=3)
+            ON DATE_FORMAT(x1.nowData,'%Y-%m-%d') = DATE_FORMAT(sk.out_time,'%Y-%m-%d') AND (sk.status=#{status} or
+            sk.status=3)
         </if>
         LEFT JOIN sys_user ur ON sk.user_id = ur.user_id
         <!-- 数据范围过滤 -->
         ${params.dataScope}
         GROUP BY x1.nowData
     </select>
+
+    <select id="queryCriticaliBySubId" resultType="java.util.Map">
+        select
+            t.subId,
+            cast((sum(t.critica)) as decimal(5,2)) as criticali
+        from (
+            select
+                s.subId,
+                ifnull((sum(s.suttle)/1000/1000/s.criticality), 0) as critica
+            from (
+                select
+                jo.sub_id as subId,
+                jo.chemical_id as chemicalId,
+                ifnull(che.criticality, 0) as criticality,
+                (s.usages - s.tare) as suttle
+                from hxp_stock s left join hxp_chemical_join_cabinet jo on s.join_id = jo.id
+                left join hxp_chemical che on jo.chemical_id = che.id
+                <where>
+                    s.status != 2 and s.status != 3
+                    <if test="subIds != null and subIds.size > 0">
+                        and jo.sub_id in
+                        <foreach item="id" collection="list" open="(" separator="," close=")">
+                            #{id}
+                        </foreach>
+                    </if>
+                </where>
+            ) s
+            group by s.subId
+        ) t
+
+    </select>
 </mapper>

+ 5 - 3
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/device/DeviceRemoteController.java

@@ -57,14 +57,16 @@ public class DeviceRemoteController {
 
             Thread.sleep(100);
             Integer status = redisService.getCacheObject(relayCode + ":" + cabinetV2Lock.getLockId());
-            if(status != null && status == 1){
+            /*if(status != null && status == 1){
                 return R.ok();
-            }
+            }*/
+            // TODO 因样件锁 发送开锁指令后锁未主动弹开,先不关注锁的状态
+            return R.ok();
         } catch (Exception e) {
             e.printStackTrace();
             return R.fail("柜锁连接失败!");
         }
-        return R.fail();
+//        return R.fail();
     }
 
     /**

+ 35 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/vo/LabSubjectVO.java

@@ -7,6 +7,7 @@ import com.zd.laboratory.interfaces.SysProperties;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -19,12 +20,18 @@ import java.util.List;
 @ApiModel("实验室管理类")
 public class LabSubjectVO extends LabSubject {
 
-    @ApiModelProperty("楼名称")
+    @ApiModelProperty("楼名称")
     private String buildName;
 
     @ApiModelProperty("楼栋名称")
     private String building;
 
+    @ApiModelProperty(value = "楼层名称")
+    private String floorName;
+
+    @ApiModelProperty(value = "房间名称")
+    private String roomName;
+
     @ApiModelProperty("实验室学科")
     private String subDept;
 
@@ -91,6 +98,9 @@ public class LabSubjectVO extends LabSubject {
 
     private String adminNameAndPhone;
 
+    @ApiModelProperty(value = "化学品临界值危险指标")
+    private BigDecimal riskIndicator;
+
     public LabSubjectVO() {
     }
 
@@ -300,4 +310,28 @@ public class LabSubjectVO extends LabSubject {
     public void setSafeUserNameAdminPhone(String safeUserNameAdminPhone) {
         this.safeUserNameAdminPhone = safeUserNameAdminPhone;
     }
+
+    public BigDecimal getRiskIndicator() {
+        return riskIndicator;
+    }
+
+    public void setRiskIndicator(BigDecimal riskIndicator) {
+        this.riskIndicator = riskIndicator;
+    }
+
+    public String getFloorName() {
+        return floorName;
+    }
+
+    public void setFloorName(String floorName) {
+        this.floorName = floorName;
+    }
+
+    public String getRoomName() {
+        return roomName;
+    }
+
+    public void setRoomName(String roomName) {
+        this.roomName = roomName;
+    }
 }

+ 24 - 4
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabSubjectManagerService.java

@@ -4,10 +4,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONObject;
-import com.zd.common.core.constant.CacheConstants;
-import com.zd.common.core.constant.CacheDevice;
-import com.zd.common.core.constant.Constants;
-import com.zd.common.core.constant.SecurityConstants;
+import com.zd.common.core.constant.*;
 import com.zd.common.core.domain.R;
 import com.zd.common.core.enums.HardwareOperate;
 import com.zd.common.core.enums.HardwareTypeEnum;
@@ -36,6 +33,7 @@ import com.zd.laboratory.socket.vo.TransmissionVo;
 import com.zd.laboratory.utils.FunctionMapperUtil;
 import com.zd.system.api.RemoteUserService;
 import com.zd.system.api.chemical.RemoteChemicalAlarmService;
+import com.zd.system.api.chemical.RemoteChemicalService;
 import com.zd.system.api.domain.SubQueryConfig;
 import com.zd.system.api.domain.SysDictData;
 import com.zd.system.api.domain.SysUser;
@@ -53,6 +51,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
@@ -103,6 +102,8 @@ public class LabSubjectManagerService {
 
     @Autowired
     RemoteChemicalAlarmService remoteChemicalAlarmService;
+    @Autowired
+    private RemoteChemicalService remoteChemicalService;
 
     private Map<Control.CommTypeEnums, ControlService> controlServiceMap = new HashMap<>();
 
@@ -493,6 +494,7 @@ public class LabSubjectManagerService {
         //1.获取权限的分页数据
         PageHelperUtil.startPage();
         List<LabSubjectVO> labSubjects = subjectService.selectLabSubjectListAUTH(subject);
+        List<Long> subIds = new ArrayList<>();
         labSubjects.forEach( a -> {
             // 危险源
             List<LabHazardSubVO> hazards = labHazardSubjectRelationService.queryHazardSubListVO(a.getId());
@@ -505,7 +507,25 @@ public class LabSubjectManagerService {
                 hazardList.add(hazardSubVO);
             });
             a.setLabHazardList(hazardList);
+
+            a.setSafeUserName(labSubjectMapper.queryUserNameBySafeUserId(a.getSafeUserId()));
+
+            subIds.add(a.getId());
+
+
         });
+        // 实验室化学品临界量计算
+        R r = remoteChemicalService.queryCriticaliBySubId(subIds);
+        if(r.getCode() == HttpStatus.SUCCESS){
+            Map<Long, BigDecimal> map = (Map<Long, BigDecimal>) r.getData();
+            map.entrySet().forEach(a -> {
+                labSubjects.forEach(s -> {
+                    if(Objects.equals(s.getId(), a.getKey())){
+                        s.setRiskIndicator(a.getValue());
+                    }
+                });
+            });
+        }
 
 
         // 2.5 页面改变,接口加分页,并拆成两部分

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

@@ -162,7 +162,12 @@
                t.check_count,
                t.sign_time,
                t.mold_id,
-               CONCAT(su.nick_name,'@',su.phonenumber) AS adminNameAndPhone
+               CONCAT(su.nick_name,'@',su.phonenumber) AS adminNameAndPhone,
+
+               (select d.dept_name from sys_dept d where t.build_id = d.dept_id) buildName,
+               (select b.name from lab_building b where b.id = t.floor_id) floorName,
+               (SELECT l.room FROM lab_subject_layout l WHERE l.id = t.layout_id ) roomName
+
         from lab_subject t
         left  join  sys_user su on su.user_id = t.admin_id  AND su.`del_flag`=0
         left  join  sys_dept sd on sd.dept_id = t.dept_id