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