demand: TMS系统 - 运输管理 -漏组批次实时扫描/定时扫描/根据线路扫描-性能优化
committer: heyu
This commit is contained in:
parent
d50efbdf17
commit
d26740e8f3
@ -7,6 +7,7 @@ import com.alibaba.excel.annotation.ExcelIgnore;
|
|||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.xdadan.erp.common.core.domain.BaseEntity;
|
import com.xdadan.erp.common.core.domain.BaseEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import com.xdadan.erp.common.annotation.Excel;
|
import com.xdadan.erp.common.annotation.Excel;
|
||||||
import com.alibaba.excel.annotation.ExcelProperty;
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
import com.alibaba.excel.converters.date.DateStringConverter;
|
import com.alibaba.excel.converters.date.DateStringConverter;
|
||||||
@ -19,6 +20,7 @@ import com.alibaba.excel.converters.longconverter.LongNumberConverter;
|
|||||||
* @date 2024-04-22
|
* @date 2024-04-22
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@EqualsAndHashCode(exclude = { "children" })
|
||||||
public class EmisTransPlanRule extends BaseEntity {
|
public class EmisTransPlanRule extends BaseEntity {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|||||||
@ -5299,26 +5299,30 @@ public class EmisBaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. 统计每条路径的匹配度
|
// 2. 统计每条路径的匹配度
|
||||||
Map<List<EmisTransPlanRule>, Integer> pathMatchCountMap = new HashMap<>();
|
// 优化:预先构建filterRules的匹配键,避免重复计算
|
||||||
for (List<EmisTransPlanRule> path : allPaths) {
|
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;
|
int pathMatchCount = 0;
|
||||||
for (EmisTransPlanRule node : path) {
|
for (EmisTransPlanRule node : path) {
|
||||||
for (EmisTransPlanRule filterRule : filterRules) {
|
String nodeKey = node.getStartSiteCode() + "_" + node.getNextSiteCode() + "_" + node.getSupplierCode();
|
||||||
if (Objects.equals(node.getStartSiteCode(), filterRule.getStartSiteCode()) &&
|
if (filterRuleKeys.contains(nodeKey)) {
|
||||||
Objects.equals(node.getNextSiteCode(), filterRule.getNextSiteCode()) &&
|
pathMatchCount++;
|
||||||
compareSupplierCodes(node.getSupplierCode(), filterRule.getSupplierCode())) {
|
|
||||||
pathMatchCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pathMatchCountMap.put(path, pathMatchCount);
|
pathMatchCountMap.put(i, pathMatchCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 过滤出匹配度最高的path(可多个)
|
// 3. 过滤出匹配度最高的path(可多个)
|
||||||
int maxMatch = pathMatchCountMap.values().stream().max(Integer::compareTo).orElse(0);
|
int maxMatch = pathMatchCountMap.values().stream().max(Integer::compareTo).orElse(0);
|
||||||
List<List<EmisTransPlanRule>> bestPaths = pathMatchCountMap.entrySet().stream()
|
List<List<EmisTransPlanRule>> bestPaths = pathMatchCountMap.entrySet().stream()
|
||||||
.filter(e -> e.getValue() == maxMatch)
|
.filter(e -> e.getValue() == maxMatch)
|
||||||
.map(Map.Entry::getKey)
|
.map(e -> allPaths.get(e.getKey()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 4. 对这些path的节点分组去重并做漏组处理
|
// 4. 对这些path的节点分组去重并做漏组处理
|
||||||
@ -5382,11 +5386,12 @@ public class EmisBaseService {
|
|||||||
|
|
||||||
boolean isGroupMatch = false;
|
boolean isGroupMatch = false;
|
||||||
for (List<EmisTransPlanRule> group : groupMap.values()) {
|
for (List<EmisTransPlanRule> group : groupMap.values()) {
|
||||||
// 判断该组是否有匹配
|
// 判断该组是否有匹配 - 优化:使用预构建的匹配键
|
||||||
boolean matched = group.stream().anyMatch(levelRule -> filterRules.stream().anyMatch(
|
boolean matched = group.stream().anyMatch(levelRule -> {
|
||||||
filterRule -> Objects.equals(filterRule.getStartSiteCode(), levelRule.getStartSiteCode()) &&
|
String levelRuleKey = levelRule.getStartSiteCode() + "_" + levelRule.getNextSiteCode() + "_"
|
||||||
Objects.equals(filterRule.getNextSiteCode(), levelRule.getNextSiteCode()) &&
|
+ levelRule.getSupplierCode();
|
||||||
compareSupplierCodes(filterRule.getSupplierCode(), levelRule.getSupplierCode())));
|
return filterRuleKeys.contains(levelRuleKey);
|
||||||
|
});
|
||||||
if (matched) {
|
if (matched) {
|
||||||
isGroupMatch = true;
|
isGroupMatch = true;
|
||||||
if (group.get(0).getChildren() == null) {
|
if (group.get(0).getChildren() == null) {
|
||||||
@ -5400,11 +5405,12 @@ public class EmisBaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (List<EmisTransPlanRule> group : groupMap.values()) {
|
for (List<EmisTransPlanRule> group : groupMap.values()) {
|
||||||
// 判断该组是否有匹配
|
// 判断该组是否有匹配 - 优化:使用预构建的匹配键
|
||||||
boolean matched = group.stream().anyMatch(levelRule -> filterRules.stream().anyMatch(
|
boolean matched = group.stream().anyMatch(levelRule -> {
|
||||||
filterRule -> Objects.equals(filterRule.getStartSiteCode(), levelRule.getStartSiteCode()) &&
|
String levelRuleKey = levelRule.getStartSiteCode() + "_" + levelRule.getNextSiteCode() + "_"
|
||||||
Objects.equals(filterRule.getNextSiteCode(), levelRule.getNextSiteCode()) &&
|
+ levelRule.getSupplierCode();
|
||||||
compareSupplierCodes(filterRule.getSupplierCode(), levelRule.getSupplierCode())));
|
return filterRuleKeys.contains(levelRuleKey);
|
||||||
|
});
|
||||||
if (matched && group.get(0).getChildren() == null) {
|
if (matched && group.get(0).getChildren() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user