Commit 061ba903 authored by tianyiming's avatar tianyiming

修改bug

parent 8d84959f
......@@ -46,9 +46,7 @@ import org.elasticsearch.client.core.CountResponse;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.nested.ParsedNested;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.metrics.ParsedSum;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
......@@ -711,6 +709,9 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
dto.get("unitType").toString().contains("安装改造维修单位"))) {
permissionStatus = noneStr;
}
if(dto.get("unitType").equals("使用单位") || dto.get("unitType").equals("个人主体")){
permissionStatus = null;
}
dto.put("permissionStatus", permissionStatus);
list.add(dto);
}
......@@ -735,7 +736,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
if (!"".equals(permitStatusStr)) {
getFilterCompanyOrPersonPermitStatusStatic(staticMap, StatisticalAnalysisEnum.company.getKey(), permitStatusStr, totle);
} else {
getCompanyOrPersonPermitStatusStatic(boolMust, staticMap, StatisticalAnalysisEnum.person.getKey());
getCompanyOrPersonPermitStatusStatic(boolMust, staticMap, StatisticalAnalysisEnum.company.getKey());
}
result.put("keyIndicator", staticMap);
......@@ -820,7 +821,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
} else if (item.equals(none)) {
NestedQueryBuilder nestedQuery = QueryBuilders.nestedQuery(
path,
QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(nestedField)),
QueryBuilders.boolQuery().mustNot(existsQuery(nestedField)),
ScoreMode.None
);
enhancedDynamicQueryBuilder.add(nestedQuery, or);
......@@ -1020,7 +1021,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
DynamicQueryBuilder dynamicQueryBuilder = new DynamicQueryBuilder();
dynamicQueryBuilder.or(QueryBuilders.prefixQuery("ORG_BRANCH_CODE", orgCode));
dynamicQueryBuilder.or(QueryBuilders.boolQuery().must(QueryBuilders.termQuery("ORG_BRANCH_CODE", "")));
dynamicQueryBuilder.or(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("ORG_BRANCH_CODE")));
dynamicQueryBuilder.or(QueryBuilders.boolQuery().mustNot(existsQuery("ORG_BRANCH_CODE")));
boolMust.must(dynamicQueryBuilder.build());
} else {
boolMust.must(QueryBuilders.prefixQuery("ORG_BRANCH_CODE", orgCode));
......@@ -1064,7 +1065,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
// 正常:大于当前日期加上30天
queryBuilder.add(QueryBuilders.boolQuery().filter(QueryBuilders.rangeQuery(finalField).gt(LocalDate.now().plusDays(30).format(formatter))), or);
} else {
queryBuilder.add(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(finalField)), or);
queryBuilder.add(QueryBuilders.boolQuery().mustNot(existsQuery(finalField)), or);
}
});
boolMust.must(queryBuilder.build());
......@@ -1074,11 +1075,11 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
if ("1".equals(item)) {
queryBuilder.must(QueryBuilders.termsQuery("IS_INTO_MANAGEMENT", Boolean.TRUE))
.must(QueryBuilders.existsQuery("USE_ORG_CODE"));
.must(existsQuery("USE_ORG_CODE"));
} else {
queryBuilder.should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("IS_INTO_MANAGEMENT")))
queryBuilder.should(QueryBuilders.boolQuery().mustNot(existsQuery("IS_INTO_MANAGEMENT")))
.should(QueryBuilders.matchQuery("IS_INTO_MANAGEMENT", Boolean.FALSE))
.should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("USE_ORG_CODE")))
.should(QueryBuilders.boolQuery().mustNot(existsQuery("USE_ORG_CODE")))
.minimumShouldMatch(1);
}
enhancedDynamicQueryBuilder.add(queryBuilder, or);
......@@ -1110,7 +1111,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
if (!item.equals("99")) {
queryBuilder.add(QueryBuilders.matchQuery(k, item.toString()), or);
} else {
queryBuilder.add(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(k)), or);
queryBuilder.add(QueryBuilders.boolQuery().mustNot(existsQuery(k)), or);
}
});
boolMust.must(queryBuilder.build());
......@@ -1289,24 +1290,53 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
private BigDecimal getPipeLength(BoolQueryBuilder boolMust, SearchSourceBuilder builder, String countField) {
SearchRequest request = new SearchRequest();
request.indices(StatisticalAnalysisEnum.equip.getKey());
BigDecimal pipeLong;
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("techParams",
QueryBuilders.boolQuery().must(QueryBuilders.termsQuery("techParams.paramKey", "pipeLength")),
ScoreMode.None);
boolMust.must(nestedQueryBuilder);
builder.query(boolMust).aggregation(AggregationBuilders.nested(countField, "techParams").subAggregation(
AggregationBuilders.sum("pipeLength").field("techParams.doubleValue")
)
);
BigDecimal pipeLong = new BigDecimal(0);
// String painlessScript =
// "double total = 0.0; " +
// "for (int i = 0; i < doc['techParams.doubleValue'].length; i++) { " +
// " if (doc['techParams.paramKey'][i] == 'pipeLength') { " +
// " try { " +
// " total += Double.parseDouble(doc['techParams.doubleValue'][i].toString()); " +
// " } catch (Exception e) {} " +
// " } " +
// "} " +
// "return total;";
// NestedAggregationBuilder nestedAgg = AggregationBuilders.nested(countField, "techParams");
// SumAggregationBuilder sumAgg = AggregationBuilders.sum("pipeLength")
// .script(new Script(ScriptType.INLINE, "painless", painlessScript, Collections.emptyMap()));
// nestedAgg.subAggregation(sumAgg);
builder.query(boolMust).size(10000000);
request.source(builder);
try {
SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
ParsedSum sumAgg = ((ParsedNested) response.getAggregations()
.get(countField))
.getAggregations()
.get("pipeLength");
double value = sumAgg.getValue();
pipeLong = new BigDecimal(value);
JSONArray resultList = new JSONArray();
for (SearchHit hit : response.getHits().getHits()) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(hit);
JSONObject dto = jsonObject.getJSONObject("sourceAsMap");
resultList.add(dto.get("techParams"));
}
for (Object object : resultList) {
JSONArray jsonArray = (JSONArray) object;
for (Object o : jsonArray) {
JSONObject jsonObject = (JSONObject) o;
if(jsonObject.getString("paramKey").equals("pipeLength") && jsonObject.containsKey("doubleValue")){
BigDecimal value = new BigDecimal(jsonObject.get("doubleValue").toString());
pipeLong = pipeLong.add(value);
}
}
}
// // 获取最外层聚合结果
// Aggregations aggregations = response.getAggregations();
// // 1. 获取嵌套聚合结果
// ParsedNested nestedItems = aggregations.get(countField);
// 2. 从嵌套聚合中获取过滤聚合结果
// ParsedFilter filteredItems = nestedItems.getAggregations().get("filtered_items");
// 3. 从过滤聚合中获取指标聚合结果
// ParsedSum totalValue = nestedItems.getAggregations().get("pipeLength");
// double value = 0;
} catch (IOException e) {
throw new RuntimeException(e);
}
......@@ -1801,13 +1831,13 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
// 无许可到期日期
NestedQueryBuilder noneQuery = QueryBuilders.nestedQuery(
path,
QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(nestedField)),
QueryBuilders.boolQuery().mustNot(existsQuery(nestedField)),
ScoreMode.None
);
// 有效许可到期日期
NestedQueryBuilder existsQuery = QueryBuilders.nestedQuery(
path,
QueryBuilders.boolQuery().must(QueryBuilders.existsQuery(nestedField)),
QueryBuilders.boolQuery().must(existsQuery(nestedField)),
ScoreMode.None
);
// 正常许可到期日期
......@@ -3043,7 +3073,9 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
if (groupField.equals("EQU_LIST_CODE")) {
gasBoolQueryBuilder = QueryBuilderUtils.copyBoolQuery(boolMust);
}
boolMust.mustNot(QueryBuilders.matchQuery("EQU_CATEGORY_CODE", "2300"));
if(!"2300".equals(equipCode)){
boolMust.mustNot(QueryBuilders.matchQuery("EQU_CATEGORY_CODE", "2300"));
}
getStatisticCountByGroup(request, builder, boolMust, groupField, staticCountByGroup, "noGas");
AtomicReference<Long> otherCount = new AtomicReference<>(0L);
......@@ -3060,7 +3092,8 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
BoolQueryBuilder queryBuilder = QueryBuilderUtils.copyBoolQuery(pipeBoolMust);
String code = categoryMap.get("value").toString();
codes.add(code);
if (code.startsWith("2300")) {
// 去除类别中的气瓶
if (code.equals("2300")) {
staticCountByGroup.remove(code);
continue;
}
......@@ -3079,7 +3112,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
map.put("img", dpEquipPhotoPrefix + code + dpEquipPhotoSuffix);
Integer count = tzsCustomFilterMapper.selectEquipmentCategoryCountByParentId(categoryMap.get("key").toString());
map.put("noChild", 0 == count ? Boolean.TRUE : Boolean.FALSE);
map.put("measurementUnit", equipCode != null && equipCode.startsWith("8") ? "千米" : equipCode != null && equipCode.startsWith("2") ? "个" : "台套");
map.put("measurementUnit", code.startsWith("8") ? "千米" : code.startsWith("2") ? "个" : "台套");
map.put("noBottom", code.startsWith("8") ? Boolean.TRUE : Boolean.FALSE);
// 统计该分类下的数据完整性的分组数量 DATA_QUALITY_SCORE
BoolQueryBuilder scoreQuery = QueryBuilderUtils.copyBoolQuery(boolMust);
......@@ -3124,7 +3157,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
map.put("measurementUnit", "个");
map.put("noBottom", Boolean.FALSE);
// 统计该分类下的数据完整性的分组数量 DATA_QUALITY_SCORE
BoolQueryBuilder scoreQuery = QueryBuilderUtils.copyBoolQuery(boolMust);
BoolQueryBuilder scoreQuery = QueryBuilderUtils.copyBoolQuery(gasBoolQueryBuilder);
scoreQuery.must(QueryBuilders.termQuery(fieldKey, code));
SearchSourceBuilder scoreBuilder = new SearchSourceBuilder();
Map<String, Object> scoreCountByGroup = new HashMap<>();
......@@ -3132,7 +3165,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
map.put("DATA_QUALITY_SCORE", scoreCountByGroup);
// 统计该分类下红黄绿码分别的分组数量 NEXT_INSPECT_DATE
Map<String, Long> nextInspectCountByGroup = new HashMap<>();
BoolQueryBuilder nextInspectQuery = QueryBuilderUtils.copyBoolQuery(boolMust);
BoolQueryBuilder nextInspectQuery = QueryBuilderUtils.copyBoolQuery(gasBoolQueryBuilder);
nextInspectQuery.must(QueryBuilders.termQuery(fieldKey, code));
getStatisticCountByDate(StatisticalAnalysisEnum.equip.getKey(), "NEXT_INSPECT_DATE", nextInspectQuery, nextInspectCountByGroup);
map.put("NEXT_INSPECT_DATE", nextInspectCountByGroup);
......@@ -3196,7 +3229,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
// 统计该分类下的数据完整性的分组数量 DATA_QUALITY_SCORE
BoolQueryBuilder scoreQuery = QueryBuilderUtils.copyBoolQuery(boolMust);
if (key.equals("NA")) {
scoreQuery.mustNot(QueryBuilders.existsQuery(groupField));
scoreQuery.mustNot(existsQuery(groupField));
} else {
scoreQuery.must(QueryBuilders.termQuery(groupField, key));
}
......@@ -3211,7 +3244,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
Map<String, Long> nextInspectCountByGroup = new HashMap<>();
BoolQueryBuilder nextInspectQuery = QueryBuilderUtils.copyBoolQuery(boolMust);
if (key.equals("NA")) {
nextInspectQuery.mustNot(QueryBuilders.existsQuery(groupField));
nextInspectQuery.mustNot(existsQuery(groupField));
} else {
nextInspectQuery.must(QueryBuilders.termQuery(groupField, key));
}
......@@ -3260,7 +3293,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
Long normalCount = getStatisticCount(normalQuery, index);
// 无日期
BoolQueryBuilder noFieldQuery = QueryBuilderUtils.copyBoolQuery(nextInspectQuery);
noFieldQuery.mustNot(QueryBuilders.existsQuery(field));
noFieldQuery.mustNot(existsQuery(field));
Long noFieldCount = getStatisticCount(noFieldQuery, index);
nextInspectCountByGroup.put("red", overdueCount);
nextInspectCountByGroup.put("yellow", nearCount);
......@@ -3388,7 +3421,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
BoolQueryBuilder nothingBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery);
NestedQueryBuilder nothingNestedQuery = QueryBuilders.nestedQuery(
path,
QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(nestedField)),
QueryBuilders.boolQuery().mustNot(existsQuery(nestedField)),
ScoreMode.None
);
nothingBoolQuery.must(nothingNestedQuery);
......@@ -3487,7 +3520,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
searchSourceBuilder.trackTotalHits(true);
searchSourceBuilder.size(0);// 不返回任何文档,只返回聚合结果
SearchRequest searchRequest = new SearchRequest();
QueryBuilderUtils.buildSplitFieldAggCondition(searchSourceBuilder, itemName + ".keyword", ",", aggName, "其他");
QueryBuilderUtils.buildSplitFieldAggCondition(searchSourceBuilder, itemName + ".keyword", "", aggName, "其他");
searchSourceBuilder.query(boolQuery);
searchRequest.source(searchSourceBuilder);
try {
......@@ -3644,7 +3677,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
BoolQueryBuilder nothingBoolQuery = QueryBuilderUtils.copyBoolQuery(boolQuery);
NestedQueryBuilder nothingNestedQuery = QueryBuilders.nestedQuery(
path,
QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(nestedField)),
QueryBuilders.boolQuery().mustNot(existsQuery(nestedField)),
ScoreMode.None
);
nothingBoolQuery.must(nothingNestedQuery);
......
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