123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644 |
- <?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.StatMeterReadRateByCollectorMapper">
- <!--auto generated Code-->
- <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.StatMeterReadRateByCollector">
- <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="concentrator_id" property="concentratorId" jdbcType="INTEGER"/>
- <result column="collector_id" property="collectorId" 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,
- concentrator_id,
- collector_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="statMeterReadRateByCollector.statDay">
- INSERT INTO sc_stat_meter_read_rate_by_collector (
- stat_day,
- site_id,
- channel_id,
- customer_id,
- concentrator_id,
- collector_id,
- device_count,
- read_times,
- real_read_times,
- un_read_times,
- read_rate,
- date_create,
- date_update
- ) VALUES (
- #{statMeterReadRateByCollector.statDay,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.siteId,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.channelId,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.customerId,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.concentratorId,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.collectorId,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.deviceCount,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.readTimes,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.realReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.unReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.readRate,jdbcType=DECIMAL},
- #{statMeterReadRateByCollector.dateCreate,jdbcType=TIMESTAMP},
- #{statMeterReadRateByCollector.dateUpdate,jdbcType=TIMESTAMP}
- )
- </insert>
- <!--auto generated Code-->
- <insert id="insertSelective" useGeneratedKeys="true" keyProperty="statMeterReadRateByCollector.statDay">
- INSERT INTO sc_stat_meter_read_rate_by_collector
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="statMeterReadRateByCollector.statDay!=null"> stat_day,</if>
- <if test="statMeterReadRateByCollector.siteId!=null"> site_id,</if>
- <if test="statMeterReadRateByCollector.channelId!=null"> channel_id,</if>
- <if test="statMeterReadRateByCollector.customerId!=null"> customer_id,</if>
- <if test="statMeterReadRateByCollector.concentratorId!=null"> concentrator_id,</if>
- <if test="statMeterReadRateByCollector.collectorId!=null"> collector_id,</if>
- <if test="statMeterReadRateByCollector.deviceCount!=null"> device_count,</if>
- <if test="statMeterReadRateByCollector.readTimes!=null"> read_times,</if>
- <if test="statMeterReadRateByCollector.realReadTimes!=null"> real_read_times,</if>
- <if test="statMeterReadRateByCollector.unReadTimes!=null"> un_read_times,</if>
- <if test="statMeterReadRateByCollector.readRate!=null"> read_rate,</if>
- <if test="statMeterReadRateByCollector.dateCreate!=null"> date_create,</if>
- <if test="statMeterReadRateByCollector.dateUpdate!=null"> date_update,</if>
- </trim>
- VALUES
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="statMeterReadRateByCollector.statDay!=null">#{statMeterReadRateByCollector.statDay,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByCollector.siteId!=null">#{statMeterReadRateByCollector.siteId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByCollector.channelId!=null">#{statMeterReadRateByCollector.channelId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByCollector.customerId!=null">#{statMeterReadRateByCollector.customerId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByCollector.concentratorId!=null">#{statMeterReadRateByCollector.concentratorId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByCollector.collectorId!=null">#{statMeterReadRateByCollector.collectorId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByCollector.deviceCount!=null">#{statMeterReadRateByCollector.deviceCount,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByCollector.readTimes!=null">#{statMeterReadRateByCollector.readTimes,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByCollector.realReadTimes!=null">#{statMeterReadRateByCollector.realReadTimes,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByCollector.unReadTimes!=null">#{statMeterReadRateByCollector.unReadTimes,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByCollector.readRate!=null">#{statMeterReadRateByCollector.readRate,jdbcType=DECIMAL},
- </if>
- <if test="statMeterReadRateByCollector.dateCreate!=null">#{statMeterReadRateByCollector.dateCreate,jdbcType=TIMESTAMP},
- </if>
- <if test="statMeterReadRateByCollector.dateUpdate!=null">#{statMeterReadRateByCollector.dateUpdate,jdbcType=TIMESTAMP},
- </if>
- </trim>
- </insert>
- <!--auto generated Code-->
- <insert id="insertList">
- INSERT INTO sc_stat_meter_read_rate_by_collector (
- stat_day,
- site_id,
- channel_id,
- customer_id,
- concentrator_id,
- collector_id,
- device_count,
- read_times,
- real_read_times,
- un_read_times,
- read_rate,
- date_create,
- date_update
- )VALUES
- <foreach collection="statMeterReadRateByCollectors" item="statMeterReadRateByCollector" index="index" separator=",">
- (
- #{statMeterReadRateByCollector.statDay,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.siteId,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.channelId,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.customerId,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.concentratorId,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.collectorId,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.deviceCount,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.readTimes,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.realReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.unReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByCollector.readRate,jdbcType=DECIMAL},
- #{statMeterReadRateByCollector.dateCreate,jdbcType=TIMESTAMP},
- #{statMeterReadRateByCollector.dateUpdate,jdbcType=TIMESTAMP}
- )
- </foreach>
- </insert>
- <!--auto generated Code-->
- <update id="updateByPrimaryKeySelective">
- UPDATE sc_stat_meter_read_rate_by_collector
- <set>
- <if test="statMeterReadRateByCollector.siteId != null"> site_id= #{statMeterReadRateByCollector.siteId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByCollector.channelId != null"> channel_id= #{statMeterReadRateByCollector.channelId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByCollector.customerId != null"> customer_id= #{statMeterReadRateByCollector.customerId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByCollector.concentratorId != null"> concentrator_id= #{statMeterReadRateByCollector.concentratorId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByCollector.collectorId != null"> collector_id= #{statMeterReadRateByCollector.collectorId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByCollector.deviceCount != null"> device_count= #{statMeterReadRateByCollector.deviceCount,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByCollector.readTimes != null"> read_times= #{statMeterReadRateByCollector.readTimes,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByCollector.realReadTimes != null"> real_read_times= #{statMeterReadRateByCollector.realReadTimes,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByCollector.unReadTimes != null"> un_read_times= #{statMeterReadRateByCollector.unReadTimes,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByCollector.readRate != null"> read_rate= #{statMeterReadRateByCollector.readRate,jdbcType=DECIMAL},</if>
- <if test="statMeterReadRateByCollector.dateCreate != null"> date_create= #{statMeterReadRateByCollector.dateCreate,jdbcType=TIMESTAMP},</if>
- <if test="statMeterReadRateByCollector.dateUpdate != null"> date_update= #{statMeterReadRateByCollector.dateUpdate,jdbcType=TIMESTAMP}</if>
- </set>
- WHERE stat_day = #{statMeterReadRateByCollector.statDay,jdbcType=INTEGER}
- </update>
- <sql id="base_query">
- SELECT
- cust.customer_name as customer_name,
- con.serial_number as serial_number,
- col.collector_no as collector_no,
- tmp.device_count as device_count,
- tmp.read_times as read_times,
- tmp.real_read_times as real_read_times,
- tmp.un_read_times as un_read_times,
- tmp.read_rate as read_rate
- FROM
- (
- SELECT
- customer_id,
- concentrator_id,
- collector_id,
- 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 ,
- FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
- FROM
- sc_stat_meter_read_rate_by_collector
- WHERE 1 = 1
- <!-- 表类型 -->
- <if test="param.deviceTypeId != null ">
- and meter_type_id = #{param.deviceTypeId}
- </if>
- <!-- 数据权限 -->
- <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
- <!--
- <if test="param.isAdmin != null and param.isAdmin == 1">
- and site_id = 0
- </if>
- <if test="param.sites != null and param.sites.size() != 0">
- and 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 collector_id IN (
- SELECT DISTINCT
- rd.collector_id
- FROM
- sc_water_related_device rd
- WHERE
- rd.device_id IN (
- SELECT
- ud.device_id
- FROM
- (
- SELECT
- DISTINCT df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud
- )
- )
- </if>
- <if test = "param.startDate != null and param.startDate != 0"> and stat_day >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and stat_day <![CDATA[ <= ]]> #{param.endDate}</if>
- GROUP BY
- customer_id,
- concentrator_id,
- collector_id
- ) tmp
- LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
- LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
- LEFT JOIN sc_collector col ON ( tmp.collector_id = col.id )
- </sql>
- <sql id="where_clause">
- where 1 = 1
- <if test = "param.beginRate != null "> and tmp.read_rate >= #{param.beginRate}</if>
- <if test = "param.endRate != null "> and tmp.read_rate <![CDATA[ <= ]]> #{param.endRate}</if>
- <if test = "param.custormerId != null"> and tmp.customer_id = #{param.custormerId}</if>
- <if test = "param.collectorCode != null and param.collectorCode != '' "> and col.collector_no like #{param.collectorCode}</if>
- <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
- </sql>
- <select id="summaryList" 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(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
- from (
- <include refid="base_query" />
- <include refid="where_clause"/>
- ) tmp
- </select>
- <!-- 查询抄表率,不含近7天统计 -->
- <select id="getListWithOut7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_query" />
- <include refid="where_clause" />
- </select>
-
- <!-- 查询抄表率,含近7天统计 -->
- <select id="getListWith7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- SELECT
- rc.stat_day as stat_day,
- cust.customer_name as customer_name,
- con.serial_number as serial_number,
- col.collector_no as collector_no,
- rc.device_count as device_count,
- rc.read_times as read_times,
- rc.real_read_times as real_read_times,
- rc.un_read_times as un_read_times,
- rc.read_rate as read_rate,
- rcd.read_rate as last_seven_day_read_rate
- FROM
- sc_stat_meter_read_rate_by_collector rc
- LEFT JOIN sc_stat_meter_read_rate_by_collector_7day rcd ON (
- rc.site_id = rcd.site_id
- AND rc.channel_id = rcd.channel_id
- AND rc.customer_id = rcd.customer_id
- and rc.meter_type_id = rcd.meter_type_id
- AND rc.concentrator_id = rcd.concentrator_id
- AND rc.collector_id = rcd.collector_id
- AND rc.stat_day = rcd.stat_day
- )
- LEFT JOIN sc_customer cust ON ( rc.customer_id = cust.id )
- LEFT JOIN sc_concentrator con ON ( rc.concentrator_id = con.id )
- LEFT JOIN sc_collector col ON ( rc.collector_id = col.id )
- where 1 = 1
- <!-- 表类型 -->
- <if test="param.deviceTypeId != null ">
- and rc.meter_type_id = #{param.deviceTypeId}
- </if>
- <!-- 数据权限 -->
- <if test="param.siteId != null and param.siteId != 0 "> and rc.site_id = #{param.siteId} </if>
- <!--
- <if test="param.isAdmin != null and param.isAdmin == 1">
- and rc.site_id = 0
- </if>
- <if test="param.sites != null and param.sites.size() != 0">
- and rc.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 rc.collector_id IN (
- SELECT DISTINCT
- rd.collector_id
- FROM
- sc_water_related_device rd
- WHERE
- rd.device_id IN (
- SELECT
- ud.device_id
- FROM
- (
- SELECT
- DISTINCT df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud
- )
- )
- </if>
- <if test = "param.startDate != null and param.startDate != 0"> and rc.stat_day >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and rc.stat_day <![CDATA[ <= ]]> #{param.endDate}</if>
- <if test = "param.beginRate != null "> and rc.read_rate >= #{param.beginRate}</if>
- <if test = "param.endRate != null "> and rc.read_rate <![CDATA[ <= ]]> #{param.endRate}</if>
- <if test = "param.custormerId != null"> and rc.customer_id = #{param.custormerId}</if>
- <if test = "param.collectorCode != null and param.collectorCode != '' "> and col.collector_no like #{param.collectorCode}</if>
- <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
- </select>
- <!--查询抄表率明细-->
- <select id="getList" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- SELECT
- d.customer_name,
- a.*,
- b.collector_no,
- c.serial_number
- FROM
- sc_stat_meter_read_rate_by_collector a
- LEFT JOIN sc_customer d ON d.id = a.customer_id
- LEFT JOIN sc_collector b ON b.id = a.collector_id
- LEFT JOIN sc_concentrator c ON c.id = a.concentrator_id
- WHERE 1=1
- <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
- AND DATE(a.stat_day) BETWEEN CONCAT(#{beginTime},' 00:00:00') AND CONCAT(#{endTime}, '23:59:59')
- </if>
- <if test="beginRate !=null">
- AND a.read_rate >= #{beginRate}
- </if>
- <if test="endRate !=null">
- AND #{endRate} >= a.read_rate
- </if>
- <if test="customerId !=null">
- AND a.customer_id = #{customerId}
- </if>
- <if test="serialNumber !=null and serialNumber !=''">
- AND c.serial_number LIKE CONCAT('%',#{serialNumber},'%')
- </if>
- <if test="collectorNo !=null and collectorNo !=''">
- AND b.collector_no LIKE CONCAT('%',#{collectorNo},'%')
- </if>
- </select>
- <!--查询客户最近7天抄表率-->
- <select id="getLast7DayReadRate" resultType="String">
- SELECT SUM(read_rate)/COUNT(1)
- FROM sc_stat_meter_read_rate_by_collector
- WHERE customer_id = #{customerId}
- AND DATE(stat_day) BETWEEN CONCAT(#{beginTime},' 00:00:00') AND CONCAT(#{endTime}, '23:59:59')
- </select>
- <sql id= "base_query_getListByDay">
- SELECT
- cust.customer_name as customer_name,
- con.serial_number as serial_number,
- col.collector_no as collector_no,
- tmp.device_count as device_count,
- tmp.read_times as read_times,
- tmp.real_read_times as real_read_times,
- tmp.un_read_times as un_read_times,
- tmp.read_rate as read_rate
- FROM
- (
- SELECT
- customer_id,
- concentrator_id,
- collector_id,
- 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 ,
- FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
- FROM
- sc_stat_meter_read_rate_by_collector
- WHERE 1 = 1
- <!-- 表类型 -->
- <if test="param.deviceTypeId != null ">
- and meter_type_id = #{param.deviceTypeId}
- </if>
- <!-- 数据权限 -->
- <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and collector_id IN (
- SELECT DISTINCT
- rd.collector_id
- FROM
- sc_water_related_device rd
- WHERE
- rd.device_id IN (
- SELECT
- ud.device_id
- FROM
- (
- SELECT
- DISTINCT df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud
- )
- )
- </if>
- <if test = "param.statDay != null and param.statDay != 0"> and stat_day = #{param.statDay}</if>
- GROUP BY
- customer_id,
- concentrator_id,
- collector_id
- ) tmp
- LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
- LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
- LEFT JOIN sc_collector col ON ( tmp.collector_id = col.id )
- </sql>
- <select id="getListByDay" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_query_getListByDay" />
- <include refid="where_clause" />
- <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="summaryListByDay" 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(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
- from (
- <include refid="base_query_getListByDay" />
- <include refid="where_clause"/>
- ) tmp
- </select>
-
-
- <sql id= "base_query_getListBy7Day">
- SELECT
- cust.customer_name as customer_name,
- con.serial_number as serial_number,
- col.collector_no as collector_no,
- tmp.device_count as device_count,
- tmp.read_times as read_times,
- tmp.real_read_times as real_read_times,
- tmp.un_read_times as un_read_times,
- tmp.read_rate as read_rate
- FROM
- (
- SELECT
- customer_id,
- concentrator_id,
- collector_id,
- 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 ,
- FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
- FROM
- sc_stat_meter_read_rate_by_collector_7day
- WHERE 1 = 1
- <!-- 表类型 -->
- <if test="param.deviceTypeId != null ">
- and meter_type_id = #{param.deviceTypeId}
- </if>
- <!-- 数据权限 -->
- <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and collector_id IN (
- SELECT DISTINCT
- rd.collector_id
- FROM
- sc_water_related_device rd
- WHERE
- rd.device_id IN (
- SELECT
- ud.device_id
- FROM
- (
- SELECT
- DISTINCT df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud
- )
- )
- </if>
- <if test = "param.statDay != null and param.statDay != 0"> and stat_day = #{param.statDay}</if>
- GROUP BY
- customer_id,
- concentrator_id,
- collector_id
- ) tmp
- LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
- LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
- LEFT JOIN sc_collector col ON ( tmp.collector_id = col.id )
- </sql>
- <select id="getListBy7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_query_getListBy7Day" />
- <include refid="where_clause" />
- <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="summaryListBy7Day" 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(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
- from (
- <include refid="base_query_getListBy7Day" />
- <include refid="where_clause"/>
- ) tmp
- </select>
-
- <sql id= "base_query_getListBy15Day">
- SELECT
- cust.customer_name as customer_name,
- con.serial_number as serial_number,
- col.collector_no as collector_no,
- tmp.device_count as device_count,
- tmp.read_times as read_times,
- tmp.real_read_times as real_read_times,
- tmp.un_read_times as un_read_times,
- tmp.read_rate as read_rate
- FROM
- (
- SELECT
- customer_id,
- concentrator_id,
- collector_id,
- 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 ,
- FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
- FROM
- sc_stat_meter_read_rate_by_collector_15day
- WHERE 1 = 1
- <!-- 表类型 -->
- <if test="param.deviceTypeId != null ">
- and meter_type_id = #{param.deviceTypeId}
- </if>
- <!-- 数据权限 -->
- <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and collector_id IN (
- SELECT DISTINCT
- rd.collector_id
- FROM
- sc_water_related_device rd
- WHERE
- rd.device_id IN (
- SELECT
- ud.device_id
- FROM
- (
- SELECT
- DISTINCT df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud
- )
- )
- </if>
- <if test = "param.statDay != null and param.statDay != 0"> and stat_day = #{param.statDay}</if>
- GROUP BY
- customer_id,
- concentrator_id,
- collector_id
- ) tmp
- LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
- LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
- LEFT JOIN sc_collector col ON ( tmp.collector_id = col.id )
- </sql>
- <select id="getListBy15Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_query_getListBy15Day" />
- <include refid="where_clause" />
- <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="summaryListBy15Day" 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(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
- from (
- <include refid="base_query_getListBy15Day" />
- <include refid="where_clause"/>
- ) tmp
- </select>
-
- </mapper>
|