|
@@ -8,14 +8,41 @@
|
|
|
<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="sceneState" column="scene_state" jdbcType="INTEGER"/>
|
|
|
<collection property="MonitorDataEntities" ofType="com.huaxu.dto.MonitorDataDto" javaType="list">
|
|
|
+ <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
|
|
|
<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"/>
|
|
|
</collection>
|
|
|
</resultMap>
|
|
|
+ <sql id="Base_Column_List">
|
|
|
+ t1.id scene_Id,
|
|
|
+ t1.scene_name ,
|
|
|
+ t1.point_x ,
|
|
|
+ t1.point_y,
|
|
|
+ t1.address ,
|
|
|
+ if (t7.alarm_count>0, 1, 0) scene_state,
|
|
|
+ t5.device_id,
|
|
|
+ t5.attribute_id ,
|
|
|
+ ifnull(t5.remark, t5.`name`) attribute_name,
|
|
|
+ t5.unit ,
|
|
|
+ if (t6.id is null, 0, 1) is_alarm
|
|
|
+ </sql>
|
|
|
|
|
|
+ <sql id="monitorDataJoins">
|
|
|
+ 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
|
|
|
+ left join (
|
|
|
+ select substring_index(substring_index(a3.parent_scene_ids, ',', 2), ',', -1) one_scene_id,count(1) alarm_count
|
|
|
+ from sms_device a1
|
|
|
+ inner join sms_alarm_details a2 on a1.id=a2.device_id and a2.`status` = 1 and a2.state = 1
|
|
|
+ inner join sms_scene a3 on a3.id=a1.scene_id and a3.`status` = 1
|
|
|
+ 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
|
|
@@ -73,66 +100,81 @@
|
|
|
<!--查询地图悬浮数据-->
|
|
|
<select id="selectMapSuspension" resultMap="monitorDataMap">
|
|
|
select
|
|
|
- t4.id scene_Id,
|
|
|
- t4.scene_name ,
|
|
|
- t4.point_x ,
|
|
|
- t4.point_y,
|
|
|
- t4.address ,
|
|
|
- t3.attribute_id ,
|
|
|
- ifnull(t3.remark, t2.`name`) attribute_Name,
|
|
|
- t2.unit ,
|
|
|
- if (t5.id is null, 0, 1) is_Alarm
|
|
|
- from sms_device t1
|
|
|
- inner join sms_device_attribute t2 on t1.device_type_id = t2.device_type_id and t2.`status` = 1
|
|
|
- inner join sms_device_parm t3 on t1.id = t3.device_id and t3.attribute_id = t2.id and t3.`status` = 1
|
|
|
- inner join (
|
|
|
- select a.id,a.scene_name,a.point_x,a.point_y,a.address,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>
|
|
|
- ) t4 on t1.scene_id = t4.c_id
|
|
|
- left join sms_alarm_details t5 on t5.device_id = t1.id and t5.attribute_id = t3.attribute_id and t5.state = 1
|
|
|
- where t1.`status` = 1 and t3.is_suspension = 1
|
|
|
- order by t4.scene_name,t3.seq
|
|
|
+ <include refid="Base_Column_List"/>
|
|
|
+ from sms_scene t1
|
|
|
+ <include refid="monitorDataJoins"/>
|
|
|
+ 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
|
|
|
+ )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
|
|
|
+ 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
|
|
|
+ <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
|
|
|
+ #{item}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ order by t1.scene_name,t5.seq
|
|
|
</select>
|
|
|
<!--查询地图参数数据-->
|
|
|
<select id="selectMapParam" resultMap="monitorDataMap">
|
|
|
select
|
|
|
- t4.id scene_Id,
|
|
|
- t4.scene_name ,
|
|
|
- t4.point_x ,
|
|
|
- t4.point_y,
|
|
|
- t4.address ,
|
|
|
- t3.attribute_id ,
|
|
|
- ifnull(t3.remark, t2.`name`) attribute_Name,
|
|
|
- t2.unit ,
|
|
|
- if (t5.id is null, 0, 1) is_Alarm
|
|
|
- from sms_device t1
|
|
|
- inner join sms_device_attribute t2 on t1.device_type_id = t2.device_type_id and t2.`status` = 1
|
|
|
- inner join sms_device_parm t3 on t1.id = t3.device_id and t3.attribute_id = t2.id and t3.`status` = 1
|
|
|
- inner join (
|
|
|
- select a.id,a.scene_name,a.point_x,a.point_y,a.address,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 a.id = #{sceneId}
|
|
|
+ <include refid="Base_Column_List"/>
|
|
|
+ from sms_scene t1
|
|
|
+ <include refid="monitorDataJoins"/>
|
|
|
+ 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
|
|
|
+ )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
|
|
|
+ where t1.parent_scene_id = 0 and t1. status = 1 and t1.id = #{sceneId}
|
|
|
<if test="sceneIds != null and sceneIds.size() > 0">
|
|
|
- and b.id in
|
|
|
+ and t1.id in
|
|
|
<foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
|
|
|
#{item}
|
|
|
</foreach>
|
|
|
</if>
|
|
|
- ) t4 on t1.scene_id = t4.c_id
|
|
|
- left join sms_alarm_details t5 on t5.device_id = t1.id and t5.attribute_id = t3.attribute_id and t5.state = 1
|
|
|
- where t1.`status` = 1 and t3.is_map = 1
|
|
|
- order by t4.scene_name,t3.seq
|
|
|
+ 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
|
|
|
+ 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
|
|
|
+ where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{onlineDataDto.sceneTypeName}
|
|
|
+ <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
|
|
|
+ and t1.id in
|
|
|
+ <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
|
|
|
+ #{item}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
|
|
|
+ </select>
|
|
|
+ <!--查询实时报警数量-->
|
|
|
+ <select id="selectAlarmStats" resultType="java.util.Map">
|
|
|
+ select
|
|
|
+ t4.id,
|
|
|
+ t4.device_name as "deviceName",
|
|
|
+ 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
|
|
|
+ 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
|
|
|
+ <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
|
|
|
+ #{item}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="days != null">
|
|
|
+ and t5.alarm_start_time>DATE(NOW() + INTERVAL-#{days}+1 DAY)
|
|
|
+ </if>
|
|
|
+ group by t4.id,t4.device_name
|
|
|
+ </select>
|
|
|
</mapper>
|