|
|
@ -0,0 +1,205 @@ |
|
|
|
|
|
package com.inspect.analysis.service; |
|
|
|
|
|
|
|
|
|
|
|
import com.inspect.analysis.domain.AlgValue; |
|
|
|
|
|
import com.inspect.base.core.constant.AlgConstants; |
|
|
|
|
|
import com.inspect.base.core.utils.StringUtils; |
|
|
|
|
|
import com.inspect.partrolresult.domain.AlgInfo; |
|
|
|
|
|
import com.inspect.task.domain.PatrolData; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
import java.util.Comparator; |
|
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
|
|
import java.util.LinkedHashSet; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
import java.util.function.Function; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 将缺陷分析明细按任务、对象和算法聚合为列表展示记录。 |
|
|
|
|
|
*/ |
|
|
|
|
|
public final class DefectListAggregator { |
|
|
|
|
|
|
|
|
|
|
|
private DefectListAggregator() { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static List<PatrolData> aggregate(List<PatrolData> source, List<AlgInfo> algInfos) { |
|
|
|
|
|
if (source == null || source.isEmpty()) { |
|
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> algNameMap = algInfos == null ? Collections.emptyMap() : algInfos.stream() |
|
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
|
.filter(item -> StringUtils.isNotEmpty(item.getAlgSubtypeCode())) |
|
|
|
|
|
.collect(Collectors.toMap(AlgInfo::getAlgSubtypeCode, AlgInfo::getAlgSubtypeName, |
|
|
|
|
|
(first, ignored) -> first)); |
|
|
|
|
|
|
|
|
|
|
|
Map<GroupKey, List<PatrolData>> groups = new LinkedHashMap<>(); |
|
|
|
|
|
for (PatrolData item : source) { |
|
|
|
|
|
if (item == null || !"0".equals(item.getWarnStatus()) |
|
|
|
|
|
|| AlgConstants.CORRECTION.equals(item.getAlgType())) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
item.setAlgName(algNameMap.getOrDefault(item.getAlgType(), "")); |
|
|
|
|
|
prepareItem(item); |
|
|
|
|
|
GroupKey key = new GroupKey(item.getTaskPatrolId(), item.getObjectId(), item.getAlgType()); |
|
|
|
|
|
groups.computeIfAbsent(key, ignored -> new ArrayList<>()).add(item); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<PatrolData> result = new ArrayList<>(); |
|
|
|
|
|
for (Map.Entry<GroupKey, List<PatrolData>> entry : groups.entrySet()) { |
|
|
|
|
|
result.add(merge(entry.getKey(), entry.getValue())); |
|
|
|
|
|
} |
|
|
|
|
|
result.sort(Comparator.comparingInt(item -> statusRank(item.getResStatus()))); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static List<PatrolData> page(List<PatrolData> source, Integer pageNum, Integer pageSize) { |
|
|
|
|
|
if (source == null || source.isEmpty()) { |
|
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
|
} |
|
|
|
|
|
int safePageNum = pageNum == null || pageNum < 1 ? 1 : pageNum; |
|
|
|
|
|
int safePageSize = pageSize == null || pageSize < 1 ? 10 : pageSize; |
|
|
|
|
|
long from = (long) (safePageNum - 1) * safePageSize; |
|
|
|
|
|
if (from >= source.size()) { |
|
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
|
} |
|
|
|
|
|
int fromIndex = (int) from; |
|
|
|
|
|
long to = Math.min((long) source.size(), from + safePageSize); |
|
|
|
|
|
int toIndex = (int) to; |
|
|
|
|
|
return source.subList(fromIndex, toIndex); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void prepareItem(PatrolData item) { |
|
|
|
|
|
if ("1".equals(item.getFilter()) && StringUtils.isNotEmpty(item.getImageNormalUrlPath())) { |
|
|
|
|
|
item.setImg(item.getImageNormalUrlPath()); |
|
|
|
|
|
} |
|
|
|
|
|
if (item.getResValue() != null && "meter".equals(item.getAlgType())) { |
|
|
|
|
|
String value = new AlgValue().formatValue(item.getResValue()); |
|
|
|
|
|
if ("-1".equals(value)) { |
|
|
|
|
|
item.setResValue("空值"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static PatrolData merge(GroupKey key, List<PatrolData> values) { |
|
|
|
|
|
PatrolData result = new PatrolData(); |
|
|
|
|
|
result.setTaskPatrolId(key.taskPatrolId); |
|
|
|
|
|
result.setObjectId(key.objectId); |
|
|
|
|
|
result.setAlgType(key.algType); |
|
|
|
|
|
result.setDesc(joinDistinct(values, PatrolData::getDesc)); |
|
|
|
|
|
|
|
|
|
|
|
for (PatrolData item : values) { |
|
|
|
|
|
if ("1".equals(item.getFilter())) { |
|
|
|
|
|
// if (StringUtils.isEmpty(result.getImgAnalyse())) { |
|
|
|
|
|
// result.setImgAnalyse(item.getImgAnalyse()); |
|
|
|
|
|
// } |
|
|
|
|
|
if (StringUtils.isEmpty(result.getImg())) { |
|
|
|
|
|
result.setImg(item.getImg()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if ("0".equals(item.getFilter())) { |
|
|
|
|
|
if (StringUtils.isNotEmpty(item.getImgAnalyse())) { |
|
|
|
|
|
result.setImgAnalyse(item.getImgAnalyse()); |
|
|
|
|
|
} |
|
|
|
|
|
// if (StringUtils.isNotEmpty(item.getImg())) { |
|
|
|
|
|
// result.setImg(item.getImg()); |
|
|
|
|
|
// } |
|
|
|
|
|
} |
|
|
|
|
|
// if (StringUtils.isEmpty(result.getImg())) { |
|
|
|
|
|
// if (StringUtils.isNotEmpty(item.getImgAnalyse())) { |
|
|
|
|
|
// result.setImgAnalyse(item.getImgAnalyse()); |
|
|
|
|
|
// } |
|
|
|
|
|
// if (StringUtils.isNotEmpty(item.getImg())) { |
|
|
|
|
|
// result.setImg(item.getImg()); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
result.setImageNormalUrlPath(firstNonEmpty(values, PatrolData::getImageNormalUrlPath)); |
|
|
|
|
|
result.setFilePath(firstNonEmpty(values, PatrolData::getFilePath)); |
|
|
|
|
|
result.setAlgName(firstNonEmpty(values, PatrolData::getAlgName)); |
|
|
|
|
|
result.setAreaName(firstNonEmpty(values, PatrolData::getAreaName)); |
|
|
|
|
|
// result.setBrightDesc(firstNonEmpty(values, PatrolData::getBrightDesc)); |
|
|
|
|
|
// result.setBrightImgAnalyse(firstNonEmpty(values, PatrolData::getBrightImgAnalyse)); |
|
|
|
|
|
// result.setBrightResStatus(firstNonEmpty(values, PatrolData::getBrightResStatus)); |
|
|
|
|
|
result.setChannelName(firstNonEmpty(values, PatrolData::getChannelName)); |
|
|
|
|
|
result.setDataType(firstNonEmpty(values, PatrolData::getDataType)); |
|
|
|
|
|
result.setDeviceName(firstNonEmpty(values, PatrolData::getDeviceName)); |
|
|
|
|
|
result.setDeviceSource(firstNonEmpty(values, PatrolData::getDeviceSource)); |
|
|
|
|
|
result.setImgType(firstNonEmpty(values, PatrolData::getImgType)); |
|
|
|
|
|
result.setLineId(joinDistinct(values, PatrolData::getLineId)); |
|
|
|
|
|
result.setPatrolTime(firstNonEmpty(values, PatrolData::getPatrolTime)); |
|
|
|
|
|
result.setPointId(firstNonEmpty(values, PatrolData::getPointId)); |
|
|
|
|
|
result.setPointName(firstNonEmpty(values, PatrolData::getPointName)); |
|
|
|
|
|
result.setPointStatus(firstNonEmpty(values, PatrolData::getPointStatus)); |
|
|
|
|
|
result.setRequestId(firstNonEmpty(values, PatrolData::getRequestId)); |
|
|
|
|
|
result.setResValue(firstNonEmpty(values, PatrolData::getResValue)); |
|
|
|
|
|
result.setResStatus(firstNonEmpty(values, PatrolData::getResStatus)); |
|
|
|
|
|
result.setSuggestion(firstNonEmpty(values, PatrolData::getSuggestion)); |
|
|
|
|
|
result.setWarnStatus("0"); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static String firstNonEmpty(List<PatrolData> values, Function<PatrolData, String> getter) { |
|
|
|
|
|
return values.stream().map(getter).filter(StringUtils::isNotEmpty).findFirst().orElse(""); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static String joinDistinct(List<PatrolData> values, Function<PatrolData, String> getter) { |
|
|
|
|
|
Set<String> distinct = new LinkedHashSet<>(); |
|
|
|
|
|
for (PatrolData value : values) { |
|
|
|
|
|
String item = getter.apply(value); |
|
|
|
|
|
if (StringUtils.isNotEmpty(item)) { |
|
|
|
|
|
distinct.add(item); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return String.join(",", distinct); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static int statusRank(String status) { |
|
|
|
|
|
if ("1".equals(status)) { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
if ("3".equals(status)) { |
|
|
|
|
|
return 2; |
|
|
|
|
|
} |
|
|
|
|
|
if ("2".equals(status)) { |
|
|
|
|
|
return 3; |
|
|
|
|
|
} |
|
|
|
|
|
return 10; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static final class GroupKey { |
|
|
|
|
|
private final String taskPatrolId; |
|
|
|
|
|
private final String objectId; |
|
|
|
|
|
private final String algType; |
|
|
|
|
|
|
|
|
|
|
|
private GroupKey(String taskPatrolId, String objectId, String algType) { |
|
|
|
|
|
this.taskPatrolId = taskPatrolId; |
|
|
|
|
|
this.objectId = objectId; |
|
|
|
|
|
this.algType = algType; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean equals(Object other) { |
|
|
|
|
|
if (this == other) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
if (!(other instanceof GroupKey)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
GroupKey that = (GroupKey) other; |
|
|
|
|
|
return Objects.equals(taskPatrolId, that.taskPatrolId) |
|
|
|
|
|
&& Objects.equals(objectId, that.objectId) |
|
|
|
|
|
&& Objects.equals(algType, that.algType); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public int hashCode() { |
|
|
|
|
|
return Objects.hash(taskPatrolId, objectId, algType); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |