故障录波文件解析
This commit is contained in:
parent
91efa06892
commit
c546b9e52b
@ -35,8 +35,8 @@ public class FaultRecorderController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/parseData", method = RequestMethod.POST)
|
||||
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"));
|
||||
public R<Map<String, List<Object>>> parseData(@RequestBody JSONObject jsonObject) throws IOException {
|
||||
Map<String, List<Object>> dataCurve = faultRecorderService.getDataCurve(jsonObject.getString("url"), jsonObject.getString("deviceCode"));
|
||||
return R.success(dataCurve);
|
||||
}
|
||||
|
||||
|
@ -13,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) throws IOException;
|
||||
Map<String, List<Object>> getDataCurve(String url, String deviceCode) throws IOException;
|
||||
|
||||
void updateFdrConfig(SysEquipment sysEquipment);
|
||||
|
||||
|
@ -24,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.rmi.ServerException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
@ -96,11 +97,9 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<String>> getDataCurve(String url, String deviceCode) throws IOException {
|
||||
Map<String, List<String>> resultMap = null;
|
||||
InputStream fileStream = null;
|
||||
try {
|
||||
fileStream = minioViewsServcie.getFileStream(url);
|
||||
public Map<String, List<Object>> getDataCurve(String url, String deviceCode) throws IOException {
|
||||
Map<String, List<Object>> resultMap = null;
|
||||
try (InputStream fileStream = minioViewsServcie.getFileStream(url)) {
|
||||
//根据device Code查询故障录波格式
|
||||
QueryWrapper<SysEquipment> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("CODE", deviceCode);
|
||||
@ -109,19 +108,17 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
||||
throw new ServiceException("设备不存在,请选择正确设备");
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(sysEquipment.getFdrFormat())){
|
||||
throw new ServerException("请添加设备故障录波配置");
|
||||
}
|
||||
FdrFormatVo fdrFormatVo = JSON.parseObject(sysEquipment.getFdrFormat(), FdrFormatVo.class);
|
||||
|
||||
|
||||
// 解析文件内容
|
||||
List<List<String>> parsedData = parseFile(fileStream, fdrFormatVo.getDelimiter(), fdrFormatVo.getValidStartLine());
|
||||
resultMap = parseDataCurve(parsedData, fdrFormatVo.getTimeFormat());
|
||||
resultMap = parseFile(fileStream, fdrFormatVo.getTimeFormat(), fdrFormatVo.getDelimiter(), fdrFormatVo.getValidStartLine());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if (fileStream != null){
|
||||
fileStream.close();
|
||||
}
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
@ -131,9 +128,11 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
||||
sysEquipmentMapper.updateById(sysEquipment);
|
||||
}
|
||||
|
||||
public List<List<String>> parseFile(InputStream inputStream, String delimiter, int validStartLine) {
|
||||
public Map<String, List<Object>> parseFile(InputStream inputStream, String timeFormat, String delimiter, int validStartLine) {
|
||||
|
||||
|
||||
List<List<String>> result = new ArrayList<>();
|
||||
Map<String, List<Object>> stringListMap = null;
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
int lineNumber = 0;
|
||||
@ -148,36 +147,44 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
||||
List<String> lineData = Arrays.stream(line.split(delimiter)).toList();
|
||||
result.add(lineData);
|
||||
}
|
||||
stringListMap = parseDataCurve(result, timeFormat);
|
||||
} catch (Exception e) {
|
||||
|
||||
log.error("文件解析失败{}", e);
|
||||
}
|
||||
return result;
|
||||
return stringListMap;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> parseDataCurve(List<List<String>> data, String timeFormat) throws ParseException {
|
||||
public Map<String, List<Object>> parseDataCurve(List<List<String>> data, String timeFormat) throws ParseException {
|
||||
List<String> listField = data.get(0);
|
||||
Map<String, List<String>> map = new HashMap<>();
|
||||
Map<String, List<Object>> map = new HashMap<>();
|
||||
data.remove(0);
|
||||
for (List<String> item : data) {
|
||||
for (int i = 0; i < item.size(); i++) {
|
||||
if (map.get(listField.get(i)) == null) {
|
||||
List<String> valueList = new ArrayList<>();
|
||||
valueList.add(item.get(i));
|
||||
map.put(listField.get(i), valueList);
|
||||
if (i == 0){
|
||||
List<Object> timeList = new ArrayList<>();
|
||||
long timestamp = convertToTimestamp(item.get(i), timeFormat);
|
||||
timeList.add(timestamp);
|
||||
map.put(listField.get(i),timeList);
|
||||
}else {
|
||||
List<String> valueList = map.get(listField.get(i));
|
||||
valueList.add(item.get(i));
|
||||
List<Object> valueList = new ArrayList<>();
|
||||
valueList.add(Double.valueOf(item.get(i)));
|
||||
map.put(listField.get(i), valueList);
|
||||
}
|
||||
|
||||
} else {
|
||||
List<Object> valueList = map.get(listField.get(i));
|
||||
if (i == 0){
|
||||
valueList.add(convertToTimestamp(item.get(i),timeFormat));
|
||||
|
||||
}
|
||||
else {
|
||||
valueList.add(Double.valueOf(item.get(i)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
List<String> list = map.get(listField.get(0));
|
||||
List<String> timeList = new ArrayList<>();
|
||||
for (String item : list) {
|
||||
long timestamp = convertToTimestamp(item, timeFormat);
|
||||
timeList.add(String.valueOf(timestamp));
|
||||
map.put(listField.get(0), timeList);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user