Browse Source

地图设置添加租户

yuejiaying 4 years ago
parent
commit
7970949f1a

+ 3 - 2
sms_water/src/main/java/com/huaxu/controller/MapSettingController.java

@@ -52,14 +52,15 @@ public class MapSettingController {
      * @param mapSetting 地图设置信息
      * @return
      */
-    @RequestMapping(value = "saveSystem", method = RequestMethod.POST)
+    @RequestMapping(value = "saveMap", method = RequestMethod.POST)
     @ApiOperation(value = "保存单条地图配置数据")
-    public AjaxMessage<Boolean> saveSystem(
+    public AjaxMessage<Boolean> saveMap(
             @ApiParam(value = "地图设置信息", required = true) @RequestBody MapSetting mapSetting) {
         LoginUser currentUser = UserUtil.getCurrentUser();
         MapSetting idSetting= mapSettingService.selectMap(mapSetting.getSceneTypeName(),currentUser.getId());
         Integer mapId=idSetting != null?idSetting.getId():null;
         Integer id = mapSetting.getId() != null?mapSetting.getId():mapId;
+        mapSetting.setTenantId(currentUser.getTenantId());
         mapSetting.setUserId(currentUser.getId());
         if(id==null){//没有查询到数据则新增
             mapSetting.setCreateBy(currentUser.getUsername());

+ 4 - 2
sms_water/src/main/java/com/huaxu/dto/MonitorDataDto.java

@@ -1,6 +1,7 @@
 package com.huaxu.dto;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -22,8 +23,6 @@ public class MonitorDataDto implements Serializable {
 
     @ApiModelProperty(value = "设备编号")
     private Integer deviceId;
-    @ApiModelProperty(value = "设备名称")
-    private Integer deviceName;
     @ApiModelProperty(value = "设备属性编号")
     private Integer attributeId;
     @ApiModelProperty(value = "设备属性名称")
@@ -36,4 +35,7 @@ public class MonitorDataDto implements Serializable {
     private String specsName;
     @ApiModelProperty(value = "是否报警 1报警 0正常")
     private Integer isAlarm;
+    @ApiModelProperty(value = "属性类型标记",hidden = true)
+    @JsonIgnore
+    private String attributeType;
 }

+ 5 - 0
sms_water/src/main/java/com/huaxu/entity/MapSetting.java

@@ -30,6 +30,11 @@ public class MapSetting implements Serializable {
     @ApiModelProperty(value = "主键")
     @TableId(type= IdType.AUTO)
     private Integer id;
+    /**
+     * 租户标识
+     */
+    @ApiModelProperty(value = "租户标识")
+    private String tenantId;
     /**
      * 用户编号
      */

+ 82 - 62
sms_water/src/main/resources/mapper/OnlineMonitorMapper.xml

@@ -15,8 +15,10 @@
             <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="attributeType" column="attribute_type" jdbcType="VARCHAR"/>
         </collection>
     </resultMap>
+
     <sql id="Base_Column_List">
         t1.id scene_Id,
         t1.scene_name ,
@@ -28,13 +30,25 @@
         t5.attribute_id ,
         ifnull(t5.remark, t5.`name`) attribute_name,
         t5.unit ,
-        if (t6.id is null, 0, 1) is_alarm
+        case when t5.attribute_id is  null then null when t6.id is null then 0 else 1 end is_alarm,
+        t5.attribute_type
     </sql>
 
-    <sql id="monitorDataJoins">
+    <sql id="sceneDeviceJoins">
         inner join sms_scene t2 on find_in_set(t1.id, t2.parent_scene_ids) and t2. status = 1
         inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
         left join sms_device t4 on t4.scene_id=t2.id
+    </sql>
+    <sql id="attributeJoins">
+        select a1.device_id,a1.attribute_id,a1.remark,a1.seq,a2.name,a2.unit,a2.attribute_type
+        from sms_device_parm a1
+        inner join sms_device_attribute a2 on a1.attribute_id=a2.id
+        where a1. status = 1 and a2.status = 1
+    </sql>
+    <sql id="alarmDetailsJoins">
+        inner join sms_alarm_details t6 on t6.device_id=t4.id and t6. status = 1
+    </sql>
+    <sql id="sceneAlarmJoins">
         left join (
             select substring_index(substring_index(a3.parent_scene_ids, ',', 2), ',', -1) one_scene_id,count(1) alarm_count
             from sms_device a1
@@ -43,72 +57,60 @@
             where a1.`status` = 1 group by one_scene_id
         )t7 on t7.one_scene_id=t1.id
     </sql>
+
     <!--查询实时报警信息-->
     <select id="selectAlarmDetails" resultType="com.huaxu.dto.AlarmDetailsDto">
         select
-        t3.scene_name as "sceneName",
-        t1.alarm_content as "alarmContent",
-        t1.alarm_start_time as "alarmStartTime"
-        from sms_alarm_details t1
-        inner join sms_device t2 on t1.device_id=t2.id and t2.`status`=1
-        inner join (
-            select a.id,a.scene_name,b.id c_id,b.scene_name c_scene_name
-            from sms_scene a
-            inner join sms_scene b on find_in_set(a.id, b.parent_scene_ids ) and b.status=1
-            inner join sms_scene_type s on s.id =a.scene_type_id and s.status=1
-            where a.parent_scene_id=0 and a.status=1 and s.scene_type_name=#{sceneTypeName}
-            <if test="sceneIds != null and sceneIds.size() > 0">
-                and b.id  in
-                <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
-                    #{item}
-                </foreach>
-            </if>
-            <if test="sceneName != null and sceneName != ''">
-                and a.scene_name  like concat('%',#{sceneName},'%')
-            </if>
-        )t3 on t2.scene_id=t3.c_id
-        where t1.`status`=1 and t1.state=1
-        order by t3.scene_name
+        t1.scene_name as "sceneName",
+        t5.alarm_content as "alarmContent",
+        t5.alarm_start_time as "alarmStartTime"
+        from sms_scene t1
+        <include refid="sceneDeviceJoins"/>
+        <include refid="alarmDetailsJoins"/>
+        where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{sceneTypeName} and t6.state=1
+        <if test="sceneIds != null and sceneIds.size() > 0">
+            and t1.id  in
+            <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        <if test="sceneName != null and sceneName != ''">
+            and t1.scene_name  like concat('%',#{sceneName},'%')
+        </if>
+        order by t1.scene_name
     </select>
     <!--查询实时报警数量-->
     <select id="selectAlarmCount" resultType="java.util.Map">
         select
-        t3.scene_name as "sceneName",
+        t1.scene_name as "sceneName",
         count(1) as "alalmCount"
-        from sms_alarm_details t1
-        inner join sms_device t2 on t1.device_id=t2.id and t2.`status`=1
-        inner join (
-            select a.id,a.scene_name,b.id c_id,b.scene_name c_scene_name
-            from sms_scene a
-            inner join sms_scene b on find_in_set(a.id, b.parent_scene_ids ) and b.status=1
-            inner join sms_scene_type s on s.id =a.scene_type_id and s.status=1
-            where a.parent_scene_id=0 and a.status=1 and s.scene_type_name=#{sceneTypeName}
-            <if test="sceneIds != null and sceneIds.size() > 0">
-                and b.id  in
-                <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
-                    #{item}
-                </foreach>
-            </if>
-            <if test="sceneName != null and sceneName != ''">
-                and a.scene_name  like concat('%',#{sceneName},'%')
-            </if>
-        )t3 on t2.scene_id=t3.c_id
-        where t1.`status`=1 and t1.state=1
-        group by t3.scene_name
-        order by count(1) desc
+        from sms_scene t1
+        <include refid="sceneDeviceJoins"/>
+        <include refid="alarmDetailsJoins"/>
+        where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{sceneTypeName} and t6.state=1
+        <if test="sceneIds != null and sceneIds.size() > 0">
+            and t1.id  in
+            <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        <if test="sceneName != null and sceneName != ''">
+            and t1.scene_name  like concat('%',#{sceneName},'%')
+        </if>
+        group by t1.scene_name
+        order by alalmCount desc
     </select>
     <!--查询地图悬浮数据-->
     <select id="selectMapSuspension" resultMap="monitorDataMap">
         select
         <include refid="Base_Column_List"/>
         from sms_scene t1
-        <include refid="monitorDataJoins"/>
+        <include refid="sceneDeviceJoins"/>
+        <include refid="sceneAlarmJoins"/>
         left join(
-            select a1.device_id,a1.attribute_id,a1.remark,a1.seq,a2.name,a2.unit from sms_device_parm a1
-            inner join sms_device_attribute a2 on a1.attribute_id=a2.id
-            where a1. status = 1 and a1.device_id is not null and a1.attribute_id is not null and a2.status = 1 and a1.is_suspension = 1
+            <include refid="attributeJoins"/> and a1.is_suspension = 1
         )t5 on t5.device_id=t4.id
-        left join sms_alarm_details t6 on t6.device_id = t4.id and t6.attribute_id = t5.attribute_id and t6.state = 1
+        left join sms_alarm_details t6 on t6.device_id=t4.id and t6. status = 1 and t6.attribute_id = t5.attribute_id and t6.state = 1
         where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{sceneTypeName}
         <if test="sceneIds != null and sceneIds.size() > 0">
             and t1.id  in
@@ -123,13 +125,12 @@
         select
         <include refid="Base_Column_List"/>
         from sms_scene t1
-        <include refid="monitorDataJoins"/>
+        <include refid="sceneDeviceJoins"/>
+        <include refid="sceneAlarmJoins"/>
         left join(
-            select a1.device_id,a1.attribute_id,a1.remark,a1.seq,a2.name,a2.unit from sms_device_parm a1
-            inner join sms_device_attribute a2 on a1.attribute_id=a2.id
-            where a1. status = 1 and a1.device_id is not null and a1.attribute_id is not null and a2.status = 1 and a1.is_map = 1
+            <include refid="attributeJoins"/> and a1.is_map = 1
         )t5 on t5.device_id=t4.id
-        left join sms_alarm_details t6 on t6.device_id = t4.id and t6.attribute_id = t5.attribute_id and t6.state = 1
+        left join sms_alarm_details t6 on t6.device_id=t4.id and t6. status = 1 and t6.attribute_id = t5.attribute_id and t6.state = 1
         where t1.parent_scene_id = 0 and t1. status = 1 and t1.id = #{sceneId}
         <if test="sceneIds != null and sceneIds.size() > 0">
             and t1.id  in
@@ -139,6 +140,7 @@
         </if>
         order by t1.scene_name,t5.seq
     </select>
+    <!--查询实时数据列表-->
     <select id="selectPage" resultType="com.huaxu.dto.OnlineDataDto">
         select t1.id scene_id,t1.scene_name
         from sms_scene t1
@@ -153,7 +155,7 @@
         </if>
 
     </select>
-    <!--查询实时报警数量-->
+    <!--查询设备报警分析-->
     <select id="selectAlarmStats" resultType="java.util.Map">
         select
         t4.id,
@@ -161,10 +163,8 @@
         count(1) as "alarmCount",
         sum(timestampdiff(minute,t5.alarm_start_time,ifnull(t5.alarm_end_time,now()))) as "alarmduration"
         from sms_scene t1
-        inner join sms_scene t2 on find_in_set(t1.id, t2.parent_scene_ids) and t2. status = 1
-        inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
-        inner join sms_device t4 on t4.scene_id=t2.id and t4.`status`=1
-        inner join sms_alarm_details t5 on t5.device_id=t4.id and t5. status = 1
+        <include refid="sceneDeviceJoins"/>
+        <include refid="alarmDetailsJoins"/>
         where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{sceneTypeName}
         <if test="sceneIds != null and sceneIds.size() > 0">
             and t1.id  in
@@ -177,4 +177,24 @@
         </if>
         group by t4.id,t4.device_name
     </select>
+    <!--查询场景对应参数数据-->
+    <select id="selectSceneParam" resultMap="monitorDataMap">
+        select
+        <include refid="Base_Column_List"/>
+        from sms_scene t1
+        <include refid="sceneDeviceJoins"/>
+        <include refid="sceneAlarmJoins"/>
+        left join(
+        <include refid="attributeJoins"/> and a2.attribute_type in(2,3,4,5,6,7,8,9,10,11,12,13,14)
+        )t5 on t5.device_id=t4.id
+        left join sms_alarm_details t6 on t6.device_id=t4.id and t6. status = 1 and t6.attribute_id = t5.attribute_id and t6.state = 1
+        where t1.parent_scene_id = 0 and t1. status = 1 and t1.id = #{sceneId}
+        <if test="sceneIds != null and sceneIds.size() > 0">
+            and t1.id  in
+            <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        order by t1.scene_name,t5.seq
+    </select>
 </mapper>