You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
537 lines
27 KiB
537 lines
27 KiB
package com.mh.user.mapper; |
|
|
|
import com.mh.user.entity.EnergyEntity; |
|
import com.mh.user.mapper.provider.EnergyProvider; |
|
import com.mh.user.model.SumModel; |
|
import org.apache.ibatis.annotations.*; |
|
import org.apache.ibatis.mapping.StatementType; |
|
|
|
import java.util.List; |
|
|
|
public interface EnergyMapper { |
|
/** |
|
* 生产信息 |
|
* 保存 |
|
* @param energyEntity |
|
*/ |
|
//按天 |
|
@Insert("insert into energy_day(cur_date,building_id,building_name,hot_water_value,use_hot_water,elect_value,elect_water,check_in_count,per_elect,per_water) values (" + |
|
" #{curDate},#{buildingId},#{buildingName},#{hotWaterValue},#{useHotWater},#{electValue},#{electWater},#{checkInCount},#{perElect},#{perWater})") |
|
void saveEnergyDay(EnergyEntity energyEntity); |
|
//按月 |
|
@Insert("insert into energy_month(cur_date,building_id,building_name,hot_water_value,use_hot_water,elect_value,elect_water,check_in_count,per_elect,per_water) values (" + |
|
" #{curTime},#{buildingId},#{buildingName},#{hotWaterValue},#{useHotWater},#{electValue},#{electWater},#{checkInCount},#{perElect},#{perWater})") |
|
void saveEnergyMonth(EnergyEntity energyEntity); |
|
//按年 |
|
@Insert("insert into energy_month(cur_date,building_id,building_name,hot_water_value,use_hot_water,elect_value,elect_water,check_in_count,per_elect,per_water) values (" + |
|
" #{curDate},#{buildingId},#{buildingName},#{hotWaterValue},#{useHotWater},#{electValue},#{electWater},#{checkInCount},#{perElect},#{perWater})") |
|
void saveEnergyYear(EnergyEntity energyEntity); |
|
/** |
|
* 生产信息 |
|
* 修改 |
|
* @param energyEntity |
|
*/ |
|
//按天 |
|
@Update("<script>" + |
|
" update energy_day set " + |
|
" <if test='buildingName!=null'> , building_name = #{buildingName} </if>" + |
|
" <if test='hotWaterValue!=null'> , hot_water_value = #{hotWaterValue} </if>" + |
|
" <if test='useHotWater!=null'> , use_hot_water = #{useHotWater} </if>" + |
|
" <if test='electValue!=null'> , elect_value = #{electValue} </if>" + |
|
" <if test='electWater!=null'> , elect_water = #{electWater} </if>" + |
|
" <if test='checkInCount!=null'> , check_in_count = #{checkInCount} </if>" + |
|
" <if test='perElect!=null'> , per_elect = #{perElect} </if>" + |
|
" <if test='perWater!=null'> , per_water = #{perWater} </if>" + |
|
" where cur_date = #{curDate} and building_id=#{buildingId} " + |
|
"</script>") |
|
void updateEnergyDay(EnergyEntity energyEntity); |
|
//按月 |
|
@Update("<script>" + |
|
" update energy_month set " + |
|
" <if test='buildingName!=null'> , building_name = #{buildingName} </if>" + |
|
" <if test='hotWaterValue!=null'> , hot_water_value = #{hotWaterValue} </if>" + |
|
" <if test='useHotWater!=null'> , use_hot_water = #{useHotWater} </if>" + |
|
" <if test='electValue!=null'> , elect_value = #{electValue} </if>" + |
|
" <if test='electWater!=null'> , elect_water = #{electWater} </if>" + |
|
" <if test='checkInCount!=null'> , check_in_count = #{checkInCount} </if>" + |
|
" <if test='perElect!=null'> , per_elect = #{perElect} </if>" + |
|
" <if test='perWater!=null'> , per_water = #{perWater} </if>" + |
|
" where cur_date = #{curDate} and building_id=#{buildingId} " + |
|
"</script>") |
|
void updateEnergyMonth(EnergyEntity energyEntity); |
|
//按年 |
|
@Update("<script>" + |
|
" update energy_year set " + |
|
" <if test='buildingName!=null'> , building_name = #{buildingName} </if>" + |
|
" <if test='hotWaterValue!=null'> , hot_water_value = #{hotWaterValue} </if>" + |
|
" <if test='useHotWater!=null'> , use_hot_water = #{useHotWater} </if>" + |
|
" <if test='electValue!=null'> , elect_value = #{electValue} </if>" + |
|
" <if test='electWater!=null'> , elect_water = #{electWater} </if>" + |
|
" <if test='checkInCount!=null'> , check_in_count = #{checkInCount} </if>" + |
|
" <if test='perElect!=null'> , per_elect = #{perElect} </if>" + |
|
" <if test='perWater!=null'> , per_water = #{perWater} </if>" + |
|
" where cur_date = #{curDate} and building_id=#{buildingId} " + |
|
"</script>") |
|
void updateEnergyYear(EnergyEntity energyEntity); |
|
|
|
/** |
|
* 生产信息 |
|
* 根据时间日期和楼栋编号删除记录 |
|
* @param curDate |
|
* @param buildingId |
|
*/ |
|
//按天 |
|
@Delete("delete from energy_day where cur_date=#{curDate} and building_id=#{buildingId} ") |
|
void deleteEnergyDay(@Param("curDate") String curDate,@Param("buildingId") String buildingId); |
|
//按月 |
|
@Delete("delete from energy_month where cur_date=#{curDate} and building_id=#{buildingId} ") |
|
void deleteEnergyMonth(@Param("curDate") String curDate,@Param("buildingId") String buildingId); |
|
//按年 |
|
@Delete("delete from energy_year where cur_date=#{curDate} and building_id=#{buildingId} ") |
|
void deleteEnergyYear(@Param("curDate") String curDate,@Param("buildingId") String buildingId); |
|
/** |
|
* 生产信息 |
|
* 查询 |
|
* @param buildingId |
|
* @param startDate |
|
* @param endDate |
|
* @param page |
|
* @param limit |
|
* @return |
|
*/ |
|
//按天 |
|
@SelectProvider(type = EnergyProvider.class,method = "queryEnergyDay") |
|
@Results(id="rs",value = { |
|
@Result(property="curDate",column="cur_date"), |
|
@Result(property="buildingId",column="building_id"), |
|
@Result(property="buildingName",column="building_name"), |
|
@Result(property="hotWaterValue",column="hot_water_value"), |
|
@Result(property ="useHotWater",column ="use_hot_water"), |
|
@Result(property ="electValue",column ="elect_value"), |
|
@Result(property="electWater",column="elect_water"), |
|
@Result(property="checkInCount",column="check_in_count"), |
|
@Result(property="perElect",column="per_elect"), |
|
@Result(property="perWater",column="per_water"), |
|
@Result(property="electCurValue",column="elect_curValue"), |
|
@Result(property="wtCurValue",column="wt_curValue") |
|
}) |
|
List<EnergyEntity> queryEnergyDay(@Param("buildingId") String buildingId, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, @Param("limit") int limit); |
|
//按月 |
|
@SelectProvider(type = EnergyProvider.class,method = "queryEnergyMonth") |
|
@ResultMap("rs") |
|
List<EnergyEntity> queryEnergyMonth(@Param("buildingId") String buildingId, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, @Param("limit") int limit); |
|
//按年 |
|
@SelectProvider(type = EnergyProvider.class,method = "queryEnergyYear") |
|
@ResultMap("rs") |
|
List<EnergyEntity> queryEnergyYear(@Param("buildingId") String buildingId, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, @Param("limit") int limit); |
|
/** |
|
* 生产信息 |
|
* 查询记录数 |
|
* @return |
|
*/ |
|
//按天 |
|
@SelectProvider(type = EnergyProvider.class,method = "getEnergyDayCount") |
|
int getEnergyDayCount(@Param("buildingId") String buildingId, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, @Param("limit") int limit); |
|
//按月 |
|
@SelectProvider(type = EnergyProvider.class,method = "getEnergyMonthCount") |
|
int getEnergyMonthCount(@Param("buildingId") String buildingId, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, @Param("limit") int limit); |
|
//按年 |
|
@SelectProvider(type = EnergyProvider.class,method = "getEnergyYearCount") |
|
int getEnergyYearCount(@Param("buildingId") String buildingId, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, @Param("limit") int limit); |
|
|
|
//按天 |
|
@Results(value = { |
|
@Result(property="curDate",column="cur_date"), |
|
@Result(property ="useHotWater",column ="use_hot_water"), |
|
@Result(property ="electValue",column ="elect_value"), |
|
@Result(property="electWater",column="elect_water"), |
|
@Result(property="perElect",column="per_elect"), |
|
@Result(property="perWater",column="per_water") |
|
}) |
|
@Select("SELECT cur_date,sum(use_hot_water) as use_hot_water,sum(elect_value) as elect_value,sum(elect_water) as elect_water FROM energy_day where Left(cur_date,10)=#{curDate} GROUP BY(cur_date)") |
|
List<EnergyEntity> queryEnergyDayGroup(@Param("curDate") String curDate); |
|
|
|
//按月 |
|
@Select("SELECT cur_date,sum(use_hot_water) as use_hot_water,sum(elect_value) as elect_value,sum(elect_water) as elect_water FROM energy_month where Left(cur_date,7)=#{curDate} GROUP BY(cur_date)") |
|
List<EnergyEntity> queryEnergyMonthGroup(@Param("curDate") String curDate); |
|
|
|
//按年 |
|
@Select("SELECT cur_date,sum(use_hot_water) as use_hot_water,sum(elect_value) as elect_value,sum(elect_water) as elect_water FROM energy_year where Left(cur_date,4)=#{curDate} GROUP BY(cur_date)") |
|
List<EnergyEntity> queryEnergyYearGroup(@Param("curDate") String curDate); |
|
|
|
//查询每天的用量 |
|
@SelectProvider(type = EnergyProvider.class,method = "queryDayEnergy") |
|
@ResultMap("rs") |
|
List<EnergyEntity> queryDayEnergy(@Param("buildingId") String buildingId, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, |
|
@Param("limit") int limit); |
|
|
|
@SelectProvider(type = EnergyProvider.class,method = "getDayEnergyCount") |
|
int getDayEnergyCount(@Param("buildingId") String buildingId, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, |
|
@Param("limit") int limit); |
|
/** |
|
* 生产信息 |
|
* 查询 |
|
* @param buildingId |
|
* @param curDate |
|
* @param page |
|
* @param limit |
|
* @return |
|
*/ |
|
//查询每小时的用量和能耗 |
|
@SelectProvider(type = EnergyProvider.class,method = "queryHourEnergy") |
|
@ResultMap("rs") |
|
List<EnergyEntity> queryHourEnergy(@Param("buildingId") String buildingId, |
|
@Param("curDate") String curDate, |
|
@Param("page") int page, @Param("limit") int limit); |
|
|
|
@SelectProvider(type = EnergyProvider.class,method = "getHourEnergyCount") |
|
int getHourEnergyCount(@Param("buildingId") String buildingId, |
|
@Param("curDate") String curDate); |
|
|
|
@ResultMap("rs") |
|
@SelectProvider(type = EnergyProvider.class,method = "queryEnergyBuilding") |
|
List<EnergyEntity> queryEnergyBuilding(@Param("page") int page, |
|
@Param("limit") int limit); |
|
|
|
@Select("select count(*) from energy_building ") |
|
int getEnergyBuildingCount(); |
|
|
|
//按日、月和年查询水、电用量,计算单耗、平均用量 |
|
@Select("exec pro_energy_building #{curDate,jdbcType=VARCHAR,mode=IN},#{endDate,jdbcType=VARCHAR,mode=IN},#{type,jdbcType=VARCHAR,mode=IN} ") |
|
@Options(statementType = StatementType.CALLABLE) |
|
void proEnergyBuilding(@Param("curDate") String curDate,@Param("endDate") String endDate,@Param("type") int type); |
|
|
|
//查询合计 |
|
@Select("select sum(use_hot_water) as sumWater,sum(elect_value) as sumElect from energy_building") |
|
SumModel queryEnergySum(); |
|
|
|
|
|
@Select({ |
|
"<script>", |
|
"SELECT count(1) FROM (", |
|
" SELECT " + |
|
" cur_date, " + |
|
" sum(use_hot_water) as use_hot_water, " + |
|
" sum(elect_value) as elect_value, " + |
|
" CASE WHEN sum(use_hot_water) = 0 THEN 0 ELSE sum(elect_value)/ sum(use_hot_water) END as elect_water, " + |
|
" sum(check_in_count) as check_in_count, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(use_hot_water) / sum(check_in_count) END as per_water, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(elect_value)/ sum(check_in_count) END as per_elect , " + |
|
" ROW_NUMBER() OVER(ORDER BY cur_date DESC) AS rn " + |
|
" FROM energy_day", |
|
" WHERE 1=1", |
|
" <if test='buildingIds != null and !buildingIds.isEmpty()'>", |
|
" AND building_id IN", |
|
" <foreach collection='buildingIds' item='id' open='(' separator=',' close=')'>", |
|
" #{id}", |
|
" </foreach>", |
|
" </if>", |
|
" <if test='startDate != null and startDate != \"\"'>", |
|
" AND LEFT(cur_date,10) >= #{startDate}", |
|
" </if>", |
|
" <if test='endDate != null and endDate != \"\"'>", |
|
" AND LEFT(cur_date,10) <= #{endDate}", |
|
" </if>", |
|
" group by cur_date ) T", |
|
"</script>" |
|
}) |
|
int getAreaEnergyDayCount(@Param("buildingIds") List<String> buildingIds, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, |
|
@Param("limit") int limit); |
|
|
|
@Select({ |
|
"<script>", |
|
"SELECT T.cur_date, " + |
|
" T.use_hot_water , " + |
|
" T.elect_value, " + |
|
" T.elect_water, " + |
|
" t.check_in_count , " + |
|
" t.per_water , " + |
|
" t.per_elect , " + |
|
" t.rn, " + |
|
" #{areaName} as building_name FROM (", |
|
" SELECT " + |
|
" cur_date, " + |
|
" sum(use_hot_water) as use_hot_water, " + |
|
" sum(elect_value) as elect_value, " + |
|
" CASE WHEN sum(use_hot_water) = 0 THEN 0 ELSE sum(elect_value)/ sum(use_hot_water) END as elect_water, " + |
|
" sum(check_in_count) as check_in_count, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(use_hot_water) / sum(check_in_count) END as per_water, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(elect_value)/ sum(check_in_count) END as per_elect , " + |
|
" ROW_NUMBER() OVER(ORDER BY cur_date DESC) AS rn " + |
|
" FROM energy_day", |
|
" WHERE 1=1", |
|
" <if test='buildingIds != null and !buildingIds.isEmpty()'>", |
|
" AND building_id IN", |
|
" <foreach collection='buildingIds' item='id' open='(' separator=',' close=')'>", |
|
" #{id}", |
|
" </foreach>", |
|
" </if>", |
|
" <if test='startDate != null and startDate != \"\"'>", |
|
" AND LEFT(cur_date,10) >= #{startDate}", |
|
" </if>", |
|
" <if test='endDate != null and endDate != \"\"'>", |
|
" AND LEFT(cur_date,10) <= #{endDate}", |
|
" </if>", |
|
" group by cur_date ) T", |
|
"<where>", |
|
" <if test='page != 0 and limit != 0'>", |
|
" T.rn > (#{page}-1)*#{limit} AND T.rn <= #{page}*#{limit}", |
|
" </if>", |
|
"</where>", |
|
"ORDER BY T.cur_date DESC", |
|
"</script>" |
|
}) |
|
@ResultMap("rs") |
|
List<EnergyEntity> getAreaEnergyDay(@Param("buildingIds") List<String> buildingIds, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, |
|
@Param("limit") int limit, |
|
@Param("areaName") String areaName); |
|
|
|
@Select({ |
|
"<script>", |
|
"SELECT count(1) FROM (", |
|
" SELECT " + |
|
" cur_date, " + |
|
" sum(use_hot_water) as use_hot_water, " + |
|
" sum(elect_value) as elect_value, " + |
|
" CASE WHEN sum(use_hot_water) = 0 THEN 0 ELSE sum(elect_value)/ sum(use_hot_water) END as elect_water, " + |
|
" sum(check_in_count) as check_in_count, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(use_hot_water) / sum(check_in_count) END as per_water, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(elect_value)/ sum(check_in_count) END as per_elect , " + |
|
" ROW_NUMBER() OVER(ORDER BY cur_date DESC) AS rn " + |
|
" FROM energy_month", |
|
" WHERE 1=1", |
|
" <if test='buildingIds != null and !buildingIds.isEmpty()'>", |
|
" AND building_id IN", |
|
" <foreach collection='buildingIds' item='id' open='(' separator=',' close=')'>", |
|
" #{id}", |
|
" </foreach>", |
|
" </if>", |
|
" <if test='startDate != null and startDate != \"\"'>", |
|
" AND LEFT(cur_date,7) >= #{startDate}", |
|
" </if>", |
|
" <if test='endDate != null and endDate != \"\"'>", |
|
" AND LEFT(cur_date,7) <= #{endDate}", |
|
" </if>", |
|
" group by cur_date ) T", |
|
"</script>" |
|
}) |
|
int getAreaEnergyMonthCount(@Param("buildingIds") List<String> buildingIds, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, |
|
@Param("limit") int limit); |
|
|
|
@Select({ |
|
"<script>", |
|
"SELECT T.cur_date, " + |
|
" T.use_hot_water , " + |
|
" T.elect_value, " + |
|
" T.elect_water, " + |
|
" t.check_in_count , " + |
|
" t.per_water , " + |
|
" t.per_elect , " + |
|
" t.rn, " + |
|
" #{areaName} as building_name FROM (", |
|
" SELECT " + |
|
" cur_date, " + |
|
" sum(use_hot_water) as use_hot_water, " + |
|
" sum(elect_value) as elect_value, " + |
|
" CASE WHEN sum(use_hot_water) = 0 THEN 0 ELSE sum(elect_value)/ sum(use_hot_water) END as elect_water, " + |
|
" sum(check_in_count) as check_in_count, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(use_hot_water) / sum(check_in_count) END as per_water, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(elect_value)/ sum(check_in_count) END as per_elect , " + |
|
" ROW_NUMBER() OVER(ORDER BY cur_date DESC) AS rn " + |
|
" FROM energy_month ", |
|
" WHERE 1=1", |
|
" <if test='buildingIds != null and !buildingIds.isEmpty()'>", |
|
" AND building_id IN", |
|
" <foreach collection='buildingIds' item='id' open='(' separator=',' close=')'>", |
|
" #{id}", |
|
" </foreach>", |
|
" </if>", |
|
" <if test='startDate != null and startDate != \"\"'>", |
|
" AND LEFT(cur_date,7) >= #{startDate}", |
|
" </if>", |
|
" <if test='endDate != null and endDate != \"\"'>", |
|
" AND LEFT(cur_date,7) <= #{endDate}", |
|
" </if>", |
|
" group by cur_date ) T", |
|
"<where>", |
|
" <if test='page != 0 and limit != 0'>", |
|
" T.rn > (#{page}-1)*#{limit} AND T.rn <= #{page}*#{limit}", |
|
" </if>", |
|
"</where>", |
|
"ORDER BY T.cur_date DESC", |
|
"</script>" |
|
}) |
|
@ResultMap("rs") |
|
List<EnergyEntity> getAreaEnergyMonth(@Param("buildingIds") List<String> buildingIds, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, |
|
@Param("limit") int limit, |
|
@Param("areaName") String areaName); |
|
|
|
@Select({ |
|
"<script>", |
|
"SELECT count(1) FROM (", |
|
" SELECT " + |
|
" cur_date, " + |
|
" sum(use_hot_water) as use_hot_water, " + |
|
" sum(elect_value) as elect_value, " + |
|
" CASE WHEN sum(use_hot_water) = 0 THEN 0 ELSE sum(elect_value)/ sum(use_hot_water) END as elect_water, " + |
|
" sum(check_in_count) as check_in_count, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(use_hot_water) / sum(check_in_count) END as per_water, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(elect_value)/ sum(check_in_count) END as per_elect , " + |
|
" ROW_NUMBER() OVER(ORDER BY cur_date DESC) AS rn " + |
|
" FROM energy_year", |
|
" WHERE 1=1", |
|
" <if test='buildingIds != null and !buildingIds.isEmpty()'>", |
|
" AND building_id IN", |
|
" <foreach collection='buildingIds' item='id' open='(' separator=',' close=')'>", |
|
" #{id}", |
|
" </foreach>", |
|
" </if>", |
|
" <if test='startDate != null and startDate != \"\"'>", |
|
" AND LEFT(cur_date,4) >= #{startDate}", |
|
" </if>", |
|
" <if test='endDate != null and endDate != \"\"'>", |
|
" AND LEFT(cur_date,4) <= #{endDate}", |
|
" </if>", |
|
" group by cur_date ) T", |
|
"</script>" |
|
}) |
|
int getAreaEnergyYearCount(@Param("buildingIds") List<String> buildingIds, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, |
|
@Param("limit") int limit); |
|
|
|
@Select({ |
|
"<script>", |
|
"SELECT T.cur_date, " + |
|
" T.use_hot_water , " + |
|
" T.elect_value, " + |
|
" T.elect_water, " + |
|
" t.check_in_count , " + |
|
" t.per_water , " + |
|
" t.per_elect , " + |
|
" t.rn, " + |
|
" #{areaName} as building_name FROM (", |
|
" SELECT " + |
|
" cur_date, " + |
|
" sum(use_hot_water) as use_hot_water, " + |
|
" sum(elect_value) as elect_value, " + |
|
" CASE WHEN sum(use_hot_water) = 0 THEN 0 ELSE sum(elect_value)/ sum(use_hot_water) END as elect_water, " + |
|
" sum(check_in_count) as check_in_count, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(use_hot_water) / sum(check_in_count) END as per_water, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(elect_value)/ sum(check_in_count) END as per_elect , " + |
|
" ROW_NUMBER() OVER(ORDER BY cur_date DESC) AS rn " + |
|
" FROM energy_year ", |
|
" WHERE 1=1", |
|
" <if test='buildingIds != null and !buildingIds.isEmpty()'>", |
|
" AND building_id IN", |
|
" <foreach collection='buildingIds' item='id' open='(' separator=',' close=')'>", |
|
" #{id}", |
|
" </foreach>", |
|
" </if>", |
|
" <if test='startDate != null and startDate != \"\"'>", |
|
" AND LEFT(cur_date,4) >= #{startDate}", |
|
" </if>", |
|
" <if test='endDate != null and endDate != \"\"'>", |
|
" AND LEFT(cur_date,4) <= #{endDate}", |
|
" </if>", |
|
" group by cur_date ) T", |
|
"<where>", |
|
" <if test='page != 0 and limit != 0'>", |
|
" T.rn > (#{page}-1)*#{limit} AND T.rn <= #{page}*#{limit}", |
|
" </if>", |
|
"</where>", |
|
"ORDER BY T.cur_date DESC", |
|
"</script>" |
|
}) |
|
@ResultMap("rs") |
|
List<EnergyEntity> getAreaEnergyYear(@Param("buildingIds") List<String> buildingIds, |
|
@Param("startDate") String startDate, |
|
@Param("endDate") String endDate, |
|
@Param("page") int page, |
|
@Param("limit") int limit, |
|
@Param("areaName") String areaName); |
|
|
|
@Select({ |
|
"<script>", |
|
"SELECT T.cur_date, " + |
|
" T.use_hot_water , " + |
|
" T.elect_value, " + |
|
" T.elect_water, " + |
|
" t.check_in_count , " + |
|
" t.per_water , " + |
|
" t.per_elect , " + |
|
" t.rn, " + |
|
" #{areaName} as building_name FROM (", |
|
" SELECT " + |
|
" cur_date, " + |
|
" sum(use_hot_water) as use_hot_water, " + |
|
" sum(elect_value) as elect_value, " + |
|
" CASE WHEN sum(use_hot_water) = 0 THEN 0 ELSE sum(elect_value)/ sum(use_hot_water) END as elect_water, " + |
|
" sum(check_in_count) as check_in_count, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(use_hot_water) / sum(check_in_count) END as per_water, " + |
|
" CASE WHEN sum(check_in_count) = 0 THEN 0 ELSE sum(elect_value)/ sum(check_in_count) END as per_elect , " + |
|
" ROW_NUMBER() OVER(ORDER BY cur_date DESC) AS rn " + |
|
" FROM energy_hour ", |
|
" WHERE 1=1", |
|
" <if test='buildingIds != null and !buildingIds.isEmpty()'>", |
|
" AND building_id IN", |
|
" <foreach collection='buildingIds' item='id' open='(' separator=',' close=')'>", |
|
" #{id}", |
|
" </foreach>", |
|
" </if>", |
|
" <if test='curDate != null and curDate != \"\"'>", |
|
" AND LEFT(cur_date,10) = #{curDate}", |
|
" </if>", |
|
" group by cur_date ) T", |
|
"<where>", |
|
" <if test='page != 0 and limit != 0'>", |
|
" T.rn > (#{page}-1)*#{limit} AND T.rn <= #{page}*#{limit}", |
|
" </if>", |
|
"</where>", |
|
"ORDER BY T.cur_date DESC", |
|
"</script>" |
|
}) |
|
@ResultMap("rs") |
|
List<EnergyEntity> getAreaEnergyHour(@Param("buildingIds") List<String> buildingIds, |
|
@Param("curDate") String curDate, |
|
@Param("page") int page, |
|
@Param("limit") int limit, |
|
@Param("areaName") String areaName); |
|
}
|
|
|