Browse Source

报警修改

wangli 4 years ago
parent
commit
631cedbca8

+ 27 - 1
sms_water/src/main/java/com/huaxu/common/CalcUtil.java

@@ -1,8 +1,11 @@
 package com.huaxu.common;
 
+import cn.hutool.crypto.asymmetric.Sign;
+
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
+import java.math.BigDecimal;
 
 /**
  * @description
@@ -25,7 +28,30 @@ public class CalcUtil {
         return String.valueOf(scriptEngine.eval(expression));
     }
 
+    /**
+     * 根据比较符号返回结果 ( >、≥、<、≤、=、≠ )
+     * 比较规则  param1  (sign)  param2
+     * 参数为 null 则默认为 0,符号不存在或为空则返回 false
+     * @param param1
+     * @param param2
+     * @return
+     */
+    public static Boolean compareBySign(Double param1 , Double param2 , String sign){
+           int result = new BigDecimal( param1 != null?param1 :0 ).compareTo(new BigDecimal(param2 != null?param2 :0 ));
+        switch (sign){
+            case ">": return result == 1;
+            case "≥": return result != -1;
+            case "<": return result == -1;
+            case "≤": return result != 1;
+            case "=": return result == 0;
+            case "≠": return result != 0;
+        }
+        return false;
+    }
+
     public static void main(String[] args) throws ScriptException{
-       System.out.println( Boolean.valueOf(CalcUtil.executeExpression("1>2")));
+       System.out.println( CalcUtil.compareBySign(null ,2.0,">"));
     }
+
+
 }

+ 3 - 2
sms_water/src/main/java/com/huaxu/dto/AlarmDetailsDto.java

@@ -7,6 +7,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 
@@ -30,9 +31,9 @@ public class AlarmDetailsDto extends AlarmDetailsEntity {
     @ApiModelProperty("地址")
     private String address;
     @ApiModelProperty("经度")
-    private Double pointX;
+    private BigDecimal pointX;
     @ApiModelProperty("维度")
-    private Double pointY;
+    private BigDecimal pointY;
     @ApiModelProperty("持续时间,单位分钟")
     private Integer duration;
 

+ 6 - 5
sms_water/src/main/java/com/huaxu/dto/AlarmDetailsHistoryDto.java

@@ -8,6 +8,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.util.Date;
 
 /**
@@ -41,10 +42,10 @@ public class AlarmDetailsHistoryDto implements Serializable {
     private String alermRule;
     @ApiModelProperty(value = "最大告警数值")
     @ExcelProperty(value = "最高值",index =6)
-    private Double maxValue;
+    private String maxValue;
     @ApiModelProperty(value = "最小告警数值")
     @ExcelProperty(value = "最低值",index =7)
-    private Double minValue;
+    private String minValue;
     @ApiModelProperty("地址")
     @ExcelProperty(value = "地址",index =8)
     private String address;
@@ -58,14 +59,14 @@ public class AlarmDetailsHistoryDto implements Serializable {
     private Date alarmEndTime;
     @ApiModelProperty("持续时间,单位分钟")
     @ExcelProperty(value = "持续时间(分钟)",index =11)
-    private Integer duration;
+    private String duration;
 
     @ExcelIgnore
     @ApiModelProperty("经度")
-    private Double pointX;
+    private BigDecimal pointX;
     @ExcelIgnore
     @ApiModelProperty("维度")
-    private Double pointY;
+    private BigDecimal pointY;
     @ExcelIgnore
     @ApiModelProperty(value = "报警状态")
     private Integer state;

+ 4 - 3
sms_water/src/main/java/com/huaxu/dto/AlarmDetailsRealTimeDto.java

@@ -8,6 +8,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.util.Date;
 
 /**
@@ -41,7 +42,7 @@ public class AlarmDetailsRealTimeDto implements Serializable {
     private String attributeName;
     @ApiModelProperty(value = "当前数值")
     @ExcelProperty(value = "当前数值",index = 5)
-    private Double alarmValue;
+    private String alarmValue;
     @ApiModelProperty(value = "报警详情")
     @ExcelProperty(value = "报警详情",index = 6)
     private String alarmContent;
@@ -55,10 +56,10 @@ public class AlarmDetailsRealTimeDto implements Serializable {
 
     @ExcelIgnore
     @ApiModelProperty("经度")
-    private Double pointX;
+    private BigDecimal pointX;
     @ExcelIgnore
     @ApiModelProperty("维度")
-    private Double pointY;
+    private BigDecimal pointY;
     @ExcelIgnore
     @ApiModelProperty(value = "报警状态")
     private Integer state;

+ 7 - 16
sms_water/src/main/java/com/huaxu/dto/DeviceCheckAlarmDto.java

@@ -26,6 +26,7 @@ public class DeviceCheckAlarmDto {
     private Integer attributeId;//
     private Date lastUpdateTime;//
 
+    private Integer alarmSettingId;//报警设置id
     private Double duration;//离线时间
     private String alarmCondition;//报警规则(符号)
     private Double alarmValue;//报警值
@@ -35,33 +36,23 @@ public class DeviceCheckAlarmDto {
     private String attributeName; //属性名称
     private String unit; //属性单位
 
+    // 识别符号 >、≥、<、≤、=、≠
     public Boolean checkdeviceOffLine(){
         if(this.duration != null && this.alarmValue != null
               &&  StringUtils.isNotBlank(this.alarmCondition)){
-            String expression =this.duration+this.alarmCondition+this.alarmValue;
-           try{
-               return Boolean.valueOf(CalcUtil.executeExpression(expression));
-           }catch (ScriptException e){
-               log.info("判断设备是否在线表示式异常:表达式{} ,异常信息:{}",expression,e.getStackTrace());
-           }
+               return CalcUtil.compareBySign(this.duration,this.alarmValue,this.alarmCondition);
         }
         return false;
     }
-    public Boolean checkdeviceAttributeAlarm(String value){
-        if(StringUtils.isNotBlank(value) && alarmValue != null
+    public Boolean checkdeviceAttributeAlarm(Double value){
+        if( value != null && alarmValue != null
                 &&  StringUtils.isNotBlank(this.alarmCondition)){
-            String expression =value+this.alarmCondition+this.alarmValue;
-            try{
-                return Boolean.valueOf(CalcUtil.executeExpression(expression));
-
-            }catch (ScriptException e){
-                log.info("判断设备是否报警表示式异常:表达式{} ,异常信息:{}",expression,e.getStackTrace());
-            }
+                return CalcUtil.compareBySign(this.duration,this.alarmValue,this.alarmCondition);
         }
         return false;
     }
 
-    public String getAlarminfo(String receivedValue){
+    public String getAlarminfo(Double receivedValue){
       return  new StringBuilder().append(this.deviceName)
                 .append(this.attributeName)
                 .append(receivedValue)

+ 4 - 3
sms_water/src/main/java/com/huaxu/entity/AlarmDetailsEntity.java

@@ -32,6 +32,10 @@ public class AlarmDetailsEntity implements Serializable {
     @ApiModelProperty(value = "所属部门")
     private Integer deptOrgId;
 
+    @ApiModelProperty(value = "报警参数设置id")
+    private Integer alarmSettingId;
+
+
     @ApiModelProperty(value = "报警类型")
     private String alarmType;
     @ApiModelProperty(value = "报警参数ID")
@@ -70,7 +74,4 @@ public class AlarmDetailsEntity implements Serializable {
     @ApiModelProperty(value = "更新人")
     private String updateBy;
 
-    public String getMapKey(){
-        return deviceId+"_"+attributeId;
-    }
 }

+ 3 - 2
sms_water/src/main/java/com/huaxu/entity/DeviceEntity.java

@@ -7,6 +7,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.util.Date;
 
 
@@ -41,9 +42,9 @@ public class DeviceEntity implements Serializable {
     @ApiModelProperty(value = "所属场景")
     private Integer sceneId;
     @ApiModelProperty(value = "经度")
-    private Double pointX;
+    private BigDecimal pointX;
     @ApiModelProperty(value = "纬度")
-    private Double pointY;
+    private BigDecimal pointY;
     @ApiModelProperty(value = "设备状态")
     private Integer enableState;
     @ApiModelProperty(value = "最后上报时间")

+ 3 - 2
sms_water/src/main/java/com/huaxu/entity/SceneEntity.java

@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 
@@ -88,11 +89,11 @@ public class SceneEntity implements Serializable {
 
     /** 经度 */
     @ApiModelProperty(value = "经度")
-    private Double pointX;
+    private BigDecimal pointX;
 
     /** 纬度 */
     @ApiModelProperty(value = "纬度")
-    private Double pointY;
+    private BigDecimal pointY;
 
     /** 数据删除标记 */
     @TableLogic

+ 17 - 12
sms_water/src/main/java/com/huaxu/rabbitmq/ReceiveData.java

@@ -7,6 +7,7 @@ package com.huaxu.rabbitmq;
  */
 
 import com.alibaba.fastjson.JSONObject;
+import com.huaxu.common.CalcUtil;
 import com.huaxu.common.StringUtils;
 import com.huaxu.dao.AlarmDetailMapper;
 import com.huaxu.dto.AlarmDetailsDto;
@@ -97,8 +98,8 @@ public class ReceiveData {
                    Integer deviceId= deviceCheckAlarmDtos.get(0).getDeviceId();
                    //系统中已存在的报警信息
                    List<AlarmDetailsDto> alarmDetailsDtos = alarmDetailMapper.selectStateAlarm(deviceId,"参数报警");
-                   //已存在的报警信息转为map方便匹配
-                   Map<String,AlarmDetailsDto> alarmDetailsDtoMap = alarmDetailsDtos.stream().collect(Collectors.toMap(AlarmDetailsDto::getMapKey, a -> a,(k1, k2)->k1));
+                   //已存在的报警信息转为map方便匹配alarmSettingId
+                   Map<Integer,AlarmDetailsDto> alarmDetailsDtoMap = alarmDetailsDtos.stream().collect(Collectors.toMap(AlarmDetailsDto::getAlarmSettingId, a -> a,(k1, k2)->k1));
 
                    List<AlarmDetailsEntity> insert =new ArrayList<>();
                    List<AlarmDetailsDto> update =new ArrayList<>();
@@ -107,19 +108,21 @@ public class ReceiveData {
                    //校验各参数异常情况
                    for(DeviceCheckAlarmDto deviceCheckAlarmDto:deviceCheckAlarmDtos){
                        //获取参数接收值
-                       String receivedValue = receiveData.getString(deviceCheckAlarmDto.getIdentifiter());
+                       Double receivedValue = receiveData.getDouble(deviceCheckAlarmDto.getIdentifiter());
+
                        if(deviceCheckAlarmDto.checkdeviceAttributeAlarm(receivedValue)){
                           //判断报警是否已存在
-                           if(alarmDetailsDtoMap.containsKey(deviceCheckAlarmDto.getDeviceId()+"_"+deviceCheckAlarmDto.getAttributeId())){
-                               AlarmDetailsDto alarmDetailsDto = alarmDetailsDtoMap.get(deviceCheckAlarmDto.getDeviceId()+"_"+deviceCheckAlarmDto.getAttributeId());
-                               alarmDetailsDto.setAlarmValue(Double.valueOf(receivedValue));
+                           if(alarmDetailsDtoMap.containsKey(deviceCheckAlarmDto.getAlarmSettingId())){
+                               AlarmDetailsDto alarmDetailsDto = alarmDetailsDtoMap.get(deviceCheckAlarmDto.getAlarmSettingId());
+                               alarmDetailsDto.setAlarmValue(receivedValue);
                                alarmDetailsDto.setAlarmContent(deviceCheckAlarmDto.getAlarminfo(receivedValue));
-                               alarmDetailsDto.setMinValue(alarmDetailsDto.getMinValue()<Double.valueOf(receivedValue)?alarmDetailsDto.getMinValue():Double.valueOf(receivedValue));
-                               alarmDetailsDto.setMaxValue(alarmDetailsDto.getMaxValue()>Double.valueOf(receivedValue)?alarmDetailsDto.getMaxValue():Double.valueOf(receivedValue));
+                               alarmDetailsDto.setMinValue(CalcUtil.compareBySign(alarmDetailsDto.getMinValue(),receivedValue, "<")?alarmDetailsDto.getMinValue():receivedValue);
+                               alarmDetailsDto.setMaxValue(CalcUtil.compareBySign(alarmDetailsDto.getMaxValue(),receivedValue,">")?alarmDetailsDto.getMaxValue():receivedValue);
 //                                   update.add(alarmDetailsDto);
+                               alarmDetailsDto.setDateUpdate( new Date());
                                alarmDetailMapper.update(alarmDetailsDto);
                                //已存在的修改后从集合移除
-                               alarmDetailsDtoMap.remove(deviceCheckAlarmDto.getDeviceId()+"_"+deviceCheckAlarmDto.getAttributeId());
+                               alarmDetailsDtoMap.remove(deviceCheckAlarmDto.getAlarmSettingId());
                            }else{
                                AlarmDetailsEntity alarmDetailsEntity = new AlarmDetailsDto();
                                alarmDetailsEntity.setTenantId(deviceCheckAlarmDto.getTenantId());
@@ -128,13 +131,14 @@ public class ReceiveData {
                                alarmDetailsEntity.setDeptOrgId(deviceCheckAlarmDto.getDeptOrgId());
                                alarmDetailsEntity.setAlarmType(deviceCheckAlarmDto.getAlarmType());
                                alarmDetailsEntity.setAttributeId(deviceCheckAlarmDto.getAttributeId());
-                               alarmDetailsEntity.setAlarmValue(Double.valueOf(receivedValue));
+                               alarmDetailsEntity.setAlarmValue(receivedValue);
                                alarmDetailsEntity.setAlarmStartTime(receiveDateTime);
                                alarmDetailsEntity.setAlarmContent(deviceCheckAlarmDto.getAlarminfo(receivedValue));
+                               alarmDetailsEntity.setAlarmSettingId(deviceCheckAlarmDto.getAlarmSettingId());
                                alarmDetailsEntity.setState(1);
                                alarmDetailsEntity.setOpState(1);
-                               alarmDetailsEntity.setMinValue(Double.valueOf(receivedValue));
-                               alarmDetailsEntity.setMaxValue(Double.valueOf(receivedValue));
+                               alarmDetailsEntity.setMinValue(receivedValue);
+                               alarmDetailsEntity.setMaxValue(receivedValue);
                                alarmDetailsEntity.setStatus(1);
                                alarmDetailsEntity.setDateCreate(new Date());
                                alarmDetailsEntity.setDateUpdate(new Date());
@@ -147,6 +151,7 @@ public class ReceiveData {
                        for(AlarmDetailsDto alarmDetailsDto:alarmDetailsDtoMap.values()){
                            alarmDetailsDto.setState(0);
                            alarmDetailsDto.setAlarmEndTime(receiveDateTime);
+                           alarmDetailsDto.setDateUpdate(new Date());
                            alarmDetailMapper.update(alarmDetailsDto);
                        }
                        //批量插入新增报警

+ 6 - 5
sms_water/src/main/java/com/huaxu/service/impl/AlarmDetailsServiceImpl.java

@@ -146,10 +146,10 @@ public class AlarmDetailsServiceImpl implements AlarmDetailsService {
         //系统中已存在的离线报警
         List<AlarmDetailsDto> alarmDetailsDtos = alarmDetailMapper.selectStateAlarm(null,"状态报警");
         //已存在的报警信息转为map方便匹配
-        Map<Integer,AlarmDetailsDto> alarmDetailsDtoMap = alarmDetailsDtos.stream().collect(Collectors.toMap(AlarmDetailsDto::getDeviceId, a -> a,(k1, k2)->k1));
+        Map<Integer,AlarmDetailsDto> alarmDetailsDtoMap = alarmDetailsDtos.stream().collect(Collectors.toMap(AlarmDetailsDto::getAlarmSettingId, a -> a,(k1, k2)->k1));
         //需要新增的
         List<AlarmDetailsEntity>  deviceStateAlarmDtoNews =alarmlist.stream()
-                .filter(deviceCheckAlarmDto -> !alarmDetailsDtoMap.containsKey(deviceCheckAlarmDto.getDeviceId()))
+                .filter(deviceCheckAlarmDto -> !alarmDetailsDtoMap.containsKey(deviceCheckAlarmDto.getAlarmSettingId()))
                 .map(d ->{
                     AlarmDetailsEntity alarmDetailsEntity = new AlarmDetailsEntity();
                     alarmDetailsEntity.setDateUpdate(new Date());
@@ -166,6 +166,7 @@ public class AlarmDetailsServiceImpl implements AlarmDetailsService {
                     alarmDetailsEntity.setCompanyOrgId(d.getCompanyOrgId());
                     alarmDetailsEntity.setDeviceId(d.getDeviceId());
                     alarmDetailsEntity.setTenantId(d.getTenantId());
+                    alarmDetailsEntity.setAlarmSettingId(d.getAlarmSettingId());
                     return alarmDetailsEntity;
                 })
                 .collect(Collectors.toList());
@@ -175,14 +176,14 @@ public class AlarmDetailsServiceImpl implements AlarmDetailsService {
 
         //需要更新的
         List<AlarmDetailsEntity>  DeviceStateAlarmDtoOlds =alarmlist.stream()
-                .filter(deviceCheckAlarmDto -> alarmDetailsDtoMap.containsKey(deviceCheckAlarmDto.getDeviceId()))
+                .filter(deviceCheckAlarmDto -> alarmDetailsDtoMap.containsKey(deviceCheckAlarmDto.getAlarmSettingId()))
                 .map(d ->{
-                    AlarmDetailsDto alarmDetailsDto = alarmDetailsDtoMap.get(d.getDeviceId());
+                    AlarmDetailsDto alarmDetailsDto = alarmDetailsDtoMap.get(d.getAlarmSettingId());
                     alarmDetailsDto.setDateUpdate(new Date());
                     alarmDetailsDto.setAlarmContent(d.getDeviceName()+"离线时间"+d.getAlarmCondition() +d.getAlarmValue()+"分钟");
                     alarmDetailsDto.setAlarmValue(d.getDuration());
                     alarmDetailMapper.update(alarmDetailsDto);//直接更新
-                    alarmDetailsDtoMap.remove(d.getDeviceId());//更新完成后从集合中移除,只剩下未处理的
+                    alarmDetailsDtoMap.remove(d.getAlarmSettingId());//更新完成后从集合中移除,只剩下未处理的
                     return alarmDetailsDto;
                 })
                 .collect(Collectors.toList());

+ 21 - 14
sms_water/src/main/resources/mapper/AlarmDetailMapper.xml

@@ -33,6 +33,7 @@
             ,d.ADDRESS as "address"
             ,d.POINT_X as "pointX"
             ,d.POINT_Y as "pointY"
+            ,ast.id as "alarmSettingId"
             ,ast.ALARM_CONDITION +" " +ast.ALARM_VALUE as "alermRule"
             ,concat(ifnull(ast.ALARM_CONDITION,''),ifnull(ast.ALARM_VALUE,'')) as "alermRule"
             ,att.UNIT as "unit"
@@ -52,8 +53,8 @@
             ,d.POINT_X as "pointX"
             ,d.POINT_Y as "pointY"
 
-
-            ,a.ALARM_VALUE as "alarmValue"
+            ,ast.id as "alarmSettingId"
+            ,concat(a.ALARM_VALUE,ifnull(ast.unit,'')) as "alarmValue"
             ,a.ALARM_CONTENT as "alarmContent"
 
     </sql>
@@ -72,11 +73,12 @@
             ,d.POINT_X as "pointX"
             ,d.POINT_Y as "pointY"
 
-            ,a.MIN_VALUE as "minValue"
-            ,a.MAX_VALUE as "maxValue"
-            ,concat(ifnull(ast.ALARM_CONDITION,''),ifnull(ast.ALARM_VALUE,'')) as "alermRule"
+            ,concat(a.MIN_VALUE,ifnull(ast.unit,'')) as "minValue"
+            ,concat(a.MAX_VALUE,ifnull(ast.unit,''))as "maxValue"
+            ,ast.id as "alarmSettingId"
+            ,concat(ifnull(ast.ALARM_CONDITION,''),ifnull(ast.ALARM_VALUE,''),ifnull(ast.unit,'')) as "alermRule"
             ,a.ALARM_END_TIME as "alarmEndTime"
-            ,timestampdiff(MINUTE,ifnull(a.ALARM_END_TIME,now()),a.ALARM_START_TIME) as "duration"
+            ,concat(timestampdiff(MINUTE,a.ALARM_START_TIME,ifnull(a.ALARM_END_TIME,now())),,'分钟') as "duration"
 
     </sql>
 
@@ -84,8 +86,8 @@
         left join sms_device d on a.DEVICE_ID =d.id and d.`STATUS` = 1
         left join sms_scene s on d.SCENE_ID =s.id and s.`STATUS` =1
         left join sms_device_type t on d.DEVICE_TYPE_ID =t.ID
-        left join sms_alarm_setting ast on ast.id= a.ATTRIBUTE_ID
-        left join sms_device_attribute att on att.id=ast.ATTRIBUTE_ID
+        left join sms_alarm_setting ast on ast.id= a.alarm_setting_id
+        left join sms_device_attribute att on att.id=a.ATTRIBUTE_ID
     </sql>
     <select id="selectById" resultType="com.huaxu.dto.AlarmDetailsDto">
         select
@@ -172,16 +174,16 @@
 
     <!-- 新增所有列 -->
     <insert id="insert" keyProperty="id" useGeneratedKeys="true">
-        INSERT INTO  sms_alarm_details (  TENANT_ID ,  DEVICE_ID ,  COMPANY_ORG_ID ,  DEPT_ORG_ID ,  ALARM_TYPE ,  ATTRIBUTE_ID ,  ALARM_VALUE ,  ALARM_CONTENT ,  ALARM_START_TIME ,  ALARM_END_TIME ,  STATE ,  OP_STATE ,  REMARK ,  STATUS ,  DATE_CREATE ,  CREATE_BY ,  DATE_UPDATE ,  UPDATE_BY , MIN_VALUE, MAX_VALUE )
-        VALUES ( #{tenantId} ,  #{deviceId} ,  #{companyOrgId} ,  #{deptOrgId} ,  #{alarmType} ,  #{attributeId} ,  #{alarmValue} ,  #{alarmContent} ,  #{alarmStartTime} ,  #{alarmEndTime} ,  #{state} ,  #{opState} ,  #{remark} ,  #{status} ,  #{dateCreate} ,  #{createBy} ,  #{dateUpdate} ,  #{updateBy},#{minValue} ,#{maxValue} )
+        INSERT INTO  sms_alarm_details (  TENANT_ID ,  DEVICE_ID ,  COMPANY_ORG_ID ,  DEPT_ORG_ID ,  ALARM_TYPE ,  ATTRIBUTE_ID ,  ALARM_VALUE ,  ALARM_CONTENT ,  ALARM_START_TIME ,  ALARM_END_TIME ,  STATE ,  OP_STATE ,  REMARK ,  STATUS ,  DATE_CREATE ,  CREATE_BY ,  DATE_UPDATE ,  UPDATE_BY , MIN_VALUE, MAX_VALUE, ALARM_SETTING_ID )
+        VALUES ( #{tenantId} ,  #{deviceId} ,  #{companyOrgId} ,  #{deptOrgId} ,  #{alarmType} ,  #{attributeId} ,  #{alarmValue} ,  #{alarmContent} ,  #{alarmStartTime} ,  #{alarmEndTime} ,  #{state} ,  #{opState} ,  #{remark} ,  #{status} ,  #{dateCreate} ,  #{createBy} ,  #{dateUpdate} ,  #{updateBy},#{minValue} ,#{maxValue}, #{alarmSettingId} )
     </insert>
 
     <!-- 批量新增 -->
     <insert id="batchInsert">
-        INSERT INTO  sms_alarm_details (  TENANT_ID ,  DEVICE_ID ,  COMPANY_ORG_ID ,  DEPT_ORG_ID ,  ALARM_TYPE ,  ATTRIBUTE_ID ,  ALARM_VALUE ,  ALARM_CONTENT ,  ALARM_START_TIME ,  ALARM_END_TIME ,  STATE ,  OP_STATE ,  REMARK ,  STATUS ,  DATE_CREATE ,  CREATE_BY ,  DATE_UPDATE ,  UPDATE_BY, MIN_VALUE, MAX_VALUE )
+        INSERT INTO  sms_alarm_details (  TENANT_ID ,  DEVICE_ID ,  COMPANY_ORG_ID ,  DEPT_ORG_ID ,  ALARM_TYPE ,  ATTRIBUTE_ID ,  ALARM_VALUE ,  ALARM_CONTENT ,  ALARM_START_TIME ,  ALARM_END_TIME ,  STATE ,  OP_STATE ,  REMARK ,  STATUS ,  DATE_CREATE ,  CREATE_BY ,  DATE_UPDATE ,  UPDATE_BY, MIN_VALUE, MAX_VALUE,ALARM_SETTING_ID )
         values
         <foreach collection="alarmDetails" item="item" index="index" separator=",">
-            ( #{item.tenantId} ,  #{item.deviceId} ,  #{item.companyOrgId} ,  #{item.deptOrgId} ,  #{item.alarmType} ,  #{item.attributeId} ,  #{item.alarmValue} ,  #{item.alarmContent} ,  #{item.alarmStartTime} ,  #{item.alarmEndTime} ,  #{item.state} ,  #{item.opState} ,  #{item.remark} ,  #{item.status} ,  #{item.dateCreate} ,  #{item.createBy} ,  #{item.dateUpdate} ,  #{item.updateBy} ,#{item.minValue} ,#{item.maxValue})
+            ( #{item.tenantId} ,  #{item.deviceId} ,  #{item.companyOrgId} ,  #{item.deptOrgId} ,  #{item.alarmType} ,  #{item.attributeId} ,  #{item.alarmValue} ,  #{item.alarmContent} ,  #{item.alarmStartTime} ,  #{item.alarmEndTime} ,  #{item.state} ,  #{item.opState} ,  #{item.remark} ,  #{item.status} ,  #{item.dateCreate} ,  #{item.createBy} ,  #{item.dateUpdate} ,  #{item.updateBy} ,#{item.minValue} ,#{item.maxValue},#{item.alarmSettingId})
         </foreach>
     </insert>
 
@@ -245,7 +247,10 @@
                 MIN_VALUE  = #{minValue},
             </if>
             <if test="maxValue != null">
-                MAX_VALUE  = #{maxValue}
+                MAX_VALUE  = #{maxValue},
+            </if>
+            <if test="alarmSettingId != null">
+                ALARM_SETTING_ID  = #{alarmSettingId}
             </if>
         </set>
         WHERE ID  = #{id};
@@ -592,11 +597,12 @@
 
             ,a.ALARM_CONDITION as "alarmCondition"
             ,a.ALARM_VALUE as "alarmValue"
-
+            ,a.id as "alarmSettingId"
         <if test="deviceCode != null">
             ,da.id as "attributeId"
             ,da.IDENTIFIER as "identifiter"
 		    ,da.`NAME` as "attributeName"
+            ,da.unit as "unit"
         </if>
         from sms_device d
         left join sms_alarm_setting a on a.DEVICE_ID =d.ID and a.ALARM_TYPE =#{alarmType} and a.ALARM_VALUE is not null
@@ -619,6 +625,7 @@
             ,ALARM_START_TIME as "alarmStartTime"
             ,max_value as "maxValue"
             ,min_value as "minValue"
+            ,alarm_setting_id as "alarmSettingId"
         from sms_alarm_details
         where STATE = 1 and status = 1
         <if test="alarmType != null and alarmType != ''">