|
|
@ -9,10 +9,7 @@ import com.kms.yg.cz.dto.CharInfoDto; |
|
|
|
import com.kms.yg.cz.dto.CurrentWaterMonitorDto; |
|
|
|
import com.kms.yg.cz.dto.MonitorConfigDto; |
|
|
|
import com.kms.yg.cz.dto.MonitorQueDto; |
|
|
|
import com.kms.yg.cz.enmu.MonitorComposeEnum; |
|
|
|
import com.kms.yg.cz.enmu.MonitorSourceEnum; |
|
|
|
import com.kms.yg.cz.enmu.MonitorTypeEnum; |
|
|
|
import com.kms.yg.cz.enmu.MsgTypeEnum; |
|
|
|
import com.kms.yg.cz.enmu.*; |
|
|
|
import com.kms.yg.cz.mapper.MonitorConfigMapper; |
|
|
|
import com.kms.yxgh.base.domain.monitor.MsHdmObp; |
|
|
|
import com.kms.yxgh.base.domain.monitor.MsHdmRsvr; |
|
|
@ -27,11 +24,9 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
@ -85,11 +80,21 @@ public class MonitorService { |
|
|
|
Map<MonitorSourceEnum, CompletableFuture<List<Object>>> futureMap = sourceEnums.stream() |
|
|
|
.collect(Collectors.toMap(Function.identity(), item -> CompletableFuture.supplyAsync(() -> queryDataList(item, queDto))) |
|
|
|
); |
|
|
|
CompletableFuture.allOf(futureMap.values().toArray(new CompletableFuture[0])).join(); |
|
|
|
return futureMap.entrySet().stream() |
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, item -> item.getValue().join().stream() |
|
|
|
.map(BeanCopyUtils::copyToMap) |
|
|
|
.collect(Collectors.toList()))); |
|
|
|
try { |
|
|
|
CompletableFuture.allOf(futureMap.values().toArray(new CompletableFuture[0])).get(1, TimeUnit.MINUTES); |
|
|
|
return futureMap.entrySet().stream() |
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, item -> { |
|
|
|
CompletableFuture<List<Object>> future = item.getValue(); |
|
|
|
return future.getNow(Collections.emptyList()) |
|
|
|
.stream() |
|
|
|
.map(BeanCopyUtils::copyToMap) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
})); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("查询数据异常", e); |
|
|
|
return Collections.emptyMap(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public CurrentWaterMonitorDto watter(MonitorQueDto sp) { |
|
|
@ -201,4 +206,75 @@ public class MonitorService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<MonitorIndexEnum.IndexInfo> index(MonitorQueDto sp) { |
|
|
|
List<MonitorIndexEnum.IndexInfo> indexInfos = sp.getGroup().info(); |
|
|
|
List<MonitorSourceEnum> sourceEnums = sp.getGroup() |
|
|
|
.getIndexElements().stream() |
|
|
|
.flatMap(item -> item.getIndexElements().stream()) |
|
|
|
.flatMap(item -> item.keySet().stream()) |
|
|
|
.map(MonitorTypeEnum::getSource) |
|
|
|
.distinct() |
|
|
|
.collect(Collectors.toList()); |
|
|
|
Map<MonitorSourceEnum, List<Map<String, Object>>> dataMap = queryData(sourceEnums, sp); |
|
|
|
indexInfos.stream() |
|
|
|
.flatMap(item -> item.getItems().stream()) |
|
|
|
.forEach(item -> { |
|
|
|
String key = item.getKey(); |
|
|
|
if (key.contains(MonitorIndexInfo.KEY_FIELD)) { |
|
|
|
String[] keys = key.split(MonitorIndexInfo.KEY_FIELD); |
|
|
|
if (keys.length == 2) { |
|
|
|
getDataFromMonitor(item, keys, dataMap); |
|
|
|
} |
|
|
|
} else { |
|
|
|
try { |
|
|
|
MarkTypeEnum markTypeEnum = MarkTypeEnum.valueOf(key); |
|
|
|
item.setValue(markTypeEnum.getData(sp.getResCode())); |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
log.error("未找到对应的枚举值markTypeEnum, key:{}", key); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
return indexInfos; |
|
|
|
} |
|
|
|
|
|
|
|
private void getDataFromMonitor(MonitorIndexInfo.Info item, String[] keys, Map<MonitorSourceEnum, List<Map<String, Object>>> dataMap) { |
|
|
|
try { |
|
|
|
MonitorTypeEnum monitorTypeEnum = MonitorTypeEnum.valueOf(keys[1]); |
|
|
|
MonitorTypeEnum.OperatorEnum operatorEnum = MonitorTypeEnum.OperatorEnum.valueOf(keys[0]); |
|
|
|
List<Map<String, Object>> data = dataMap.getOrDefault(monitorTypeEnum.getSource(), Collections.emptyList()); |
|
|
|
switch (operatorEnum) { |
|
|
|
case MAX: |
|
|
|
Optional<Double> v = getData(monitorTypeEnum, data).max(Comparator.comparingDouble(Double::doubleValue)); |
|
|
|
v.ifPresent(aDouble -> item.setValue(aDouble.toString())); |
|
|
|
break; |
|
|
|
case MIN: |
|
|
|
Optional<Double> v1 = getData(monitorTypeEnum, data).min(Comparator.comparingDouble(Double::doubleValue)); |
|
|
|
v1.ifPresent(aDouble -> item.setValue(aDouble.toString())); |
|
|
|
break; |
|
|
|
case TOTAL: |
|
|
|
Optional<Double> v2 = getData(monitorTypeEnum, data).reduce(Double::sum); |
|
|
|
v2.ifPresent(aDouble -> item.setValue(aDouble.toString())); |
|
|
|
break; |
|
|
|
case TOP: |
|
|
|
Optional<Double> v3 = getData(monitorTypeEnum, data).limit(1).findFirst(); |
|
|
|
v3.ifPresent(aDouble -> item.setValue(aDouble.toString())); |
|
|
|
break; |
|
|
|
default: |
|
|
|
Optional<Double> v4 = getData(monitorTypeEnum, data).reduce(Double::sum); |
|
|
|
v4.ifPresent(aDouble -> item.setValue((aDouble / data.size()) + "")); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
log.error("未找到对应的枚举值MonitorTypeEnum, key:{}", keys[2]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Stream<Double> getData(MonitorTypeEnum monitorTypeEnum, List<Map<String, Object>> data) { |
|
|
|
return data.stream() |
|
|
|
.map(map -> map.getOrDefault(monitorTypeEnum.getValueField(), "0.0").toString()) |
|
|
|
.filter(StringUtils::isNotBlank) |
|
|
|
.map(Double::parseDouble); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|