故障录波文件解析
This commit is contained in:
parent
bc0d9cb39c
commit
718f3b3a6f
@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -34,7 +35,7 @@ public class FaultRecorderController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/parseData", method = RequestMethod.POST)
|
||||
public R<Map<String, List<String>>> parseData(@RequestBody JSONObject jsonObject) {
|
||||
public R<Map<String, List<String>>> parseData(@RequestBody JSONObject jsonObject) throws IOException {
|
||||
Map<String, List<String>> dataCurve = faultRecorderService.getDataCurve(jsonObject.getString("url"), jsonObject.getString("deviceCode"));
|
||||
return R.success(dataCurve);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class FdrFormatVo {
|
||||
|
||||
private String timeFormat;
|
||||
|
||||
private String delimite;
|
||||
private String delimiter;
|
||||
|
||||
private Integer validStartLine;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.das.modules.equipment.entity.SysEquipment;
|
||||
import com.das.modules.fdr.domain.FileNode;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
@ -12,7 +13,7 @@ import java.util.Map;
|
||||
public interface FaultRecorderService {
|
||||
List<FileNode> getDirOrFileList(String name,String startTime, String endTime);
|
||||
|
||||
Map<String, List<String>> getDataCurve(String url, String deviceCode);
|
||||
Map<String, List<String>> getDataCurve(String url, String deviceCode) throws IOException;
|
||||
|
||||
void updateFdrConfig(SysEquipment sysEquipment);
|
||||
|
||||
|
@ -218,19 +218,14 @@ public class MinioViewsServcie {
|
||||
return total;
|
||||
}
|
||||
|
||||
public InputStream getFileStream(String url) throws IOException {
|
||||
public InputStream getFileStream(String url){
|
||||
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = minioClient.getObject(GetObjectArgs.builder().bucket(minioProperties.getBucket()).object(url).build());
|
||||
} catch (Exception e) {
|
||||
log.error("获取文件失败");
|
||||
}finally {
|
||||
if (inputStream != null){
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -99,9 +96,9 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<String>> getDataCurve(String url, String deviceCode) {
|
||||
public Map<String, List<String>> getDataCurve(String url, String deviceCode) throws IOException {
|
||||
Map<String, List<String>> resultMap = null;
|
||||
InputStream fileStream;
|
||||
InputStream fileStream = null;
|
||||
try {
|
||||
fileStream = minioViewsServcie.getFileStream(url);
|
||||
//根据device Code查询故障录波格式
|
||||
@ -116,11 +113,15 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
||||
|
||||
|
||||
// 解析文件内容
|
||||
List<List<String>> parsedData = parseFile(fileStream, fdrFormatVo.getDelimite(), fdrFormatVo.getValidStartLine());
|
||||
List<List<String>> parsedData = parseFile(fileStream, fdrFormatVo.getDelimiter(), fdrFormatVo.getValidStartLine());
|
||||
resultMap = parseDataCurve(parsedData, fdrFormatVo.getTimeFormat());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if (fileStream != null){
|
||||
fileStream.close();
|
||||
}
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
@ -143,18 +144,13 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
||||
if (lineNumber < validStartLine) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 按照分隔符分割行数据
|
||||
String[] values = line.split(delimiter);
|
||||
List<String> lineData = new ArrayList<>();
|
||||
for (String value : values) {
|
||||
lineData.add(value.trim());
|
||||
}
|
||||
List<String> lineData = Arrays.stream(line.split(delimiter)).toList();
|
||||
result.add(lineData);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
log.error("文件解析失败");
|
||||
log.error("文件解析失败{}",e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user