波形下载bug
This commit is contained in:
@@ -25,6 +25,7 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: chenchao
|
* @author: chenchao
|
||||||
@@ -64,11 +65,10 @@ public class TransientController extends BaseController {
|
|||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
||||||
@PostMapping("/downloadWaveFile")
|
@PostMapping("/downloadWaveFile")
|
||||||
@ApiOperation("暂态波形下载")
|
@ApiOperation("暂态波形下载")
|
||||||
@ApiImplicitParam(name = "waveFileParam", value = "波形下载参数", required = true)
|
@ApiImplicitParam(name = "eventIds", value = "波形下载参数", required = true)
|
||||||
public HttpResult downloadWaveFile(@RequestBody @Validated WaveFileParam waveFileParam, HttpServletResponse response) throws Exception {
|
public void downloadWaveFile(@RequestBody List<String> eventIds, HttpServletResponse response) {
|
||||||
String methodDescribe = getMethodDescribe("downloadWaveFile");
|
String methodDescribe = getMethodDescribe("downloadWaveFile");
|
||||||
HttpServletResponse resp = transientService.downloadWaveFile(waveFileParam, response);
|
transientService.downloadWaveFile(eventIds, response);
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resp, methodDescribe);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.njcn.event.service.majornetwork.Impl;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
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.enums.DicDataTypeEnum;
|
||||||
import com.njcn.system.pojo.po.DictData;
|
import com.njcn.system.pojo.po.DictData;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.influxdb.dto.QueryResult;
|
import org.influxdb.dto.QueryResult;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -73,6 +75,7 @@ import java.util.zip.ZipOutputStream;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class TransientServiceImpl implements TransientService {
|
public class TransientServiceImpl implements TransientService {
|
||||||
|
|
||||||
private final GeneralDeviceInfoClient generalDeviceInfoClient;
|
private final GeneralDeviceInfoClient generalDeviceInfoClient;
|
||||||
@@ -87,10 +90,6 @@ public class TransientServiceImpl implements TransientService {
|
|||||||
|
|
||||||
private final GeneralInfo generalInfo;
|
private final GeneralInfo generalInfo;
|
||||||
|
|
||||||
private final InfluxDbUtils influxDbUtils;
|
|
||||||
|
|
||||||
private final OBSUtil obsUtil;
|
|
||||||
|
|
||||||
private final WaveUtil waveUtil;
|
private final WaveUtil waveUtil;
|
||||||
|
|
||||||
private final MonitorClient monitorClient;
|
private final MonitorClient monitorClient;
|
||||||
@@ -184,8 +183,6 @@ public class TransientServiceImpl implements TransientService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WaveDataDTO getTransientAnalyseWave(MonitorTerminalParam param) {
|
public WaveDataDTO getTransientAnalyseWave(MonitorTerminalParam param) {
|
||||||
//EventDetail eventDetailByTime = eventDetailService.getEventDetailByTime(lineId, timeId);
|
|
||||||
|
|
||||||
WaveDataDTO waveDataDTO;
|
WaveDataDTO waveDataDTO;
|
||||||
//原始数据
|
//原始数据
|
||||||
WaveDataDTO originalData;
|
WaveDataDTO originalData;
|
||||||
@@ -224,14 +221,14 @@ public class TransientServiceImpl implements TransientService {
|
|||||||
System.out.println("波形路径-------------------"+cfgPath);
|
System.out.println("波形路径-------------------"+cfgPath);
|
||||||
try (
|
try (
|
||||||
|
|
||||||
InputStream cfgStream = fileStorageUtil.downloadStream(cfgPath);
|
InputStream cfgStream = fileStorageUtil.getFileStream(cfgPath);
|
||||||
InputStream datStream = fileStorageUtil.downloadStream(datPath)
|
InputStream datStream = fileStorageUtil.getFileStream(datPath)
|
||||||
) {
|
) {
|
||||||
if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) {
|
if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) {
|
||||||
throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND);
|
throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
originalData = waveUtil.getComtrade(cfgStream, datStream, 1);
|
originalData = waveUtil.getComtrade(cfgStream, datStream, 1);
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
throw new BusinessException(EventResponseEnum.WAVE_DATA_INVALID);
|
throw new BusinessException(EventResponseEnum.WAVE_DATA_INVALID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,10 +251,9 @@ public class TransientServiceImpl implements TransientService {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpServletResponse downloadWaveFile(WaveFileParam waveFileParam, HttpServletResponse response) throws Exception {
|
public void downloadWaveFile(List<String> eventIds, HttpServletResponse response) {
|
||||||
List<String> lineId = waveFileParam.getLineId();
|
|
||||||
List<String> timeId = waveFileParam.getTimeId();
|
copyTempData(eventIds);
|
||||||
copyTempData(timeId, lineId);
|
|
||||||
zipCompress(new File(generalInfo.getBusinessTempPath() + File.separator + "comtrade"));
|
zipCompress(new File(generalInfo.getBusinessTempPath() + File.separator + "comtrade"));
|
||||||
String zipPath = generalInfo.getBusinessTempPath() + File.separator + "comtrade.zip";
|
String zipPath = generalInfo.getBusinessTempPath() + File.separator + "comtrade.zip";
|
||||||
try {
|
try {
|
||||||
@@ -281,11 +277,10 @@ public class TransientServiceImpl implements TransientService {
|
|||||||
toClient.flush();
|
toClient.flush();
|
||||||
toClient.close();
|
toClient.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
log.error(LocalDateTime.now() + "压缩波形文件下载异常异常信息" + ex.getMessage());
|
||||||
}
|
}
|
||||||
delFile(zipPath);
|
delFile(zipPath);
|
||||||
deleteDirectoryLegacyIO(new File(generalInfo.getBusinessTempPath() + File.separator + "comtrade"));
|
deleteDirectoryLegacyIO(new File(generalInfo.getBusinessTempPath() + File.separator + "comtrade"));
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -423,42 +418,110 @@ public class TransientServiceImpl implements TransientService {
|
|||||||
/**
|
/**
|
||||||
* 复制保存文件
|
* 复制保存文件
|
||||||
*/
|
*/
|
||||||
public void copyTempData(List<String> timeId, List<String> lineId) throws IOException {
|
public void copyTempData(List<String> eventIds) {
|
||||||
for (int i = 0; i < timeId.size(); i++) {
|
|
||||||
|
|
||||||
|
for (int i = 0; i < eventIds.size(); i++) {
|
||||||
//根据监测点id获取监测点详情
|
//根据监测点id获取监测点详情
|
||||||
LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(lineId.get(i)).getData();
|
|
||||||
EventDetail eventDetailByTime = eventDetailService.getEventDetailByTime(lineId.get(i), timeId.get(i));
|
RmpEventDetailPO rmpEventDetailPO = eventDetailService.getById(eventIds.get(i));
|
||||||
String ip = lineDetailData.getIp();
|
if (Objects.nonNull(rmpEventDetailPO)) {
|
||||||
String waveName = eventDetailByTime.getWavePath();
|
LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(rmpEventDetailPO.getMeasurementPointId()).getData();
|
||||||
if (StrUtil.isBlank(ip) && StrUtil.isBlank(waveName)) {
|
if (Objects.nonNull(lineDetailData)) {
|
||||||
throw new BusinessException(EventResponseEnum.EVENT_NOT_FOUND);
|
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 {
|
public static void writeFile(InputStream inputStream, File temp) {
|
||||||
FileInputStream fis = new FileInputStream(wave);
|
FileOutputStream fos = null;
|
||||||
FileOutputStream fos = new FileOutputStream(temp);
|
|
||||||
int len;
|
try {
|
||||||
byte[] bys = new byte[1024];
|
fos = new FileOutputStream(temp);
|
||||||
while ((len = fis.read(bys)) != -1) {
|
int len;
|
||||||
fos.write(bys, 0, len);
|
byte[] bys = new byte[1024];
|
||||||
fos.flush();
|
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 源文件(夹)
|
* @param inputFile 源文件(夹)
|
||||||
* @return File 压缩后的文件(路径在源文件的文件夹路径下)
|
* @return File 压缩后的文件(路径在源文件的文件夹路径下)
|
||||||
*/
|
*/
|
||||||
public static File zipCompress(File inputFile) throws Exception {
|
public static File zipCompress(File inputFile) {
|
||||||
File zipFile = null;
|
File zipFile = null;
|
||||||
ZipOutputStream zos = null;
|
ZipOutputStream zos = null;
|
||||||
if (inputFile != null && inputFile.exists()) {
|
if (inputFile != null && inputFile.exists()) {
|
||||||
@@ -485,8 +548,7 @@ public class TransientServiceImpl implements TransientService {
|
|||||||
//压缩文件或文件夹
|
//压缩文件或文件夹
|
||||||
compressFile(zos, inputFile, inputFile.getName());
|
compressFile(zos, inputFile, inputFile.getName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("文件压缩异常:" + e);
|
log.error(LocalDateTime.now() + "暂态波形文件压缩异常:" + e.getMessage());
|
||||||
throw e;
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (zos != null) {
|
if (zos != null) {
|
||||||
@@ -496,7 +558,7 @@ public class TransientServiceImpl implements TransientService {
|
|||||||
zos.close();
|
zos.close();
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println("输出流关闭异常:" + ex);
|
log.error(LocalDateTime.now() + "输出流关闭异常:" + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ public interface TransientService {
|
|||||||
WaveDataDTO getTransientAnalyseWave(MonitorTerminalParam param);
|
WaveDataDTO getTransientAnalyseWave(MonitorTerminalParam param);
|
||||||
/**
|
/**
|
||||||
* 功能描述: 暂态事件波形文件下载
|
* 功能描述: 暂态事件波形文件下载
|
||||||
* @param waveFileParam
|
* @param eventIds
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
HttpServletResponse downloadWaveFile(WaveFileParam waveFileParam, HttpServletResponse response) throws Exception;
|
void downloadWaveFile(List<String> eventIds, HttpServletResponse response);
|
||||||
/**
|
/**
|
||||||
* 功能描述: 根据条件查询暂态事件
|
* 功能描述: 根据条件查询暂态事件
|
||||||
* @param transientParam
|
* @param transientParam
|
||||||
|
|||||||
Reference in New Issue
Block a user