Commit f864d6af authored by jichao's avatar jichao

运维--能耗分布 接口

parent 1b0ecd77
package org.rcisoft.business.mainte.distributed.controller;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.mainte.distributed.service.MainteDistributedService;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by JiChao on 2018/4/23.
*/
@RestController
@RequestMapping("maintedistributed")
public class MainteDistributedController {
@Autowired
private MainteDistributedService mainteDistributedServiceImpl;
@ApiOperation(value="能耗分布", notes="能耗分布")
@ApiImplicitParams({@ApiImplicitParam(name = "year", value = "年", required = true, dataType = "字符串或数字"),
@ApiImplicitParam(name = "month", value = "月", required = true, dataType = "字符串或数字")
})
@RequestMapping("/queryEnergyDistributed")
public Result queryEnergyDistributed(@RequestParam String year, @RequestParam String month) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, mainteDistributedServiceImpl.queryEnergyDistributed(year, month));
}
@ApiOperation(value="能耗对比", notes="能耗对比")
@ApiImplicitParams({@ApiImplicitParam(name = "year", value = "年", required = true, dataType = "字符串或数字"),
@ApiImplicitParam(name = "bldZoneId", value = "分区id", required = true, dataType = "字符串或数字")
})
@RequestMapping("/queryEnergyCompared")
public Result queryEnergyCompared(@RequestParam String year, @RequestParam String bldZoneId) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, mainteDistributedServiceImpl.queryEnergyCompared(year, bldZoneId));
}
@ApiOperation(value="建筑年代统计", notes="建筑年代统计")
@ApiImplicitParams({})
@RequestMapping("/queryBuildingAge")
public Result queryBuildingAge() {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, mainteDistributedServiceImpl.queryBuildingAge());
}
@ApiOperation(value="设备年代统计", notes="设备年代统计")
@ApiImplicitParams({})
@RequestMapping("/queryDeviceAge")
public Result queryDeviceAge() {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, mainteDistributedServiceImpl.queryDeviceAge());
}
}
package org.rcisoft.business.mainte.distributed.dao;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.mainte.distributed.entity.BuildingAge;
import org.rcisoft.business.mainte.distributed.entity.DeviceAge;
import org.rcisoft.business.mainte.distributed.entity.EnergyCompared;
import org.rcisoft.business.mainte.distributed.entity.EnergyDistributed;
import org.rcisoft.business.mainte.distributed.vo.Params;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Created by JiChao on 2018/4/23.
*/
@Repository
public interface MainteDistributedRepository {
@Select("<script>select b.PRO_NM,b.BLD_COORDINATE,b.BLD_AREA, " +
"sum(if(e.WATER_MONEY is null, 0, e.WATER_MONEY)) WATER_MONEY, " +
"sum(if(e.ELEC_MONEY is null, 0, e.ELEC_MONEY)) ELEC_MONEY, " +
"sum(if(e.GAS_MONEY is null, 0, e.GAS_MONEY)) GAS_MONEY " +
"from energy_count_m e,bus_project b " +
"where e.PRO_ID=b.PRO_ID and e.`YEAR`=#{year} and e.MON=#{month} " +
"group by e.MON,b.PRO_NM</script>")
@ResultMap(value = "EnergyDistributed")
List<EnergyDistributed> queryEnergyDistributed(Params params);
@Select("<script>select a.BLD_TP_NM,a.MON,convert(avg(a.MONEY),decimal(10,2)) MONEY from (" +
"select e.PRO_ID,t.BLD_TP_NM,e.MON," +
"sum((if(e.WATER_MONEY is null, 0, e.WATER_MONEY)+if(e.ELEC_MONEY is null, 0, e.ELEC_MONEY)+if(e.GAS_MONEY is null, 0, e.GAS_MONEY))/b.BLD_AREA) MONEY " +
"from energy_count_m e,bus_project b,bus_build_tp t " +
"where e.PRO_ID=b.PRO_ID and b.BLD_TP_ID=t.BLD_TP_ID and e.`YEAR`=#{year} and b.BLD_ZONE_ID=#{bldZoneId} " +
"group by e.PRO_ID,t.BLD_TP_NM,e.MON order by t.BLD_TP_NM,e.MON" +
") a group by a.MON,a.BLD_TP_NM order by a.BLD_TP_NM,a.MON</script>")
@ResultMap(value = "EnergyCompared")
List<EnergyCompared> queryEnergyCompared(Params params);
@Select("<script>select b.PRO_NM,t.BLD_TP_NM,date_format(b.BLD_YEAR, '%Y') `YEAR`," +
"convert(sum((if(e.WATER_MONEY is null, 0, e.WATER_MONEY)+if(e.ELEC_MONEY is null, 0, e.ELEC_MONEY)+if(e.GAS_MONEY is null, 0, e.GAS_MONEY))/b.BLD_AREA),decimal(10,2)) MONEY " +
"from energy_count_m e,bus_project b,bus_build_tp t " +
"where e.PRO_ID=b.PRO_ID and b.BLD_TP_ID=t.BLD_TP_ID " +
"group by e.PRO_ID,b.PRO_NM,t.BLD_TP_NM,date_format(b.BLD_YEAR, '%Y') " +
"order by t.BLD_TP_NM</script>")
@ResultMap(value = "BuildingAge")
List<BuildingAge> queryBuildingAge();
@Select("<script>select b.PRO_NM,t.BLD_TP_NM,date_format(b.DEVICE_YEAR, '%Y') `YEAR`," +
"convert(sum((if(e.WATER_MONEY is null, 0, e.WATER_MONEY)+if(e.ELEC_MONEY is null, 0, e.ELEC_MONEY)+if(e.GAS_MONEY is null, 0, e.GAS_MONEY))/b.BLD_AREA),decimal(10,2)) MONEY " +
"from energy_count_m e,bus_project b,bus_build_tp t " +
"where e.PRO_ID=b.PRO_ID and b.BLD_TP_ID=t.BLD_TP_ID " +
"group by e.PRO_ID,b.PRO_NM,t.BLD_TP_NM,date_format(b.DEVICE_YEAR, '%Y') " +
"order by t.BLD_TP_NM</script>")
@ResultMap(value = "DeviceAge")
List<DeviceAge> queryDeviceAge();
}
package org.rcisoft.business.mainte.distributed.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* Created by JiChao on 2018/4/23.
* 能耗对比
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BuildingAge implements Serializable {
private String bldTPNm;
private String proNm;
private Integer year;
private BigDecimal money;
}
package org.rcisoft.business.mainte.distributed.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* Created by JiChao on 2018/4/23.
* 能耗对比
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DeviceAge implements Serializable {
private String bldTPNm;
private String proNm;
private Integer year;
private BigDecimal money;
}
package org.rcisoft.business.mainte.distributed.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* Created by JiChao on 2018/4/23.
* 能耗对比
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EnergyCompared implements Serializable {
private String bldTPNm;
private Integer mon;
private BigDecimal money;
}
package org.rcisoft.business.mainte.distributed.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* Created by JiChao on 2018/4/23.
* 能耗分布
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EnergyDistributed implements Serializable {
private String proNm;
private String bldCoordinate;
private Float bldArea;
private BigDecimal waterMoney;
private BigDecimal elecMoney;
private BigDecimal gasMoney;
}
package org.rcisoft.business.mainte.distributed.service;
import org.rcisoft.business.mainte.distributed.vo.BuildingAgeVo;
import org.rcisoft.business.mainte.distributed.vo.DeviceAgeVo;
import org.rcisoft.business.mainte.distributed.vo.EnergyComparedVo;
import org.rcisoft.business.mainte.distributed.vo.EnergyDistributedVo;
import java.util.List;
/**
* Created by JiChao on 2018/4/23.
*/
public interface MainteDistributedService {
List<EnergyDistributedVo> queryEnergyDistributed(String year, String month);
EnergyComparedVo queryEnergyCompared(String year, String bldZoneId);
BuildingAgeVo queryBuildingAge();
DeviceAgeVo queryDeviceAge();
}
package org.rcisoft.business.mainte.distributed.service.impl;
import org.apache.commons.lang3.StringUtils;
import org.rcisoft.business.mainte.distributed.dao.MainteDistributedRepository;
import org.rcisoft.business.mainte.distributed.entity.BuildingAge;
import org.rcisoft.business.mainte.distributed.entity.DeviceAge;
import org.rcisoft.business.mainte.distributed.entity.EnergyCompared;
import org.rcisoft.business.mainte.distributed.entity.EnergyDistributed;
import org.rcisoft.business.mainte.distributed.service.MainteDistributedService;
import org.rcisoft.business.mainte.distributed.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
/**
* Created by JiChao on 2018/4/23.
*/
@Service
public class MainteDistributedServiceImpl implements MainteDistributedService {
@Autowired
private MainteDistributedRepository mainteDistributedRepository;
@Override
public List<EnergyDistributedVo> queryEnergyDistributed(String year, String month) {
List<EnergyDistributedVo> resultList = new ArrayList<>();
List<EnergyDistributed> list = mainteDistributedRepository.queryEnergyDistributed(new Params(year, month, null));
list.forEach(energyDistributed -> {
EnergyDistributedVo vo = new EnergyDistributedVo();
//项目名
vo.setName(energyDistributed.getProNm());
//坐标
List<Object> value = new ArrayList<>();
String[] coordinate = StringUtils.deleteWhitespace(energyDistributed.getBldCoordinate()).split(",");
value.add(Float.parseFloat(coordinate[0]));
value.add(Float.parseFloat(coordinate[1]));
//值
value.add(new BigDecimal(0)
.add(energyDistributed.getWaterMoney())
.add(energyDistributed.getElecMoney())
.add(energyDistributed.getGasMoney())
.divide(new BigDecimal(energyDistributed.getBldArea()), 2, RoundingMode.HALF_UP)
);
vo.setValue(value);
//放入结果集
resultList.add(vo);
});
return resultList;
}
@Override
public EnergyComparedVo queryEnergyCompared(String year, String bldZoneId) {
//标题集
List<Object> title = new ArrayList<>();
//返回集
List<EnergyComparedVo.EnergyCompareResult> resultList = new ArrayList<>();
//结果集
List<EnergyCompared> list = mainteDistributedRepository.queryEnergyCompared(new Params(year, null, bldZoneId));
list.forEach(e -> {
String bldTPNm = e.getBldTPNm();
//判断,如果title中没有这个值
if(!title.contains(bldTPNm)){
EnergyComparedVo.EnergyCompareResult ev = new EnergyComparedVo().new EnergyCompareResult(bldTPNm, Arrays.asList(new Object[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}));
//放入返回集
resultList.add(ev);
//放入标题集
title.add(bldTPNm);
}
//取返回集中对应的记录,添加内容
resultList.forEach(ev -> {
if (StringUtils.equals(ev.getName(), bldTPNm))
ev.getData().set(e.getMon() - 1, e.getMoney());
});
});
//结果
return new EnergyComparedVo(title, resultList);
}
@Override
public BuildingAgeVo queryBuildingAge() {
//标题集
List<Object> title = new ArrayList<>();
//返回集
List<BuildingAgeVo.BuildingAgeResult> resultList = new ArrayList<>();
//结果集
List<BuildingAge> list = mainteDistributedRepository.queryBuildingAge();
list.forEach(b -> {
String bldTPNm = b.getBldTPNm();
if (!title.contains(bldTPNm)) {
BuildingAgeVo.BuildingAgeResult buildingAgeResult = new BuildingAgeVo().new BuildingAgeResult(bldTPNm, new ArrayList<>());
resultList.add(buildingAgeResult);
title.add(bldTPNm);
}
resultList.forEach(r -> {
if (StringUtils.equals(r.getName(), bldTPNm))
r.getData().add(Arrays.asList(new Object[]{b.getYear(), b.getMoney(), b.getProNm()}));
});
});
//返回值
return new BuildingAgeVo(title, resultList);
}
@Override
public DeviceAgeVo queryDeviceAge() {
//获得当前年份
int year = Calendar.getInstance().get(Calendar.YEAR);
//标题集
List<Object> title = new ArrayList<>();
//返回集
List<DeviceAgeVo.DeviceAgeResult> resultList = new ArrayList<>();
//结果集
List<DeviceAge> list = mainteDistributedRepository.queryDeviceAge();
list.forEach(d -> {
String bldTPNm = d.getBldTPNm();
if (!title.contains(bldTPNm)) {
DeviceAgeVo.DeviceAgeResult deviceAgeResult = new DeviceAgeVo().new DeviceAgeResult(bldTPNm, new ArrayList<>());
resultList.add(deviceAgeResult);
title.add(bldTPNm);
}
resultList.forEach(r -> {
if (StringUtils.equals(r.getName(), bldTPNm))
r.getData().add(Arrays.asList(new Object[]{year - d.getYear() + 1, d.getMoney(), d.getProNm()}));
});
});
return new DeviceAgeVo(title, resultList);
}
}
package org.rcisoft.business.mainte.distributed.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* Created by JiChao on 2018/4/23.
* 能耗对比 返回值
*/
@Data
@NoArgsConstructor
public class BuildingAgeVo {
private List<Object> title;
private List<BuildingAgeResult> result;
public BuildingAgeVo(List<Object> title, List<BuildingAgeResult> result){
this.title = title;
this.result = result;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BuildingAgeResult{
private String name;
private List<Object> data;
}
}
package org.rcisoft.business.mainte.distributed.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* Created by JiChao on 2018/4/23.
* 能耗对比 返回值
*/
@Data
@NoArgsConstructor
public class DeviceAgeVo {
private List<Object> title;
private List<DeviceAgeResult> result;
public DeviceAgeVo(List<Object> title, List<DeviceAgeResult> result){
this.title = title;
this.result = result;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DeviceAgeResult{
private String name;
private List<Object> data;
}
}
package org.rcisoft.business.mainte.distributed.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* Created by JiChao on 2018/4/23.
* 能耗对比 返回值
*/
@Data
@NoArgsConstructor
public class EnergyComparedVo {
private List<Object> title;
private List<EnergyCompareResult> result;
public EnergyComparedVo(List<Object> title, List<EnergyCompareResult> result) {
this.title = title;
this.result = result;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EnergyCompareResult {
private String name;
private List<Object> data;
}
}
package org.rcisoft.business.mainte.distributed.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* Created by JiChao on 2018/4/23.
* 能耗分布 返回值
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EnergyDistributedVo {
private String name;
private List<Object> value;
}
package org.rcisoft.business.mainte.distributed.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Created by JiChao on 2018/4/23.
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Params {
private String year,month;
//建筑分区id
private String bldZoneId;
}
<?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.mainte.distributed.dao.MainteDistributedRepository">
<resultMap id="EnergyDistributed" type="org.rcisoft.business.mainte.distributed.entity.EnergyDistributed">
<result column="PRO_NM" jdbcType="VARCHAR" property="proNm"/>
<result column="BLD_COORDINATE" jdbcType="VARCHAR" property="bldCoordinate"/>
<result column="BLD_AREA" jdbcType="FLOAT" property="bldArea"/>
<result column="WATER_MONEY" jdbcType="DECIMAL" property="waterMoney"/>
<result column="ELEC_MONEY" jdbcType="DECIMAL" property="elecMoney"/>
<result column="GAS_MONEY" jdbcType="DECIMAL" property="gasMoney"/>
</resultMap>
<resultMap id="EnergyCompared" type="org.rcisoft.business.mainte.distributed.entity.EnergyCompared">
<result column="BLD_TP_NM" jdbcType="VARCHAR" property="bldTPNm"/>
<result column="MON" jdbcType="VARCHAR" property="mon"/>
<result column="MONEY" jdbcType="DECIMAL" property="money"/>
</resultMap>
<resultMap id="BuildingAge" type="org.rcisoft.business.mainte.distributed.entity.BuildingAge">
<result column="BLD_TP_NM" jdbcType="VARCHAR" property="bldTPNm"/>
<result column="PRO_NM" jdbcType="VARCHAR" property="proNm"/>
<result column="YEAR" jdbcType="INTEGER" property="year"/>
<result column="MONEY" jdbcType="DECIMAL" property="money"/>
</resultMap>
<resultMap id="DeviceAge" type="org.rcisoft.business.mainte.distributed.entity.DeviceAge">
<result column="BLD_TP_NM" jdbcType="VARCHAR" property="bldTPNm"/>
<result column="PRO_NM" jdbcType="VARCHAR" property="proNm"/>
<result column="YEAR" jdbcType="INTEGER" property="year"/>
<result column="MONEY" jdbcType="DECIMAL" property="money"/>
</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