方法优化
This commit is contained in:
parent
8928607514
commit
4410bf68d3
|
@ -23,9 +23,7 @@ public class PHDFileUtil {
|
|||
|
||||
public static Map<String, Object> getSourceData(String filePath){
|
||||
//加载dll工具库
|
||||
/* System.loadLibrary("ReadPHDFile");*/
|
||||
String dllPath = "D:\\Work\\C++\\c++lib\\ReadPHDFile.dll";
|
||||
System.load(dllPath);
|
||||
System.loadLibrary("ReadPHDFile");
|
||||
EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(filePath);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
try {
|
||||
|
@ -116,8 +114,8 @@ public class PHDFileUtil {
|
|||
//Gamma Spectrum Projected
|
||||
List<Double> gCentroidChannel = struct.g_centroid_channel;
|
||||
List<Double> gEnergy = struct.g_energy;
|
||||
/*List<Double> gammaProjectedData = EnergySpectrumHandler.GetFileFittingPara(gCentroidChannel, gEnergy);*/
|
||||
map.put("gammaProjectedData", null);
|
||||
List<Double> gammaProjectedData = EnergySpectrumHandler.GetFileFittingPara(gCentroidChannel, gEnergy);
|
||||
map.put("gammaProjectedData", gammaProjectedData);
|
||||
|
||||
//Beta Spectrum Original
|
||||
List<Long> betaOriginalData = new LinkedList<>();
|
||||
|
@ -141,8 +139,8 @@ public class PHDFileUtil {
|
|||
//Beta Spectrum Projected
|
||||
List<Double> bChannel = struct.b_channel;
|
||||
List<Double> bElectronEnergy = struct.b_electron_energy;
|
||||
/*List<Double> betaProjectedData = EnergySpectrumHandler.GetFileFittingPara(bChannel, bElectronEnergy);*/
|
||||
map.put("betaProjectedData", null);
|
||||
List<Double> betaProjectedData = EnergySpectrumHandler.GetFileFittingPara(bChannel, bElectronEnergy);
|
||||
map.put("betaProjectedData", betaProjectedData);
|
||||
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.jeecg.common.util;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
|
@ -9,6 +10,7 @@ import org.apache.commons.io.FileUtils;
|
|||
import org.apache.commons.net.ftp.FTP;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
import org.jeecg.common.enums.SampleFileHeader;
|
||||
import org.jeecg.modules.entity.data.HistogramData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -158,7 +160,7 @@ public class ReadLineUtil {
|
|||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
} catch (FileNotFoundException e){
|
||||
log.error("Report文件["+filePath+"]不存在!");
|
||||
log.error("文件["+filePath+"]不存在!");
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -178,29 +180,38 @@ public class ReadLineUtil {
|
|||
FTPClient ftpClient = ftpUtil.LoginFTP();
|
||||
// 判断FTP是否连接成功
|
||||
if (Objects.isNull(ftpClient)){
|
||||
throw new RuntimeException("ftp连接失败!");
|
||||
throw new RuntimeException("FTP连接失败!");
|
||||
}
|
||||
|
||||
String fileName = filePath.substring(filePath.lastIndexOf(StringPool.SLASH) + 1);
|
||||
String parameterFilePath = filePath.substring(0, filePath.lastIndexOf(StringPool.SLASH));
|
||||
// 根据字符切割文件路径
|
||||
List<String> paths = Arrays.asList(parameterFilePath.split(StringPool.SLASH));
|
||||
OutputStream outputStream = null;
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
for (String path : paths) {
|
||||
ftpClient.changeWorkingDirectory(path);
|
||||
// 切换工作目录为 /
|
||||
ftpClient.changeWorkingDirectory(SymbolConstant.SINGLE_SLASH);
|
||||
|
||||
// 判断FTP服务器上是否存在此文件
|
||||
String[] files = ftpClient.listNames(filePath);
|
||||
if (ArrayUtil.isEmpty(files)){
|
||||
log.error("文件["+filePath+"]不存在!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 存在多个文件名表示此路径为目录而非文件
|
||||
if (ArrayUtil.length(files) > 1){
|
||||
log.error("路径["+filePath+"]存在多个文件名,可能是一个目录!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取文件名
|
||||
String fileName = FileUtil.getName(filePath);
|
||||
|
||||
// 在当前工作路径下读取文件
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
||||
// 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项
|
||||
ftpClient.setControlEncoding(encoding);
|
||||
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
|
||||
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
|
||||
for (FTPFile ftpFile : ftpFiles) {
|
||||
if (ftpFile.getName().equals(fileName)){
|
||||
inputStream = ftpClient.retrieveFileStream(fileName);
|
||||
inputStream = ftpClient.retrieveFileStream(filePath);
|
||||
outputStream = response.getOutputStream();
|
||||
// 设置响应头
|
||||
response.setContentType("application/octet-stream");
|
||||
|
@ -214,8 +225,6 @@ public class ReadLineUtil {
|
|||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
|
@ -227,7 +236,6 @@ public class ReadLineUtil {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user