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 = "生成站点月报")
@ApiOperationSupport(order = 1)
public R<Boolean> generate(@RequestParam("mon") String mon,
@RequestParam("stationCode") String stationCode){
@RequestParam("stationCode") String 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.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<RunMonthMapper, RunMont
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
@ -101,7 +106,7 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
.eq(RunMonthEntity::getMonth,mon)
);
if(ObjectUtil.isEmpty(entity)){
throw new ServiceException("站点" + mon + "月份未生成运行月报,请联系管理员进行处理!");
throw new ServiceException("站点" + mon + "月份未生成运行月报,请先点击【生成】按钮生成月报!");
}
RunDataShowVo data = new RunDataShowVo();
BeanUtil.copyProperties(entity,data);
@ -198,17 +203,39 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
run.setUpdateUser(station.getUpdateUser());
run.setStationCode(station.getCode());
run.setStationName(station.getName());
run.setMonth(mon);
Calendar calendar = Calendar.getInstance();
calendar.setTime(DateUtil.parse("2024-05-01 00:00:00", org.springblade.core.tool.utils.DateUtil.PATTERN_DATETIME));
calendar.add(Calendar.DAY_OF_MONTH,-1);
run.setMonth(DateUtil.format(calendar.getTime(),"yyyy-MM"));
List<RideDeviceVo> 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<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 运行建议及其他
// 先删除原先月报数据
@ -238,35 +265,31 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param devices
* @return
*/
private String runData(String stationCode,List<RideDeviceVo> devices,List<PlanGenerationEntity> plans) {
List<RunDataVo> 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<PlanGenerationEntity> 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<RunMonthMapper, RunMont
* @param ride
* @return
*/
private Double generates(int type,String deviceCode,double ride) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(DateUtil.parse("2024-05-01 00:00:00",DateUtil.PATTERN_DATETIME));
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;
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));
}
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
* @return
*/
private Double runHours(EmInfoEntity device) {
private Double runHours(RideDeviceVo device,Date startDate,Date endDate) {
MultiAnalyzeCodePO analyze = new MultiAnalyzeCodePO();
analyze.setDeviceCode(device.getNumber());
analyze.setSignages(Collections.singletonList(HomePageConstant.ACTIVE_POWER));
@ -348,14 +355,6 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
if(StringUtils.isEmpty(realId)){
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);
}
@ -421,20 +420,9 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
* @param code
* @return
*/
private String alarmData(String code) {
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);
private String alarmData(String code,String start,String end) {
// HZ3000:故障告警
List<RunAlarmVo> 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<RunMonthMapper, RunMont
* @param devices
* @return
*/
private String curveData(List<RideDeviceVo> devices) {
List<CurveEchartVo> 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<RunMonthMapper, RunMont
*
*
*/
private List<EchartVo> curve(List<AttributeVo> 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<EchartVo> curve(List<AttributeVo> attributes,String start,String end, String deviceCode) {
List<AnalyzeDataConditionVO> datas = dataService.periodTargetSignages(start,end,3,3,deviceCode,attributes.stream().map(AttributeVo::getSignage).collect(Collectors.toList()));
if(CollectionUtil.isEmpty(datas)){
return new ArrayList<>();

Loading…
Cancel
Save