Browse Source

修正水电站月报导出bug

zhongwei
tyty 1 year ago
parent
commit
e4b07e8667
  1. 12
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java
  2. 23
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java

12
hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java

@ -20,6 +20,7 @@ import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.feign.ISysClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -43,7 +44,8 @@ public class AreaMonthReportController extends BladeController {
@NotNull
private final IAreaMonthReportService service;
@NotNull
private final ISysClient sysClient;
@ApiLog
@ApiOperationSupport(order = 1)
@ApiOperation("生成区域月报")
@ -129,14 +131,18 @@ public class AreaMonthReportController extends BladeController {
if (Func.isEmpty(year)||Func.isEmpty(deptId)||Func.isEmpty(month)||year==0||deptId==0||month==0){
return R.fail("传入格式不对,请重新导出");
}
String deptName="";
R<String> deptNameR = sysClient.getDeptName(deptId);
if (!deptNameR.isSuccess()) {
return R.fail("暂无该机构");
}
String deptName = deptNameR.getData();
if (type==1){
service.exportHydropowerStationMonthReport(response, map,year,month,deptId,deptName);
//word模板相对路径、word生成路径、word生成的文件名称、数据源
}
XWPFDocument xwpfDocument = WordUtils.exportWordV2("template/waterMonReport.docx", map);
// 下载导出
String filename = "(" + year+"年"+month+"月"+ ")"+deptName+"水电站月报";
String filename = year+"年"+month+"月"+deptName+"月报";
// 设置头信息
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel");

23
hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java

@ -50,10 +50,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.jfree.data.category.DefaultCategoryDataset;
import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.core.tool.utils.*;
import org.springblade.system.entity.Dept;
import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.entity.User;
@ -204,18 +201,11 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService {
return R.data("success");
}
@Override
public R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap<String, Object> map, Integer year, Integer month, Long deptId,String name) {
public R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap<String, Object> map, Integer year, Integer month, Long deptId,String deptName) {
R<List<Dept>> deptByCurrentUser = sysClient.getDeptByCurrentUser();
if (!deptByCurrentUser.isSuccess()||deptByCurrentUser.getData()==null){
return R.fail("用户权限查询失败");
}
R<String> deptNameR = sysClient.getDeptName(deptId);
if (!deptNameR.isSuccess()) {
return R.fail("暂无该机构");
}
String deptName = deptNameR.getData();
// 赋值给导出表格名称
name=deptName;
R<List<Dept>> deptR = sysClient.getDeptByType("200000", deptId, 4);
if (!deptR.isSuccess() || deptR.getData() == null) {
return R.fail("该机构不包含水站信息");
@ -229,12 +219,13 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService {
List<StationEntity> stationEntityList = stationService.list(Wrappers.<StationEntity>lambdaQuery()
.in(StationEntity::getRefDept, deptIds)
.eq(StationEntity::getType, HomePageConstant.HYDROPOWER));
stationEntityList=Optional.ofNullable(stationEntityList).orElse(new ArrayList<>()).stream().filter(s->Func.isNotEmpty(s.getCommissionTime())).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(stationEntityList)) {
Integer commissionTime = stationEntityList.stream().map(s -> {
int commissionTime = stationEntityList.stream().map(s -> {
Duration dur = Duration.between(s.getCommissionTime(), LocalDateTime.now());
return (int) dur.toDays();
}).reduce(Integer::max).get();
map.put("commissionTime", commissionTime.toString());
map.put("commissionTime", String.valueOf(commissionTime));
}else {
map.put("commissionTime", 0);
}
@ -782,11 +773,11 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService {
private static void getTabelSum(Long deptId, List<MonPowerPercentageVo> powerPercentageVoList, List<PlanGenerationEntity> planYearAll, List<PlanGenerationEntity> planMonAll, HashMap<String, Object> map) {
Float planGeneration = 0f;
if (CollectionUtil.isNotEmpty(planYearAll)) {
if (Func.isNotEmpty(planYearAll)) {
planGeneration = planYearAll.get(0).getPlanGeneration();
}
Float planMonGeneration = 0f;
if (CollectionUtil.isNotEmpty(planYearAll)) {
if (Func.isNotEmpty(planMonAll)) {
planMonGeneration = planMonAll.get(0).getPlanGeneration();
}
MonPowerPercentageVo powerVo = new MonPowerPercentageVo();

Loading…
Cancel
Save