| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <?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.template.mapper.WechatScanLoginMapper">
- <resultMap id="Tj" type="com.template.model.tongji.Tj">
- <result property="name" column="name"/>
- <result property="num" column="num"/>
- <result property="date" column="date"/>
- </resultMap>
- <resultMap id="Tjt" type="com.template.model.tongji.All">
- <result property="total" column="total"/>
- </resultMap>
- <resultMap id="Elct" type="com.template.model.tongji.DAll">
- <result property="num" column="num"/>
- </resultMap>
- <resultMap id="Energy" type="com.template.model.tongji.EnergyTj">
- <result property="name" column="name"/>
- <result property="meterName" column="meter_name"/>
- <result property="num" column="num"/>
- </resultMap>
- <resultMap id="MonthT" type="com.template.model.tongji.EnergyTj">
- <result property="id" column="id"/>
- <result property="name" column="name"/>
- <result property="type" column="type"/>
- <result property="date" column="date"/>
- <result property="num" column="num"/>
- </resultMap>
- <resultMap id="DayT" type="com.template.model.tongji.EnergyTj">
- <result property="id" column="id"/>
- <result property="name" column="name"/>
- <result property="type" column="type"/>
- <result property="date" column="date"/>
- <result property="num" column="num"/>
- </resultMap>
- <resultMap id="meterMonthDataVo" type="com.template.model.tongji.MeterMonthDataVo">
- <result property="id" column="id"/>
- <result property="buildAddress" column="build_address"/>
- <result property="address" column="address"/>
- <result property="meterPower" column="meter_power"/>
- <result property="meterPowerRecord" column="meter_power_record"/>
- <result property="meterNo" column="meter_no"/>
- <result property="createTime" column="create_time"/>
- </resultMap>
- <resultMap id="meterMonthData" type="com.template.model.tongji.MeterMonthData">
- <result property="id" column="id"/>
- <result property="name" column="name"/>
- <result property="type" column="type"/>
- <result property="date" column="date"/>
- <result property="num" column="num"/>
- </resultMap>
- <!--用户类别统计-->
- <select id="getUserIdTj" parameterType="com.template.model.tongji.Tj" resultMap="Tj">
- select a.name,IFNULL(b.num,0) as num from `smart_identity` a
- left join (
- select identity_id,COUNT(*) as num from `smart_user`
- where is_cancel=0 and deleted=0 group by identity_id ) b
- on a.id=b.identity_id where a.`deleted`=0
- </select>
- <!--用户总数-->
- <select id="getUserIdTjt" parameterType="com.template.model.tongji.Tj" resultMap="Tjt">
- select count(*) as total from `smart_user` where is_cancel=0 and deleted=0
- </select>
- <!--水表总计-->
- <select id="getWaterTj" parameterType="com.template.model.tongji.Tj" resultMap="Elct">
- select ifnull(sum(meter_power),0) as num from `smart_meter_detail` where meter_type=0 and deleted=0
- </select>
- <!--电表总计-->
- <select id="getElcTj" parameterType="com.template.model.tongji.Tj" resultMap="Elct">
- select ifnull(sum(meter_power),0) as num from `smart_meter_detail` where meter_type=1 and deleted=0
- </select>
- <!--每个月各水表数据统计-->
- <select id="getWaterTjByMonAndBuild" parameterType="String" resultMap="Energy">
- select e.name,d.name as meter_name,d.num from (
- select c.name,b.build_id,a.num from (
- select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
- where deleted=0 and meter_type=0 and update_time like concat(#{month}, '%')
- group by meter_id ) a left join `smart_build_meter` b
- on a.meter_id=b.meter_id
- left join `smart_meter` c on a.meter_id=c.id
- where b.meter_type=0 and c.meter_type=0 and b.`deleted`=0 and c.`deleted`=0 ) d
- left join `smart_build` e on d.build_id=e.id
- where e.deleted=0
- </select>
- <!--每个月各电表数据统计-->
- <select id="getElcTjByMonAndBuild" parameterType="String" resultMap="Energy">
- select e.name,d.name as meter_name,d.num from (
- select c.name,b.build_id,a.num from (
- select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
- where deleted=0 and meter_type=1 and update_time like concat(#{month}, '%')
- group by meter_id ) a left join `smart_build_meter` b
- on a.meter_id=b.meter_id
- left join `smart_meter` c on a.meter_id=c.id
- where b.meter_type=1 and c.meter_type=1 and b.`deleted`=0 and c.`deleted`=0 ) d
- left join `smart_build` e on d.build_id=e.id
- where e.deleted=0
- </select>
- <!--每个月每个楼栋查询-->
- <select id="getTjByMon" parameterType="String" resultMap="MonthT">
- select * from `month_meter_detail` where `name`=#{name} and `meter_name`=#{meterName} and `date`=#{month} and `type`=#{type}
- </select>
- <insert id="insertMonthMeter" parameterType="com.template.model.tongji.EnergyTj" useGeneratedKeys="true">
- INSERT INTO `month_meter_detail`
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="name != null">`name`,</if>
- <if test="meterName != null">`meter_name`,</if>
- <if test="type != null">`type`,</if>
- <if test="date != null">`date`,</if>
- <if test="num != null">`num`,</if>
- </trim>
- <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
- <if test="name != null">#{name},</if>
- <if test="meterName != null">#{meterName},</if>
- <if test="type != null">#{type},</if>
- <if test="date != null">#{date},</if>
- <if test="num != null">#{num},</if>
- </trim>
- </insert>
- <update id="updateMonthMeter">
- UPDATE `month_meter_detail`
- <trim prefix="SET" suffixOverrides=",">
- num=#{energyTj.num}
- </trim>
- <where>
- and id=#{energyTj.id}
- </where>
- </update>
- <!--每天各水表数据统计-->
- <select id="getWaterTjByDayAndBuild" parameterType="String" resultMap="Energy">
- select e.name,d.name as meter_name,d.num from (
- select c.name,b.build_id,a.num from (
- select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
- where deleted=0 and meter_type=0 and update_time like concat(#{day}, '%')
- group by meter_id ) a left join `smart_build_meter` b
- on a.meter_id=b.meter_id
- left join `smart_meter` c on a.meter_id=c.id
- where b.meter_type=0 and c.meter_type=0 and b.`deleted`=0 and c.`deleted`=0 ) d
- left join `smart_build` e on d.build_id=e.id
- where e.deleted=0
- </select>
- <!--每天各电表数据统计-->
- <select id="getElcTjByDayAndBuild" parameterType="String" resultMap="Energy">
- select e.name,d.name as meter_name,d.num from (
- select c.name,b.build_id,a.num from (
- select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
- where deleted=0 and meter_type=1 and update_time like concat(#{day}, '%')
- group by meter_id ) a left join `smart_build_meter` b
- on a.meter_id=b.meter_id
- left join `smart_meter` c on a.meter_id=c.id
- where b.meter_type=1 and c.meter_type=1 and b.`deleted`=0 and c.`deleted`=0 ) d
- left join `smart_build` e on d.build_id=e.id
- where e.deleted=0
- </select>
- <select id="getTjByDay" parameterType="String" resultMap="DayT">
- select * from `day_meter_detail` where `name`=#{name} and `meter_name`=#{meterName} and `date`=#{day} and `type`=#{type}
- </select>
- <insert id="insertDayMeter" parameterType="com.template.model.tongji.EnergyTj" useGeneratedKeys="true">
- INSERT INTO `day_meter_detail`
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="name != null">`name`,</if>
- <if test="meterName != null">`meter_name`,</if>
- <if test="type != null">`type`,</if>
- <if test="date != null">`date`,</if>
- <if test="num != null">`num`,</if>
- </trim>
- <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
- <if test="name != null">#{name},</if>
- <if test="meterName != null">#{meterName},</if>
- <if test="type != null">#{type},</if>
- <if test="date != null">#{date},</if>
- <if test="num != null">#{num},</if>
- </trim>
- </insert>
- <update id="updateDayMeter">
- UPDATE `day_meter_detail`
- <trim prefix="SET" suffixOverrides=",">
- num=#{energyTj.num}
- </trim>
- <where>
- and id=#{energyTj.id}
- </where>
- </update>
- <!--每个月水费数据-->
- <select id="getMonWater" parameterType="String" resultMap="Tj">
- select * from `month_meter_detail` where type=0 and `date`=#{month}
- </select>
- <!--每个月水费数据-->
- <select id="getMonWaters" parameterType="String" resultMap="Tj">
- select * from `month_meter_detail` where type=0 and `date` >= #{startMonth} and `date` <= #{endMonth}
- </select>
- <!--每个月电费数据-->
- <select id="getMonElcs" parameterType="String" resultMap="Tj">
- select * from `month_meter_detail` where type=1 and `date` >= #{startMonth} and `date` <= #{endMonth}
- </select>
- <!--每个月电费数据-->
- <select id="getMonElc" parameterType="String" resultMap="Tj">
- select * from `month_meter_detail` where type=1 and `date`=#{month}
- </select>
- <!--区域能耗统计-->
- <select id="getMeterMonthPage" resultMap="meterMonthData">
- <!-- select * from (select a.id,a.`name`,a.`date`,a.`num` w_num,b.num as e_num-->
- <!-- from `month_meter_detail` a,`month_meter_detail` b-->
- <!-- where a.`type`=0 and b.`type`=1 and a.name=b.`name`-->
- <!-- and a.`date`=b.`date` ) a-->
- <!-- <where>-->
- <!-- <if test="meterMonthData.date != null and meterMonthData.date != ''"> a.date like concat(#{meterMonthData.date}, '%')</if>-->
- <!-- </where>-->
- <!-- order by a.date desc-->
- select 0 as id, (select d.num from (select sum(num) as num,name,type,date from month_meter_detail
- <where>
- <if test="meterMonthData.date != null and meterMonthData.date != ''">date like
- concat(#{meterMonthData.date}, '%')
- </if>
- </where>
- group by date,name,type) d where d.name = b.name and d.date = b.date and d.type = 0) as w_num ,(select d.num
- from (select sum(num) as num,name,type,date from month_meter_detail
- <where>
- <if test="meterMonthData.date != null and meterMonthData.date != ''">date like
- concat(#{meterMonthData.date}, '%')
- </if>
- </where>
- group by date,name,type) d where d.name = b.name and d.date = b.date and d.type = 1) as e_num,b.name,b.date from
- (select a.name,a.date from (select sum(num) as num,name,type,date from month_meter_detail
- <where>
- <if test="meterMonthData.date != null and meterMonthData.date != ''">date like
- concat(#{meterMonthData.date}, '%')
- </if>
- </where>
- group by date,name,type) a
- group by a.name,a.date) b
- order by b.date desc
- </select>
- <select id="getMeterMonthPageDatas" resultType="com.template.model.pojo.MonthMeterDetail">
- select * from month_meter_detail
- <where>
- <if test="meterMonthData.date != null and meterMonthData.date != ''">a.date like
- concat(#{meterMonthData.date}, '%')
- </if>
- </where>
- order by date desc
- </select>
- <!--实时抄表-->
- <select id="getMeterDayPage" resultMap="meterMonthDataVo">
- select smd.id,sm.build_address,sm.address,smd.meter_power,smd.meter_power_record,sm.meter_no,smd.create_time from smart_meter_detail
- smd
- left join smart_meter sm on sm.deleted = 0 and sm.id = smd.meter_id
- where smd.deleted = 0
- <if test="meterMonthData.date != null and meterMonthData.date != ''">AND smd.create_time like
- concat(#{meterMonthData.date}, '%')
- </if>
- <if test="meterMonthData.type != null and meterMonthData.type != -1">AND smd.meter_type =
- #{meterMonthData.type}
- </if>
- order by smd.create_time desc
- </select>
- </mapper>
|