demand: TMS系统 - 运输管理 -漏组批次实时扫描/定时扫描/根据线路扫描-性能优化

committer: heyu
This commit is contained in:
aike 2025-10-24 15:34:39 +08:00
parent d50efbdf17
commit d26740e8f3
2 changed files with 28 additions and 20 deletions

View File

@ -7,6 +7,7 @@ import com.alibaba.excel.annotation.ExcelIgnore;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xdadan.erp.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.xdadan.erp.common.annotation.Excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.converters.date.DateStringConverter;
@ -19,6 +20,7 @@ import com.alibaba.excel.converters.longconverter.LongNumberConverter;
* @date 2024-04-22
*/
@Data
@EqualsAndHashCode(exclude = { "children" })
public class EmisTransPlanRule extends BaseEntity {
private static final long serialVersionUID = 1L;

View File

@ -5299,26 +5299,30 @@ public class EmisBaseService {
}
// 2. 统计每条路径的匹配度
Map<List<EmisTransPlanRule>, Integer> pathMatchCountMap = new HashMap<>();
for (List<EmisTransPlanRule> path : allPaths) {
// 优化:预先构建filterRules的匹配键,避免重复计算
Set<String> filterRuleKeys = filterRules.stream()
.map(r -> r.getStartSiteCode() + "_" + r.getNextSiteCode() + "_" + r.getSupplierCode())
.collect(Collectors.toSet());
// 优化:使用路径索引而不是List作为key,避免hashCode计算问题
Map<Integer, Integer> pathMatchCountMap = new HashMap<>();
for (int i = 0; i < allPaths.size(); i++) {
List<EmisTransPlanRule> path = allPaths.get(i);
int pathMatchCount = 0;
for (EmisTransPlanRule node : path) {
for (EmisTransPlanRule filterRule : filterRules) {
if (Objects.equals(node.getStartSiteCode(), filterRule.getStartSiteCode()) &&
Objects.equals(node.getNextSiteCode(), filterRule.getNextSiteCode()) &&
compareSupplierCodes(node.getSupplierCode(), filterRule.getSupplierCode())) {
pathMatchCount++;
}
String nodeKey = node.getStartSiteCode() + "_" + node.getNextSiteCode() + "_" + node.getSupplierCode();
if (filterRuleKeys.contains(nodeKey)) {
pathMatchCount++;
}
}
pathMatchCountMap.put(path, pathMatchCount);
pathMatchCountMap.put(i, pathMatchCount);
}
// 3. 过滤出匹配度最高的path(可多个)
int maxMatch = pathMatchCountMap.values().stream().max(Integer::compareTo).orElse(0);
List<List<EmisTransPlanRule>> bestPaths = pathMatchCountMap.entrySet().stream()
.filter(e -> e.getValue() == maxMatch)
.map(Map.Entry::getKey)
.map(e -> allPaths.get(e.getKey()))
.collect(Collectors.toList());
// 4. 对这些path的节点分组去重并做漏组处理
@ -5382,11 +5386,12 @@ public class EmisBaseService {
boolean isGroupMatch = false;
for (List<EmisTransPlanRule> group : groupMap.values()) {
// 判断该组是否有匹配
boolean matched = group.stream().anyMatch(levelRule -> filterRules.stream().anyMatch(
filterRule -> Objects.equals(filterRule.getStartSiteCode(), levelRule.getStartSiteCode()) &&
Objects.equals(filterRule.getNextSiteCode(), levelRule.getNextSiteCode()) &&
compareSupplierCodes(filterRule.getSupplierCode(), levelRule.getSupplierCode())));
// 判断该组是否有匹配 - 优化:使用预构建的匹配键
boolean matched = group.stream().anyMatch(levelRule -> {
String levelRuleKey = levelRule.getStartSiteCode() + "_" + levelRule.getNextSiteCode() + "_"
+ levelRule.getSupplierCode();
return filterRuleKeys.contains(levelRuleKey);
});
if (matched) {
isGroupMatch = true;
if (group.get(0).getChildren() == null) {
@ -5400,11 +5405,12 @@ public class EmisBaseService {
}
for (List<EmisTransPlanRule> group : groupMap.values()) {
// 判断该组是否有匹配
boolean matched = group.stream().anyMatch(levelRule -> filterRules.stream().anyMatch(
filterRule -> Objects.equals(filterRule.getStartSiteCode(), levelRule.getStartSiteCode()) &&
Objects.equals(filterRule.getNextSiteCode(), levelRule.getNextSiteCode()) &&
compareSupplierCodes(filterRule.getSupplierCode(), levelRule.getSupplierCode())));
// 判断该组是否有匹配 - 优化:使用预构建的匹配键
boolean matched = group.stream().anyMatch(levelRule -> {
String levelRuleKey = levelRule.getStartSiteCode() + "_" + levelRule.getNextSiteCode() + "_"
+ levelRule.getSupplierCode();
return filterRuleKeys.contains(levelRuleKey);
});
if (matched && group.get(0).getChildren() == null) {
return;
}