Commit 5a5ca1cf authored by tianyiming's avatar tianyiming

feat(core): 添加设备统计无子节点判断功能

parent 9ab4bc81
...@@ -20,5 +20,7 @@ public interface TzsCustomFilterMapper extends BaseMapper<TzsCustomFilter> { ...@@ -20,5 +20,7 @@ public interface TzsCustomFilterMapper extends BaseMapper<TzsCustomFilter> {
@MapKey("key") @MapKey("key")
List<Map<String, Object>> selectEquipmentCategoryByParentId(@Param("parentId") String parentId); List<Map<String, Object>> selectEquipmentCategoryByParentId(@Param("parentId") String parentId);
Integer selectEquipmentCategoryCountByParentId(@Param("parentId") String parentId);
JSONArray queryEquCategory(@Param("type") String type, @Param("description") String description); JSONArray queryEquCategory(@Param("type") String type, @Param("description") String description);
} }
...@@ -25,4 +25,7 @@ ...@@ -25,4 +25,7 @@
AND parent_id = (SELECT id FROM tz_equipment_category where code = #{type}) AND parent_id = (SELECT id FROM tz_equipment_category where code = #{type})
</if> </if>
</select> </select>
<select id="selectEquipmentCategoryCountByParentId" resultType="java.lang.Integer">
select count(1) from tz_equipment_category where is_delete = 0 and parent_id = #{parentId}
</select>
</mapper> </mapper>
...@@ -100,6 +100,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -100,6 +100,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
private final TzsCustomFilterMapper tzsCustomFilterMapper; private final TzsCustomFilterMapper tzsCustomFilterMapper;
private final DataDictionaryServiceImpl dataDictionaryService; private final DataDictionaryServiceImpl dataDictionaryService;
private final EmqKeeper emqKeeper; private final EmqKeeper emqKeeper;
private final EquipmentCategoryMapper tzEquipmentCategoryMapper;
private final StCommonServiceImpl stCommonService; private final StCommonServiceImpl stCommonService;
private final RestHighLevelClient restHighLevelClient; private final RestHighLevelClient restHighLevelClient;
...@@ -1628,6 +1629,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -1628,6 +1629,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
/** /**
* 需要资质的人员查询构造条件 * 需要资质的人员查询构造条件
* 无资质:需要资质但是没有填写 * 无资质:需要资质但是没有填写
*
* @return * @return
*/ */
private BoolQueryBuilder getNotLicencesBuilderWithPerson() { private BoolQueryBuilder getNotLicencesBuilderWithPerson() {
...@@ -1647,6 +1649,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -1647,6 +1649,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
/** /**
* 无资质要求的人员查询构造条件 * 无资质要求的人员查询构造条件
* 无资质要求:不需要资质 * 无资质要求:不需要资质
*
* @return * @return
*/ */
private BoolQueryBuilder getNotNeedLicencesBuilderWithPerson() { private BoolQueryBuilder getNotNeedLicencesBuilderWithPerson() {
...@@ -2856,12 +2859,10 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2856,12 +2859,10 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
Long equipCount = staticCountByGroup.values().stream().reduce(0L, Long::sum); Long equipCount = staticCountByGroup.values().stream().reduce(0L, Long::sum);
tabTotalMap.put(StatisticalAnalysisEnum.equip.getCode(), equipCount); tabTotalMap.put(StatisticalAnalysisEnum.equip.getCode(), equipCount);
List<String> codes = new ArrayList<>();
// 组装数据 // 组装数据
List<Map<String, Object>> dataMapList = new ArrayList<>(); List<Map<String, Object>> dataMapList = new ArrayList<>();
for (Map<String, Object> categoryMap : staticCountByGroupMap) { for (Map<String, Object> categoryMap : staticCountByGroupMap) {
String code = categoryMap.get("value").toString(); String code = categoryMap.get("value").toString();
codes.add(code);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("key", categoryMap.get("key")); map.put("key", categoryMap.get("key"));
map.put("label", categoryMap.get("label")); map.put("label", categoryMap.get("label"));
...@@ -2869,6 +2870,8 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2869,6 +2870,8 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
map.put("fieldKey", groupField.replace("_CODE", "")); map.put("fieldKey", groupField.replace("_CODE", ""));
map.put("value", staticCountByGroup.containsKey(code) ? staticCountByGroup.get(code) : 0L); map.put("value", staticCountByGroup.containsKey(code) ? staticCountByGroup.get(code) : 0L);
map.put("img", dpEquipPhotoPrefix + code + dpEquipPhotoSuffix); 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", "台套"); map.put("measurementUnit", "台套");
// 统计该分类下的数据完整性的分组数量 DATA_QUALITY_SCORE // 统计该分类下的数据完整性的分组数量 DATA_QUALITY_SCORE
BoolQueryBuilder scoreQuery = QueryBuilderUtils.copyBoolQuery(boolMust); BoolQueryBuilder scoreQuery = QueryBuilderUtils.copyBoolQuery(boolMust);
...@@ -2888,7 +2891,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2888,7 +2891,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
} }
// 统计种类/类别/品种数据不对的数据字段 // 统计种类/类别/品种数据不对的数据字段
if(!ObjectUtils.isEmpty(staticCountByGroup)){ if (!ObjectUtils.isEmpty(staticCountByGroup)) {
statisticOtherCount(request, dataMapList, staticCountByGroup, boolMust, groupField); statisticOtherCount(request, dataMapList, staticCountByGroup, boolMust, groupField);
} }
...@@ -2913,7 +2916,11 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2913,7 +2916,11 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
otherCount += staticCountByGroup.get(key); otherCount += staticCountByGroup.get(key);
// 统计该分类下的数据完整性的分组数量 DATA_QUALITY_SCORE // 统计该分类下的数据完整性的分组数量 DATA_QUALITY_SCORE
BoolQueryBuilder scoreQuery = QueryBuilderUtils.copyBoolQuery(boolMust); BoolQueryBuilder scoreQuery = QueryBuilderUtils.copyBoolQuery(boolMust);
scoreQuery.must(QueryBuilders.termQuery(groupField, key)); if (key.equals("NA")) {
scoreQuery.mustNot(QueryBuilders.existsQuery(groupField));
} else {
scoreQuery.must(QueryBuilders.termQuery(groupField, key));
}
SearchSourceBuilder scoreBuilder = new SearchSourceBuilder(); SearchSourceBuilder scoreBuilder = new SearchSourceBuilder();
Map<String, Long> scoreCountByGroup = new HashMap<>(); Map<String, Long> scoreCountByGroup = new HashMap<>();
getStatisticCountByGroup(request, scoreBuilder, scoreQuery, "DATA_QUALITY_SCORE", scoreCountByGroup); getStatisticCountByGroup(request, scoreBuilder, scoreQuery, "DATA_QUALITY_SCORE", scoreCountByGroup);
...@@ -2924,7 +2931,11 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2924,7 +2931,11 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
// 统计该分类下红黄绿码分别的分组数量 NEXT_INSPECT_DATE // 统计该分类下红黄绿码分别的分组数量 NEXT_INSPECT_DATE
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, key)); if (key.equals("NA")) {
nextInspectQuery.mustNot(QueryBuilders.existsQuery(groupField));
} else {
nextInspectQuery.must(QueryBuilders.termQuery(groupField, key));
}
getStatisticCountByDate(StatisticalAnalysisEnum.equip.getKey(), "NEXT_INSPECT_DATE", nextInspectQuery, nextInspectCountByGroup); getStatisticCountByDate(StatisticalAnalysisEnum.equip.getKey(), "NEXT_INSPECT_DATE", nextInspectQuery, nextInspectCountByGroup);
redCount += nextInspectCountByGroup.containsKey("red") ? nextInspectCountByGroup.get("red") : 0L; redCount += nextInspectCountByGroup.containsKey("red") ? nextInspectCountByGroup.get("red") : 0L;
yellowCount += nextInspectCountByGroup.containsKey("yellow") ? nextInspectCountByGroup.get("yellow") : 0L; yellowCount += nextInspectCountByGroup.containsKey("yellow") ? nextInspectCountByGroup.get("yellow") : 0L;
...@@ -2940,12 +2951,12 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2940,12 +2951,12 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
map.put("value", otherCount); map.put("value", otherCount);
map.put("img", dpEquipPhotoPrefix + type + dpEquipPhotoSuffix); map.put("img", dpEquipPhotoPrefix + type + dpEquipPhotoSuffix);
map.put("measurementUnit", "台套"); map.put("measurementUnit", "台套");
Map<String,Long> scoreCount = new HashMap<>(); Map<String, Long> scoreCount = new HashMap<>();
scoreCount.put("1", oneCount); scoreCount.put("1", oneCount);
scoreCount.put("2", twoCount); scoreCount.put("2", twoCount);
scoreCount.put("3", threeCount); scoreCount.put("3", threeCount);
map.put("DATA_QUALITY_SCORE", scoreCount); map.put("DATA_QUALITY_SCORE", scoreCount);
Map<String,Long> nextInspectCount = new HashMap<>(); Map<String, Long> nextInspectCount = new HashMap<>();
nextInspectCount.put("red", redCount); nextInspectCount.put("red", redCount);
nextInspectCount.put("yellow", yellowCount); nextInspectCount.put("yellow", yellowCount);
nextInspectCount.put("green", greenCount); nextInspectCount.put("green", greenCount);
...@@ -2978,9 +2989,12 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2978,9 +2989,12 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
} }
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).size(50)); if (groupField.equals("DATA_QUALITY_SCORE")) {
builder.aggregation(AggregationBuilders.terms("groupCount").field(groupField).missing(99).size(50));
} else {
builder.aggregation(AggregationBuilders.terms("groupCount").field(groupField).missing("NA").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