Bladeren bron

添加消息

lihui001 3 jaren geleden
bovenliggende
commit
590790e831

+ 3 - 0
common/src/main/java/com/zcxk/entity/Message.java

@@ -116,4 +116,7 @@ public class Message implements Serializable {
     @ApiModelProperty(value = "消息类型id")
     private Integer typeId;
     private Integer appId;
+    @ApiModelProperty(value = "场景类型")
+    private Integer sceneType;
+
 }

+ 3 - 0
zoniot-common/zoniot-core-common/src/main/java/com/bz/zoneiot/core/common/pojo/Message.java

@@ -125,4 +125,7 @@ public class Message implements Serializable {
 
     @ApiModelProperty(value = "部门ID")
     private Integer departmentOrgId;
+
+    @ApiModelProperty(value = "场景类型")
+    private Integer sceneType;
 }

+ 11 - 0
zoniot-water/zoniot-water-api/src/main/java/com/bz/zoneiot/water/api/enums/SceneTypeEnum.java

@@ -65,4 +65,15 @@ public enum SceneTypeEnum {
         return list;
     }
 
+    public static SceneTypeEnum get(Integer code){
+        if (code == null){
+            return null;
+        }
+        for (SceneTypeEnum value : SceneTypeEnum.values()) {
+            if (code == value.getCode()){
+                return value;
+            }
+        }
+        return null;
+    }
 }

+ 17 - 0
zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/dao/AlarmTypeDetailMapper.java

@@ -67,4 +67,21 @@ public interface AlarmTypeDetailMapper {
     **/
     Integer updateStateByDeviceId(@Param("deviceId") Long deviceId, @Param("state") Integer state);
 
+    /**
+    * 更新
+    * @author Andy
+    * @date 17:19 2021/11/11
+    * @param entity:
+    * @return int
+    **/
+    int update(AlarmDetailsEntity entity);
+
+    /**
+    * 根据报警设值id查询报警信息id
+    * @author Andy
+    * @date 17:23 2021/11/11
+    * @param alarmId:
+    * @return int
+    **/
+    long selectLastAlarmId(int alarmId);
 }

+ 2 - 0
zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/entity/AlarmDetailsEntity.java

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import lombok.ToString;
 
 import java.io.Serializable;
 import java.util.Date;
@@ -16,6 +17,7 @@ import java.util.Date;
  */
 @Data
 @ApiModel("报警详情信息")
+@ToString
 public class AlarmDetailsEntity implements Serializable {
 
     private static final long serialVersionUID = 6916916266193290481L;

+ 16 - 17
zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/mapper/AlarmDetailMapper.xml

@@ -35,7 +35,7 @@
             ,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"
+            ,concat(ifnull(asr.operator,''),ifnull(asr.`value`,'')) as "alermRule" ,
             ,att.UNIT as "unit"
     </sql>
 
@@ -87,7 +87,8 @@
     <sql id="alarmDetailJoins">
         left join sms_device d on a.DEVICE_ID =d.id and d.`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.alarm_setting_id
+        left join sms_alarm_type ast on ast.id= a.ALARM_ID
+        left join sms_alarm_rule asr on ast.id= asr.alarm_type_id
         left join sms_device_attribute att on att.id=a.ATTRIBUTE_ID
     </sql>
 
@@ -615,11 +616,9 @@
         ,d.LAST_UPDATE_TIME as "lastUpdateTime"
         ,timestampdiff(MINUTE,ifnull(d.LAST_UPDATE_TIME,d.DATE_CREATE),now()) AS "duration"
 
-        ,a.ALARM_CONDITION as "alarmCondition"
-        ,a.ALARM_VALUE as "alarmValue"
+        ,r.operator as "alarmCondition"
+        ,r.value as "alarmValue"
         ,a.id as "alarmSettingId"
-        ,a.START_TIME as "startTime"
-        ,a.END_TIME as "endTime"
         <if test="deviceId != null">
             ,da.id as "attributeId"
             ,da.IDENTIFIER as "identifiter"
@@ -627,7 +626,8 @@
             ,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
+        left join sms_alarm_type a on a.DEVICE_ID =d.ID and a.ALARM_TYPE =#{alarmType}
+        left join sms_alarm_rule r on r.alarm_type_id = a.ID
         <if test="deviceId != null">
             left join sms_device_attribute da on da.id=a.ATTRIBUTE_ID
         </if>
@@ -668,8 +668,6 @@
             </foreach>
         </if>
 
-
-
     </select>
 
     <update id="udpateLastUpdateTime">
@@ -678,9 +676,8 @@
 
     <select id="selectByDeviceId" resultType="com.bz.zoneiot.water.api.vo.AlarmDetailsEntityVo">
         select
-        <include refid="Base_Column_List"/>,concat(b.alarm_condition,cast(b.alarm_value as char)+0) alarmRange
+        <include refid="Base_Column_List"/>,concat(asr.operator,cast(asr.`value` as char)+0) alarmRange
         from sms_alarm_details a
-        left join sms_alarm_setting b on a.alarm_setting_id=b.id and b.status = 1 and b.alarm_condition!='='
         <include refid="alarmDetailJoins"/>
         where a.`STATUS` = 1
         and a.DEVICE_ID=#{deviceId} and (a.scene_id=#{sceneId} or a.PARENT_SCENE_ID=#{sceneId}) and a.state=1
@@ -688,9 +685,8 @@
 
     <select id="selectByDeviceAttributeId" resultType="com.bz.zoneiot.water.api.vo.AlarmDetailsEntityVo">
         select
-        <include refid="Base_Column_List"/>,concat(b.alarm_condition,cast(b.alarm_value as char)+0) alarmRange
+        <include refid="Base_Column_List"/>,concat(asr.operator,cast(asr.`value` as char)+0) alarmRange
         from sms_alarm_details a
-        left join sms_alarm_setting b on a.alarm_setting_id=b.id and b.status = 1 and b.alarm_condition!='='
         <include refid="alarmDetailJoins"/>
         where a.`STATUS` = 1
         and a.DEVICE_ID=#{deviceId} and a.ATTRIBUTE_ID=#{attributeId} and (a.scene_id=#{sceneId} or a.PARENT_SCENE_ID=#{sceneId}) and a.state=1
@@ -704,7 +700,7 @@
             ,ad.ALARM_TYPE as "alarmType"
             ,d.DEVICE_NAME as "deviceName"
             ,da.NAME as "attributeName"
-            ,CONCAT(ast.ALARM_CONDITION,ast.ALARM_VALUE) as "alarmContent"
+            ,CONCAT(asr.operator,asr.value) as "alarmContent"
             ,da.UNIT as "unit"
 
             ,d.id as "deviceId"
@@ -718,7 +714,8 @@
         from sms_alarm_details ad
         left join sms_device d on ad.DEVICE_ID =d.ID
         left join sms_device_attribute da on ad.ATTRIBUTE_ID =da.id
-        left join sms_alarm_setting ast on ast.id=ad.ALARM_SETTING_ID
+        left join sms_alarm_type ast on ast.id=ad.ALARM_ID
+        left join sms_alarm_rule asr on ast.id= asr.alarm_type_id
         where  ad.OP_STATE=1 and ad.STATE=1 and ad.is_send_message = 0 and d.status = 1 and d.ENABLE_STATE = 1
         and timestampdiff(MINUTE,ad.ALARM_START_TIME,now())>10
     </select>
@@ -730,13 +727,15 @@
             #{item.alarmId}
         </foreach>
     </update>
+
     <select id="selectBySceneId" resultType="com.bz.zoneiot.water.api.vo.AlarmDetailsEntityVo">
         select
-        <include refid="Base_Column_List"/>,concat(b.alarm_condition,cast(b.alarm_value as char)+0) alarmRange
+        <include refid="Base_Column_List"/>,concat(asr.operator,cast(asr.`value` as char)+0) alarmRange
         from sms_alarm_details a
-        left join sms_alarm_setting b on a.alarm_setting_id=b.id and b.status = 1 and b.alarm_condition!='='
         <include refid="alarmDetailJoins"/>
         where a.`STATUS` = 1
         and (a.parent_scene_id =#{sceneId} or a.scene_id=#{sceneId})and a.state=1
     </select>
+
+
 </mapper>

+ 92 - 0
zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/mapper/AlarmTypeDetailMapper.xml

@@ -123,4 +123,96 @@
         update sms_alarm_details set state =#{state}, ALARM_END_TIME = now(), DATE_UPDATE = now() where device_id = #{deviceId}
     </update>
 
+    <update id="update">
+        update sms_alarm_details
+        <set>
+            <if test="alarmId != null">
+                ALARM_ID = #{alarmId},
+            </if>
+            <if test="tenantId != null and tenantId != ''">
+                TENANT_ID = #{tenantId},
+            </if>
+            <if test="parentSceneId != null">
+                PARENT_SCENE_ID = #{parentSceneId},
+            </if>
+            <if test="parentSceneName != null and parentSceneName != ''">
+                PARENT_SCENE_NAME = #{parentSceneName},
+            </if>
+            <if test="sceneId != null">
+                SCENE_ID = #{sceneId},
+            </if>
+            <if test="sceneName != null and sceneName != ''">
+                SCENE_NAME = #{sceneName},
+            </if>
+            <if test="deviceId != null">
+                DEVICE_ID = #{deviceId},
+            </if>
+            <if test="companyOrgId != null">
+                COMPANY_ORG_ID = #{companyOrgId},
+            </if>
+            <if test="deptOrgId != null">
+                DEPT_ORG_ID = #{deptOrgId},
+            </if>
+            <if test="alarmType != null and alarmType != ''">
+                ALARM_TYPE = #{alarmType},
+            </if>
+            <if test="attributeId != null">
+                ATTRIBUTE_ID = #{attributeId},
+            </if>
+            <if test="alarmValue != null">
+                ALARM_VALUE = #{alarmValue},
+            </if>
+            <if test="alarmContent != null and alarmContent != ''">
+                ALARM_CONTENT = #{alarmContent},
+            </if>
+            <if test="alarmStartTime != null">
+                ALARM_START_TIME = #{alarmStartTime},
+            </if>
+            <if test="alarmEndTime != null">
+                ALARM_END_TIME = #{alarmEndTime},
+            </if>
+            <if test="state != null">
+                STATE = #{state},
+            </if>
+            <if test="opState != null">
+                OP_STATE = #{opState},
+            </if>
+            <if test="remark != null and remark != ''">
+                REMARK = #{remark},
+            </if>
+            <if test="status != null">
+                STATUS = #{status},
+            </if>
+            <if test="dateCreate != null">
+                DATE_CREATE = #{dateCreate},
+            </if>
+            <if test="createBy != null and createBy != ''">
+                CREATE_BY = #{createBy},
+            </if>
+            <if test="dateUpdate != null">
+                DATE_UPDATE = #{dateUpdate},
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                UPDATE_BY = #{updateBy},
+            </if>
+            <if test="minValue != null">
+                MIN_VALUE = #{minValue},
+            </if>
+            <if test="maxValue != null">
+                MAX_VALUE = #{maxValue},
+            </if>
+            <if test="alarmSettingId != null">
+                ALARM_SETTING_ID = #{alarmSettingId},
+            </if>
+            <if test="isSendMessage != null">
+                IS_SEND_MESSAGE = #{isSendMessage},
+            </if>
+        </set>
+        where ID = #{id}
+    </update>
+
+    <select id="selectLastAlarmId" resultType="java.lang.Long">
+        select id from sms_alarm_details where ALARM_ID =#{alarmId} and STATE = 1 order by DATE_CREATE desc
+    </select>
+
 </mapper>

+ 11 - 8
zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/mapper/OnlineMonitorMapper.xml

@@ -86,7 +86,7 @@
         case when t5.attribute_id is  null then null when t6.id is null then 0 else 1 end is_alarm,
         t5.parm_type attribute_type,
         if (t5.device_id is null, null, t4.device_code) device_code,
-        concat(t11.alarm_condition,cast(t11.alarm_value as char)+0) alarm_range
+        concat(t12.operator,cast(t12.value as char)+0) alarm_range
     </sql>
 
     <sql id="sceneDeviceJoins">
@@ -103,7 +103,8 @@
         left join sms_device_attribute t9 on t5.attribute_id=t9.id and t9.status = 1
         left join sms_alarm_details t6 on t6.scene_id=t2.scene_id and t6.device_id=t2.device_id
                   and t6.attribute_id=t5.attribute_id and t6.status = 1 and t6.state=1
-        left join sms_alarm_setting t11 on t6.alarm_setting_id=t11.id and t11.status = 1 and t11.alarm_condition!='='
+        left join sms_alarm_type t11 on t6.ALARM_ID = t11.id and t11.status = 1
+        left join sms_alarm_rule t12 on t11.id = t12.alarm_type_id and t12.status = 1
     </sql>
 
     <sql id="sceneAlarmJoins">
@@ -129,7 +130,7 @@
         <if test="flag == 1">
             left join (
                 select parent_scene_id,count(distinct device_id) setting_device_count
-                from sms_alarm_setting
+                from sms_alarm_details
                 where alarm_type='状态报警' and status=1
                 group by parent_scene_id
             )t10 on t7.parent_scene_id=t10.parent_scene_id
@@ -445,7 +446,7 @@
     <!--查询设备地图参数数据-->
     <select id="selectDeviceMapParam" resultMap="deviceDataMap">
         select distinct t1.id device_id,t1.device_code,t1.device_name,t1.point_x,point_y,t1.address,t2.attribute_id, ifnull(t2.remark, t3.`name`) attribute_name,t3.unit,t2.parm_type attribute_type,
-         t2.seq,case when t2.attribute_id is  null then null when t6.id is null then 0 else 1 end is_alarm,concat(t11.alarm_condition,cast(t11.alarm_value as char)+0) alarm_range
+         t2.seq,case when t2.attribute_id is  null then null when t6.id is null then 0 else 1 end is_alarm,concat(t12.operator,cast(t12.operator as char)+0) alarm_range
         <if test="flag == null or flag ==0">
             ,if (t4.alarm_count>0, 1, 0) device_state
         </if>
@@ -467,7 +468,8 @@
             from sms_alarm_details a1 where a1.device_id= #{deviceId} and a1.`status` = 1 and a1.state = 1
         )t4 on t4.device_id=t1.id
         left join sms_alarm_details t6 on t6.device_id=t1.id and t6.attribute_id=t2.attribute_id and t6.status = 1 and t6.state=1
-        left join sms_alarm_setting t11 on t6.alarm_setting_id=t11.id and t11.status = 1 and t11.alarm_condition!='='
+        left join sms_alarm_type t11 on t6.ALARM_ID=t11.id and t11.status = 1
+        left join sms_alarm_rule t12 on t12.alarm_type_id=t11.id and t12.status = 1
         where t1. status = 1 and t1.id= #{deviceId}
         order by t2.seq
     </select>
@@ -640,7 +642,7 @@
     </select>
     <!--查询管网地图图层及设备-->
     <select id="selectPipeNetLayer" resultMap="layerMap">
-        select t4.id scene_id,t4.scene_name,t5.scene_type_name,t6.id device_id,t6.device_code,t6.device_name,t6.point_x,t6.point_y,t6.address,concat(t11.alarm_condition,cast(t11.alarm_value as char)+0) alarm_range
+        select t4.id scene_id,t4.scene_name,t5.scene_type_name,t6.id device_id,t6.device_code,t6.device_name,t6.point_x,t6.point_y,t6.address,concat(t12.operator,cast(t12.value as char)+0) alarm_range
         ,t8.attribute_id ,ifnull(t8.remark, t9.`name`) attribute_name,t9.unit,case when t8.attribute_id is null then null when t10.id is null then 0 else 1 end is_alarm
         <if test="flag == null or flag ==0">
             ,if (t7.alarm_count>0, 1, 0) device_state
@@ -664,7 +666,8 @@
         left join sms_device_parm t8 on t8.device_id=t2.device_id and t8. status = 1 and t8.is_suspension = 1
         left join sms_device_attribute t9 on t8.attribute_id=t9.id and t9.status = 1
         left join sms_alarm_details t10 on t10.scene_id=t2.scene_id and t10.device_id=t2.device_id and t10.attribute_id=t8.attribute_id and t10.status = 1 and t10.state=1
-        left join sms_alarm_setting t11 on t10.alarm_setting_id=t11.id and t11.status = 1 and t11.alarm_condition!='='
+        left join sms_alarm_type t11 on t10.ALARM_ID=t11.id and t11.status = 1
+        left join sms_alarm_rule t12 on t12.alarm_type_id=t11.id and t12.status = 1
         where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网'
         <choose>
             <when test="sceneTypeName != null and sceneTypeName !=''">
@@ -742,7 +745,7 @@
         )t7 on t7.parent_scene_id=t1.id
         left join (
             select parent_scene_id,count(distinct device_id) setting_device_count
-            from sms_alarm_setting
+            from sms_alarm_details
             where alarm_type='状态报警' and status=1
             group by parent_scene_id
         )t10 on t7.parent_scene_id=t10.parent_scene_id

+ 68 - 0
zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/config/MessageConfig.java

@@ -0,0 +1,68 @@
+package com.bz.zoneiot.water.web.config;
+
+import com.bz.zoneiot.water.api.enums.SceneTypeEnum;
+import feign.RequestInterceptor;
+import feign.RequestTemplate;
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpHeaders;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @description  消息系统配置
+ * @author  Andy
+ * @data 2020-11-17 8:52
+ */
+@Configuration
+@Component
+public class MessageConfig {
+
+    /**
+     * 水源告警消息跳转链接
+     */
+    @Value("${message.water.source.skip.url:http://114.135.61.186:21020/productionmanage/warnDetail}")
+    private String waterSourceSkipUrl;
+
+    /**
+     * 水厂告警消息跳转链接
+     */
+    @Value("${message.water.works.skip.url:http://114.135.61.186:21020/productionmanage/warnDetail}")
+    private String waterWorksSkipUrl;
+
+    /**
+     * 泵站告警消息跳转链接
+     */
+    @Value("${message.pumping.station.skip.url:http://114.135.61.186:21020/secondwatersupply/warnDetail}")
+    private String pumpingStationSkipUrl;
+
+    /**
+     * 管网告警消息跳转链接
+     */
+    @Value("${message.pipe.network.skip.url:http://114.135.61.186:21020/gwmangement/warnDetail}")
+    private String pipeNetworkSkipUrl;
+
+    /**
+     * 获取告警跳转url
+     * @param sceneTypeEnum
+     * @return
+     */
+    public String getAlarmSkipUrl(SceneTypeEnum sceneTypeEnum){
+        switch (sceneTypeEnum){
+            case WATER_SOURCE:
+            case WATER_WORKS:
+            case WATER_SOURCE_OR_WORKS:
+                return this.waterWorksSkipUrl;
+            case PUMPING_STATION:
+                return this.pumpingStationSkipUrl;
+            case PIPE_NETWORK:
+                return this.pipeNetworkSkipUrl;
+            default:
+                return null;
+        }
+    }
+}

+ 46 - 16
zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/service/impl/AlarmTypeDetailsServiceImpl.java

@@ -9,6 +9,7 @@ import com.bz.zoneiot.core.oauth2.util.UserUtil;
 import com.bz.zoneiot.water.api.dto.AlarmDetailsAddDto;
 import com.bz.zoneiot.water.api.dto.AlarmTypeDetailsDto;
 import com.bz.zoneiot.water.api.enums.AlarmStateEnum;
+import com.bz.zoneiot.water.api.enums.SceneTypeEnum;
 import com.bz.zoneiot.water.api.vo.AlarmTypeDetailsEntityVo;
 import com.bz.zoneiot.water.api.vo.DeviceSceneVo;
 import com.bz.zoneiot.water.core.dao.AlarmTypeDetailMapper;
@@ -19,6 +20,7 @@ import com.bz.zoneiot.water.core.entity.DeviceAttributeEntity;
 import com.bz.zoneiot.water.core.entity.Org;
 import com.bz.zoneiot.water.web.client.UserCenterClient;
 import com.bz.zoneiot.water.web.component.MessageComponent;
+import com.bz.zoneiot.water.web.config.MessageConfig;
 import com.bz.zoneiot.water.web.service.AlarmTypeDetailsService;
 import com.bz.zoneiot.water.web.service.AlarmTypeService;
 import lombok.extern.log4j.Log4j2;
@@ -26,6 +28,7 @@ import org.springframework.amqp.core.AmqpTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
@@ -50,6 +53,9 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
     @Value("${dispath.routing.key}")
     private String dispathRoutingKey;
 
+    @Resource
+    private MessageConfig messageConfig;
+
     @Resource
     private MessageComponent messageComponent;
 
@@ -67,20 +73,14 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
 
     @Override
     public Integer insert(AlarmDetailsAddDto dto) {
-        List<AlarmDetailsEntity> entities = this.convert(dto);
-        if (entities == null) {
-            return 0;
-        }
-        return alarmTypeDetailMapper.batchInsert(entities);
+        this.saveOrUpdate(this.convert(dto));
+        return 1;
     }
 
     @Override
     public Integer batchInsert(List<AlarmDetailsAddDto> alarmDetails) {
-        List<AlarmDetailsEntity> entities = this.convert(alarmDetails);
-        if (entities == null) {
-            return 0;
-        }
-        return alarmTypeDetailMapper.batchInsert(entities);
+        this.saveOrUpdate(this.convert(alarmDetails));
+        return 1;
     }
 
     @Override
@@ -99,6 +99,27 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
         return alarmTypeDetailMapper.updateStateByDeviceId(deviceId, state);
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    public void saveOrUpdate(List<AlarmDetailsEntity> entities) {
+        StringBuilder builder = new StringBuilder();
+        List<AlarmDetailsEntity> addList = new ArrayList<>();
+        for (AlarmDetailsEntity entity : entities) {
+            if (entity.getId() != null) {
+                alarmTypeDetailMapper.update(entity);
+                builder.append(",").append(entity.getId());
+            } else {
+                addList.add(entity);
+            }
+        }
+        if (builder.length() > 0 ){
+            log.info("【接收告警信息】:更新数:{}", builder.toString());
+        }
+        if (addList.size() > 0){
+            alarmTypeDetailMapper.batchInsert(addList);
+            log.info("【接收告警信息】:添加数量 {}", addList.size());
+        }
+    }
+
 
     /**
     * 转换实体
@@ -132,12 +153,15 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
     private List<AlarmDetailsEntity> convert(AlarmDetailsAddDto dto){
         BigDecimal value;
         String deviceName;
+        Integer sceneType;
         String attrName = null;
         AlarmType alarmType = alarmTypeService.findByIotAlarmId(dto.getAlarmTypeId());
         if (alarmType == null) {
             log.error("【接收告警信息失败】:告警信息为空 ,请求参数:{}", dto.toString());
             return null;
         }
+        sceneType = alarmType.getSceneType();
+        long alarmId = alarmTypeDetailMapper.selectLastAlarmId(alarmType.getId());
         List<AlarmDetailsEntity> result = new ArrayList<>();
         // 离线告警
         if (alarmType.getAlarmCategory() == 2 || alarmType.getAttributeId() == null) {
@@ -154,7 +178,9 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
         List<DeviceSceneVo> sceneVos = deviceSceneMapper.findSceneByDeviceId(alarmType.getDeviceId());
         for (DeviceSceneVo sceneVo : sceneVos) {
             AlarmDetailsEntity alarmDetailsEntity = new AlarmDetailsEntity();
-
+            if (alarmId != 0) {
+                alarmDetailsEntity.setId(alarmId);
+            }
             alarmDetailsEntity.setAlarmStartTime(dto.getAlarmTime());
             alarmDetailsEntity.setAlarmContent(dto.getDescription());
 
@@ -180,21 +206,21 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
             alarmDetailsEntity.setState(AlarmStateEnum.REALTIME_ALARM.getCode());
             alarmDetailsEntity.setDateCreate(new Date());
             deviceName = sceneVo.getDeviceName();
-            sendMessage(alarmDetailsEntity, alarmType.getAlarmCategory(), attrName, deviceName);
+            sendMessage(alarmDetailsEntity, alarmType.getAlarmCategory(), attrName, deviceName, sceneType);
             result.add(alarmDetailsEntity);
         }
 
         return result;
     }
 
-    private void sendMessage(AlarmDetailsEntity alarmDetailsEntity, int category , String attrName, String deviceName){
+    private void sendMessage(AlarmDetailsEntity alarmDetailsEntity, int category , String attrName, String deviceName, Integer sceneType){
         Message message = new Message();
         message.setStatus(1);
         message.setTenantId(alarmDetailsEntity.getTenantId());
         message.setMessageId(UUID.randomUUID().toString());
         JSONObject jsonContent = new JSONObject();
-        jsonContent.put("场景名称",alarmDetailsEntity.getSceneName());
-        jsonContent.put("设备名称",deviceName);
+        jsonContent.put("场景名称", alarmDetailsEntity.getSceneName());
+        jsonContent.put("设备名称", deviceName);
         jsonContent.put("报警字段", attrName);
         if (category == 1) {
             jsonContent.put("报警字段", attrName);
@@ -204,11 +230,15 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
         // 消息内容,如果需要动态使用,配合模板使用{key:value}
         message.setMessageContent(jsonContent.toJSONString());
         // 消息类型、模板id、渠道
-        message.setMessageType(1);
+        message.setMessageType(category == 1 ? 1 : 2);
         message.setMessageTemplateId(category == 1 ? 1 : 2);
         message.setChannel(0);
+        message.setSceneType(sceneType);
         message.setCompanyOrgId(alarmDetailsEntity.getCompanyOrgId());
         message.setDepartmentOrgId(alarmDetailsEntity.getDeptOrgId());
+        String url = messageConfig.getAlarmSkipUrl(SceneTypeEnum.get(sceneType));
+        message.setUrl(url);
+        message.setSceneType(sceneType);
         messageComponent.sendMessageToAllTenantUsers(message, receiveExchangeName, dispathRoutingKey);
     }