Commit 70947d80 authored by tianbo's avatar tianbo

refactor(amos-boot-module-statistics): 优化单位类型统计逻辑- 新增 companyCount…

refactor(amos-boot-module-statistics): 优化单位类型统计逻辑- 新增 companyCount 变量,用于存储公司数量统计结果- 修改监管标签和行业主管统计中的总数计算方式,使用 companyCount 替代原有逻辑 -优化 getItemGroupStatisticsByItemName 方法,使用 Map 映射监管标签,提高性能 - 移除未使用的 boolQueryCopy 变量
parent ca437994
......@@ -2853,6 +2853,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
String unitType = filterParams.getJSONArray("unitType").getString(0);
// 使用单位:使用单位 返回管控级别和所属行业;个人主体 前端不下钻
boolMust.must(QueryBuilders.matchQuery("unitType", unitType));
Long companyCount = getStatisticCount(boolMust, StatisticalAnalysisEnum.company.getKey());
if (unitCategory.equals(UnitCategoryEnum.use.getCode())) {
JSONObject regulatoryLabels = this.getItemGroupStatisticsByItemName(boolMust,
StatisticalAnalysisEnum.company.getKey(),
......@@ -2864,8 +2865,9 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
"industrySupervisorAggName",
"industrySupervisor",
this::buildIndustrySupervisorGroupResult);
result.put("tabTotalMap", new JSONObject()
.fluentPut("regulatoryLabelsTotal", this.sumWithJSONObjectValues(regulatoryLabels))
.fluentPut("regulatoryLabelsTotal", companyCount)
.fluentPut("industrySupervisorTotal", this.sumWithJSONObjectValues(industrySupervisor)));
result.put("datas", new JSONObject()
.fluentPut("regulatoryLabels", regulatoryLabels)
......@@ -2873,7 +2875,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
} else if (unitCategory.equals(UnitCategoryEnum.license.getCode())) {// 许可单位:设计单位、制造单位、充装单位、检验机构、检查机构、安装改造维修单位
JSONObject permitStatus = getPermitStatusGroupStatistics(boolMust);
result.put("tabTotalMap", new JSONObject()
.fluentPut("permitStatusTotal", this.sumWithJSONObjectValues(permitStatus)));
.fluentPut("permitStatusTotal", companyCount));
result.put("datas", new JSONObject()
.fluentPut("permitStatus", permitStatus));
}
......@@ -3269,8 +3271,6 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
private JSONObject getItemGroupStatisticsByItemName(BoolQueryBuilder boolQuery, String indexName, String aggName, String itemName, BiConsumer<Terms, JSONObject> task) {
JSONObject result = new JSONObject();
// copy一份,避免后续两部分逻辑不一致
BoolQueryBuilder boolQueryCopy = QueryBuilderUtils.copyBoolQuery(boolQuery);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.trackTotalHits(true);
......@@ -3323,21 +3323,43 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
return;
}
JSONArray regulatoryLabels = deployDictionary(dataDictionaryService.getByType("QYBQ"));
// 枚举遍历 + 动态匹配
for (Terms.Bucket bucket : groupAgg.getBuckets()) {
String bucketKey = bucket.getKeyAsString();
for (Object obj : regulatoryLabels) {
JSONObject jsonObject = (JSONObject) obj;
result.put(jsonObject.getString("extendCode"), 0);
if (jsonObject.getString("label").equals(bucketKey)) {
result.put(jsonObject.getString("extendCode"), bucket.getDocCount());
break;
Map<String, String> keyToValueMap = new HashMap<>();
for (Object obj : regulatoryLabels) {
if (obj instanceof JSONObject) {
String key = ((JSONObject) obj).getString("key");
String value = ((JSONObject) obj).getString("extendCode");
if (key != null && value != null) {
keyToValueMap.put(key, value);
result.put(value, 0); // 初始化为 0
}
}
if (bucketKey.equals("其他")) {
}
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());
}
}
// for (Terms.Bucket bucket : groupAgg.getBuckets()) {
// String bucketKey = bucket.getKeyAsString();
// for (Object obj : regulatoryLabels) {
// JSONObject jsonObject = (JSONObject) obj;
// result.put(jsonObject.getString("extendCode"), 0);
// if (jsonObject.getString("label").equals(bucketKey)) {
// result.put(jsonObject.getString("extendCode"), bucket.getDocCount());
// break;
// }
// }
// if (bucketKey.equals("其他")) {
// result.put("other", bucket.getDocCount());
// }
// }
}
private void buildIndustrySupervisorGroupResult(Terms groupAgg, JSONObject result) {
......
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