123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.huaxu.dao.OnlineMonitorMapper">
- <!-- 结果集 -->
- <resultMap type="com.huaxu.dto.MonitorDataCollectDto" id="monitorDataMap">
- <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
- <result property="sceneName" column="scene_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="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"/>
- <result property="attributeType" column="attribute_type" jdbcType="VARCHAR"/>
- <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
- <result property="sumValue" column="sum_value" jdbcType="VARCHAR"/>
- <result property="latestValue" column="latest_value" 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 ,
- case when t5.attribute_id is null then null when t6.id is null then 0 else 1 end is_alarm,
- t5.attribute_type,
- if (t5.device_id is null, null, t4.device_code) device_code
- </sql>
- <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 and t4. status = 1 and t4.enable_state=1
- </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
- 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 and a1.enable_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 one_scene_id
- )t7 on t7.one_scene_id=t1.id
- </sql>
- <!--查询实时报警信息-->
- <select id="selectAlarmDetails" resultType="com.huaxu.dto.AlarmDetailsDto">
- select
- t1.scene_name as "sceneName",
- t6.alarm_content as "alarmContent",
- t6.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 t1. enable_state = 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="sceneIds == null or sceneIds.size() == 0">
- and t1.id is null
- </if>
- <if test="sceneName != null and sceneName != ''">
- and t1.scene_name like concat('%',#{sceneName},'%')
- </if>
- <if test="tenantId != null and tenantId != ''">
- and t1.tenant_id = #{tenantId}
- </if>
- order by t1.scene_name
- </select>
- <!--查询实时报警数量-->
- <select id="selectAlarmCount" resultType="java.util.Map">
- select
- t1.scene_name as "sceneName",
- count(1) as "alalmCount"
- from sms_scene t1
- <include refid="sceneDeviceJoins"/>
- <include refid="alarmDetailsJoins"/>
- where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 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="sceneIds == null or sceneIds.size() == 0">
- and t1.id is null
- </if>
- <if test="sceneName != null and sceneName != ''">
- and t1.scene_name like concat('%',#{sceneName},'%')
- </if>
- <if test="tenantId != null and tenantId != ''">
- and t1.tenant_id = #{tenantId}
- </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="sceneDeviceJoins"/>
- <include refid="sceneAlarmJoins"/>
- left join(
- <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. 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. 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>
- order by t1.scene_name,t5.seq
- </select>
- <!--查询地图参数数据-->
- <select id="selectMapParam" resultMap="monitorDataMap">
- select
- <include refid="Base_Column_List"/>
- from sms_scene t1
- <include refid="sceneDeviceJoins"/>
- <include refid="sceneAlarmJoins"/>
- left join(
- <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. 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>
- <!--查询实时数据列表-->
- <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
- 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
- <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="onlineDataDto.sceneIds == null or onlineDataDto.sceneIds.size() == 0">
- and t1.id is null
- </if>
- <if test="onlineDataDto.sceneName != null and onlineDataDto.sceneName != ''">
- and t1.scene_name like concat('%',#{onlineDataDto.sceneName},'%')
- </if>
- <if test="onlineDataDto.tenantId != null and onlineDataDto.tenantId != ''">
- and t1.tenant_id = #{onlineDataDto.tenantId}
- </if>
- order by t1.date_create
- </select>
- <!--查询设备报警分析-->
- <select id="selectAlarmStats" resultType="java.util.Map">
- select
- t4.id,
- t4.device_name as "deviceName",
- count(1) as "alarmCount",
- sum(timestampdiff(minute,t6.alarm_start_time,ifnull(t6.alarm_end_time,now()))) as "alarmDuration"
- from sms_scene t1
- <include refid="sceneDeviceJoins"/>
- <include refid="alarmDetailsJoins"/>
- where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t1.id = #{id}
- <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 t6.alarm_start_time>DATE(NOW() + INTERVAL-#{days}+1 DAY)
- </if>
- group by t4.id,t4.device_name
- </select>
- <!--查询场景对应参数数据-->
- <select id="selectSceneParam" resultMap="monitorDataMap">
- select
- t1.id scene_Id,
- t1.scene_name ,
- t5.device_id,
- t5.attribute_id ,
- ifnull(t5.remark, t5.`name`) attribute_name,
- if(t6.id is null , 0 , 1 ) is_alarm,
- t5.attribute_type,
- if (t5.device_id is null, null, t4.device_code) device_code,
- t8.latest_value
- from sms_scene t1
- <include refid="sceneDeviceJoins"/>
- inner join(
- <include refid="attributeJoins"/>
- <if test="type == 1 ">
- and a2.attribute_type in(3,4,5,6)
- </if>
- <if test="type == 2 ">
- and a2.attribute_type in(2,3,4,5,6,7,8,9,10,11,12,13,14)
- </if>
- )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
- left join (
- select parent_scene_id,max(latest_value) latest_value
- from sms_day_report b1
- where b1.year = year(now() + interval-1 day) and b1.year = month(now() + interval-1 day) and b1.day = day(now() + interval-1 day)
- <if test="sceneIds != null and sceneIds.size() > 0">
- and b1.parent_scene_id in
- <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- group by parent_scene_id
- )t8 on t8.parent_scene_id = t1.id
- where t1.parent_scene_id = 0 and t1. status = 1
- <if test="sceneTypeName != null and sceneTypeName != '' ">
- and t3.scene_type_name = #{sceneTypeName}
- </if>
- <if test="sceneId != null and sceneId != '' ">
- and t1.id = #{sceneId}
- </if>
- <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="tenantId != null and tenantId != ''">
- and t1.tenant_id = #{tenantId}
- </if>
- order by t1.scene_name,t5.seq
- </select>
- </mapper>
|