|
|
@ -1,12 +1,16 @@ |
|
|
|
package com.hnac.hzims.operational.report.service.impl; |
|
|
|
package com.hnac.hzims.operational.report.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.google.common.util.concurrent.ThreadFactoryBuilder; |
|
|
|
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.bigmodel.api.feign.IDataAnalyseClient; |
|
|
|
|
|
|
|
import com.hnac.hzims.bigmodel.business.dto.*; |
|
|
|
import com.hnac.hzims.common.logs.utils.StringUtils; |
|
|
|
import com.hnac.hzims.common.logs.utils.StringUtils; |
|
|
|
import com.hnac.hzims.equipment.entity.EmInfoEntity; |
|
|
|
import com.hnac.hzims.equipment.entity.EmInfoEntity; |
|
|
|
import com.hnac.hzims.equipment.entity.PlanGenerationEntity; |
|
|
|
import com.hnac.hzims.equipment.entity.PlanGenerationEntity; |
|
|
@ -40,6 +44,7 @@ import com.hnac.hzinfo.sdk.v5.soe.dto.StbAnalysisDTO; |
|
|
|
import com.hnac.hzinfo.sdk.v5.soe.vo.StbAnalysisVO; |
|
|
|
import com.hnac.hzinfo.sdk.v5.soe.vo.StbAnalysisVO; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFFont; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFFont; |
|
|
|
import org.apache.poi.hssf.util.HSSFColor; |
|
|
|
import org.apache.poi.hssf.util.HSSFColor; |
|
|
|
import org.apache.poi.ss.usermodel.*; |
|
|
|
import org.apache.poi.ss.usermodel.*; |
|
|
@ -61,6 +66,7 @@ import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
|
|
import java.time.YearMonth; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.LinkedBlockingQueue; |
|
|
|
import java.util.concurrent.LinkedBlockingQueue; |
|
|
@ -93,6 +99,8 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt |
|
|
|
|
|
|
|
|
|
|
|
private final IHistoryDataSearchClient historyDataSearchClient; |
|
|
|
private final IHistoryDataSearchClient historyDataSearchClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final IDataAnalyseClient dataAnalyseClient; |
|
|
|
|
|
|
|
|
|
|
|
// 创建线程池
|
|
|
|
// 创建线程池
|
|
|
|
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()); |
|
|
|
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()); |
|
|
|
|
|
|
|
|
|
|
@ -145,6 +153,8 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt |
|
|
|
return data; |
|
|
|
return data; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 导出站点月报文件 |
|
|
|
* 导出站点月报文件 |
|
|
|
* @param mon |
|
|
|
* @param mon |
|
|
@ -273,7 +283,121 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt |
|
|
|
// 先删除原先月报数据
|
|
|
|
// 先删除原先月报数据
|
|
|
|
this.deleteRunReport(mon,stationCode); |
|
|
|
this.deleteRunReport(mon,stationCode); |
|
|
|
// 保存生成月报数据
|
|
|
|
// 保存生成月报数据
|
|
|
|
return runMonthReportService.save(run); |
|
|
|
boolean save = runMonthReportService.save(run); |
|
|
|
|
|
|
|
// 调用大模型分析月报接口 结果通过mqtt获取
|
|
|
|
|
|
|
|
this.smartReportGeneratePower(mon,stationCode); |
|
|
|
|
|
|
|
return save; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 调用大模型分析月报接口 |
|
|
|
|
|
|
|
* @param mon 月报月份 |
|
|
|
|
|
|
|
* @param stationCode 月报站号 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void smartReportGeneratePower(String mon,String stationCode) { |
|
|
|
|
|
|
|
List<RunReportDataAnalyseDTO> analyseVOList = Lists.newArrayList(); |
|
|
|
|
|
|
|
YearMonth yearMonth = YearMonth.parse(mon); |
|
|
|
|
|
|
|
List<YearMonth> months = Lists.newArrayList(yearMonth, yearMonth.minusMonths(1), yearMonth.minusYears(1)); |
|
|
|
|
|
|
|
months.stream().map(YearMonth::toString).map(m ->{ |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
return this.data(m,stationCode); |
|
|
|
|
|
|
|
} catch(Exception e) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}).filter(Func::isNotEmpty).forEach(d -> this.fillAnalyseData(d,analyseVOList,mon)); |
|
|
|
|
|
|
|
// 过滤掉发电量为空的数据
|
|
|
|
|
|
|
|
analyseVOList.forEach(analyseVO -> { |
|
|
|
|
|
|
|
List<PowerDataDTO> power = analyseVO.getPower(); |
|
|
|
|
|
|
|
analyseVO.setPower(power.stream().filter(p -> Func.isNotEmpty(p.getValue())).collect(Collectors.toList())); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
RunReportAnalyseRequest analyseRequest = new RunReportAnalyseRequest(); |
|
|
|
|
|
|
|
analyseRequest.setMonth(mon); |
|
|
|
|
|
|
|
analyseRequest.setStationCode(stationCode); |
|
|
|
|
|
|
|
analyseRequest.setAnalyseDTOS(analyseVOList); |
|
|
|
|
|
|
|
dataAnalyseClient.smartReportGeneratePower(analyseRequest); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 填充大模型分析所需数据格式 |
|
|
|
|
|
|
|
* @param req 月报数据 |
|
|
|
|
|
|
|
* @param analyseVOList 大模型分析对象 |
|
|
|
|
|
|
|
* @param month 查询月报筛选条件 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void fillAnalyseData(RunMonthEntity req, List<RunReportDataAnalyseDTO> analyseVOList, String month) { |
|
|
|
|
|
|
|
if(Func.isNotEmpty(req)) { |
|
|
|
|
|
|
|
// 解析运行月报数据 - 运行数据、告警数据
|
|
|
|
|
|
|
|
List<RunDataVo> rundatas = JSONArray.parseArray(req.getRunData(), RunDataVo.class); |
|
|
|
|
|
|
|
List<RunAlarmVo> alarms = JSONArray.parseArray(req.getAlarmData(),RunAlarmVo.class); |
|
|
|
|
|
|
|
// 取运行、告警设备设备并集
|
|
|
|
|
|
|
|
List<String> runDatas = rundatas.stream().map(RunDataVo::getDeviceName).distinct().collect(Collectors.toList()); |
|
|
|
|
|
|
|
List<String> alarmDatas = alarms.stream().map(RunAlarmVo::getDeviceName).distinct().collect(Collectors.toList()); |
|
|
|
|
|
|
|
Collection<String> unionDeviceNames = CollectionUtils.union(runDatas, alarmDatas); |
|
|
|
|
|
|
|
unionDeviceNames.forEach(deviceName -> { |
|
|
|
|
|
|
|
Optional<RunReportDataAnalyseDTO> exist = analyseVOList.stream().filter(vo -> deviceName.equals(vo.getEmName())).findFirst(); |
|
|
|
|
|
|
|
if(!exist.isPresent()) { |
|
|
|
|
|
|
|
// 若该设备未新增接受数据对象,则新增之后填充数据
|
|
|
|
|
|
|
|
RunReportDataAnalyseDTO analyseVO = this.createDeviceAnalyse(deviceName, month); |
|
|
|
|
|
|
|
analyseVOList.add(analyseVO); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.fillDeviceAnalyse(deviceName,req.getMonth(),rundatas,alarms,analyseVOList); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 创建大模型分析所需对象 |
|
|
|
|
|
|
|
* @param deviceName 设备名称 |
|
|
|
|
|
|
|
* @param month 对象月份 |
|
|
|
|
|
|
|
* @return 大模型分析所需对象 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private RunReportDataAnalyseDTO createDeviceAnalyse(String deviceName, String month) { |
|
|
|
|
|
|
|
RunReportDataAnalyseDTO analyseVO = new RunReportDataAnalyseDTO(); |
|
|
|
|
|
|
|
analyseVO.setEmName(deviceName); |
|
|
|
|
|
|
|
YearMonth yearMonth = YearMonth.parse(month); |
|
|
|
|
|
|
|
List<PowerDataDTO> powerDataDTOS = Lists.newArrayList(); |
|
|
|
|
|
|
|
List<RunTimeDataDTO> runTimeDataDTOS = Lists.newArrayList(); |
|
|
|
|
|
|
|
List<SoeDataDTO> soeDataDTOS = Lists.newArrayList(); |
|
|
|
|
|
|
|
List<YearMonth> months = Lists.newArrayList(yearMonth, yearMonth.minusMonths(1), yearMonth.minusYears(1)); |
|
|
|
|
|
|
|
months.stream().map(YearMonth::toString).forEach(m -> { |
|
|
|
|
|
|
|
PowerDataDTO powerDataDTO = new PowerDataDTO(); |
|
|
|
|
|
|
|
powerDataDTO.setDate(m); |
|
|
|
|
|
|
|
powerDataDTOS.add(powerDataDTO); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
analyseVO.setPower(powerDataDTOS); |
|
|
|
|
|
|
|
analyseVO.setSoe(soeDataDTOS); |
|
|
|
|
|
|
|
return analyseVO; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 填充大模型分析所需参数 |
|
|
|
|
|
|
|
* @param deviceName 设备名称 |
|
|
|
|
|
|
|
* @param month 月报数据月份 |
|
|
|
|
|
|
|
* @param rundatas 月报运行数据 |
|
|
|
|
|
|
|
* @param alarms 月报告警报表数据 |
|
|
|
|
|
|
|
* @param analyseVOList 待填充的设备分析传参对象 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void fillDeviceAnalyse(String deviceName,String month,List<RunDataVo> rundatas,List<RunAlarmVo> alarms,List<RunReportDataAnalyseDTO> analyseVOList) { |
|
|
|
|
|
|
|
Optional<RunDataVo> runDataVo = rundatas.stream().filter(d -> deviceName.equals(d.getDeviceName())).findFirst(); |
|
|
|
|
|
|
|
List<SoeDataDTO> soeDataDTOS = alarms.stream().filter(a -> deviceName.equals(a.getDeviceName())).map(alarm -> { |
|
|
|
|
|
|
|
SoeDataDTO soeDataDTO = new SoeDataDTO(); |
|
|
|
|
|
|
|
soeDataDTO.setDate(month); |
|
|
|
|
|
|
|
soeDataDTO.setName(alarm.getContent()); |
|
|
|
|
|
|
|
soeDataDTO.setTimes(alarm.getCount()); |
|
|
|
|
|
|
|
return soeDataDTO; |
|
|
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
RunReportDataAnalyseDTO analyseVO = analyseVOList.stream().filter(vo -> deviceName.equals(vo.getEmName())).findFirst().get(); |
|
|
|
|
|
|
|
if(runDataVo.isPresent()) { |
|
|
|
|
|
|
|
// 补充发电量、运行时长
|
|
|
|
|
|
|
|
Optional<PowerDataDTO> powerData = analyseVO.getPower().stream().filter(p -> month.equals(p.getDate())).findFirst(); |
|
|
|
|
|
|
|
if(powerData.isPresent()) { |
|
|
|
|
|
|
|
powerData.get().setValue(runDataVo.get().getGenerate()); |
|
|
|
|
|
|
|
powerData.get().setRunTime(runDataVo.get().getRunHours()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(Func.isNotEmpty(soeDataDTOS)) { |
|
|
|
|
|
|
|
// 补充告警
|
|
|
|
|
|
|
|
analyseVO.getSoe().addAll(soeDataDTOS); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|