返回添加故障时间
This commit is contained in:
parent
c55b7f62ba
commit
bc64e0db41
@ -56,8 +56,8 @@ public class FaultRecorderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/parseData", method = RequestMethod.POST)
|
@RequestMapping(value = "/parseData", method = RequestMethod.POST)
|
||||||
public R<Map<String, List<Object>>> parseData(@RequestBody JSONObject jsonObject) throws IOException {
|
public R<Map<String, Object>> parseData(@RequestBody JSONObject jsonObject) throws IOException {
|
||||||
Map<String, List<Object>> dataCurve = faultRecorderService.getDataCurve(jsonObject.getString("url"), jsonObject.getString("deviceCode"));
|
Map<String, Object> dataCurve = faultRecorderService.getDataCurve(jsonObject.getString("url"), jsonObject.getString("deviceCode"));
|
||||||
return R.success(dataCurve);
|
return R.success(dataCurve);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ public interface FaultRecorderService {
|
|||||||
|
|
||||||
void download(String path, HttpServletResponse httpServletResponse) throws IOException;
|
void download(String path, HttpServletResponse httpServletResponse) throws IOException;
|
||||||
|
|
||||||
Map<String, List<Object>> getDataCurve(String url, String deviceCode);
|
Map<String, Object> getDataCurve(String url, String deviceCode);
|
||||||
|
|
||||||
void updateFdrConfig(SysEquipment sysEquipment);
|
void updateFdrConfig(SysEquipment sysEquipment);
|
||||||
|
|
||||||
|
@ -168,8 +168,8 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<Object>> getDataCurve(String url, String deviceCode) {
|
public Map<String, Object> getDataCurve(String url, String deviceCode) {
|
||||||
Map<String, List<Object>> resultMap = null;
|
Map<String, Object> resultMap = null;
|
||||||
//根据device Code查询故障录波格式
|
//根据device Code查询故障录波格式
|
||||||
QueryWrapper<SysEquipment> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<SysEquipment> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("CODE", deviceCode);
|
queryWrapper.eq("CODE", deviceCode);
|
||||||
@ -211,15 +211,20 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
|||||||
sysEquipmentMapper.updateById(sysEquipment);
|
sysEquipmentMapper.updateById(sysEquipment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<Object>> parseFile(InputStream inputStream, String timeFormat, String delimiter, int validStartLine) {
|
public Map<String, Object> parseFile(InputStream inputStream, String timeFormat, String delimiter, int validStartLine) {
|
||||||
List<List<String>> result = new ArrayList<>();
|
List<List<String>> result = new ArrayList<>();
|
||||||
Map<String, List<Object>> stringListMap = null;
|
Map<String, Object> stringListMap = null;
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
String line;
|
String line;
|
||||||
int lineNumber = 0;
|
int lineNumber = 0;
|
||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
lineNumber++;
|
lineNumber++;
|
||||||
|
|
||||||
|
if (lineNumber == 2){
|
||||||
|
List<String> lineData = Arrays.stream(line.split(":")).toList();
|
||||||
|
result.add(lineData);
|
||||||
|
}
|
||||||
// 忽略有效行之前的行
|
// 忽略有效行之前的行
|
||||||
if (lineNumber < validStartLine) {
|
if (lineNumber < validStartLine) {
|
||||||
continue;
|
continue;
|
||||||
@ -236,19 +241,29 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
|||||||
return stringListMap;
|
return stringListMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<Object>> parseDataCurve(List<List<String>> data, String timeFormat) throws ParseException {
|
public Map<String, Object> parseDataCurve(List<List<String>> data, String timeFormat) throws ParseException {
|
||||||
|
List<String> faultTimeList = data.get(0);
|
||||||
|
Long faultTime = null;
|
||||||
|
try {
|
||||||
|
faultTime = convertToTimestamp(faultTimeList.get(1).trim(), timeFormat);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("faultTime转换失败");
|
||||||
|
}
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put("faultTime", faultTime);
|
||||||
|
data.remove(0);
|
||||||
List<String> listField = data.get(0);
|
List<String> listField = data.get(0);
|
||||||
Map<String, List<Object>> map = new HashMap<>();
|
Map<String, List<Object>> map = new HashMap<>();
|
||||||
data.remove(0);
|
data.remove(0);
|
||||||
for (List<String> item : data) {
|
for (List<String> item : data) {
|
||||||
for (int i = 0; i < item.size(); i++) {
|
for (int i = 0; i < item.size(); i++) {
|
||||||
if (map.get(listField.get(i)) == null) {
|
if (map.get(listField.get(i)) == null) {
|
||||||
if (i == 0){
|
if (i == 0) {
|
||||||
List<Object> timeList = new ArrayList<>();
|
List<Object> timeList = new ArrayList<>();
|
||||||
long timestamp = convertToTimestamp(item.get(i), timeFormat);
|
long timestamp = convertToTimestamp(item.get(i), timeFormat);
|
||||||
timeList.add(timestamp);
|
timeList.add(timestamp);
|
||||||
map.put(listField.get(i),timeList);
|
map.put(listField.get(i), timeList);
|
||||||
}else {
|
} else {
|
||||||
List<Object> valueList = new ArrayList<>();
|
List<Object> valueList = new ArrayList<>();
|
||||||
valueList.add(Double.valueOf(item.get(i)));
|
valueList.add(Double.valueOf(item.get(i)));
|
||||||
map.put(listField.get(i), valueList);
|
map.put(listField.get(i), valueList);
|
||||||
@ -256,18 +271,18 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
List<Object> valueList = map.get(listField.get(i));
|
List<Object> valueList = map.get(listField.get(i));
|
||||||
if (i == 0){
|
if (i == 0) {
|
||||||
valueList.add(convertToTimestamp(item.get(i),timeFormat));
|
valueList.add(convertToTimestamp(item.get(i), timeFormat));
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
valueList.add(Double.valueOf(item.get(i)));
|
valueList.add(Double.valueOf(item.get(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map;
|
result.put("dataCurve",map);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long convertToTimestamp(String time, String pattern) throws ParseException {
|
public long convertToTimestamp(String time, String pattern) throws ParseException {
|
||||||
|
Loading…
Reference in New Issue
Block a user