123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645 |
- <?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.bz.smart_city.dao.AlarmStatMapper">
- <sql id="where">
- <where>
- 1=1
- <if test="params.statDay != null">
- and t1.stat_day = #{params.statDay}
- </if>
- <if test="params.siteId != null">
- and t1.site_id = #{params.siteId}
- </if>
- <if test="params.sysId != null">
- and t1.sys_id = #{params.sysId}
- </if>
- <if test="params.buildingId != null">
- and t1.building_id = #{params.buildingId}
- </if>
- <if test="params.buildingId == null">
- and t1.building_id != 0
- </if>
- <if test="params.floor != null">
- and t1.floor = #{params.floor}
- </if>
- <if test="params.alarmCategory != null and params.alarmCategory != ''">
- and t1.alarm_category = #{params.alarmCategory}
- </if>
- <if test="params.alarmType != null">
- and t1.alarm_type = #{params.alarmType}
- </if>
- <if test="params.handleStatus != null">
- and t1.handle_status = #{params.handleStatus}
- </if>
- <if test="params.startDate != null and params.startDate != 0">
- and t1.stat_day >= #{params.startDate}
- </if>
- <if test="params.endDate != null and params.endDate != 0">
- and t1.stat_day < #{params.endDate}
- </if>
- </where>
- </sql>
- <sql id="anotherWhere">
- <where>
- 1=1
- <if test="params.statDay != null">
- and t1.stat_day = #{params.statDay}
- </if>
- <if test="params.siteId != null and params.siteId != 0">
- and t1.site_id = #{params.siteId}
- </if>
- <if test="params.sysId != null and params.sysId != 0">
- and t1.sys_id = #{params.sysId}
- </if>
- <if test="params.buildingId != null and params.buildingId != 0">
- and t1.building_id = #{params.buildingId}
- </if>
- <if test='params.floor != null and params.floor != 0'>
- and t1.floor = #{params.floor}
- </if>
- <if test='params.alarmCategory != null and params.alarmCategory != "0"'>
- and t1.alarm_category = #{params.alarmCategory}
- </if>
- <if test="params.alarmType != null and params.alarmType != 0">
- and t1.alarm_type = #{params.alarmType}
- </if>
- <if test='params.handleStatus != null and params.handleStatus != "0" '>
- and t1.handle_status = #{params.handleStatus}
- </if>
- <if test="params.startDate != null and params.startDate != 0">
- and t1.alarm_time > #{params.startDate}
- </if>
- <if test="params.endDate != null and params.endDate != 0">
- and t1.alarm_time < #{params.endDate}
- </if>
- <if test="params.sysIds != null and params.sysIds.size != 0">
- and t1.sys_id in
- <foreach collection="params.sysIds" item="sysId" index="index" separator="," open="(" close=")">
- #{sysId}
- </foreach>
- </if>
- <if test="params.sites != null and params.sites.size() != 0">
- and t1.site_id in
- <foreach collection="params.sites" item="site" open="(" separator="," close=")">
- #{site.id}
- </foreach>
- </if>
-
-
- </where>
- </sql>
- <!-- 查询告警天表 -->
- <select id="queryAlarmStatForDay" resultType="java.util.HashMap">
- SELECT
- t1.stat_day as statDay,
- t1.site_id as siteId,
- t4.`name` as siteName,
- t1.sys_id as sysId,
- t2.channel_name as sysName,
- t1.building_id as buildingId,
- t3.`name` as buildingName,
- t1.alarm_type as alarmTypeCode,
- t5.`name` as alarmTypeName,
- t1.alarm_category as alarmCategoryCode,
- t6.config_name as alarmCategoryName,
- t1.floor as floor,
- t1.handle_status as handlStatus,
- t7.config_name as handleStatusName,
- t1.alarm_times as alarmTimes,
- t1.alarm_device_num as alarmDeviceNumber
- FROM
- sc_stat_device_error_day t1
- LEFT JOIN sc_channel t2 ON ( t1.sys_id = t2.id )
- LEFT JOIN sc_building t3 ON ( t1.building_id = t3.id )
- LEFT JOIN sc_site t4 ON ( t1.site_id = t4.id )
- LEFT JOIN sc_alarm_type t5 ON ( t1.alarm_type = t5.id )
- LEFT JOIN sc_config_t t6 ON ( t1.alarm_category = t6.config_value AND t6.parent_id = 4)
- LEFT JOIN sc_config_t t7 ON ( t1.handle_status = t7.config_value AND t7.parent_id = 1)
- <include refid="where" />
- ${params.orderBy}
- <if test="limit != null and limit != 0">
- limit #{offset}, #{limit}
- </if>
- </select>
- <!-- 查询告警7天表 -->
- <select id="queryAlarmStatFor7Day" resultType="java.util.HashMap">
- SELECT
- t1.stat_day as statDay,
- t1.site_id as siteId,
- t4.`name` as siteName,
- t1.sys_id as sysId,
- t2.channel_name as sysName,
- t1.building_id as buildingId,
- t3.`name` as buildingName,
- t1.alarm_type as alarmTypeCode,
- t5.`name` as alarmTypeName,
- t1.alarm_category as alarmCategoryCode,
- t6.config_name as alarmCategoryName,
- t1.floor as floor,
- t1.handle_status as handlStatus,
- t7.config_name as handleStatusName,
- t1.alarm_times as alarmTimes,
- t1.alarm_device_num as alarmDeviceNumber
- FROM
- sc_stat_device_error_7day t1
- LEFT JOIN sc_channel t2 ON ( t1.sys_id = t2.id )
- LEFT JOIN sc_building t3 ON ( t1.building_id = t3.id )
- LEFT JOIN sc_site t4 ON ( t1.site_id = t4.id )
- LEFT JOIN sc_alarm_type t5 ON ( t1.alarm_type = t5.id )
- LEFT JOIN sc_config_t t6 ON ( t1.alarm_category = t6.config_value AND t6.parent_id = 4)
- LEFT JOIN sc_config_t t7 ON ( t1.handle_status = t7.config_value AND t7.parent_id = 1)
- <include refid="where" />
- ${params.orderBy}
- <if test="limit != null and limit != 0">
- limit #{offset}, #{limit}
- </if>
- </select>
- <!-- 查询告警30天表 -->
- <select id="queryAlarmStatFor30Day" resultType="java.util.HashMap">
- SELECT
- t1.stat_day as statDay,
- t1.site_id as siteId,
- t4.`name` as siteName,
- t1.sys_id as sysId,
- t2.channel_name as sysName,
- t1.building_id as buildingId,
- t3.`name` as buildingName,
- t1.alarm_type as alarmTypeCode,
- t5.`name` as alarmTypeName,
- t1.alarm_category as alarmCategoryCode,
- t6.config_name as alarmCategoryName,
- t1.floor as floor,
- t1.handle_status as handlStatus,
- t7.config_name as handleStatusName,
- t1.alarm_times as alarmTimes,
- t1.alarm_device_num as alarmDeviceNumber
- FROM
- sc_stat_device_error_30day t1
- LEFT JOIN sc_channel t2 ON ( t1.sys_id = t2.id )
- LEFT JOIN sc_building t3 ON ( t1.building_id = t3.id )
- LEFT JOIN sc_site t4 ON ( t1.site_id = t4.id )
- LEFT JOIN sc_alarm_type t5 ON ( t1.alarm_type = t5.id )
- LEFT JOIN sc_config_t t6 ON ( t1.alarm_category = t6.config_value AND t6.parent_id = 4)
- LEFT JOIN sc_config_t t7 ON ( t1.handle_status = t7.config_value AND t7.parent_id = 1)
- <include refid="where" />
- ${params.orderBy}
- <if test="limit != null and limit != 0">
- limit #{offset}, #{limit}
- </if>
- </select>
-
- <!-- 查询原始记录表 -->
- <select id="queryAlarmBuilding" resultType="java.util.HashMap">
- SELECT
- t1.building_id as buildingId,
- t2.name as buildingName,
- count(1) as alarmTimes
- FROM
- sc_device_error t1
- LEFT JOIN sc_building t2 ON ( t1.building_id = t2.id)
- <if test="params.programItems != null and params.programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = t1.device_id and sdd.status = 1)</if>
- <include refid="anotherWhere" />
- and t1.status = 1 and t1.sys_id != -99
- <if test="params.programItems != null and params.programItems.size() != 0"> and
- <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
- sdd.${item.dimensionCode} = #{item.dimensionValue}
- </foreach>
- </if>
- GROUP BY t1.building_id
- ${params.orderBy}
- <if test="limit != null and limit != 0">
- limit #{offset}, #{limit}
- </if>
- </select>
- <select id="queryAlarmCategory" resultType="java.util.HashMap">
- SELECT
- DATE_FORMAT(t1.alarm_time,'%Y%m%d') as statDay,
- t1.alarm_category as alarmCategoryCode,
- t2.config_name as alarmCategoryName,
- count( 1 ) as alarmTimes
- FROM
- sc_device_error t1
- LEFT JOIN sc_config_t t2 ON ( t1.alarm_category = t2.config_value AND t2.parent_id = 4 )
- <include refid="anotherWhere" />
- and t1.status = 1
- <if test='params.programItems != null and params.programItems.size() != 0' >
- and EXISTS (
- select 1 from
- (select
- distinct df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud WHERE ud.device_id = t1.device_id)
- </if>
- GROUP BY
- DATE_FORMAT(t1.alarm_time,'%Y%m%d'),t1.alarm_category,t2.config_name
- </select>
- <select id="queryAlarmCategoryStat" resultType="java.util.HashMap">
- SELECT
- t1.alarm_category as alarmCategoryCode,
- t2.config_name as alarmCategoryName,
- count( 1 ) as alarmTimes
- FROM
- sc_device_error t1
- LEFT JOIN sc_config_t t2 ON ( t1.alarm_category = t2.config_value AND t2.parent_id = 4 )
- <include refid="anotherWhere" />
- and t1.status = 1
- GROUP BY
- t1.alarm_category,t2.config_name
- </select>
- <select id="queryAlarmStatus" resultType="java.util.HashMap">
- SELECT
- t1.handle_status as handlStatus,
- t2.config_name as handleStatusName,
- count(1) as alarmDeviceNumber
- FROM
- sc_device_error t1
- LEFT JOIN sc_config_t t2 ON ( t1.handle_status = t2.config_value AND t2.parent_id = 1 )
- <if test="params.programItems != null and params.programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = t1.device_id and sdd.status = 1)</if>
- <include refid="anotherWhere" />
- and t1.status = 1
- <!-- 添加权限控制 -->
- <if test="params.programItems != null and params.programItems.size() != 0"> and
- <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
- sdd.${item.dimensionCode} = #{item.dimensionValue}
- </foreach>
- </if>
- GROUP BY
- t1.handle_status,t2.config_name
- </select>
- <select id="queryAlarmType" resultType="java.util.HashMap">
- SELECT
- t1.alarm_type_id AS alarmTypeCode,
- t2.`name` AS alarmTypeName,
- count(1) as alarmDeviceNumber
- FROM
- sc_device_error t1
- LEFT JOIN sc_alarm_type t2 ON ( t1.alarm_type_id = t2.id )
- <if test="params.programItems != null and params.programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = t1.device_id and sdd.status = 1)</if>
- <include refid="anotherWhere" />
- and t1.status = 1
- <!-- 添加权限控制 -->
- <if test="params.programItems != null and params.programItems.size() != 0"> and
- <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
- sdd.${item.dimensionCode} = #{item.dimensionValue}
- </foreach>
- </if>
- GROUP BY
- t1.alarm_type_id,t2.`name`
- </select>
- <select id="queryDeviceStatus" resultType="java.util.HashMap">
- SELECT
- t1.device_status as statusCode,
- t2.config_name as statusName,
- COUNT(t1.device_no) as numberOfDevice
- FROM
- sc_device t1
- LEFT JOIN sc_config_t t2 ON ( t1.device_status = t2.config_value AND t2.parent_id = 7 )
- <if test="params.programItems != null and params.programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = t1.id and sdd.status = 1)</if>
- <include refid="anotherWhere" />
- <if test="params.programItems != null and params.programItems.size() != 0"> and
- <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
- sdd.${item.dimensionCode} = #{item.dimensionValue}
- </foreach>
- </if>
- and t1.sys_id != -99
- and t1.status = 1
- and t1.building_id is not null
- GROUP BY t1.device_status,t2.config_name
- </select>
- <select id="queryAlarmHandleType" resultType="java.util.HashMap">
- SELECT
- t1.handle_type as handleTypeCode,
- t2.config_name as handleTypeName,
- count(DISTINCT t1.device_id) as numberOfDevice
- FROM
- sc_device_error_handle t1
- LEFT JOIN sc_config_t t2 on(t1.handle_type = t2.config_value and t2.parent_id = 13 )
- <include refid="anotherWhere" />
- and t1.status = 1
- GROUP BY t1.handle_type, t2.config_name
- </select>
-
- <select id="queryAlarmIsHandleStatByAdmin" resultType="com.bz.smart_city.entity.AlarmIsHandledStat">
- SELECT
- count(1) as times,
- count(distinct t1.device_no) as count,
- t1.handle_status as is_handle_value,
- t2.config_name as is_handle_name
- FROM
- sc_device_error t1
- LEFT JOIN sc_config_t t2 ON ( t1.handle_status = t2.config_value AND t2.parent_id = 1 )
- <include refid="anotherWhere" />
- and t1.`status` = 1
- group by t1.handle_status, t2.config_name
- </select>
-
- <select id="queryAlarmIsHandleStatByUser" resultType="com.bz.smart_city.entity.AlarmIsHandledStat">
- SELECT
- count( 1 ) AS times,
- count( DISTINCT t1.device_no ) AS count,
- t1.handle_status AS is_hanlde_value,
- t2.config_name AS is_handle_name
- FROM
- sc_device_error t1
- LEFT JOIN sc_config_t t2 ON ( t1.handle_status = t2.config_value AND t2.parent_id = 1 )
- <include refid="anotherWhere" />
- and t1.`status` = 1
- <if test='params.programItems != null and params.programItems.size() != 0' >
- and EXISTS (
- select 1 from
- (select
- distinct df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud WHERE ud.device_id = t1.device_id)
- </if>
- <!--
- AND EXISTS ( SELECT 1 FROM v_sc_user_device WHERE user_id = #{params.userId} and device_no = t1.device_no )
- -->
- GROUP BY
- t1.handle_status,
- t2.config_name
- </select>
-
- <select id="queryDeviceTypeAndStatusStatByAdmin" resultType="com.bz.smart_city.entity.DeviceTypeAndStatusStat">
- SELECT
- count(1) as total ,
- t1.device_type as device_type_id,
- dt.equipment_type as device_type_name,
- SUM(IF(t1.device_status = 1, 1, 0)) as normal_count,
- SUM(IF(t1.device_status != 1, 1, 0)) as abnormal_count,
- SUM(IF(t1.device_status = 2, 1, 0)) as fault_count,
- SUM(IF(t1.device_status = 4, 1, 0)) as early_warning_count,
- SUM(IF(t1.device_status = 5, 1, 0)) as not_enabled_count
- FROM
- sc_device t1
- left join sc_device_type dt on (t1.device_type = dt.id and dt.`status` = 1)
- WHERE
- t1.`status` = 1
- GROUP BY
- t1.device_type,dt.equipment_type
- </select>
-
- <select id="queryDeviceTypeAndStatusStatByUser" resultType="com.bz.smart_city.entity.DeviceTypeAndStatusStat">
- SELECT
- count(1) as total ,
- t1.device_type as device_type_id,
- dt.equipment_type as device_type_name,
- SUM(IF(t1.device_status = 1, 1, 0)) as normal_count,
- SUM(IF(t1.device_status != 1, 1, 0)) as abnormal_count,
- SUM(IF(t1.device_status = 2, 1, 0)) as fault_count,
- SUM(IF(t1.device_status = 4, 1, 0)) as early_warning_count,
- SUM(IF(t1.device_status = 5, 1, 0)) as not_enabled_count
- FROM
- sc_device t1
- <!--
- inner join v_sc_user_device t2 on (t1.device_no = t2.device_no and t2.user_id = #{params.userId})
- -->
- left join sc_device_type dt on (t1.device_type = dt.id and dt.`status` = 1)
- <if test="params.programItems != null and params.programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = t1.id and sdd.status = 1)</if>
- <include refid="anotherWhere" />
- and t1.sys_id != -99
-
- <!--
- <if test='params.programItems != null and params.programItems.size() != 0' >
- and EXISTS (
- select 1 from
- (select
- distinct df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud WHERE ud.device_id = t1.id)
- </if>
- -->
- and t1.`status` = 1
- <if test="params.programItems != null and params.programItems.size() != 0"> and
- <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
- sdd.${item.dimensionCode} = #{item.dimensionValue}
- </foreach>
- </if>
- GROUP BY
- t1.device_type,dt.equipment_type
- </select>
-
- <select id="queryAlarmTypeStatByAdmin" resultType="com.bz.smart_city.entity.AlarmTypeStat">
- select
- count(distinct t1.device_no) as number_of_alarm_device,
- count(1) as alarm_times,
- t2.name as alarm_type_name
- FROM
- sc_device_error t1
- left join sc_alarm_type t2 on (t1.alarm_type_id = t2.id)
- <include refid="anotherWhere" />
- and t1.`status` = 1
- GROUP BY alarm_type_name
- order by alarm_times desc
- </select>
-
- <select id="queryAlarmTypeStatByUser" resultType="com.bz.smart_city.entity.AlarmTypeStat">
- SELECT
- sum( number_of_alarm_device ) as number_of_alarm_device,
- sum( alarm_times ) AS alarm_times,
- t2.`name` as alarm_type_name
- FROM
- (
- SELECT
- count( DISTINCT t1.device_no ) AS number_of_alarm_device,
- count( 1 ) AS alarm_times,
- t1.alarm_type_id
- FROM
- sc_device_error t1 FORCE INDEX ( alarm_time )
- <include refid="anotherWhere" />
- and t1.`status` = 1
- <if test="params.buildingIds != null and params.buildingIds.size() != 0">
- and t1.building_id in <foreach collection="params.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- GROUP BY
- t1.alarm_type_id
- ) tmp
- LEFT JOIN sc_alarm_type t2 ON ( tmp.alarm_type_id = t2.id )
- GROUP BY
- t2.`name`
- ORDER BY
- alarm_times DESC
-
-
-
-
- <!--
-
- select
- count(distinct t1.device_no) as number_of_alarm_device,
- count(1) as alarm_times,
- t2.name as alarm_type_name
- FROM
- sc_device_error t1
- left join sc_alarm_type t2 on (t1.alarm_type_id = t2.id)
- <include refid="anotherWhere" />
- and t1.`status` = 1
- <if test="params.buildingIds != null and params.buildingIds.size() != 0">
- and t1.building_id in <foreach collection="params.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- -->
- <!--
- <if test='params.programItems != null and params.programItems.size() != 0' >
- and EXISTS (
- select 1 from
- (select
- distinct df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud WHERE ud.device_id = t1.device_id)
- </if>
- -->
- <!--
- AND EXISTS ( SELECT 1 FROM v_sc_user_device WHERE user_id = #{params.userId} and device_no = t1.device_no )
-
- GROUP BY alarm_type_name
- order by alarm_times desc
- -->
- </select>
-
- <select id="queryAlarmCategoryStatByAdmin" resultType="com.bz.smart_city.entity.AlarmCategoryStat">
- SELECT
- DATE_FORMAT(t1.alarm_time,'%Y%m%d') as stat_date,
- t1.alarm_category as alarm_category_code,
- t2.config_name as alarm_category_name,
- count( 1 ) as alarm_times
- FROM
- sc_device_error t1
- LEFT JOIN sc_config_t t2 ON ( t1.alarm_category = t2.config_value AND t2.parent_id = 4 )
- <include refid="anotherWhere" />
- and t1.status = 1
- GROUP BY
- DATE_FORMAT(t1.alarm_time,'%Y%m%d'),t1.alarm_category,t2.config_name
- order by stat_date asc
- </select>
-
- <select id="queryAlarmCategoryStatByUser" resultType="com.bz.smart_city.entity.AlarmCategoryStat">
- SELECT
- stat_date as stat_date,
- alarm_category as alarm_category_code,
- t2.config_name as alarm_category_name,
- alarm_times
- FROM
- (
- SELECT
- DATE_FORMAT( t1.alarm_time, '%Y%m%d' ) AS stat_date,
- t1.alarm_category,
- count( 1 ) AS alarm_times
- FROM
- sc_device_error t1 FORCE INDEX ( alarm_time )
- <include refid="anotherWhere" />
- and t1.status = 1
- <if test="params.buildingIds != null and params.buildingIds.size() != 0">
- and t1.building_id in <foreach collection="params.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- GROUP BY
- DATE_FORMAT( t1.alarm_time, '%Y%m%d' ),
- t1.alarm_category
- ) tmp
- LEFT JOIN sc_config_t t2 ON ( tmp.alarm_category = t2.config_value AND t2.parent_id = 4 )
- ORDER BY
- stat_date ASC
- <!--
-
- SELECT
- DATE_FORMAT(t1.alarm_time,'%Y%m%d') as stat_date,
- t1.alarm_category as alarm_category_code,
- t2.config_name as alarm_category_name,
- count( 1 ) as alarm_times
- FROM
- sc_device_error t1
- LEFT JOIN sc_config_t t2 ON ( t1.alarm_category = t2.config_value AND t2.parent_id = 4 )
- <include refid="anotherWhere" />
- and t1.status = 1
- <if test="params.buildingIds != null and params.buildingIds.size() != 0">
- and t1.building_id in <foreach collection="params.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- -->
- <!--
- <if test='params.programItems != null and params.programItems.size() != 0' >
- and EXISTS (
- select 1 from
- (select
- distinct df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud WHERE ud.device_id = t1.device_id)
- </if>
- -->
- <!--
- AND EXISTS ( SELECT 1 FROM v_sc_user_device WHERE user_id = #{params.userId} and device_no = t1.device_no )
-
- GROUP BY
- DATE_FORMAT(t1.alarm_time,'%Y%m%d'),t1.alarm_category,t2.config_name
- order by stat_date asc
- -->
- </select>
-
- <select id="queryAlarmHandleStatByAdmin" resultType="com.bz.smart_city.entity.AlarmHandleStat">
- SELECT
- DATE_FORMAT( t1.alarm_time, '%Y%m%d' ) as stat_date,
- count( 1 ) as total_alarm_times,
- SUM(IF(t1.`handle_status` = 1, 1, 0)) as handled_alarm_times,
- SUM(IF(t1.`handle_status` = 2, 1, 0)) as unhandle_alarm_times,
- CONCAT(FORMAT(SUM(IF(t1.`handle_status` = 2, 1, 0))/ COUNT(1)*100, 2), '%') as unhandle_percentage,
- CONCAT(FORMAT(SUM(IF(t1.`handle_status` = 1, 1, 0))/ COUNT(1)*100, 2), '%') as handled_percentage
- FROM
- sc_device_error t1
- <include refid="anotherWhere" />
- AND t1.STATUS = 1
- GROUP BY
- DATE_FORMAT( t1.alarm_time, '%Y%m%d' )
- order by stat_date asc
- </select>
-
- <select id="queryAlarmHandleStatByUser" resultType="com.bz.smart_city.entity.AlarmHandleStat">
- SELECT
- DATE_FORMAT( t1.alarm_time, '%Y%m%d' ) as stat_date,
- count( 1 ) as total_alarm_times,
- SUM(IF(t1.`handle_status` = 1, 1, 0)) as handled_alarm_times,
- SUM(IF(t1.`handle_status` = 2, 1, 0)) as unhandle_alarm_times,
- CONCAT(FORMAT(SUM(IF(t1.`handle_status` = 2, 1, 0))/ COUNT(1)*100, 2), '%') as unhandle_percentage,
- CONCAT(FORMAT(SUM(IF(t1.`handle_status` = 1, 1, 0))/ COUNT(1)*100, 2), '%') as handled_percentage
- FROM
- sc_device_error t1
- <include refid="anotherWhere" />
- AND t1.STATUS = 1
- <if test="params.buildingIds != null and params.buildingIds.size() != 0">
- and t1.building_id in <foreach collection="params.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <!--
- AND EXISTS ( SELECT 1 FROM v_sc_user_device WHERE user_id = #{params.userId} and device_no = t1.device_no )
- -->
- <!--
- <if test='params.programItems != null and params.programItems.size() != 0' >
- and EXISTS (
- select 1 from
- (select
- distinct df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="params.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud WHERE ud.device_id = t1.device_id)
- </if>
- -->
- GROUP BY
- DATE_FORMAT( t1.alarm_time, '%Y%m%d' )
- order by stat_date asc
- </select>
- </mapper>
|