上传文件格式化文件名称代码修改增加正则表达式判断
This commit is contained in:
parent
06c2302a56
commit
e2ac538042
|
@ -34,6 +34,7 @@ import java.io.FileInputStream;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
@ -65,6 +66,10 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService {
|
|||
String tempFilePath = System.getProperty("java.io.tmpdir") + username + slash;
|
||||
List<String> fileNames = new ArrayList<>();
|
||||
List<File> fileList = new ArrayList<>();
|
||||
String sampleRx = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_S_(FULL_|PREL_)\\d+\\.PHD";
|
||||
Pattern regexPattern = Pattern.compile(sampleRx);
|
||||
String sampleRx1 = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_S_(FULL_|PREL_)\\d+\\.\\d+\\.PHD";
|
||||
Pattern regexPattern1 = Pattern.compile(sampleRx1);
|
||||
try{
|
||||
File tempDir = new File(tempFilePath);
|
||||
if (!tempDir.exists()) tempDir.mkdir();
|
||||
|
@ -92,9 +97,12 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService {
|
|||
if (!created) return Result.error(Prompt.DIR_CREATE_FAIL + filePath);
|
||||
// 上传所有文件
|
||||
for (File oneFile : fileList) {
|
||||
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 fileName = oneFile.getName();
|
||||
if (!regexPattern.matcher(fileName).find() && !regexPattern1.matcher(fileName).find()) {
|
||||
EnergySpectrumStruct struct = phdFileUtil.analyzeFileSourceData(oneFile);
|
||||
String suffix = nameStandUtil.GetSuffix(struct.data_type, struct.spectrum_quantity, String.valueOf(struct.acquisition_live_time));
|
||||
fileName = oneFile.getName().substring(0, 23)+suffix;
|
||||
}
|
||||
String fullFilePath = filePath + slash + fileName;
|
||||
FileInputStream local = new FileInputStream(oneFile);
|
||||
ftpClient.storeFile(fullFilePath, local);
|
||||
|
|
Loading…
Reference in New Issue
Block a user