Browse Source

#水电站运行月报

zhongwei
yang_shj 6 months ago
parent
commit
bc4fde238c
  1. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java
  2. 199
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java

@ -28,7 +28,7 @@ public class RunMonthController {
@ApiOperation(value = "生成站点月报",notes = "生成站点月报") @ApiOperation(value = "生成站点月报",notes = "生成站点月报")
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
public R<Boolean> generate(@RequestParam("mon") String mon, public R<Boolean> generate(@RequestParam("mon") String mon,
@RequestParam("stationCode") String stationCode){ @RequestParam("stationCode") String stationCode){
return R.data(runMonthService.generate(mon,stationCode)); return R.data(runMonthService.generate(mon,stationCode));
} }

199
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.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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.AlarmConstants;
import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant; import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant;
import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.common.logs.utils.StringUtils;
@ -61,6 +62,7 @@ import java.math.RoundingMode;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -88,6 +90,9 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
private final IHistoryDataSearchClient historyDataSearchClient; private final IHistoryDataSearchClient historyDataSearchClient;
// 创建线程池
private static final ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("generate-run-report-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy());
/** /**
* 查询站点月报运行数据 * 查询站点月报运行数据
* @param mon * @param mon
@ -101,7 +106,7 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
.eq(RunMonthEntity::getMonth,mon) .eq(RunMonthEntity::getMonth,mon)
); );
if(ObjectUtil.isEmpty(entity)){ if(ObjectUtil.isEmpty(entity)){
throw new ServiceException("站点" + mon + "月份未生成运行月报,请联系管理员进行处理!"); throw new ServiceException("站点" + mon + "月份未生成运行月报,请先点击【生成】按钮生成月报!");
} }
RunDataShowVo data = new RunDataShowVo(); RunDataShowVo data = new RunDataShowVo();
BeanUtil.copyProperties(entity,data); BeanUtil.copyProperties(entity,data);
@ -198,17 +203,39 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
run.setUpdateUser(station.getUpdateUser()); run.setUpdateUser(station.getUpdateUser());
run.setStationCode(station.getCode()); run.setStationCode(station.getCode());
run.setStationName(station.getName()); run.setStationName(station.getName());
run.setMonth(mon);
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(DateUtil.parse("2024-05-01 00:00:00", org.springblade.core.tool.utils.DateUtil.PATTERN_DATETIME)); calendar.setTime(DateUtil.parse(mon,"yyyy-MM"));
calendar.add(Calendar.DAY_OF_MONTH,-1); String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME);
run.setMonth(DateUtil.format(calendar.getTime(),"yyyy-MM")); calendar.add(Calendar.MONTH,1);
List<RideDeviceVo> stationDevices = devices.stream().filter(device->device.getDepartment().equals(station.getRefDept())).collect(Collectors.toList()); String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME);
// 运行数据
run.setRunData(this.runData(station.getCode(),stationDevices,plans));
// 告警数据 // 告警数据
run.setAlarmData(this.alarmData(station.getCode())); run.setAlarmData(this.alarmData(station.getCode(),start,end));
// 月度运行曲线 CountDownLatch countDownLatch = new CountDownLatch(devices.size());
run.setCurveData(this.curveData(stationDevices)); List<RunDataVo> runDatas = new CopyOnWriteArrayList<>();
List<CurveEchartVo> 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 运行数据分析
// TODO 运行建议及其他 // TODO 运行建议及其他
// 先删除原先月报数据 // 先删除原先月报数据
@ -238,35 +265,31 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param devices * @param devices
* @return * @return
*/ */
private String runData(String stationCode,List<RideDeviceVo> devices,List<PlanGenerationEntity> plans) { private RunDataVo runData(String stationCode,RideDeviceVo device,List<PlanGenerationEntity> plans,String start,String end) {
List<RunDataVo> runs = new ArrayList<>(); RunDataVo run = new RunDataVo();
devices.forEach(device->{ run.setDeviceCode(device.getNumber());
RunDataVo run = new RunDataVo(); run.setDeviceName(device.getName());
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)); Double day = this.generates(0,device.getNumber(),device.getRide(),start,end);
// 月发电量 if(ObjectUtil.isEmpty(day)){
Double day = this.generates(0,device.getNumber(),device.getRide()); run.setGenerate(0.0);
if(ObjectUtil.isEmpty(day)){ }else{
run.setGenerate(0.0); 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()); run.setGenerateYear(0.0);
if(ObjectUtil.isEmpty(day)){ }else{
run.setGenerateYear(0.0); 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);
// 年计划发电量 return run;
run.setPlanYear(this.planGenerate(1,stationCode,plans)/10000);
runs.add(run);
});
return JSONObject.toJSONString(runs);
} }
/** /**
@ -276,34 +299,18 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param ride * @param ride
* @return * @return
*/ */
private Double generates(int type,String deviceCode,double ride) { private Double generates(int type,String deviceCode,double ride,String start,String end) {
Calendar calendar = Calendar.getInstance(); if(type == 0){
calendar.setTime(DateUtil.parse("2024-05-01 00:00:00",DateUtil.PATTERN_DATETIME)); return Double.valueOf(dataService.periodTargetFloat(start,end,5,5,deviceCode,ride,HomePageConstant.HYDROPOWER_GENERATE_POWER));
String end = null,start = null;
int cycleType = 5;
switch (type){
case 0 :
calendar.add(Calendar.DAY_OF_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));
end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME);
calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1);
start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME);
break;
case 1 :
cycleType = 6;
end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME);
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);
start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME);
break;
} }
return Double.valueOf(dataService.periodTargetFloat(start,end,5,cycleType,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.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));
} }
/** /**
@ -335,7 +342,7 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param device * @param device
* @return * @return
*/ */
private Double runHours(EmInfoEntity device) { private Double runHours(RideDeviceVo device,Date startDate,Date endDate) {
MultiAnalyzeCodePO analyze = new MultiAnalyzeCodePO(); MultiAnalyzeCodePO analyze = new MultiAnalyzeCodePO();
analyze.setDeviceCode(device.getNumber()); analyze.setDeviceCode(device.getNumber());
analyze.setSignages(Collections.singletonList(HomePageConstant.ACTIVE_POWER)); analyze.setSignages(Collections.singletonList(HomePageConstant.ACTIVE_POWER));
@ -348,14 +355,6 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
if(StringUtils.isEmpty(realId)){ if(StringUtils.isEmpty(realId)){
return 0.0; return 0.0;
} }
// 确定查询时间范围: 年、月
Date startDate,endDate;
Calendar calendar = Calendar.getInstance();
calendar.setTime(DateUtil.parse("2024-05-01 00:00:00",DateUtil.PATTERN_DATETIME));
endDate = calendar.getTime();
calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH));
calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1);
startDate = calendar.getTime();
return this.getRunConvertData(realId,startDate,endDate); return this.getRunConvertData(realId,startDate,endDate);
} }
@ -421,20 +420,9 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param code * @param code
* @return * @return
*/ */
private String alarmData(String code) { private String alarmData(String code,String start,String end) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(DateUtil.parse("2024-05-01 00:00:00",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.DAY_OF_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);
// HZ3000:故障告警 // HZ3000:故障告警
List<RunAlarmVo> alarms = this.hz3000Alarm(code,start,end); List<RunAlarmVo> alarms = this.hz3000Alarm(code,start,end);
// FIXME 设备实例:一级告警
// FDP智能预警 // FDP智能预警
alarms.addAll(this.intelligentEarly(code,start,end)); alarms.addAll(this.intelligentEarly(code,start,end));
return JSONObject.toJSONString(alarms); return JSONObject.toJSONString(alarms);
@ -503,20 +491,17 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param devices * @param devices
* @return * @return
*/ */
private String curveData(List<RideDeviceVo> devices) { private CurveEchartVo curveData(RideDeviceVo device,String start,String end) {
List<CurveEchartVo> curveDatas = devices.stream().map(device -> { CurveEchartVo curveData = new CurveEchartVo();
CurveEchartVo curveData = new CurveEchartVo(); curveData.setDeviceCode(device.getNumber());
curveData.setDeviceCode(device.getNumber()); curveData.setDeviceName(device.getName());
curveData.setDeviceName(device.getName()); // 负荷曲线
// 负荷曲线 curveData.setLoadCurve(this.curve(this.attribute(0),start,end, device.getNumber()));
curveData.setLoadCurve(this.curve(this.attribute(0), device.getNumber())); // 轴承温度曲线
// 轴承温度曲线 curveData.setBearingTempCurve(this.curve(this.attribute(1),start,end, device.getNumber()));
curveData.setBearingTempCurve(this.curve(this.attribute(1), device.getNumber())); // 定子温度曲线
// 定子温度曲线 curveData.setStatorTempCurve(this.curve(this.attribute(2),start,end, device.getNumber()));
curveData.setStatorTempCurve(this.curve(this.attribute(2), device.getNumber())); return curveData;
return curveData;
}).collect(Collectors.toList());
return JSONObject.toJSONString(curveDatas);
} }
/** /**
@ -527,17 +512,7 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* *
* *
*/ */
private List<EchartVo> curve(List<AttributeVo> attributes, String deviceCode) { private List<EchartVo> curve(List<AttributeVo> attributes,String start,String end, 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);
List<AnalyzeDataConditionVO> datas = dataService.periodTargetSignages(start,end,3,3,deviceCode,attributes.stream().map(AttributeVo::getSignage).collect(Collectors.toList())); List<AnalyzeDataConditionVO> datas = dataService.periodTargetSignages(start,end,3,3,deviceCode,attributes.stream().map(AttributeVo::getSignage).collect(Collectors.toList()));
if(CollectionUtil.isEmpty(datas)){ if(CollectionUtil.isEmpty(datas)){
return new ArrayList<>(); return new ArrayList<>();

Loading…
Cancel
Save