123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895 |
- <?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.StatMeterReadRateByConcentratorMapper">
- <!--auto generated Code-->
- <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.StatMeterReadRateByConcentrator">
- <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="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,
- 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="statMeterReadRateByConcentrator.statDay">
- INSERT INTO sc_stat_meter_read_rate_by_concentrator (
- stat_day,
- site_id,
- channel_id,
- customer_id,
- concentrator_id,
- device_count,
- read_times,
- real_read_times,
- un_read_times,
- read_rate,
- date_create,
- date_update
- ) VALUES (
- #{statMeterReadRateByConcentrator.statDay,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.siteId,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.channelId,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.customerId,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.concentratorId,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.deviceCount,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.readTimes,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.realReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.unReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.readRate,jdbcType=DECIMAL},
- #{statMeterReadRateByConcentrator.dateCreate,jdbcType=TIMESTAMP},
- #{statMeterReadRateByConcentrator.dateUpdate,jdbcType=TIMESTAMP}
- )
- </insert>
- <!--auto generated Code-->
- <insert id="insertSelective" useGeneratedKeys="true" keyProperty="statMeterReadRateByConcentrator.statDay">
- INSERT INTO sc_stat_meter_read_rate_by_concentrator
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="statMeterReadRateByConcentrator.statDay!=null"> stat_day,</if>
- <if test="statMeterReadRateByConcentrator.siteId!=null"> site_id,</if>
- <if test="statMeterReadRateByConcentrator.channelId!=null"> channel_id,</if>
- <if test="statMeterReadRateByConcentrator.customerId!=null"> customer_id,</if>
- <if test="statMeterReadRateByConcentrator.concentratorId!=null"> concentrator_id,</if>
- <if test="statMeterReadRateByConcentrator.deviceCount!=null"> device_count,</if>
- <if test="statMeterReadRateByConcentrator.readTimes!=null"> read_times,</if>
- <if test="statMeterReadRateByConcentrator.realReadTimes!=null"> real_read_times,</if>
- <if test="statMeterReadRateByConcentrator.unReadTimes!=null"> un_read_times,</if>
- <if test="statMeterReadRateByConcentrator.readRate!=null"> read_rate,</if>
- <if test="statMeterReadRateByConcentrator.dateCreate!=null"> date_create,</if>
- <if test="statMeterReadRateByConcentrator.dateUpdate!=null"> date_update,</if>
- </trim>
- VALUES
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="statMeterReadRateByConcentrator.statDay!=null">#{statMeterReadRateByConcentrator.statDay,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByConcentrator.siteId!=null">#{statMeterReadRateByConcentrator.siteId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByConcentrator.channelId!=null">#{statMeterReadRateByConcentrator.channelId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByConcentrator.customerId!=null">#{statMeterReadRateByConcentrator.customerId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByConcentrator.concentratorId!=null">#{statMeterReadRateByConcentrator.concentratorId,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByConcentrator.deviceCount!=null">#{statMeterReadRateByConcentrator.deviceCount,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByConcentrator.readTimes!=null">#{statMeterReadRateByConcentrator.readTimes,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByConcentrator.realReadTimes!=null">#{statMeterReadRateByConcentrator.realReadTimes,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByConcentrator.unReadTimes!=null">#{statMeterReadRateByConcentrator.unReadTimes,jdbcType=INTEGER},
- </if>
- <if test="statMeterReadRateByConcentrator.readRate!=null">#{statMeterReadRateByConcentrator.readRate,jdbcType=DECIMAL},
- </if>
- <if test="statMeterReadRateByConcentrator.dateCreate!=null">#{statMeterReadRateByConcentrator.dateCreate,jdbcType=TIMESTAMP},
- </if>
- <if test="statMeterReadRateByConcentrator.dateUpdate!=null">#{statMeterReadRateByConcentrator.dateUpdate,jdbcType=TIMESTAMP},
- </if>
- </trim>
- </insert>
- <!--auto generated Code-->
- <insert id="insertList">
- INSERT INTO sc_stat_meter_read_rate_by_concentrator (
- stat_day,
- site_id,
- channel_id,
- customer_id,
- concentrator_id,
- device_count,
- read_times,
- real_read_times,
- un_read_times,
- read_rate,
- date_create,
- date_update
- )VALUES
- <foreach collection="statMeterReadRateByConcentrators" item="statMeterReadRateByConcentrator" index="index" separator=",">
- (
- #{statMeterReadRateByConcentrator.statDay,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.siteId,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.channelId,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.customerId,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.concentratorId,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.deviceCount,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.readTimes,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.realReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.unReadTimes,jdbcType=INTEGER},
- #{statMeterReadRateByConcentrator.readRate,jdbcType=DECIMAL},
- #{statMeterReadRateByConcentrator.dateCreate,jdbcType=TIMESTAMP},
- #{statMeterReadRateByConcentrator.dateUpdate,jdbcType=TIMESTAMP}
- )
- </foreach>
- </insert>
- <!--auto generated Code-->
- <update id="updateByPrimaryKeySelective">
- UPDATE sc_stat_meter_read_rate_by_concentrator
- <set>
- <if test="statMeterReadRateByConcentrator.siteId != null"> site_id= #{statMeterReadRateByConcentrator.siteId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByConcentrator.channelId != null"> channel_id= #{statMeterReadRateByConcentrator.channelId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByConcentrator.customerId != null"> customer_id= #{statMeterReadRateByConcentrator.customerId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByConcentrator.concentratorId != null"> concentrator_id= #{statMeterReadRateByConcentrator.concentratorId,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByConcentrator.deviceCount != null"> device_count= #{statMeterReadRateByConcentrator.deviceCount,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByConcentrator.readTimes != null"> read_times= #{statMeterReadRateByConcentrator.readTimes,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByConcentrator.realReadTimes != null"> real_read_times= #{statMeterReadRateByConcentrator.realReadTimes,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByConcentrator.unReadTimes != null"> un_read_times= #{statMeterReadRateByConcentrator.unReadTimes,jdbcType=INTEGER},</if>
- <if test="statMeterReadRateByConcentrator.readRate != null"> read_rate= #{statMeterReadRateByConcentrator.readRate,jdbcType=DECIMAL},</if>
- <if test="statMeterReadRateByConcentrator.dateCreate != null"> date_create= #{statMeterReadRateByConcentrator.dateCreate,jdbcType=TIMESTAMP},</if>
- <if test="statMeterReadRateByConcentrator.dateUpdate != null"> date_update= #{statMeterReadRateByConcentrator.dateUpdate,jdbcType=TIMESTAMP}</if>
- </set>
- WHERE stat_day = #{statMeterReadRateByConcentrator.statDay,jdbcType=INTEGER}
- </update>
- <!--查询抄表率明细-->
- <select id="getList" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- SELECT
- d.customer_name,
- a.*,
- c.serial_number
- FROM
- sc_stat_meter_read_rate_by_concentrator a
- LEFT JOIN sc_customer d ON d.id = a.customer_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>
- </select>
- <!--查询客户最近7天抄表率-->
- <select id="getLast7DayReadRate" resultType="String">
- SELECT SUM(read_rate)/COUNT(1)
- FROM sc_stat_meter_read_rate_by_concentrator
- WHERE customer_id = #{customerId}
- AND DATE(stat_day) BETWEEN CONCAT(#{beginTime},' 00:00:00') AND CONCAT(#{endTime}, '23:59:59')
- </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,
- 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_concentrator rc
- LEFT JOIN sc_stat_meter_read_rate_by_concentrator_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.concentrator_id = rcd.concentrator_id
- and rc.meter_type_id = rcd.meter_type_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 )
- 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.concentrator_id IN (
- SELECT DISTINCT
- rd.concentrator_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.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
- ORDER BY read_rate DESC
- </select>
- <sql id="base_query">
- SELECT
- cust.customer_name as customer_name,
- con.serial_number as serial_number,
- 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,
- 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_concentrator
- 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 concentrator_id IN (
- SELECT DISTINCT
- rd.concentrator_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
- ) tmp
- LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
- LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.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.concentratorId != null">and tmp.concentrator_id = #{param.concentratorId}</if>
- <if test = "param.deviceTypeId != null" >and tmp.device_type_id = #{param.deviceTypeId}</if>
- <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
- </sql>
- <!-- 查询抄表率,不含近7天统计 -->
- <select id="getListWithOut7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_query" />
- <include refid="where_clause"/>
- ORDER BY read_rate DESC
- </select>
- <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
- ORDER BY read_rate DESC
- </select>
-
- <sql id="base_query_getListByDay">
- SELECT
- cust.customer_name as customer_name,
- con.serial_number as serial_number,
- concat_ws('/',m.name,dt.equipment_type,dt.model) as device_type_name,
- 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,
- meter_type_id as device_type_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_concentrator
- 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.customerIds != null and param.customerIds.size() != 0">
- and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <!--
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and concentrator_id IN (
- SELECT DISTINCT
- rd.concentrator_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,
- device_type_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_device_type dt on (tmp.device_type_id = dt.id)
- left join sc_device_manufacturer m on (dt.manufacturer_id = m.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
- ORDER BY read_rate DESC
- </select>
-
- <sql id="base_query_getListBy7Day">
- SELECT
- cust.customer_name as customer_name,
- con.serial_number as serial_number,
- concat_ws('/',m.name,dt.equipment_type,dt.model) as device_type_name,
- 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,
- meter_type_id as device_type_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_concentrator_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.customerIds != null and param.customerIds.size() != 0">
- and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <!--
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and concentrator_id IN (
- SELECT DISTINCT
- rd.concentrator_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,
- device_type_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_device_type dt on (tmp.device_type_id = dt.id)
- left join sc_device_manufacturer m on (dt.manufacturer_id = m.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
- ORDER BY read_rate DESC
- </select>
-
- <sql id="base_query_getListBy15Day">
- SELECT
- cust.customer_name as customer_name,
- con.serial_number as serial_number,
- concat_ws('/',m.name,dt.equipment_type,dt.model) as device_type_name,
- 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,
- meter_type_id as device_type_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_concentrator_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.customerIds != null and param.customerIds.size() != 0">
- and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <!--
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and concentrator_id IN (
- SELECT DISTINCT
- rd.concentrator_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,
- device_type_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_device_type dt on (tmp.device_type_id = dt.id)
- left join sc_device_manufacturer m on (dt.manufacturer_id = m.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_getListBy7Day" />
- <include refid="where_clause"/>
- ) tmp
- ORDER BY read_rate DESC
- </select>
- <!-- 今日抄表率 -->
- <sql id="base_query_getListByToday">
- SELECT
- cust.customer_name as customer_name,
- con.serial_number as serial_number,
- concat_ws('/',m.name,dt.equipment_type,dt.model) as device_type_name,
- 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,
- device_type_id,
- count(1) as device_count,
- count(1) AS read_times,
- SUM(IF(read_status = 2, 1, 0)) as real_read_times,
- SUM(IF(read_status = 1, 1, 0)) as un_read_times ,
- convert( SUM(IF(read_status = 2, 1, 0)) / count(1) * 100, decimal(5,2) ) AS read_rate
- FROM
- sc_meter_read_record
- WHERE 1 = 1
- and device_type_id IN ( SELECT device_type_id FROM sc_w_meter_type WHERE parent_id = 1 )
- <!-- 表类型 -->
- <if test="param.deviceTypeId != null ">
- and device_type_id = #{param.deviceTypeId}
- </if>
- <!-- 数据权限 -->
- <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
- <if test="param.customerIds != null and param.customerIds.size() != 0">
- and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <!--
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and concentrator_id IN (
- SELECT DISTINCT
- rd.concentrator_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 read_date = #{param.statDay}</if>
- GROUP BY
- customer_id,
- concentrator_id,
- device_type_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_device_type dt on (tmp.device_type_id = dt.id)
- left join sc_device_manufacturer m on (dt.manufacturer_id = m.id)
- </sql>
- <select id="getListByToday_COUNT" resultType="Long">
- SELECT
- count(1)
- FROM
- (
- SELECT
- customer_id,
- concentrator_id,
- device_type_id,
- count(1) as device_count,
- count(1) AS read_times,
- SUM(IF(read_status = 2, 1, 0)) as real_read_times,
- SUM(IF(read_status = 1, 1, 0)) as un_read_times ,
- convert( SUM(IF(read_status = 2, 1, 0)) / count(1) * 100, decimal(5,2) ) AS read_rate
- FROM
- sc_meter_read_record
- WHERE 1 = 1
- and device_type_id IN ( SELECT device_type_id FROM sc_w_meter_type WHERE parent_id = 1 )
- <!-- 表类型 -->
- <if test="param.deviceTypeId != null ">
- and device_type_id = #{param.deviceTypeId}
- </if>
- <!-- 数据权限 -->
- <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
- <if test="param.customerIds != null and param.customerIds.size() != 0">
- and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <!--
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and concentrator_id IN (
- SELECT DISTINCT
- rd.concentrator_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 read_date = #{param.statDay}</if>
- GROUP BY
- customer_id,
- concentrator_id,
- device_type_id
- ) tmp
- 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.concentratorId != null">and tmp.concentrator_id = #{param.concentratorId}</if>
- <if test = "param.deviceTypeId != null" >and tmp.device_type_id = #{param.deviceTypeId}</if>
- </select>
- <select id="getListByToday" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_query_getListByToday" />
- <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="summaryListByToday" 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_getListByToday" />
- <include refid="where_clause"/>
- ) tmp
- ORDER BY read_rate DESC
- </select>
- <!-- 按月查询抄表率 -->
- <sql id="base_query_getListByMonth">
- SELECT
- cust.customer_name as customer_name,
- con.serial_number as serial_number,
- concat_ws('/',m.name,dt.equipment_type,dt.model) as device_type_name,
- 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,
- meter_type_id as device_type_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_concentrator_month
- 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.customerIds != null and param.customerIds.size() != 0">
- and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <!--
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and concentrator_id IN (
- SELECT DISTINCT
- rd.concentrator_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_month = #{param.statDay}</if>
- GROUP BY
- customer_id,
- concentrator_id,
- device_type_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_device_type dt on (tmp.device_type_id = dt.id)
- left join sc_device_manufacturer m on (dt.manufacturer_id = m.id)
- </sql>
- <select id="getListByMonth" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
- <include refid="base_query_getListByMonth" />
- <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="summaryListByMonth" 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_getListByMonth" />
- <include refid="where_clause"/>
- ) tmp
- ORDER BY read_rate DESC
- </select>
- </mapper>
|