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 {
}
/** -------------碳排放量--------------- */
@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="年用能计划")
@ApiImplicitParams({@ApiImplicitParam(name = "proId", value = "项目类型主键", required = true, dataType = "字符串"),
@ApiImplicitParam(name = "year", value = "年份,如:2018", required = true, dataType = "字符串或数字")
......@@ -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));
}
@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;
import org.apache.ibatis.annotations.Param;
import org.rcisoft.business.overview.entity.BusEnergyplanV;
import org.rcisoft.business.overview.vo.BusEnergyPlanVo;
import org.rcisoft.core.base.BaseMapper;
......@@ -16,15 +17,28 @@ import java.util.List;
@Repository
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")
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")
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")
List<BusEnergyPlanVo> statEnergyPlanDay(BusEnergyPlanVo busEnergyPlanVo);
}
......
package org.rcisoft.business.overview.dao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.overview.entity.EnergyCountM;
......@@ -79,7 +80,7 @@ public interface EnergyCountMRepository extends BaseMapper<EnergyCountM> {
"select e.`DAY`," +
"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}" +
"<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>")
@ResultMap("resultMapVo")
List<EnergyCountMVo> getPriceRank(EnergyCountMVo energyCountMVo);
......@@ -116,6 +117,15 @@ public interface EnergyCountMRepository extends BaseMapper<EnergyCountM> {
@ResultMap("BaseResultMap")
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
......
package org.rcisoft.business.overview.dao;
import org.apache.ibatis.annotations.Insert;
import org.rcisoft.business.overview.entity.EnergyEmissionPlan;
import org.rcisoft.core.base.BaseMapper;
import org.apache.ibatis.annotations.ResultMap;
......@@ -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>")
@ResultMap(value = "BaseResultMap")
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 {
*/
PersistModel statEmission();
/**
* 查询每年的用能
* @param proId
* @return
*/
List<Map<String, Object>> statEnergyPlan(String proId);
/**
* 年用能计划
* @param proId
......
......@@ -98,8 +98,9 @@ global:
filepath:
analysis: /home/zhny/filepath/analysis/
equipment: /home/zhny/filepath/equipment/
devicetp: /home/zhny/filepath/devicetp/
devicetp: /home/zhny/dist/devicetp/
loginimg: /home/zhny/filepath/loginimg/
qrcode: /home/zhny/filepath/qrcode/
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