Ver código fonte

Merge remote-tracking branch 'origin/20210716' into 20210716

hym 3 anos atrás
pai
commit
47a759d2dd
25 arquivos alterados com 515 adições e 119 exclusões
  1. 3 0
      common/src/main/java/com/zcxk/entity/Message.java
  2. 7 0
      message/src/main/java/com/zcxk/controller/MessageController.java
  3. 2 0
      message/src/main/java/com/zcxk/dao/MessageMapper.java
  4. 2 0
      message/src/main/java/com/zcxk/service/MessageService.java
  5. 6 1
      message/src/main/java/com/zcxk/service/impl/MessageServiceImpl.java
  6. 1 1
      message/src/main/resources/application-dev.properties
  7. 20 4
      message/src/main/resources/mapper/MessageMapper.xml
  8. 46 0
      user_center/src/main/java/com/zcxk/config/JacksonConfig.java
  9. 3 0
      zoniot-common/zoniot-core-common/src/main/java/com/bz/zoneiot/core/common/pojo/AjaxMessage.java
  10. 12 0
      zoniot-common/zoniot-core-common/src/main/java/com/bz/zoneiot/core/common/pojo/Message.java
  11. 1 1
      zoniot-common/zoniot-core-mq/src/main/java/com/bz/zoneiot/core/utils/rabbit/RabbitServiceImpl.java
  12. 11 0
      zoniot-water/zoniot-water-api/src/main/java/com/bz/zoneiot/water/api/enums/SceneTypeEnum.java
  13. 17 0
      zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/dao/AlarmTypeDetailMapper.java
  14. 5 0
      zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/entity/AlarmDetailsEntity.java
  15. 1 1
      zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/entity/AlarmType.java
  16. 16 17
      zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/mapper/AlarmDetailMapper.xml
  17. 92 0
      zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/mapper/AlarmTypeDetailMapper.xml
  18. 1 1
      zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/mapper/AlarmTypeMapper.xml
  19. 33 32
      zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/mapper/OnlineMonitorMapper.xml
  20. 4 0
      zoniot-water/zoniot-water-web/pom.xml
  21. 14 11
      zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/client/UserCenterClient.java
  22. 79 0
      zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/component/MessageComponent.java
  23. 3 3
      zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/config/FeignConfig.java
  24. 71 0
      zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/config/MessageConfig.java
  25. 65 47
      zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/service/impl/AlarmTypeDetailsServiceImpl.java

+ 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;
+
 }

+ 7 - 0
message/src/main/java/com/zcxk/controller/MessageController.java

@@ -75,6 +75,13 @@ public class MessageController {
 
        return new AjaxMessage<>(ResultStatus.OK,messageService.queryLastMessage(num,type));
     }
+
+    @RequestMapping(value = "queryLastMessageBySceneType", method = RequestMethod.POST)
+    @ApiOperation(value = "查询最新消息")
+    public AjaxMessage<List<Message>> queryLastMessageBySceneType(int num,Integer type, int sceneType) {
+
+        return new AjaxMessage<>(ResultStatus.OK,messageService.queryLastMessage(num,type, sceneType));
+    }
     /**
      * 分页查询
      *

+ 2 - 0
message/src/main/java/com/zcxk/dao/MessageMapper.java

@@ -85,6 +85,8 @@ public interface MessageMapper {
 
     List<Message> queryLastMessage(@Param("num") int num, @Param("id") Integer id, Integer type);
 
+    List<Message> queryLastMessageBySceneType(@Param("num") int num, @Param("id") Integer id, Integer type, @Param("sceneType")Integer sceneType);
+
     List<MessageStatic> queryUnreadMessageStatic(Integer id);
 
     int updateMultiple(RequsetMessageQuery requsetMessageQuery);

+ 2 - 0
message/src/main/java/com/zcxk/service/MessageService.java

@@ -87,5 +87,7 @@ public interface MessageService {
 
     List<Message> queryLastMessage(int num, Integer type);
 
+    List<Message> queryLastMessage(int num, Integer type, Integer sceneType);
+
     int judgingTheMessageJumpPermission(String url, String appId);
 }

+ 6 - 1
message/src/main/java/com/zcxk/service/impl/MessageServiceImpl.java

@@ -9,6 +9,7 @@ import com.zcxk.entity.Message;
 import com.zcxk.model.LoginUser;
 import com.zcxk.service.MessageService;
 import com.zcxk.util.UserUtil;
+import io.swagger.models.auth.In;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -177,11 +178,15 @@ public class MessageServiceImpl implements MessageService {
 
     @Override
     public List<Message> queryLastMessage(int num, Integer type) {
-       ;
 
         return messageMapper.queryLastMessage(num, UserUtil.getCurrentUser().getId(),type);
     }
 
+    @Override
+    public List<Message> queryLastMessage(int num, Integer type, Integer sceneType) {
+        return messageMapper.queryLastMessageBySceneType(num, UserUtil.getCurrentUser().getId(),type, sceneType);
+    }
+
     @Override
     public int judgingTheMessageJumpPermission(String url, String appId) {
         int result=-1;

+ 1 - 1
message/src/main/resources/application-dev.properties

@@ -38,7 +38,7 @@ spring.redis.lettuce.shutdown-timeout=100
 security.oauth2.client.client-id=smart-city-v2
 security.oauth2.client.client-secret=smart-city-v2-123
 security.oauth2.resource.id=smartcity-deivice-service
-security.oauth2.resource.user-info-uri=http://localhost:8321/user/principal
+security.oauth2.resource.user-info-uri=http://10.0.0.62:8321/user/principal
 
 security.oauth2.resource.prefer-token-info=false
 

+ 20 - 4
message/src/main/resources/mapper/MessageMapper.xml

@@ -105,22 +105,22 @@
 
     <!-- 新增所有列 -->
     <insert id="insert" keyProperty="id" useGeneratedKeys="true">
-        insert into uims_message(id, message_id, message_type, message_content, message_template_id, url, message_status, user_id, channel, title, tenant_id, status, date_create, create_by, update_by, unique_flag, date_update)
-        values ( #{id}, #{messageId}, #{messageType}, #{messageContent}, #{messageTemplateId}, #{url}, #{messageStatus}, #{userId}, #{channel}, #{title}, #{tenantId}, #{status}, #{dateCreate}, #{createBy}, #{updateBy}, #{uniqueFlag}, #{dateUpdate})
+        insert into uims_message(id, message_id, message_type, message_content, message_template_id, url, message_status, user_id, channel, title, tenant_id, status, date_create, create_by, update_by, unique_flag, date_update, scene_type)
+        values ( #{id}, #{messageId}, #{messageType}, #{messageContent}, #{messageTemplateId}, #{url}, #{messageStatus}, #{userId}, #{channel}, #{title}, #{tenantId}, #{status}, #{dateCreate}, #{createBy}, #{updateBy}, #{uniqueFlag}, #{dateUpdate}, #{sceneType})
     </insert>
 
     <!-- 批量新增 -->
     <insert id="batchInsert">
         insert into uims_message(id, message_id, message_type, message_content, message_template_id, url,
         message_status, user_id, channel, title, tenant_id, status, date_create, create_by, update_by, unique_flag,
-        date_update)
+        date_update,scene_type)
         values
         <foreach collection="messages" item="item" index="index" separator=",">
             (
             #{item.id}, #{item.messageId}, #{item.messageType}, #{item.messageContent}, #{item.messageTemplateId},
             #{item.url}, #{item.messageStatus}, #{item.userId}, #{item.channel}, #{item.title}, #{item.tenantId},
             #{item.status}, #{item.dateCreate}, #{item.createBy}, #{item.updateBy}, #{item.uniqueFlag},
-            #{item.dateUpdate} )
+            #{item.dateUpdate},#{item.sceneType})
         </foreach>
     </insert>
 
@@ -260,6 +260,22 @@
         </if>
         order by date_create desc limit #{num}
     </select>
+
+    <select id="queryLastMessageBySceneType" resultType="com.zcxk.entity.Message">
+        select a.date_create,a.message_content,b.short_name,b.path,b.id typeId,a.url,
+        b.type typeName,b.app_id
+        from uims_message a
+        join uims_message_type b
+        on a.message_type=b.id
+        where user_id=#{id} and a.status=1
+        <if test="type!= null">
+            and message_status =0
+        </if>
+        <if test="sceneType!= null">
+            and scene_type = #{sceneType}
+        </if>
+        order by date_create desc limit #{num}
+    </select>
     <select id="queryUnreadMessageStatic" resultType="com.zcxk.Dto.MessageStatic">
          select a.typeId,b.type,a.cn from (select message_type typeId ,
          count(*)cn  from

+ 46 - 0
user_center/src/main/java/com/zcxk/config/JacksonConfig.java

@@ -0,0 +1,46 @@
+package com.zcxk.config;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
+
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+/**
+ * jackson配置
+ */
+@Configuration
+public class JacksonConfig {
+    @Bean
+    @Primary
+    @ConditionalOnMissingBean(ObjectMapper.class)
+    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
+        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
+
+        /**
+         * 序列换成json时,将所有的long变成string
+         * 因为js中得数字类型不能包含所有的java long值并且long值转json丢失精度
+         */
+        SimpleModule module = new SimpleModule();
+        module.addSerializer(Long.class, ToStringSerializer.instance);
+        module.addSerializer(Long.TYPE, ToStringSerializer.instance);
+        module.addSerializer(BigInteger.class, ToStringSerializer.instance);
+
+
+
+        //LocalDateTime
+        LocalDateTimeDeserializer localDateTimeDeserializer = new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        module.addDeserializer(LocalDateTime.class, localDateTimeDeserializer);
+        objectMapper.registerModule(module);
+
+        return objectMapper;
+    }
+}

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

@@ -31,6 +31,9 @@ public class AjaxMessage<T> implements Serializable {
     public AjaxMessage() {
     }
 
+    public AjaxMessage(String msg) {
+        this.msg = msg;
+    }
 
     public AjaxMessage(RespCode respCode) {
         this.status = respCode.getStatus();

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

@@ -17,6 +17,7 @@ import java.util.Date;
 @Data
 @ApiModel
 public class Message implements Serializable {
+
     private static final long serialVersionUID = 218863842329351978L;
     /**
      * 主键
@@ -113,7 +114,18 @@ public class Message implements Serializable {
     private String shortName;
     @ApiModelProperty(value = "消息跳转绝对路径")
     private String path;
+
     @ApiModelProperty(value = "消息类型id")
     private Integer typeId;
+
     private Integer appId;
+
+    @ApiModelProperty(value = "公司ID")
+    private Integer companyOrgId;
+
+    @ApiModelProperty(value = "部门ID")
+    private Integer departmentOrgId;
+
+    @ApiModelProperty(value = "场景类型")
+    private Integer sceneType;
 }

+ 1 - 1
zoniot-common/zoniot-core-mq/src/main/java/com/bz/zoneiot/core/utils/rabbit/RabbitServiceImpl.java

@@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
  * @author Andy
  * @date 2021-07-22 11:03
  */
-@Service
+@Service("rabbitService")
 @Slf4j
 public class RabbitServiceImpl implements MqService {
 

+ 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);
 }

+ 5 - 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;
@@ -105,4 +107,7 @@ public class AlarmDetailsEntity implements Serializable {
     @ApiModelProperty(value = "更新人")
     private String updateBy;
 
+    @ApiModelProperty(value = "更新人 : 是否推送消息(0否1是)")
+    private Integer isSendMessage;
+
 }

+ 1 - 1
zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/entity/AlarmType.java

@@ -38,7 +38,7 @@ public class AlarmType {
     @ApiModelProperty(value="产品id")
     private Integer productId;
 
-    @ApiModelProperty(value="条件值")
+    @ApiModelProperty(value="场景")
     private Integer sceneType;
 
     @ApiModelProperty(value="告警名称")

+ 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>

+ 1 - 1
zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/mapper/AlarmTypeMapper.xml

@@ -36,7 +36,7 @@
   <sql id="Base_Column_List">
     <!--@mbg.generated-->
     id, tenant_id, company_org_id,device_id, dept_org_id, product_id, `name`, attribute_id, `desc`, alarm_category, enabled,
-    alarm_rule_num, days, times,`status`, create_date, create_by, update_date, update_by, iot_alarm_id
+    alarm_rule_num, days, times,`status`, create_date, create_by, update_date, update_by, iot_alarm_id,scene_type
   </sql>
   <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.bz.zoneiot.water.core.entity.AlarmType" useGeneratedKeys="true">
     <!--@mbg.generated-->

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

@@ -50,22 +50,26 @@
         <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
         <result property="sceneName" column="scene_name" jdbcType="VARCHAR"/>
         <result property="sceneTypeName" column="scene_type_name" jdbcType="VARCHAR"/>
-        <collection property="deviceDataList" ofType="com.bz.zoneiot.water.api.vo.MonitorDataCollectVo" javaType="list">
-            <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
-            <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
-            <result property="deviceName" column="device_name" jdbcType="VARCHAR"/>
-            <result property="pointX" column="point_x" jdbcType="VARCHAR"/>
-            <result property="pointY" column="point_y" jdbcType="VARCHAR"/>
-            <result property="address" column="address" jdbcType="VARCHAR"/>
-            <result property="deviceState" column="device_state" jdbcType="INTEGER"/>
-            <collection property="monitorDataEntities" ofType="com.bz.zoneiot.water.api.vo.MonitorDataVo" javaType="list">
-                <result property="attributeId" column="attribute_id" jdbcType="INTEGER"/>
-                <result property="attributeName" column="attribute_name" jdbcType="VARCHAR"/>
-                <result property="unit" column="unit" jdbcType="VARCHAR"/>
-                <result property="isAlarm" column="is_Alarm" jdbcType="VARCHAR"/>
-                <result property="alarmRange" column="alarm_range" jdbcType="VARCHAR"/>
-            </collection>
-        </collection>
+        <collection property="deviceDataList"  resultMap="dataCollectVoMap"></collection>
+    </resultMap>
+
+    <resultMap id="dataCollectVoMap" type="com.bz.zoneiot.water.api.vo.MonitorDataCollectVo">
+        <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
+        <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
+        <result property="deviceName" column="device_name" jdbcType="VARCHAR"/>
+        <result property="pointX" column="point_x" jdbcType="VARCHAR"/>
+        <result property="pointY" column="point_y" jdbcType="VARCHAR"/>
+        <result property="address" column="address" jdbcType="VARCHAR"/>
+        <result property="deviceState" column="device_state" jdbcType="INTEGER"/>
+        <collection property="monitorDataEntities"  resultMap="monitorDataVoMap"></collection>
+    </resultMap>
+
+    <resultMap id="monitorDataVoMap" type="com.bz.zoneiot.water.api.vo.MonitorDataVo">
+        <result property="attributeId" column="attribute_id" jdbcType="INTEGER"/>
+        <result property="attributeName" column="attribute_name" jdbcType="VARCHAR"/>
+        <result property="unit" column="unit" jdbcType="VARCHAR"/>
+        <result property="isAlarm" column="is_Alarm" jdbcType="VARCHAR"/>
+        <result property="alarmRange" column="alarm_range" jdbcType="VARCHAR"/>
     </resultMap>
 
     <sql id="Base_Column_List">
@@ -82,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">
@@ -99,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">
@@ -125,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
@@ -212,13 +217,7 @@
     <select id="selectMapSuspension" resultMap="monitorDataMap">
         select
         <include refid="Base_Column_List"/>
-        <if test="flag == null or flag ==0">
-            ,if (t7.alarm_count>0, 1, 0) scene_state,
-        </if>
-        <if test="flag == 1">
-            ,case when t7.offline_alarm_count=t10.setting_device_count then 2
-            when t7.alarm_count>0 or t7.offline_alarm_count>0 then 1 else 0 end scene_state,
-        </if>
+        ,t4.ENABLE_STATE scene_state,
         t1.company_org_id as "companyOrgId"
         from sms_scene t1
         <include refid="sceneDeviceJoins"/>
@@ -441,7 +440,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>
@@ -463,8 +462,9 @@
             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!='='
-        where t1. status = 1 and t1. enable_state = 1 and t1.id= #{deviceId}
+        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>
     <!--统计设备合格数据-->
@@ -636,7 +636,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
@@ -660,7 +660,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 !=''">
@@ -738,7 +739,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

+ 4 - 0
zoniot-water/zoniot-water-web/pom.xml

@@ -72,6 +72,10 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-amqp</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.zcxk</groupId>
+            <artifactId>zoniot-core-mq</artifactId>
+        </dependency>
 
     </dependencies>
 

+ 14 - 11
zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/client/UserCenterClient.java

@@ -19,6 +19,19 @@ import java.util.Map;
 @FeignClient(value = "user-center",configuration={FeignConfig.class})
 public interface UserCenterClient {
 
+
+    /**
+     * findUserIdsByPermissonOrg
+     * @author Andy
+     * @date 11:33 2021/8/18
+     * @param tenantId:
+     * @param companyOrgId:
+     * @param deptOrgId:
+     * @return java.util.List<java.lang.Integer>
+     **/
+    @PostMapping("/user/findUserIdsByPermissonOrg")
+    List<Integer> findUserIdsByPermissonOrg(@RequestParam("tenantId") String tenantId, @RequestParam("companyOrgId") Integer companyOrgId, @RequestParam("deptOrgId") Integer deptOrgId);
+
     /**
     * 日志保存(仅设备增删改)
     * @author Andy
@@ -39,17 +52,7 @@ public interface UserCenterClient {
     @PostMapping("/org/getAllByTenantId")
     List<Org> getAllByTenantId();
 
-    /**
-    * findUserIdsByPermissonOrg
-    * @author Andy
-    * @date 11:33 2021/8/18
-    * @param tenantId:
-    * @param companyOrgId:
-    * @param deptOrgId:
-    * @return java.util.List<java.lang.Integer>
-    **/
-    @PostMapping("/user/findUserIdsByPermissonOrg")
-    List<Integer> findUserIdsByPermissonOrg(@RequestParam("tenantId") String tenantId, @RequestParam("companyOrgId") Integer companyOrgId, @RequestParam("deptOrgId") Integer deptOrgId);
+
 
     /**
     * countCompanyByUser

+ 79 - 0
zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/component/MessageComponent.java

@@ -0,0 +1,79 @@
+package com.bz.zoneiot.water.web.component;
+
+import com.alibaba.fastjson.JSONObject;
+import com.bz.zoneiot.core.common.pojo.Message;
+import com.bz.zoneiot.core.utils.MqService;
+import com.bz.zoneiot.water.web.client.UserCenterClient;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.AmqpTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.util.Assert;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @author Andy
+ * @version V1.0
+ * @description: TODO
+ * @date 2021/10/25
+ **/
+@Component
+@Slf4j
+public class MessageComponent  {
+
+    @Resource
+    private MqService rabbitService;
+
+    @Autowired
+    private UserCenterClient userCenterClient;
+
+    /**
+    * 推送消息给租户所有的用户
+    * @author Andy
+    * @date 11:51 2021/11/11
+    * @param message:
+    * @param receiveExchangeName:
+    * @param dispatchRoutingKey:
+    * @return void
+    **/
+    public void sendMessageToAllTenantUsers(Message message, String receiveExchangeName, String dispatchRoutingKey){
+        Assert.notNull(message.getTenantId(), "租户ID为空");
+        Assert.notNull(message.getCompanyOrgId(), "公司ID为空");
+        try{
+            List<Integer> taskUsers = userCenterClient.findUserIdsByPermissonOrg(message.getTenantId() , message.getCompanyOrgId(), message.getCompanyOrgId());
+            if (taskUsers == null) {
+                return;
+            }
+            taskUsers.forEach(id -> {
+                message.setUserId(id);
+                this.send(message, receiveExchangeName, dispatchRoutingKey);
+            });
+        } catch (Exception e) {
+            log.error ("推送报警消息失败:{}",e);
+        }
+    }
+
+    /**
+    * 推送单个
+    * @author Andy
+    * @date 11:52 2021/11/11
+    * @param message:
+    * @param receiveExchangeName:
+    * @param dispatchRoutingKey:
+    * @return void
+    **/
+    public void sendMessageToUser(Message message, String receiveExchangeName, String dispatchRoutingKey){
+        Assert.notNull(message.getUserId(), "用户ID为空");
+        this.send(message, receiveExchangeName, dispatchRoutingKey);
+    }
+
+    private void send(Message message, String receiveExchangeName, String dispatchRoutingKey){
+        log.debug("消息发送 exchange={}  routingkey={} 用户id={}",receiveExchangeName, dispatchRoutingKey, message.getUserId());
+        rabbitService.send(receiveExchangeName, dispatchRoutingKey, JSONObject.toJSONString(message));
+    }
+
+
+}

+ 3 - 3
zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/config/FeignConfig.java

@@ -17,10 +17,12 @@ import javax.servlet.http.HttpServletRequest;
 @Configuration
 public class FeignConfig implements RequestInterceptor {
 
-
     @Override
     public void apply(RequestTemplate requestTemplate) {
         ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+        if (requestTemplate.url().indexOf("/user/findUserIdsByPermissonOrg") != -1 ){
+            return;
+        }
         if(attributes != null){
             HttpServletRequest request = attributes.getRequest();
             if(request != null){
@@ -28,6 +30,4 @@ public class FeignConfig implements RequestInterceptor {
             }
         }
     }
-
-
 }

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

@@ -0,0 +1,71 @@
+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){
+        if (sceneTypeEnum == null) {
+            return null;
+        }
+        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;
+        }
+    }
+}

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

@@ -3,11 +3,13 @@ package com.bz.zoneiot.water.web.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.bz.zoneiot.core.common.enums.StatusEnum;
+import com.bz.zoneiot.core.common.pojo.AjaxMessage;
 import com.bz.zoneiot.core.common.pojo.Message;
 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;
@@ -15,7 +17,10 @@ import com.bz.zoneiot.water.core.dao.DeviceSceneMapper;
 import com.bz.zoneiot.water.core.entity.AlarmDetailsEntity;
 import com.bz.zoneiot.water.core.entity.AlarmType;
 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;
@@ -23,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;
@@ -41,18 +47,18 @@ import java.util.UUID;
 @Log4j2
 public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
 
-    @Resource
-    private AmqpTemplate amqpTemplate;
-
-    @Autowired
-    private UserCenterClient userCenterClient;
-
     @Value("${receive.exchange.name}")
     private String receiveExchangeName;
 
     @Value("${dispath.routing.key}")
     private String dispathRoutingKey;
 
+    @Resource
+    private MessageConfig messageConfig;
+
+    @Resource
+    private MessageComponent messageComponent;
+
     @Resource
     private AlarmTypeDetailMapper alarmTypeDetailMapper;
 
@@ -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());
+        }
+    }
+
 
     /**
     * 转换实体
@@ -130,16 +151,18 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
     * @return java.util.List<AlarmDetailsEntity>
     **/
     private List<AlarmDetailsEntity> convert(AlarmDetailsAddDto dto){
-        List<AlarmDetailsEntity> result;
+        BigDecimal value;
+        String deviceName;
+        Integer sceneType;
+        String attrName = null;
         AlarmType alarmType = alarmTypeService.findByIotAlarmId(dto.getAlarmTypeId());
         if (alarmType == null) {
             log.error("【接收告警信息失败】:告警信息为空 ,请求参数:{}", dto.toString());
             return null;
         }
-        result = new ArrayList<>();
-        BigDecimal value;
-        String attrName = null;
-        String deviceName = null;
+        sceneType = alarmType.getSceneType();
+        Long alarmId = alarmTypeDetailMapper.selectLastAlarmId(alarmType.getId());
+        List<AlarmDetailsEntity> result = new ArrayList<>();
         // 离线告警
         if (alarmType.getAlarmCategory() == 2 || alarmType.getAttributeId() == null) {
             value = new BigDecimal("0");
@@ -155,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 != null) {
+                alarmDetailsEntity.setId(alarmId);
+            }
             alarmDetailsEntity.setAlarmStartTime(dto.getAlarmTime());
             alarmDetailsEntity.setAlarmContent(dto.getDescription());
 
@@ -181,48 +206,41 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
             alarmDetailsEntity.setState(AlarmStateEnum.REALTIME_ALARM.getCode());
             alarmDetailsEntity.setDateCreate(new Date());
             deviceName = sceneVo.getDeviceName();
-            sendMessage(alarmDetailsEntity, attrName, deviceName);
+            sendMessage(alarmDetailsEntity, alarmType.getAlarmCategory(), attrName, deviceName, sceneType);
             result.add(alarmDetailsEntity);
         }
 
         return result;
     }
 
-    private void sendMessage(AlarmDetailsEntity alarmDetailsEntity, 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);
+        } else {
+            jsonContent.put("状态", "离线");
+        }
         // 消息内容,如果需要动态使用,配合模板使用{key:value}
         message.setMessageContent(jsonContent.toJSONString());
         // 消息类型、模板id、渠道
-        message.setMessageType(1);
-        message.setMessageTemplateId(1);
+        message.setMessageType(category == 1 ? 1 : 2);
+        message.setMessageTemplateId(category == 1 ? 1 : 2);
         message.setChannel(0);
-        Integer companyOrgId = alarmDetailsEntity.getCompanyOrgId();
-        Integer departmentOrgId = alarmDetailsEntity.getDeptOrgId();
-        try{
-            List<Integer> taskUsers = userCenterClient.findUserIdsByPermissonOrg(alarmDetailsEntity.getTenantId(),companyOrgId,departmentOrgId);
-            if (taskUsers == null) {
-                return;
-            }
-            taskUsers.forEach(id -> {
-                message.setUserId(id);
-                this.send(message);
-            });
-        } catch (Exception e) {
-            log.error ("推送报警消息失败:{}",e);
-        }
+        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);
     }
 
-    private void send(Message message){
-        log.debug("消息发送 exchange={}  routingkey={} 用户id={}",receiveExchangeName,dispathRoutingKey,message.getUserId());
-        amqpTemplate.convertAndSend(receiveExchangeName, dispathRoutingKey, JSONObject.toJSONString(message));
-    }
 
 }