1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804 |
- <?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.MeterReadRecordMapper">
- <!--auto generated Code-->
- <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.MeterReadRecord">
- <result column="id" property="id" jdbcType="BIGINT"/>
- <result column="read_date" property="readDate" jdbcType="INTEGER"/>
- <result column="site_id" property="siteId" jdbcType="INTEGER"/>
- <result column="sys_id" property="sysId" jdbcType="INTEGER"/>
- <result column="province" property="province" jdbcType="INTEGER"/>
- <result column="city" property="city" jdbcType="INTEGER"/>
- <result column="region" property="region" jdbcType="INTEGER"/>
- <result column="community" property="communityId" jdbcType="VARCHAR"/>
- <result column="building_id" property="buildingId" jdbcType="INTEGER"/>
- <result column="location" property="location" jdbcType="VARCHAR"/>
- <result column="device_type_id" property="deviceTypeId" jdbcType="INTEGER"/>
- <result column="device_id" property="deviceId" jdbcType="BIGINT"/>
- <result column="device_no" property="deviceNo" jdbcType="VARCHAR"/>
- <result column="meter_no" property="meterNo" jdbcType="VARCHAR"/>
- <result column="meter_file_no" property="meterFileNo" jdbcType="VARCHAR"/>
- <result column="read_time" property="readTime" jdbcType="TIMESTAMP"/>
- <result column="read_status" property="readStatus" jdbcType="VARCHAR"/>
- <result column="read_data" property="readData" jdbcType="VARCHAR"/>
- <result column="last_valid" property="lastValid" jdbcType="VARCHAR"/>
- <result column="last_cost" property="lastCost" jdbcType="DECIMAL"/>
- <result column="status" property="status" jdbcType="INTEGER"/>
- <result column="date_create" property="dateCreate" jdbcType="TIMESTAMP"/>
- <result column="date_update" property="dateUpdate" jdbcType="TIMESTAMP"/>
- <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
- <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
- </resultMap>
- <!--auto generated Code-->
- <sql id="Base_Column_List">
- id,
- read_date,
- site_id,
- sys_id,
- province,
- city,
- region,
- community,
- building_id,
- location,
- device_type_id,
- device_id,
- device_no,
- meter_no,
- meter_file_no,
- read_time,
- read_status,
- read_data,
- last_valid,
- last_cost,
- status,
- date_create,
- date_update,
- create_by,
- update_by
- </sql>
- <!--auto generated Code-->
- <insert id="insert" useGeneratedKeys="true" keyProperty="meterReadRecord.id">
- INSERT INTO sc_meter_read_record (
- id,
- read_date,
- site_id,
- sys_id,
- province,
- city,
- region,
- community,
- building_id,
- location,
- device_type_id,
- device_id,
- device_no,
- meter_no,
- meter_file_no,
- read_time,
- read_status,
- read_data,
- last_valid,
- last_cost,
- status,
- date_create,
- date_update,
- create_by,
- update_by
- ) VALUES (
- #{meterReadRecord.id,jdbcType=BIGINT},
- #{meterReadRecord.readDate,jdbcType=INTEGER},
- #{meterReadRecord.siteId,jdbcType=INTEGER},
- #{meterReadRecord.sysId,jdbcType=INTEGER},
- #{meterReadRecord.province,jdbcType=INTEGER},
- #{meterReadRecord.city,jdbcType=INTEGER},
- #{meterReadRecord.region,jdbcType=INTEGER},
- #{meterReadRecord.communityId,jdbcType=VARCHAR},
- #{meterReadRecord.buildingId,jdbcType=INTEGER},
- #{meterReadRecord.location,jdbcType=VARCHAR},
- #{meterReadRecord.deviceTypeId,jdbcType=INTEGER},
- #{meterReadRecord.deviceId,jdbcType=BIGINT},
- #{meterReadRecord.deviceNo,jdbcType=VARCHAR},
- #{meterReadRecord.meterNo,jdbcType=VARCHAR},
- #{meterReadRecord.meterFileNo,jdbcType=VARCHAR},
- #{meterReadRecord.readTime,jdbcType=TIMESTAMP},
- #{meterReadRecord.readStatus,jdbcType=VARCHAR},
- #{meterReadRecord.readData,jdbcType=VARCHAR},
- #{meterReadRecord.lastValid,jdbcType=VARCHAR},
- #{meterReadRecord.lastCost,jdbcType=DECIMAL},
- #{meterReadRecord.status,jdbcType=INTEGER},
- #{meterReadRecord.dateCreate,jdbcType=TIMESTAMP},
- #{meterReadRecord.dateUpdate,jdbcType=TIMESTAMP},
- #{meterReadRecord.createBy,jdbcType=VARCHAR},
- #{meterReadRecord.updateBy,jdbcType=VARCHAR}
- )
- </insert>
- <!--auto generated Code-->
- <insert id="insertSelective" useGeneratedKeys="true" keyProperty="meterReadRecord.id">
- INSERT INTO sc_meter_read_record
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="meterReadRecord.id!=null"> id,</if>
- <if test="meterReadRecord.readDate!=null"> read_date,</if>
- <if test="meterReadRecord.siteId!=null"> site_id,</if>
- <if test="meterReadRecord.sysId!=null"> sys_id,</if>
- <if test="meterReadRecord.province!=null"> province,</if>
- <if test="meterReadRecord.city!=null"> city,</if>
- <if test="meterReadRecord.region!=null"> region,</if>
- <if test="meterReadRecord.communityId!=null"> community,</if>
- <if test="meterReadRecord.buildingId!=null"> building_id,</if>
- <if test="meterReadRecord.location!=null"> location,</if>
- <if test="meterReadRecord.deviceTypeId!=null"> device_type_id,</if>
- <if test="meterReadRecord.deviceId!=null"> device_id,</if>
- <if test="meterReadRecord.deviceNo!=null"> device_no,</if>
- <if test="meterReadRecord.meterNo!=null"> meter_no,</if>
- <if test="meterReadRecord.meterFileNo!=null"> meter_file_no,</if>
- <if test="meterReadRecord.readTime!=null"> read_time,</if>
- <if test="meterReadRecord.readStatus!=null"> read_status,</if>
- <if test="meterReadRecord.readData!=null"> read_data,</if>
- <if test="meterReadRecord.lastValid!=null"> last_valid,</if>
- <if test="meterReadRecord.lastCost!=null"> last_cost,</if>
- <if test="meterReadRecord.status!=null"> status,</if>
- <if test="meterReadRecord.dateCreate!=null"> date_create,</if>
- <if test="meterReadRecord.dateUpdate!=null"> date_update,</if>
- <if test="meterReadRecord.createBy!=null"> create_by,</if>
- <if test="meterReadRecord.updateBy!=null"> update_by,</if>
- </trim>
- VALUES
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="meterReadRecord.id!=null">#{meterReadRecord.id,jdbcType=BIGINT},
- </if>
- <if test="meterReadRecord.readDate!=null">#{meterReadRecord.readDate,jdbcType=INTEGER},
- </if>
- <if test="meterReadRecord.siteId!=null">#{meterReadRecord.siteId,jdbcType=INTEGER},
- </if>
- <if test="meterReadRecord.sysId!=null">#{meterReadRecord.sysId,jdbcType=INTEGER},
- </if>
- <if test="meterReadRecord.province!=null">#{meterReadRecord.province,jdbcType=INTEGER},
- </if>
- <if test="meterReadRecord.city!=null">#{meterReadRecord.city,jdbcType=INTEGER},
- </if>
- <if test="meterReadRecord.region!=null">#{meterReadRecord.region,jdbcType=INTEGER},
- </if>
- <if test="meterReadRecord.communityId!=null">#{meterReadRecord.communityId,jdbcType=VARCHAR},
- </if>
- <if test="meterReadRecord.buildingId!=null">#{meterReadRecord.buildingId,jdbcType=INTEGER},
- </if>
- <if test="meterReadRecord.location!=null">#{meterReadRecord.location,jdbcType=VARCHAR},
- </if>
- <if test="meterReadRecord.deviceTypeId!=null">#{meterReadRecord.deviceTypeId,jdbcType=INTEGER},
- </if>
- <if test="meterReadRecord.deviceId!=null">#{meterReadRecord.deviceId,jdbcType=BIGINT},
- </if>
- <if test="meterReadRecord.deviceNo!=null">#{meterReadRecord.deviceNo,jdbcType=VARCHAR},
- </if>
- <if test="meterReadRecord.meterNo!=null">#{meterReadRecord.meterNo,jdbcType=VARCHAR},
- </if>
- <if test="meterReadRecord.meterFileNo!=null">#{meterReadRecord.meterFileNo,jdbcType=VARCHAR},
- </if>
- <if test="meterReadRecord.readTime!=null">#{meterReadRecord.readTime,jdbcType=TIMESTAMP},
- </if>
- <if test="meterReadRecord.readStatus!=null">#{meterReadRecord.readStatus,jdbcType=VARCHAR},
- </if>
- <if test="meterReadRecord.readData!=null">#{meterReadRecord.readData,jdbcType=VARCHAR},
- </if>
- <if test="meterReadRecord.lastValid!=null">#{meterReadRecord.lastValid,jdbcType=VARCHAR},
- </if>
- <if test="meterReadRecord.lastCost!=null">#{meterReadRecord.lastCost,jdbcType=DECIMAL},
- </if>
- <if test="meterReadRecord.status!=null">#{meterReadRecord.status,jdbcType=INTEGER},
- </if>
- <if test="meterReadRecord.dateCreate!=null">#{meterReadRecord.dateCreate,jdbcType=TIMESTAMP},
- </if>
- <if test="meterReadRecord.dateUpdate!=null">#{meterReadRecord.dateUpdate,jdbcType=TIMESTAMP},
- </if>
- <if test="meterReadRecord.createBy!=null">#{meterReadRecord.createBy,jdbcType=VARCHAR},
- </if>
- <if test="meterReadRecord.updateBy!=null">#{meterReadRecord.updateBy,jdbcType=VARCHAR},
- </if>
- </trim>
- </insert>
- <!--auto generated Code-->
- <insert id="insertList">
- replace INTO sc_meter_read_record (
- id,
- read_date,
- site_id,
- sys_id,
- province,
- city,
- region,
- community,
- customer_id,
- building_id,
- location,
- device_type_id,
- device_id,
- device_no,
- meter_no,
- meter_file_no,
- read_time,
- read_status,
- read_data,
- last_valid,
- last_cost,
- status,
- date_create,
- date_update,
- create_by,
- update_by
- )VALUES
- <foreach collection="meterReadRecords" item="meterReadRecord" index="index" separator=",">
- (
- #{meterReadRecord.id,jdbcType=BIGINT},
- #{meterReadRecord.readDate,jdbcType=INTEGER},
- #{meterReadRecord.siteId,jdbcType=INTEGER},
- #{meterReadRecord.sysId,jdbcType=INTEGER},
- #{meterReadRecord.province,jdbcType=INTEGER},
- #{meterReadRecord.city,jdbcType=INTEGER},
- #{meterReadRecord.region,jdbcType=INTEGER},
- #{meterReadRecord.communityId,jdbcType=INTEGER},
- #{meterReadRecord.customerId,jdbcType=INTEGER},
- #{meterReadRecord.buildingId,jdbcType=INTEGER},
- #{meterReadRecord.location,jdbcType=VARCHAR},
- #{meterReadRecord.deviceTypeId,jdbcType=INTEGER},
- #{meterReadRecord.deviceId,jdbcType=BIGINT},
- #{meterReadRecord.deviceNo,jdbcType=VARCHAR},
- #{meterReadRecord.meterNo,jdbcType=VARCHAR},
- #{meterReadRecord.meterFileNo,jdbcType=VARCHAR},
- #{meterReadRecord.readTime,jdbcType=TIMESTAMP},
- #{meterReadRecord.readStatus,jdbcType=VARCHAR},
- #{meterReadRecord.readData,jdbcType=VARCHAR},
- #{meterReadRecord.lastValid, jdbcType=VARCHAR},
- #{meterReadRecord.lastCost,jdbcType=DECIMAL},
- #{meterReadRecord.status,jdbcType=INTEGER},
- #{meterReadRecord.dateCreate,jdbcType=TIMESTAMP},
- #{meterReadRecord.dateUpdate,jdbcType=TIMESTAMP},
- #{meterReadRecord.createBy,jdbcType=VARCHAR},
- #{meterReadRecord.updateBy,jdbcType=VARCHAR}
- )
- </foreach>
- </insert>
- <!--auto generated Code-->
- <update id="updateByPrimaryKeySelective">
- UPDATE sc_meter_read_record
- <set>
- <if test="meterReadRecord.readDate != null"> read_date= #{meterReadRecord.readDate,jdbcType=INTEGER},</if>
- <if test="meterReadRecord.siteId != null"> site_id= #{meterReadRecord.siteId,jdbcType=INTEGER},</if>
- <if test="meterReadRecord.sysId != null"> sys_id= #{meterReadRecord.sysId,jdbcType=INTEGER},</if>
- <if test="meterReadRecord.province != null"> province= #{meterReadRecord.province,jdbcType=INTEGER},</if>
- <if test="meterReadRecord.city != null"> city= #{meterReadRecord.city,jdbcType=INTEGER},</if>
- <if test="meterReadRecord.region != null"> region= #{meterReadRecord.region,jdbcType=INTEGER},</if>
- <if test="meterReadRecord.communityId != null"> community= #{meterReadRecord.communityId,jdbcType=VARCHAR},</if>
- <if test="meterReadRecord.buildingId != null"> building_id= #{meterReadRecord.buildingId,jdbcType=INTEGER},</if>
- <if test="meterReadRecord.location != null"> location= #{meterReadRecord.location,jdbcType=VARCHAR},</if>
- <if test="meterReadRecord.deviceTypeId != null"> device_type_id= #{meterReadRecord.deviceTypeId,jdbcType=INTEGER},</if>
- <if test="meterReadRecord.deviceId != null"> device_id= #{meterReadRecord.deviceId,jdbcType=BIGINT},</if>
- <if test="meterReadRecord.deviceNo != null"> device_no= #{meterReadRecord.deviceNo,jdbcType=VARCHAR},</if>
- <if test="meterReadRecord.meterNo != null"> meter_no= #{meterReadRecord.meterNo,jdbcType=VARCHAR},</if>
- <if test="meterReadRecord.meterFileNo != null"> meter_file_no= #{meterReadRecord.meterFileNo,jdbcType=VARCHAR},</if>
- <if test="meterReadRecord.readTime != null"> read_time= #{meterReadRecord.readTime,jdbcType=TIMESTAMP},</if>
- <if test="meterReadRecord.readStatus != null"> read_status= #{meterReadRecord.readStatus,jdbcType=VARCHAR},</if>
- <if test="meterReadRecord.readData != null"> read_data= #{meterReadRecord.readData,jdbcType=VARCHAR},</if>
- <if test="meterReadRecord.lastValid!=null"> last_valid = #{meterReadRecord.lastValid,jdbcType=VARCHAR},</if>
- <if test="meterReadRecord.lastCost!=null"> last_cost = #{meterReadRecord.lastCost,jdbcType=DECIMAL},</if>
- <if test="meterReadRecord.status != null"> status= #{meterReadRecord.status,jdbcType=INTEGER},</if>
- <if test="meterReadRecord.dateCreate != null"> date_create= #{meterReadRecord.dateCreate,jdbcType=TIMESTAMP},</if>
- <if test="meterReadRecord.dateUpdate != null"> date_update= #{meterReadRecord.dateUpdate,jdbcType=TIMESTAMP},</if>
- <if test="meterReadRecord.createBy != null"> create_by= #{meterReadRecord.createBy,jdbcType=VARCHAR},</if>
- <if test="meterReadRecord.updateBy != null"> update_by= #{meterReadRecord.updateBy,jdbcType=VARCHAR}</if>
- </set>
- WHERE id = #{meterReadRecord.id,jdbcType=BIGINT}
- </update>
- <select id="queryMeterReadRecord" resultType="com.bz.smart_city.entity.MeterReadRecord">
- select
- m.id as id,
- read_date,
- m.site_id as site_id,
- m.sys_id as sys_id,
- m.province as province,
- m.city as city,
- m.region as region,
- m.community as community,
- m.building_id as building_id,
- b.name as building_name,
- m.location as location,
- device_type_id,
- device_id,
- device_no,
- meter_no,
- meter_file_no,
- read_time,
- read_status,
- read_data,
- m.status as status
- from
- sc_meter_read_record m
- left join sc_building b on ( building_id = b.id)
- where 1=1
- <if test="param.siteId != null and param.siteId != 0"> and m.site_id = #{param.siteId}</if>
- <if test="param.buildingId != null and param.buildingId != 0"> and building_id = #{param.buildingId}</if>
- <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
- <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
- <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
- <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
- and m.status = 1
- order by read_time desc
- </select>
- <!--
- <select id="statisticReadRecordsByProvince" resultType="com.bz.smart_city.entity.MeterRecordStat">
- SELECT
- '省' as level,
- a.province as item_id,
- a.NAME as item_name,
- CASE WHEN b.total IS NULL THEN 0 ELSE b.total END AS total
- FROM
- (
- SELECT
- DISTINCT
- province,
- a.NAME
- FROM
- sc_building
- LEFT JOIN sc_area a ON (province = a.id )
- WHERE
- 1 = 1
- and STATUS = 1
- <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 <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- <if test = 'item.dimensionCode == "PROVINCE" '>
- province = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "CITY" '>
- city = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "REGION" '>
- region = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "COMMUNITY" '>
- community = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "BUILDING" '>
- id = #{item.dimensionValue}
- </if>
- </foreach>
- </if>
- ) a
- LEFT JOIN (
- SELECT
- province,
- count( 1 ) AS total
- FROM
- sc_meter_read_record
- WHERE
- 1 = 1
- AND STATUS = 1
- <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</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 EXISTS (
- select 1 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 WHERE ud.device_id = device_id)
- </if>
-
- <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
- <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
- <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
- <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
- GROUP BY
- province
- ) b ON ( a.province = b.province )
- order by total desc
- </select>
- <select id="statisticReadRecordsByCity" resultType="com.bz.smart_city.entity.MeterRecordStat">
- SELECT
- '市' as level,
- a.city as item_id,
- a.NAME as item_name,
- CASE WHEN b.total IS NULL THEN 0 ELSE b.total END AS total
- FROM
- (
- SELECT
- DISTINCT
- city,
- a.NAME
- FROM
- sc_building
- LEFT JOIN sc_area a ON (city = a.id )
- WHERE
- 1 = 1
- and STATUS = 1
- <if test = "param.siteId != null and param.siteId != 0"> and site_id = #{param.siteId}</if>
- <if test = "param.province != null and param.province != ''"> and province = #{param.province}</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" '>
- province = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "CITY" '>
- city = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "REGION" '>
- region = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "COMMUNITY" '>
- community = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "BUILDING" '>
- id = #{item.dimensionValue}
- </if>
- </foreach>
- </if>
- ) a
- LEFT JOIN (
- SELECT
- city,
- count( 1 ) AS total
- FROM
- sc_meter_read_record
- WHERE
- 1 = 1
- AND STATUS = 1
- <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</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 EXISTS (
- select 1 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 WHERE ud.device_id = device_id)
- </if>
- <if test = "param.province != null and param.province != ''"> and province = #{param.province}</if>
- <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
- <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
- <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
- <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
- GROUP BY
- city
- ) b ON ( a.city = b.city )
- order by total desc
- </select>
- -->
- <!-- 按照小区进行汇总
- <select id="statisticReadRecordsByCommunity" resultType="com.bz.smart_city.entity.MeterRecordStat">
- SELECT
- '小区' as level,
- a.community as item_id,
- a.NAME as item_name,
- CASE WHEN b.total IS NULL THEN 0 ELSE b.total END AS total
- FROM
- (
- SELECT
- DISTINCT
- community,
- a.NAME
- FROM
- sc_building b
- left join sc_community a on (community = a.id)
- WHERE
- 1 = 1
- and a.STATUS = 1
- <if test = "param.siteId != null and param.siteId != 0"> and b.site_id = #{param.siteId}</if>
- <if test = "param.city != null and param.city != ''"> and b.city = #{param.city}</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" '>
- b.province = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "CITY" '>
- b.city = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "REGION" '>
- b.region = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "COMMUNITY" '>
- b.community = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "BUILDING" '>
- b.id = #{item.dimensionValue}
- </if>
- </foreach>
- </if>
- ) a
- LEFT JOIN (
- SELECT
- community,
- count( 1 ) AS total
- FROM
- sc_meter_read_record
- WHERE
- 1 = 1
- AND STATUS = 1
- <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</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 EXISTS (
- select 1 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 WHERE ud.device_id = device_id)
- </if>
- <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
- <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
- <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
- <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
- <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
- GROUP BY
- community
- ) b ON ( a.community = b.community )
- order by total desc
- </select>
- -->
- <update id = "createTmpTable">
- create TEMPORARY table ${tableName} as
- select
- province,
- city,
- community,
- building_id,
- id
- from
- sc_meter_read_record
- where status = 1
- <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</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 device_id in (
- select
- 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>
- )
- </if>
- <if test = "param.province != null and param.province != ''"> and province = #{param.province}</if>
- <if test = "param.region != null and param.region != ''"> and region = #{param.region}</if>
- <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
- <if test = "param.communityId != null and param.communityId != '' ">and community = #{param.communityId} </if>
- <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
- <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
- <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
- <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
- </update>
-
- <update id="dropTmpTable" >
- drop TEMPORARY table if exists ${tableName}
- </update>
-
- <select id= "statisticReadRecordsByProvince" resultType="com.bz.smart_city.entity.MeterRecordStat">
- select
- 1 as level,
- a.parent_id as parent_id,
- province as item_id,
- a.name as item_name,
- count(1) as total
- from
- ${tableName}
- left join sc_area a on (province = a.id)
- group by province,a.name,a.parent_id
- </select>
- <select id= "statisticReadRecordsByCity" resultType="com.bz.smart_city.entity.MeterRecordStat">
- select
- 2 as level,
- a.parent_id as parent_id,
- city as item_id,
- a.name as item_name,
- count(1) as total
- from
- ${tableName}
- left join sc_area a on (city = a.id)
- group by city,a.name,a.parent_id
- </select>
-
- <select id= "statisticReadRecordsByCommuinty" resultType="com.bz.smart_city.entity.MeterRecordStat">
- select
- 3 as level,
- a.city as parent_id,
- community as item_id,
- a.name as item_name,
- count(1) as total
- from
- ${tableName}
- left join sc_community a on (community = a.id)
- group by community,a.name,a.city
- </select>
-
-
- <select id= "statisticReadRecordsByBuilding" resultType="com.bz.smart_city.entity.MeterRecordStat">
- select
- 4 as level,
- a.community as parent_id,
- building_id as item_id,
- a.name as item_name,
- count(1) as total
- from
- ${tableName}
- left join sc_building a on (building_id = a.id)
- group by building_id,a.name,a.community
- </select>
-
- <!--
- <select id="statisticReadRecordsByRegion" resultType="com.bz.smart_city.entity.MeterRecordStat">
- SELECT
- '区' as level,
- a.region as item_id,
- a.NAME as item_name,
- CASE WHEN b.total IS NULL THEN 0 ELSE b.total END AS total
- FROM
- (
- SELECT DISTINCT
- region,
- NAME
- FROM
- sc_meter_read_record
- LEFT JOIN sc_area a ON ( region = a.id )
- WHERE
- 1 = 1
- AND a.STATUS = 1
- <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</if>
- <if test = "param.siteId !=null and param.siteId != 0"> and site_id = #{param.siteId}</if>
- <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
- ) a
- LEFT JOIN (
- SELECT
- region,
- count( 1 ) AS total
- FROM
- sc_meter_read_record
- WHERE
- 1 = 1
- AND STATUS = 1
- <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</if>
- <if test = "param.siteId !=null and param.siteId != 0"> and site_id = #{param.siteId}</if>
- <if test = "param.province != null and param.province != ''"> and province = #{param.province}</if>
- <if test = "param.region != null and param.region != ''"> and region = #{param.region}</if>
- <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
- <if test = "param.communityId != null and param.communityId != '' ">and community = #{param.communityId} </if>
- <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
- <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
- <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
- <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
- GROUP BY
- region
- ) b ON ( a.region = b.region )
- order by total desc
- </select>
-
- <select id="statisticReadRecordsByBuilding" resultType="com.bz.smart_city.entity.MeterRecordStat">
- SELECT
- '建筑' as level,
- a.id as item_id,
- a.name as item_name,
- case when b.total is null then 0 else b.total end as total
- FROM
- (
- SELECT
- DISTINCT
- id,
- NAME
- FROM
- sc_building
- WHERE
- 1 = 1
- and STATUS = 1
- <if test = "param.siteId != null and param.siteId != 0"> and site_id = #{param.siteId}</if>
- <if test = "param.province != null and param.province != ''"> and province = #{param.province}</if>
- <if test = "param.region != null and param.region != ''"> and region = #{param.region}</if>
- <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
- <if test=" param.communityId != null and param.communityId != '' ">and community = #{param.communityId} </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" '>
- province = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "CITY" '>
- city = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "REGION" '>
- region = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "COMMUNITY" '>
- community = #{item.dimensionValue}
- </if>
- <if test = 'item.dimensionCode == "BUILDING" '>
- id = #{item.dimensionValue}
- </if>
- </foreach>
- </if>
- ) a
- LEFT JOIN (
- SELECT
- building_id,
- count( 1 ) AS total
- FROM
- sc_meter_read_record
- WHERE
- 1 = 1
- AND STATUS = 1
- <if test = "param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</if>
- <if test = "param.siteId !=null and param.siteId != 0"> and site_id = #{param.siteId}</if>
- <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
- <if test = "param.region != null and param.region != ''"> and region = #{param.region}</if>
- <if test=" param.communityId != null and param.communityId != '' ">and community = #{param.communityId} </if>
- <if test='param.programItems != null and param.programItems.size() != 0' >
- and EXISTS (
- select 1 from
- (select
- distinct df.device_id
- FROM sc_device_dim_info df
- WHERE 1 = 1
- and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
- </foreach> ) ud WHERE ud.device_id = device_id)
- </if>
- <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
- <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
- <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
- <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
- GROUP BY
- building_id
- ) b ON ( a.id = b.building_id )
- order by b.total desc
- </select>
- -->
- <select id="queryMeterReadRecordWithCondtion" resultType="com.bz.smart_city.entity.MeterReadRecord">
- SELECT
- m.id AS id,
- m.read_date as read_date,
- m.site_id AS site_id,
- m.sys_id AS sys_id,
- m.province AS province,
- m.city AS city,
- m.community AS community_id,
- com.`name` as community_name,
- m.building_id AS building_id,
- b.NAME AS building_name,
- m.location AS location,
- device_type_id ,
- m.device_id,
- device_no,
- meter_no,
- meter_file_no,
- read_time,
- read_status,
- read_data,
- m.concentrator_id as concentrator_id,
- con.serial_number as concentrator_no,
- m.collector_id as collector_id ,
- col.collector_no as collector_no,
- m.customer_id as customer_id,
- cust.customer_name as customer_name,
- dt.manufacturer_id as factory_id,
- dt.equipment_type,
- dt.model,
- dm.`name` as factory_name,
- scn.channel_name as channel_number_name
- FROM
- sc_meter_read_record m
- LEFT JOIN sc_building b ON ( m.building_id = b.id )
- left join sc_community com on (com.id = m.community)
- left join sc_customer cust on (cust.id = m.customer_id)
- left join sc_concentrator con on (con.id = m.concentrator_id)
- left join sc_collector col on (col.id = m.collector_id)
- left join sc_device_type dt on (dt.id = m.device_type_id)
- left join sc_device_manufacturer dm on (dm.id = dt.manufacturer_id)
- left join sc_water_related_device wrd on (wrd.device_id = m.device_id)
- left join sc_channel_number scn on (scn.id = wrd.channel_number_id)
- WHERE m.STATUS = 1
- <!-- 数据权限 -->
- <if test="param.siteId != null and param.siteId != 0">
- and m.site_id = #{param.siteId}
- </if>
- <if test="param.sites != null and param.sites.size() != 0">
- and m.site_id in
- <foreach collection="param.sites" item="site" open="(" separator="," close=")">
- #{site.id}
- </foreach>
- </if>
- <if test="param.buildingIds != null and param.buildingIds.size() != 0">
- and m.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <if test="param.customerIds != null and param.customerIds.size() != 0">
- and m.customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
- <if test = "param.concentratorId != null"> and m.concentrator_id = #{param.concentratorId}</if>
- <if test = "param.channelNumberId != null"> and wrd.channel_number_id = #{param.channelNumberId}</if>
- <if test = "param.collectorCode != null and param.collectorCode != '' "> and col.collector_no like #{param.collectorCode}</if>
- <if test = "param.deviceNo != null and param.deviceNo != '' ">
- and m.meter_no like #{param.deviceElectricNo}
- </if>
- <if test = "param.custormerId !=null and param.custormerId != 0"> and m.customer_id = #{param.custormerId}</if>
- <if test = "param.communityId != null and param.communityId != 0"> and m.community = #{param.communityId}</if>
- <if test = "param.buildingId != null and param.buildingId != 0"> and m.building_id = #{param.buildingId}</if>
- <if test = 'param.readStatus != null and param.readStatus != ""'> and read_status = #{param.readStatus}</if>
- <if test = "param.channelId != null and param.channelId != 0"> and m.sys_id = #{param.channelId}</if>
- <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
- order by read_time desc
- </select>
- <select id="queryMeterReadRecordWithCondtion_COUNT" resultType="Long">
- SELECT
- count(1)
- FROM
- sc_meter_read_record m
- <if test = "param.concentratorCode != null and param.concentratorCode != '' ">left join sc_concentrator con on (con.id = m.concentrator_id)</if>
- <if test = "param.collectorCode != null and param.collectorCode != '' ">left join sc_collector col on (col.id = m.collector_id)</if>
- <if test = "param.channelNumberId != null">left join sc_water_related_device wrd on (wrd.device_id = m.device_id)</if>
- WHERE m.STATUS = 1
- <!-- 数据权限 -->
- <if test="param.siteId != null and param.siteId != 0">
- and m.site_id = #{param.siteId}
- </if>
- <if test="param.sites != null and param.sites.size() != 0">
- and m.site_id in
- <foreach collection="param.sites" item="site" open="(" separator="," close=")">
- #{site.id}
- </foreach>
- </if>
- <if test="param.buildingIds != null and param.buildingIds.size() != 0">
- and m.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <if test="param.customerIds != null and param.customerIds.size() != 0">
- and m.customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
- </if>
- <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
- <if test = "param.concentratorId != null"> and m.concentrator_id = #{param.concentratorId}</if>
- <if test = "param.channelNumberId != null"> and wrd.channel_number_id = #{param.channelNumberId}</if>
- <if test = "param.collectorCode != null and param.collectorCode != '' "> and col.collector_no like #{param.collectorCode}</if>
- <if test = "param.deviceNo != null and param.deviceNo != '' ">
- and m.meter_no like #{param.deviceElectricNo}
- </if>
- <if test = "param.custormerId !=null and param.custormerId != 0"> and m.customer_id = #{param.custormerId}</if>
- <if test = "param.communityId != null and param.communityId != 0"> and m.community = #{param.communityId}</if>
- <if test = "param.buildingId != null and param.buildingId != 0"> and m.building_id = #{param.buildingId}</if>
- <if test = 'param.readStatus != null and param.readStatus != ""'> and read_status = #{param.readStatus}</if>
- <if test = "param.channelId != null and param.channelId != 0"> and m.sys_id = #{param.channelId}</if>
- <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
- order by read_time desc
- </select>
- <select id="queryUnReadDeviceListWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
- SELECT
- d.site_id as siteId,
- d.customer_id as customerId,
- d.sys_id as sysId,
- d.id as id,
- d.device_type as deviceType,
- d.building_id as buildingId,
- co.id as community,
- p.id as province,
- c.id as city,
- r.id as region,
- cu.customer_name as customerName,
- b.`name`as buildingName,
- co.`name`as communityName,
- col.collector_no as collectorName,
- con.serial_number as concentratorName,
- d.water_meter_no as waterMeterNo,
- d.water_meter_file_no as waterMeterFileNo,
- d.device_no as deviceNo,
- d.device_status as deviceStatus,
- d.floor as floor,
- d.loc_desc as locDesc,
- d.last_receive_time as lastReceiveTime
- FROM
- sc_device d
- LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
- LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
- LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
- LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
- LEFT JOIN sc_area p ON ( b.province = p.id )
- LEFT JOIN sc_area c ON ( b.city = c.id )
- LEFT JOIN sc_area r ON ( b.region = r.id )
- LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
- LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
- LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
- where d.status = 1
- <if test = "param.buildingId != null and param.buildingId != 0">
- and d.building_id = #{param.buildingId}
- </if>
- <if test="param.siteId != null and param.siteId != 0">
- and d.site_id = #{param.siteId}
- </if>
- <if test = "param.channelId != null and param.channelId != 0">
- and d.sys_id = #{param.channelId}
- </if>
- <if test="param.custormerId != null and param.custormerId != 0">
- and d.customer_id = #{param.custormerId}
- </if>
- and ( d.id IN (
- SELECT
- tmp.device_id
- FROM
- (
- SELECT
- site_id,
- sys_id,
- building_id,
- device_id
- FROM
- sc_meter_read_record
- WHERE
- <if test = "param.statDay != null and param.statDay != 0">
- read_date = #{param.statDay}
- </if>
- <if test = "param.buildingId != null and param.buildingId != 0">
- AND building_id = #{param.buildingId}
- </if>
- AND read_status = 1
- ) tmp
- ) or d.device_status = 5)
- </select>
- <select id="queryUnReadDeviceList" resultType="com.bz.smart_city.dto.DeviceDto">
- SELECT
- d.site_id as siteId,
- d.customer_id as customerId,
- d.sys_id as sysId,
- d.id as id,
- d.device_type as deviceType,
- d.building_id as buildingId,
- co.id as community,
- p.id as province,
- c.id as city,
- r.id as region,
- cu.customer_name as customerName,
- b.`name`as buildingName,
- co.`name`as communityName,
- col.collector_no as collectorName,
- con.serial_number as concentratorName,
- d.water_meter_no as waterMeterNo,
- d.water_meter_file_no as waterMeterFileNo,
- d.device_no as deviceNo,
- d.device_status as deviceStatus,
- d.floor as floor,
- d.loc_desc as locDesc,
- d.last_receive_time as lastReceiveTime
- FROM
- sc_device d
- LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
- LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
- LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
- LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
- LEFT JOIN sc_area p ON ( b.province = p.id )
- LEFT JOIN sc_area c ON ( b.city = c.id )
- LEFT JOIN sc_area r ON ( b.region = r.id )
- LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
- LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
- LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
- where d.status = 1
- <if test = "param.buildingId != null and param.buildingId != 0">
- and d.building_id = #{param.buildingId}
- </if>
- <if test="param.siteId != null and param.siteId != 0">
- and d.site_id = #{param.siteId}
- </if>
- <if test = "param.channelId != null and param.channelId != 0">
- and d.sys_id = #{param.channelId}
- </if>
- <if test="param.custormerId != null and param.custormerId != 0">
- and d.customer_id = #{param.custormerId}
- </if>
- and d.id IN (
- SELECT
- tmp.device_id
- FROM
- (
- SELECT
- site_id,
- channel_id,
- building_id,
- device_id
- FROM
- sc_stat_meter_unread_device_by_building
- WHERE
- <if test = "param.statDay != null and param.statDay != 0">
- stat_day = #{param.statDay}
- </if>
- <if test = "param.buildingId != null and param.buildingId != 0">
- AND building_id = #{param.buildingId}
- </if>
- ) tmp
- )
- </select>
- <select id="queryUnReadDeviceListV2" resultType="com.bz.smart_city.dto.DeviceDto">
- SELECT
- d.site_id as siteId,
- d.customer_id as customerId,
- d.sys_id as sysId,
- d.id as id,
- d.device_type as deviceType,
- d.building_id as buildingId,
- co.id as community,
- cu.customer_name as customerName,
- b.`name`as buildingName,
- co.`name`as communityName,
- col.collector_no as collectorName,
- con.serial_number as concentratorName,
- d.water_meter_no as waterMeterNo,
- d.water_meter_file_no as waterMeterFileNo,
- d.device_no as deviceNo,
- d.device_status as deviceStatus,
- d.floor as floor,
- d.loc_desc as locDesc,
- d.last_receive_time as lastReceiveTime
- FROM ${tableName} as t1
- LEFT JOIN sc_device d on(t1.device_id = d.id)
- LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
- LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
- LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
- LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
- LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
- LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
- where d.status = 1
- <if test = "param.buildingId != null and param.buildingId != 0">
- and d.building_id = #{param.buildingId}
- </if>
- <if test="param.siteId != null and param.siteId != 0">
- and d.site_id = #{param.siteId}
- </if>
- <if test = "param.channelId != null and param.channelId != 0">
- and d.sys_id = #{param.channelId}
- </if>
- <if test="param.custormerId != null and param.custormerId != 0">
- and d.customer_id = #{param.custormerId}
- </if>
- <if test = "param.statDay != null and param.statDay != 0">
- and t1.stat_day = #{param.statDay}
- </if>
- <if test = "param.buildingId != null and param.buildingId != 0">
- AND t1.building_id = #{param.buildingId}
- </if>
- </select>
- <select id="queryUnReadDeviceListForToday_COUNT" resultType="Long">
- SELECT
- count(device_id)
- FROM sc_meter_read_record
- WHERE read_status = 1
- <if test = "param.buildingId != null">
- and building_id = #{param.buildingId}
- </if>
- <if test="param.channelId != null">
- and sys_id = #{param.channelId}
- </if>
- <if test="param.custormerId != null ">
- and customer_id = #{param.custormerId}
- </if>
- AND read_date = DATE_FORMAT( now( ), '%Y%m%d' )
- </select>
- <select id="queryUnReadDeviceListForToday" resultType="com.bz.smart_city.dto.DeviceDto">
- SELECT
- d.site_id as siteId,
- d.customer_id as customerId,
- d.sys_id as sysId,
- d.id as id,
- d.device_type as deviceType,
- d.building_id as buildingId,
- col.collector_no as collectorName,
- con.serial_number as concentratorName,
- d.water_meter_no as waterMeterNo,
- d.water_meter_file_no as waterMeterFileNo,
- d.device_no as deviceNo,
- d.device_status as deviceStatus,
- d.floor as floor,
- d.loc_desc as locDesc,
- d.last_receive_time as lastReceiveTime
- FROM (
- SELECT
- device_id
- FROM sc_meter_read_record
- WHERE read_status = 1
- <if test = "param.buildingId != null">
- and building_id = #{param.buildingId}
- </if>
- <if test="param.channelId != null">
- and sys_id = #{param.channelId}
- </if>
- <if test="param.custormerId != null ">
- and customer_id = #{param.custormerId}
- </if>
- AND read_date = DATE_FORMAT( now( ), '%Y%m%d' )
- ) t1
- LEFT JOIN sc_device d on (t1.device_id = d.id)
- LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
- LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
- LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
- where d.status = 1
- </select>
- <select id="queryUnReadDeviceListFor7Day" resultType="com.bz.smart_city.dto.DeviceDto">
- SELECT
- d.site_id as siteId,
- d.customer_id as customerId,
- d.sys_id as sysId,
- d.id as id,
- d.device_type as deviceType,
- d.building_id as buildingId,
- co.id as community,
- p.id as province,
- c.id as city,
- r.id as region,
- cu.customer_name as customerName,
- b.`name`as buildingName,
- co.`name`as communityName,
- col.collector_no as collectorName,
- con.serial_number as concentratorName,
- d.water_meter_no as waterMeterNo,
- d.water_meter_file_no as waterMeterFileNo,
- d.device_no as deviceNo,
- d.device_status as deviceStatus,
- d.floor as floor,
- d.loc_desc as locDesc,
- d.last_receive_time as lastReceiveTime
- FROM
- sc_device d
- LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
- LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
- LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
- LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
- LEFT JOIN sc_area p ON ( b.province = p.id )
- LEFT JOIN sc_area c ON ( b.city = c.id )
- LEFT JOIN sc_area r ON ( b.region = r.id )
- LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
- LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
- LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
- where d.status = 1
- <if test = "param.buildingId != null and param.buildingId != 0">
- and d.building_id = #{param.buildingId}
- </if>
- <if test="param.siteId != null and param.siteId != 0">
- and d.site_id = #{param.siteId}
- </if>
- <if test = "param.channelId != null and param.channelId != 0">
- and d.sys_id = #{param.channelId}
- </if>
- <if test="param.custormerId != null and param.custormerId != 0">
- and d.customer_id = #{param.custormerId}
- </if>
- and d.id IN (
- SELECT
- tmp.device_id
- FROM
- (
- SELECT
- site_id,
- channel_id,
- building_id,
- device_id
- FROM
- sc_stat_meter_unread_device_by_building_7day
- WHERE
- <if test = "param.statDay != null and param.statDay != 0">
- stat_day = #{param.statDay}
- </if>
- <if test = "param.buildingId != null and param.buildingId != 0">
- AND building_id = #{param.buildingId}
- </if>
- ) tmp
- )
- </select>
- <select id="queryUnReadDeviceListFor7DayWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
- SELECT
- d.site_id as siteId,
- d.customer_id as customerId,
- d.sys_id as sysId,
- d.id as id,
- d.device_type as deviceType,
- d.building_id as buildingId,
- co.id as community,
- p.id as province,
- c.id as city,
- r.id as region,
- cu.customer_name as customerName,
- b.`name`as buildingName,
- co.`name`as communityName,
- col.collector_no as collectorName,
- con.serial_number as concentratorName,
- d.water_meter_no as waterMeterNo,
- d.water_meter_file_no as waterMeterFileNo,
- d.device_no as deviceNo,
- d.device_status as deviceStatus,
- d.floor as floor,
- d.loc_desc as locDesc,
- d.last_receive_time as lastReceiveTime
- FROM
- sc_device d
- LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
- LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
- LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
- LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
- LEFT JOIN sc_area p ON ( b.province = p.id )
- LEFT JOIN sc_area c ON ( b.city = c.id )
- LEFT JOIN sc_area r ON ( b.region = r.id )
- LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
- LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
- LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
- where d.status = 1
- <if test = "param.buildingId != null and param.buildingId != 0">
- and d.building_id = #{param.buildingId}
- </if>
- <if test="param.siteId != null and param.siteId != 0">
- and d.site_id = #{param.siteId}
- </if>
- <if test = "param.channelId != null and param.channelId != 0">
- and d.sys_id = #{param.channelId}
- </if>
- <if test="param.custormerId != null and param.custormerId != 0">
- and d.customer_id = #{param.custormerId}
- </if>
- and ( d.id IN (
- SELECT
- tmp.device_id
- FROM
- (
- SELECT
- site_id,
- channel_id,
- building_id,
- device_id
- FROM
- sc_stat_meter_unread_device_by_building_7day
- WHERE
- <if test = "param.statDay != null and param.statDay != 0">
- stat_day = #{param.statDay}
- </if>
- <if test = "param.buildingId != null and param.buildingId != 0">
- AND building_id = #{param.buildingId}
- </if>
- ) tmp
- ) or d.device_status = 5 )
- </select>
- <select id="queryUnReadDeviceListFor15Day" resultType="com.bz.smart_city.dto.DeviceDto">
- SELECT
- d.site_id as siteId,
- d.customer_id as customerId,
- d.sys_id as sysId,
- d.id as id,
- d.device_type as deviceType,
- d.building_id as buildingId,
- co.id as community,
- p.id as province,
- c.id as city,
- r.id as region,
- cu.customer_name as customerName,
- b.`name`as buildingName,
- co.`name`as communityName,
- col.collector_no as collectorName,
- con.serial_number as concentratorName,
- d.water_meter_no as waterMeterNo,
- d.water_meter_file_no as waterMeterFileNo,
- d.device_no as deviceNo,
- d.device_status as deviceStatus,
- d.floor as floor,
- d.loc_desc as locDesc,
- d.last_receive_time as lastReceiveTime
- FROM
- sc_device d
- LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
- LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
- LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
- LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
- LEFT JOIN sc_area p ON ( b.province = p.id )
- LEFT JOIN sc_area c ON ( b.city = c.id )
- LEFT JOIN sc_area r ON ( b.region = r.id )
- LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
- LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
- LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
- where d.status = 1
- <if test = "param.buildingId != null and param.buildingId != 0">
- and d.building_id = #{param.buildingId}
- </if>
- <if test="param.siteId != null and param.siteId != 0">
- and d.site_id = #{param.siteId}
- </if>
- <if test = "param.channelId != null and param.channelId != 0">
- and d.sys_id = #{param.channelId}
- </if>
- <if test="param.custormerId != null and param.custormerId != 0">
- and d.customer_id = #{param.custormerId}
- </if>
- and d.id IN (
- SELECT
- tmp.device_id
- FROM
- (
- SELECT
- site_id,
- channel_id,
- building_id,
- device_id
- FROM
- sc_stat_meter_unread_device_by_building_15day
- WHERE
- <if test = "param.statDay != null and param.statDay != 0">
- stat_day = #{param.statDay}
- </if>
- <if test = "param.buildingId != null and param.buildingId != 0">
- AND building_id = #{param.buildingId}
- </if>
- ) tmp
- )
- </select>
- <select id="queryUnReadDeviceListForMonth" resultType="com.bz.smart_city.dto.DeviceDto">
- SELECT
- d.site_id as siteId,
- d.customer_id as customerId,
- d.sys_id as sysId,
- d.id as id,
- d.device_type as deviceType,
- d.building_id as buildingId,
- co.id as community,
- p.id as province,
- c.id as city,
- r.id as region,
- cu.customer_name as customerName,
- b.`name`as buildingName,
- co.`name`as communityName,
- col.collector_no as collectorName,
- con.serial_number as concentratorName,
- d.water_meter_no as waterMeterNo,
- d.water_meter_file_no as waterMeterFileNo,
- d.device_no as deviceNo,
- d.device_status as deviceStatus,
- d.floor as floor,
- d.loc_desc as locDesc,
- d.last_receive_time as lastReceiveTime
- FROM
- sc_device d
- LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
- LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
- LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
- LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
- LEFT JOIN sc_area p ON ( b.province = p.id )
- LEFT JOIN sc_area c ON ( b.city = c.id )
- LEFT JOIN sc_area r ON ( b.region = r.id )
- LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
- LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
- LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
- where d.status = 1
- <if test = "param.buildingId != null and param.buildingId != 0">
- and d.building_id = #{param.buildingId}
- </if>
- <if test="param.siteId != null and param.siteId != 0">
- and d.site_id = #{param.siteId}
- </if>
- <if test = "param.channelId != null and param.channelId != 0">
- and d.sys_id = #{param.channelId}
- </if>
- <if test="param.custormerId != null and param.custormerId != 0">
- and d.customer_id = #{param.custormerId}
- </if>
- and d.id IN (
- SELECT
- tmp.device_id
- FROM
- (
- SELECT
- site_id,
- channel_id,
- building_id,
- device_id
- FROM
- sc_stat_meter_unread_device_by_building_month
- WHERE
- <if test = "param.statDay != null and param.statDay != 0">
- stat_day = #{param.statDay}
- </if>
- <if test = "param.buildingId != null and param.buildingId != 0">
- AND building_id = #{param.buildingId}
- </if>
- ) tmp
- )
- </select>
- <select id="queryUnReadDeviceListFor15DayWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
- SELECT
- d.site_id as siteId,
- d.customer_id as customerId,
- d.sys_id as sysId,
- d.id as id,
- d.device_type as deviceType,
- d.building_id as buildingId,
- co.id as community,
- p.id as province,
- c.id as city,
- r.id as region,
- cu.customer_name as customerName,
- b.`name`as buildingName,
- co.`name`as communityName,
- col.collector_no as collectorName,
- con.serial_number as concentratorName,
- d.water_meter_no as waterMeterNo,
- d.water_meter_file_no as waterMeterFileNo,
- d.device_no as deviceNo,
- d.device_status as deviceStatus,
- d.floor as floor,
- d.loc_desc as locDesc,
- d.last_receive_time as lastReceiveTime
- FROM
- sc_device d
- LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
- LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
- LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
- LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
- LEFT JOIN sc_area p ON ( b.province = p.id )
- LEFT JOIN sc_area c ON ( b.city = c.id )
- LEFT JOIN sc_area r ON ( b.region = r.id )
- LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
- LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
- LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
- where d.status = 1
- <if test = "param.buildingId != null and param.buildingId != 0">
- and d.building_id = #{param.buildingId}
- </if>
- <if test="param.siteId != null and param.siteId != 0">
- and d.site_id = #{param.siteId}
- </if>
- <if test = "param.channelId != null and param.channelId != 0">
- and d.sys_id = #{param.channelId}
- </if>
- <if test="param.custormerId != null and param.custormerId != 0">
- and d.customer_id = #{param.custormerId}
- </if>
- and (d.id IN (
- SELECT
- tmp.device_id
- FROM
- (
- SELECT
- site_id,
- channel_id,
- building_id,
- device_id
- FROM
- sc_stat_meter_unread_device_by_building_15day
- WHERE
- <if test = "param.statDay != null and param.statDay != 0">
- stat_day = #{param.statDay}
- </if>
- <if test = "param.buildingId != null and param.buildingId != 0">
- AND building_id = #{param.buildingId}
- </if>
- ) tmp
- ) or d.device_status = 5)
- </select>
- <select id="queryDeviceMeterReadRecordWithCondtion" resultType="com.bz.smart_city.entity.MeterReadRecord">
- select
- <include refid="Base_Column_List" />
- from
- sc_meter_read_record
- where read_status = 2
- and device_id = #{param.deviceId}
- <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
- <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
- order by read_date desc
- </select>
- <select id="getSummary" resultType="com.bz.smart_city.dto.WaterConsumptionSummaryDto">
- select
- ifnull(sum(result.water_consumption), 0) as total_water_consumption,
- count(result.device_id) as total_device_count
- from (
- select
- smrr.device_id as device_id,
- smrr.building_id as building_id,
- ifnull(sum(smrr.last_cost), 0) as water_consumption
- from
- sc_meter_read_record smrr
- where smrr.status = 1
- <if test="param.siteId != null"> and smrr.site_id = #{param.siteId}</if>
- <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
- <if test="param.buildingIds != null and param.buildingIds.size() != 0">
- and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
- </if>
- <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
- <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
- <if test="param.customerIds != null and param.customerIds.size() != 0"> and smrr.customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- group by
- smrr.device_id, smrr.building_id
- ) result
- left join sc_building sb on (result.building_id = sb.id and sb.status = 1)
- <if test="param.programItems != null and param.programItems.size() != 0"> left join sc_device_dimension sdd on (sdd.device_id = result.device_id and sdd.status = 1) </if>
- where 1 = 1
- <if test="param.programItems != null and param.programItems.size() != 0"> and
- <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- sdd.${item.dimensionCode} = #{item.dimensionValue}
- </foreach>
- </if>
- <if test="param.provinces != null and param.provinces.size() != 0">
- and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.cities != null and param.cities.size() != 0">
- and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.regions != null and param.regions.size() != 0">
- and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.communities != null and param.communities.size() != 0">
- and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.beginRate != null"> and result.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
- <if test="param.endRate != null"> and result.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
- </select>
- <select id="getList" resultType="com.bz.smart_city.dto.WaterConsumptionDto">
- select
- list.meter_no as meter_no,
- list.device_type as device_type,
- list.customer as customer,
- list.district as district,
- list.community as community,
- list.building as building,
- list.location as location,
- list.water_consumption as water_consumption
- from (
- select
- smrr.meter_no as meter_no,
- sdt.equipment_type as device_type,
- scu.customer_name as customer,
- replace(replace(sa.manger_name, "中国", ""), ",", "") as district,
- sco.name as community,
- sb.name as building,
- smrr.location as location,
- ifnull(sum(smrr.last_cost), 0) as water_consumption
- from
- sc_meter_read_record smrr
- left join sc_device_type sdt on (smrr.device_type_id = sdt.id and sdt.status = 1)
- left join sc_customer scu on (smrr.customer_id = scu.id and scu.status = 1)
- left join sc_building sb on (smrr.building_id = sb.id and sb.status = 1)
- left join sc_area sa on (sa.id = sb.region)
- left join sc_community sco on (sb.community = sco.id and sco.id)
- <if test="param.programItems != null and param.programItems.size() != 0"> left join sc_device_dimension sdd on (sdd.device_id = smrr.device_id and sdd.status = 1) </if>
- where
- smrr.status = 1
- <if test="param.siteId != null"> and smrr.site_id = #{param.siteId} </if>
- <if test="param.programItems != null and param.programItems.size() != 0"> and
- <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- sdd.${item.dimensionCode} = #{item.dimensionValue}
- </foreach>
- </if>
- <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
- <if test="param.provinces != null and param.provinces.size() != 0">
- and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.cities != null and param.cities.size() != 0">
- and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.regions != null and param.regions.size() != 0">
- and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.communities != null and param.communities.size() != 0">
- and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.buildingIds != null and param.buildingIds.size() != 0">
- and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
- </if>
- <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
- <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
- <if test="param.customerIds != null and param.customerIds.size() != 0"> and smrr.customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
- group by
- smrr.meter_no, sdt.equipment_type, scu.customer_name, district, sco.name, sb.name, smrr.location
- ) list
- where 1 = 1
- <if test="param.beginRate != null"> and list.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
- <if test="param.endRate != null"> and list.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
- <if test="param.sortOrder != null"> order by list.water_consumption ${param.sortOrder} </if>
- </select>
- <select id="getList_COUNT" resultType="Long">
- select
- count(result.device_id)
- from (
- select
- smrr.device_id as device_id,
- smrr.building_id as building_id,
- ifnull(sum(smrr.last_cost), 0) as water_consumption
- from
- sc_meter_read_record smrr
- where smrr.status = 1
- <if test="param.siteId != null"> and smrr.site_id = #{param.siteId}</if>
- <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
- <if test="param.buildingIds != null and param.buildingIds.size() != 0">
- and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
- </if>
- <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
- <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
- group by
- smrr.device_id, smrr.building_id
- ) result
- left join sc_building sb on (result.building_id = sb.id and sb.status = 1)
- <if test="param.programItems != null and param.programItems.size() != 0"> left join sc_device_dimension sdd on (sdd.device_id = result.device_id and sdd.status = 1) </if>
- where 1 = 1
- <if test="param.programItems != null and param.programItems.size() != 0"> and
- <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
- sdd.${item.dimensionCode} = #{item.dimensionValue}
- </foreach>
- </if>
- <if test="param.provinces != null and param.provinces.size() != 0">
- and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.cities != null and param.cities.size() != 0">
- and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.regions != null and param.regions.size() != 0">
- and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.communities != null and param.communities.size() != 0">
- and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
- </if>
- <if test="param.beginRate != null"> and result.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
- <if test="param.endRate != null"> and result.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
- </select>
- <select id="getLastDayData" resultMap="BaseResultMap">
- select
- <include refid="Base_Column_List" />
- from
- sc_meter_read_record
- where
- status = 1 and device_id = #{deviceId} and read_date = #{lastDate}
- </select>
- <select id="getLastDayDataV2" resultMap="BaseResultMap">
- select
- <include refid="Base_Column_List" />
- from
- sc_meter_read_record
- where
- status = 1 and device_id = #{deviceId} and read_date <![CDATA[ < ]]> #{lastDate} order by read_date desc limit 1
- </select>
- <select id="getAllDeviceId" resultType="Long">
- select distinct device_id
- from sc_meter_read_record
- where status = 1 and sys_id = -99
- <if test="startDate != null"> and read_date <![CDATA[ >= ]]> #{startDate} </if>
- order by device_id asc
- </select>
- <select id="getMeterReadRecordByDeviceId" resultMap="BaseResultMap">
- select
- <include refid="Base_Column_List" />
- from sc_meter_read_record
- where status = 1
- <if test="deviceId != null"> and device_id = #{deviceId} </if>
- <if test="startDate != null"> and read_date <![CDATA[ >= ]]> #{startDate} </if>
- order by read_date asc
- </select>
- <update id="batchUpdate" parameterType="list">
- UPDATE sc_meter_read_record
- <trim prefix="set" suffixOverrides=",">
- <trim prefix="last_valid =case" suffix="end,">
- <foreach collection="list" item="item">
- <if test="item.lastValid!=null">
- when id=#{item.id} then #{item.lastValid}
- </if>
- </foreach>
- </trim>
- <trim prefix="last_cost =case" suffix="end,">
- <foreach collection="list" item="item">
- <if test="item.lastCost!=null">
- when id=#{item.id} then #{item.lastCost}
- </if>
- </foreach>
- </trim>
- </trim>
- <where>
- id in <foreach collection="list" item="item" open="(" separator="," close=")">#{item.id}</foreach>
- </where>
- </update>
- <select id="getDeviceIdOnDate" resultType="Long">
- select
- device_id
- from sc_meter_read_record
- where status = 1 and read_date = #{date}
- limit #{limit}
- </select>
- <select id="queryMeterReadData" resultType="com.bz.smart_city.dto.MeterReadDataDTO">
- SELECT
- read_date as meter_read_date,
- device_no,
- meter_no as electronic_no,
- read_data as meter_read_data,
- read_time as meter_read_time
- FROM
- sc_meter_read_record
- WHERE
- read_status = 2
- AND read_date = #{meterReadDate}
- <if test="deviceNo != null and deviceNo != ''">
- and device_no = #{deviceNo}
- </if>
- <if test="electronicNo != null and electronicNo != ''">
- and meter_no = #{electronicNo}
- </if>
- <if test="custId != null">
- and customer_id = #{custId}
- </if>
- </select>
- <update id="updateHitoryData">
- UPDATE sc_meter_read_record
- <set>
- <if test="meterReadRecord.sysId != null"> sys_id= #{meterReadRecord.sysId,jdbcType=INTEGER},</if>
- </set>
- where device_id= #{meterReadRecord.deviceId,jdbcType=BIGINT}
- </update>
- <select id="findSyncMeterRecord" resultMap="BaseResultMap">
- select device_id,meter_file_no,read_data,read_time from sc_meter_read_record
- where read_date=#{readTime} and read_data is not null
- and device_id in
- <foreach collection="deviceIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </select>
- <select id="findMeterLastReadRecord" resultMap="BaseResultMap">
- select
- <include refid="Base_Column_List"></include>
- from
- sc_meter_read_record
- where device_id = #{deviceId,jdbcType=BIGINT}
- and read_status = 2
- and status = 1
- and read_date = ( SELECT max( read_date ) FROM sc_meter_read_record WHERE device_id = #{deviceId,jdbcType=BIGINT} and read_status = 2)
- limit 1
- </select>
- <select id="getReadingMeter" resultType="com.bz.smart_city.dto.RequestMaterInfo">
- select
- meter_file_no as ciid,
- meter_no as miid,
- read_data as mrecode,
- read_time as mrrdate,
- now() as mrinputdate,
- '' as mrinputper,
- if(read_status = 2,'Y','N') as mrreadok,
- 1 as mrface
- from sc_meter_read_record r
- where status = 1
- and customer_id = #{customerId} and read_date = #{date}
- <if test ="meterNo != null">
- and meter_no = #{meterNo}
- </if>
- </select>
- <select id="findById" resultMap="BaseResultMap">
- select id,device_id,concentrator_id,collector_id,building_id,read_status from sc_meter_read_record
- where status = 1
- and id in <foreach collection="ids" item="item" open="(" separator="," close=")">#{item}</foreach>
- </select>
- </mapper>
|