diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java index f15a66a5..7d1e29bf 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java @@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.text.ParseException; @@ -40,10 +41,8 @@ public class PHDFileUtil { private FTPUtil ftpUtil; @Autowired private NameStandUtil nameStandUtil; - @Autowired - private SpectrumPathProperties spectrumPathProperties; - public Map getSourceData(String filePath, Integer sampleId, String status){ + public Map getSourceData(String filePath, Integer sampleId, String status) { EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(filePath); Map map = new HashMap<>(); try { @@ -259,7 +258,7 @@ public class PHDFileUtil { return map; } - public List readLine(String filePath){ + public List readLine(String filePath) { String parameterFilePath = filePath.substring(0, filePath.lastIndexOf(StringPool.SLASH)); String fileName = filePath.substring(filePath.lastIndexOf(StringPool.SLASH) + 1); //连接ftp @@ -310,7 +309,7 @@ public class PHDFileUtil { return Collections.emptyList(); } - public void getLightColor(Map sampleMap, Map gasBgMap, Map detBgMap, Map qcMap){ + public void getLightColor(Map sampleMap, Map gasBgMap, Map detBgMap, Map qcMap) { SpectrumData sampleSpectrumData = (SpectrumData)sampleMap.get("spectrumData"); SpectrumData gasBgSpectrumData = (SpectrumData)gasBgMap.get("spectrumData"); SpectrumData detBgSpectrumData = (SpectrumData)detBgMap.get("spectrumData"); @@ -449,7 +448,7 @@ public class PHDFileUtil { } - public Map getFileData(String filePath, String sampleFileName){ + public Map getFileData(String filePath, String sampleFileName) { Map map = new HashMap<>(); //连接ftp 获取ftp文件数据 FTPClient ftpClient = ftpUtil.LoginFTP(); @@ -514,7 +513,7 @@ public class PHDFileUtil { return map; } - public String NameStandardBy(String filePath, String fileName){ + public String NameStandardBy(String filePath, String fileName) { //连接ftp FTPClient ftpClient = ftpUtil.LoginFTP(); InputStream inputStream = null; @@ -585,7 +584,7 @@ public class PHDFileUtil { return path.toString(); } - public List FileNameByStandardForm(String filePath, String sampleFileName){ + public List FileNameByStandardForm(String filePath, String sampleFileName) { //用于最后的结果 List fileNames = new LinkedList<>(); String station = sampleFileName.substring(0, 9); @@ -816,7 +815,38 @@ public class PHDFileUtil { return struct; } - public List analyzeQCResultXe(File sampleTmp, File gasTmp, File detTmp){ + public EnergySpectrumStruct analyzeFileSourceData(File uploadFile) { + EnergySpectrumStruct struct = null; + InputStream inputStream = null; + File file = null; + try { + inputStream = new FileInputStream(uploadFile); + if (Objects.nonNull(inputStream)){ + //声明一个临时文件 + file = File.createTempFile("betaGamma", null); + //将ftp文件的输入流复制给临时文件 + FileUtils.copyInputStreamToFile(inputStream, file); + struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); + } + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + if (Objects.nonNull(inputStream)){ + inputStream.close(); + } + if (Objects.nonNull(file)) { + file.delete(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return struct; + } + + + public List analyzeQCResultXe(File sampleTmp, File gasTmp, File detTmp) { //调用动态库解析文件 BgAnalyseResult bgAnalyseResult = EnergySpectrumHandler.bgAnalyse(sampleTmp.getAbsolutePath(), gasTmp.getAbsolutePath(), detTmp.getAbsolutePath()); List xeResultsSpectrumList = new LinkedList<>(); @@ -851,7 +881,7 @@ public class PHDFileUtil { return xeResultsSpectrumList; } - public Map analyze(File sampleTmp, File gasTmp, File detTmp){ + public Map analyze(File sampleTmp, File gasTmp, File detTmp) { Map result = new HashMap<>(); //调用动态库解析文件 BgAnalyseResult bgAnalyseResult = EnergySpectrumHandler.bgAnalyse(sampleTmp.getAbsolutePath(), gasTmp.getAbsolutePath(), detTmp.getAbsolutePath()); diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java index 725beb56..d6b8bee7 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java @@ -148,7 +148,6 @@ public class SpectrumAnalysesController { return spectrumAnalysisService.viewExtrapolation(sampleId, sampleFileName, request); } - //todo--功能不明确待完成 @PostMapping("analyseExtrapolation") public Result analyseExtrapolation(@RequestBody AnalyseExtInfo extInfo, HttpServletRequest request) { return spectrumAnalysisService.analyseExtrapolation(extInfo, request); diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java index 90cc2ef8..fc672da4 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java @@ -17,10 +17,13 @@ import org.jeecg.common.constant.enums.FileTypeEnum; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.FTPUtil; +import org.jeecg.common.util.NameStandUtil; +import org.jeecg.common.util.PHDFileUtil; import org.jeecg.common.util.PageUtil; import org.jeecg.modules.base.comparator.FileComparator; import org.jeecg.modules.base.dto.FileDto; import org.jeecg.modules.base.bizVo.FileVo; +import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; import org.jeecg.modules.service.ISpectrumFileService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -42,6 +45,10 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { private FTPUtil ftpUtil; @Autowired private SpectrumPathProperties spectrumPathProperties; + @Autowired + private PHDFileUtil phdFileUtil; + @Autowired + private NameStandUtil nameStandUtil; @Override public Result upload(MultipartFile file) { @@ -85,9 +92,12 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { if (!created) return Result.error(Prompt.DIR_CREATE_FAIL + filePath); // 上传所有文件 for (File oneFile : fileList) { - String fullFilePath = filePath + slash + oneFile.getName(); + EnergySpectrumStruct struct = phdFileUtil.analyzeFileSourceData(oneFile); + String suffix = nameStandUtil.GetSuffix(struct.data_type, struct.spectrum_quantity, String.valueOf(struct.acquisition_live_time)); + String fileName = oneFile.getName().substring(0, 23)+suffix; + String fullFilePath = filePath + slash + fileName; FileInputStream local = new FileInputStream(oneFile); - ftpClient.storeFile(fullFilePath,local); + ftpClient.storeFile(fullFilePath, local); } return Result.OK(Prompt.UPLOAD_SUCC); } catch (IOException e) {