diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java index 6694a16..d646833 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java @@ -44,4 +44,7 @@ public class RunMonthEntity extends TenantEntity { @ApiModelProperty("分析结果") private String analyseResult; + @ApiModelProperty("评价") + private String evaluation; + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/VectorParamController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/VectorParamController.java index ec681f1..0f72ac5 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/VectorParamController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/VectorParamController.java @@ -107,11 +107,11 @@ public class VectorParamController { return R.data(vectorParamService.getUrlResponseKeyList(url, bladeToken, hzinfoToken)); } - @PutMapping("/synchronization") + @PutMapping("/synchronization/{id}") @ApiOperation(value = "同步") @ApiOperationSupport(order = 10) public R synchronization(@RequestHeader(name = "Blade-Auth", value = "Blade-Auth", required = false) String bladeToken, - @RequestHeader(name = "Hzinfo-Auth", value = "Hzinfo-Auth", required = false) String hzinfoToken) throws JsonProcessingException { - return R.status(vectorParamService.synchronization(bladeToken, hzinfoToken)); + @RequestHeader(name = "Hzinfo-Auth", value = "Hzinfo-Auth", required = false) String hzinfoToken, @PathVariable Long id) throws JsonProcessingException { + return R.status(vectorParamService.synchronization(id, bladeToken, hzinfoToken)); } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/VectorParamService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/VectorParamService.java index 20cf06f..bc22e15 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/VectorParamService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/VectorParamService.java @@ -18,5 +18,5 @@ public interface VectorParamService extends IService { List getUrlResponseKeyList(String url, String bladeToken, String hzinfoToken); - Boolean synchronization(String bladeToken, String hzinfoToken); + Boolean synchronization(Long id ,String bladeToken, String hzinfoToken); } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java index a350a57..03c19fb 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; @@ -16,7 +17,6 @@ import com.hnac.hzims.bigmodel.maintenance.service.VectorParamService; import com.hnac.hzims.bigmodel.maintenance.vo.VectorUrlResponse; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.utils.CollectionUtil; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; @@ -49,59 +49,57 @@ public class VectorParamServiceImpl extends ServiceImpl keyList = new ArrayList<>(); -// Iterator iterator = item.fieldNames(); -// while (iterator.hasNext()) { -// keyList.add(iterator.next()); -// } -// result.setKeyList(keyList); -// } -// return result; -// } + private VectorUrlResponse getUrlResponseByArray(JsonNode rootNode) throws JsonProcessingException { + VectorUrlResponse result = new VectorUrlResponse(); + result.setOriginalData(JSONArray.parseArray(rootNode.toPrettyString()).toJavaList(JSONObject.class)); + JsonNode item = rootNode.get(0); + if (item != null) { + List keyList = new ArrayList<>(); + Iterator iterator = item.fieldNames(); + while (iterator.hasNext()) { + keyList.add(iterator.next()); + } + result.setKeyList(keyList); + } + return result; + } -// private VectorUrlResponse getUrlResponseByObject(JsonNode rootNode) throws JsonProcessingException { -// VectorUrlResponse result = new VectorUrlResponse(); -// result.setOriginalData(rootNode); -// List keyList = new ArrayList<>(); -// Iterator iterator = rootNode.fieldNames(); -// while (iterator.hasNext()) { -// keyList.add(iterator.next()); -// } -// result.setKeyList(keyList); -// return result; -// } + private VectorUrlResponse getUrlResponseByObject(JsonNode rootNode) throws JsonProcessingException { + VectorUrlResponse result = new VectorUrlResponse(); + List originalData = new ArrayList<>(); + originalData.add(JSON.parseObject(rootNode.toPrettyString())); + result.setOriginalData(originalData); + List keyList = new ArrayList<>(); + Iterator iterator = rootNode.fieldNames(); + while (iterator.hasNext()) { + keyList.add(iterator.next()); + } + result.setKeyList(keyList); + return result; + } @Override public List getUrlResponseKeyList(String url, String bladeToken, String hzinfoToken) { @@ -110,45 +108,30 @@ public class VectorParamServiceImpl extends ServiceImpl list = this.list(); - if (CollectionUtil.isEmpty(list)) { + public Boolean synchronization(Long id, String bladeToken, String hzinfoToken) { + VectorParamEntity entity = getById(id); + if (null == entity) { return false; } - for (VectorParamEntity entity : list) { - VectorUrlResponse response = getUrlResponse(entity.getUrl(), bladeToken, hzinfoToken); - if (response != null) { - ObjectMapper mapper = new ObjectMapper(); - JsonNode rootNode = null; - try { - rootNode = mapper.readTree(entity.getAttributeMap()); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - Map attrMap = new HashMap<>(); - Iterator iterator = rootNode.fieldNames(); - while (iterator.hasNext()) { - String key = iterator.next(); - attrMap.put(key, rootNode.findValue(key).textValue()); - } - List dataList = new ArrayList(); - JsonNode dataObject = (JsonNode) response.getOriginalData(); - if (dataObject.isArray()) { - Iterator dataIterator = dataObject.iterator(); - while (dataIterator.hasNext()) { - dataList.add(toJsonObject(dataIterator.next())); - } - } else { - dataList.add(toJsonObject(dataObject)); - } - weaviateService.saveBatch(response.getOriginalData(), entity.getTableName(), attrMap); + VectorUrlResponse response = getUrlResponse(entity.getUrl(), bladeToken, hzinfoToken); + if (response != null) { + ObjectMapper mapper = new ObjectMapper(); + JsonNode rootNode = null; + try { + rootNode = mapper.readTree(entity.getAttributeMap()); + } catch (JsonProcessingException e) { + e.printStackTrace(); } + Map attrMap = new HashMap<>(); + Iterator iterator = rootNode.fieldNames(); + while (iterator.hasNext()) { + String key = iterator.next(); + attrMap.put(key, rootNode.findValue(key).textValue()); + } + weaviateService.saveBatch(response.getOriginalData(), entity.getTableName(), attrMap); + this.update(Wrappers.lambdaUpdate().eq(VectorParamEntity::getId, id).set(VectorParamEntity::getUpdateTime, new Date())); } return true; } - private JSONObject toJsonObject(JsonNode node) { - JSONObject jsonObject = JSON.parseObject(node.toString()); - return jsonObject; - } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java index a3a905f..7e47281 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java @@ -3,64 +3,69 @@ package com.hnac.hzims.operational.report.controller; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.operational.report.entity.RunMonthEntity; import com.hnac.hzims.operational.report.service.RunMonthService; +import com.hnac.hzims.operational.report.vo.RunMonthEvaluateVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.GetMapping; -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.bind.annotation.*; /** * @author ysj */ @RestController -@Api(value = "运行月报",tags = "生产月报") +@Api(value = "运行月报", tags = "生产月报") @AllArgsConstructor @RequestMapping("/run/month") public class RunMonthController { - private final RunMonthService runMonthService; + private final RunMonthService runMonthService; - @GetMapping("/generate") - @ApiOperation(value = "生成站点月报",notes = "生成站点月报") - @ApiOperationSupport(order = 1) - public R generate(@RequestParam("mon") String mon, - @RequestParam("stationCode") String stationCode){ - return R.data(runMonthService.generate(mon,stationCode)); - } + @GetMapping("/generate") + @ApiOperation(value = "生成站点月报", notes = "生成站点月报") + @ApiOperationSupport(order = 1) + public R generate(@RequestParam("mon") String mon, + @RequestParam("stationCode") String stationCode) { + return R.data(runMonthService.generate(mon, stationCode)); + } - @GetMapping("/check") - @ApiOperation(value = "查询站点月报数据",notes = "查询站点月报数据") - @ApiOperationSupport(order = 2) - public R check(@RequestParam("stationCode") String stationCode){ - return R.data(runMonthService.check(stationCode)); - } + @GetMapping("/check") + @ApiOperation(value = "查询站点月报数据", notes = "查询站点月报数据") + @ApiOperationSupport(order = 2) + public R check(@RequestParam("stationCode") String stationCode) { + return R.data(runMonthService.check(stationCode)); + } - @GetMapping("/data") - @ApiOperation(value = "查询站点月报数据",notes = "查询站点月报数据") - @ApiOperationSupport(order = 3) - public R data(@RequestParam("mon") String mon, - @RequestParam("stationCode") String stationCode){ - return R.data(runMonthService.data(mon,stationCode)); - } + @GetMapping("/data") + @ApiOperation(value = "查询站点月报数据", notes = "查询站点月报数据") + @ApiOperationSupport(order = 3) + public R data(@RequestParam("mon") String mon, + @RequestParam("stationCode") String stationCode) { + return R.data(runMonthService.data(mon, stationCode)); + } - @GetMapping("/export") - @ApiOperation(value = "导出站点运行月报",notes = "导出站点运行月报") - @ApiOperationSupport(order = 4) - public void export(@RequestParam("mon") String mon, - @RequestParam("stationCode") String stationCode){ - runMonthService.export(mon,stationCode); - } + @GetMapping("/export") + @ApiOperation(value = "导出站点运行月报", notes = "导出站点运行月报") + @ApiOperationSupport(order = 4) + public void export(@RequestParam("mon") String mon, + @RequestParam("stationCode") String stationCode) { + runMonthService.export(mon, stationCode); + } - @GetMapping("/generateAnalyseResult") - @ApiOperation(value = "生成分析结果",notes = "生成分析结果") - @ApiOperationSupport(order = 5) - public R generateAnalyseResult(@RequestParam @ApiParam("查询月份") String month, @RequestParam @ApiParam("站点编号") String stationCode) { - runMonthService.generateAnalyseResult(month,stationCode); - return R.success("调用成功!"); - } + @GetMapping("/generateAnalyseResult") + @ApiOperation(value = "生成分析结果", notes = "生成分析结果") + @ApiOperationSupport(order = 5) + public R generateAnalyseResult(@RequestParam @ApiParam("查询月份") String month, @RequestParam @ApiParam("站点编号") String stationCode) { + runMonthService.generateAnalyseResult(month, stationCode); + return R.success("调用成功!"); + } + + @PutMapping("/evaluate") + @ApiOperation(value = "站点月报评价", notes = "站点月报评价") + @ApiOperationSupport(order = 6) + public R evaluate(@RequestBody RunMonthEvaluateVO req) { + return R.data(runMonthService.evaluate(req.getId(), req.getText())); + } } \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java index 8f484f7..600b3d4 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java @@ -24,4 +24,6 @@ public interface RunMonthService extends IService { * @return 大模型调用结果 */ Boolean generateAnalyseResult(String month,String stationCode); + + Boolean evaluate(Long id, String text); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java index 616f38a..a926c3e 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java @@ -104,10 +104,11 @@ public class RunMonthServiceImpl extends ServiceImpl(256), new ThreadFactoryBuilder().setNameFormat("generate-run-report-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy()); + private static final ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(256), new ThreadFactoryBuilder().setNameFormat("generate-run-report-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy()); /** * 查询站点月报运行数据 + * * @param mon * @param stationCode * @return @@ -115,20 +116,21 @@ public class RunMonthServiceImpl extends ServiceImpllambdaQuery() - .eq(RunMonthEntity::getStationCode,stationCode) - .eq(RunMonthEntity::getMonth,mon) + .eq(RunMonthEntity::getStationCode, stationCode) + .eq(RunMonthEntity::getMonth, mon) ); - if(ObjectUtil.isEmpty(entity)){ + if (ObjectUtil.isEmpty(entity)) { throw new ServiceException("站点" + mon + "月份未生成运行月报,请先点击【生成】按钮生成月报!"); } RunDataShowVo data = new RunDataShowVo(); - BeanUtil.copyProperties(entity,data); - List runs = JSONObject.parseObject(entity.getRunData(),new TypeReference>(){}); - if(CollectionUtil.isEmpty(runs)){ + BeanUtil.copyProperties(entity, data); + List runs = JSONObject.parseObject(entity.getRunData(), new TypeReference>() { + }); + if (CollectionUtil.isEmpty(runs)) { return data; } // 保留两位小数 - data.setRunData(JSONObject.toJSONString(runs.stream().map(run->{ + data.setRunData(JSONObject.toJSONString(runs.stream().map(run -> { // 月发电量 run.setGenerate(BigDecimal.valueOf(run.getGenerate()).setScale(2, RoundingMode.HALF_UP).doubleValue()); // 年发电量 @@ -141,24 +143,24 @@ public class RunMonthServiceImpl extends ServiceImpl 0 && Math.abs(monSumPlan) > 0){ - data.setMonRate(BigDecimal.valueOf(monSumGenerate / monSumPlan * 100L).setScale(2, RoundingMode.HALF_UP).doubleValue()); + if (Math.abs(monSumGenerate) > 0 && Math.abs(monSumPlan) > 0) { + data.setMonRate(BigDecimal.valueOf(monSumGenerate / monSumPlan * 100L).setScale(2, RoundingMode.HALF_UP).doubleValue()); } // 年发电量完成率 double yearSumGenerate = runs.stream().mapToDouble(RunDataVo::getGenerateYear).sum(); double yearSumPlan = runs.stream().mapToDouble(RunDataVo::getPlanYear).sum(); data.setYearSumGenerate(yearSumGenerate); data.setYearSumPlan(yearSumPlan); - if(Math.abs(yearSumGenerate) > 0 && Math.abs(yearSumPlan) > 0){ - data.setYearRate(BigDecimal.valueOf(yearSumGenerate / yearSumPlan * 100L).setScale(2, RoundingMode.HALF_UP).doubleValue()); + if (Math.abs(yearSumGenerate) > 0 && Math.abs(yearSumPlan) > 0) { + data.setYearRate(BigDecimal.valueOf(yearSumGenerate / yearSumPlan * 100L).setScale(2, RoundingMode.HALF_UP).doubleValue()); } return data; } - /** * 导出站点月报文件 + * * @param mon * @param stationCode */ @@ -167,17 +169,18 @@ public class RunMonthServiceImpl extends ServiceImpllambdaQuery() - .eq(RunMonthEntity::getStationCode,stationCode) - .eq(RunMonthEntity::getMonth,mon) + RunMonthEntity data = this.getOne(Wrappers.lambdaQuery() + .eq(RunMonthEntity::getStationCode, stationCode) + .eq(RunMonthEntity::getMonth, mon) ); - if(ObjectUtil.isEmpty(data)){ + if (ObjectUtil.isEmpty(data)) { throw new ServiceException("站点" + mon + "月份未生成运行月报数据!"); } - List runs = JSONObject.parseObject(data.getRunData(),new TypeReference>(){}); - if(CollectionUtil.isNotEmpty(runs)){ + List runs = JSONObject.parseObject(data.getRunData(), new TypeReference>() { + }); + if (CollectionUtil.isNotEmpty(runs)) { // 保留两位小数 - data.setRunData(JSONObject.toJSONString(runs.stream().map(run->{ + data.setRunData(JSONObject.toJSONString(runs.stream().map(run -> { // 月发电量 run.setGenerate(BigDecimal.valueOf(run.getGenerate()).setScale(2, RoundingMode.HALF_UP).doubleValue()); // 年发电量 @@ -188,7 +191,7 @@ public class RunMonthServiceImpl extends ServiceImpllambdaQuery() .eq(StationEntity::getDataOrigin, HomePageConstant.DATA_ORIGIN) - .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) - .eq(StationEntity::getCode,stationCode) + .eq(StationEntity::getType, HomePageConstant.HYDROPOWER) + .eq(StationEntity::getCode, stationCode) ); - if(ObjectUtil.isEmpty(station)){ + if (ObjectUtil.isEmpty(station)) { throw new ServiceException("未查询到站点信息!"); } // 查询站点设备 List devices = deivceClient.rideDevices(Collections.singletonList(station.getRefDept())); - if(CollectionUtil.isEmpty(devices)){ + if (CollectionUtil.isEmpty(devices)) { throw new ServiceException("站点未配置机组设备信息、请先为站点添加设备,绑定设备实例,再进行月报查询!"); } // 计划发电量 DevicePlanGenerationVo param = new DevicePlanGenerationVo(); param.setStationIds(Collections.singletonList(stationCode)); - param.setDate(DateUtil.format(new Date(),"yyyy")); + param.setDate(DateUtil.format(new Date(), "yyyy")); List plans = planClient.getPlanGenerationByParam(param); RunMonthEntity run = new RunMonthEntity(); run.setTenantId(station.getTenantId()); @@ -244,20 +248,20 @@ public class RunMonthServiceImpl extends ServiceImpl runDatas = new ArrayList<>(); List curveEcharts = new ArrayList<>(); - for (RideDeviceVo device : devices){ + for (RideDeviceVo device : devices) { // 运行数据 - 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 countDownLatch = new CountDownLatch(devices.size()); List runDatas = new CopyOnWriteArrayList<>(); @@ -278,39 +282,40 @@ public class RunMonthServiceImpl extends ServiceImpl this.smartReportGeneratePower(mon,stationCode),"运行月报分析结论").start(); + new Thread(() -> this.smartReportGeneratePower(mon, stationCode), "运行月报分析结论").start(); return save; } /** * 调用大模型分析月报接口 - * @param mon 月报月份 + * + * @param mon 月报月份 * @param stationCode 月报站号 */ - private void smartReportGeneratePower(String mon,String stationCode) { + private void smartReportGeneratePower(String mon, String stationCode) { List analyseVOList = Lists.newArrayList(); YearMonth yearMonth = YearMonth.parse(mon); List months = Lists.newArrayList(yearMonth, yearMonth.minusMonths(1), yearMonth.minusYears(1)); - months.stream().map(YearMonth::toString).map(m ->{ + months.stream().map(YearMonth::toString).map(m -> { try { - return this.data(m,stationCode); - } catch(Exception e) { + return this.data(m, stationCode); + } catch (Exception e) { return null; } - }).filter(Func::isNotEmpty).forEach(d -> this.fillAnalyseData(d,analyseVOList,mon)); + }).filter(Func::isNotEmpty).forEach(d -> this.fillAnalyseData(d, analyseVOList, mon)); // 过滤掉发电量为空的数据 analyseVOList.forEach(analyseVO -> { List power = analyseVO.getPower(); @@ -329,15 +334,16 @@ public class RunMonthServiceImpl extends ServiceImpl analyseVOList, String month) { - if(Func.isNotEmpty(req)) { + if (Func.isNotEmpty(req)) { // 解析运行月报数据 - 运行数据、告警数据 List rundatas = JSONArray.parseArray(req.getRunData(), RunDataVo.class); - List alarms = JSONArray.parseArray(req.getAlarmData(),RunAlarmVo.class); + List alarms = JSONArray.parseArray(req.getAlarmData(), RunAlarmVo.class); // 取运行、告警设备设备并集 List runDatas = rundatas.stream().map(RunDataVo::getDeviceName).distinct().collect(Collectors.toList()); List alarmDatas = alarms.stream().map(RunAlarmVo::getDeviceName).distinct().collect(Collectors.toList()); @@ -345,10 +351,10 @@ public class RunMonthServiceImpl extends ServiceImpl { Integer deviceOrder = SetNameFormatterUtil.getSetOrder(deviceName); - if(Func.isNotEmpty(deviceOrder)) { + if (Func.isNotEmpty(deviceOrder)) { String formateDevice = deviceOrder + "#机组"; Optional exist = analyseVOList.stream().filter(a -> formateDevice.equals(a.getEmName())).findFirst(); - if(!exist.isPresent()) { + if (!exist.isPresent()) { // 若该设备未新增接受数据对象,则新增之后填充数据 RunReportDataAnalyseDTO analyseVO = this.createDeviceAnalyse(formateDevice, month, deviceOrder); analyseVOList.add(analyseVO); @@ -359,11 +365,11 @@ public class RunMonthServiceImpl extends ServiceImpl formateDevice.equals(a.getEmName())).findFirst().get(); PowerDataDTO powerDataDTO = analyseDTO.getPower().stream().filter(p -> req.getMonth().equals(p.getDate())).findFirst().get(); // 发电量赋值 - if(Func.isNotEmpty(powerDataDTO)) { - if(Func.isNotEmpty(power)) { + if (Func.isNotEmpty(powerDataDTO)) { + if (Func.isNotEmpty(power)) { powerDataDTO.setValue(Optional.ofNullable(powerDataDTO.getValue()).orElse(0.0) + power); } - if(Func.isNotEmpty(runHours)) { + if (Func.isNotEmpty(runHours)) { powerDataDTO.setRunTime(Optional.ofNullable(powerDataDTO.getRunTime()).orElse(0.0) + runHours); } } @@ -375,7 +381,7 @@ public class RunMonthServiceImpl extends ServiceImpl runs = runMonthReportService.list(Wrappers.lambdaQuery() - .eq(RunMonthEntity::getMonth,mon) - .eq(RunMonthEntity::getStationCode,stationCode) + .eq(RunMonthEntity::getMonth, mon) + .eq(RunMonthEntity::getStationCode, stationCode) ); - if(CollectionUtil.isEmpty(runs)){ + if (CollectionUtil.isEmpty(runs)) { return; } this.runMonthReportService.removeByIds(runs.stream().map(RunMonthEntity::getId).collect(Collectors.toList())); @@ -459,104 +467,109 @@ public class RunMonthServiceImpl extends ServiceImpl plans,String start,String end) { + private RunDataVo runData(String stationCode, RideDeviceVo device, List plans, String start, String end) { RunDataVo run = new RunDataVo(); run.setDeviceCode(device.getNumber()); run.setDeviceName(device.getName()); // 运行时长 - run.setRunHours(this.runHours(device,DateUtil.parse(start,DateUtil.PATTERN_DATETIME), DateUtil.parse(end,DateUtil.PATTERN_DATETIME))); + run.setRunHours(this.runHours(device, DateUtil.parse(start, DateUtil.PATTERN_DATETIME), DateUtil.parse(end, DateUtil.PATTERN_DATETIME))); // 月发电量 - Double day = this.generates(0,device.getNumber(),device.getRide(),start,end); - if(ObjectUtil.isEmpty(day)){ + Double day = this.generates(0, device.getNumber(), device.getRide(), start, end); + if (ObjectUtil.isEmpty(day)) { run.setGenerate(0.0); - }else{ - run.setGenerate(day/10000); + } else { + run.setGenerate(day / 10000); } // 年发电量 - Double year = this.generates(1,device.getNumber(),device.getRide(),start,end); - if(ObjectUtil.isEmpty(day)){ + Double year = this.generates(1, device.getNumber(), device.getRide(), start, end); + if (ObjectUtil.isEmpty(day)) { run.setGenerateYear(0.0); - }else{ - run.setGenerateYear(year/10000); + } else { + run.setGenerateYear(year / 10000); } // 计划发电量 - run.setPlan(this.planGenerate(0,stationCode,plans)/10000); + run.setPlan(this.planGenerate(0, stationCode, plans) / 10000); // 年计划发电量 - run.setPlanYear(this.planGenerate(1,stationCode,plans)/10000); + run.setPlanYear(this.planGenerate(1, stationCode, plans) / 10000); return run; } /** * 实际发电量 + * * @param type * @param deviceCode * @param ride * @return */ - private Double generates(int type,String deviceCode,double ride,String start,String end) { - if(type == 0){ - return Double.valueOf(dataService.periodTargetFloat(start,end,5,5,deviceCode,ride,HomePageConstant.HYDROPOWER_GENERATE_POWER)); + private Double generates(int type, String deviceCode, double ride, String start, String end) { + if (type == 0) { + return Double.valueOf(dataService.periodTargetFloat(start, end, 5, 5, deviceCode, ride, HomePageConstant.HYDROPOWER_GENERATE_POWER)); } Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.MONTH,-calendar.get(Calendar.MONTH)); - calendar.add(Calendar.DAY_OF_MONTH,-calendar.get(Calendar.DAY_OF_MONTH)); - calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + calendar.add(Calendar.DAY_OF_MONTH, -calendar.get(Calendar.DAY_OF_MONTH)); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - calendar.add(Calendar.DAY_OF_MONTH,1); - return Double.valueOf(dataService.periodTargetFloat(DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME),end,5,6,deviceCode,ride,HomePageConstant.HYDROPOWER_GENERATE_POWER)); + calendar.add(Calendar.DAY_OF_MONTH, 1); + return Double.valueOf(dataService.periodTargetFloat(DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME), end, 5, 6, deviceCode, ride, HomePageConstant.HYDROPOWER_GENERATE_POWER)); } /** * 计划发电量 + * * @param type * @param stationCode * @param plans * @return */ - private Double planGenerate(int type, String stationCode,List plans) { + private Double planGenerate(int type, String stationCode, List plans) { Calendar calendar = Calendar.getInstance(); - calendar.setTime(DateUtil.parse("2024-05-01 00:00:00",DateUtil.PATTERN_DATETIME)); - if(type == 0){ - calendar.add(Calendar.DAY_OF_MONTH,-1); - calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY) + 1); + calendar.setTime(DateUtil.parse("2024-05-01 00:00:00", DateUtil.PATTERN_DATETIME)); + if (type == 0) { + calendar.add(Calendar.DAY_OF_MONTH, -1); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY) + 1); calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - String time = DateUtil.format(calendar.getTime(),"yyyy-MM"); + String time = DateUtil.format(calendar.getTime(), "yyyy-MM"); return plans.stream().filter(plan -> plan.getStationId().equals(stationCode) && plan.getDateTime().contains(time)) .mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); } - String time = DateUtil.format(calendar.getTime(),"yyyy"); + String time = DateUtil.format(calendar.getTime(), "yyyy"); return plans.stream().filter(plan -> plan.getStationId().equals(stationCode) && plan.getDateTime().contains(time)) .mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); } /** * 获取运行数据 + * * @param device * @return */ - private Double runHours(RideDeviceVo device,Date startDate,Date endDate) { + private Double runHours(RideDeviceVo device, Date startDate, Date endDate) { MultiAnalyzeCodePO analyze = new MultiAnalyzeCodePO(); analyze.setDeviceCode(device.getNumber()); analyze.setSignages(Collections.singletonList(HomePageConstant.ACTIVE_POWER)); List signages = dataService.analyzeCodeBySignages(Collections.singletonList(analyze)); - if(CollectionUtil.isEmpty(signages)){ + if (CollectionUtil.isEmpty(signages)) { return 0.0; } // 监测点 String realId = signages.get(0).getRealId(); - if(StringUtils.isEmpty(realId)){ + if (StringUtils.isEmpty(realId)) { return 0.0; } - return this.getRunConvertData(realId,startDate,endDate); + return this.getRunConvertData(realId, startDate, endDate); } /** * 获取时间范围内运行时长 + * * @param realId * @param startDate * @param endDate @@ -571,41 +584,42 @@ public class RunMonthServiceImpl extends ServiceImpl> result = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); - if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData())){ + if (!result.isSuccess() || ObjectUtil.isEmpty(result.getData())) { return 0.0; } // 开机运行时长 - long time = this.getRunTime(result.getData().getRecords(),startDate,endDate); + long time = this.getRunTime(result.getData().getRecords(), startDate, endDate); return BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue(); } /** * 获取运行时长 + * * @param result * @return */ - private long getRunTime(List result,Date startDate,Date endDate) { - if(result.size() == 1){ + private long getRunTime(List result, Date startDate, Date endDate) { + if (result.size() == 1) { // 一直开机 - if(Double.parseDouble(result.get(0).getValue()) > 0){ + if (Double.parseDouble(result.get(0).getValue()) > 0) { return endDate.getTime() - startDate.getTime(); } // 一直关机 return 0; } - long time=0; + long time = 0; // 遍历累计开机时长 - for(int i = 0; i< result.size() ; i++){ + for (int i = 0; i < result.size(); i++) { // 记录为开机状态 就计算到下次关机的时间差 - if(Double.parseDouble(result.get(i).getValue()) <= 0){ + if (Double.parseDouble(result.get(i).getValue()) <= 0) { continue; } - Date endTime,startTime = DateUtil.parse(result.get(i).getTime(), DateUtil.PATTERN_DATETIME); + Date endTime, startTime = DateUtil.parse(result.get(i).getTime(), DateUtil.PATTERN_DATETIME); // 遍历至最后一条数据,累计至当前时间 - if(i == result.size() - 1){ + if (i == result.size() - 1) { endTime = endDate; - }else { - endTime = DateUtil.parse(result.get(i+1).getTime(), DateUtil.PATTERN_DATETIME); + } else { + endTime = DateUtil.parse(result.get(i + 1).getTime(), DateUtil.PATTERN_DATETIME); } time += endTime.getTime() - startTime.getTime(); } @@ -614,46 +628,49 @@ public class RunMonthServiceImpl extends ServiceImpl alarms = this.hz3000Alarm(code,start,end); + List alarms = this.hz3000Alarm(code, start, end); // FDP智能预警 - alarms.addAll(this.intelligentEarly(code,start,end)); + alarms.addAll(this.intelligentEarly(code, start, end)); return JSONObject.toJSONString(alarms); } /** * 查询hz3000告警 + * * @param code */ - private List hz3000Alarm(String code,String start,String end) { + private List hz3000Alarm(String code, String start, String end) { SoeQueryConditionByStation query = new SoeQueryConditionByStation(); query.setStationIds(Collections.singletonList(code)); query.setTypes(Collections.singletonList(AlarmHandleConstant.FAULT)); - query.setBeginTime(LocalDateTime.parse(start,DateUtil.DATETIME_FORMATTER)); - query.setEndTime(LocalDateTime.parse(end,DateUtil.DATETIME_FORMATTER)); + query.setBeginTime(LocalDateTime.parse(start, DateUtil.DATETIME_FORMATTER)); + query.setEndTime(LocalDateTime.parse(end, DateUtil.DATETIME_FORMATTER)); query.setNeedPage(false); Result> result = soeClient.getByStationsAndTime(query); - if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData()) || CollectionUtil.isEmpty(result.getData().getRecords())){ + if (!result.isSuccess() || ObjectUtil.isEmpty(result.getData()) || CollectionUtil.isEmpty(result.getData().getRecords())) { return new ArrayList<>(); } - return result.getData().getRecords().stream().collect(Collectors.groupingBy(SoeData::getSoeExplain)).entrySet().stream().map(entry->{ + return result.getData().getRecords().stream().collect(Collectors.groupingBy(SoeData::getSoeExplain)).entrySet().stream().map(entry -> { RunAlarmVo alarm = new RunAlarmVo(); - alarm.setAlarmTime(DateUtil.format(entry.getValue().stream().sorted(Comparator.comparing(SoeData::getTs)).collect(Collectors.toList()).get(0).getTs(),DateUtil.PATTERN_DATETIME)); + alarm.setAlarmTime(DateUtil.format(entry.getValue().stream().sorted(Comparator.comparing(SoeData::getTs)).collect(Collectors.toList()).get(0).getTs(), DateUtil.PATTERN_DATETIME)); alarm.setDeviceName(entry.getValue().get(0).getDeviceName()); alarm.setContent(entry.getKey()); alarm.setType(String.valueOf(AlarmConstants.FAULT)); alarm.setTypeName("故障"); - alarm.setCount(Math.max(entry.getValue().stream().filter(o->StringUtil.isNotBlank(o.getTraceCount())).mapToInt(soe->Integer.parseInt(soe.getTraceCount())).sum(), 1)); + alarm.setCount(Math.max(entry.getValue().stream().filter(o -> StringUtil.isNotBlank(o.getTraceCount())).mapToInt(soe -> Integer.parseInt(soe.getTraceCount())).sum(), 1)); return alarm; }).collect(Collectors.toList()); } /** * 智能预警 + * * @param code * @param start * @param end @@ -661,15 +678,15 @@ public class RunMonthServiceImpl extends ServiceImpl intelligentEarly(String code, String start, String end) { StbAnalysisDTO param = new StbAnalysisDTO(); - param.setStartTime(LocalDateTime.parse(start,DateUtil.DATETIME_FORMATTER)); + param.setStartTime(LocalDateTime.parse(start, DateUtil.DATETIME_FORMATTER)); param.setEndTime(LocalDateTime.parse(end, DateUtil.DATETIME_FORMATTER)); param.setStations(Collections.singletonList(code)); param.setNeedPage(false); Result> result = soeDataClient.pageStbAnalysis(param); - if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData()) || CollectionUtil.isEmpty(result.getData().getRecords())){ + if (!result.isSuccess() || ObjectUtil.isEmpty(result.getData()) || CollectionUtil.isEmpty(result.getData().getRecords())) { return new ArrayList<>(); } - return result.getData().getRecords().stream().collect(Collectors.groupingBy(StbAnalysisVO::getName)).entrySet().stream().map(entry->{ + return result.getData().getRecords().stream().collect(Collectors.groupingBy(StbAnalysisVO::getName)).entrySet().stream().map(entry -> { RunAlarmVo alarm = new RunAlarmVo(); alarm.setAlarmTime(entry.getValue().stream().sorted(Comparator.comparing(StbAnalysisVO::getTs)).collect(Collectors.toList()).get(0).getTs()); alarm.setDeviceName(entry.getValue().get(0).getOrd()); @@ -685,67 +702,67 @@ public class RunMonthServiceImpl extends ServiceImpl curve(List attributes,String start,String end, String deviceCode) { - List datas = dataService.periodTargetSignages(start,end,3,3,deviceCode,attributes.stream().map(AttributeVo::getSignage).collect(Collectors.toList())); - if(CollectionUtil.isEmpty(datas)){ + private List curve(List attributes, String start, String end, String deviceCode) { + List datas = dataService.periodTargetSignages(start, end, 3, 3, deviceCode, attributes.stream().map(AttributeVo::getSignage).collect(Collectors.toList())); + if (CollectionUtil.isEmpty(datas)) { return new ArrayList<>(); } List analyseDatas = new ArrayList<>(); Calendar day = Calendar.getInstance(); - datas.forEach(data->{ - if(CollectionUtil.isEmpty(data.getList())){ + datas.forEach(data -> { + if (CollectionUtil.isEmpty(data.getList())) { return; } - analyseDatas.addAll(data.getList().stream().peek(item->{ + analyseDatas.addAll(data.getList().stream().peek(item -> { item.setSignage(data.getSignage()); Date date; - if(item.getTs().contains(".0")){ + if (item.getTs().contains(".0")) { date = DateUtil.parse(item.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - }else{ + } else { date = DateUtil.parse(item.getTs() + ".0", "yyyy-MM-dd HH:mm:ss.s"); } day.setTime(date); item.setTs(String.valueOf(day.get(Calendar.DAY_OF_MONTH))); }).collect(Collectors.toList())); }); - if(CollectionUtil.isEmpty(analyseDatas)){ + if (CollectionUtil.isEmpty(analyseDatas)) { return new ArrayList<>(); } - Map> map = analyseDatas.stream().collect(Collectors.groupingBy(AnalyseDataTaosVO::getTs)); - return map.entrySet().stream().map(entry->{ + Map> map = analyseDatas.stream().collect(Collectors.groupingBy(AnalyseDataTaosVO::getTs)); + return map.entrySet().stream().map(entry -> { EchartVo echart = new EchartVo(); echart.setTime(Integer.valueOf(entry.getKey())); - echart.setValues(entry.getValue().stream().map(value->{ + echart.setValues(entry.getValue().stream().map(value -> { EchartValueVo echartValue = new EchartValueVo(); echartValue.setAttribute(value.getSignage()); - echartValue.setAttributeName(attributes.stream().filter(o->o.getSignage().equals(value.getSignage())).collect(Collectors.toList()).get(0).getSignageName()); - if(StringUtil.isEmpty(value.getVal())){ + echartValue.setAttributeName(attributes.stream().filter(o -> o.getSignage().equals(value.getSignage())).collect(Collectors.toList()).get(0).getSignageName()); + if (StringUtil.isEmpty(value.getVal())) { echartValue.setValue(0.0); - }else{ + } else { echartValue.setValue(Double.parseDouble(value.getVal())); } return echartValue; @@ -756,12 +773,13 @@ public class RunMonthServiceImpl extends ServiceImpl attribute(int attributeType) { List attributes = new ArrayList<>(); - switch (attributeType){ + switch (attributeType) { case 0: AttributeVo attribute = new AttributeVo(); attribute.setSignage(HomePageConstant.ACTIVE_POWER); @@ -820,6 +838,7 @@ public class RunMonthServiceImpl extends ServiceImpl> emInfos = deivceClient.getEmInfoByDept(Collections.singletonList(station.getRefDept())); - if(!emInfos.isSuccess() || CollectionUtil.isEmpty(emInfos.getData())){ + if (!emInfos.isSuccess() || CollectionUtil.isEmpty(emInfos.getData())) { throw new ServiceException("站点未配置机组设备信息、请先为站点添加设备,绑定设备实例,再进行月报查询!"); } - List devices = emInfos.getData().stream().filter(o->"2".equals(o.getEmType())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(devices)){ + List devices = emInfos.getData().stream().filter(o -> "2".equals(o.getEmType())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(devices)) { throw new ServiceException("站点未配置机组设备信息、请先为站点添加设备,绑定设备实例,再进行月报查询!"); } return true; @@ -844,15 +863,21 @@ public class RunMonthServiceImpl extends ServiceImpllambdaUpdate().set(RunMonthEntity::getEvaluation, text).eq(RunMonthEntity::getId, id)); + } + /** * 手绘运行数据表格 + * * @return */ - private Workbook drawBook(String headerName,RunMonthEntity entity) { + private Workbook drawBook(String headerName, RunMonthEntity entity) { Workbook hssWB = new XSSFWorkbook(); // 添加sheet页 Sheet sheet = hssWB.createSheet(headerName); @@ -863,88 +888,91 @@ public class RunMonthServiceImpl extends ServiceImpl curves = JSONObject.parseObject(data,new TypeReference>(){}); - if(CollectionUtil.isEmpty(curves)){ + List curves = JSONObject.parseObject(data, new TypeReference>() { + }); + if (CollectionUtil.isEmpty(curves)) { // 绘制空表格 - this.emptyRow(hssWB,sheet,rowNumber); + this.emptyRow(hssWB, sheet, rowNumber); CellRangeAddress region = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7); sheet.addMergedRegion(region); return rowNumber + 1; } // 遍历机组 - for(CurveEchartVo device : curves) { + for (CurveEchartVo device : curves) { // 负荷曲线 - rowNumber = this.drawCurve(hssWB,sheet,rowNumber,device.getLoadCurve(),device.getDeviceName() + "_负荷曲线"); + rowNumber = this.drawCurve(hssWB, sheet, rowNumber, device.getLoadCurve(), device.getDeviceName() + "_负荷曲线"); // 轴承温度 - rowNumber = this.drawCurve(hssWB,sheet,rowNumber,device.getBearingTempCurve(),device.getDeviceName() + "_轴承温度曲线"); + rowNumber = this.drawCurve(hssWB, sheet, rowNumber, device.getBearingTempCurve(), device.getDeviceName() + "_轴承温度曲线"); // 定子温度曲线 - rowNumber = this.drawCurve(hssWB,sheet,rowNumber,device.getStatorTempCurve(),device.getDeviceName() + "_定子温度曲线"); + rowNumber = this.drawCurve(hssWB, sheet, rowNumber, device.getStatorTempCurve(), device.getDeviceName() + "_定子温度曲线"); } return rowNumber; } /** * 绘制曲线 + * * @param loadCurve * @param rowNumber */ - private int drawCurve(Workbook hssWB,Sheet sheet,int rowNumber,List loadCurve,String title) { + private int drawCurve(Workbook hssWB, Sheet sheet, int rowNumber, List loadCurve, String title) { // 标题 Row row_1 = sheet.createRow(rowNumber); this.setTitileStyle(hssWB, row_1, 7, false, false, HorizontalAlignment.LEFT); @@ -953,9 +981,9 @@ public class RunMonthServiceImpl extends ServiceImpl xds = DataSources.fromArray(loadCurve.stream().map(EchartVo::getTime).toArray(Number[]::new)); // 曲线条目集合 - List curveYArray = this.curveToArray(loadCurve); + List curveYArray = this.curveToArray(loadCurve); // Y 轴曲线 : 平滑散点值 - for(CurveYArrayVo array : curveYArray){ + for (CurveYArrayVo array : curveYArray) { ChartDataSource yds = DataSources.fromArray(array.getValues()); - LineChartSeries series = lineChartData.addSeries(xds,yds); + LineChartSeries series = lineChartData.addSeries(xds, yds); // 曲线名称 series.setTitle(array.getAttributeName()); } @@ -1000,12 +1028,13 @@ public class RunMonthServiceImpl extends ServiceImpl curveToArray(List curves) { List attrValues = new ArrayList<>(); - curves.forEach(curve-> attrValues.addAll(curve.getValues().stream().map(value->{ + curves.forEach(curve -> attrValues.addAll(curve.getValues().stream().map(value -> { CurveAttrValueVo attrValue = new CurveAttrValueVo(); attrValue.setAttribute(value.getAttribute()); attrValue.setAttributeName(value.getAttributeName()); @@ -1013,7 +1042,7 @@ public class RunMonthServiceImpl extends ServiceImpl{ + return attrValues.stream().collect(Collectors.groupingBy(CurveAttrValueVo::getAttribute)).entrySet().stream().map(entry -> { CurveYArrayVo yArray = new CurveYArrayVo(); yArray.setAttribute(entry.getKey()); yArray.setAttributeName(entry.getValue().get(0).getAttributeName()); @@ -1024,25 +1053,26 @@ public class RunMonthServiceImpl extends ServiceImpl runData = JSONObject.parseObject(data,new TypeReference>(){}); - if(CollectionUtil.isEmpty(runData)){ + List runData = JSONObject.parseObject(data, new TypeReference>() { + }); + if (CollectionUtil.isEmpty(runData)) { // 绘制空表格 - this.emptyRow(hssWB,sheet,rowNumber); + this.emptyRow(hssWB, sheet, rowNumber); CellRangeAddress region = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7); sheet.addMergedRegion(region); return rowNumber + 1; } int row = rowNumber; int endRow = rowNumber + runData.size(); - for (;row < endRow; row ++){ + for (; row < endRow; row++) { // 创建行 Row frow = sheet.createRow(row); - this.setTitileStyle(hssWB, frow, 7, false,false,HorizontalAlignment.CENTER); + this.setTitileStyle(hssWB, frow, 7, false, false, HorizontalAlignment.CENTER); // 组名 Cell frow_cell_1 = frow.getCell(0); frow_cell_1.setCellValue(runData.get(row - rowNumber).getDeviceName()); @@ -1179,7 +1215,7 @@ public class RunMonthServiceImpl extends ServiceImpl 0 && Math.abs(monSumPlan) > 0){ - frow_cell_6.setCellValue(BigDecimal.valueOf(monSumGenerate / monSumPlan * 100L).setScale(2, RoundingMode.HALF_UP).doubleValue() + "%"); - }else{ + if (Math.abs(monSumGenerate) > 0 && Math.abs(monSumPlan) > 0) { + frow_cell_6.setCellValue(BigDecimal.valueOf(monSumGenerate / monSumPlan * 100L).setScale(2, RoundingMode.HALF_UP).doubleValue() + "%"); + } else { frow_cell_6.setCellValue("0%"); } // 年累计发电量 @@ -1202,15 +1238,15 @@ public class RunMonthServiceImpl extends ServiceImpl 0 && Math.abs(yearSumPlan) > 0){ - frow_cell_8.setCellValue(BigDecimal.valueOf(yearSumGenerate / yearSumPlan * 100L).setScale(2, RoundingMode.HALF_UP).doubleValue() + "%"); - }else{ + if (Math.abs(yearSumGenerate) > 0 && Math.abs(yearSumPlan) > 0) { + frow_cell_8.setCellValue(BigDecimal.valueOf(yearSumGenerate / yearSumPlan * 100L).setScale(2, RoundingMode.HALF_UP).doubleValue() + "%"); + } else { frow_cell_8.setCellValue("0%"); } } } // 行合并情况 - if(runData.size() > 1){ + if (runData.size() > 1) { CellRangeAddress region3 = new CellRangeAddress(rowNumber, endRow - 1, (short) 3, (short) 3); CellRangeAddress region4 = new CellRangeAddress(rowNumber, endRow - 1, (short) 4, (short) 4); CellRangeAddress region5 = new CellRangeAddress(rowNumber, endRow - 1, (short) 5, (short) 5); @@ -1227,6 +1263,7 @@ public class RunMonthServiceImpl extends ServiceImpl runAlarm = JSONObject.parseObject(data,new TypeReference>(){}); - if(CollectionUtil.isEmpty(runAlarm)){ + List runAlarm = JSONObject.parseObject(data, new TypeReference>() { + }); + if (CollectionUtil.isEmpty(runAlarm)) { // 绘制空表格 - this.emptyRow(hssWB,sheet,rowNumber); + this.emptyRow(hssWB, sheet, rowNumber); CellRangeAddress region = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 7); sheet.addMergedRegion(region); return rowNumber + 1; } int row = rowNumber; int endRow = rowNumber + runAlarm.size(); - for (;row < endRow ; row ++){ + for (; row < endRow; row++) { // 创建行 Row frow = sheet.createRow(row); - this.setTitileStyle(hssWB, frow, 7, false,false,HorizontalAlignment.CENTER); + this.setTitileStyle(hssWB, frow, 7, false, false, HorizontalAlignment.CENTER); // 组名 Cell frow_cell_1 = frow.getCell(0); frow_cell_1.setCellValue(runAlarm.get(row - rowNumber).getDeviceName()); @@ -1349,8 +1389,8 @@ public class RunMonthServiceImpl extends ServiceImpl