4 Commits

Author SHA1 Message Date
wr
94037d588b 暂态事件报告功能下载 2026-02-28 15:30:35 +08:00
01a77fa92d 1.暂降事件报告 2026-02-27 09:40:12 +08:00
9d9150e418 Merge remote-tracking branch 'origin/main' 2026-02-27 09:35:44 +08:00
ee1ca85a5d 1.暂降事件报告 2026-02-27 09:35:38 +08:00
13 changed files with 746 additions and 43 deletions

View File

@@ -47,7 +47,7 @@ import java.util.List;
* angle_diff_cn C相相位负跳变
* bph_max_value 不平衡度(单位%
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonIgnoreProperties(ignoreUnknown = true,value = {"pointer"})
public class BackData extends Structure {
public int qvvr_cata_cause[] = new int[256];
public int qvvr_phasetype[] = new int[256];

View File

@@ -63,6 +63,9 @@ public class AreaLineInfoVO implements Serializable {
@ApiModelProperty(name = "pt2",value = "pt2")
private Integer pt2;
@ApiModelProperty(name = "ptType",value = "接线类型(0:星型接法;1:三角型接法;2:开口三角型接法)")
private Integer ptType;
@ApiModelProperty(name = "objName",value = "对象名称")
private String objName;

View File

@@ -557,6 +557,7 @@
detail.ct2,
detail.pt1,
detail.pt2,
detail.PT_Type as ptType,
detail.obj_name,
detail.Dev_Capacity deviceCapacity,
detail.Short_Capacity,

View File

@@ -234,4 +234,10 @@ public class ReportController extends BaseController {
reportService.getPmsAreaReport(areaReportParam, response);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/createEventReport")
@ApiOperation("暂态事件报告导出")
public void createEventReport(@RequestBody @Validated List<String> index, HttpServletResponse response) throws IOException, InvalidFormatException {
commMonitorEventReportService.createEventReport(index,response);
}
}

View File

@@ -2021,7 +2021,7 @@ public class ReportServiceImpl implements ReportService {
@Override
public Page<WaveTypeVO> getEventReport(WaveTypeParam deviceInfoParam) {
Page<WaveTypeVO> page = new Page<>(deviceInfoParam.getPageNum(), deviceInfoParam.getPageSize());
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalRunDeviceInfo(deviceInfoParam).getData();
List<String> lineIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
if (CollUtil.isEmpty(lineIds)) {
return page;

View File

@@ -1,10 +1,8 @@
package com.njcn.event.common.mapper;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.event.pojo.dto.EventCount;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import com.njcn.event.pojo.vo.RmpEventDetailVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

View File

@@ -0,0 +1,69 @@
package com.njcn.event.common.pojo.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @description: 暂降事件特征幅值
* @author: denghuajun
* @time: 2019-10-17 13:59:51
**/
@Data
public class EventEigDetail implements Serializable {
/**
* 输出参数
* 持续时间(单位秒)
* hold_time_rms 有效值算法持续时间
* hold_time_dq dq变换算法持续时间
* 波形起始点(单位度)
* POW_a A相波形起始点
* POW_b B相波形起始点
* POW_c C相波形起始点
* 跳变段电压变化率单位V/S
* Voltagechange_Va A相跳变段电压变化率
* Voltagechange_Vb B相跳变段电压变化率
* Voltagechange_Vc C相跳变段电压变化率
* 分段信息
* SEG_T_num 分段数目
* SEG_T0_idx 原始分段位置
* SEG_T_idx 修正分段位置
* 有效值分段信息
* SEG_RMS_T_num 分段数目
* SEG_RMS_T_idx 分段位置
* 特征幅值单位V
* u_min_num 特征值个数
* ua_min A相电压特征值
* ub_min B相电压特征值
* uc_min C相电压特征值
* u3_min 三相电压特征值
* order_min_idx 最小值位置
* 相位跳变(单位度)
* angle_diff_ap A相相位正跳变
* angle_diff_bp B相相位正跳变
* angle_diff_cp C相相位正跳变
* angle_diff_an A相相位负跳变
* angle_diff_bn B相相位负跳变
* angle_diff_cn C相相位负跳变
* bph_max_value 不平衡度(单位%
*/
public float hold_time_dq;
public float pow_a;
public float pow_b;
public float pow_c;
public float voltagechange_Va;
public float voltagechange_Vb;
public float voltagechange_Vc;
public float ua_min;
public float ub_min;
public float uc_min;
public float angle_diff_ap;
public float angle_diff_bp;
public float angle_diff_cp;
public float bph_max_value;
public String sagReason; // 暂降原因描述,数据库获取
public String sagType; // 暂降类型描述,数据库获取
private Integer pttype;
}

View File

@@ -0,0 +1,63 @@
package com.njcn.event.common.pojo.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @Description:
* @Author: wr
* @Date: 2023/11/1 13:17
*/
@Data
public class EventInfoDetailVO implements Serializable {
@ApiModelProperty("监测点名称")
private String lineName;
@ApiModelProperty("供电公司名称")
private String gdName;
@ApiModelProperty("变电站名称")
private String bdzName;
@ApiModelProperty("终端名称")
private String devName;
@ApiModelProperty("电压等级")
private String scale;
@ApiModelProperty("ip")
private String ip;
@ApiModelProperty("暂降事件id")
private String eventDetailIndex;
@ApiModelProperty("触发时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
private LocalDateTime timeID;
@ApiModelProperty("持续时间")
private Double persistTime;
@ApiModelProperty("处理结果第一条事件发生时间毫秒")
private Double ms;
@ApiModelProperty("特征幅值")
private Double eventValue;
@ApiModelProperty("报告状态")
private int report;
@ApiModelProperty("评价")
private int evaluate;
@ApiModelProperty("报告路径")
private String reportPath;
}

View File

@@ -2,8 +2,11 @@ package com.njcn.event.common.service;
import com.njcn.event.common.pojo.dto.LineDetailDataCommDTO;
import com.njcn.event.pojo.param.ExportParam;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* pqs
@@ -15,4 +18,10 @@ public interface CommMonitorEventReportService {
void getLineExport(ExportParam exportParam, LineDetailDataCommDTO lineDetailDataCommDTO, HttpServletResponse response);
/**
* 暂态事件报告
* @param index
*/
void createEventReport(List<String> index, HttpServletResponse response) throws IOException, InvalidFormatException;
}

View File

@@ -0,0 +1,28 @@
package com.njcn.event.common.service;
import com.njcn.device.pq.pojo.vo.AreaLineInfoVO;
import com.njcn.event.common.pojo.dto.EventEigDetail;
import com.njcn.event.file.pojo.dto.WaveDataDTO;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import java.util.List;
/**
* @Author: cdf
* @CreateTime: 2026-02-26
* @Description:
*/
public interface WaveService {
/**
* 通过优化后的方式获取波形数据
* @param
* @param
* @return
*/
WaveDataDTO getWavedata(RmpEventDetailPO eventDetail, AreaLineInfoVO line);
List<EventEigDetail> eventDetailEigenvalue(String eventDetailIndex,Integer ptType);
}

View File

@@ -1,34 +1,43 @@
package com.njcn.event.common.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.device.pms.api.MonitorClient;
import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.pq.pojo.vo.AreaLineInfoVO;
import com.njcn.echarts.pojo.constant.PicCommonData;
import com.njcn.echarts.util.DrawPicUtil;
import com.njcn.event.common.mapper.RmpEventDetailMapper;
import com.njcn.event.common.pojo.dto.EventEigDetail;
import com.njcn.event.common.pojo.dto.LineDetailDataCommDTO;
import com.njcn.event.common.service.CommMonitorEventReportService;
import com.njcn.event.common.service.EventAnalysisService;
import com.njcn.event.common.service.EventReportService;
import com.njcn.event.common.service.WaveService;
import com.njcn.event.common.pojo.dto.EventInfoDetailVO;
import com.njcn.event.common.utils.WordUtil;
import com.njcn.event.common.utils.WordUtils;
import com.njcn.event.file.component.WavePicComponent;
import com.njcn.event.file.pojo.bo.WaveDataDetail;
import com.njcn.event.file.pojo.dto.WaveDataDTO;
import com.njcn.event.file.utils.WaveUtil;
import com.njcn.event.pojo.param.ExportParam;
import com.njcn.event.pojo.param.StatisticsParam;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import com.njcn.event.pojo.vo.*;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.DictData;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.*;
@@ -38,9 +47,7 @@ import org.springframework.stereotype.Service;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
@@ -49,6 +56,7 @@ import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
@@ -63,17 +71,16 @@ import java.util.stream.Collectors;
public class CommMonitorEventReportServiceImpl implements CommMonitorEventReportService {
private final DicDataFeignClient dicDataFeignClient;
private final EventReportService eventReportService;
private final EventAnalysisService eventAnalysisService;
private final RmpEventDetailMapper rmpEventDetailMapper;
private final WaveService waveService;
private final DrawPicUtil drawPicUtil;
private final WavePicComponent wavePicComponent;
private final FileStorageUtil fileStorageUtil;
private final LineFeignClient lineFeignClient;
private final DicDataFeignClient dicDataFeignClient;
private final EventReportService eventReportService;
//调用暂降密度接口
private final EventAnalysisService eventAnalysisService;
private final MonitorClient monitorClient;
private final RmpEventDetailMapper rmpEventDetailMapper;
private final DrawPicUtil drawPicUtil;
/**
* 监测点导出word
@@ -218,7 +225,7 @@ public class CommMonitorEventReportServiceImpl implements CommMonitorEventReport
EventDetail eventDetail = plot.get(j);
String s = eventDetail.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
insertRow(doc, table, centerParagraph, false, j + 1 + "", s, BigDecimal.valueOf(eventDetail.getFeatureAmplitude() * 100).setScale(2, RoundingMode.HALF_UP).toString(), eventDetail.getDuration() + "", Objects.isNull(eventDetail.getAdvanceType())?"/":eventDetail.getAdvanceType(), Objects.isNull(eventDetail.getAdvanceReason())?"/":eventDetail.getAdvanceReason(), Objects.isNull(eventDetail.getSeverity())?"/":eventDetail.getSeverity() + "");
insertRow(doc, table, centerParagraph, false, j + 1 + "", s, BigDecimal.valueOf(eventDetail.getFeatureAmplitude() * 100).setScale(2, RoundingMode.HALF_UP).toString(), eventDetail.getDuration() + "", Objects.isNull(eventDetail.getAdvanceType()) ? "/" : eventDetail.getAdvanceType(), Objects.isNull(eventDetail.getAdvanceReason()) ? "/" : eventDetail.getAdvanceReason(), Objects.isNull(eventDetail.getSeverity()) ? "/" : eventDetail.getSeverity() + "");
}
i++;
}
@@ -361,7 +368,7 @@ public class CommMonitorEventReportServiceImpl implements CommMonitorEventReport
} else {
for (int j = 0; j < reasonTypeTime.size(); j++) {
TimeVO timeVO = reasonTypeTime.get(j);
insertRow(doc, table1, centerParagraph, false,timeVO.getFulltime(), timeVO.getTimes());
insertRow(doc, table1, centerParagraph, false, timeVO.getFulltime(), timeVO.getTimes());
}
}
two++;
@@ -376,7 +383,7 @@ public class CommMonitorEventReportServiceImpl implements CommMonitorEventReport
if (fly) {
List<DictData> tempDictType = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_STATIS.getCode()).getData();
List<String> typeIds = tempDictType.stream().filter(x -> DicDataEnum.VOLTAGE_DIP.getCode().equals(x.getCode()) || DicDataEnum.SHORT_INTERRUPTIONS.getCode().equals(x.getCode()))
.map(DictData::getId).collect(Collectors.toList());
.map(DictData::getId).collect(Collectors.toList());
List<EventDetail> tempInfo = info.stream().filter(temp -> typeIds.contains(temp.getEventType())).collect(Collectors.toList());
StatisticVO statistic = eventReportService.getStatistic(tempInfo, reasonData, typeData);
if (exportParam.isYybg() || exportParam.isYytx()) {
@@ -460,8 +467,8 @@ public class CommMonitorEventReportServiceImpl implements CommMonitorEventReport
response.setContentType("application/octet-stream;charset=UTF-8");
doc.write(outputStream);
outputStream.close();
}catch (Exception e){
throw new BusinessException(CommonResponseEnum.FAIL,"导出监测点暂降报告异常");
} catch (Exception e) {
throw new BusinessException(CommonResponseEnum.FAIL, "导出监测点暂降报告异常");
}
}
@@ -520,14 +527,8 @@ public class CommMonitorEventReportServiceImpl implements CommMonitorEventReport
}
public void setCellStyle(HSSFCell cellname, String value, HSSFCellStyle style) {
cellname.setCellValue(value);
cellname.setCellStyle(style);
}
/**
*
*
* @param document 文档
* @param image 图片base64
* @param name 图片名
@@ -536,16 +537,16 @@ public class CommMonitorEventReportServiceImpl implements CommMonitorEventReport
*/
public void createPic(XWPFDocument document, String image, String name) {
try {
XWPFParagraph picParagraph = WordUtils.getCenterParagraph(document);
XWPFRun createRun = picParagraph.createRun();
if (image.contains(PicCommonData.PNG_PREFIX)) {
image = image.replace(PicCommonData.PNG_PREFIX, "");
}
byte[] bytes = Base64.getDecoder().decode(image);
InputStream in = new ByteArrayInputStream(bytes);
createRun.addPicture(in, 5, name, Units.toEMU(410), Units.toEMU(170));
}catch (Exception e){
log.error("在word中创建图片异常:",e);
XWPFParagraph picParagraph = WordUtils.getCenterParagraph(document);
XWPFRun createRun = picParagraph.createRun();
if (image.contains(PicCommonData.PNG_PREFIX)) {
image = image.replace(PicCommonData.PNG_PREFIX, "");
}
byte[] bytes = Base64.getDecoder().decode(image);
InputStream in = new ByteArrayInputStream(bytes);
createRun.addPicture(in, 5, name, Units.toEMU(410), Units.toEMU(170));
} catch (Exception e) {
log.error("在word中创建图片异常:", e);
}
}
@@ -581,14 +582,72 @@ public class CommMonitorEventReportServiceImpl implements CommMonitorEventReport
// .map(DictData::getId).collect(Collectors.toList());
//数据暂降查询
List<RmpEventDetailPO> info = rmpEventDetailMapper.selectList(new LambdaQueryWrapper<RmpEventDetailPO>()
.eq(RmpEventDetailPO::getMeasurementPointId, statisticsParam.getLineIndex())
.eq(RmpEventDetailPO::getMeasurementPointId, statisticsParam.getLineIndex())
// .in(RmpEventDetailPO::getEventType, typeIds)
.ge(StrUtil.isNotBlank(statisticsParam.getStartTime()), RmpEventDetailPO::getStartTime, DateUtil.beginOfDay(DateUtil.parse(statisticsParam.getStartTime())))
.le(StrUtil.isNotBlank(statisticsParam.getEndTime()), RmpEventDetailPO::getStartTime, DateUtil.endOfDay(DateUtil.parse(statisticsParam.getEndTime())))
.ge(StrUtil.isNotBlank(statisticsParam.getStartTime()), RmpEventDetailPO::getStartTime, DateUtil.beginOfDay(DateUtil.parse(statisticsParam.getStartTime())))
.le(StrUtil.isNotBlank(statisticsParam.getEndTime()), RmpEventDetailPO::getStartTime, DateUtil.endOfDay(DateUtil.parse(statisticsParam.getEndTime())))
.orderByDesc(RmpEventDetailPO::getStartTime)
);
return BeanUtil.copyToList(info, EventDetail.class);
}
/**
* 生成暂降事件报告
*/
public void createEventReport(List<String> eventIndex, HttpServletResponse response) throws IOException, InvalidFormatException {
WordUtil wordUtil = new WordUtil();
for (String index : eventIndex) {
RmpEventDetailPO detail = rmpEventDetailMapper.selectById(index);
List<AreaLineInfoVO> lineDetail = lineFeignClient.getBaseLineAreaInfo(Stream.of(detail.getLineId()).collect(Collectors.toList())).getData();
AreaLineInfoVO line = lineDetail.get(0);
WaveDataDTO waveData = waveService.getWavedata(detail, line);
//数据筛选,如果是双路电压的话会存在2个波形数据
List<WaveDataDetail> waveDataDetails = WaveUtil.filterWaveData(waveData);
if (ObjUtil.isNull(waveData)) {
throw new BusinessException(CommonResponseEnum.FAIL, "没有波形数据");
} else {
//获取瞬时波形
String instantPath = wavePicComponent.generateImageShun(waveData, waveDataDetails);
InputStream instantStream = fileStorageUtil.getFileStream(instantPath);
String imageShun64 = cn.hutool.core.codec.Base64.encode(instantStream);
wordUtil.translateShun(index, imageShun64);
//获取rms波形
String rmsPath = wavePicComponent.generateImageRms(waveData, waveDataDetails);
InputStream rmsStream = fileStorageUtil.getFileStream(rmsPath);
String rmsShun64 = cn.hutool.core.codec.Base64.encode(rmsStream);
wordUtil.translateRms(index, rmsShun64);
EventInfoDetailVO eventInfoList = new EventInfoDetailVO();
eventInfoList.setLineName(line.getLineName());
eventInfoList.setGdName(line.getGdName());
eventInfoList.setBdzName(line.getSubName());
eventInfoList.setDevName(line.getDeviceName());
eventInfoList.setScale(line.getVoltageScale());
eventInfoList.setIp(line.getIp());
eventInfoList.setEventDetailIndex(detail.getEventId());
eventInfoList.setTimeID(detail.getStartTime());
eventInfoList.setPersistTime(detail.getDuration());
eventInfoList.setMs(detail.getFirstMs());
eventInfoList.setEventValue(detail.getFeatureAmplitude());
wordUtil.setEventInfoList(index, eventInfoList);
List<EventEigDetail> eventDetailEigenvalue = waveService.eventDetailEigenvalue(index,line.getPtType());
wordUtil.setEventDetailEigenvalue(index, eventDetailEigenvalue);
}
}
wordUtil.createReport(eventIndex);
try {
ServletOutputStream outputStream = response.getOutputStream();
String fileName = URLEncoder.encode("暂降事件报告_" + DateUtil.format(new Date(),DatePattern.NORM_DATE_PATTERN)+ ".docx", "UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.setContentType("application/octet-stream;charset=UTF-8");
wordUtil.getDocument().write(outputStream);
outputStream.close();
} catch (Exception e) {
throw new BusinessException(CommonResponseEnum.FAIL, "导出暂降事件报告异常");
}
}
}

View File

@@ -0,0 +1,125 @@
package com.njcn.event.common.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.advance.api.EventWaveAnalysisFeignClient;
import com.njcn.advance.pojo.dto.waveAnalysis.EntityAdvancedData;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.device.pq.pojo.vo.AreaLineInfoVO;
import com.njcn.event.common.pojo.dto.EventEigDetail;
import com.njcn.event.common.service.WaveService;
import com.njcn.event.file.component.WaveFileComponent;
import com.njcn.event.file.pojo.dto.WaveDataDTO;
import com.njcn.event.file.pojo.enums.WaveFileResponseEnum;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import com.njcn.oss.constant.GeneralConstant;
import com.njcn.oss.constant.OssPath;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.system.api.DicDataFeignClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.util.*;
/**
* @Author: cdf
* @CreateTime: 2026-02-26
* @Description:
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class WaveServiceImpl implements WaveService {
private final WaveFileComponent waveFileComponent;
private final FileStorageUtil fileStorageUtil;
private final EventWaveAnalysisFeignClient eventWaveAnalysisFeignClient;
/**
* 根据暂降事件索引获取波形数据
* 注:当前只考虑本地的波形文件
*
* @param eventDetail 暂态事件
* @param line 监测点
*/
@Override
public WaveDataDTO getWavedata(RmpEventDetailPO eventDetail, AreaLineInfoVO line) {
WaveDataDTO waveDataDTO = null;
if (ObjectUtil.isNotEmpty(line)) {
String waveName = eventDetail.getWavePath();
if (StrUtil.isBlank(waveName)) {
throw new BusinessException(WaveFileResponseEnum.ANALYSE_WAVE_NOT_FOUND);
}
String wavePath = OssPath.WAVE_DIR + line.getIp() + StrUtil.SLASH + waveName;
try (
InputStream cfgStream = fileStorageUtil.getFileStream(wavePath + GeneralConstant.CFG);
InputStream datStream = fileStorageUtil.getFileStream(wavePath + GeneralConstant.DAT)
) {
if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) {
throw new BusinessException(WaveFileResponseEnum.ANALYSE_WAVE_NOT_FOUND);
}
waveDataDTO = waveFileComponent.getComtrade(cfgStream, datStream, 1);
} catch (Exception e) {
try {
InputStream cfgStreamLower = fileStorageUtil.getFileStream(wavePath + GeneralConstant.CFG_LOWER);
InputStream datStreamLower = fileStorageUtil.getFileStream(wavePath + GeneralConstant.DAT_LOWER);
if (Objects.isNull(cfgStreamLower) || Objects.isNull(datStreamLower)) {
throw new BusinessException(WaveFileResponseEnum.ANALYSE_WAVE_NOT_FOUND);
}
waveDataDTO = waveFileComponent.getComtrade(cfgStreamLower, datStreamLower, 1);
} catch (Exception e1) {
throw new BusinessException(WaveFileResponseEnum.WAVE_DATA_INVALID);
}
}
waveDataDTO = waveFileComponent.getValidData(waveDataDTO);
waveDataDTO.setPtType(line.getPtType());
waveDataDTO.setPt(line.getPt1() * 1.0 / line.getPt2());
waveDataDTO.setCt(line.getCt1() * 1.0 / line.getCt2());
waveDataDTO.setMonitorName(line.getLineName());
}
return waveDataDTO;
}
@Override
public List<EventEigDetail> eventDetailEigenvalue(String eventDetailIndex,Integer ptType) {
List<EventEigDetail> eventInfoDetails = new ArrayList<>();
EntityAdvancedData entityAdvancedData = eventWaveAnalysisFeignClient.analysis(eventDetailIndex).getData() ;
if (entityAdvancedData.backNumber != -1) {
for (int i = 0; i < entityAdvancedData.backNumber; i++) {
EventEigDetail eventEigDetail = new EventEigDetail();
eventEigDetail.setHold_time_dq(entityAdvancedData.evt_buf[i].hold_time_dq * 1000);
eventEigDetail.setPow_a(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].POW_a));
eventEigDetail.setPow_b(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].POW_b));
eventEigDetail.setPow_c(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].POW_c));
eventEigDetail.setVoltagechange_Va(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].Voltagechange_Va / 1000));
eventEigDetail.setVoltagechange_Vb(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].Voltagechange_Vb / 1000));
eventEigDetail.setVoltagechange_Vc(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].Voltagechange_Vc / 1000));
eventEigDetail.setUa_min(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].ua_min[0]));
eventEigDetail.setUb_min(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].ub_min[0]));
eventEigDetail.setUc_min(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].ua_min[0]));
eventEigDetail.setAngle_diff_ap(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].angle_diff_ap[0]));
eventEigDetail.setAngle_diff_bp(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].angle_diff_bp[0]));
eventEigDetail.setAngle_diff_cp(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].angle_diff_cp[0]));
eventEigDetail.setBph_max_value(PubUtils.floatRound(2, entityAdvancedData.evt_buf[i].bph_max_value[0]));
eventEigDetail.setSagReason(entityAdvancedData.sagReason[0]);//暂降原因,暂降原因都一样
eventEigDetail.setSagType(entityAdvancedData.sagType[i]);//暂降类型
eventInfoDetails.add(eventEigDetail);
eventEigDetail.setPttype(ptType);
}
} else {
eventInfoDetails = null;
}
return eventInfoDetails;
}
}

View File

@@ -0,0 +1,342 @@
package com.njcn.event.common.utils;
import com.njcn.event.common.pojo.dto.EventEigDetail;
import com.njcn.event.common.pojo.dto.EventInfoDetailVO;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import sun.misc.BASE64Decoder;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.time.format.DateTimeFormatter;
import java.util.*;
public class WordUtil {
private Map<String, List<byte[]>> listShunPic = new HashMap<>();
private Map<String, List<byte[]>> listRmsPic = new HashMap<>();
private XWPFDocument document;
private Map<String, List<EventEigDetail>> eventDetailEigenvalue = new HashMap<>();
private Map<String, EventInfoDetailVO> eventInfoList = new HashMap<>();
public void setEventInfoList(String index, EventInfoDetailVO eventInfoList) {
EventInfoDetailVO tmp = eventInfoList == null ? new EventInfoDetailVO() : eventInfoList;
this.eventInfoList.put(index, tmp);
}
public void setEventDetailEigenvalue(String index, List<EventEigDetail> eventDetailEigenvalue) {
List<EventEigDetail> tmp = eventDetailEigenvalue == null ? new ArrayList<>() : eventDetailEigenvalue;
this.eventDetailEigenvalue.put(index, tmp);
}
public XWPFDocument getDocument() {
return document;
}
public WordUtil() {
this.document = new XWPFDocument();
}
public void translateShun(String index, String strShunPic) {
BASE64Decoder decoder = new BASE64Decoder();
List<byte[]> tmp = new ArrayList<>();
try {
byte[] buffer = decoder.decodeBuffer(strShunPic);
tmp.add(buffer);
} catch (Exception e) {
}
listShunPic.put(index, tmp);
}
public void translateRms(String index, String strRmsPic) {
BASE64Decoder decoder = new BASE64Decoder();
List<byte[]> tmp = new ArrayList<>();
try {
byte[] buffer = decoder.decodeBuffer(strRmsPic);
tmp.add(buffer);
} catch (Exception e) {
}
listRmsPic.put(index, tmp);
}
public void createReport(List<String> eventIndex) throws IOException, InvalidFormatException {
setHeadingStyle(this.document);
// 添加标题
XWPFParagraph titleParagraph = getCenterParagraph(this.document);
addLine(titleParagraph, 11);
// 设置段落居中
XWPFRun titleParagraphBigRun = titleParagraph.createRun();
addParagraph(titleParagraphBigRun, "宋体", 28, "000000", "暂降事件报告", true);
addLine(titleParagraph, 17);
XWPFRun titleParagraphDateRun = titleParagraph.createRun();
addParagraph(titleParagraphDateRun, "宋体", 16, "000000", "南京灿能电力自动化股份有限公司", false);
addLine(titleParagraph, 1);
titleParagraphDateRun = titleParagraph.createRun();
addParagraph(titleParagraphDateRun, "宋体", 14, "000000", "生成时间:" + getRightNow(), false);
addLine(titleParagraph, 8);
titleParagraph = getLeftParagraph(this.document);
titleParagraphDateRun = titleParagraph.createRun();
addParagraph(titleParagraphDateRun, "宋体", 10, "000000", "【申明】本公司保留对报告的修改权,恕不另行通知,敬请关注最新版本。", false);
for (int m = 0; m < eventIndex.size(); m++) {
String eventId = eventIndex.get(m);
List<EventEigDetail> eventDetailEigenvaluetmp = this.eventDetailEigenvalue.get(eventId);
String time = eventInfoList.get(eventId).getTimeID().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
createTitle(document, (m + 1) + ". " + time, "标题 1", 0, 20);
createTitle(document, (m + 1) + "." + "1. 基本信息", "标题 2", 0, 15);
XWPFParagraph introductionContentParagraph = getLeftParagraph(document);
introductionContentParagraph.setIndentationFirstLine(200);
XWPFRun introductionContentRun = introductionContentParagraph.createRun();
addParagraph(introductionContentRun, "宋体", 11, "000000", eventInfoList.get(eventId).getGdName() + "" + eventInfoList.get(eventId).getBdzName() + ",网络参数:" + eventInfoList.get(eventId).getIp() + "" + eventInfoList.get(eventId).getLineName() + "" + time + "发生暂降事件,特征幅值:" + (eventInfoList.get(eventId).getEventValue()) + "%,持续时间:" + eventInfoList.get(eventId).getPersistTime() + "s。", false);
createTitle(document, (m + 1) + "." + "2. 波形图", "标题 2", 0, 15);
createTitle(document, (m + 1) + "." + "2.1 瞬时波形图", "标题 3", 200, 11);
for (int shun = 0; shun < listShunPic.get(eventId).size(); shun++) {
createPic(document, "瞬时波形" + (shun), listShunPic.get(eventId).get(shun));
}
createTitle(document, (m + 1) + "." + "2.2 RMS波形图", "标题 3", 200, 11);
for (int rms = 0; rms < listRmsPic.get(eventId).size(); rms++) {
createPic(document, "RMS波形" + (eventId), listRmsPic.get(eventId).get(rms));
}
createTitle(document, (m + 1) + "." + "3. 多特征值", "标题 2", 0, 15);
XWPFParagraph value = getLeftParagraph(document);
XWPFRun valuex = value.createRun();
addParagraph(valuex, "宋体", 11, "000000", "事件总分段数:" + eventDetailEigenvaluetmp.size(), false);
addLine(value, 1);
if (eventDetailEigenvaluetmp.size() == 0) {
continue;
}
valuex = value.createRun();
addParagraph(valuex, "宋体", 11, "000000", "暂降原因:" + eventDetailEigenvaluetmp.get(0).getSagReason(), false);
addLine(value, 1);
for (int i = 0; i < eventDetailEigenvaluetmp.size(); i++) {
valuex = value.createRun();
addParagraph(valuex, "宋体", 11, "000000", "分段" + (i + 1) + "多特征值", true);
addLine(value, 1);
valuex = value.createRun();
addParagraph(valuex, "宋体", 11, "000000", "波形起始点相位(°)" + (eventDetailEigenvaluetmp.get(0).getPttype() == 0 ? "A" : "AB") + "" + eventDetailEigenvaluetmp.get(i).getPow_a() + " " + (eventDetailEigenvaluetmp.get(0).getPttype() == 0 ? "B" : "BC") + "" + eventDetailEigenvaluetmp.get(i).getPow_b() + " " + ((eventDetailEigenvaluetmp.get(0).getPttype() == 2) ? "" : ((eventDetailEigenvaluetmp.get(0).getPttype() == 0 ? "C" : "CA") + "" + eventDetailEigenvaluetmp.get(i).getPow_c())), false);
addLine(value, 1);
valuex = value.createRun();
addParagraph(valuex, "宋体", 11, "000000", "跳变段电压变化率(V/ms)" + (eventDetailEigenvaluetmp.get(0).getPttype() == 0 ? "A" : "AB") + "" + eventDetailEigenvaluetmp.get(i).getVoltagechange_Va() + " " + (eventDetailEigenvaluetmp.get(0).getPttype() == 0 ? "B" : "BC") + "" + eventDetailEigenvaluetmp.get(i).getVoltagechange_Vb() + " " + ((eventDetailEigenvaluetmp.get(0).getPttype() == 2) ? "" : ((eventDetailEigenvaluetmp.get(0).getPttype() == 0 ? "C" : "CA") + "" + eventDetailEigenvaluetmp.get(i).getVoltagechange_Vc())), false);
addLine(value, 1);
valuex = value.createRun();
addParagraph(valuex, "宋体", 11, "000000", "相位跳变(°)" + (eventDetailEigenvaluetmp.get(0).getPttype() == 0 ? "A" : "AB") + "" + eventDetailEigenvaluetmp.get(i).getAngle_diff_ap() + " " + (eventDetailEigenvaluetmp.get(0).getPttype() == 0 ? "B" : "BC") + "" + eventDetailEigenvaluetmp.get(i).getAngle_diff_bp() + " " + ((eventDetailEigenvaluetmp.get(0).getPttype() == 2) ? "" : ((eventDetailEigenvaluetmp.get(0).getPttype() == 0 ? "C" : "CA") + "" + eventDetailEigenvaluetmp.get(i).getAngle_diff_cp())), false);
/*
* addLine(value, 1); valuex = value.createRun();
* addParagraph(valuex, "宋体", 11, "000000", "特征幅值(V)A相" +
* this.eventDetailEigenvalue.get(i).getUa_min() + " B相" +
* this.eventDetailEigenvalue.get(i).getUb_min() + " C相" +
* this.eventDetailEigenvalue.get(i).getUc_min(), false);
*/
/*
* addLine(value, 1); valuex = value.createRun();
* addParagraph(valuex, "宋体", 11, "000000", "持续时间(ms)" +
* this.eventDetailEigenvalue.get(i).getHold_time_dq(), false);
*/
addLine(value, 1);
valuex = value.createRun();
addParagraph(valuex, "宋体", 11, "000000", "不平衡度(%)" + eventDetailEigenvaluetmp.get(i).getBph_max_value(), false);
addLine(value, 1);
valuex = value.createRun();
addParagraph(valuex, "宋体", 11, "000000", "暂降类型:" + eventDetailEigenvaluetmp.get(i).getSagType(), false);
addLine(value, 1);
}
addLine(value, 1);
}
System.out.println("11");
}
public void createPic(XWPFDocument document, String name, byte[] base64Info) throws IOException, InvalidFormatException {
XWPFParagraph picParagraph = getCenterParagraph(document);
XWPFRun createRun = picParagraph.createRun();
InputStream in = new ByteArrayInputStream(base64Info);
createRun.addPicture(in, 5, name, Units.toEMU(410), Units.toEMU(170));
}
public void createTitle(XWPFDocument document, String message, String style, int line, int fontSize) {
XWPFParagraph summaeTableParagraph = getLeftParagraph(document);
summaeTableParagraph.setStyle(style);
summaeTableParagraph.setIndentationFirstLine(line);
XWPFRun summaeTableRun = summaeTableParagraph.createRun();
addParagraph(summaeTableRun, "宋体", fontSize, "000000", message, false);
}
public void setParagraphStyle(XWPFParagraph paragraph) {
paragraph.setSpacingBefore(100);
paragraph.setSpacingAfter(100);
}
/**
* 返回指定格式的段落 居中型
*
* @param document 文档对象
*/
public XWPFParagraph getCenterParagraph(XWPFDocument document) {
XWPFParagraph paragraph = document.createParagraph();
setParagraphStyle(paragraph);
paragraph.setAlignment(ParagraphAlignment.CENTER);
paragraph.setVerticalAlignment(TextAlignment.CENTER);
return paragraph;
}
/**
* 返回指定格式的段落 居左型
*
* @param document 文档对象
*/
public XWPFParagraph getLeftParagraph(XWPFDocument document) {
XWPFParagraph paragraph = document.createParagraph();
setParagraphStyle(paragraph);
paragraph.setAlignment(ParagraphAlignment.LEFT);
return paragraph;
}
/**
* 添加换行符
*
* @param paragraph 指定段落
* @param amount 行数
*/
public void addLine(XWPFParagraph paragraph, Integer amount) {
XWPFRun run = paragraph.createRun();
run.setFontSize(11);
for (int i = 0; i < amount; i++) {
run.addCarriageReturn();
}
}
/**
* 添加段落文本
*
* @param run 文本执行对象
* @param fontFamily 字体类型
* @param fontSize 字体大小
* @param backgroundColor 字体颜色
* @param bold 是否加粗
*/
public void addParagraph(XWPFRun run, String fontFamily, Integer fontSize, String backgroundColor, String message, boolean bold) {
run.setText(message);
run.setColor(backgroundColor);
run.setFontSize(fontSize);
run.setFontFamily(fontFamily);
run.setBold(bold);
}
/**
* 增加自定义标题样式。这里用的是stackoverflow的源码
*
* @param docxDocument 目标文档
* @param strStyleId 样式名称
* @param headingLevel 样式级别
*/
public void addCustomHeadingStyle(XWPFDocument docxDocument, String strStyleId, int headingLevel) {
CTStyle ctStyle = CTStyle.Factory.newInstance();
ctStyle.setStyleId(strStyleId);
CTString styleName = CTString.Factory.newInstance();
styleName.setVal(strStyleId);
ctStyle.setName(styleName);
CTDecimalNumber indentNumber = CTDecimalNumber.Factory.newInstance();
indentNumber.setVal(BigInteger.valueOf(headingLevel));
// lower number > style is more prominent in the formats bar
ctStyle.setUiPriority(indentNumber);
CTOnOff onoffnull = CTOnOff.Factory.newInstance();
ctStyle.setUnhideWhenUsed(onoffnull);
// style shows up in the formats bar
ctStyle.setQFormat(onoffnull);
// style defines a heading of the given level
CTPPr ppr = CTPPr.Factory.newInstance();
ppr.setOutlineLvl(indentNumber);
ctStyle.setPPr(ppr);
XWPFStyle style = new XWPFStyle(ctStyle);
// is a null op if already defined
XWPFStyles styles = docxDocument.createStyles();
style.setType(STStyleType.PARAGRAPH);
styles.addStyle(style);
}
/**
* 设置文档中标题格式
*/
public void setHeadingStyle(XWPFDocument document) {
addCustomHeadingStyle(document, "标题 1", 1);
addCustomHeadingStyle(document, "标题 2", 2);
addCustomHeadingStyle(document, "标题 3", 3);
addCustomHeadingStyle(document, "标题 4", 4);
addCustomHeadingStyle(document, "标题 5", 5);
addCustomHeadingStyle(document, "标题 6", 6);
addCustomHeadingStyle(document, "标题 7", 7);
}
/**
* 给表格添加一行数据
*
* @param paragraph 段落对象
* @param row 行对象
* @param data 不定长度的数据
*/
public void setExcelContent(XWPFParagraph paragraph, XWPFTableRow row, String... data) {
for (int i = 0; i < data.length; i++) {
XWPFRun run = paragraph.createRun();
run.setFontFamily("宋体");
run.setText(data[i]);
row.getCell(i).setParagraph(paragraph);
paragraph.removeRun(0);
}
}
/**
* 添加表头标题一行数据
*
* @param paragraph 段落对象
* @param row 行对象
* @param data 不定长度的数据
*/
public void setExcelHeadContent(XWPFParagraph paragraph, XWPFTableRow row, String... data) {
XWPFRun run = paragraph.createRun();
run.setFontFamily("宋体");
run.setBold(true);
run.setText(data[0]);
row.getCell(0).setParagraph(paragraph);
paragraph.removeRun(0);
for (int i = 1; i < data.length; i++) {
XWPFRun run1 = paragraph.createRun();
run1.setFontFamily("宋体");
run1.setBold(true);
run1.setText(data[i]);
row.addNewTableCell().setParagraph(paragraph);
paragraph.removeRun(0);
}
}
/**
* 获取当前的日期
*
* @return
*/
public String getRightNow() {
Calendar rightNow = Calendar.getInstance();
Integer year = rightNow.get(Calendar.YEAR);
Integer month = rightNow.get(Calendar.MONTH) + 1;
Integer day = rightNow.get(rightNow.DAY_OF_MONTH);
return year + "" + month + "" + day + "";
}
}