|
|
|
@ -3,10 +3,40 @@ 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; |
|
|
|
|
import com.hnac.hzims.equipment.entity.EmInfoEntity; |
|
|
|
|
import com.hnac.hzims.equipment.entity.PlanGenerationEntity; |
|
|
|
|
import com.hnac.hzims.equipment.feign.IEmInfoClient; |
|
|
|
|
import com.hnac.hzims.equipment.feign.IPlanGenertionClient; |
|
|
|
|
import com.hnac.hzims.equipment.vo.RideDeviceVo; |
|
|
|
|
import com.hnac.hzims.operational.main.constant.HomePageConstant; |
|
|
|
|
import com.hnac.hzims.operational.main.service.IAnalyseDataService; |
|
|
|
|
import com.hnac.hzims.operational.report.entity.RunMonthEntity; |
|
|
|
|
import com.hnac.hzims.operational.report.mapper.RunMonthMapper; |
|
|
|
|
import com.hnac.hzims.operational.report.service.RunMonthReportService; |
|
|
|
|
import com.hnac.hzims.operational.report.service.RunMonthService; |
|
|
|
|
import com.hnac.hzims.operational.report.vo.*; |
|
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
|
import com.hnac.hzims.operational.station.service.IStationService; |
|
|
|
|
import com.hnac.hzims.operational.station.vo.StationVO; |
|
|
|
|
import com.hnac.hzinfo.datasearch.PointData; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; |
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; |
|
|
|
|
import com.hnac.hzinfo.datasearch.history.IHistoryDataSearchClient; |
|
|
|
|
import com.hnac.hzinfo.datasearch.history.OriginalDataQuery; |
|
|
|
|
import com.hnac.hzinfo.datasearch.soe.ISoeClient; |
|
|
|
|
import com.hnac.hzinfo.datasearch.soe.domian.SoeData; |
|
|
|
|
import com.hnac.hzinfo.datasearch.soe.domian.SoeQueryConditionByStation; |
|
|
|
|
import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; |
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.HzPage; |
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.Result; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.soe.SoeDataClient; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.soe.dto.StbAnalysisDTO; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.soe.vo.StbAnalysisVO; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFFont; |
|
|
|
@ -17,10 +47,9 @@ import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
import org.springblade.core.tool.utils.*; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
@ -31,19 +60,39 @@ import java.io.IOException;
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Comparator; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author ysj |
|
|
|
|
*/ |
|
|
|
|
@SuppressWarnings("ALL") |
|
|
|
|
@Service |
|
|
|
|
@AllArgsConstructor |
|
|
|
|
@Slf4j |
|
|
|
|
public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMonthEntity> implements RunMonthService { |
|
|
|
|
|
|
|
|
|
private final IStationService stationService; |
|
|
|
|
|
|
|
|
|
private final IAnalyseDataService dataService; |
|
|
|
|
|
|
|
|
|
private final RunMonthReportService runMonthReportService; |
|
|
|
|
|
|
|
|
|
private final ISoeClient soeClient; |
|
|
|
|
|
|
|
|
|
private final IEmInfoClient deivceClient; |
|
|
|
|
|
|
|
|
|
private final SoeDataClient soeDataClient; |
|
|
|
|
|
|
|
|
|
private final IPlanGenertionClient planClient; |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
@ -57,23 +106,34 @@ 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); |
|
|
|
|
List<RunDataVo> run = JSONObject.parseObject(entity.getRunData(),new TypeReference<List<RunDataVo>>(){}); |
|
|
|
|
if(CollectionUtil.isEmpty(run)){ |
|
|
|
|
List<RunDataVo> runs = JSONObject.parseObject(entity.getRunData(),new TypeReference<List<RunDataVo>>(){}); |
|
|
|
|
if(CollectionUtil.isEmpty(runs)){ |
|
|
|
|
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.setMonSumPlan(monSumPlan); |
|
|
|
|
if(Math.abs(monSumGenerate) > 0 && Math.abs(monSumPlan) > 0){ |
|
|
|
|
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.setYearSumPlan(yearSumPlan); |
|
|
|
|
if(Math.abs(yearSumGenerate) > 0 && Math.abs(yearSumPlan) > 0){ |
|
|
|
@ -82,7 +142,6 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
|
|
|
|
|
return data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 导出站点月报文件 |
|
|
|
|
* @param mon |
|
|
|
@ -100,6 +159,17 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
|
|
|
|
|
if(ObjectUtil.isEmpty(data)){ |
|
|
|
|
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文件
|
|
|
|
|
// 表头、sheet页、文件名
|
|
|
|
|
String headerName = data.getStationName() + "运行月报(" + mon + ")"; |
|
|
|
@ -124,6 +194,483 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 生成站点月报 |
|
|
|
|
* @param mon |
|
|
|
|
* @param stationCode |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Boolean generate(String mon, String stationCode) { |
|
|
|
|
// 步骤2.查询站点
|
|
|
|
|
StationEntity station = stationService.getOne(Wrappers.<StationEntity>lambdaQuery() |
|
|
|
|
.eq(StationEntity::getDataOrigin, HomePageConstant.DATA_ORIGIN) |
|
|
|
|
.eq(StationEntity::getType,HomePageConstant.HYDROPOWER) |
|
|
|
|
.eq(StationEntity::getCode,stationCode) |
|
|
|
|
); |
|
|
|
|
if(ObjectUtil.isEmpty(station)){ |
|
|
|
|
throw new ServiceException("未查询到站点信息!"); |
|
|
|
|
} |
|
|
|
|
// 查询站点设备
|
|
|
|
|
List<RideDeviceVo> devices = deivceClient.rideDevices(Collections.singletonList(station.getRefDept())); |
|
|
|
|
if(CollectionUtil.isEmpty(devices)){ |
|
|
|
|
throw new ServiceException("站点未配置机组设备信息、请先为站点添加设备,绑定设备实例,再进行月报查询!"); |
|
|
|
|
} |
|
|
|
|
// 计划发电量
|
|
|
|
|
List<PlanGenerationEntity> plans = planClient.getPlanGenerationByParam(Collections.singletonList(stationCode), null , DateUtil.format(new Date(),"yyyy")); |
|
|
|
|
RunMonthEntity run = new RunMonthEntity(); |
|
|
|
|
run.setTenantId(station.getTenantId()); |
|
|
|
|
run.setCreateDept(station.getRefDept()); |
|
|
|
|
run.setCreateUser(station.getCreateUser()); |
|
|
|
|
run.setUpdateUser(station.getUpdateUser()); |
|
|
|
|
run.setStationCode(station.getCode()); |
|
|
|
|
run.setStationName(station.getName()); |
|
|
|
|
run.setMonth(mon); |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
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(),start,end)); |
|
|
|
|
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<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 运行建议及其他
|
|
|
|
|
// 先删除原先月报数据
|
|
|
|
|
this.deleteRunReport(mon,stationCode); |
|
|
|
|
// 保存生成月报数据
|
|
|
|
|
return runMonthReportService.save(run); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 先删除原先月报数据 |
|
|
|
|
* @param mon |
|
|
|
|
* @param stationCode |
|
|
|
|
*/ |
|
|
|
|
private void deleteRunReport(String mon, String stationCode) { |
|
|
|
|
List<RunMonthEntity> runs = runMonthReportService.list(Wrappers.<RunMonthEntity>lambdaQuery() |
|
|
|
|
.eq(RunMonthEntity::getMonth,mon) |
|
|
|
|
.eq(RunMonthEntity::getStationCode,stationCode) |
|
|
|
|
); |
|
|
|
|
if(CollectionUtil.isEmpty(runs)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.runMonthReportService.deleteLogic(runs.stream().map(RunMonthEntity::getId).collect(Collectors.toList())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 运行数据 |
|
|
|
|
* @param devices |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 实际发电量 |
|
|
|
|
* @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)); |
|
|
|
|
} |
|
|
|
|
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)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 计划发电量 |
|
|
|
|
* @param type |
|
|
|
|
* @param stationCode |
|
|
|
|
* @param plans |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private Double planGenerate(int type, String stationCode,List<PlanGenerationEntity> 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.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); |
|
|
|
|
calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); |
|
|
|
|
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"); |
|
|
|
|
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) { |
|
|
|
|
MultiAnalyzeCodePO analyze = new MultiAnalyzeCodePO(); |
|
|
|
|
analyze.setDeviceCode(device.getNumber()); |
|
|
|
|
analyze.setSignages(Collections.singletonList(HomePageConstant.ACTIVE_POWER)); |
|
|
|
|
List<AnalyzeCodeBySignagesVO> signages = dataService.analyzeCodeBySignages(Collections.singletonList(analyze)); |
|
|
|
|
if(CollectionUtil.isEmpty(signages)){ |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
// 监测点
|
|
|
|
|
String realId = signages.get(0).getRealId(); |
|
|
|
|
if(StringUtils.isEmpty(realId)){ |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
return this.getRunConvertData(realId,startDate,endDate); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取时间范围内运行时长 |
|
|
|
|
* @param realId |
|
|
|
|
* @param startDate |
|
|
|
|
* @param endDate |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private Double getRunConvertData(String realId, Date startDate, Date endDate) { |
|
|
|
|
OriginalDataQuery originalDataQuery = new OriginalDataQuery(); |
|
|
|
|
originalDataQuery.setRealId(realId); |
|
|
|
|
originalDataQuery.setBeginTime(startDate); |
|
|
|
|
originalDataQuery.setEndTime(endDate); |
|
|
|
|
originalDataQuery.setLimit(100000); |
|
|
|
|
originalDataQuery.setPage(1); |
|
|
|
|
// 查询时间范围开关机监测点历史数据
|
|
|
|
|
Result<HzPage<PointData>> result = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); |
|
|
|
|
if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData())){ |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
// 开机运行时长
|
|
|
|
|
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<PointData> result,Date startDate,Date endDate) { |
|
|
|
|
if(result.size() == 1){ |
|
|
|
|
// 一直开机
|
|
|
|
|
if(Double.parseDouble(result.get(0).getValue()) > 0){ |
|
|
|
|
return endDate.getTime() - startDate.getTime(); |
|
|
|
|
} |
|
|
|
|
// 一直关机
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
long time=0; |
|
|
|
|
// 遍历累计开机时长
|
|
|
|
|
for(int i = 0; i< result.size() ; i++){ |
|
|
|
|
// 记录为开机状态 就计算到下次关机的时间差
|
|
|
|
|
if(Double.parseDouble(result.get(i).getValue()) <= 0){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
Date endTime,startTime = DateUtil.parse(result.get(i).getTime(), DateUtil.PATTERN_DATETIME); |
|
|
|
|
// 遍历至最后一条数据,累计至当前时间
|
|
|
|
|
if(i == result.size() - 1){ |
|
|
|
|
endTime = endDate; |
|
|
|
|
}else { |
|
|
|
|
endTime = DateUtil.parse(result.get(i+1).getTime(), DateUtil.PATTERN_DATETIME); |
|
|
|
|
} |
|
|
|
|
time += endTime.getTime() - startTime.getTime(); |
|
|
|
|
} |
|
|
|
|
return time; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 告警数据 |
|
|
|
|
* @param code |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private String alarmData(String code,String start,String end) { |
|
|
|
|
// HZ3000:故障告警
|
|
|
|
|
List<RunAlarmVo> alarms = this.hz3000Alarm(code,start,end); |
|
|
|
|
// FDP智能预警
|
|
|
|
|
alarms.addAll(this.intelligentEarly(code,start,end)); |
|
|
|
|
return JSONObject.toJSONString(alarms); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询hz3000告警 |
|
|
|
|
* @param code |
|
|
|
|
*/ |
|
|
|
|
private List<RunAlarmVo> 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.setNeedPage(false); |
|
|
|
|
Result<HzPage<SoeData>> result = soeClient.getByStationsAndTime(query); |
|
|
|
|
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->{ |
|
|
|
|
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.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)); |
|
|
|
|
return alarm; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 智能预警 |
|
|
|
|
* @param code |
|
|
|
|
* @param start |
|
|
|
|
* @param end |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<RunAlarmVo> intelligentEarly(String code, String start, String end) { |
|
|
|
|
StbAnalysisDTO param = new StbAnalysisDTO(); |
|
|
|
|
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<HzPage<StbAnalysisVO>> result = soeDataClient.pageStbAnalysis(param); |
|
|
|
|
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->{ |
|
|
|
|
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()); |
|
|
|
|
alarm.setContent(entry.getKey()); |
|
|
|
|
alarm.setType(String.valueOf(AlarmConstants.EARLY)); |
|
|
|
|
alarm.setTypeName("智能预警"); |
|
|
|
|
alarm.setReason(entry.getValue().get(0).getFinfo()); |
|
|
|
|
alarm.setMemo(entry.getValue().get(0).getInfo()); |
|
|
|
|
alarm.setCount(entry.getValue().size()); |
|
|
|
|
return alarm; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 运行曲线 |
|
|
|
|
* @param devices |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取曲线数据 |
|
|
|
|
* @param attributes |
|
|
|
|
* @param deviceCode |
|
|
|
|
* @return |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
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<>(); |
|
|
|
|
} |
|
|
|
|
List<AnalyseDataTaosVO> analyseDatas = new ArrayList<>(); |
|
|
|
|
Calendar day = Calendar.getInstance(); |
|
|
|
|
datas.forEach(data->{ |
|
|
|
|
if(CollectionUtil.isEmpty(data.getList())){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
analyseDatas.addAll(data.getList().stream().peek(item->{ |
|
|
|
|
item.setSignage(data.getSignage()); |
|
|
|
|
Date date = DateUtil.parse(item.getTs(), "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)){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
Map<String,List<AnalyseDataTaosVO>> 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->{ |
|
|
|
|
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.setValue(0.0); |
|
|
|
|
}else{ |
|
|
|
|
echartValue.setValue(Double.parseDouble(value.getVal())); |
|
|
|
|
} |
|
|
|
|
return echartValue; |
|
|
|
|
}).collect(Collectors.toList())); |
|
|
|
|
return echart; |
|
|
|
|
}).sorted(Comparator.comparing(EchartVo::getTime)).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 曲线属性获取 |
|
|
|
|
* @param attributeType |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<AttributeVo> attribute(int attributeType) { |
|
|
|
|
List<AttributeVo> attributes = new ArrayList<>(); |
|
|
|
|
switch (attributeType){ |
|
|
|
|
case 0: |
|
|
|
|
AttributeVo attribute = new AttributeVo(); |
|
|
|
|
attribute.setSignage(HomePageConstant.ACTIVE_POWER); |
|
|
|
|
attribute.setSignageName("负荷"); |
|
|
|
|
attributes.add(attribute); |
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
|
|
|
|
|
AttributeVo upper_temp = new AttributeVo(); |
|
|
|
|
upper_temp.setSignage(HomePageConstant.UPPER_GUIDE_BEARING_TEMP); |
|
|
|
|
upper_temp.setSignageName("上导轴承瓦温1"); |
|
|
|
|
attributes.add(upper_temp); |
|
|
|
|
AttributeVo oil_tem = new AttributeVo(); |
|
|
|
|
oil_tem.setSignage(HomePageConstant.UPPER_GUIDE_BEARING_OIL_GROOVE_TEMP); |
|
|
|
|
oil_tem.setSignageName("上导轴承油槽温度"); |
|
|
|
|
attributes.add(oil_tem); |
|
|
|
|
AttributeVo thrust_tem = new AttributeVo(); |
|
|
|
|
thrust_tem.setSignage(HomePageConstant.THRUST_BEARING_TEMP); |
|
|
|
|
thrust_tem.setSignageName("推力轴瓦温度1"); |
|
|
|
|
attributes.add(thrust_tem); |
|
|
|
|
AttributeVo lower_tem = new AttributeVo(); |
|
|
|
|
lower_tem.setSignage(HomePageConstant.LOWER_GUIDE_BEARING_TEMP); |
|
|
|
|
lower_tem.setSignageName("下导轴承瓦温1"); |
|
|
|
|
attributes.add(lower_tem); |
|
|
|
|
AttributeVo tank_tem = new AttributeVo(); |
|
|
|
|
tank_tem.setSignage(HomePageConstant.LOWER_GUIDE_OIL_TANK_TEMP); |
|
|
|
|
tank_tem.setSignageName("下导油槽温度"); |
|
|
|
|
attributes.add(tank_tem); |
|
|
|
|
AttributeVo tile_tem = new AttributeVo(); |
|
|
|
|
tile_tem.setSignage(HomePageConstant.WATER_GUIDE_TILE_TEMP); |
|
|
|
|
tile_tem.setSignageName("水导瓦温"); |
|
|
|
|
attributes.add(tile_tem); |
|
|
|
|
AttributeVo water_tem = new AttributeVo(); |
|
|
|
|
water_tem.setSignage(HomePageConstant.WATER_GUIDE_OIL_TANK_TEMP); |
|
|
|
|
water_tem.setSignageName("水导油槽温度"); |
|
|
|
|
attributes.add(water_tem); |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
AttributeVo A_tem = new AttributeVo(); |
|
|
|
|
A_tem.setSignage(HomePageConstant.A_PHASE_IRON_CORE_TEMP); |
|
|
|
|
A_tem.setSignageName("A相铁芯温度1"); |
|
|
|
|
attributes.add(A_tem); |
|
|
|
|
|
|
|
|
|
AttributeVo B_tem = new AttributeVo(); |
|
|
|
|
B_tem.setSignage(HomePageConstant.B_PHASE_IRON_CORE_TEMP); |
|
|
|
|
B_tem.setSignageName("B相铁芯温度1"); |
|
|
|
|
attributes.add(B_tem); |
|
|
|
|
|
|
|
|
|
AttributeVo C_tem = new AttributeVo(); |
|
|
|
|
C_tem.setSignage(HomePageConstant.C_PHASE_IRON_CORE_TEMP); |
|
|
|
|
C_tem.setSignageName("C相铁芯温度1"); |
|
|
|
|
attributes.add(C_tem); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
return attributes; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 检查站点是否存在设备信息 |
|
|
|
|
* @param stationCode |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Boolean check(String stationCode) { |
|
|
|
|
// 查询站点
|
|
|
|
|
StationVO station = stationService.getStationByCode(stationCode); |
|
|
|
|
if(ObjectUtil.isEmpty(station)){ |
|
|
|
|
throw new ServiceException("未查询到站点信息!"); |
|
|
|
|
} |
|
|
|
|
// 查询设备
|
|
|
|
|
R<List<EmInfoEntity>> emInfos = deivceClient.getEmInfoByDept(Collections.singletonList(station.getRefDept())); |
|
|
|
|
if(!emInfos.isSuccess() || CollectionUtil.isEmpty(emInfos.getData())){ |
|
|
|
|
throw new ServiceException("站点未配置机组设备信息、请先为站点添加设备,绑定设备实例,再进行月报查询!"); |
|
|
|
|
} |
|
|
|
|
List<EmInfoEntity> devices = emInfos.getData().stream().filter(o->"2".equals(o.getEmType())).collect(Collectors.toList()); |
|
|
|
|
if(CollectionUtil.isEmpty(devices)){ |
|
|
|
|
throw new ServiceException("站点未配置机组设备信息、请先为站点添加设备,绑定设备实例,再进行月报查询!"); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 手绘运行数据表格 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
@ -280,16 +827,14 @@ public class RunMonthServiceImpl extends BaseServiceImpl<RunMonthMapper, RunMont
|
|
|
|
|
*/ |
|
|
|
|
private List<CurveYArrayVo> curveToArray(List<EchartVo> curves) { |
|
|
|
|
List<CurveAttrValueVo> attrValues = new ArrayList<>(); |
|
|
|
|
curves.forEach(curve->{ |
|
|
|
|
attrValues.addAll(curve.getValues().stream().map(value->{ |
|
|
|
|
CurveAttrValueVo attrValue = new CurveAttrValueVo(); |
|
|
|
|
attrValue.setAttribute(value.getAttribute()); |
|
|
|
|
attrValue.setAttributeName(value.getAttributeName()); |
|
|
|
|
attrValue.setTime(curve.getTime()); |
|
|
|
|
attrValue.setValue(value.getValue()); |
|
|
|
|
return attrValue; |
|
|
|
|
}).collect(Collectors.toList())); |
|
|
|
|
}); |
|
|
|
|
curves.forEach(curve-> attrValues.addAll(curve.getValues().stream().map(value->{ |
|
|
|
|
CurveAttrValueVo attrValue = new CurveAttrValueVo(); |
|
|
|
|
attrValue.setAttribute(value.getAttribute()); |
|
|
|
|
attrValue.setAttributeName(value.getAttributeName()); |
|
|
|
|
attrValue.setTime(curve.getTime()); |
|
|
|
|
attrValue.setValue(value.getValue()); |
|
|
|
|
return attrValue; |
|
|
|
|
}).collect(Collectors.toList()))); |
|
|
|
|
return attrValues.stream().collect(Collectors.groupingBy(CurveAttrValueVo::getAttribute)).entrySet().stream().map(entry->{ |
|
|
|
|
CurveYArrayVo yArray = new CurveYArrayVo(); |
|
|
|
|
yArray.setAttribute(entry.getKey()); |
|
|
|
|