Commit be83eba2 authored by tianyiming's avatar tianyiming

refactor(core): 优化设备统计分析逻辑

parent 224e10de
...@@ -2795,8 +2795,6 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2795,8 +2795,6 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
staticCountByGroupMap = resourceJson.get(EquipmentClassifityEnum.ZHTJFX.getCode()); staticCountByGroupMap = resourceJson.get(EquipmentClassifityEnum.ZHTJFX.getCode());
} }
SearchSourceBuilder nextInspectBuilder = new SearchSourceBuilder();
Map<String, Long> staticCountByGroup = new HashMap<>(); Map<String, Long> staticCountByGroup = new HashMap<>();
getStatisticCountByGroup(request, builder, boolMust, groupField, staticCountByGroup); getStatisticCountByGroup(request, builder, boolMust, groupField, staticCountByGroup);
...@@ -2808,8 +2806,10 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2808,8 +2806,10 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
for (Map<String, Object> categoryMap : staticCountByGroupMap) { for (Map<String, Object> categoryMap : staticCountByGroupMap) {
String code = categoryMap.get("value").toString(); String code = categoryMap.get("value").toString();
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.putAll(categoryMap); map.put("key", categoryMap.get("key"));
map.put("value", staticCountByGroup.get(code)); map.put("label", categoryMap.get("label"));
map.put("code", categoryMap.get("value"));
map.put("value", staticCountByGroup.containsKey(code) ? staticCountByGroup.get(code) : 0);
map.put("img", dpEquipPhotoPrefix + code + dpEquipPhotoSuffix); map.put("img", dpEquipPhotoPrefix + code + dpEquipPhotoSuffix);
map.put("measurementUnit", "台套"); map.put("measurementUnit", "台套");
// 统计该分类下的数据完整性的分组数量 DATA_QUALITY_SCORE // 统计该分类下的数据完整性的分组数量 DATA_QUALITY_SCORE
...@@ -2823,41 +2823,40 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2823,41 +2823,40 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
Map<String, Long> nextInspectCountByGroup = new HashMap<>(); Map<String, Long> nextInspectCountByGroup = new HashMap<>();
BoolQueryBuilder nextInspectQuery = QueryBuilderUtils.copyBoolQuery(boolMust); BoolQueryBuilder nextInspectQuery = QueryBuilderUtils.copyBoolQuery(boolMust);
nextInspectQuery.must(QueryBuilders.termQuery(groupField, code)); nextInspectQuery.must(QueryBuilders.termQuery(groupField, code));
getStatisticCountByDate(StatisticalAnalysisEnum.equip.getKey(), nextInspectQuery, nextInspectCountByGroup); getStatisticCountByDate(StatisticalAnalysisEnum.equip.getKey(), "NEXT_INSPECT_DATE", nextInspectQuery, nextInspectCountByGroup);
getStatisticCountByGroup(request, nextInspectBuilder, nextInspectQuery, "NEXT_INSPECT_DATE", nextInspectCountByGroup);
map.put("NEXT_INSPECT_DATE", nextInspectCountByGroup); map.put("NEXT_INSPECT_DATE", nextInspectCountByGroup);
dataMapList.add(map); dataMapList.add(map);
} }
return dataMapList; return dataMapList;
} }
private void getStatisticCountByDate(String key, BoolQueryBuilder nextInspectQuery, Map<String, Long> nextInspectCountByGroup) { private void getStatisticCountByDate(String index, String field, BoolQueryBuilder nextInspectQuery, Map<String, Long> nextInspectCountByGroup) {
// 超期 // 超期
// BoolQueryBuilder overdueQuery = QueryBuilderUtils.copyBoolQuery(nextInspectQuery); BoolQueryBuilder overdueQuery = QueryBuilderUtils.copyBoolQuery(nextInspectQuery);
// overdueQuery.must(QueryBuilders.rangeQuery("NEXT_INSPECT_DATE").lte(DateUtils.addDays(new Date(), -1))); overdueQuery.filter(QueryBuilders.rangeQuery(field).lt(LocalDate.now().format(formatter)));
// if (item.equals("overdue")) { Long overdueCount = getStatisticCount(overdueQuery, index);
// // 超期:小于当前日期
// queryBuilder.add(QueryBuilders.boolQuery().filter(QueryBuilders.rangeQuery(finalField).lt(LocalDate.now().format(formatter))), or);
// } else if (item.equals("near")) {
// // 临期:小于等于当前日期加上30天
// queryBuilder.add(QueryBuilders.boolQuery().filter(QueryBuilders.rangeQuery(finalField).gte(LocalDate.now().format(formatter)).lte(LocalDate.now().plusDays(30).format(formatter))), or);
// } else if (item.equals("normal")) {
// // 正常:大于当前日期加上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);
// }
// 临期 // 临期
BoolQueryBuilder nearQuery = QueryBuilderUtils.copyBoolQuery(nextInspectQuery);
nearQuery.filter(QueryBuilders.rangeQuery(field).gte(LocalDate.now().format(formatter)).lte(LocalDate.now().plusDays(30).format(formatter)));
Long nearCount = getStatisticCount(nearQuery, index);
// 正常 // 正常
BoolQueryBuilder normalQuery = QueryBuilderUtils.copyBoolQuery(nextInspectQuery);
normalQuery.filter(QueryBuilders.rangeQuery(field).gt(LocalDate.now().plusDays(30).format(formatter)));
Long normalCount = getStatisticCount(normalQuery, index);
// 无日期 // 无日期
BoolQueryBuilder noFieldQuery = QueryBuilderUtils.copyBoolQuery(nextInspectQuery);
noFieldQuery.mustNot(QueryBuilders.existsQuery(field));
Long noFieldCount = getStatisticCount(noFieldQuery, index);
nextInspectCountByGroup.put("red", overdueCount);
nextInspectCountByGroup.put("yellow", nearCount);
nextInspectCountByGroup.put("green", normalCount);
nextInspectCountByGroup.put("gray", noFieldCount);
} }
private void getStatisticCountByGroup(SearchRequest request, SearchSourceBuilder builder, BoolQueryBuilder boolMust, String groupField, Map<String, Long> staticCountByGroup) { private void getStatisticCountByGroup(SearchRequest request, SearchSourceBuilder builder, BoolQueryBuilder boolMust, String groupField, Map<String, Long> staticCountByGroup) {
builder.query(boolMust); builder.query(boolMust);
builder.aggregation(AggregationBuilders.terms("groupCount").field(groupField)); builder.aggregation(AggregationBuilders.terms("groupCount").field(groupField).size(50));
request.source(builder); request.source(builder);
try { try {
SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT); SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
......
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