|
|
@ -1,10 +1,18 @@ |
|
|
|
package com.kms.yg.cz.enmu; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.kms.yg.cz.dto.CharInfoDto; |
|
|
|
import com.kms.yg.cz.dto.MonitorQueDto; |
|
|
|
import com.shuili.common.utils.DateUtils; |
|
|
|
import lombok.Getter; |
|
|
|
import org.apache.commons.collections4.KeyValue; |
|
|
|
import org.apache.commons.collections4.keyvalue.DefaultKeyValue; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
import static com.shuili.common.utils.DateUtils.YYYY_MM_DD_HH_MM_SS; |
|
|
|
|
|
|
|
|
|
|
|
@Getter |
|
|
@ -66,4 +74,65 @@ public enum MonitorComposeEnum { |
|
|
|
this.rightUnit = rightUnit; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public CharInfoDto toChar(Map<MonitorSourceEnum, List<Map<String, Object>>> dataMap, MonitorQueDto sp) { |
|
|
|
CharInfoDto charInfoDto = new CharInfoDto(); |
|
|
|
charInfoDto.setXAxis(Stream.concat(this.leftElements.stream(), this.rightElements.stream()) |
|
|
|
.flatMap(type -> { |
|
|
|
MonitorSourceEnum source = type.getSource(); |
|
|
|
return dataMap.get(source).stream().map(map -> map.get(type.getTimeField())); |
|
|
|
} |
|
|
|
).filter(Objects::nonNull) |
|
|
|
.filter(item -> item instanceof Date) |
|
|
|
.map(item -> (Date) item) |
|
|
|
.map(date -> DateUtils.parseDateToStr(YYYY_MM_DD_HH_MM_SS, date)) |
|
|
|
.sorted() |
|
|
|
.collect(Collectors.toList())); |
|
|
|
List<CharInfoDto.YAxis> yAxis = new ArrayList<>(); |
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(this.leftElements)) { |
|
|
|
CharInfoDto.YAxis left = new CharInfoDto.YAxis(); |
|
|
|
left.setName(this.leftName); |
|
|
|
left.setUnit(this.leftUnit); |
|
|
|
left.setSeries(getCollect(this.leftElements, this.leftName, dataMap, charInfoDto)); |
|
|
|
yAxis.add(left); |
|
|
|
} |
|
|
|
if (CollectionUtil.isNotEmpty(this.rightElements)) { |
|
|
|
CharInfoDto.YAxis right = new CharInfoDto.YAxis(); |
|
|
|
right.setName(this.rightName); |
|
|
|
right.setUnit(this.rightUnit); |
|
|
|
right.setSeries(getCollect(this.rightElements, this.rightName, dataMap, charInfoDto)); |
|
|
|
yAxis.add(right); |
|
|
|
} |
|
|
|
return charInfoDto; |
|
|
|
} |
|
|
|
|
|
|
|
private List<CharInfoDto.Series> getCollect(List<MonitorTypeEnum> element, String name, Map<MonitorSourceEnum, List<Map<String, Object>>> dataMap, CharInfoDto charInfoDto) { |
|
|
|
return element.stream() |
|
|
|
.map(type -> { |
|
|
|
CharInfoDto.Series series = new CharInfoDto.Series(); |
|
|
|
series.setName(name); |
|
|
|
MonitorSourceEnum source = type.getSource(); |
|
|
|
Map<String, Object> values = dataMap.get(source).stream() |
|
|
|
.map(map -> { |
|
|
|
Object time = map.get(type.getTimeField()); |
|
|
|
if (time instanceof Date) { |
|
|
|
DefaultKeyValue<String, Object> keyValue = new DefaultKeyValue<>(); |
|
|
|
keyValue.setKey(DateUtils.parseDateToStr(YYYY_MM_DD_HH_MM_SS, (Date) time)); |
|
|
|
keyValue.setValue(map.get(type.getValueField())); |
|
|
|
return keyValue; |
|
|
|
} |
|
|
|
return null; |
|
|
|
}) |
|
|
|
.filter(Objects::nonNull) |
|
|
|
.collect(Collectors.toMap(KeyValue::getKey, KeyValue::getValue)); |
|
|
|
series.setData(charInfoDto.getXAxis().stream() |
|
|
|
.map(time -> { |
|
|
|
Object value = values.get(time); |
|
|
|
return value == null ? "0" : value.toString(); |
|
|
|
}).collect(Collectors.toList())); |
|
|
|
return series; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|