123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- <?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="latestValue" column="latest_value" jdbcType="VARCHAR"/>
- </collection>
- </resultMap>
- <!-- 设备结果集 -->
- <resultMap type="com.huaxu.dto.MonitorDataCollectDto" id="deviceDataMap">
- <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
- <result property="sceneName" column="scene_name" jdbcType="VARCHAR"/>
- <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
- <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
- <result property="deviceName" column="device_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="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 ,
- t5.device_id,
- t5.attribute_id ,
- ifnull(t5.remark, t9.`name`) attribute_name,
- t9.unit ,
- case when t5.attribute_id is null then null when t6.id is null then 0 else 1 end is_alarm,
- t5.parm_type attribute_type,
- if (t5.device_id is null, null, t4.device_code) device_code
- </sql>
- <sql id="sceneDeviceJoins">
- inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
- left join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
- left join sms_device t4 on t2.device_id=t4.id and t4. status = 1 and t4. enable_state = 1
- left join sms_device_parm t5 on t5.scene_id = t2.scene_id and t5.device_id=t2.device_id and t5. status = 1
- <if test="type == 3 ">
- and t5.is_suspension = 1
- </if>
- <if test="type == 4 ">
- and t5.is_map = 1
- </if>
- left join sms_device_attribute t9 on t5.attribute_id=t9.id and t9.status = 1
- left join sms_alarm_details t6 on t6.scene_id=t2.scene_id and t6.device_id=t2.device_id
- and t6.attribute_id=t5.attribute_id and t6.status = 1 and t6.state=1
- </sql>
- <sql id="sceneAlarmJoins">
- left join (
- select parent_scene_id,count(1) 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
- </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
- inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
- inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
- 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 t6.alarm_start_time desc
- </select>
- <!--查询实时报警数量-->
- <select id="selectAlarmCount" resultType="java.util.Map">
- select
- t1.scene_name as "sceneName",
- count(1) as "alalmCount"
- from sms_scene t1
- inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
- inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
- 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"/>,if (t7.alarm_count>0, 1, 0) scene_state
- from sms_scene t1
- <include refid="sceneDeviceJoins"/>
- <include refid="sceneAlarmJoins"/>
- 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"/>
- 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
- inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
- inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
- inner join sms_device t4 on t4.id=t6.device_id and t4.`status`=1 and t4. enable_state = 1
- 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
- <include refid="Base_Column_List"/>,t8.latest_value
- from sms_scene t1
- <include refid="sceneDeviceJoins"/>
- left join (
- select b1.device_id,b1.attribute_id,max(latest_value) latest_value
- from sms_day_report b1
- where b1.year = year(now() + interval-1 day) and b1.month = month(now() + interval-1 day) and b1.day = day(now() + interval-1 day)
- group by b1.device_id,b1.attribute_id
- )t8 on t8.device_id=t2.device_id and t8.attribute_id =t5.attribute_id
- where t1.parent_scene_id = 0 and t1. status = 1
- <if test="type == 1 ">
- and t5.parm_type in(3,4,5,6)
- </if>
- <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="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>
- <!--按管网名称分类查询设备数量-->
- <select id="selectDeviceCount" resultType="java.util.Map">
- select t1.id,t1.scene_name sceneName,sum(if(t5.id is null,0,1)) deviceCount
- from sms_scene t1
- inner join sms_scene_type t3 on t1.scene_type_id=t3.id and t3. status = 1
- left join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
- left join sms_device t6 on t2.device_id=t6.id and t6. status = 1
- left join sms_scene t4 on t2.scene_id=t4.id and t4. status = 1
- left join sms_scene_type t5 on t4.scene_type_id=t5.id and t5. status = 1 and t5.scene_type_name = #{sceneTypeName}
- where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网'
- <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="sceneId != null">
- and t1.id = #{sceneId}
- </if>
- <if test="deviceName != null and deviceName != ''">
- and t6.device_name like concat('%', #{deviceName},'%')
- </if>
- group by t1.id,t1.scene_name
- </select>
- <!--查询设备地图参数数据-->
- <select id="selectDeviceMapParam" resultMap="deviceDataMap">
- select distinct t1.id device_id,t1.device_code,t1.device_name,t1.point_x,point_y,t1.address,t2.attribute_id, ifnull(t2.remark, t3.`name`) attribute_name,t3.unit,
- case when t2.attribute_id is null then null when t6.id is null then 0 else 1 end is_alarm, if (t4.alarm_count>0, 1, 0) scene_state
- from sms_device t1
- left join sms_device_parm t2 on t2.device_id=t1.id and t2.is_map=1
- left join sms_device_attribute t3 on t2.attribute_id=t3.id
- left join (
- select a1.device_id,count(1) alarm_count from sms_alarm_details a1 where a1.device_id= #{deviceId} and a1.`status` = 1 and a1.state = 1
- )t4 on t4.device_id=t1.id
- left join sms_alarm_details t6 on t6.device_id=t1.id and t6.attribute_id=t2.attribute_id and t6.status = 1 and t6.state=1
- where t1. status = 1 and t1. enable_state = 1 and t1.id= #{deviceId}
- </select>
- </mapper>
|