Commit b7d4aad6 authored by jichao's avatar jichao

改bug,增加基准碳排放量是否上传接口

parent fce6ab98
......@@ -5,6 +5,9 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.manage.service.EnergyEmissionPlanService;
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;
......@@ -32,13 +35,23 @@ public class EnergyEmissionPlanController {
energyEmissionPlanServiceImpl.downloadExcel(request, response);
}
@ApiOperation(value="下载模板文件", notes="excel文件下载")
@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);
public Result uploadExcel(@RequestParam MultipartFile file, @RequestParam String proId) {
Integer result = energyEmissionPlanServiceImpl.uploadExcel(file, proId);
return new Result().builder(new PersistModel(result), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, result);
}
@ApiOperation(value="判断是否上传过", notes="判断是否上传过")
@ApiImplicitParams({
@ApiImplicitParam(name = "proId", value = "项目主键", required = true, dataType = "字符串")
})
@RequestMapping("/checkExcel")
public Result checkExcel(@RequestParam String proId) {
return new Result().builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, energyEmissionPlanServiceImpl.checkExcel(proId));
}
}
......@@ -25,4 +25,11 @@ public interface EnergyEmissionPlanService {
*/
Integer uploadExcel(MultipartFile file, String proId);
/**
* 判断是否上传过
* @param proId
* @return
*/
Integer checkExcel(String proId);
}
......@@ -2,9 +2,11 @@ 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.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.rcisoft.business.manage.service.EnergyEmissionPlanService;
import org.rcisoft.business.overview.dao.EnergyEmissionPlanRepository;
import org.rcisoft.business.overview.entity.EnergyEmissionPlan;
......@@ -13,6 +15,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -83,11 +86,11 @@ public class EnergyEmissionPlanServiceImpl implements EnergyEmissionPlanService
HSSFRow row = sheet.getRow(i);
if (row != null) {
// 如果第一列为空,认为已经结束,跳出循环
if (StringUtils.isEmpty(row.getCell(0).getStringCellValue())) break;
if (StringUtils.isEmpty(this.getValue(row.getCell(0)))) break;
// 从第二列开始,读取12个月份
for (int j = 1; j < 13; j++) {
// 获得单元格的值
String emission = row.getCell(j).getStringCellValue();
String emission = this.getValue(row.getCell(j));
if (StringUtils.isNotEmpty(emission)) {
// id,proId,月,日,值
EnergyEmissionPlan e = new EnergyEmissionPlan(null, proId, j, i, new BigDecimal(emission));
......@@ -114,4 +117,35 @@ public class EnergyEmissionPlanServiceImpl implements EnergyEmissionPlanService
}
return result;
}
@Override
public Integer checkExcel(String proId) {
Example example = new Example(EnergyEmissionPlan.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("proId", proId);
return energyEmissionPlanRepository.selectCountByExample(example);
}
/**
* 读取cell的内容
* @param cell
* @return
*/
@SuppressWarnings("deprecation")
private String getValue(HSSFCell cell) {
if (cell == null) return null;
switch (cell.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? "TRUE" : "FALSE";
case Cell.CELL_TYPE_FORMULA:
return cell.getCellFormula();
case Cell.CELL_TYPE_NUMERIC:
cell.setCellType(Cell.CELL_TYPE_STRING);
return cell.getStringCellValue();
case Cell.CELL_TYPE_STRING:
return cell.getStringCellValue();
default:
return null;
}
}
}
package org.rcisoft.business.overview.dao;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultType;
import org.rcisoft.business.overview.entity.EnergyEmissionPlan;
import org.rcisoft.core.base.BaseMapper;
import org.apache.ibatis.annotations.ResultMap;
......@@ -30,10 +31,11 @@ public interface EnergyEmissionPlanRepository extends BaseMapper<EnergyEmissionP
* @param list
* @return
*/
@Insert("<script><foreach collection=\"resultList\" item=\"item\" separator=\";\">" +
@Insert("<script><foreach collection=\"list\" item=\"item\" separator=\";\">" +
"insert into energy_emission_plan(PRO_ID,MON,DAY,EMISSION) " +
"values(#{item.proId},#{item.mon},#{item.day},#{item.emission})" +
"</foreach></script>")
@ResultType(value = Integer.class)
Integer batchSave(List<EnergyEmissionPlan> list);
}
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