Merge remote-tracking branch 'origin/station' into station
This commit is contained in:
commit
e937652cc1
|
@ -1,9 +1,12 @@
|
|||
package org.jeecg.common.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -11,6 +14,8 @@ import org.apache.commons.net.ftp.FTP;
|
|||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.apache.commons.net.ftp.FTPReply;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.Prompt;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
@ -195,6 +200,58 @@ public class FTPUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public void downloadFTPFile(String localPath, HttpServletResponse response) {
|
||||
// 连接FTP
|
||||
FTPClient ftpClient = this.LoginFTP();
|
||||
// 判断FTP是否连接成功
|
||||
if (Objects.isNull(ftpClient)){
|
||||
throw new RuntimeException(Prompt.FTP_ERR);
|
||||
}
|
||||
|
||||
OutputStream outputStream = null;
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
// 判断FTP服务器上是否存在此文件
|
||||
String[] files = ftpClient.listNames(localPath);
|
||||
if (ArrayUtil.isEmpty(files)) return;
|
||||
|
||||
// 存在多个文件名表示此路径为目录而非文件
|
||||
if (ArrayUtil.length(files) > 1) return;
|
||||
|
||||
// 获取文件名
|
||||
String fileName = FileUtil.getName(localPath);
|
||||
|
||||
// 在当前工作路径下读取文件
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
||||
// 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项
|
||||
ftpClient.setControlEncoding(encoding);
|
||||
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
|
||||
inputStream = ftpClient.retrieveFileStream(localPath);
|
||||
outputStream = ExportUtil.stream(response, fileName);
|
||||
|
||||
// 缓冲区大小
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
|
||||
// 将文件输出流写入到输出流中
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
if (ObjectUtil.isNotNull(inputStream))inputStream.close();
|
||||
if (ObjectUtil.isNotNull(outputStream))outputStream.close();
|
||||
ftpClient.disconnect();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查目录是否存在,不存在则创建,支持递归创建
|
||||
* @param path 目录路径
|
||||
|
|
|
@ -45,10 +45,6 @@ public class LogManageController {
|
|||
@PostMapping("downloadFile")
|
||||
@ApiOperation(value = "ftp文件下载", notes = "ftp文件下载")
|
||||
public void downloadFile(String localPath, String fileName, HttpServletResponse response) {
|
||||
if (localPath.contains(fileName)){
|
||||
localPath=localPath.substring(0,localPath.indexOf(fileName)-1);
|
||||
}
|
||||
ftpUtil.downloadFTPFile(localPath, fileName,response);
|
||||
ftpUtil.downloadFTPFile(localPath, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1255,17 +1255,17 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void exportSampleInformation(Integer sampleId, String sampleFileName, HttpServletRequest request, HttpServletResponse response) {
|
||||
Result<StringBuffer> result = viewSampleInformation(sampleId, sampleFileName, request);
|
||||
StringBuffer buffer = result.getResult();
|
||||
if (ObjectUtil.isNull(buffer)) return;
|
||||
String sampleInfo = buffer.toString();
|
||||
public void exportSampleInformation(Integer sampleId, String sampleFileName,
|
||||
HttpServletRequest request, HttpServletResponse response) {
|
||||
Result<String> result = viewSampleInformation(sampleId, sampleFileName, request);
|
||||
String sampleInfo = result.getResult();
|
||||
if (StrUtil.isBlank(sampleInfo)) return;
|
||||
String colon = SymbolConstant.COLON;
|
||||
String space = SymbolConstant.SPACE;
|
||||
String line = SymbolConstant.LINE;
|
||||
List<String> sampleInfos = ListUtil.toList(sampleInfo.split(line)).stream()
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.filter(item -> StrUtil.contains(item,colon))
|
||||
.filter(item -> StrUtil.contains(item, colon))
|
||||
.collect(Collectors.toList());
|
||||
Map<String,Object> dataMap = new HashMap<>();
|
||||
for (String s : sampleInfos) {
|
||||
|
@ -3777,7 +3777,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements
|
|||
export = StrUtil.replace(sampleFileName, ".PHD", ".xls");
|
||||
}
|
||||
String template = SAVETOEXCEL.getName();
|
||||
ExportUtil.exportXls(response, template, analyze,export);
|
||||
ExportUtil.exportXls(response, template, analyze, export);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue
Block a user