Commit bbae4123 authored by jichao's avatar jichao

用能比较模块接口,用能概览--更改查询价格的接口

parent 0d8778fe
package org.rcisoft.business.overview.dao;
import org.rcisoft.business.overview.entity.BusProjectArea;
import org.rcisoft.business.overview.vo.BusProjectAreaVo;
import org.rcisoft.core.base.BaseMapper;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
......@@ -23,5 +24,9 @@ public interface BusProjectAreaRepository extends BaseMapper<BusProjectArea> {
@Select("<script>select * from bus_project_area b where b.PRO_ID=#{proId}</script>")
@ResultMap(value = "BaseResultMap")
List<BusProjectArea> queryBusProjectAreas(BusProjectArea busProjectArea);
@Select("<script>select SUM(IF(b.TYPE=1, b.AREA, 0)) as WATER_AREA,SUM(IF(b.TYPE=2, b.AREA, 0)) as ELEC_AREA,SUM(IF(b.TYPE=3, b.AREA, 0)) as GAS_AREA from bus_project_area b where b.PRO_ID=#{proId}</script>")
@ResultMap(value = "vo")
BusProjectAreaVo classifyProjectArea(String proId);
}
package org.rcisoft.business.overview.dao;
import org.rcisoft.business.overview.entity.BusProject;
import org.rcisoft.core.base.BaseMapper;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Created with on 2018-4-14 10:15:52.
*/
@Repository
public interface BusProjectRepository extends BaseMapper<BusProject> {
/**
* 查询项目信息
* @return
*/
@Select("<script>select * from bus_project</script>")
@ResultMap(value = "BaseResultMap" )
List<BusProject> queryBusProjects();
}
......@@ -90,4 +90,14 @@ public interface EnergyCountMRepository extends BaseMapper<EnergyCountM> {
@ResultMap("resultMapVo")
List<EnergyCountMVo> getEnergyCompare(EnergyCountMVo energyCountMVo);
/**
* 按月统计水电气能耗
* @param energyCountM proId:项目主键,year:年份
* @return
*/
@Select("<script>select e.MON,sum(e.WATER) as WATER,sum(e.ELEC) as ELEC,sum(e.GAS) as GAS from energy_count_m e" +
" where e.PRO_ID=#{proId} and e.`YEAR`=#{year} group by e.MON</script>")
@ResultMap("BaseResultMap")
List<EnergyCountM> getEnergyMonth(EnergyCountM energyCountM);
}
......@@ -3,6 +3,7 @@ package org.rcisoft.business.overview.dao;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.overview.entity.EnergyPrice;
import org.rcisoft.business.overview.vo.EnergyPriceVo;
import org.rcisoft.core.base.BaseMapper;
import org.springframework.stereotype.Repository;
......@@ -17,11 +18,11 @@ public interface EnergyPriceRepository extends BaseMapper<EnergyPrice> {
/**
* 根据项目id搜索水电气价格列表
* @param proId 项目id
* @param energyPrice proId:项目id,pHour:小时
* @return
*/
@Select("<script>select * from ENERGY_PRICE e where e.PRO_ID = #{proId}</script>")
@ResultMap("BaseResultMap")
List<EnergyPrice> getPrice(String proId);
@Select("<script>select e.P_HOUR,SUM(IF(e.P_TP=1, e.P_PRICE, 0)) as WATER,SUM(IF(e.P_TP=2, e.P_PRICE, 0)) as ELEC,SUM(IF(e.P_TP=3, e.P_PRICE, 0)) as GAS from energy_price e where e.PRO_ID=#{proId} and e.P_HOUR=#{pHour}</script>")
@ResultMap("vo")
EnergyPriceVo getPrice(EnergyPrice energyPrice);
}
package org.rcisoft.business.overview.entity;
import lombok.*;
import org.rcisoft.core.entity.IdNotDataEntity;
import javax.persistence.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* Created with on 2018-4-14 10:15:52.
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "bus_project")
public class BusProject implements Serializable {
@Id
private String proId;
private String proNm;
private String bldTpId;
private Float bldArea;
private String bldLocal;
private String bldCoordinate;
private String ownId;
private String teamId;
}
......@@ -27,6 +27,14 @@ public class BusProjectAreaStat implements Serializable {
this.gas = gas;
}
public BusProjectAreaStat(String proId, String year, Float water, Float elec, Float gas) {
this.proId = proId;
this.year = year;
this.water = water;
this.elec = elec;
this.gas = gas;
}
@Id
private Integer id;
......
......@@ -27,56 +27,13 @@ public class EnergyPrice implements Serializable {
private String proId;
private Float p0;
private String pHour;
private Float p1;
private Float p2;
private Float p3;
private Float p4;
private Float p5;
private Float p6;
private Float p7;
private Float p8;
private Float p9;
private Float p10;
private Float p11;
private Float p12;
private Float p13;
private Float p14;
private Float p15;
private Float p16;
private Float p17;
private Float p18;
private Float p19;
private Float p20;
private Float p21;
private Float p22;
private Float p23;
private BigDecimal pPrice;
private String pTp;
}
package org.rcisoft.business.overview.service;
import org.rcisoft.business.overview.vo.EnergyCountMVo;
import org.rcisoft.business.overview.vo.EnergyPriceVo;
import org.rcisoft.core.model.PersistModel;
import java.util.List;
import java.util.Map;
......@@ -16,7 +18,7 @@ public interface OverViewService {
* @param proId
* @return
*/
Map<String, Object> getPrice(String proId);
EnergyPriceVo getPrice(String proId);
/**
* 用量和费用统计,当日或当月
......@@ -75,4 +77,10 @@ public interface OverViewService {
*/
Map<String, Object> getEnergyCompare(String proId, String year, String month, Integer type, Integer cType);
/**
* 每月统计能量
* @return
*/
PersistModel statEnergyMonthly();
}
......@@ -2,18 +2,19 @@ package org.rcisoft.business.overview.service.impl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.rcisoft.business.overview.dao.BusProjectAreaRepository;
import org.rcisoft.business.overview.dao.BusProjectAreaStatRepository;
import org.rcisoft.business.overview.dao.EnergyCountMRepository;
import org.rcisoft.business.overview.dao.EnergyPriceRepository;
import org.rcisoft.business.overview.entity.BusProjectArea;
import org.rcisoft.business.overview.entity.BusProjectAreaStat;
import org.rcisoft.business.overview.entity.EnergyCountM;
import org.rcisoft.business.overview.entity.EnergyPrice;
import org.rcisoft.business.overview.dao.*;
import org.rcisoft.business.overview.entity.*;
import org.rcisoft.business.overview.service.OverViewService;
import org.rcisoft.business.overview.vo.BusProjectAreaVo;
import org.rcisoft.business.overview.vo.EnergyCountMVo;
import org.rcisoft.business.overview.vo.EnergyPriceVo;
import org.rcisoft.core.model.PersistModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.util.*;
......@@ -32,6 +33,26 @@ public class OverViewServiceImpl implements OverViewService {
private BusProjectAreaRepository busProjectAreaRepository;
@Autowired
private BusProjectAreaStatRepository busProjectAreaStatRepository;
@Autowired
private BusProjectRepository busProjectRepository;
private String[] time(int year, int month, int day, int hour, int minute, int second) {
Calendar cal = Calendar.getInstance();
if(year != 0) cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + year);
if(month != 0) cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + month);
if(day != 0) cal.set(Calendar.DATE, cal.get(Calendar.DATE) + day);
if(hour != 0) cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) + day);
if(minute != 0) cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + minute);
if(second != 0) cal.set(Calendar.SECOND, cal.get(Calendar.SECOND) + second);
String[] result = new String[6];
result[0] = String.valueOf(cal.get(Calendar.YEAR));
result[1] = String.valueOf(cal.get(Calendar.MONTH));
result[2] = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
result[3] = String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
result[4] = String.valueOf(cal.get(Calendar.MINUTE));
result[5] = String.valueOf(cal.get(Calendar.SECOND));
return result;
}
private Calendar getBeforeDay(Calendar cl, int time){
int day = cl.get(Calendar.DATE);
......@@ -91,17 +112,37 @@ public class OverViewServiceImpl implements OverViewService {
return type;
}
private List<Float> getFloatList(List<EnergyCountMVo> list){
List<Float> resultList = new ArrayList<Float>();
if(list != null && list.size() > 0){
int size = list.size();
Integer start = Integer.parseInt(list.get(0).getDay());
Integer end = Integer.parseInt(list.get(size - 1).getDay());
for (int i = 1; i < start; i++) {
resultList.add(0f);
}
for (int i = 0; i < size; i++) {
resultList.add(list.get(i).getEnergy());
}
for (int i = end; i < 31; i++) {
resultList.add(0f);
}
}else{
for (int i = 0; i < 31; i++) {
resultList.add(0f);
}
}
return resultList;
}
@Override
public Map<String, Object> getPrice(String proId) {
public EnergyPriceVo getPrice(String proId) {
Map<String, Object> map = new HashMap<String, Object>();
List<EnergyPrice> list = overViewRepository.getPrice(proId);
Iterator<EnergyPrice> it = list.iterator();
while (it.hasNext()) {
EnergyPrice energyPrice = it.next();
String type = this.getType(energyPrice.getPTp());
if(StringUtils.isNotEmpty(type)) map.put(type, energyPrice);
}
return map;
int i = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
EnergyPrice e = new EnergyPrice();
e.setProId(proId);
e.setPHour(String.valueOf(i));
return overViewRepository.getPrice(e);
}
@Override
......@@ -265,26 +306,69 @@ public class OverViewServiceImpl implements OverViewService {
return result;
}
private List<Float> getFloatList(List<EnergyCountMVo> list){
List<Float> resultList = new ArrayList<Float>();
if(list != null && list.size() > 0){
int size = list.size();
Integer start = Integer.parseInt(list.get(0).getDay());
Integer end = Integer.parseInt(list.get(size - 1).getDay());
for (int i = 1; i < start; i++) {
resultList.add(0f);
}
for (int i = 0; i < size; i++) {
resultList.add(list.get(i).getEnergy());
}
for (int i = end; i < 31; i++) {
resultList.add(0f);
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override
public PersistModel statEnergyMonthly() {
System.out.println("---------------------start--------------------");
int result = 0;
//需要更新或保存的list
List<BusProjectAreaStat> resultList = new ArrayList<BusProjectAreaStat>();
//得到需要统计的年份
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
if(calendar.get(Calendar.MONTH) == 1) year -= 1;
String yearS = String.valueOf(year);
//1.得到所有的项目
List<BusProject> busProjectList = busProjectRepository.queryBusProjects();
//2.循环所有的项目,查询对应项目的统计信息
Iterator<BusProject> busProjectIterator = busProjectList.iterator();
while (busProjectIterator.hasNext()) {
//得到项目主键
String proId = busProjectIterator.next().getProId();
//查询该项目的水电气面积
BusProjectAreaVo busProjectAreaVo = busProjectAreaRepository.classifyProjectArea(proId);
//3.查询对应项目的能源统计(按月份统计)
EnergyCountM e = new EnergyCountM();
e.setProId(proId);
e.setYear(yearS);
List<EnergyCountM> energyList = energyCountMRepository.getEnergyMonth(e);
//4.算出水电气的统计
if(energyList != null){
int size = energyList.size();
if(size > 0){
//得到全年总和
Float waterSum = 0f, elecSum = 0f, gasSum = 0f;
Iterator<EnergyCountM> it = energyList.iterator();
while (it.hasNext()) {
EnergyCountM energyCountM = it.next();
waterSum += energyCountM.getWater();
elecSum += energyCountM.getElec();
gasSum += energyCountM.getGas();
}
//算出年度平均值
waterSum = waterSum * 12 / size / busProjectAreaVo.getWaterArea();
elecSum = elecSum * 12 / size / busProjectAreaVo.getElecArea();
gasSum = gasSum * 12 / size / busProjectAreaVo.getGasArea();
//需要新增或更新的对象
resultList.add(new BusProjectAreaStat(proId, yearS, waterSum, elecSum, gasSum));
}
}
}else{
for (int i = 0; i < 31; i++) {
resultList.add(0f);
}
//增加或更新
Iterator<BusProjectAreaStat> resultIt = resultList.iterator();
while (resultIt.hasNext()) {
BusProjectAreaStat busProjectAreaStat = resultIt.next();
Example example = new Example(BusProjectAreaStat.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("year", yearS);
int i = busProjectAreaStatRepository.updateByExampleSelective(busProjectAreaStat, example);
if (i < 1) {
i = busProjectAreaStatRepository.insert(busProjectAreaStat);
}
result += i;
}
return resultList;
System.out.println("---------------------end--------------------");
return new PersistModel(result);
}
}
package org.rcisoft.business.overview.task;
import org.rcisoft.business.overview.service.OverViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* Created by JiChao on 2018/4/13.
* 概览中的定时任务
*/
@Component
public class OverViewTask {
@Autowired
private OverViewService overViewServiceImpl;
/**
* 每个月的1号0点30分执行
* 用能比较--计算上一个月 单位面积用量(水电气),更新结果至bus_project_area_stat表
*/
@Scheduled(cron = "0 30 0 1 * ?")
// @Scheduled(cron = "0/5 * * * * ?")
public void busProjectAreaStat(){
overViewServiceImpl.statEnergyMonthly();
}
}
package org.rcisoft.business.overview.vo;
import lombok.Data;
import org.rcisoft.business.overview.entity.BusProjectArea;
/**
* Created by JiChao on 2018/4/14.
*/
@Data
public class BusProjectAreaVo extends BusProjectArea {
private Float waterArea, elecArea, gasArea;
}
package org.rcisoft.business.overview.vo;
import lombok.Data;
import org.rcisoft.business.overview.entity.EnergyPrice;
import java.math.BigDecimal;
/**
* Created by JiChao on 2018/4/14.
*/
@Data
public class EnergyPriceVo extends EnergyPrice {
BigDecimal water, elec, gas;
}
......@@ -11,5 +11,11 @@
<result column="COUNTRY_STD" jdbcType="FLOAT" property="countryStd"/>
</resultMap>
<resultMap id="vo" type="org.rcisoft.business.overview.vo.BusProjectAreaVo">
<result column="WATER_AREA" jdbcType="FLOAT" property="waterArea"/>
<result column="ELEC_AREA" jdbcType="FLOAT" property="elecArea"/>
<result column="GAS_AREA" jdbcType="FLOAT" property="gasArea"/>
</resultMap>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
</mapper>
\ No newline at end of file
<?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="org.rcisoft.business.overview.dao.BusProjectRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.overview.entity.BusProject">
<id column="PRO_ID" jdbcType="VARCHAR" property="proId"/>
<result column="PRO_NM" jdbcType="VARCHAR" property="proNm"/>
<result column="BLD_TP_ID" jdbcType="VARCHAR" property="bldTpId"/>
<result column="BLD_AREA" jdbcType="FLOAT" property="bldArea"/>
<result column="BLD_LOCAL" jdbcType="VARCHAR" property="bldLocal"/>
<result column="BLD_COORDINATE" jdbcType="VARCHAR" property="bldCoordinate"/>
<result column="OWN_ID" jdbcType="VARCHAR" property="ownId"/>
<result column="TEAM_ID" jdbcType="VARCHAR" property="teamId"/>
</resultMap>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
</mapper>
\ No newline at end of file
......@@ -4,32 +4,17 @@
<resultMap id="BaseResultMap" type="org.rcisoft.business.overview.entity.EnergyPrice">
<id column="ID" jdbcType="VARCHAR" property="id"/>
<result column="PRO_ID" jdbcType="VARCHAR" property="proId"/>
<result column="P_0" jdbcType="FLOAT" property="p0"/>
<result column="P_1" jdbcType="FLOAT" property="p1"/>
<result column="P_2" jdbcType="FLOAT" property="p2"/>
<result column="P_3" jdbcType="FLOAT" property="p3"/>
<result column="P_4" jdbcType="FLOAT" property="p4"/>
<result column="P_5" jdbcType="FLOAT" property="p5"/>
<result column="P_6" jdbcType="FLOAT" property="p6"/>
<result column="P_7" jdbcType="FLOAT" property="p7"/>
<result column="P_8" jdbcType="FLOAT" property="p8"/>
<result column="P_9" jdbcType="FLOAT" property="p9"/>
<result column="P_10" jdbcType="FLOAT" property="p10"/>
<result column="P_11" jdbcType="FLOAT" property="p11"/>
<result column="P_12" jdbcType="FLOAT" property="p12"/>
<result column="P_13" jdbcType="FLOAT" property="p13"/>
<result column="P_14" jdbcType="FLOAT" property="p14"/>
<result column="P_15" jdbcType="FLOAT" property="p15"/>
<result column="P_16" jdbcType="FLOAT" property="p16"/>
<result column="P_17" jdbcType="FLOAT" property="p17"/>
<result column="P_18" jdbcType="FLOAT" property="p18"/>
<result column="P_19" jdbcType="FLOAT" property="p19"/>
<result column="P_20" jdbcType="FLOAT" property="p20"/>
<result column="P_21" jdbcType="FLOAT" property="p21"/>
<result column="P_22" jdbcType="FLOAT" property="p22"/>
<result column="P_23" jdbcType="FLOAT" property="p23"/>
<result column="P_HOUR" jdbcType="VARCHAR" property="pHour"/>
<result column="P_PRICE" jdbcType="DECIMAL" property="pPrice"/>
<result column="P_TP" jdbcType="CHAR" property="pTp"/>
</resultMap>
<resultMap id="vo" type="org.rcisoft.business.overview.vo.EnergyPriceVo">
<result column="P_HOUR" jdbcType="VARCHAR" property="pHour"/>
<result column="WATER" jdbcType="DECIMAL" property="water"/>
<result column="ELEC" jdbcType="DECIMAL" property="elec"/>
<result column="GAS" jdbcType="DECIMAL" property="gas"/>
</resultMap>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment