Commit 5a5ca1cf authored by tianyiming's avatar tianyiming

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

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