暂降报告修改
This commit is contained in:
@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* pqs
|
||||
@@ -25,7 +26,7 @@ public interface CommMonitorEventReportService {
|
||||
* 暂态事件报告
|
||||
* @param index
|
||||
*/
|
||||
void createEventReport(List<String> index, HttpServletResponse response) throws IOException, InvalidFormatException;
|
||||
void createEventReport(List<String> index, HttpServletResponse response) throws IOException, InvalidFormatException, ExecutionException, InterruptedException;
|
||||
|
||||
/**
|
||||
* 暂态事件报告存储,返回文件路径
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -60,6 +61,7 @@ import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -86,7 +88,8 @@ public class CommMonitorEventReportServiceImpl implements CommMonitorEventReport
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
private final LineFeignClient lineFeignClient;
|
||||
private final EventCauseFeignClient eventCauseFeignClient;
|
||||
|
||||
@Resource(name="asyncExecutor")
|
||||
private Executor executor;
|
||||
|
||||
/**
|
||||
* 监测点导出word
|
||||
@@ -600,8 +603,10 @@ public class CommMonitorEventReportServiceImpl implements CommMonitorEventReport
|
||||
/**
|
||||
* 生成暂降事件报告
|
||||
*/
|
||||
public void createEventReport(List<String> eventIndex, HttpServletResponse response) throws IOException, InvalidFormatException {
|
||||
@Override
|
||||
public void createEventReport(List<String> eventIndex, HttpServletResponse response) throws IOException, InvalidFormatException, ExecutionException, InterruptedException {
|
||||
WordUtil wordUtil = new WordUtil();
|
||||
// 创建专用的线程池(建议大小为CPU核心数或稍大,这里设为3个并行任务)
|
||||
for (String index : eventIndex) {
|
||||
RmpEventDetailPO detail = rmpEventDetailMapper.selectById(index);
|
||||
List<AreaLineInfoVO> lineDetail = lineFeignClient.getBaseLineAreaInfo(Stream.of(detail.getLineId()).collect(Collectors.toList())).getData();
|
||||
@@ -612,18 +617,42 @@ public class CommMonitorEventReportServiceImpl implements CommMonitorEventReport
|
||||
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);
|
||||
// 使用 CompletableFuture 并行执行三个耗时操作
|
||||
CompletableFuture<String> instantFuture = CompletableFuture.supplyAsync(() -> {
|
||||
String instantPath = wavePicComponent.generateImageShun(waveData, waveDataDetails);
|
||||
try (InputStream instantStream = fileStorageUtil.getFileStream(instantPath)) {
|
||||
return cn.hutool.core.codec.Base64.encode(instantStream);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("生成瞬时波形失败", e);
|
||||
}
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<String> rmsFuture = CompletableFuture.supplyAsync(() -> {
|
||||
String rmsPath = wavePicComponent.generateImageRms(waveData, waveDataDetails);
|
||||
try (InputStream rmsStream = fileStorageUtil.getFileStream(rmsPath)) {
|
||||
return cn.hutool.core.codec.Base64.encode(rmsStream);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("生成RMS波形失败", e);
|
||||
}
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<List<EventEigDetail>> eigFuture = CompletableFuture.supplyAsync(() ->
|
||||
waveService.eventDetailEigenvalue(index, line.getPtType()), executor
|
||||
);
|
||||
|
||||
// 等待所有异步任务完成并获取结果(无超时,但可加)
|
||||
CompletableFuture<Void> allFutures = CompletableFuture.allOf(instantFuture, rmsFuture, eigFuture);
|
||||
allFutures.join(); // 阻塞直到三个任务都完成
|
||||
|
||||
// 获取结果(此时所有任务已完成,get()不会阻塞)
|
||||
String imageShun64 = instantFuture.get();
|
||||
String rmsShun64 = rmsFuture.get();
|
||||
List<EventEigDetail> eventDetailEigenvalue = eigFuture.get();
|
||||
// 主线程顺序调用 WordUtil 方法(保证线程安全)
|
||||
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);
|
||||
|
||||
wordUtil.setEventDetailEigenvalue(index, eventDetailEigenvalue);
|
||||
// 设置事件基本信息(不涉及耗时操作)
|
||||
EventInfoDetailVO eventInfoList = new EventInfoDetailVO();
|
||||
eventInfoList.setLineName(line.getLineName());
|
||||
eventInfoList.setGdName(line.getGdName());
|
||||
@@ -637,9 +666,6 @@ public class CommMonitorEventReportServiceImpl implements CommMonitorEventReport
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user