Commit fe067391 authored by tianyiming's avatar tianyiming

fix(Statistics): 修改bug

parent bf71572d
...@@ -101,7 +101,7 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -101,7 +101,7 @@ public class AQZSDPStatisticsServiceImpl {
private StCommonServiceImpl stCommonService; private StCommonServiceImpl stCommonService;
private TZSCommonServiceImpl tstCommonService; private TZSCommonServiceImpl tzsCommonService;
private JGDPStatisticsServiceImpl jgDPStatisticsService; private JGDPStatisticsServiceImpl jgDPStatisticsService;
...@@ -119,7 +119,7 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -119,7 +119,7 @@ public class AQZSDPStatisticsServiceImpl {
StCommonServiceImpl stCommonService, StCommonServiceImpl stCommonService,
DataDictionaryMapper dataDictionaryMapper, DataDictionaryMapper dataDictionaryMapper,
JGDPStatisticsServiceImpl jgDPStatisticsService, JGDPStatisticsServiceImpl jgDPStatisticsService,
TZSCommonServiceImpl tstCommonService) { TZSCommonServiceImpl tzsCommonService) {
this.restHighLevelClient = restHighLevelClient; this.restHighLevelClient = restHighLevelClient;
this.statisticsMapper = statisticsMapper; this.statisticsMapper = statisticsMapper;
this.enterpriseInfoMapper = enterpriseInfoMapper; this.enterpriseInfoMapper = enterpriseInfoMapper;
...@@ -128,7 +128,7 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -128,7 +128,7 @@ public class AQZSDPStatisticsServiceImpl {
this.stCommonService = stCommonService; this.stCommonService = stCommonService;
this.dataDictionaryMapper = dataDictionaryMapper; this.dataDictionaryMapper = dataDictionaryMapper;
this.jgDPStatisticsService = jgDPStatisticsService; this.jgDPStatisticsService = jgDPStatisticsService;
this.tstCommonService = tstCommonService; this.tzsCommonService = tzsCommonService;
} }
...@@ -512,14 +512,24 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -512,14 +512,24 @@ public class AQZSDPStatisticsServiceImpl {
List<String> enumNameList = IssueTypeEnum.getEnumNameListByMainBody("1"); List<String> enumNameList = IssueTypeEnum.getEnumNameListByMainBody("1");
String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
if (orgCode != null) { if (orgCode != null) {
// BoolQueryBuilder overdueQuery = new BoolQueryBuilder();
// statisticalAnalysisService.personOrgCodeBoolMust(orgCode, overdueQuery, StatisticalAnalysisEnum.person.getCode());
// tstCommonService.buildExpiryDateQueryBuilder(overdueQuery, "overdue", "licenses", "licenses.expiryDate");
// Long overNumber = statisticalAnalysisService.getStatisticCount(overdueQuery, StatisticalAnalysisEnum.person.getKey());
// BoolQueryBuilder nearQuery = new BoolQueryBuilder();
// statisticalAnalysisService.personOrgCodeBoolMust(orgCode, nearQuery, StatisticalAnalysisEnum.person.getCode());
// tstCommonService.buildExpiryDateQueryBuilder(nearQuery, "near", "licenses", "licenses.expiryDate");
// Long nearNumber = statisticalAnalysisService.getStatisticCount(nearQuery, StatisticalAnalysisEnum.person.getKey());
// dataMap.put(IssueTypeEnum.LICENSE_OVERDUE_PERSON.getName(), overNumber);
// dataMap.put(IssueTypeEnum.LICENSE_EXPIRY_PERSON.getName(), nearNumber);
BoolQueryBuilder overdueQuery = new BoolQueryBuilder(); BoolQueryBuilder overdueQuery = new BoolQueryBuilder();
overdueQuery.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode)); // overdueQuery.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode));
tstCommonService.buildExpiryDateQueryBuilder(overdueQuery, "overdue", "licenses", "licenses.expiryDate"); // tstCommonService.buildExpiryDateQueryBuilder(overdueQuery, "overdue", "licenses", "licenses.expiryDate");
Long overNumber = stCommonService.getNestedQueryStatisticCount(overdueQuery, StatisticalAnalysisEnum.person.getKey(), "licenses", "expiryDate"); Long overNumber = stCommonService.getNestedQueryStatisticCount(overdueQuery, StatisticalAnalysisEnum.person.getKey(), "licenses", "expiryDate", tzsCommonService.overdue);
BoolQueryBuilder nearQuery = new BoolQueryBuilder(); BoolQueryBuilder nearQuery = new BoolQueryBuilder();
nearQuery.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode)); statisticalAnalysisService.personOrgCodeBoolMust(orgCode, nearQuery, StatisticalAnalysisEnum.person.getCode());
tstCommonService.buildExpiryDateQueryBuilder(nearQuery, "near", "licenses", "licenses.expiryDate"); Long nearNumber = stCommonService.getNestedQueryStatisticCount(nearQuery, StatisticalAnalysisEnum.person.getKey(), "licenses", "expiryDate", tzsCommonService.near);
Long nearNumber = stCommonService.getNestedQueryStatisticCount(nearQuery, StatisticalAnalysisEnum.person.getKey(), "licenses", "expiryDate");
dataMap.put(IssueTypeEnum.LICENSE_OVERDUE_PERSON.getName(), overNumber); dataMap.put(IssueTypeEnum.LICENSE_OVERDUE_PERSON.getName(), overNumber);
dataMap.put(IssueTypeEnum.LICENSE_EXPIRY_PERSON.getName(), nearNumber); dataMap.put(IssueTypeEnum.LICENSE_EXPIRY_PERSON.getName(), nearNumber);
} }
...@@ -933,8 +943,8 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -933,8 +943,8 @@ public class AQZSDPStatisticsServiceImpl {
//3.单位数量统计 //3.单位数量统计
// 单位统计修改为查询es // 单位统计修改为查询es
// this.staticsCenterMapCountDataForCompany(result, orgCode, dpFilterParamDto.getCityCode()); // this.staticsCenterMapCountDataForCompany(result, orgCode, dpFilterParamDto.getCityCode());
this.staticsCenterMapCompanyCountToEs(result, orgCode); this.staticsCenterMapCompanyCountToEs(result, orgCode);
//4.人员数量统计 //4.人员数量统计
// 人员统计改为查询es,修改之前查询的是作业人员的总数,修改为所有人员的总数 // 人员统计改为查询es,修改之前查询的是作业人员的总数,修改为所有人员的总数
// this.staticsCenterMapCountDataForPerson(result, dpFilterParamDto, orgCode); // this.staticsCenterMapCountDataForPerson(result, dpFilterParamDto, orgCode);
this.staticsCenterMapPersonCountToEs(result, orgCode); this.staticsCenterMapPersonCountToEs(result, orgCode);
...@@ -1211,4 +1221,4 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -1211,4 +1221,4 @@ public class AQZSDPStatisticsServiceImpl {
return item; return item;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
} }
\ No newline at end of file
...@@ -403,7 +403,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -403,7 +403,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
return result; return result;
} }
private void personOrgCodeBoolMust(String orgCode, BoolQueryBuilder boolMust, String type) { public void personOrgCodeBoolMust(String orgCode, BoolQueryBuilder boolMust, String type) {
String superviseOrgCodeKey = type.equals(StatisticalAnalysisEnum.person.getCode()) ? "superviseOrgCode" : "superviseOrgCode.keyword"; String superviseOrgCodeKey = type.equals(StatisticalAnalysisEnum.person.getCode()) ? "superviseOrgCode" : "superviseOrgCode.keyword";
String officeRegion = commonMapper.getCompanyCodeByOrgCode(orgCode); String officeRegion = commonMapper.getCompanyCodeByOrgCode(orgCode);
BoolQueryBuilder queryBuilder1 = QueryBuilders.boolQuery(); BoolQueryBuilder queryBuilder1 = QueryBuilders.boolQuery();
...@@ -4670,7 +4670,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -4670,7 +4670,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
// 使用 match_all 查询,拉取所有文档(通过 scroll 分批) // 使用 match_all 查询,拉取所有文档(通过 scroll 分批)
log.info("ES 全量查询开始, index={}, 时间={}", index, System.currentTimeMillis()); log.info("ES 全量查询开始, index={}, 时间={}", index, System.currentTimeMillis());
//BoolQueryBuilder boolQuery = QueryBuilders.boolQuery() //BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
// .must(QueryBuilders.termsQuery("STATUS", Collections.singletonList("已认领"))); // .must(QueryBuilders.termsQuery("STATUS", Collections.singletonList("已认领")));
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must(QueryBuilders.matchAllQuery()); boolQuery.must(QueryBuilders.matchAllQuery());
// 线程安全的结果容器 // 线程安全的结果容器
...@@ -4696,4 +4696,4 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -4696,4 +4696,4 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
return esIds.stream().distinct().collect(Collectors.toList()); return esIds.stream().distinct().collect(Collectors.toList());
} }
} }
\ No newline at end of file
...@@ -11,6 +11,7 @@ import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamForDetailDto; ...@@ -11,6 +11,7 @@ import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamForDetailDto;
import com.yeejoin.amos.boot.module.common.api.enums.CylinderTypeEnum; import com.yeejoin.amos.boot.module.common.api.enums.CylinderTypeEnum;
import com.yeejoin.amos.boot.module.common.api.enums.ReginStepEnum; import com.yeejoin.amos.boot.module.common.api.enums.ReginStepEnum;
import com.yeejoin.amos.boot.module.common.api.enums.StatisticalAnalysisEnum; import com.yeejoin.amos.boot.module.common.api.enums.StatisticalAnalysisEnum;
import com.yeejoin.amos.boot.module.common.biz.service.impl.TZSCommonServiceImpl;
import com.yeejoin.amos.boot.module.jg.api.enums.DPMapStatisticsItemEnum; import com.yeejoin.amos.boot.module.jg.api.enums.DPMapStatisticsItemEnum;
import com.yeejoin.amos.boot.module.statistics.api.mapper.CommonBaseMapper; import com.yeejoin.amos.boot.module.statistics.api.mapper.CommonBaseMapper;
import com.yeejoin.amos.boot.module.statistics.api.mapper.ZLStatisticsMapper; import com.yeejoin.amos.boot.module.statistics.api.mapper.ZLStatisticsMapper;
...@@ -23,6 +24,7 @@ import com.yeejoin.amos.feign.systemctl.Systemctl; ...@@ -23,6 +24,7 @@ import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.RegionModel; import com.yeejoin.amos.feign.systemctl.model.RegionModel;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RequestOptions;
...@@ -30,6 +32,8 @@ import org.elasticsearch.client.RestHighLevelClient; ...@@ -30,6 +32,8 @@ import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.core.CountRequest; import org.elasticsearch.client.core.CountRequest;
import org.elasticsearch.client.core.CountResponse; import org.elasticsearch.client.core.CountResponse;
import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.NestedQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.filter.Filter;
...@@ -44,18 +48,24 @@ import org.springframework.util.ObjectUtils; ...@@ -44,18 +48,24 @@ import org.springframework.util.ObjectUtils;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.elasticsearch.index.query.QueryBuilders.existsQuery;
/** /**
* @author Administrator * @author Administrator
*/ */
@Service @Service
public class StCommonServiceImpl { public class StCommonServiceImpl {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
/** /**
* 气瓶设备类别 * 气瓶设备类别
*/ */
...@@ -71,6 +81,8 @@ public class StCommonServiceImpl { ...@@ -71,6 +81,8 @@ public class StCommonServiceImpl {
private RestHighLevelClient restHighLevelClient; private RestHighLevelClient restHighLevelClient;
private TZSCommonServiceImpl tzsCommonService;
private EquipTechParamPipelineMapper techParamsPipelineMapper; private EquipTechParamPipelineMapper techParamsPipelineMapper;
private EquipmentCategoryMapper equipmentCategoryMapper; private EquipmentCategoryMapper equipmentCategoryMapper;
...@@ -85,12 +97,18 @@ public class StCommonServiceImpl { ...@@ -85,12 +97,18 @@ public class StCommonServiceImpl {
private static List<EquipmentCategoryDto> equipmentCategoryDtos; private static List<EquipmentCategoryDto> equipmentCategoryDtos;
public StCommonServiceImpl(CommonBaseMapper commonMapper, RestHighLevelClient restHighLevelClient, EquipTechParamPipelineMapper techParamsPipelineMapper, EquipmentCategoryMapper equipmentCategoryMapper, ZLStatisticsMapper zlStatisticsMapper) { public StCommonServiceImpl(CommonBaseMapper commonMapper,
RestHighLevelClient restHighLevelClient,
EquipTechParamPipelineMapper techParamsPipelineMapper,
EquipmentCategoryMapper equipmentCategoryMapper,
ZLStatisticsMapper zlStatisticsMapper,
TZSCommonServiceImpl tzsCommonService) {
this.commonMapper = commonMapper; this.commonMapper = commonMapper;
this.restHighLevelClient = restHighLevelClient; this.restHighLevelClient = restHighLevelClient;
this.techParamsPipelineMapper = techParamsPipelineMapper; this.techParamsPipelineMapper = techParamsPipelineMapper;
this.equipmentCategoryMapper = equipmentCategoryMapper; this.equipmentCategoryMapper = equipmentCategoryMapper;
this.zlStatisticsMapper = zlStatisticsMapper; this.zlStatisticsMapper = zlStatisticsMapper;
this.tzsCommonService = tzsCommonService;
} }
public static Map<String, String> getRegionCodeOrgCodeMap() { public static Map<String, String> getRegionCodeOrgCodeMap() {
...@@ -262,7 +280,7 @@ public class StCommonServiceImpl { ...@@ -262,7 +280,7 @@ public class StCommonServiceImpl {
public long staticsCenterMapCountDataForEquip(Map<String, Object> result, long cylinderNum, String orgCode, Boolean supervisoryFlag, Boolean isMatchSupervisoryCode, Boolean isOrgBranchCodeExactMatch) { public long staticsCenterMapCountDataForEquip(Map<String, Object> result, long cylinderNum, String orgCode, Boolean supervisoryFlag, Boolean isMatchSupervisoryCode, Boolean isOrgBranchCodeExactMatch) {
SearchRequest request = new SearchRequest(); SearchRequest request = new SearchRequest();
// request.indices("idx_biz_view_jg_all"); // request.indices("idx_biz_view_jg_all");
request.indices(StatisticalAnalysisEnum.equip.getKey()); request.indices(StatisticalAnalysisEnum.equip.getKey());
BoolQueryBuilder boolMust = QueryBuilders.boolQuery(); BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
if (isOrgBranchCodeExactMatch) { if (isOrgBranchCodeExactMatch) {
...@@ -338,16 +356,27 @@ public class StCommonServiceImpl { ...@@ -338,16 +356,27 @@ public class StCommonServiceImpl {
} }
public Long getNestedQueryStatisticCount(BoolQueryBuilder builder, String index, String nestedFiled, String filterFiled) { public Long getNestedQueryStatisticCount(BoolQueryBuilder builder, String index, String nestedFiled, String filterFiled, String type) {
SearchRequest searchRequest = new SearchRequest(index); SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
// 构建嵌套聚合 BoolQueryBuilder notNeedLicensesQueryBuilder = tzsCommonService.getNotLicencesBuilderWithPerson();
NestedQueryBuilder nestedQuery = QueryBuilders.nestedQuery(
nestedFiled,
existsQuery(nestedFiled + "." + "certNo"),
ScoreMode.None
);
builder.must(notNeedLicensesQueryBuilder);
builder.must(nestedQuery);
// 根据类型动态获取日期范围查询
QueryBuilder dateRangeQuery = getRangeDateByType(nestedFiled, filterFiled, type);
NestedAggregationBuilder nestedAgg = AggregationBuilders.nested(nestedFiled, nestedFiled) NestedAggregationBuilder nestedAgg = AggregationBuilders.nested(nestedFiled, nestedFiled)
.subAggregation( .subAggregation(
AggregationBuilders.filter(filterFiled + "_count", builder) AggregationBuilders.filter(filterFiled + "_count", dateRangeQuery)
); );
sourceBuilder.aggregation(nestedAgg); sourceBuilder.aggregation(nestedAgg);
sourceBuilder.size(0); // 只要聚合结果,不要文档 sourceBuilder.size(0); // 只要聚合结果,不要文档
sourceBuilder.query(builder);
searchRequest.source(sourceBuilder); searchRequest.source(sourceBuilder);
long count = 0; long count = 0;
try { try {
...@@ -362,6 +391,19 @@ public class StCommonServiceImpl { ...@@ -362,6 +391,19 @@ public class StCommonServiceImpl {
return count; return count;
} }
private QueryBuilder getRangeDateByType(String nestedFiled, String filterFiled, String type) {
QueryBuilder dateRangeQuery = null;
if (tzsCommonService.near.equals(type)) {
dateRangeQuery = QueryBuilders.rangeQuery(nestedFiled + "." + filterFiled)
.lt(LocalDate.now().format(formatter));
} else if (tzsCommonService.overdue.equals(type)) {
dateRangeQuery = QueryBuilders.rangeQuery(nestedFiled + "." + filterFiled)
.gte(LocalDate.now().format(formatter))
.lte(LocalDate.now().plusDays(30).format(formatter));
}
return dateRangeQuery;
}
/** /**
* 统计已赋码设备数量 * 统计已赋码设备数量
* @param orgCode * @param orgCode
......
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