Skip to content

Commit e984605

Browse files
WangXu10fit2-zhao
authored andcommitted
fix: industry
--bug=1063849 --user=王旭 【客户/线索/商机】高级筛选-行业字段-筛选条件错误-筛选报错 https://www.tapd.cn/34675357/s/1803330
1 parent 7d332b1 commit e984605

2 files changed

Lines changed: 64 additions & 4 deletions

File tree

backend/crm/src/main/java/cn/cordys/common/utils/ConditionFilterUtils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
import org.springframework.stereotype.Component;
2929

3030
import java.util.ArrayList;
31+
import java.util.Arrays;
3132
import java.util.List;
3233
import java.util.Objects;
34+
import java.util.stream.Collectors;
35+
36+
import static cn.cordys.common.utils.IndustryUtils.getIndustries;
3337

3438
/**
3539
* @Author: jianxing
@@ -152,6 +156,20 @@ private static void parseCondition(CombineSearch combineSearch) {
152156
List<String> attachmentIds = Objects.requireNonNull(attachmentMapper).getAttachmentIdsByNames(attachmentNames);
153157
item.setValue(CollectionUtils.isEmpty(attachmentIds) ? attachmentNames : attachmentIds);
154158
}
159+
160+
161+
if (item.getValue() != null && Strings.CS.equals(item.getType(), FieldType.INDUSTRY.name())) {
162+
String str = item.getValue().toString()
163+
.replace("[", "")
164+
.replace("]", "");
165+
166+
List<String> list = Arrays.stream(str.split(","))
167+
.map(String::trim)
168+
.collect(Collectors.toList());
169+
List<String> values = IndustryUtils.getValues(getIndustries(), list);
170+
values.addAll(list);
171+
item.setValue(values.stream().distinct().toList());
172+
}
155173
});
156174
replaceCurrentUser(validConditions);
157175
}

backend/crm/src/main/java/cn/cordys/common/utils/IndustryUtils.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
import java.io.InputStream;
1212
import java.lang.ref.SoftReference;
13-
import java.util.ArrayList;
14-
import java.util.LinkedList;
15-
import java.util.List;
16-
import java.util.Queue;
13+
import java.util.*;
1714

1815
/**
1916
* @author song-cc-rock
@@ -108,4 +105,49 @@ private static boolean findRecursive(List<IndustryDict> industryTree, Queue<Stri
108105
}
109106
return false;
110107
}
108+
109+
110+
public static List<String> getValues(List<IndustryDict> tree, List<String> targetValues) {
111+
List<String> result = new ArrayList<>();
112+
113+
for (String target : targetValues) {
114+
List<String> values = getValuesForSingle(tree, target);
115+
if (values != null) {
116+
result.addAll(values);
117+
}
118+
}
119+
return result;
120+
}
121+
122+
/**
123+
* 查找单个 value,并返回其所有子节点 value
124+
*/
125+
private static List<String> getValuesForSingle(List<IndustryDict> tree, String targetValue) {
126+
for (IndustryDict node : tree) {
127+
if (node.getValue().equals(targetValue)) {
128+
List<String> result = new ArrayList<>();
129+
collectValues(node, result);
130+
return result;
131+
}
132+
133+
if (node.getChildren() != null) {
134+
List<String> res = getValuesForSingle(node.getChildren(), targetValue);
135+
if (res != null) return res;
136+
}
137+
}
138+
return null;
139+
}
140+
141+
/**
142+
* 收集节点自身和所有子节点的 value
143+
*/
144+
private static void collectValues(IndustryDict node, List<String> result) {
145+
result.add(node.getValue());
146+
147+
if (node.getChildren() != null) {
148+
for (IndustryDict child : node.getChildren()) {
149+
collectValues(child, result);
150+
}
151+
}
152+
}
111153
}

0 commit comments

Comments
 (0)