Commit 9efb7698 authored by tianbo's avatar tianbo

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

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