Commit ef3240ac authored by jichao's avatar jichao

改bug,增加用能计划--年度查询接口

parent a95c4f3d
package org.rcisoft.business.manage.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.manage.service.EnergyEmissionPlanService;
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;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Created by JiChao on 2018/5/31.
* 基准(计划)碳排放量
*/
@Api(tags = "基准碳排放量")
@RestController
@RequestMapping("energyplan")
public class EnergyEmissionPlanController {
@Autowired
private EnergyEmissionPlanService energyEmissionPlanServiceImpl;
@ApiOperation(value="下载模板文件", notes="excel文件下载")
@RequestMapping("/downloadExcel")
public void downloadExcel(HttpServletRequest request, HttpServletResponse response) {
energyEmissionPlanServiceImpl.downloadExcel(request, response);
}
@ApiOperation(value="下载模板文件", notes="excel文件下载")
@ApiImplicitParams({
@ApiImplicitParam(name = "proId", value = "项目主键", required = true, dataType = "字符串")
})
@RequestMapping("/uploadExcel")
public void uploadExcel(@RequestParam MultipartFile file, @RequestParam String proId) {
energyEmissionPlanServiceImpl.uploadExcel(file, proId);
}
}
package org.rcisoft.business.manage.service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Created by JiChao on 2018/5/31.
*/
public interface EnergyEmissionPlanService {
/**
* 下载模板文件
* @param request
* @param response
*/
void downloadExcel(HttpServletRequest request, HttpServletResponse response);
/**
* 上传模板文件
* @param file
* @param proId
* @return
*/
Integer uploadExcel(MultipartFile file, String proId);
}
package org.rcisoft.business.manage.service.impl;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.rcisoft.business.manage.service.EnergyEmissionPlanService;
import org.rcisoft.business.overview.dao.EnergyEmissionPlanRepository;
import org.rcisoft.business.overview.entity.EnergyEmissionPlan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
/**
* Created by JiChao on 2018/5/31.
*/
@Service
public class EnergyEmissionPlanServiceImpl implements EnergyEmissionPlanService {
@Autowired
private EnergyEmissionPlanRepository energyEmissionPlanRepository;
/**
* 解决中文名乱码
* @param request
* @param response
* @param title
* @param bytes
* @throws UnsupportedEncodingException
*/
private void setResponse(HttpServletRequest request, HttpServletResponse response, String title, byte[] bytes) throws UnsupportedEncodingException {
String userAgent = request.getHeader("User-Agent");
boolean isMSIE = userAgent != null && (userAgent.indexOf("MSIE") > -1 || userAgent.indexOf("like Gecko") > -1);
if (isMSIE) {
title = URLEncoder.encode(title, "UTF8");
} else {
title = new String(title.getBytes("UTF-8"), "ISO-8859-1");
}
response.setContentType("application/x-msdownload");
response.setContentLength(bytes.length);
response.setHeader("Content-Disposition", "attachment;filename=" + title + ".xls");
}
@Override
public void downloadExcel(HttpServletRequest request, HttpServletResponse response) {
try(OutputStream outputStream = response.getOutputStream()) {
File file = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "excel/碳排放量.xls");
//转成字节
byte[] bytes = FileUtils.readFileToByteArray(file);
//设置下载头
this.setResponse(request, response, "碳排放量", bytes);
outputStream.write(bytes);
} catch (IOException e) {
e.printStackTrace();
}
}
@Transactional
@Override
public Integer uploadExcel(MultipartFile file, String proId) {
HSSFWorkbook workbook = null;
//需要保存的结果集
List<EnergyEmissionPlan> resultList = new ArrayList<>();
//结果
int result = 0;
try(InputStream is = file.getInputStream()) {
workbook = new HSSFWorkbook(is);
//读取sheet
HSSFSheet sheet = workbook.getSheetAt(0);
//从第二行开始读取数据
for (int i = 1; i < sheet.getLastRowNum() + 1; i++) {
HSSFRow row = sheet.getRow(i);
if (row != null) {
// 如果第一列为空,认为已经结束,跳出循环
if (StringUtils.isEmpty(row.getCell(0).getStringCellValue())) break;
// 从第二列开始,读取12个月份
for (int j = 1; j < 13; j++) {
// 获得单元格的值
String emission = row.getCell(j).getStringCellValue();
if (StringUtils.isNotEmpty(emission)) {
// id,proId,月,日,值
EnergyEmissionPlan e = new EnergyEmissionPlan(null, proId, j, i, new BigDecimal(emission));
resultList.add(e);
}
}
}
}
// 保存数据
if (resultList.size() > 0) {
//先删除之前的
energyEmissionPlanRepository.delete(new EnergyEmissionPlan(null, proId, null, null, null));
//增加
result = energyEmissionPlanRepository.batchSave(resultList);
}
}catch (IOException e) {
e.printStackTrace();
} finally {
try {
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
}
...@@ -132,6 +132,15 @@ public class OverViewController { ...@@ -132,6 +132,15 @@ public class OverViewController {
} }
/** -------------碳排放量--------------- */ /** -------------碳排放量--------------- */
@ApiOperation(value="查询每年的用能", notes="查询每年的用能")
@ApiImplicitParams({
@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串")
})
@RequestMapping("/statEnergyPlan")
public Result statEnergyPlan(@RequestParam String proId) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.statEnergyPlan(proId));
}
@ApiOperation(value="年用能计划", notes="年用能计划") @ApiOperation(value="年用能计划", notes="年用能计划")
@ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串"), @ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串"),
@ApiImplicitParam(name = "year", value = "年份,如:2018", required = true, dataType = "字符串或数字") @ApiImplicitParam(name = "year", value = "年份,如:2018", required = true, dataType = "字符串或数字")
...@@ -162,4 +171,10 @@ public class OverViewController { ...@@ -162,4 +171,10 @@ public class OverViewController {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.statEnergyPlanDay(proId, year, month, day)); return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.statEnergyPlanDay(proId, year, month, day));
} }
@ApiOperation(value="实际排放量定时任务测试", notes="实际排放量定时任务测试")
@RequestMapping("/statEmission")
public Result statEmission() {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, overViewServiceImpl.statEmission());
}
} }
package org.rcisoft.business.overview.dao; package org.rcisoft.business.overview.dao;
import org.apache.ibatis.annotations.Param;
import org.rcisoft.business.overview.entity.BusEnergyplanV; import org.rcisoft.business.overview.entity.BusEnergyplanV;
import org.rcisoft.business.overview.vo.BusEnergyPlanVo; import org.rcisoft.business.overview.vo.BusEnergyPlanVo;
import org.rcisoft.core.base.BaseMapper; import org.rcisoft.core.base.BaseMapper;
...@@ -16,15 +17,28 @@ import java.util.List; ...@@ -16,15 +17,28 @@ import java.util.List;
@Repository @Repository
public interface BusEnergyplanVRepository extends BaseMapper<BusEnergyplanV> { public interface BusEnergyplanVRepository extends BaseMapper<BusEnergyplanV> {
@Select("<script>select date_format(b.TM,'%c') MON,sum(b.ENERGY_MONEY) ENERGY_MONEY from bus_energyplan_v b,bus_device d where b.DEV_NUM=d.DEV_ID and d.PRO_ID=#{proId} and date_format(b.TM,'%Y')=#{time} group by date_format(b.TM,'%c') order by date_format(b.TM,'%c')+0 asc</script>") /**
* 查询每年的用能计划
* @param proId
* @return
*/
@Select("<script>SELECT date_format(b.TM, '%Y') `YEAR`,sum(b.ENERGY_MONEY) ENERGY_MONEY " +
"FROM bus_energyplan_v b, bus_device d " +
"WHERE b.DEV_NUM = d.DEV_NUM AND d.PRO_ID = #{proId} " +
"group by date_format(b.TM,'%Y') " +
"order by date_format(b.TM,'%Y')+0 asc</script>")
@ResultMap(value = "vo")
List<BusEnergyPlanVo> statEnergyPlan(@Param("proId") String proId);
@Select("<script>select date_format(b.TM,'%c') MON,sum(b.ENERGY_MONEY) ENERGY_MONEY from bus_energyplan_v b,bus_device d where b.DEV_NUM=d.DEV_NUM and d.PRO_ID=#{proId} and date_format(b.TM,'%Y')=#{time} group by date_format(b.TM,'%c') order by date_format(b.TM,'%c')+0 asc</script>")
@ResultMap(value = "vo") @ResultMap(value = "vo")
List<BusEnergyPlanVo> statEnergyPlanYear(BusEnergyPlanVo busEnergyPlanVo); List<BusEnergyPlanVo> statEnergyPlanYear(BusEnergyPlanVo busEnergyPlanVo);
@Select("<script>select date_format(b.TM,'%e') `DAY`,sum(b.ENERGY_MONEY) ENERGY_MONEY from bus_energyplan_v b,bus_device d where b.DEV_NUM=d.DEV_ID and d.PRO_ID=#{proId} and date_format(b.TM,'%Y-%c')=#{time} group by date_format(b.TM,'%e') order by date_format(b.TM,'%e')+0 asc</script>") @Select("<script>select date_format(b.TM,'%e') `DAY`,sum(b.ENERGY_MONEY) ENERGY_MONEY from bus_energyplan_v b,bus_device d where b.DEV_NUM=d.DEV_NUM and d.PRO_ID=#{proId} and date_format(b.TM,'%Y-%c')=#{time} group by date_format(b.TM,'%e') order by date_format(b.TM,'%e')+0 asc</script>")
@ResultMap(value = "vo") @ResultMap(value = "vo")
List<BusEnergyPlanVo> statEnergyPlanMonth(BusEnergyPlanVo busEnergyPlanVo); List<BusEnergyPlanVo> statEnergyPlanMonth(BusEnergyPlanVo busEnergyPlanVo);
@Select("<script>select date_format(b.TM,'%k') `HOUR`,sum(b.ENERGY_MONEY) ENERGY_MONEY from bus_energyplan_v b,bus_device d where b.DEV_NUM=d.DEV_ID and d.PRO_ID=#{proId} and date_format(b.TM,'%Y-%c-%e')=#{time} group by date_format(b.TM,'%k') order by date_format(b.TM,'%k')+0 asc</script>") @Select("<script>select date_format(b.TM,'%k') `HOUR`,sum(b.ENERGY_MONEY) ENERGY_MONEY from bus_energyplan_v b,bus_device d where b.DEV_NUM=d.DEV_NUM and d.PRO_ID=#{proId} and date_format(b.TM,'%Y-%c-%e')=#{time} group by date_format(b.TM,'%k') order by date_format(b.TM,'%k')+0 asc</script>")
@ResultMap(value = "vo") @ResultMap(value = "vo")
List<BusEnergyPlanVo> statEnergyPlanDay(BusEnergyPlanVo busEnergyPlanVo); List<BusEnergyPlanVo> statEnergyPlanDay(BusEnergyPlanVo busEnergyPlanVo);
} }
......
package org.rcisoft.business.overview.dao; package org.rcisoft.business.overview.dao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap; import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.overview.entity.EnergyCountM; import org.rcisoft.business.overview.entity.EnergyCountM;
...@@ -79,7 +80,7 @@ public interface EnergyCountMRepository extends BaseMapper<EnergyCountM> { ...@@ -79,7 +80,7 @@ public interface EnergyCountMRepository extends BaseMapper<EnergyCountM> {
"select e.`DAY`," + "select e.`DAY`," +
"sum(e.WATER_MONEY)+sum(e.ELEC_MONEY)+sum(e.GAS_MONEY) MONEY" + "sum(e.WATER_MONEY)+sum(e.ELEC_MONEY)+sum(e.GAS_MONEY) MONEY" +
" from energy_count_m e where e.PRO_ID=#{proId} and e.`YEAR`=#{year} and e.MON=${mon}" + " from energy_count_m e where e.PRO_ID=#{proId} and e.`YEAR`=#{year} and e.MON=${mon}" +
"<if test=\"hour != null\"> and e.HOUR &lt;= ${hour}</if>" + // "<if test=\"hour != null\"> and e.HOUR &lt;= ${hour}</if>" +
" group by e.`DAY`+0 asc) a order by a.MONEY desc</script>") " group by e.`DAY`+0 asc) a order by a.MONEY desc</script>")
@ResultMap("resultMapVo") @ResultMap("resultMapVo")
List<EnergyCountMVo> getPriceRank(EnergyCountMVo energyCountMVo); List<EnergyCountMVo> getPriceRank(EnergyCountMVo energyCountMVo);
...@@ -116,6 +117,15 @@ public interface EnergyCountMRepository extends BaseMapper<EnergyCountM> { ...@@ -116,6 +117,15 @@ public interface EnergyCountMRepository extends BaseMapper<EnergyCountM> {
@ResultMap("BaseResultMap") @ResultMap("BaseResultMap")
EnergyCountM countEnergyDay(EnergyCountM energyCountM); EnergyCountM countEnergyDay(EnergyCountM energyCountM);
/**
* 查询每年的用能
* @param proId
* @return
*/
@Select("<script>select e.`YEAR`,sum(if(e.WATER_MONEY is null,0,e.WATER_MONEY))+sum(if(e.ELEC_MONEY is null,0,e.ELEC_MONEY))+sum(if(e.GAS_MONEY is null,0,e.GAS_MONEY)) MONEY from energy_count_m e where e.PRO_ID=#{proId} group by e.`YEAR`+0 asc</script>")
@ResultMap("resultMapVo")
List<EnergyCountMVo> statEnergyPlan(@Param("proId") String proId);
/** /**
* 年用能计划 * 年用能计划
* @param energyCountMVo * @param energyCountMVo
......
package org.rcisoft.business.overview.dao; package org.rcisoft.business.overview.dao;
import org.apache.ibatis.annotations.Insert;
import org.rcisoft.business.overview.entity.EnergyEmissionPlan; import org.rcisoft.business.overview.entity.EnergyEmissionPlan;
import org.rcisoft.core.base.BaseMapper; import org.rcisoft.core.base.BaseMapper;
import org.apache.ibatis.annotations.ResultMap; import org.apache.ibatis.annotations.ResultMap;
...@@ -23,5 +24,16 @@ public interface EnergyEmissionPlanRepository extends BaseMapper<EnergyEmissionP ...@@ -23,5 +24,16 @@ public interface EnergyEmissionPlanRepository extends BaseMapper<EnergyEmissionP
@Select("<script>select * from energy_emission_plan where PRO_ID=#{proId} and MON=#{mon} and `DAY`=#{day}</script>") @Select("<script>select * from energy_emission_plan where PRO_ID=#{proId} and MON=#{mon} and `DAY`=#{day}</script>")
@ResultMap(value = "BaseResultMap") @ResultMap(value = "BaseResultMap")
List<EnergyEmissionPlan> queryEnergyEmissionPlans(EnergyEmissionPlan energyEmissionPlan); List<EnergyEmissionPlan> queryEnergyEmissionPlans(EnergyEmissionPlan energyEmissionPlan);
/**
* 批量添加
* @param list
* @return
*/
@Insert("<script><foreach collection=\"resultList\" item=\"item\" separator=\";\">" +
"insert into energy_emission_plan(PRO_ID,MON,DAY,EMISSION) " +
"values(#{item.proId},#{item.mon},#{item.day},#{item.emission})" +
"</foreach></script>")
Integer batchSave(List<EnergyEmissionPlan> list);
} }
...@@ -121,6 +121,13 @@ public interface OverViewService { ...@@ -121,6 +121,13 @@ public interface OverViewService {
*/ */
PersistModel statEmission(); PersistModel statEmission();
/**
* 查询每年的用能
* @param proId
* @return
*/
List<Map<String, Object>> statEnergyPlan(String proId);
/** /**
* 年用能计划 * 年用能计划
* @param proId * @param proId
......
...@@ -2,6 +2,8 @@ package org.rcisoft.business.overview.service.impl; ...@@ -2,6 +2,8 @@ package org.rcisoft.business.overview.service.impl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
//import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.rcisoft.business.manage.vo.EnergyPriceVo; import org.rcisoft.business.manage.vo.EnergyPriceVo;
import org.rcisoft.business.overview.dao.*; import org.rcisoft.business.overview.dao.*;
import org.rcisoft.business.overview.entity.*; import org.rcisoft.business.overview.entity.*;
...@@ -18,6 +20,8 @@ import tk.mybatis.mapper.entity.Example; ...@@ -18,6 +20,8 @@ import tk.mybatis.mapper.entity.Example;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
/** /**
...@@ -47,8 +51,7 @@ public class OverViewServiceImpl implements OverViewService { ...@@ -47,8 +51,7 @@ public class OverViewServiceImpl implements OverViewService {
private BusEnergyplanVRepository busEnergyplanVRepository; private BusEnergyplanVRepository busEnergyplanVRepository;
private Calendar getBeforeDay(Calendar cl, int time){ private Calendar getBeforeDay(Calendar cl, int time){
int day = cl.get(Calendar.DATE); cl.add(Calendar.DATE, time);
cl.set(Calendar.DATE, day + time);
return cl; return cl;
} }
...@@ -71,56 +74,60 @@ public class OverViewServiceImpl implements OverViewService { ...@@ -71,56 +74,60 @@ public class OverViewServiceImpl implements OverViewService {
} }
//返回同比或环比的年、月 //返回同比或环比的年、月
private Map<String, String> getTime(String year, String month, String day, int yearVar, int monthVar, int dayVar){ private Map<String, String> getTime(Object year, Object month, Object day, int yearVar, int monthVar, int dayVar){
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
if(year != null){ if(year != null){
calendar.set(Calendar.YEAR, Integer.parseInt(year) + yearVar); if (year instanceof String) {
calendar.set(Calendar.YEAR, Integer.parseInt((String) year));
}else if (year instanceof Integer) {
calendar.set(Calendar.YEAR, (Integer) year);
}
calendar.add(Calendar.YEAR, yearVar);
} }
if(month != null){ if(month != null){
calendar.set(Calendar.MONTH, Integer.parseInt(month) - 1 + monthVar); if (month instanceof String) {
calendar.set(Calendar.MONTH, Integer.parseInt((String) month) - 1);
}else if (month instanceof Integer) {
calendar.set(Calendar.MONTH, (Integer) month - 1);
}
calendar.add(Calendar.MONTH, monthVar);
} }
if(day != null){ if(day != null){
calendar.set(Calendar.DATE, Integer.parseInt(day) + dayVar); if (day instanceof String) {
calendar.set(Calendar.DATE, Integer.parseInt((String) day));
}else if (day instanceof Integer) {
calendar.set(Calendar.DATE, (Integer) day);
}
calendar.add(Calendar.DATE, dayVar);
} }
Map<String, String> result = new HashMap<String, String>(); Map<String, String> result = new HashMap<String, String>();
result.put("year", String.valueOf(calendar.get(Calendar.YEAR))); result.put("year", String.valueOf(calendar.get(Calendar.YEAR)));
String _month = String.valueOf(calendar.get(Calendar.MONTH) + 1); result.put("month", String.valueOf(calendar.get(Calendar.MONTH) + 1));
if (_month.length() == 1) _month = "0" + _month; result.put("day", String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
result.put("month", _month);
String _day = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
if (_day.length() == 1) _day = "0" + _day;
result.put("day", _day);
return result; return result;
} }
//查询当月的天数 //查询当月的天数
private int getCurrentMonthDateCount(Object year, Object month){ private int getCurrentMonthDateCount(Object year, Object month){
Calendar cal = Calendar.getInstance(); if (year != null && month != null) {
if(year != null){ String time = year + "-" + month;
if (year instanceof Integer){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
cal.set(Calendar.YEAR, (Integer) year); Calendar cal = Calendar.getInstance();
}else if (year instanceof String){ try {
cal.set(Calendar.YEAR, Integer.parseInt((String) year)); cal.setTime(sdf.parse(time));
} catch (ParseException e) {
e.printStackTrace();
} }
return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
} else {
return 0;
} }
if(month != null){
if (month instanceof Integer) cal.set(Calendar.MONTH, (Integer) month - 1);
else if (month instanceof String) cal.set(Calendar.MONTH, Integer.parseInt((String) month) - 1);
}
return cal.getActualMaximum(Calendar.DATE);
} }
public static void main(String[] args){ public static void main(String[] args){
// OverViewServiceImpl o = new OverViewServiceImpl();
// Map<String, String> time = o.getTime("2016", "3", null, 0, -1, 0);
// System.out.println(time.get("year") + "-" + time.get("month") + "-" + time.get("day"));
// Calendar cal = Calendar.getInstance();
// int maxDate = cal.getActualMaximum(Calendar.DATE);
// System.out.println(maxDate);
OverViewServiceImpl o = new OverViewServiceImpl(); OverViewServiceImpl o = new OverViewServiceImpl();
// System.out.println(o.getCurrentMonthDateCount("2018", null)); Map<String, String> time = o.getTime(2018, null, null, -1, 0, 0);
System.out.println(time.get("year") + "-" + time.get("month") + "-" + time.get("day"));
} }
private String getType(String type) { private String getType(String type) {
...@@ -360,7 +367,7 @@ public class OverViewServiceImpl implements OverViewService { ...@@ -360,7 +367,7 @@ public class OverViewServiceImpl implements OverViewService {
if (total.compareTo(new BigDecimal(0)) == 0) if (total.compareTo(new BigDecimal(0)) == 0)
energyCountMVo.setPercent(total + "%"); energyCountMVo.setPercent(total + "%");
else else
energyCountMVo.setPercent(energyCountMVo.getEnergy().divide(total, 1, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)) + "%"); energyCountMVo.setPercent(energyCountMVo.getEnergy().divide(total, 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)) + "%");
} }
} }
return list; return list;
...@@ -379,7 +386,7 @@ public class OverViewServiceImpl implements OverViewService { ...@@ -379,7 +386,7 @@ public class OverViewServiceImpl implements OverViewService {
e.setYear(cal.get("year")); e.setYear(cal.get("year"));
e.setMon(cal.get("month")); e.setMon(cal.get("month"));
e.setDay(day); e.setDay(day);
if(date != 0) e.setHour(cal.get("hour")); // if(date != 0) e.setHour(cal.get("hour"));
List<EnergyCountMVo> list = energyCountMRepository.getPriceRank(e); List<EnergyCountMVo> list = energyCountMRepository.getPriceRank(e);
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
EnergyCountMVo energyCountMVo = list.get(i); EnergyCountMVo energyCountMVo = list.get(i);
...@@ -387,6 +394,7 @@ public class OverViewServiceImpl implements OverViewService { ...@@ -387,6 +394,7 @@ public class OverViewServiceImpl implements OverViewService {
if(StringUtils.equals(day, eDay)) { if(StringUtils.equals(day, eDay)) {
result.put("money", energyCountMVo.getMoney()); result.put("money", energyCountMVo.getMoney());
result.put("rank", i + 1); result.put("rank", i + 1);
break;
} }
} }
return result; return result;
...@@ -471,9 +479,9 @@ public class OverViewServiceImpl implements OverViewService { ...@@ -471,9 +479,9 @@ public class OverViewServiceImpl implements OverViewService {
Map<String, String> time = null; Map<String, String> time = null;
//同比,环比,确定时间 //同比,环比,确定时间
if(cType == 1){//同比 if(cType == 1){//同比
time = this.getTime(year, month, null, -1, 0, 0); time = this.getTime(year, null, null, -1, 0, 0);
}else{//环比 }else{//环比
time = this.getTime(year, month, null, 0, -1, 0); time = this.getTime(null, month, null, 0, -1, 0);
} }
//新的时间 //新的时间
String c_year = time.get("year"); String c_year = time.get("year");
...@@ -605,13 +613,13 @@ public class OverViewServiceImpl implements OverViewService { ...@@ -605,13 +613,13 @@ public class OverViewServiceImpl implements OverViewService {
if(day_same != null) result.put("day_same", result.get("day_now").subtract(day_same.getEmission())); if(day_same != null) result.put("day_same", result.get("day_now").subtract(day_same.getEmission()));
else result.put("day_same", result.get("day_now").subtract(zero)); else result.put("day_same", result.get("day_now").subtract(zero));
//环比月 //环比月
Map<String, String> ring_time = this.getTime(null, month.toString(), null, 0, -1, 0); Map<String, String> ring_time = this.getTime(null, month, null, 0, -1, 0);
EnergyEmissionReal e_ring = new EnergyEmissionReal(proId, Integer.parseInt(ring_time.get("year")), Integer.parseInt(ring_time.get("month")), Integer.parseInt(ring_time.get("day"))); EnergyEmissionReal e_ring = new EnergyEmissionReal(proId, Integer.parseInt(ring_time.get("year")), Integer.parseInt(ring_time.get("month")), Integer.parseInt(ring_time.get("day")));
EnergyEmissionReal month_ring = energyEmissionRealRepository.statEnergyEmissionReal(e_ring); EnergyEmissionReal month_ring = energyEmissionRealRepository.statEnergyEmissionReal(e_ring);
if(month_ring != null) result.put("month_ring", result.get("month_now").subtract(month_ring.getEmission())); if(month_ring != null) result.put("month_ring", result.get("month_now").subtract(month_ring.getEmission()));
else result.put("month_ring", result.get("month_now").subtract(zero)); else result.put("month_ring", result.get("month_now").subtract(zero));
//环比日 //环比日
ring_time = this.getTime(null, null, day.toString(), 0, 0, -1); ring_time = this.getTime(null, null, day, 0, 0, -1);
e_ring = new EnergyEmissionReal(proId, Integer.parseInt(ring_time.get("year")), Integer.parseInt(ring_time.get("month")), Integer.parseInt(ring_time.get("day"))); e_ring = new EnergyEmissionReal(proId, Integer.parseInt(ring_time.get("year")), Integer.parseInt(ring_time.get("month")), Integer.parseInt(ring_time.get("day")));
EnergyEmissionReal day_ring = energyEmissionRealRepository.queryEnergyEmissionReal(e_ring); EnergyEmissionReal day_ring = energyEmissionRealRepository.queryEnergyEmissionReal(e_ring);
if(day_ring != null) result.put("day_ring", result.get("day_now").subtract(day_ring.getEmission())); if(day_ring != null) result.put("day_ring", result.get("day_now").subtract(day_ring.getEmission()));
...@@ -653,7 +661,7 @@ public class OverViewServiceImpl implements OverViewService { ...@@ -653,7 +661,7 @@ public class OverViewServiceImpl implements OverViewService {
while (busProjectIterator.hasNext()) { while (busProjectIterator.hasNext()) {
//得到项目主键 //得到项目主键
String proId = busProjectIterator.next().getProId(); String proId = busProjectIterator.next().getProId();
EnergyCountM energyCountM = energyCountMRepository.countEnergyDay(new EnergyCountM(proId, day.toString(), month.toString(), year.toString())); EnergyCountM energyCountM = energyCountMRepository.countEnergyDay(new EnergyCountM(proId, year.toString(), month.toString(), day.toString()));
if(energyCountM != null){ if(energyCountM != null){
//得到碳排放量 //得到碳排放量
BigDecimal water = energyCountM.getWater(), elec = energyCountM.getElec(), gas = energyCountM.getGas(); BigDecimal water = energyCountM.getWater(), elec = energyCountM.getElec(), gas = energyCountM.getGas();
...@@ -681,6 +689,35 @@ public class OverViewServiceImpl implements OverViewService { ...@@ -681,6 +689,35 @@ public class OverViewServiceImpl implements OverViewService {
return new PersistModel(result); return new PersistModel(result);
} }
@Override
public List<Map<String, Object>> statEnergyPlan(String proId) {
List<Map<String, Object>> resultList = new ArrayList<>();
List<BusEnergyPlanVo> planList = busEnergyplanVRepository.statEnergyPlan(proId);
List<EnergyCountMVo> realList = energyCountMRepository.statEnergyPlan(proId);
// 循环实际结果集
realList.forEach(energyCountMVo -> {
String year = energyCountMVo.getYear();
Map<String, Object> result = new HashMap<>();
result.put("year", year);
result.put("real", energyCountMVo.getMoney());
result.put("plan", 0);
// 循环计划结果集,如果有年份相同的,将结果放入
if (planList != null) {
for (int i = 0; i < planList.size(); i++) {
BusEnergyPlanVo busEnergyPlanVo = planList.get(i);
String planYear = busEnergyPlanVo.getYear();
if (StringUtils.equals(planYear, year)) {
result.put("plan", busEnergyPlanVo.getEnergyMoney());
planList.remove(i);
break;
}
}
}
resultList.add(result);
});
return resultList;
}
private Map<String, Object> getEnergyPlanResult(List<BigDecimal> planList, List<BigDecimal> realList) { private Map<String, Object> getEnergyPlanResult(List<BigDecimal> planList, List<BigDecimal> realList) {
//达标月数,未达标月数 //达标月数,未达标月数
int standard = 0, excessive = 0; int standard = 0, excessive = 0;
......
...@@ -98,8 +98,9 @@ global: ...@@ -98,8 +98,9 @@ global:
filepath: filepath:
analysis: /home/zhny/filepath/analysis/ analysis: /home/zhny/filepath/analysis/
equipment: /home/zhny/filepath/equipment/ equipment: /home/zhny/filepath/equipment/
devicetp: /home/zhny/filepath/devicetp/ devicetp: /home/zhny/dist/devicetp/
loginimg: /home/zhny/filepath/loginimg/ loginimg: /home/zhny/filepath/loginimg/
qrcode: /home/zhny/filepath/qrcode/
serverimgurl: 139.199.98.105:9000/ serverimgurl: 139.199.98.105:9000/
......
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