波形下载bug
This commit is contained in:
@@ -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<String> 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)
|
||||
|
||||
@@ -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<String> lineId = waveFileParam.getLineId();
|
||||
List<String> timeId = waveFileParam.getTimeId();
|
||||
copyTempData(timeId, lineId);
|
||||
public void downloadWaveFile(List<String> 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<String> timeId, List<String> lineId) throws IOException {
|
||||
for (int i = 0; i < timeId.size(); i++) {
|
||||
public void copyTempData(List<String> 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));
|
||||
|
||||
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 = eventDetailByTime.getWavePath();
|
||||
String waveName = rmpEventDetailPO.getWavePath();
|
||||
if (StrUtil.isBlank(ip) && StrUtil.isBlank(waveName)) {
|
||||
throw new BusinessException(EventResponseEnum.EVENT_NOT_FOUND);
|
||||
}
|
||||
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()) {
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//读写文件
|
||||
public static void writeFile(File wave, File temp) throws IOException {
|
||||
FileInputStream fis = new FileInputStream(wave);
|
||||
FileOutputStream fos = new FileOutputStream(temp);
|
||||
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 = fis.read(bys)) != -1) {
|
||||
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();
|
||||
fis.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String> eventIds, HttpServletResponse response);
|
||||
/**
|
||||
* 功能描述: 根据条件查询暂态事件
|
||||
* @param transientParam
|
||||
|
||||
Reference in New Issue
Block a user