|
@@ -130,12 +130,12 @@
|
|
|
group by parent_scene_id
|
|
|
)t7 on t7.parent_scene_id=t1.id
|
|
|
<if test="flag == 1">
|
|
|
- left join (
|
|
|
- select parent_scene_id,count(distinct device_id) setting_device_count
|
|
|
- from sms_alarm_setting
|
|
|
- where alarm_type='状态报警' and status=1
|
|
|
- group by parent_scene_id
|
|
|
- )t10 on t7.parent_scene_id=t10.parent_scene_id
|
|
|
+ left join (
|
|
|
+ select parent_scene_id,count(distinct device_id) setting_device_count
|
|
|
+ from sms_alarm_setting
|
|
|
+ where alarm_type='状态报警' and status=1
|
|
|
+ group by parent_scene_id
|
|
|
+ )t10 on t7.parent_scene_id=t10.parent_scene_id
|
|
|
</if>
|
|
|
</sql>
|
|
|
|
|
@@ -276,11 +276,27 @@
|
|
|
</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,t1.address
|
|
|
from sms_scene t1
|
|
|
inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
|
|
|
+ left join(
|
|
|
+ select parent_scene_id,max(last_update_time) last_update_time
|
|
|
+ from sms_device_scene a1
|
|
|
+ left join sms_device a2 on a2.id=a1.device_id
|
|
|
+ where
|
|
|
+ <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
|
|
|
+ a1.scene_id in
|
|
|
+ <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
|
|
|
+ #{item}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="onlineDataDto.sceneIds == null or onlineDataDto.sceneIds.size() == 0">
|
|
|
+ a1.scene_id is null
|
|
|
+ </if>
|
|
|
+ group by parent_scene_id
|
|
|
+ )t4 on t1.id=t4.parent_scene_id
|
|
|
where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{onlineDataDto.sceneTypeName}
|
|
|
<if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
|
|
|
and t1.id in
|
|
@@ -297,7 +313,7 @@
|
|
|
<if test="onlineDataDto.tenantId != null and onlineDataDto.tenantId != ''">
|
|
|
and t1.tenant_id = #{onlineDataDto.tenantId}
|
|
|
</if>
|
|
|
- order by t1.date_create
|
|
|
+ order by t4.last_update_time desc
|
|
|
</select>
|
|
|
<!--查询设备报警分析-->
|
|
|
<select id="selectAlarmStats" resultType="java.util.Map">
|
|
@@ -344,6 +360,9 @@
|
|
|
<if test="type == 2 ">
|
|
|
and t5.parm_type in(2,3,4,5,6,7,8,9,10,11,12,13,14)
|
|
|
</if>
|
|
|
+ <if test="type == 5 ">
|
|
|
+ and t5.parm_type in(3,4,13,14)
|
|
|
+ </if>
|
|
|
<if test="sceneTypeName != null and sceneTypeName != '' ">
|
|
|
and t3.scene_type_name = #{sceneTypeName}
|
|
|
</if>
|
|
@@ -456,13 +475,29 @@
|
|
|
</select>
|
|
|
<!--统计设备合格数据-->
|
|
|
<select id="statsDeviceQualified" resultType="com.huaxu.dto.DeviceCountStatsDto">
|
|
|
- select t5.scene_type_name type,count(1) totalCount,sum(if(t7.device_id is null,0,1)) alarmCount,count(1)-sum(if(t7.device_id is null,0,1)) normalCount
|
|
|
+ select t5.scene_type_name type,count(1) totalCount,sum(if(t7.device_id is null,0,1)) alarmCount
|
|
|
+ <if test="flag == null or flag ==0">
|
|
|
+ ,count(1)-sum(if(t7.device_id is null,0,1)) normalCount
|
|
|
+ </if>
|
|
|
+ <if test="flag == 1">
|
|
|
+ ,sum(if(t8.device_id is null,0,1)) offlineCount
|
|
|
+ ,count(1)-sum(if(t7.device_id is null,0,1))-sum(if(t8.device_id is null,0,1)) normalCount
|
|
|
+ </if>
|
|
|
from sms_scene t1
|
|
|
<include refid="deviceInnerJoins"/>
|
|
|
left join(
|
|
|
- select a1.scene_id, a1.device_id from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1 and a1.alarm_type = '参数报警'
|
|
|
+ select a1.scene_id, a1.device_id from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1
|
|
|
+ <if test="sceneTypeName != null and sceneTypeName !=''">
|
|
|
+ and a1.alarm_type = '参数报警'
|
|
|
+ </if>
|
|
|
group by a1.scene_id, a1.device_id
|
|
|
)t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
|
|
|
+ <if test="flag == 1">
|
|
|
+ left join(
|
|
|
+ select a1.scene_id, a1.device_id from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1 and a1.alarm_type = '状态报警'
|
|
|
+ group by a1.scene_id, a1.device_id
|
|
|
+ )t8 on t8.scene_id=t2.scene_id and t8.device_id=t2.device_id
|
|
|
+ </if>
|
|
|
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 !=''">
|
|
@@ -577,7 +612,7 @@
|
|
|
and t6.device_name like concat('%', #{deviceName},'%')
|
|
|
</if>
|
|
|
</select>
|
|
|
- <!--查询管网实时数据列表-->
|
|
|
+ <!--分页查询管网实时数据列表-->
|
|
|
<select id="selectPipeNetPage" resultType="com.huaxu.dto.OnlineDataDto">
|
|
|
select t1.id scene_id,t1.scene_name,t6.id device_id,t6.device_code,t6.device_name,t6.address,if (t7.alarm_count>0, 1, 0) deviceState
|
|
|
from sms_scene t1
|
|
@@ -663,4 +698,98 @@
|
|
|
and t1.tenant_id = #{tenantId}
|
|
|
</if>
|
|
|
</select>
|
|
|
+ <!--查询实时数据列表-->
|
|
|
+ <select id="selectList" resultType="com.huaxu.dto.OnlineDataDto">
|
|
|
+ select t1.id scene_id,t1.scene_name,t1.address
|
|
|
+ ,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
|
|
|
+ from sms_scene t1
|
|
|
+ inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
|
|
|
+ left join(
|
|
|
+ select parent_scene_id,max(last_update_time) last_update_time
|
|
|
+ from sms_device_scene a1
|
|
|
+ left join sms_device a2 on a2.id=a1.device_id
|
|
|
+ where
|
|
|
+ <if test="sceneIds != null and sceneIds.size() > 0">
|
|
|
+ a1.scene_id in
|
|
|
+ <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
|
|
|
+ #{item}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="sceneIds == null or sceneIds.size() == 0">
|
|
|
+ a1.scene_id is null
|
|
|
+ </if>
|
|
|
+ group by parent_scene_id
|
|
|
+ )t4 on t1.id=t4.parent_scene_id
|
|
|
+ left join (
|
|
|
+ select parent_scene_id
|
|
|
+ ,sum(case when alarm_type='参数报警' then 1 else 0 end) alarm_count
|
|
|
+ ,sum(case when alarm_type='状态报警' then 1 else 0 end) offline_alarm_count
|
|
|
+ from sms_alarm_details a1
|
|
|
+ where a1.`status` = 1 and a1.state = 1
|
|
|
+ <if test="sceneIds != null and sceneIds.size() > 0">
|
|
|
+ and a1.scene_id in
|
|
|
+ <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
|
|
|
+ #{item}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ group by parent_scene_id
|
|
|
+ )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
|
|
|
+ where alarm_type='状态报警' and status=1
|
|
|
+ group by parent_scene_id
|
|
|
+ )t10 on t7.parent_scene_id=t10.parent_scene_id
|
|
|
+ where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{sceneTypeName}
|
|
|
+ <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="sceneIds == null or sceneIds.size() == 0">
|
|
|
+ and t1.id is null
|
|
|
+ </if>
|
|
|
+ <if test="tenantId != null and tenantId != ''">
|
|
|
+ and t1.tenant_id = #{tenantId}
|
|
|
+ </if>
|
|
|
+ <if test="sceneId != null and sceneId != ''">
|
|
|
+ and t1.id = #{sceneId}
|
|
|
+ </if>
|
|
|
+ <if test="companyOrgId != null and companyOrgId != ''">
|
|
|
+ and t1.company_org_id = #{companyOrgId}
|
|
|
+ </if>
|
|
|
+ order by field(scene_state,1,0,2),t4.last_update_time desc
|
|
|
+ </select>
|
|
|
+ <!--查询管网实时数据列表-->
|
|
|
+ <select id="selectPipeNetList" resultType="com.huaxu.dto.OnlineDataDto">
|
|
|
+ select t1.id scene_id,t1.scene_name,t6.id device_id,t6.device_code,t6.device_name,t6.address
|
|
|
+ ,case when t7.offline_alarm_count>0 then 2 when t7.alarm_count>0 then 1 else 0 end device_state
|
|
|
+ from sms_scene t1
|
|
|
+ <include refid="deviceInnerJoins"/>
|
|
|
+ left join(
|
|
|
+ select a1.scene_id, a1.device_id
|
|
|
+ ,sum(case when alarm_type='参数报警' then 1 else 0 end) alarm_count
|
|
|
+ ,sum(case when alarm_type='状态报警' then 1 else 0 end) offline_alarm_count
|
|
|
+ from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1 group by a1.scene_id, a1.device_id
|
|
|
+ )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
|
|
|
+ where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网' and t5.scene_type_name = #{sceneTypeName}
|
|
|
+ <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="sceneIds == null or sceneIds.size() == 0">
|
|
|
+ and t1.id is null
|
|
|
+ </if>
|
|
|
+ <if test="deviceId != null and deviceId != ''">
|
|
|
+ and t6.id = #{deviceId}
|
|
|
+ </if>
|
|
|
+ <if test="companyOrgId != null and companyOrgId != ''">
|
|
|
+ and t1.company_org_id = #{companyOrgId}
|
|
|
+ </if>
|
|
|
+ order by field(device_state,1,0,2),t6.last_update_time desc
|
|
|
+ </select>
|
|
|
</mapper>
|