From bc4fde238cad836ec79fee200ff8910bbb384526 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Tue, 28 May 2024 15:06:42 +0800 Subject: [PATCH] =?UTF-8?q?#=E6=B0=B4=E7=94=B5=E7=AB=99=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=9C=88=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../report/controller/RunMonthController.java | 2 +- .../report/service/impl/RunMonthServiceImpl.java | 199 +++++++++------------ 2 files changed, 88 insertions(+), 113 deletions(-) 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 a5872ce..9801a20 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 @@ -28,7 +28,7 @@ public class RunMonthController { @ApiOperation(value = "生成站点月报",notes = "生成站点月报") @ApiOperationSupport(order = 1) public R generate(@RequestParam("mon") String mon, - @RequestParam("stationCode") String stationCode){ + @RequestParam("stationCode") String stationCode){ return R.data(runMonthService.generate(mon,stationCode)); } 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 12eebde..fe5149c 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 @@ -3,6 +3,7 @@ package com.hnac.hzims.operational.report.service.impl; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.hnac.hzims.alarm.config.constants.AlarmConstants; import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant; import com.hnac.hzims.common.logs.utils.StringUtils; @@ -61,6 +62,7 @@ import java.math.RoundingMode; import java.net.URLEncoder; import java.time.LocalDateTime; import java.util.*; +import java.util.concurrent.*; import java.util.stream.Collectors; /** @@ -88,6 +90,9 @@ public class RunMonthServiceImpl extends BaseServiceImpl(1024), new ThreadFactoryBuilder().setNameFormat("generate-run-report-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy()); + /** * 查询站点月报运行数据 * @param mon @@ -101,7 +106,7 @@ public class RunMonthServiceImpl extends BaseServiceImpl stationDevices = devices.stream().filter(device->device.getDepartment().equals(station.getRefDept())).collect(Collectors.toList()); - // 运行数据 - run.setRunData(this.runData(station.getCode(),stationDevices,plans)); + calendar.setTime(DateUtil.parse(mon,"yyyy-MM")); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + calendar.add(Calendar.MONTH,1); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); // 告警数据 - run.setAlarmData(this.alarmData(station.getCode())); - // 月度运行曲线 - run.setCurveData(this.curveData(stationDevices)); + run.setAlarmData(this.alarmData(station.getCode(),start,end)); + CountDownLatch countDownLatch = new CountDownLatch(devices.size()); + List runDatas = new CopyOnWriteArrayList<>(); + List curveEcharts = new CopyOnWriteArrayList<>(); + for (RideDeviceVo device : devices){ + pool.submit(()->{ + // 运行数据 + runDatas.add(this.runData(station.getCode(),device,plans,start,end)); + // 月度运行曲线 + curveEcharts.add(this.curveData(device,start,end)); + }); + countDownLatch.countDown(); + } + //所有模板数据获取完成后释放锁 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + if(CollectionUtil.isEmpty(runDatas)){ + run.setRunData(JSONObject.toJSONString(runDatas)); + } + if(CollectionUtil.isEmpty(curveEcharts)){ + run.setCurveData(JSONObject.toJSONString(curveEcharts)); + } // TODO 运行数据分析 // TODO 运行建议及其他 // 先删除原先月报数据 @@ -238,35 +265,31 @@ public class RunMonthServiceImpl extends BaseServiceImpl devices,List plans) { - List runs = new ArrayList<>(); - devices.forEach(device->{ - RunDataVo run = new RunDataVo(); - run.setDeviceCode(device.getNumber()); - run.setDeviceName(device.getName()); - // 运行时长 - run.setRunHours(this.runHours(device)); - // 月发电量 - Double day = this.generates(0,device.getNumber(),device.getRide()); - if(ObjectUtil.isEmpty(day)){ - run.setGenerate(0.0); - }else{ - run.setGenerate(day/10000); - } - // 年发电量 - Double year = this.generates(1,device.getNumber(),device.getRide()); - if(ObjectUtil.isEmpty(day)){ - run.setGenerateYear(0.0); - }else{ - run.setGenerateYear(year/10000); - } - // 计划发电量 - run.setPlan(this.planGenerate(0,stationCode,plans)/10000); - // 年计划发电量 - run.setPlanYear(this.planGenerate(1,stationCode,plans)/10000); - runs.add(run); - }); - return JSONObject.toJSONString(runs); + 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))); + // 月发电量 + Double day = this.generates(0,device.getNumber(),device.getRide(),start,end); + if(ObjectUtil.isEmpty(day)){ + run.setGenerate(0.0); + }else{ + run.setGenerate(day/10000); + } + // 年发电量 + Double year = this.generates(1,device.getNumber(),device.getRide(),start,end); + if(ObjectUtil.isEmpty(day)){ + run.setGenerateYear(0.0); + }else{ + run.setGenerateYear(year/10000); + } + // 计划发电量 + run.setPlan(this.planGenerate(0,stationCode,plans)/10000); + // 年计划发电量 + run.setPlanYear(this.planGenerate(1,stationCode,plans)/10000); + return run; } /** @@ -276,34 +299,18 @@ public class RunMonthServiceImpl extends BaseServiceImpl alarms = this.hz3000Alarm(code,start,end); - // FIXME 设备实例:一级告警 // FDP智能预警 alarms.addAll(this.intelligentEarly(code,start,end)); return JSONObject.toJSONString(alarms); @@ -503,20 +491,17 @@ public class RunMonthServiceImpl extends BaseServiceImpl devices) { - List curveDatas = devices.stream().map(device -> { - CurveEchartVo curveData = new CurveEchartVo(); - curveData.setDeviceCode(device.getNumber()); - curveData.setDeviceName(device.getName()); - // 负荷曲线 - curveData.setLoadCurve(this.curve(this.attribute(0), device.getNumber())); - // 轴承温度曲线 - curveData.setBearingTempCurve(this.curve(this.attribute(1), device.getNumber())); - // 定子温度曲线 - curveData.setStatorTempCurve(this.curve(this.attribute(2), device.getNumber())); - return curveData; - }).collect(Collectors.toList()); - return JSONObject.toJSONString(curveDatas); + private CurveEchartVo curveData(RideDeviceVo device,String start,String end) { + CurveEchartVo curveData = new CurveEchartVo(); + curveData.setDeviceCode(device.getNumber()); + curveData.setDeviceName(device.getName()); + // 负荷曲线 + curveData.setLoadCurve(this.curve(this.attribute(0),start,end, device.getNumber())); + // 轴承温度曲线 + curveData.setBearingTempCurve(this.curve(this.attribute(1),start,end, device.getNumber())); + // 定子温度曲线 + curveData.setStatorTempCurve(this.curve(this.attribute(2),start,end, device.getNumber())); + return curveData; } /** @@ -527,17 +512,7 @@ public class RunMonthServiceImpl extends BaseServiceImpl curve(List attributes, String deviceCode) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(DateUtil.parse("2024-05-01 00:00:00",DateUtil.PATTERN_DATETIME)); - //calendar.setTime(DateUtil.parse(DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 23:59:59",DateUtil.PATTERN_DATETIME)); - calendar.add(Calendar.DAY_OF_MONTH,-1); - String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - calendar.add(Calendar.MONTH,-1); - 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)); - String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + 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<>();