From 241929cab27db3079bedb622e104924e439eec7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E6=9C=A8c?= <857448963@qq.com> Date: Fri, 28 Apr 2023 10:17:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A2=E5=BD=A2=E4=B8=8B=E8=BD=BDbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../majornetwork/TransientController.java | 8 +- .../Impl/TransientServiceImpl.java | 158 ++++++++++++------ .../majornetwork/TransientService.java | 4 +- 3 files changed, 116 insertions(+), 54 deletions(-) diff --git a/pqs-event/event-boot/src/main/java/com/njcn/event/controller/majornetwork/TransientController.java b/pqs-event/event-boot/src/main/java/com/njcn/event/controller/majornetwork/TransientController.java index 622e7fcdf..f84ad8275 100644 --- a/pqs-event/event-boot/src/main/java/com/njcn/event/controller/majornetwork/TransientController.java +++ b/pqs-event/event-boot/src/main/java/com/njcn/event/controller/majornetwork/TransientController.java @@ -25,6 +25,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * @author: chenchao @@ -64,11 +65,10 @@ public class TransientController extends BaseController { @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD) @PostMapping("/downloadWaveFile") @ApiOperation("暂态波形下载") - @ApiImplicitParam(name = "waveFileParam", value = "波形下载参数", required = true) - public HttpResult downloadWaveFile(@RequestBody @Validated WaveFileParam waveFileParam, HttpServletResponse response) throws Exception { + @ApiImplicitParam(name = "eventIds", value = "波形下载参数", required = true) + public void downloadWaveFile(@RequestBody List eventIds, HttpServletResponse response) { String methodDescribe = getMethodDescribe("downloadWaveFile"); - HttpServletResponse resp = transientService.downloadWaveFile(waveFileParam, response); - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resp, methodDescribe); + transientService.downloadWaveFile(eventIds, response); } @OperateInfo(info = LogEnum.BUSINESS_COMMON) diff --git a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/TransientServiceImpl.java b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/TransientServiceImpl.java index c8700c5b4..94139f7a9 100644 --- a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/TransientServiceImpl.java +++ b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/TransientServiceImpl.java @@ -3,6 +3,7 @@ package com.njcn.event.service.majornetwork.Impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -45,6 +46,7 @@ import com.njcn.system.api.DicDataFeignClient; import com.njcn.system.enums.DicDataTypeEnum; import com.njcn.system.pojo.po.DictData; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.influxdb.dto.QueryResult; import org.springframework.stereotype.Service; @@ -73,6 +75,7 @@ import java.util.zip.ZipOutputStream; */ @Service @AllArgsConstructor +@Slf4j public class TransientServiceImpl implements TransientService { private final GeneralDeviceInfoClient generalDeviceInfoClient; @@ -87,10 +90,6 @@ public class TransientServiceImpl implements TransientService { private final GeneralInfo generalInfo; - private final InfluxDbUtils influxDbUtils; - - private final OBSUtil obsUtil; - private final WaveUtil waveUtil; private final MonitorClient monitorClient; @@ -184,8 +183,6 @@ public class TransientServiceImpl implements TransientService { @Override public WaveDataDTO getTransientAnalyseWave(MonitorTerminalParam param) { - //EventDetail eventDetailByTime = eventDetailService.getEventDetailByTime(lineId, timeId); - WaveDataDTO waveDataDTO; //原始数据 WaveDataDTO originalData; @@ -224,14 +221,14 @@ public class TransientServiceImpl implements TransientService { System.out.println("波形路径-------------------"+cfgPath); try ( - InputStream cfgStream = fileStorageUtil.downloadStream(cfgPath); - InputStream datStream = fileStorageUtil.downloadStream(datPath) + InputStream cfgStream = fileStorageUtil.getFileStream(cfgPath); + InputStream datStream = fileStorageUtil.getFileStream(datPath) ) { if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) { throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND); } originalData = waveUtil.getComtrade(cfgStream, datStream, 1); - } catch (IOException e) { + } catch (Exception e) { throw new BusinessException(EventResponseEnum.WAVE_DATA_INVALID); } } @@ -254,10 +251,9 @@ public class TransientServiceImpl implements TransientService { @Override - public HttpServletResponse downloadWaveFile(WaveFileParam waveFileParam, HttpServletResponse response) throws Exception { - List lineId = waveFileParam.getLineId(); - List timeId = waveFileParam.getTimeId(); - copyTempData(timeId, lineId); + public void downloadWaveFile(List eventIds, HttpServletResponse response) { + + copyTempData(eventIds); zipCompress(new File(generalInfo.getBusinessTempPath() + File.separator + "comtrade")); String zipPath = generalInfo.getBusinessTempPath() + File.separator + "comtrade.zip"; try { @@ -281,11 +277,10 @@ public class TransientServiceImpl implements TransientService { toClient.flush(); toClient.close(); } catch (IOException ex) { - ex.printStackTrace(); + log.error(LocalDateTime.now() + "压缩波形文件下载异常异常信息" + ex.getMessage()); } delFile(zipPath); deleteDirectoryLegacyIO(new File(generalInfo.getBusinessTempPath() + File.separator + "comtrade")); - return response; } @Override @@ -423,42 +418,110 @@ public class TransientServiceImpl implements TransientService { /** * 复制保存文件 */ - public void copyTempData(List timeId, List lineId) throws IOException { - for (int i = 0; i < timeId.size(); i++) { + public void copyTempData(List eventIds) { + + + for (int i = 0; i < eventIds.size(); i++) { //根据监测点id获取监测点详情 - LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(lineId.get(i)).getData(); - EventDetail eventDetailByTime = eventDetailService.getEventDetailByTime(lineId.get(i), timeId.get(i)); - String ip = lineDetailData.getIp(); - String waveName = eventDetailByTime.getWavePath(); - if (StrUtil.isBlank(ip) && StrUtil.isBlank(waveName)) { - throw new BusinessException(EventResponseEnum.EVENT_NOT_FOUND); + + RmpEventDetailPO rmpEventDetailPO = eventDetailService.getById(eventIds.get(i)); + if (Objects.nonNull(rmpEventDetailPO)) { + LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(rmpEventDetailPO.getMeasurementPointId()).getData(); + if (Objects.nonNull(lineDetailData)) { + String ip = lineDetailData.getIp(); + String waveName = rmpEventDetailPO.getWavePath(); + if (StrUtil.isBlank(ip) && StrUtil.isBlank(waveName)) { + throw new BusinessException(EventResponseEnum.EVENT_NOT_FOUND); + } + + String cfgPath = ""; + String datPath = ""; + InputStream cfgStream = null; + InputStream datStream = null; + try { + if (generalInfo.getBusinessFileStorage() == GeneralConstant.LOCAL_DISK) { + cfgPath = generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.CFG; + datPath = generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.DAT; + cfgStream = waveUtil.getFileInputStreamByFilePath(cfgPath); + datStream = waveUtil.getFileInputStreamByFilePath(datPath); + if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) { + throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND); + } + } else { + cfgPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG; + datPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT; + System.out.println("波形路径-------------------" + cfgPath); + + cfgStream = fileStorageUtil.downloadStream(cfgPath); + datStream = fileStorageUtil.downloadStream(datPath); + + if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) { + throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND); + } + } + + String fileMu = generalInfo.getBusinessTempPath()+File.separator+"comtrade"+File.separator+ip; + File mulu = new File(fileMu); + if(!mulu.exists()){ + mulu.mkdirs(); + } + File fileCfg = new File(fileMu+File.separator+waveName+GeneralConstant.CFG); + File fileDat = new File(fileMu+File.separator+waveName+GeneralConstant.DAT); + + fileCfg.createNewFile(); + fileDat.createNewFile(); + + writeFile(cfgStream, fileCfg); + writeFile(datStream, fileDat); + + } catch (Exception e) { + throw new BusinessException(EventResponseEnum.WAVE_DATA_INVALID); + }finally { + try { + if (cfgStream != null) { + cfgStream.close(); + } + if (datStream != null) { + datStream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + } } - File srcCFGFile = new File(generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + ".CFG"); - File srcDATFile = new File(generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + ".DAT"); - if (!srcCFGFile.exists() && !srcDATFile.exists()) { - throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND); - } - File temp = new File(generalInfo.getBusinessTempPath() + File.separator + "comtrade" + File.separator + ip); - temp.mkdirs(); - File cfg = new File(generalInfo.getBusinessTempPath() + File.separator + "comtrade" + File.separator + ip + File.separator + srcCFGFile.getName()); - File dat = new File(generalInfo.getBusinessTempPath() + File.separator + "comtrade" + File.separator + ip + File.separator + srcDATFile.getName()); - writeFile(srcCFGFile, cfg); - writeFile(srcDATFile, dat); } } //读写文件 - public static void writeFile(File wave, File temp) throws IOException { - FileInputStream fis = new FileInputStream(wave); - FileOutputStream fos = new FileOutputStream(temp); - int len; - byte[] bys = new byte[1024]; - while ((len = fis.read(bys)) != -1) { - fos.write(bys, 0, len); - fos.flush(); + public static void writeFile(InputStream inputStream, File temp) { + FileOutputStream fos = null; + + try { + fos = new FileOutputStream(temp); + int len; + byte[] bys = new byte[1024]; + while ((len = inputStream.read(bys)) != -1) { + fos.write(bys, 0, len); + fos.flush(); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (inputStream != null) { + inputStream.close(); + } + if (fos != null) { + fos.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } - fos.close(); - fis.close(); + } @@ -469,7 +532,7 @@ public class TransientServiceImpl implements TransientService { * @param inputFile 源文件(夹) * @return File 压缩后的文件(路径在源文件的文件夹路径下) */ - public static File zipCompress(File inputFile) throws Exception { + public static File zipCompress(File inputFile) { File zipFile = null; ZipOutputStream zos = null; if (inputFile != null && inputFile.exists()) { @@ -485,8 +548,7 @@ public class TransientServiceImpl implements TransientService { //压缩文件或文件夹 compressFile(zos, inputFile, inputFile.getName()); } catch (Exception e) { - System.out.println("文件压缩异常:" + e); - throw e; + log.error(LocalDateTime.now() + "暂态波形文件压缩异常:" + e.getMessage()); } finally { try { if (zos != null) { @@ -496,7 +558,7 @@ public class TransientServiceImpl implements TransientService { zos.close(); } } catch (Exception ex) { - System.out.println("输出流关闭异常:" + ex); + log.error(LocalDateTime.now() + "输出流关闭异常:" + ex.getMessage()); } } } diff --git a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/TransientService.java b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/TransientService.java index 6ae6610dd..ab3f56751 100644 --- a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/TransientService.java +++ b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/TransientService.java @@ -33,10 +33,10 @@ public interface TransientService { WaveDataDTO getTransientAnalyseWave(MonitorTerminalParam param); /** * 功能描述: 暂态事件波形文件下载 - * @param waveFileParam + * @param eventIds * @return */ - HttpServletResponse downloadWaveFile(WaveFileParam waveFileParam, HttpServletResponse response) throws Exception; + void downloadWaveFile(List eventIds, HttpServletResponse response); /** * 功能描述: 根据条件查询暂态事件 * @param transientParam