|
@@ -29,6 +29,7 @@ import cn.cslg.pas.service.query.FormatQueryService;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.PageUtil;
|
|
import cn.hutool.core.util.PageUtil;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
|
+import co.elastic.clients.elasticsearch._types.FieldValue;
|
|
import co.elastic.clients.elasticsearch._types.InlineScript;
|
|
import co.elastic.clients.elasticsearch._types.InlineScript;
|
|
import co.elastic.clients.elasticsearch._types.Refresh;
|
|
import co.elastic.clients.elasticsearch._types.Refresh;
|
|
import co.elastic.clients.elasticsearch._types.Script;
|
|
import co.elastic.clients.elasticsearch._types.Script;
|
|
@@ -60,6 +61,8 @@ import org.springframework.util.CollectionUtils;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.function.BiConsumer;
|
|
import java.util.function.BiConsumer;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -654,35 +657,48 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
|
|
|
|
|
|
|
|
|
|
List<String> mergeList = new ArrayList<>();
|
|
List<String> mergeList = new ArrayList<>();
|
|
- if (type == 0) {
|
|
|
|
- Aggregate agg = response.aggregations().get("Agg");
|
|
|
|
- Aggregate nestedAgg = agg.nested().aggregations().get("nestedAgg");
|
|
|
|
- List<StringTermsBucket> buckets = nestedAgg.sterms().buckets().array();
|
|
|
|
- for (StringTermsBucket bucket : buckets) {
|
|
|
|
- String value = bucket.key().stringValue();
|
|
|
|
- mergeList.add(value);
|
|
|
|
- }
|
|
|
|
- Aggregate rightAgg = response.aggregations().get("rightAgg");
|
|
|
|
- Aggregate rightNestedAgg = rightAgg.nested().aggregations().get("rightNestedAgg");
|
|
|
|
- List<StringTermsBucket> bucketList = rightNestedAgg.sterms().buckets().array();
|
|
|
|
- if (!CollectionUtils.isEmpty(bucketList)) {
|
|
|
|
- for (StringTermsBucket bucket : bucketList) {
|
|
|
|
- String value = bucket.key().stringValue();
|
|
|
|
- mergeList.add(value);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(condition)) {
|
|
|
|
+ List<String> expresses = getConditionExpress(condition);
|
|
|
|
+ Aggregate terms = totalAgg.nested().aggregations().get("terms");
|
|
|
|
+ List<StringTermsBucket> termsBucketList = terms.sterms().buckets().array();
|
|
|
|
+ List<String> merges = termsBucketList.stream().map(StringTermsBucket::key).map(FieldValue::stringValue)
|
|
|
|
+ .filter(value -> expresses.stream().anyMatch(express -> value.contains(express)))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ total = total > merges.size() ? merges.size() : total;
|
|
|
|
+ merges = merges.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
|
|
|
|
+ mergeList.addAll(merges);
|
|
} else {
|
|
} else {
|
|
- Aggregate inventorAgg = response.aggregations().get("Agg");
|
|
|
|
- Aggregate inventorNestedAgg = inventorAgg.nested().aggregations().get("nestedAgg");
|
|
|
|
- List<StringTermsBucket> bucketList = inventorNestedAgg.sterms().buckets().array();
|
|
|
|
- if (!CollectionUtils.isEmpty(bucketList)) {
|
|
|
|
- for (StringTermsBucket bucket : bucketList) {
|
|
|
|
|
|
+ if (type == 0) {
|
|
|
|
+ Aggregate agg = response.aggregations().get("Agg");
|
|
|
|
+ Aggregate nestedAgg = agg.nested().aggregations().get("nestedAgg");
|
|
|
|
+ List<StringTermsBucket> buckets = nestedAgg.sterms().buckets().array();
|
|
|
|
+ for (StringTermsBucket bucket : buckets) {
|
|
String value = bucket.key().stringValue();
|
|
String value = bucket.key().stringValue();
|
|
mergeList.add(value);
|
|
mergeList.add(value);
|
|
}
|
|
}
|
|
|
|
+ Aggregate rightAgg = response.aggregations().get("rightAgg");
|
|
|
|
+ Aggregate rightNestedAgg = rightAgg.nested().aggregations().get("rightNestedAgg");
|
|
|
|
+ List<StringTermsBucket> bucketList = rightNestedAgg.sterms().buckets().array();
|
|
|
|
+ if (!CollectionUtils.isEmpty(bucketList)) {
|
|
|
|
+ for (StringTermsBucket bucket : bucketList) {
|
|
|
|
+ String value = bucket.key().stringValue();
|
|
|
|
+ mergeList.add(value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ Aggregate inventorAgg = response.aggregations().get("Agg");
|
|
|
|
+ Aggregate inventorNestedAgg = inventorAgg.nested().aggregations().get("nestedAgg");
|
|
|
|
+ List<StringTermsBucket> bucketList = inventorNestedAgg.sterms().buckets().array();
|
|
|
|
+ if (!CollectionUtils.isEmpty(bucketList)) {
|
|
|
|
+ for (StringTermsBucket bucket : bucketList) {
|
|
|
|
+ String value = bucket.key().stringValue();
|
|
|
|
+ mergeList.add(value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
List<String> nameList = mergeList.stream().distinct().collect(Collectors.toList());
|
|
List<String> nameList = mergeList.stream().distinct().collect(Collectors.toList());
|
|
if (!CollectionUtils.isEmpty(nameList)) {
|
|
if (!CollectionUtils.isEmpty(nameList)) {
|
|
for (String name : nameList) {
|
|
for (String name : nameList) {
|
|
@@ -723,6 +739,79 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
|
|
return records;
|
|
return records;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private List<String> getConditionExpress(String input) {
|
|
|
|
+ // 编写正则表达式来匹配 = 后面的双括号内的内容
|
|
|
|
+ String regex = "=\\(\\(([^)]*)\\)\\)";
|
|
|
|
+ // 编译正则表达式
|
|
|
|
+ Pattern pattern = Pattern.compile(regex);
|
|
|
|
+ // 创建matcher对象
|
|
|
|
+ Matcher matcher = pattern.matcher(input);
|
|
|
|
+ // 使用List来存储结果,因为数组的大小是固定的
|
|
|
|
+ List<String> values = new ArrayList<>();
|
|
|
|
+ // 查找所有匹配项
|
|
|
|
+ while (matcher.find()) {
|
|
|
|
+ // 提取双括号中的内容
|
|
|
|
+ String content = matcher.group(1);
|
|
|
|
+ // 将提取的内容添加到列表中
|
|
|
|
+ values.add(content);
|
|
|
|
+ }
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ List<String> collect = values.stream().filter(cn.cslg.pas.common.utils.StringUtils::isNotEmpty).distinct().collect(Collectors.toList());
|
|
|
|
+ for (String s : collect) {
|
|
|
|
+ List<String> split = splitWithQuotes(s);
|
|
|
|
+ list.addAll(split);
|
|
|
|
+ }
|
|
|
|
+ List<String> list1 = new ArrayList<>();
|
|
|
|
+ for (String s : list) {
|
|
|
|
+ if (s.contains("\"")) {
|
|
|
|
+ String replace = s.replace("\"", "");
|
|
|
|
+ list1.add(replace);
|
|
|
|
+ } else {
|
|
|
|
+ list1.add(s);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return list1.stream().filter(cn.cslg.pas.common.utils.StringUtils::isNotEmpty).distinct().collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static List<String> splitWithQuotes(String input) {
|
|
|
|
+ List<String> result = new ArrayList<>();
|
|
|
|
+ StringBuilder currentPart = new StringBuilder();
|
|
|
|
+ boolean inQuotes = false;
|
|
|
|
+ for (int i = 0; i < input.length(); i++) {
|
|
|
|
+ char c = input.charAt(i);
|
|
|
|
+ if (c == '"' || c == '\'') {
|
|
|
|
+ // 切换引号状态
|
|
|
|
+ inQuotes = !inQuotes;
|
|
|
|
+ // 如果我们不是在引号内,并且前面有内容,则添加当前部分到结果中
|
|
|
|
+ if (!inQuotes && currentPart.length() > 0) {
|
|
|
|
+ result.add(currentPart.toString());
|
|
|
|
+ currentPart.setLength(0); // 重置当前部分
|
|
|
|
+ }
|
|
|
|
+ // 引号内的字符直接添加到当前部分
|
|
|
|
+ currentPart.append(c);
|
|
|
|
+ // 如果引号后面紧跟着的是空格,并且我们刚刚离开了引号,则跳过这个空格
|
|
|
|
+ if (i + 1 < input.length() && input.charAt(i + 1) == ' ' && !inQuotes) {
|
|
|
|
+ i++; // 跳过空格
|
|
|
|
+ }
|
|
|
|
+ } else if (c == ' ' && !inQuotes) {
|
|
|
|
+ // 如果我们在空格处且不在引号内,则添加当前部分到结果中,并重置当前部分
|
|
|
|
+ if (currentPart.length() > 0) {
|
|
|
|
+ result.add(currentPart.toString());
|
|
|
|
+ currentPart.setLength(0);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 其他字符直接添加到当前部分
|
|
|
|
+ currentPart.append(c);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 添加最后一个部分(如果有的话)
|
|
|
|
+ if (currentPart.length() > 0) {
|
|
|
|
+ result.add(currentPart.toString());
|
|
|
|
+ }
|
|
|
|
+ // 将List转换为数组
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
/*public Records getAllMergePerson1(GetAllPersonVO vo) throws Exception {
|
|
/*public Records getAllMergePerson1(GetAllPersonVO vo) throws Exception {
|
|
Integer projectId = vo.getProjectId();
|
|
Integer projectId = vo.getProjectId();
|
|
Long pageNum = vo.getPageNum();
|
|
Long pageNum = vo.getPageNum();
|