Browse Source

add: 格式化机组名称

zhongwei
haungxing 3 months ago
parent
commit
d23a74b14c
  1. 11
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunReportDataAnalyseDTO.java
  2. 9
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java
  3. 8
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java
  4. 117
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java
  5. 44
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/utils/SetNameFormatterUtil.java

11
hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunReportDataAnalyseDTO.java

@ -17,17 +17,18 @@ import java.util.List;
public class RunReportDataAnalyseDTO implements Serializable {
/**
* 设备编号
*/
private String emCode;
/**
* 设备名称
*/
@JSONField(name = "name")
private String emName;
/**
* 机组序号
*/
@JSONField(serialize = false)
private Integer deviceOrder;
/**
* 发电量数据
*/
private List<PowerDataDTO> power;

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

@ -5,6 +5,7 @@ import com.hnac.hzims.operational.report.entity.RunMonthEntity;
import com.hnac.hzims.operational.report.service.RunMonthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.GetMapping;
@ -54,4 +55,12 @@ public class RunMonthController {
@RequestParam("stationCode") String stationCode){
runMonthService.export(mon,stationCode);
}
@GetMapping("/generateAnalyseResult")
@ApiOperation(value = "生成分析结果",notes = "生成分析结果")
@ApiOperationSupport(order = 5)
public R generateAnalyseResult(@RequestParam @ApiParam("查询月份") String month, @RequestParam @ApiParam("站点编号") String stationCode) {
runMonthService.generateAnalyseResult(month,stationCode);
return R.success("调用成功!");
}
}

8
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java

@ -16,4 +16,12 @@ public interface RunMonthService extends IService<RunMonthEntity> {
Boolean generate(String mon, String stationCode);
Boolean check(String stationCode);
/**
* 生成分析结果
* @param month 月份
* @param stationCode 站点编号
* @return 大模型调用结果
*/
Boolean generateAnalyseResult(String month,String stationCode);
}

117
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java

@ -23,6 +23,7 @@ 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.utils.SetNameFormatterUtil;
import com.hnac.hzims.operational.report.vo.*;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.service.IStationService;
@ -285,7 +286,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
// 保存生成月报数据
boolean save = runMonthReportService.save(run);
// 调用大模型分析月报接口 结果通过mqtt获取
this.smartReportGeneratePower(mon,stationCode);
new Thread(() -> this.smartReportGeneratePower(mon,stationCode),"运行月报分析结论").start();
return save;
}
@ -313,7 +314,12 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
RunReportAnalyseRequest analyseRequest = new RunReportAnalyseRequest();
analyseRequest.setMonth(mon);
analyseRequest.setStationCode(stationCode);
analyseRequest.setAnalyseDTOS(analyseVOList);
// 将设备名称拼接位标准格式
List<RunReportDataAnalyseDTO> analyseDTOList = analyseVOList.stream()
.sorted(Comparator.comparing(RunReportDataAnalyseDTO::getDeviceOrder))
.peek(a -> a.setEmName(a.getDeviceOrder() + "#机组"))
.collect(Collectors.toList());
analyseRequest.setAnalyseDTOS(analyseDTOList);
dataAnalyseClient.smartReportGeneratePower(analyseRequest);
}
@ -332,14 +338,43 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
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();
Integer deviceOrder = SetNameFormatterUtil.getSetOrder(deviceName);
if(Func.isNotEmpty(deviceOrder)) {
String formateDevice = deviceOrder + "#机组";
Optional<RunReportDataAnalyseDTO> exist = analyseVOList.stream().filter(a -> formateDevice.equals(a.getEmName())).findFirst();
if(!exist.isPresent()) {
// 若该设备未新增接受数据对象,则新增之后填充数据
RunReportDataAnalyseDTO analyseVO = this.createDeviceAnalyse(deviceName, month);
RunReportDataAnalyseDTO analyseVO = this.createDeviceAnalyse(formateDevice, month, deviceOrder);
analyseVOList.add(analyseVO);
}
this.fillDeviceAnalyse(deviceName,req.getMonth(),rundatas,alarms,analyseVOList);
List<RunDataVo> runDataVos = rundatas.stream().filter(data -> deviceName.equals(data.getDeviceName())).collect(Collectors.toList());
Double power = runDataVos.stream().collect(Collectors.summingDouble(RunDataVo::getGenerate));
Double runHours = runDataVos.stream().collect(Collectors.summingDouble(RunDataVo::getRunHours));
RunReportDataAnalyseDTO analyseDTO = analyseVOList.stream().filter(a -> formateDevice.equals(a.getEmName())).findFirst().get();
PowerDataDTO powerDataDTO = analyseDTO.getPower().stream().filter(p -> req.getMonth().equals(p.getDate())).findFirst().get();
// 发电量赋值
if(Func.isNotEmpty(powerDataDTO)) {
if(Func.isNotEmpty(power)) {
powerDataDTO.setValue(Optional.ofNullable(powerDataDTO.getValue()).orElse(0.0) + power);
}
if(Func.isNotEmpty(runHours)) {
powerDataDTO.setRunTime(Optional.ofNullable(powerDataDTO.getRunTime()).orElse(0.0) + runHours);
}
}
// 告警信息
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());
if(CollectionUtil.isNotEmpty(soeDataDTOS)) {
analyseDTO.getSoe().addAll(soeDataDTOS);
}
}
});
}
}
@ -348,11 +383,13 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
* 创建大模型分析所需对象
* @param deviceName 设备名称
* @param month 对象月份
* @param deviceOrder 设备序号
* @return 大模型分析所需对象
*/
private RunReportDataAnalyseDTO createDeviceAnalyse(String deviceName, String month) {
private RunReportDataAnalyseDTO createDeviceAnalyse(String deviceName, String month, Integer deviceOrder) {
RunReportDataAnalyseDTO analyseVO = new RunReportDataAnalyseDTO();
analyseVO.setEmName(deviceName);
analyseVO.setDeviceOrder(deviceOrder);
YearMonth yearMonth = YearMonth.parse(month);
List<PowerDataDTO> powerDataDTOS = Lists.newArrayList();
List<RunTimeDataDTO> runTimeDataDTOS = Lists.newArrayList();
@ -368,37 +405,37 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
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);
}
}
// /**
// * 填充大模型分析所需参数
// * @param deviceName 设备名称
// * @param month 月报数据月份
// * @param rundatas 月报运行数据
// * @param alarms 月报告警报表数据
// * @param analyseVOList 待填充的设备分析传参对象
// */
// private void fillDeviceAnalyse(String deviceName,String formateDeviceName,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();
// powerData.get().setRunTime(runDataVo.get().getRunHours());
// }
// }
// if(Func.isNotEmpty(soeDataDTOS)) {
// // 补充告警
// analyseVO.getSoe().addAll(soeDataDTOS);
// }
// }
/**
* 先删除原先月报数据
@ -797,6 +834,12 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
return true;
}
@Override
public Boolean generateAnalyseResult(String month, String stationCode) {
this.smartReportGeneratePower(month,stationCode);
return true;
}
/**
* 手绘运行数据表格
* @return

44
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/utils/SetNameFormatterUtil.java

@ -0,0 +1,44 @@
package com.hnac.hzims.operational.report.utils;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import java.util.List;
import java.util.Optional;
/**
* @Author: huangxing
* @Date: 2024/08/19 11:15
* 机组名称格式化
*/
public class SetNameFormatterUtil {
/**
* 根据机组名称拆解出对应的序号
* @param setName 机组名称
* @return 机组序号
*/
public static Integer getSetOrder(String setName) {
String setNameFormatter = setName.replace("号", "#").replace("g", "#").replace("G", "#");
List<String> parts = Func.toStrList("#", setNameFormatter);
if(CollectionUtil.isNotEmpty(parts)) {
Optional<Integer> orderOptional = parts.stream().map(SetNameFormatterUtil::disassemblyOrder).filter(Func::isNotEmpty).findFirst();
return orderOptional.orElse(null);
}
return null;
}
/**
* 根据字符串拆解出对应的序号
* @param part 待拆解的字符串
* @return
*/
public static Integer disassemblyOrder(String part) {
part = part.trim();
if(Func.isNotEmpty(part) && Character.isDigit(part.charAt(part.length() - 1))) {
return Character.getNumericValue(part.charAt(part.length() - 1));
}
return null;
}
}
Loading…
Cancel
Save