web模块下载zip文件功能其他谱文件下载修改
This commit is contained in:
parent
93cb64cd07
commit
65c15847b0
|
@ -167,9 +167,9 @@ public class FTPUtil {
|
||||||
response.reset();
|
response.reset();
|
||||||
//设置响应类型
|
//设置响应类型
|
||||||
response.setContentType("application/download");
|
response.setContentType("application/download");
|
||||||
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||||
//解决中文不能生成文件
|
//解决中文不能生成文件
|
||||||
response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(fileName,"UTF-8"));
|
response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(fileName,"UTF-8"));
|
||||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
||||||
//获取输出流
|
//获取输出流
|
||||||
out = response.getOutputStream();
|
out = response.getOutputStream();
|
||||||
//声明一个长度参数
|
//声明一个长度参数
|
||||||
|
|
|
@ -191,9 +191,11 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
|
||||||
InputStream detStream = null;
|
InputStream detStream = null;
|
||||||
File qcFile = null;
|
File qcFile = null;
|
||||||
InputStream qcStream = null;
|
InputStream qcStream = null;
|
||||||
|
String zipFileName = "";
|
||||||
try {
|
try {
|
||||||
//根据sampleId查询自动处理库获取相应分析id
|
//根据sampleId查询自动处理库获取相应分析id
|
||||||
Integer analysisID = this.baseMapper.getAnalysisID(sampleId);
|
Integer analysisID = this.baseMapper.getAnalysisID(sampleId);
|
||||||
|
//如果有分析id 则是sample文件可以查询到对应关联文件内容
|
||||||
if (Objects.nonNull(analysisID)) {
|
if (Objects.nonNull(analysisID)) {
|
||||||
//根据sampleId和分析id查询数据库文件信息
|
//根据sampleId和分析id查询数据库文件信息
|
||||||
SpectrumFileRecord dbSpectrumFilePath = this.baseMapper.getDBSpectrumFilePath(sampleId, analysisID);
|
SpectrumFileRecord dbSpectrumFilePath = this.baseMapper.getDBSpectrumFilePath(sampleId, analysisID);
|
||||||
|
@ -204,7 +206,7 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
|
||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
}
|
}
|
||||||
//获取sample文件路径 截取sample文件名称 将PHD改为zip
|
//获取sample文件路径 截取sample文件名称 将PHD改为zip
|
||||||
String zipFileName = dbSpectrumFilePath.getSampleFilePath().substring(dbSpectrumFilePath.getSampleFilePath().lastIndexOf(StringPool.SLASH) + 1).replace("PHD", "zip");
|
zipFileName = dbSpectrumFilePath.getSampleFilePath().substring(dbSpectrumFilePath.getSampleFilePath().lastIndexOf(StringPool.SLASH) + 1).replace("PHD", "zip");
|
||||||
//获取分析表中的采集开始时间
|
//获取分析表中的采集开始时间
|
||||||
String collectStartStr = DateUtils.formatDate(dbSpectrumFilePath.getCollectStart(), "yyyy/MM/dd HH:mm:ss");
|
String collectStartStr = DateUtils.formatDate(dbSpectrumFilePath.getCollectStart(), "yyyy/MM/dd HH:mm:ss");
|
||||||
//根据探测器信息以及采集开始时间查询对应的qc文件路径
|
//根据探测器信息以及采集开始时间查询对应的qc文件路径
|
||||||
|
@ -238,6 +240,19 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
|
||||||
FileUtils.copyInputStreamToFile(qcStream, qcFile);
|
FileUtils.copyInputStreamToFile(qcStream, qcFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {//如果没有分析id 则是其他谱类型文件 直接获取文件路径
|
||||||
|
GardsSampleDataWeb sampleData = getOneSample(sampleId);
|
||||||
|
String filePath = sampleData.getInputFileName();
|
||||||
|
if (StringUtils.isNotBlank(filePath)) {
|
||||||
|
zipFileName = filePath.substring(filePath.lastIndexOf(StringPool.SLASH)+1).replace("PHD", "zip");
|
||||||
|
sampleStream = ftpUtil.downloadFileStream(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath()+ StringPool.SLASH + filePath);
|
||||||
|
if (Objects.nonNull(sampleStream)) {
|
||||||
|
sampleFile = new File(parameterProperties.getLogFilePath() + StringPool.SLASH + filePath.substring(filePath.lastIndexOf(StringPool.SLASH) + 1));
|
||||||
|
FileUtils.copyInputStreamToFile(sampleStream, sampleFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (Objects.nonNull(sampleFile) || Objects.nonNull(gasFile) || Objects.nonNull(detFile) ||Objects.nonNull(qcFile)) {
|
if (Objects.nonNull(sampleFile) || Objects.nonNull(gasFile) || Objects.nonNull(detFile) ||Objects.nonNull(qcFile)) {
|
||||||
//创建zip的临时文件
|
//创建zip的临时文件
|
||||||
zipFile = File.createTempFile("betaGammaZip", null);
|
zipFile = File.createTempFile("betaGammaZip", null);
|
||||||
|
@ -249,8 +264,8 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
|
||||||
//设置响应类型
|
//设置响应类型
|
||||||
response.setContentType("application/download");
|
response.setContentType("application/download");
|
||||||
//解决中文不能生成文件
|
//解决中文不能生成文件
|
||||||
response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(zipFileName,"UTF-8"));
|
|
||||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(zipFileName,"UTF-8"));
|
||||||
//获取响应流的输出流
|
//获取响应流的输出流
|
||||||
outputStream = response.getOutputStream();
|
outputStream = response.getOutputStream();
|
||||||
//定义一个字节大小
|
//定义一个字节大小
|
||||||
|
@ -261,8 +276,6 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
|
||||||
outputStream.write(buffer, 0, bytesRead);
|
outputStream.write(buffer, 0, bytesRead);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -719,8 +732,7 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
|
||||||
public GardsSampleDataWeb getOneSample(Integer sampleId) {
|
public GardsSampleDataWeb getOneSample(Integer sampleId) {
|
||||||
LambdaQueryWrapper<GardsSampleDataWeb> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<GardsSampleDataWeb> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(GardsSampleDataWeb::getSampleId,sampleId);
|
wrapper.eq(GardsSampleDataWeb::getSampleId,sampleId);
|
||||||
return Optional.ofNullable(getOne(wrapper))
|
return Optional.ofNullable(getOne(wrapper)).orElse(new GardsSampleDataWeb());
|
||||||
.orElse(new GardsSampleDataWeb());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user