修改web-statistics模块读取PHD文件方法,根据头部信息读取不同的内容
增加SampleFileHeader枚举匹配对应的文件头部信息 新增HistogramData实体类存储对应的横纵竖数据
This commit is contained in:
parent
fc4e994500
commit
cc9fc9e88a
|
@ -0,0 +1,53 @@
|
|||
package org.jeecg.common.enums;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public enum SampleFileHeader {
|
||||
|
||||
HEADER(0,"#Header"),COMMENT(1,"#Comment"),COLLECTION(2,"#Collection"),ACQUISITION(3,"#Acquisition"),PROCESSING(4,"#Processing"),SAMPLE(5,"#Sample"),
|
||||
GENERGY(6,"#g_Energy"),BENERGY(7,"#b_Energy"),GRESOLUTION(8,"#g_Resolution"),BRESOLUTION(9,"#b_Resolution"),GEFFICIENCY(10,"#g_Efficiency"),
|
||||
ROILIMITS(11,"#ROI_Limits"),BGEFFICIENCY(12,"#b-gEfficiency"),TOTALEFF(13,"#TotalEff"),RATIOS(14,"#Ratios"),GSPECTRUM(15,"#g_Spectrum"),BSPECTRUM(16,"#b_Spectrum"),
|
||||
HISTOGRAM(17,"#Histogram"),CALIBRATION(18,"#Calibration"),CERTIFICATE(19,"#Certificate"),STOP(20,"STOP"),BEGIN(21,"BEGIN"),SPECTRUM(22,"#Spectrum");
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String message;
|
||||
|
||||
SampleFileHeader(Integer code, String message){
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public static Integer getCodeByMessage(String message){
|
||||
if (StringUtils.isNotBlank(message)){
|
||||
for (SampleFileHeader sampleFileHeader:values()) {
|
||||
if (sampleFileHeader.getMessage().equals(message)){
|
||||
return sampleFileHeader.getCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getMessageByCode(Integer code){
|
||||
if (code == null){
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
for (SampleFileHeader sampleFileHeader:values()) {
|
||||
if (sampleFileHeader.getCode().equals(code)){
|
||||
return sampleFileHeader.getMessage();
|
||||
}
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,21 @@
|
|||
package org.jeecg.common.util;
|
||||
|
||||
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.net.ftp.FTPClient;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.jeecg.common.enums.SampleFileHeader;
|
||||
import org.jeecg.modules.entity.data.HistogramData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
|
@ -14,61 +24,113 @@ public class ReadLineUtil {
|
|||
@Autowired
|
||||
private FTPUtil ftpUtil;
|
||||
|
||||
public List<Integer> readLine(String filePath){
|
||||
List<Integer> lineValue = new LinkedList<>();
|
||||
@Value("${ftp.encoding}")
|
||||
private String encoding;
|
||||
|
||||
lineValue.add(1);
|
||||
lineValue.add(2859);
|
||||
lineValue.add(6965);
|
||||
lineValue.add(4344);
|
||||
lineValue.add(3088);
|
||||
lineValue.add(3149);
|
||||
lineValue.add(2917);
|
||||
lineValue.add(2375);
|
||||
lineValue.add(1829);
|
||||
lineValue.add(1760);
|
||||
lineValue.add(1914);
|
||||
lineValue.add(2128);
|
||||
lineValue.add(2238);
|
||||
lineValue.add(1954);
|
||||
lineValue.add(1899);
|
||||
lineValue.add(2146);
|
||||
lineValue.add(2758);
|
||||
lineValue.add(3177);
|
||||
lineValue.add(2846);
|
||||
lineValue.add(2507);
|
||||
lineValue.add(2456);
|
||||
lineValue.add(2723);
|
||||
lineValue.add(3227);
|
||||
lineValue.add(3461);
|
||||
lineValue.add(3464);
|
||||
lineValue.add(3144);
|
||||
lineValue.add(3081);
|
||||
lineValue.add(3381);
|
||||
lineValue.add(3234);
|
||||
lineValue.add(3163);
|
||||
lineValue.add(3357);
|
||||
lineValue.add(3534);
|
||||
lineValue.add(3756);
|
||||
lineValue.add(3911);
|
||||
lineValue.add(3552);
|
||||
public Map<String, Object> readLine(String filePath, String header){
|
||||
//连接ftp
|
||||
FTPClient ftpClient = ftpUtil.LoginFTP();
|
||||
//判断ftp是否连接成功
|
||||
if (Objects.isNull(ftpClient)){
|
||||
throw new RuntimeException("ftp连接失败!");
|
||||
}
|
||||
try {
|
||||
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));
|
||||
//判断文件路径是否为空
|
||||
if (CollectionUtils.isNotEmpty(paths)){
|
||||
//遍历文件路径
|
||||
for (String path:paths) {
|
||||
//切换工作路径
|
||||
ftpClient.changeWorkingDirectory(path);
|
||||
}
|
||||
//在当前工作路径下读取文件
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
||||
// 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项
|
||||
ftpClient.setControlEncoding(encoding);
|
||||
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
|
||||
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
|
||||
if (CollectionUtils.isNotEmpty(ftpFiles)){
|
||||
for (FTPFile ftpFile:ftpFiles) {
|
||||
if (ftpFile.getName().equals(fileName)){
|
||||
//读取ftp文件的输入流
|
||||
InputStream iStream=ftpClient.retrieveFileStream(ftpFile.getName());
|
||||
//声明一个临时文件
|
||||
File file = File.createTempFile("tmp", null);
|
||||
//将ftp文件的输入流复制给临时文件
|
||||
FileUtils.copyInputStreamToFile(iStream, file);
|
||||
List<String> allLines = FileUtils.readLines(file, encoding);
|
||||
if (CollectionUtils.isNotEmpty(allLines)) {
|
||||
//遍历所有的行
|
||||
for (String nowLine:allLines) {
|
||||
//判断当前行是否含有传递的头部信息
|
||||
if (nowLine.contains(header)){
|
||||
List<String> otherLines = allLines.subList(allLines.indexOf(nowLine)+1, allLines.size());
|
||||
Map<String, Object> map = this.readValue(otherLines, header);
|
||||
iStream.close();
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
|
||||
// //连接ftp
|
||||
// FTPClient ftpClient = ftpUtil.LoginFTP();
|
||||
// //判断ftp是否连接成功
|
||||
// if (Objects.isNull(ftpClient)){
|
||||
// throw new RuntimeException("ftp连接失败!");
|
||||
// }
|
||||
// //根据字符切割文件路径
|
||||
// List<String> paths = Arrays.asList(filePath.split(StringPool.SLASH));
|
||||
// if (CollectionUtils.isNotEmpty(paths)){
|
||||
//
|
||||
// }
|
||||
return lineValue;
|
||||
ftpClient.disconnect();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
public Map<String, Object> readValue(List<String> allLines,String header) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
int index = 1;
|
||||
for (String line:allLines) {
|
||||
//如果当前读取的行内容对应的编码是空 说明不是头部信息
|
||||
if (SampleFileHeader.getCodeByMessage(line)!=null) {
|
||||
index = SampleFileHeader.getCodeByMessage(line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//从下标1开始切割文件 到下一个头部信息为止
|
||||
List<String> lines = allLines.subList(1, index);
|
||||
if ( header.equals(SampleFileHeader.GSPECTRUM.getMessage()) || header.equals(SampleFileHeader.BSPECTRUM.getMessage()) ) {
|
||||
List<Integer> result = new LinkedList<>();
|
||||
for (String line:lines) {
|
||||
List<String> values = Arrays.asList(line.split("\\s+"));
|
||||
for (int i=1;i< values.size(); i++) {
|
||||
result.add(Integer.valueOf(values.get(i)));
|
||||
}
|
||||
}
|
||||
map.put(header, result);
|
||||
}else if (header.equals(SampleFileHeader.HISTOGRAM.getMessage())){
|
||||
List<HistogramData> result = new LinkedList<>();
|
||||
for (int i=0; i<lines.size(); i++) {
|
||||
List<String> values = Arrays.asList(lines.get(i).split("\\s+"));
|
||||
for (int j=0;j< values.size(); j++) {
|
||||
if (!"0".equals(values.get(j))){
|
||||
HistogramData histogramData = new HistogramData();
|
||||
histogramData.setB(i);
|
||||
histogramData.setG(j);
|
||||
histogramData.setC(Integer.valueOf(values.get(j)));
|
||||
result.add(histogramData);
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put(header, result);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,6 @@ public class Histogram implements Serializable {
|
|||
|
||||
private Integer GEnergySpan;
|
||||
|
||||
private List<Integer> histogramSubBlock;
|
||||
private List<HistogramData> histogramSubBlock;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.jeecg.modules.entity.data;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class HistogramData implements Serializable {
|
||||
|
||||
private Integer b;
|
||||
|
||||
private Integer g;
|
||||
|
||||
private Integer c;
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.api.QueryRequest;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.enums.SampleFileHeader;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.jeecg.common.util.ReadLineUtil;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
|
@ -357,7 +358,11 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
|
|||
spectrumQueryWrapper.eq(GardsSpectrum::getSampleId, sampleId);
|
||||
GardsSpectrum gardsSpectrum = gardsSpectrumMapper.selectOne(spectrumQueryWrapper);
|
||||
if (Objects.nonNull(gardsSpectrum)){
|
||||
List<Integer> gSpectrumSubBlock = readLineUtil.readLine(gardsSpectrum.getFileName());
|
||||
Map<String, Object> map = readLineUtil.readLine(gardsSpectrum.getFileName(), SampleFileHeader.GSPECTRUM.getMessage());
|
||||
List<Integer> gSpectrumSubBlock = new LinkedList<>();
|
||||
if (CollectionUtils.isNotEmpty(map)){
|
||||
gSpectrumSubBlock = (List<Integer>)map.get(SampleFileHeader.GSPECTRUM.getMessage());
|
||||
}
|
||||
gSpectrumBlock.setGSpectrumSubBlock(gSpectrumSubBlock);
|
||||
gSpectrumBlock.setEnergySpan(gardsSpectrum.getEnergySpan());
|
||||
gSpectrumBlock.setNumberGChannels(gardsSpectrum.getChannels());
|
||||
|
@ -372,7 +377,11 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
|
|||
spectrumQueryWrapper.eq(GardsSpectrum::getSampleId, sampleId);
|
||||
GardsSpectrum gardsSpectrum = gardsSpectrumMapper.selectOne(spectrumQueryWrapper);
|
||||
if (Objects.nonNull(gardsSpectrum)){
|
||||
List<Integer> bSpectrumSubBlock = readLineUtil.readLine(gardsSpectrum.getFileName());
|
||||
Map<String, Object> map = readLineUtil.readLine(gardsSpectrum.getFileName(), SampleFileHeader.BSPECTRUM.getMessage());
|
||||
List<Integer> bSpectrumSubBlock = new LinkedList<>();
|
||||
if (CollectionUtils.isNotEmpty(map)) {
|
||||
bSpectrumSubBlock = (List<Integer>)map.get(SampleFileHeader.BSPECTRUM.getMessage());
|
||||
}
|
||||
bSpectrumBlock.setBSpectrumSubBlock(bSpectrumSubBlock);
|
||||
bSpectrumBlock.setEnergySpan(gardsSpectrum.getEnergySpan());
|
||||
bSpectrumBlock.setNumberBChannels(gardsSpectrum.getChannels());
|
||||
|
@ -386,7 +395,11 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
|
|||
histogramQueryWrapper.eq(GardsHistogram::getSampleId, sampleId);
|
||||
GardsHistogram gardsHistogram = gardsHistogramMapper.selectOne(histogramQueryWrapper);
|
||||
if (Objects.nonNull(gardsHistogram)){
|
||||
List<Integer> histogramSubBlock = readLineUtil.readLine(gardsHistogram.getFileName());
|
||||
Map<String, Object> map = readLineUtil.readLine(gardsHistogram.getFileName(), SampleFileHeader.HISTOGRAM.getMessage());
|
||||
List<HistogramData> histogramSubBlock = new LinkedList<>();
|
||||
if (CollectionUtils.isNotEmpty(map)) {
|
||||
histogramSubBlock = (List<HistogramData>)map.get(SampleFileHeader.HISTOGRAM.getMessage());
|
||||
}
|
||||
histogramBlock.setHistogramSubBlock(histogramSubBlock);
|
||||
histogramBlock.setBChannels(gardsHistogram.getBChannels());
|
||||
histogramBlock.setBEnergySpan(gardsHistogram.getBEnergySpan());
|
||||
|
|
Loading…
Reference in New Issue
Block a user