Commit 6f8f73b2 authored by jichao's avatar jichao

用能比较接口

parent 7b11519b
......@@ -25,10 +25,6 @@ public class OverViewController {
private OverViewService overViewServiceImpl;
/** --------------用能概况-------------- */
/**
* @param proId 项目主键
* @return
*/
@ApiOperation(value="根据项目类型id查询水、电、气24小时的价格", notes="返回水电气三种设备24小时价格")
@ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串")})
@RequestMapping("/getPrice/{proId:\\w+}")
......@@ -36,10 +32,6 @@ public class OverViewController {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.getPrice(proId));
}
/**
* @param proId 项目主键
* @return
*/
@ApiOperation(value="用量和费用统计", notes="用量和费用统计")
@ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串")})
@RequestMapping("/getEnergy/{proId:\\w+}")
......@@ -47,11 +39,6 @@ public class OverViewController {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.countAmountAndPrice(proId));
}
/**
* @param proId 项目主键
* @param type 水电气类型,1:水,2:电,3:气
* @return
*/
@ApiOperation(value="运行费用统计", notes="运行费用统计")
@ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串"),
@ApiImplicitParam(name = "type", value = "水电气类型,1:水,2:电,3:气", required = true, dataType = "数字"),
......@@ -62,12 +49,6 @@ public class OverViewController {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.countDailyPrice(proId, type, date));
}
/**
* @param proId 项目主键
* @param type 水电气类型,1:水,2:电,3:气
* @param date 0:今日,-1:昨日,1:明日
* @return
*/
@ApiOperation(value="耗能拆分统计", notes="耗能拆分统计")
@ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串"),
@ApiImplicitParam(name = "type", value = "水电气类型,1:水,2:电,3:气", required = true, dataType = "数字"),
......@@ -78,12 +59,6 @@ public class OverViewController {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.countEnergySplit(proId, type, date));
}
/**
* @param proId 项目主键
* @param type 水电气类型,1:水,2:电,3:气
* @param date 0:今日,-1:昨日,1:明日
* @return
*/
@ApiOperation(value="运行费用排名", notes="运行费用排名")
@ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串"),
@ApiImplicitParam(name = "type", value = "水电气类型,1:水,2:电,3:气", required = true, dataType = "数字"),
......@@ -98,19 +73,28 @@ public class OverViewController {
@ApiOperation(value="建筑单位面积用量标准", notes="水电气的行业标准、建议标准、国家标准")
@ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串")})
@RequestMapping("/getStandard")
public Result getStandard(@RequestParam String proId) {
@RequestMapping("/getStandard/{proId:\\w+}")
public Result getStandard(@PathVariable String proId) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.getStandard(proId));
}
/**
* @param proId 项目主键
* @return
*/
@ApiOperation(value="建筑单位面积用量年度", notes="建筑单位面积用量")
@ApiOperation(value="建筑单位面积用量年度", notes="建筑单位面积用量年度,三年的数据")
@ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串")})
@RequestMapping("/getUnitArea")
public Result getUnitArea(@RequestParam String proId) {
return null;
@RequestMapping("/getUnitArea/{proId:\\w+}")
public Result getUnitArea(@PathVariable String proId) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.getUnitArea(proId));
}
@ApiOperation(value="用能比较", notes="返回两组数据")
@ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串"),
@ApiImplicitParam(name = "year", value = "年份,如:2018", required = true, dataType = "字符串或数字"),
@ApiImplicitParam(name = "month", value = "月份,如:6", required = true, dataType = "字符串或数字"),
@ApiImplicitParam(name = "type", value = "水电气类型,1:水,2:电,3:气", required = true, dataType = "字符串或数字"),
@ApiImplicitParam(name = "proId", value = "1:同比,2:环比", required = true, dataType = "字符串或数字"),
})
@RequestMapping("/getEnergyCompare")
public Result getEnergyCompare(@RequestParam String proId, @RequestParam String year, @RequestParam String month, @RequestParam Integer type, @RequestParam Integer cType) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.getEnergyCompare(proId, year, month, type, cType));
}
}
package org.rcisoft.business.overview.dao;
import org.rcisoft.business.overview.entity.BusProjectAreaStat;
import org.rcisoft.core.base.BaseMapper;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
/**
* Created with on 2018-4-13 15:33:14.
*/
@Repository
public interface BusProjectAreaStatRepository extends BaseMapper<BusProjectAreaStat> {
/**
*
* @param busProjectAreaStat
* @return
*/
@Select("<script>select * from bus_project_area_stat where PRO_ID=#{proId} and `YEAR`=#{year}</script>")
@ResultMap(value = "BaseResultMap")
BusProjectAreaStat queryBusProjectAreaStats(BusProjectAreaStat busProjectAreaStat);
}
......@@ -77,4 +77,17 @@ public interface EnergyCountMRepository extends BaseMapper<EnergyCountM> {
@ResultMap("resultMapVo")
List<EnergyCountMVo> getPriceRank(EnergyCountMVo energyCountMVo);
/**
* 用能比较
* @param energyCountMVo
* @return
*/
@Select("<script>select e.`DAY`," +
"<if test=\"type == 1\">sum(e.WATER)</if>" +
"<if test=\"type == 2\">sum(e.ELEC)</if>" +
"<if test=\"type == 3\">sum(e.GAS)</if>" +
" as ENERGY from energy_count_m e where e.PRO_ID=#{proId} and e.`YEAR`=#{year} and e.MON=#{mon} group by e.`DAY`</script>")
@ResultMap("resultMapVo")
List<EnergyCountMVo> getEnergyCompare(EnergyCountMVo energyCountMVo);
}
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-13 15:33:14.
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "bus_project_area_stat")
public class BusProjectAreaStat implements Serializable {
public BusProjectAreaStat(String year, Float water, Float elec, Float gas) {
this.year = year;
this.water = water;
this.elec = elec;
this.gas = gas;
}
@Id
private Integer id;
private String proId;
private String year;
private Float water;
private Float elec;
private Float gas;
}
......@@ -57,4 +57,22 @@ public interface OverViewService {
*/
Map<String, Object> getStandard(String proId);
/**
* 建筑单位面积用量年度,三年的数据
* @param proId
* @return
*/
Map<String, Object> getUnitArea(String proId);
/**
* 用能比较
* @param proId
* @param year
* @param month
* @param type
* @param cType
* @return
*/
Map<String, Object> getEnergyCompare(String proId, String year, String month, Integer type, Integer cType);
}
......@@ -3,9 +3,11 @@ 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.service.OverViewService;
......@@ -28,6 +30,8 @@ public class OverViewServiceImpl implements OverViewService {
private EnergyCountMRepository energyCountMRepository;
@Autowired
private BusProjectAreaRepository busProjectAreaRepository;
@Autowired
private BusProjectAreaStatRepository busProjectAreaStatRepository;
private Calendar getBeforeDay(Calendar cl, int time){
int day = cl.get(Calendar.DATE);
......@@ -46,6 +50,30 @@ public class OverViewServiceImpl implements OverViewService {
return result;
}
private Map<String, String> getTime(String year, String month, String day, int yearVar, int monthVar, int dayVar){
Calendar calendar = Calendar.getInstance();
if(year != null){
calendar.set(Calendar.YEAR, Integer.parseInt(year) + yearVar);
}
if(month != null){
calendar.set(Calendar.MONTH, Integer.parseInt(month) - 1 + monthVar);
}
if(day != null){
calendar.set(Calendar.DATE, Integer.parseInt(day) + dayVar);
}
Map<String, String> result = new HashMap<String, String>();
result.put("year", String.valueOf(calendar.get(Calendar.YEAR)));
result.put("month", String.valueOf(calendar.get(Calendar.MONTH) + 1));
result.put("day", String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
return result;
}
public static void main(String[] args){
OverViewServiceImpl o = new OverViewServiceImpl();
Map<String, String> time = o.getTime("2016", "2", "29", 2, 0, 0);
System.out.println(time.get("year") + "-" + time.get("month") + "-" + time.get("day"));
}
private String getType(String type) {
switch (type) {
case "1": //水
......@@ -156,4 +184,107 @@ public class OverViewServiceImpl implements OverViewService {
}
return result;
}
@Override
public Map<String, Object> getUnitArea(String proId) {
String thisY = getTime(0).get("year");
int i = Integer.parseInt(thisY);
String lastY = String.valueOf(i - 1);
String beforeY = String.valueOf(i - 2);
BusProjectAreaStat b = new BusProjectAreaStat();
b.setProId(proId);
//查询当年
b.setYear(thisY);
BusProjectAreaStat thisBus = busProjectAreaStatRepository.queryBusProjectAreaStats(b);
//查询去年
b.setYear(lastY);
BusProjectAreaStat lastBus = busProjectAreaStatRepository.queryBusProjectAreaStats(b);
//查询前年
b.setYear(beforeY);
BusProjectAreaStat beforeBus = busProjectAreaStatRepository.queryBusProjectAreaStats(b);
//返回结果
Map<String, Object> result = new HashMap<String, Object>();
if(beforeBus == null) {
beforeBus = new BusProjectAreaStat(beforeY, 0f, 0f, 0f);
}
if(lastBus == null) {
lastBus = new BusProjectAreaStat(beforeY, 0f, 0f, 0f);
}
if(thisBus == null) {
thisBus = lastBus;
}
result.put("thisY", thisBus);
result.put("lastY", lastBus);
result.put("beforeY", beforeBus);
return result;
}
@Override
public Map<String, Object> getEnergyCompare(String proId, String year, String month, Integer type, Integer cType) {
//返回值
Map<String, Object> result = new HashMap<String, Object>();
//添加当前年月
result.put("year", year);
result.put("month", month);
EnergyCountMVo e = new EnergyCountMVo();
e.setProId(proId);
e.setType(type);
e.setYear(year);
e.setMon(month);
//查找现在的数据
List<EnergyCountMVo> nowCompare = energyCountMRepository.getEnergyCompare(e);
//现在数据最后返回的对象
List<Float> nowReturn = this.getFloatList(nowCompare);
//查找需要比较的数据
Map<String, String> time = null;
//同比,环比,确定时间
if(cType == 1){//同比
time = this.getTime(year, month, null, -1, 0, 0);
}else{//环比
time = this.getTime(year, month, null, 0, -1, 0);
}
//新的时间
String c_year = time.get("year");
String c_month = time.get("month");
e.setYear(c_year);
e.setMon(c_month);
//添加当前年月
result.put("cYear", c_year);
result.put("cMonth", c_month);
List<EnergyCountMVo> lastCompare = energyCountMRepository.getEnergyCompare(e);
List<Float> lastReturn = this.getFloatList(lastCompare);
//差值
List<Float> diffReturn = new ArrayList<Float>();
for (int i = 0; i < nowReturn.size(); i++) {
diffReturn.add(nowReturn.get(i) - lastReturn.get(i));
}
//数据值
result.put("nData", nowReturn);
result.put("cData", lastReturn);
result.put("dData", diffReturn);
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);
}
}else{
for (int i = 0; i < 31; i++) {
resultList.add(0f);
}
}
return resultList;
}
}
<?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.BusProjectAreaStatRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.overview.entity.BusProjectAreaStat">
<id column="ID" jdbcType="INTEGER" property="id"/>
<result column="PRO_ID" jdbcType="VARCHAR" property="proId"/>
<result column="YEAR" jdbcType="VARCHAR" property="year"/>
<result column="WATER" jdbcType="FLOAT" property="water"/>
<result column="ELEC" jdbcType="FLOAT" property="elec"/>
<result column="GAS" jdbcType="FLOAT" 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