1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168 |
- <?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.StatMeterReadRateByBuildingMapper">
- <!--auto generated Code-->
- <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.StatMeterReadRateByBuilding">
- <result column="stat_day" property="statDay" jdbcType="INTEGER"/>
- <result column="site_id" property="siteId" jdbcType="INTEGER"/>
- <result column="channel_id" property="channelId" jdbcType="INTEGER"/>
- <result column="customer_id" property="customerId" jdbcType="INTEGER"/>
- <result column="building_id" property="buildingId" jdbcType="INTEGER"/>
- <result column="device_count" property="deviceCount" jdbcType="INTEGER"/>
- <result column="read_times" property="readTimes" jdbcType="INTEGER"/>
- <result column="real_read_times" property="realReadTimes" jdbcType="INTEGER"/>
- <result column="un_read_times" property="unReadTimes" jdbcType="INTEGER"/>
- <result column="read_rate" property="readRate" jdbcType="DECIMAL"/>
- <result column="date_create" property="dateCreate" jdbcType="TIMESTAMP"/>
- <result column="date_update" property="dateUpdate" jdbcType="TIMESTAMP"/>
- </resultMap>
- <!--auto generated Code-->
- <sql id="Base_Column_List">
- stat_day,
- site_id,
- channel_id,
- customer_id,
- building_id,
- device_count,
- read_times,
- real_read_times,
- un_read_times,
- read_rate,
- date_create,
- date_update
- </sql>
- <!--auto generated Code-->
- <insert id="insert" useGeneratedKeys="true" keyProperty="statMeterReadRateByBuilding.statDay">
- INSERT INTO sc_stat_meter_read_rate_by_building (
- stat_day,
- site_id,
- channel_id,
- customer_id,
- building_id,
- device_count,
- read_times,
- real_read_times,
- un_read_times,
- read_rate,
- date_create,
- date_update
- ) VALUES (
- #{statMeterReadRateByBuilding.statDay,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.siteId,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.channelId,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.customerId,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.buildingId,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.deviceCount,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.readTimes,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.realReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.unReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.readRate,jdbcType=DECIMAL},
- #{statMeterReadRateByBuilding.dateCreate,jdbcType=TIMESTAMP},
- #{statMeterReadRateByBuilding.dateUpdate,jdbcType=TIMESTAMP}
- )
- </insert>
- <!--auto generated Code-->
- <insert id="insertSelective" useGeneratedKeys="true" keyProperty="statMeterReadRateByBuilding.statDay">
- INSERT INTO sc_stat_meter_read_rate_by_building
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="statMeterReadRateByBuilding.statDay!=null"> stat_day,</if>
- <if test="statMeterReadRateByBuilding.siteId!=null"> site_id,</if>
- <if test="statMeterReadRateByBuilding.channelId!=null"> channel_id,</if>
- <if test="statMeterReadRateByBuilding.customerId!=null"> customer_id,</if>
- <if test="statMeterReadRateByBuilding.buildingId!=null"> building_id,</if>
- <if test="statMeterReadRateByBuilding.deviceCount!=null"> device_count,</if>
- <if test="statMeterReadRateByBuilding.readTimes!=null"> read_times,</if>
- <if test="statMeterReadRateByBuilding.realReadTimes!=null"> real_read_times,</if>
- <if test="statMeterReadRateByBuilding.unReadTimes!=null"> un_read_times,</if>
- <if test="statMeterReadRateByBuilding.readRate!=null"> read_rate,</if>
- <if test="statMeterReadRateByBuilding.dateCreate!=null"> date_create,</if>
- <if test="statMeterReadRateByBuilding.dateUpdate!=null"> date_update,</if>
- </trim>
- VALUES
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="statMeterReadRateByBuilding.statDay!=null">#{statMeterReadRateByBuilding.statDay,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByBuilding.siteId!=null">#{statMeterReadRateByBuilding.siteId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByBuilding.channelId!=null">#{statMeterReadRateByBuilding.channelId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByBuilding.customerId!=null">#{statMeterReadRateByBuilding.customerId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByBuilding.buildingId!=null">#{statMeterReadRateByBuilding.buildingId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByBuilding.deviceCount!=null">#{statMeterReadRateByBuilding.deviceCount,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByBuilding.readTimes!=null">#{statMeterReadRateByBuilding.readTimes,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByBuilding.realReadTimes!=null">#{statMeterReadRateByBuilding.realReadTimes,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByBuilding.unReadTimes!=null">#{statMeterReadRateByBuilding.unReadTimes,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByBuilding.readRate!=null">#{statMeterReadRateByBuilding.readRate,jdbcType=DECIMAL},
- </if>
- <if test="statMeterReadRateByBuilding.dateCreate!=null">#{statMeterReadRateByBuilding.dateCreate,jdbcType=TIMESTAMP},
- </if>
- <if test="statMeterReadRateByBuilding.dateUpdate!=null">#{statMeterReadRateByBuilding.dateUpdate,jdbcType=TIMESTAMP},
- </if>
- </trim>
- </insert>
- <!--auto generated Code-->
- <insert id="insertList">
- INSERT INTO sc_stat_meter_read_rate_by_building (
- stat_day,
- site_id,
- channel_id,
- customer_id,
- building_id,
- device_count,
- read_times,
- real_read_times,
- un_read_times,
- read_rate,
- date_create,
- date_update
- )VALUES
- <foreach collection="statMeterReadRateByBuildings" item="statMeterReadRateByBuilding" index="index" separator=",">
- (
- #{statMeterReadRateByBuilding.statDay,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.siteId,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.channelId,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.customerId,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.buildingId,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.deviceCount,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.readTimes,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.realReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.unReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByBuilding.readRate,jdbcType=DECIMAL},
- #{statMeterReadRateByBuilding.dateCreate,jdbcType=TIMESTAMP},
- #{statMeterReadRateByBuilding.dateUpdate,jdbcType=TIMESTAMP}
- )
- </foreach>
- </insert>
- <!--auto generated Code-->
- <update id="updateByPrimaryKeySelective">
- UPDATE sc_stat_meter_read_rate_by_building
- <set>
- <if test="statMeterReadRateByBuilding.siteId != null"> site_id= #{statMeterReadRateByBuilding.siteId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByBuilding.channelId != null"> channel_id= #{statMeterReadRateByBuilding.channelId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByBuilding.customerId != null"> customer_id= #{statMeterReadRateByBuilding.customerId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByBuilding.buildingId != null"> building_id= #{statMeterReadRateByBuilding.buildingId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByBuilding.deviceCount != null"> device_count= #{statMeterReadRateByBuilding.deviceCount,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByBuilding.readTimes != null"> read_times= #{statMeterReadRateByBuilding.readTimes,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByBuilding.realReadTimes != null"> real_read_times= #{statMeterReadRateByBuilding.realReadTimes,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByBuilding.unReadTimes != null"> un_read_times= #{statMeterReadRateByBuilding.unReadTimes,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByBuilding.readRate != null"> read_rate= #{statMeterReadRateByBuilding.readRate,jdbcType=DECIMAL},</if>
- <if test="statMeterReadRateByBuilding.dateCreate != null"> date_create= #{statMeterReadRateByBuilding.dateCreate,jdbcType=TIMESTAMP},</if>
- <if test="statMeterReadRateByBuilding.dateUpdate != null"> date_update= #{statMeterReadRateByBuilding.dateUpdate,jdbcType=TIMESTAMP}</if>
- </set>
- WHERE stat_day = #{statMeterReadRateByBuilding.statDay,jdbcType=INTEGER}
- </update>
-
- <sql id="where_clause">
- WHERE 1 = 1
- <!-- 表类型 -->
- <if test="param.channelId != null and param.channelId != 0">
- and rb.channel_id = #{param.channelId}
- </if>
- <!-- 数据权限 -->
- <if test="param.siteId != null and param.siteId != 0 "> and rb.site_id = #{param.siteId} </if>
- <!--
- <if test="param.sites != null and param.sites.size() != 0">
- and rb.site_id in
- <foreach collection="param.sites" item="site" open="(" separator="," close=")">
- #{site.id}
- </foreach>
- </if>
-
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and rb.building_id in (
- select c.id
- from
- sc_building c
- where 1 = 1
- and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- <if test = 'item.dimensionCode == "PROVINCE" '>
- c.province = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "CITY" '>
- c.city = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "REGION" '>
- c.region = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "COMMUNITY" '>
- c.community = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "BUILDING" '>
- c.id = #{item.dimensionValue}
- </if>
- </foreach>
- )
- </if>
- -->
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and
- <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- <if test = 'item.dimensionCode == "PROVINCE" or item.dimensionCode == "CITY" or item.dimensionCode == "REGION" or item.dimensionCode == "COMMUNITY" '>
- b.${item.dimensionCode} = #{item.dimensionValue}
- </if>
- <if test='item.dimensionCode == "BUILDING" '>
- b.id = #{item.dimensionValue}
- </if>
- <if test='item.dimensionCode == "CUSTOMER" '>
- c.id = #{item.dimensionValue}
- </if>
- </foreach>
- </if>
- <if test = "param.statDay != null and param.statDay != 0">and rb.stat_day = #{param.statDay}</if>
- <if test = "param.startDate != null and param.startDate != 0"> and rb.stat_day >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and rb.stat_day <![CDATA[ <= ]]> #{param.endDate}</if>
- <if test = "param.beginRate != null "> and rb.read_rate >= #{param.beginRate}</if>
- <if test = "param.endRate != null "> and rb.read_rate <![CDATA[ <= ]]> #{param.endRate}</if>
- <if test = "param.custormerId != null"> and rb.customer_id = #{param.custormerId}</if>
- <if test = "param.communityId != null "> and b.community = #{param.communityId}</if>
- <if test = "param.buildingId != null and param.buildingId != 0 "> and rb.building_id = #{param.buildingId}</if>
- </sql>
- <sql id="base_query">
- SELECT
- rb.stat_day as stat_day,
- rb.building_id as building_id,
- b.`name` AS building_name,
- rb.device_count AS device_count,
- rb.read_times AS read_times,
- rb.real_read_times AS real_read_times,
- rb.un_read_times AS un_read_times,
- rb.read_rate AS read_rate,
- de.alarm_device_num AS alarm_device_num ,
- c.customer_name as customer_name
- FROM
- sc_stat_meter_read_rate_by_building rb
- LEFT JOIN sc_stat_device_error_day de ON (
- rb.stat_day = de.stat_day
- AND rb.site_id = de.site_id
- AND rb.channel_id = de.sys_id
- AND rb.building_id = de.building_id
- AND de.alarm_category = '0'
- AND de.alarm_type = 0
- AND de.handle_status = '0'
- )
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- </sql>
- <select id="summaryRateListByBuilding" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- select
- ifnull(SUM(tmp.device_count),0) as device_count,
- ifnull(SUM(tmp.read_times),0) as read_times,
- ifnull(SUM(tmp.real_read_times),0) as real_read_times,
- ifnull(SUM(tmp.un_read_times),0) as un_read_times,
- ifnull(SUM(tmp.alarm_device_num),0) as alarm_device_num,
- ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
- from (
- <include refid="base_query"></include>
- <include refid="where_clause"></include>
- ) tmp
- </select>
- <select id="analysisMeterReadRate" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- select
- tmp.stat_day as stat_day,
- ifnull(SUM(tmp.device_count),0) as device_count,
- ifnull(SUM(tmp.read_times),0) as read_times,
- ifnull(SUM(tmp.real_read_times),0) as real_read_times,
- ifnull(SUM(tmp.un_read_times),0) as un_read_times,
- ifnull(SUM(tmp.alarm_device_num),0) as alarm_device_num,
- ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
- from (
- <include refid="base_query"></include>
- <include refid="where_clause"></include>
- ) tmp
- group by tmp.stat_day
- </select>
- <select id="getRateListByBuilding" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_query"></include>
- <include refid="where_clause"></include>
- order by rb.stat_day desc
- </select>
- <!--按表类型查询时间范围内的抄表率数据统计-->
- <select id="getRateCountByTime" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
- SELECT
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(read_times) as read_times,
- SUM(real_read_times) as real_read_times,
- SUM(un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_stat_meter_read_rate_by_building a
- LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
- WHERE a.stat_day = #{startDate}
- AND b.`status` = 1
- <if test="siteId != null"> and a.site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- </select>
- <!--按表类型查询7天内的抄表率数据统计-->
- <select id="getRateCount7DayByTime" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
- SELECT
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building_7day where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(read_times) as read_times,
- SUM(real_read_times) as real_read_times,
- SUM(un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_stat_meter_read_rate_by_building_7day a
- LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
- WHERE a.stat_day = #{startDate}
- AND b.`status` = 1
- <if test="siteId != null"> and a.site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- </select>
- <!--按表类型查询15天内的抄表率数据统计-->
- <select id="getRateCount15DayByTime" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
- SELECT
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building_15day where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(read_times) as read_times,
- SUM(real_read_times) as real_read_times,
- SUM(un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_stat_meter_read_rate_by_building_15day a
- LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
- WHERE a.stat_day = #{startDate}
- AND b.`status` = 1
- <if test="siteId != null"> and a.site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- </select>
- <!--查询时间范围内根据表类型的抄表率数据统计-->
- <select id="getRateListByType" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
- SELECT
- swmt.channel_id,
- sdt.equipment_type as device_type_name,
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building where channel_id = swmt.channel_id <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(ssmrrbb.read_times) as read_times,
- SUM(ssmrrbb.real_read_times) as real_read_times,
- SUM(ssmrrbb.un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_w_meter_type swmt
- LEFT JOIN sc_stat_meter_read_rate_by_building ssmrrbb on (
- ssmrrbb.channel_id = swmt.channel_id <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
- and ssmrrbb.stat_day = #{startDate}
- <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- )
- left join sc_device_type sdt on (sdt.id = swmt.device_type_id)
- WHERE swmt.`level` = 2
- GROUP BY swmt.channel_id,sdt.equipment_type
- <if test="sortColumn != null and sortColumn != ''">
- <if test="sortOrder != null and sortOrder != ''">
- order by ${sortColumn} ${sortOrder}
- </if>
- </if>
- </select>
- <!--查询7天内根据表类型的抄表率数据统计-->
- <select id="getRateList7DayByType" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
- SELECT
- swmt.channel_id,
- sdt.equipment_type as device_type_name,
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building_7day where channel_id = swmt.channel_id <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(ssmrrbb.read_times) as read_times,
- SUM(ssmrrbb.real_read_times) as real_read_times,
- SUM(ssmrrbb.un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_w_meter_type swmt
- LEFT JOIN sc_stat_meter_read_rate_by_building_7day ssmrrbb on (
- ssmrrbb.channel_id = swmt.channel_id <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
- and ssmrrbb.stat_day = #{startDate}
- <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- )
- left join sc_device_type sdt on (sdt.id = swmt.device_type_id)
- WHERE swmt.`level` = 2
- GROUP BY swmt.channel_id,sdt.equipment_type
- <if test="sortColumn != null and sortColumn != ''">
- <if test="sortOrder != null and sortOrder != ''">
- order by ${sortColumn} ${sortOrder}
- </if>
- </if>
- </select>
- <!--查询15天内根据表类型的抄表率数据统计-->
- <select id="getRateList15DayByType" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
- SELECT
- swmt.channel_id,
- sdt.equipment_type as device_type_name,
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building_15day where channel_id = swmt.channel_id <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(ssmrrbb.read_times) as read_times,
- SUM(ssmrrbb.real_read_times) as real_read_times,
- SUM(ssmrrbb.un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_w_meter_type swmt
- LEFT JOIN sc_stat_meter_read_rate_by_building_15day ssmrrbb on (
- ssmrrbb.channel_id = swmt.channel_id <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
- and ssmrrbb.stat_day = #{startDate}
- <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- )
- left join sc_device_type sdt on (sdt.id = swmt.device_type_id)
- WHERE swmt.`level` = 2
- GROUP BY swmt.channel_id,sdt.equipment_type
- <if test="sortColumn != null and sortColumn != ''">
- <if test="sortOrder != null and sortOrder != ''">
- order by ${sortColumn} ${sortOrder}
- </if>
- </if>
- </select>
- <!--查询最近7天抄表率-->
- <select id="getLast7DaysReadRate" resultType="java.lang.Double">
- SELECT
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0)
- FROM
- sc_stat_meter_read_rate_by_building ssmrrbb
- WHERE
- stat_day between #{beginTime} AND #{endTime}
- <if test="programItems != null and programItems.size() != 0">
- and EXISTS(
- select 1 from
- (select sd.building_id FROM sc_device_dim_info df
- LEFT JOIN sc_device sd ON sd.id = df.device_id
- WHERE 1 = 1
- and
- <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach>
- GROUP BY sd.building_id) ud
- WHERE ud.building_id = ssmrrbb.building_id
- )
- </if>
- <if test="siteId != null">
- AND site_id = #{siteId}
- </if>
- <if test="channelId != null">
- AND channel_id = #{channelId}
- </if>
- <if test="customerId != null">
- AND customer_id = #{customerId}
- </if>
- </select>
- <!--按客户查询时间范围内的抄表率数数据统计-->
- <select id="getRateListByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
- SELECT
- sc.id as customer_id,
- sc.customer_name,
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building where customer_id = ssmrrbb.customer_id <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(ssmrrbb.read_times) as read_times,
- SUM(ssmrrbb.real_read_times) as real_read_times,
- SUM(ssmrrbb.un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_customer sc
- LEFT JOIN sc_stat_meter_read_rate_by_building ssmrrbb on(
- ssmrrbb.customer_id = sc.id
- <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
- and ssmrrbb.stat_day = #{startDate}
- <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- )
- WHERE sc.status = 1
- <if test="customerList != null and customerList.size() != 0">
- and sc.id in
- <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
- </if>
- GROUP BY sc.id,ssmrrbb.customer_id,sc.customer_name
- <if test="sortColumn != null and sortColumn != ''">
- <if test="sortOrder != null and sortOrder != ''">
- order by ${sortColumn} ${sortOrder}
- </if>
- </if>
- </select>
- <select id="getRateListByCustomerV2" resultType="com.bz.smart_city.dto.CustomerRateDto">
- SELECT sc.id as customer_id,sc.parent_id,sc.customer_name,sc.children_num FROM sc_customer sc
- LEFT JOIN(
- SELECT
- ssmrrbb.customer_id,
- SUM(device_count) as device_count
- FROM
- ${tableName} ssmrrbb
- WHERE
- ssmrrbb.site_id = #{siteId}
- <if test="channelId != null"> and ssmrrbb.channel_id = #{channelId} </if>
- AND ssmrrbb.stat_day = #{startDate}
- AND ssmrrbb.channel_id <![CDATA[ <> ]]> - 99
- <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- <if test="customerIds != null and customerIds.size() != 0"> and ssmrrbb.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY
- ssmrrbb.customer_id
- )t1 on(t1.customer_id = sc.id)
- WHERE sc.`status` = 1 and sc.site_id = #{siteId}
- <if test="customerIds != null and customerIds.size() != 0"> and sc.id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- ORDER BY device_count desc
- </select>
- <select id="getRateListByCustomerV2AndDeviceType" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
- SELECT
- ssmrrbb.customer_id,
- ssmrrbb.channel_id,
- sc.channel_name,
- SUM(device_count) as device_count,
- SUM(ssmrrbb.read_times) as read_times,
- SUM(ssmrrbb.real_read_times) as real_read_times,
- SUM(ssmrrbb.un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_stat_meter_read_rate_by_building ssmrrbb
- left join sc_channel sc on(sc.id = ssmrrbb.channel_id)
- WHERE
- ssmrrbb.site_id = #{siteId}
- and ssmrrbb.stat_day = #{startDate}
- AND ssmrrbb.channel_id <![CDATA[ <> ]]> - 99
- <if test="customerId != null"> and ssmrrbb.customer_id = #{customerId} </if>
- <if test="channelId != null"> and ssmrrbb.channel_id = #{channelId} </if>
- GROUP BY ssmrrbb.customer_id,ssmrrbb.channel_id,sc.channel_name
- order by read_rate desc
- </select>
- <!--按客户查询7天内的抄表率数数据统计-->
- <select id="getRateList7DayByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
- SELECT
- sc.id as customer_id,
- sc.customer_name,
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building_7day where customer_id = ssmrrbb.customer_id <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(ssmrrbb.read_times) as read_times,
- SUM(ssmrrbb.real_read_times) as real_read_times,
- SUM(ssmrrbb.un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_customer sc
- LEFT JOIN sc_stat_meter_read_rate_by_building_7day ssmrrbb on(
- ssmrrbb.customer_id = sc.id
- <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
- and ssmrrbb.stat_day = #{startDate}
- <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- )
- WHERE sc.status = 1
- <if test="customerList != null and customerList.size() != 0">
- and sc.id in
- <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
- </if>
- GROUP BY sc.id,ssmrrbb.customer_id,sc.customer_name
- <if test="sortColumn != null and sortColumn != ''">
- <if test="sortOrder != null and sortOrder != ''">
- order by ${sortColumn} ${sortOrder}
- </if>
- </if>
- </select>
- <!--按客户查询15天内的抄表率数数据统计-->
- <select id="getRateList15DayByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
- SELECT
- sc.id as customer_id,
- sc.customer_name,
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building_15day where customer_id = ssmrrbb.customer_id <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(ssmrrbb.read_times) as read_times,
- SUM(ssmrrbb.real_read_times) as real_read_times,
- SUM(ssmrrbb.un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_customer sc
- LEFT JOIN sc_stat_meter_read_rate_by_building_15day ssmrrbb on(
- ssmrrbb.customer_id = sc.id
- <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
- and ssmrrbb.stat_day = #{startDate}
- <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- )
- WHERE sc.status = 1
- <if test="customerList != null and customerList.size() != 0">
- and sc.id in
- <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
- </if>
- GROUP BY sc.id,ssmrrbb.customer_id,sc.customer_name
- <if test="sortColumn != null and sortColumn != ''">
- <if test="sortOrder != null and sortOrder != ''">
- order by ${sortColumn} ${sortOrder}
- </if>
- </if>
- </select>
- <!--按客户查询时间范围内的抄表率数据统计-->
- <select id="getCountByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
- SELECT
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(read_times) as read_times,
- SUM(real_read_times) as real_read_times,
- SUM(un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_stat_meter_read_rate_by_building a
- LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
- WHERE a.stat_day = #{startDate}
- AND b.`status` = 1
- <if test="siteId != null"> and a.site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- <if test="customerList != null and customerList.size() != 0">
- and a.customer_id in
- <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
- </if>
- </select>
- <select id="getCountByCustomerV2" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
- SELECT
- SUM(device_count) as device_count,
- SUM(read_times) as read_times,
- SUM(real_read_times) as real_read_times,
- SUM(un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM ${tableName} scmrrbb
- WHERE stat_day = #{startDate}
- and channel_id <![CDATA[ <> ]]> - 99
- <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="channelId != null"> and channel_id = #{channelId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- <if test="customerIds != null and customerIds.size() != 0"> and customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- </select>
- <!--按客户查询时间范围内的抄表率数据统计-->
- <select id="getCount7DayByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
- SELECT
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building_7day where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(read_times) as read_times,
- SUM(real_read_times) as real_read_times,
- SUM(un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_stat_meter_read_rate_by_building_7day a
- LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
- WHERE a.stat_day = #{startDate}
- AND b.`status` = 1
- <if test="siteId != null"> and a.site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- <if test="customerList != null and customerList.size() != 0">
- and a.customer_id in
- <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
- </if>
- </select>
- <!--按客户查询时间范围内的抄表率数据统计-->
- <select id="getCount15DayByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
- SELECT
- (select SUM(device_count) from sc_stat_meter_read_rate_by_building_15day where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- GROUP BY stat_day desc limit 1) as device_count,
- SUM(read_times) as read_times,
- SUM(real_read_times) as real_read_times,
- SUM(un_read_times) as un_read_times,
- ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
- FROM sc_stat_meter_read_rate_by_building_15day a
- LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
- WHERE a.stat_day = #{startDate}
- AND b.`status` = 1
- <if test="siteId != null"> and a.site_id = #{siteId} </if>
- <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- <if test="customerList != null and customerList.size() != 0">
- and a.customer_id in
- <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
- </if>
- </select>
- <!-- 按建筑统计天表 -->
- <sql id="base_GetRateListByBuildingForDay">
- select
- rb.stat_day as stat_day,
- rb.building_id as building_id,
- b.`name` AS building_name,
- rb.device_count AS device_count,
- rb.read_times AS read_times,
- rb.real_read_times AS real_read_times,
- rb.un_read_times AS un_read_times,
- rb.read_rate AS read_rate,
- rb.customer_id as customer_id,
- c.customer_name as customer_name
- from
- sc_stat_meter_read_rate_by_building rb
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- </sql>
- <select id="getRateListByBuildingForDay" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_GetRateListByBuildingForDay"></include>
- <include refid="where_clause"></include>
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by ${param.sortColumn} ${param.sortOrder}
- </if>
- </if>
- </select>
- <select id="getRateAreaListByBuildingForDay" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
- select
- b.id,
- b.name,
- b.province,
- b.city,
- b.region,
- b.community,
- b.longitude,
- b.latitude,
- 0
- from
- sc_stat_meter_read_rate_by_building rb
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- <include refid="where_clause"></include>
- </select>
- <select id="summaryRateListByBuildingForDay" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- select
- ifnull(SUM(tmp.device_count),0) as device_count,
- ifnull(SUM(tmp.read_times),0) as read_times,
- ifnull(SUM(tmp.real_read_times),0) as real_read_times,
- ifnull(SUM(tmp.un_read_times),0) as un_read_times,
- ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
- from (
- <include refid="base_GetRateListByBuildingForDay"></include>
- <include refid="where_clause"></include>
- ) tmp
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by read_rate ${param.sortOrder}
- </if>
- </if>
- </select>
-
- <!-- 按建筑统计天表 新装水表场景适用 -->
- <sql id="base_GetRateListByBuildingForDayWithNew">
- select
- rb.stat_day as stat_day,
- rb.building_id as building_id,
- b.`name` AS building_name,
- rb.device_count AS device_count,
- rb.read_times AS read_times,
- rb.real_read_times AS real_read_times,
- rb.un_read_times AS un_read_times,
- rb.customer_id as customer_id,
- c.customer_name as customer_name,
- (
- SELECT
- count( 1 )
- FROM
- sc_install_list l
- WHERE
- l.`status` = 1
- AND l.is_installed = 1
- AND l.is_accepted = 0
- AND l.building_id = rb.building_id
- ) AS installed_device_count,
- (
- SELECT
- SUM( IF ( d.device_status = 5, 1, 0 ) )
- FROM
- sc_device d
- WHERE
- d.building_id = rb.building_id
- AND d.`status` = 1
- AND d.sys_id = - 99
- ) AS unenable_device_count ,
- FORMAT(rb.real_read_times/ (
- SELECT
- count( 1 )
- FROM
- sc_install_list l
- WHERE
- l.`status` = 1
- AND l.is_installed = 1
- AND l.is_accepted = 0
- AND l.building_id = rb.building_id
- ) *100, 2) as read_rate
- from
- sc_stat_meter_read_rate_by_building rb
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- </sql>
- <select id="getRateListByBuildingForDayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_GetRateListByBuildingForDayWithNew"></include>
- <include refid="where_clause"></include>
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by ${param.sortColumn} ${param.sortOrder}
- </if>
- </if>
- </select>
- <select id="summaryRateListByBuildingForDayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- select
- ifnull(SUM(tmp.installed_device_count),0) as device_count,
- ifnull(SUM(tmp.read_times),0) as read_times,
- ifnull(SUM(tmp.real_read_times),0) as real_read_times,
- ifnull(SUM(tmp.un_read_times),0) as un_read_times,
- ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.installed_device_count)*100,2),0) as read_rate
- from (
- <include refid="base_GetRateListByBuildingForDayWithNew"></include>
- <include refid="where_clause"></include>
- ) tmp
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by read_rate ${param.sortOrder}
- </if>
- </if>
- </select>
- <!-- 按建筑统计7天表 -->
- <sql id="base_GetRateListByBuildingFor7Day">
- select
- rb.stat_day as stat_day,
- rb.building_id as building_id,
- b.`name` AS building_name,
- rb.device_count AS device_count,
- rb.read_times AS read_times,
- rb.real_read_times AS real_read_times,
- rb.un_read_times AS un_read_times,
- rb.read_rate AS read_rate,
- rb.customer_id as customer_id,
- c.customer_name as customer_name
- from
- sc_stat_meter_read_rate_by_building_7day rb
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- </sql>
- <select id="getRateAreaListByBuildingFor7Day" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
- select
- b.id,
- b.name,
- b.province,
- b.city,
- b.region,
- b.community,
- b.longitude,
- b.latitude,
- 0
- from
- sc_stat_meter_read_rate_by_building_7day rb
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- <include refid="where_clause"></include>
- </select>
- <select id="getRateListByBuildingFor7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_GetRateListByBuildingFor7Day"></include>
- <include refid="where_clause"></include>
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by ${param.sortColumn} ${param.sortOrder}
- </if>
- </if>
- </select>
- <select id="summaryRateListByBuildingFor7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- select
- ifnull(SUM(tmp.device_count),0) as device_count,
- ifnull(SUM(tmp.read_times),0) as read_times,
- ifnull(SUM(tmp.real_read_times),0) as real_read_times,
- ifnull(SUM(tmp.un_read_times),0) as un_read_times,
- ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
- from (
- <include refid="base_GetRateListByBuildingFor7Day"></include>
- <include refid="where_clause"></include>
- ) tmp
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by read_rate ${param.sortOrder}
- </if>
- </if>
- </select>
- <!-- 按建筑统计7天表 新装水表场景适用 -->
- <sql id="base_GetRateListByBuildingFor7DayWithNew">
- select
- rb.stat_day as stat_day,
- rb.building_id as building_id,
- b.`name` AS building_name,
- rb.device_count AS device_count,
- rb.read_times AS read_times,
- rb.real_read_times AS real_read_times,
- rb.un_read_times AS un_read_times,
- rb.customer_id as customer_id,
- c.customer_name as customer_name,
- (
- SELECT
- count( 1 )
- FROM
- sc_install_list l
- WHERE
- l.`status` = 1
- AND l.is_installed = 1
- AND l.is_accepted = 0
- AND l.building_id = rb.building_id
- ) AS installed_device_count,
- (
- SELECT
- SUM( IF ( d.device_status = 5, 1, 0 ) )
- FROM
- sc_device d
- WHERE
- d.building_id = rb.building_id
- AND d.`status` = 1
- AND d.sys_id = - 99
- ) AS unenable_device_count ,
- FORMAT(rb.real_read_times/ (
- SELECT
- count( 1 )
- FROM
- sc_install_list l
- WHERE
- l.`status` = 1
- AND l.is_installed = 1
- AND l.is_accepted = 0
- AND l.building_id = rb.building_id
- ) *100, 2) as read_rate
- from
- sc_stat_meter_read_rate_by_building_7day rb
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- </sql>
- <select id="getRateListByBuildingFor7DayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_GetRateListByBuildingFor7DayWithNew"></include>
- <include refid="where_clause"></include>
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by ${param.sortColumn} ${param.sortOrder}
- </if>
- </if>
- </select>
- <select id="summaryRateListByBuildingFor7DayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- select
- ifnull(SUM(tmp.installed_device_count),0) as device_count,
- ifnull(SUM(tmp.read_times),0) as read_times,
- ifnull(SUM(tmp.real_read_times),0) as real_read_times,
- ifnull(SUM(tmp.un_read_times),0) as un_read_times,
- ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.installed_device_count)*100,2),0) as read_rate
- from (
- <include refid="base_GetRateListByBuildingFor7DayWithNew"></include>
- <include refid="where_clause"></include>
- ) tmp
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by read_rate ${param.sortOrder}
- </if>
- </if>
- </select>
-
- <!-- 按建筑统计15天表 -->
- <sql id="base_GetRateListByBuildingFor15Day">
- select
- rb.stat_day as stat_day,
- rb.building_id as building_id,
- b.`name` AS building_name,
- rb.device_count AS device_count,
- rb.read_times AS read_times,
- rb.real_read_times AS real_read_times,
- rb.un_read_times AS un_read_times,
- rb.read_rate AS read_rate,
- rb.customer_id as customer_id,
- c.customer_name as customer_name
- from
- sc_stat_meter_read_rate_by_building_15day rb
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- </sql>
- <!-- 按建筑统计月表 -->
- <sql id="base_GetRateListByBuildingForMonth">
- select
- rb.stat_day as stat_day,
- rb.building_id as building_id,
- b.`name` AS building_name,
- rb.device_count AS device_count,
- rb.read_times AS read_times,
- rb.real_read_times AS real_read_times,
- rb.un_read_times AS un_read_times,
- rb.read_rate AS read_rate,
- rb.customer_id as customer_id,
- c.customer_name as customer_name
- from
- sc_stat_meter_read_rate_by_building_month rb
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- </sql>
- <select id="getRateListByBuildingFor15Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_GetRateListByBuildingFor15Day"></include>
- <include refid="where_clause"></include>
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by ${param.sortColumn} ${param.sortOrder}
- </if>
- </if>
- </select>
- <select id="getRateListByBuildingForMonth" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_GetRateListByBuildingForMonth"></include>
- <include refid="where_clause"></include>
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by ${param.sortColumn} ${param.sortOrder}
- </if>
- </if>
- </select>
- <select id="getRateAreaListByBuildingFor15Day" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
- select
- b.id,
- b.name,
- b.province,
- b.city,
- b.region,
- b.community,
- b.longitude,
- b.latitude,
- 0
- from
- sc_stat_meter_read_rate_by_building_15day rb
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- <include refid="where_clause"></include>
- </select>
- <select id="getRateAreaListByBuildingForMonth" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
- select
- b.id,
- b.name,
- b.province,
- b.city,
- b.region,
- b.community,
- b.longitude,
- b.latitude,
- 0
- from
- sc_stat_meter_read_rate_by_building_month rb
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- <include refid="where_clause"></include>
- </select>
- <select id="summaryRateListByBuildingFor15Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- select
- ifnull(SUM(tmp.device_count),0) as device_count,
- ifnull(SUM(tmp.read_times),0) as read_times,
- ifnull(SUM(tmp.real_read_times),0) as real_read_times,
- ifnull(SUM(tmp.un_read_times),0) as un_read_times,
- ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
- from (
- <include refid="base_GetRateListByBuildingFor15Day"></include>
- <include refid="where_clause"></include>
- ) tmp
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by read_rate ${param.sortOrder}
- </if>
- </if>
- </select>
- <select id="summaryRateListByBuildingForMonth" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- select
- ifnull(SUM(tmp.device_count),0) as device_count,
- ifnull(SUM(tmp.read_times),0) as read_times,
- ifnull(SUM(tmp.real_read_times),0) as real_read_times,
- ifnull(SUM(tmp.un_read_times),0) as un_read_times,
- ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
- from (
- <include refid="base_GetRateListByBuildingForMonth"></include>
- <include refid="where_clause"></include>
- ) tmp
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by read_rate ${param.sortOrder}
- </if>
- </if>
- </select>
-
- <!-- 按建筑统计15天表 新装水表场景适用-->
- <sql id="base_GetRateListByBuildingFor15DayWithNew">
- select
- rb.stat_day as stat_day,
- rb.building_id as building_id,
- b.`name` AS building_name,
- rb.device_count AS device_count,
- rb.read_times AS read_times,
- rb.real_read_times AS real_read_times,
- rb.un_read_times AS un_read_times,
- rb.customer_id as customer_id,
- c.customer_name as customer_name,
- (
- SELECT
- count( 1 )
- FROM
- sc_install_list l
- WHERE
- l.`status` = 1
- AND l.is_installed = 1
- AND l.is_accepted = 0
- AND l.building_id = rb.building_id
- ) AS installed_device_count,
- (
- SELECT
- SUM( IF ( d.device_status = 5, 1, 0 ) )
- FROM
- sc_device d
- WHERE
- d.building_id = rb.building_id
- AND d.`status` = 1
- AND d.sys_id = - 99
- ) AS unenable_device_count ,
- FORMAT(rb.real_read_times/ (
- SELECT
- count( 1 )
- FROM
- sc_install_list l
- WHERE
- l.`status` = 1
- AND l.is_installed = 1
- AND l.is_accepted = 0
- AND l.building_id = rb.building_id
- ) *100, 2) as read_rate
- from
- sc_stat_meter_read_rate_by_building_15day rb
- LEFT JOIN sc_building b ON ( rb.building_id = b.id )
- LEFT JOIN sc_customer c on (rb.customer_id = c.id)
- </sql>
- <select id="getRateListByBuildingFor15DayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_GetRateListByBuildingFor15DayWithNew"></include>
- <include refid="where_clause"></include>
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by ${param.sortColumn} ${param.sortOrder}
- </if>
- </if>
- </select>
- <select id="summaryRateListByBuildingFor15DayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- select
- ifnull(SUM(tmp.installed_device_count),0) as device_count,
- ifnull(SUM(tmp.read_times),0) as read_times,
- ifnull(SUM(tmp.real_read_times),0) as real_read_times,
- ifnull(SUM(tmp.un_read_times),0) as un_read_times,
- ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.installed_device_count)*100,2),0) as read_rate
- from (
- <include refid="base_GetRateListByBuildingFor15DayWithNew"></include>
- <include refid="where_clause"></include>
- ) tmp
- <if test="param.sortColumn != null and param.sortColumn != ''">
- <if test="param.sortOrder != null and param.sortOrder != ''">
- order by read_rate ${param.sortOrder}
- </if>
- </if>
- </select>
- </mapper>
|