Browse Source

#水电站月报发电量小数问题

zhongwei
yang_shj 6 months ago
parent
commit
af8b1c4389
  1. 53
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java

53
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java

@ -110,19 +110,30 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
} }
RunDataShowVo data = new RunDataShowVo(); RunDataShowVo data = new RunDataShowVo();
BeanUtil.copyProperties(entity,data); BeanUtil.copyProperties(entity,data);
List<RunDataVo> run = JSONObject.parseObject(entity.getRunData(),new TypeReference<List<RunDataVo>>(){}); List<RunDataVo> runs = JSONObject.parseObject(entity.getRunData(),new TypeReference<List<RunDataVo>>(){});
if(CollectionUtil.isEmpty(run)){ if(CollectionUtil.isEmpty(runs)){
return data; return data;
} }
double monSumGenerate = run.stream().mapToDouble(RunDataVo::getGenerate).sum(); // 保留两位小数
double monSumPlan = run.stream().mapToDouble(RunDataVo::getPlan).sum(); data.setRunData(JSONObject.toJSONString(runs.stream().map(run->{
// 月发电量
run.setGenerate(BigDecimal.valueOf(run.getGenerate()).setScale(2, RoundingMode.HALF_UP).doubleValue());
// 年发电量
run.setGenerateYear(BigDecimal.valueOf(run.getGenerateYear()).setScale(2, RoundingMode.HALF_UP).doubleValue());
return run;
}).collect(Collectors.toList())));
// 月发电量完成率
double monSumGenerate = runs.stream().mapToDouble(RunDataVo::getGenerate).sum();
double monSumPlan = runs.stream().mapToDouble(RunDataVo::getPlan).sum();
data.setMonSumGenerate(monSumGenerate); data.setMonSumGenerate(monSumGenerate);
data.setMonSumPlan(monSumPlan); data.setMonSumPlan(monSumPlan);
if(Math.abs(monSumGenerate) > 0 && Math.abs(monSumPlan) > 0){ if(Math.abs(monSumGenerate) > 0 && Math.abs(monSumPlan) > 0){
data.setMonRate(BigDecimal.valueOf(monSumGenerate / monSumPlan * 100L).setScale(2, RoundingMode.HALF_UP).doubleValue()); data.setMonRate(BigDecimal.valueOf(monSumGenerate / monSumPlan * 100L).setScale(2, RoundingMode.HALF_UP).doubleValue());
} }
double yearSumGenerate = run.stream().mapToDouble(RunDataVo::getGenerateYear).sum(); // 年发电量完成率
double yearSumPlan = run.stream().mapToDouble(RunDataVo::getPlanYear).sum(); double yearSumGenerate = runs.stream().mapToDouble(RunDataVo::getGenerateYear).sum();
double yearSumPlan = runs.stream().mapToDouble(RunDataVo::getPlanYear).sum();
data.setYearSumGenerate(yearSumGenerate); data.setYearSumGenerate(yearSumGenerate);
data.setYearSumPlan(yearSumPlan); data.setYearSumPlan(yearSumPlan);
if(Math.abs(yearSumGenerate) > 0 && Math.abs(yearSumPlan) > 0){ if(Math.abs(yearSumGenerate) > 0 && Math.abs(yearSumPlan) > 0){
@ -131,7 +142,6 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
return data; return data;
} }
/** /**
* 导出站点月报文件 * 导出站点月报文件
* @param mon * @param mon
@ -149,6 +159,17 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
if(ObjectUtil.isEmpty(data)){ if(ObjectUtil.isEmpty(data)){
throw new ServiceException("站点" + mon + "月份未生成运行月报数据!"); throw new ServiceException("站点" + mon + "月份未生成运行月报数据!");
} }
List<RunDataVo> runs = JSONObject.parseObject(data.getRunData(),new TypeReference<List<RunDataVo>>(){});
if(CollectionUtil.isNotEmpty(runs)){
// 保留两位小数
data.setRunData(JSONObject.toJSONString(runs.stream().map(run->{
// 月发电量
run.setGenerate(BigDecimal.valueOf(run.getGenerate()).setScale(2, RoundingMode.HALF_UP).doubleValue());
// 年发电量
run.setGenerateYear(BigDecimal.valueOf(run.getGenerateYear()).setScale(2, RoundingMode.HALF_UP).doubleValue());
return run;
}).collect(Collectors.toList())));
}
// 创建Excel文件 // 创建Excel文件
// 表头、sheet页、文件名 // 表头、sheet页、文件名
String headerName = data.getStationName() + "运行月报(" + mon + ")"; String headerName = data.getStationName() + "运行月报(" + mon + ")";
@ -211,7 +232,15 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME);
// 告警数据 // 告警数据
run.setAlarmData(this.alarmData(station.getCode(),start,end)); run.setAlarmData(this.alarmData(station.getCode(),start,end));
CountDownLatch countDownLatch = new CountDownLatch(devices.size()); List<RunDataVo> runDatas = new ArrayList<>();
List<CurveEchartVo> curveEcharts = new ArrayList<>();
for (RideDeviceVo device : devices){
// 运行数据
runDatas.add(this.runData(station.getCode(),device,plans,start,end));
// 月度运行曲线
curveEcharts.add(this.curveData(device,start,end));
}
/*CountDownLatch countDownLatch = new CountDownLatch(devices.size());
List<RunDataVo> runDatas = new CopyOnWriteArrayList<>(); List<RunDataVo> runDatas = new CopyOnWriteArrayList<>();
List<CurveEchartVo> curveEcharts = new CopyOnWriteArrayList<>(); List<CurveEchartVo> curveEcharts = new CopyOnWriteArrayList<>();
for (RideDeviceVo device : devices){ for (RideDeviceVo device : devices){
@ -220,8 +249,8 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
runDatas.add(this.runData(station.getCode(),device,plans,start,end)); runDatas.add(this.runData(station.getCode(),device,plans,start,end));
// 月度运行曲线 // 月度运行曲线
curveEcharts.add(this.curveData(device,start,end)); curveEcharts.add(this.curveData(device,start,end));
});
countDownLatch.countDown(); countDownLatch.countDown();
});
} }
//所有模板数据获取完成后释放锁 //所有模板数据获取完成后释放锁
try { try {
@ -229,11 +258,11 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }*/
if(CollectionUtil.isEmpty(runDatas)){ if(!CollectionUtil.isEmpty(runDatas)){
run.setRunData(JSONObject.toJSONString(runDatas)); run.setRunData(JSONObject.toJSONString(runDatas));
} }
if(CollectionUtil.isEmpty(curveEcharts)){ if(!CollectionUtil.isEmpty(curveEcharts)){
run.setCurveData(JSONObject.toJSONString(curveEcharts)); run.setCurveData(JSONObject.toJSONString(curveEcharts));
} }
// TODO 运行数据分析 // TODO 运行数据分析

Loading…
Cancel
Save