Commit ad0f5d43 authored by tianbo's avatar tianbo

refactor(amos-boot-module-statistics): 优化设备总数统计逻辑- 修改了设备总数统计方法,不再直接使用 countMap 的总和

- 新增 queryHasSupervisoryCodeEquipCount 方法,专门用于统计已赋码设备数量
parent 8338e8fe
......@@ -302,7 +302,8 @@ public class StCommonServiceImpl {
result.put(this.castCategoryCode2WebCode(c.getCode()), countMap.getOrDefault(c.getCode(), 0L));
});
// 注意,求总数时:countMap不包括气瓶数量、压力管道数量(20240819修改)
result.put(DPMapStatisticsItemEnum.TOTAL.getCode(), countMap.values().stream().mapToLong(e -> e).sum());
// 总数为已赋码设备数量,需要单独统计
result.put(DPMapStatisticsItemEnum.TOTAL.getCode(), queryHasSupervisoryCodeEquipCount(orgCode, isOrgBranchCodeExactMatch, cylinderNum));
} catch (IOException e) {
throw new RuntimeException(e);
}
......@@ -310,6 +311,46 @@ public class StCommonServiceImpl {
return (long)result.getOrDefault(DPMapStatisticsItemEnum.TOTAL.getCode(), 0L);
}
/**
* 统计已赋码设备数量
* @param orgCode
* @param isOrgBranchCodeExactMatch
* @param cylinderNum
* @return
*/
public long queryHasSupervisoryCodeEquipCount(String orgCode, Boolean isOrgBranchCodeExactMatch, long cylinderNum) {
CountRequest request = new CountRequest();
request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
if (isOrgBranchCodeExactMatch) {
// 按照管辖机构区域信息精确查询
boolMust.must(QueryBuilders.termQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode)));
} else {
// 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
}
//已赋码
boolMust.must(QueryBuilders.existsQuery("SUPERVISORY_CODE"));
boolMust.mustNot(QueryBuilders.termQuery("SUPERVISORY_CODE", "null"));
//状态为已认领
String[] status = {"草稿","已拒领","待认领"};
boolMust.mustNot(QueryBuilders.termsQuery("STATUS",Arrays.asList(status)));
// 且8大类,目的去掉脏数据。去掉管道统计
boolMust.must(QueryBuilders.termsQuery("EQU_LIST_CODE",StCommonServiceImpl.getEquipmentCategory().stream().map(EquipmentCategoryDto::getCode).filter(code -> !code.equals(EquipmentClassifityEnum.YLGD.getCode())).collect(Collectors.toList())));
// 排除气瓶
boolMust.mustNot(QueryBuilders.termsQuery("EQU_CATEGORY_CODE", EQU_CATEGORY_CYLINDER));
request.query(boolMust);
long count;
try {
CountResponse response = restHighLevelClient.count(request, RequestOptions.DEFAULT);
count = response.getCount();
return count;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private String castCategoryCode2WebCode(String category) {
DPMapStatisticsItemEnum itemEnum = DPMapStatisticsItemEnum.getInstanceByCategory(category);
return itemEnum.getCode();
......
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