Commit 9efb7698 authored by tianbo's avatar tianbo

fix(statistics): 修复下钻查询总数不正确的问题

-移除了不必要的 .keyword 后缀,使用 prefixQuery 查询 superviseOrgCode
parent a2a3fa8b
......@@ -257,7 +257,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
String orgCode = filter.getString("orgCode");
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode.keyword", orgCode));
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode));
JSONObject filterParams = null;
if (!ObjectUtils.isEmpty(filter.get("filterParams"))) {
......@@ -2669,7 +2669,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode.keyword", orgCode));
data = queryDpCompanyStatistics(filter, request, builder, boolMust, tabTotalMap);
} else {
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode.keyword", orgCode));
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode));
data = queryDpPersonStatistics(filter, request, builder, boolMust, tabTotalMap);
}
......@@ -2695,7 +2695,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
BoolQueryBuilder companyBoolMust = QueryBuilders.boolQuery();
companyBoolMust.must(QueryBuilders.prefixQuery("superviseOrgCode.keyword", orgCode));
BoolQueryBuilder personBoolMust = QueryBuilders.boolQuery();
personBoolMust.must(QueryBuilders.prefixQuery("superviseOrgCode.keyword", orgCode));
personBoolMust.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode));
String equipIndex = StatisticalAnalysisEnum.equip.getKey();
String companyIndex = StatisticalAnalysisEnum.company.getKey();
String personIndex = StatisticalAnalysisEnum.person.getKey();
......@@ -2830,7 +2830,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
request.indices(StatisticalAnalysisEnum.company.getKey());
JSONObject filterParams = JSONObject.parseObject(JSONObject.toJSONString(filter.get("filterParams")));
String unitCategory = filterParams.getString("unitCategory");
String unitType = filterParams.getJSONArray("unitType").getString(0);
// 构造企业查询条件
filter.put("filterType", "advanced");
getCompanyBoolQueryBuilder(filter, boolMust);
......@@ -2846,11 +2846,20 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
} else {
// 二级统计
Map<String, Object> result = new HashMap<>();
// 使用单位:使用单位,个人主体 返回管控级别和所属行业
String unitType = filterParams.getJSONArray("unitType").getString(0);
// 使用单位:使用单位 返回管控级别和所属行业;个人主体 前端不下钻
boolMust.must(QueryBuilders.matchQuery("unitType", unitType));
if (unitCategory.equals(UnitCategoryEnum.use.getCode())) {
JSONObject regulatoryLabels = this.getItemGroupStatisticsByItemName(boolMust, StatisticalAnalysisEnum.company.getKey(), "regulatoryLabelsAggName", "regulatoryLabels", this::buildRegulatoryLabelsGroupResult);
JSONObject industrySupervisor = this.getItemGroupStatisticsByItemName(boolMust, StatisticalAnalysisEnum.company.getKey(), "industrySupervisorAggName", "industrySupervisor", this::buildIndustrySupervisorGroupResult);
JSONObject regulatoryLabels = this.getItemGroupStatisticsByItemName(boolMust,
StatisticalAnalysisEnum.company.getKey(),
"regulatoryLabelsAggName",
"regulatoryLabels",
this::buildRegulatoryLabelsGroupResult);
JSONObject industrySupervisor = this.getItemGroupStatisticsByItemName(boolMust,
StatisticalAnalysisEnum.company.getKey(),
"industrySupervisorAggName",
"industrySupervisor",
this::buildIndustrySupervisorGroupResult);
result.put("tabTotalMap", new JSONObject()
.fluentPut("regulatoryLabelsTotal", this.sumWithJSONObjectValues(regulatoryLabels))
.fluentPut("industrySupervisorTotal", this.sumWithJSONObjectValues(industrySupervisor)));
......@@ -3078,7 +3087,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
String orgCode = filter.getString("orgCode");
boolQuery.must(QueryBuilders.prefixQuery("superviseOrgCode.keyword", orgCode));
boolQuery.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode));
JSONObject filterParams = JSONObject.parseObject(JSONObject.toJSONString(filter.get("filterParams")));
String filterType = "advanced";
......@@ -3269,22 +3278,10 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
try {
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
Terms itemGroupAgg = searchResponse.getAggregations().get(aggName);
// this.buildGroupResult(itemGroupAgg, result);
task.accept(itemGroupAgg, result);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
CountRequest countRequest = new CountRequest();
countRequest.indices(indexName);
countRequest.query(boolQueryCopy);
CountResponse countResponse;
try {
countResponse = restHighLevelClient.count(countRequest, RequestOptions.DEFAULT);
} catch (Exception exception) {
throw new RuntimeException(exception);
}
result.put("total", ObjectUtils.isEmpty(countResponse) ? 0L : countResponse.getCount());
return result;
}
......@@ -3327,7 +3324,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
String bucketKey = bucket.getKeyAsString();
for (Object obj : regulatoryLabels) {
JSONObject jsonObject = (JSONObject) obj;
result.put(jsonObject.getString("value"), 0);
result.put(jsonObject.getString("extendCode"), 0);
if (jsonObject.getString("label").equals(bucketKey)) {
result.put(jsonObject.getString("extendCode"), bucket.getDocCount());
break;
......@@ -3344,18 +3341,25 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
return;
}
JSONArray industrySupervisor = deployDictionary(dataDictionaryService.getByType("HYZGBM"));
// 枚举遍历 + 动态匹配
for (Terms.Bucket bucket : groupAgg.getBuckets()) {
String bucketKey = bucket.getKeyAsString();
for (Object obj : industrySupervisor) {
JSONObject jsonObject = (JSONObject) obj;
result.put(jsonObject.getString("value"), 0);
if (jsonObject.getString("label").equals(bucketKey)) {
result.put(jsonObject.getString("value"), bucket.getDocCount());
break;
Map<String, String> keyToValueMap = new HashMap<>();
for (Object obj : industrySupervisor) {
if (obj instanceof JSONObject) {
String key = ((JSONObject) obj).getString("key");
String value = ((JSONObject) obj).getString("value");
if (key != null && value != null) {
keyToValueMap.put(key, value);
result.put(value, 0); // 初始化为 0
}
}
if (bucketKey.equals("其他")) {
}
// 处理 buckets
for (Terms.Bucket bucket : groupAgg.getBuckets()) {
String bucketKey = bucket.getKeyAsString();
String mappedValue = keyToValueMap.get(bucketKey);
if (mappedValue != null) {
result.put(mappedValue, bucket.getDocCount());
} else if ("其他".equals(bucketKey)) {
result.put("other", bucket.getDocCount());
}
}
......@@ -3403,7 +3407,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
BoolQueryBuilder nothingBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery);
NestedQueryBuilder nothingNestedQuery = QueryBuilders.nestedQuery(
path,
QueryBuilders.boolQuery().must(QueryBuilders.existsQuery(nestedField)),
QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(nestedField)),
ScoreMode.None
);
nothingBoolQuery.must(nothingNestedQuery);
......
......@@ -454,7 +454,7 @@ public class JGDPStatisticsServiceImpl {
builder.trackTotalHits(true);
request.indices(key);
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode.keyword", orgCode));
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode));
Long personSum = statisticalAnalysisService.getStatisticCount(boolMust, key);
boolMust.must(QueryBuilders.matchQuery("newPost", "6552"));
Long operatorsNum = statisticalAnalysisService.getStatisticCount(boolMust, key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment