Commit 7bf8b2c1 authored by tianyiming's avatar tianyiming

feat(statistics): 增加企业总量、许可单位和人员总数统计功能

parent bf16fa1d
...@@ -30,9 +30,12 @@ public enum DPMapStatisticsItemEnum { ...@@ -30,9 +30,12 @@ public enum DPMapStatisticsItemEnum {
PASSENGER_ROPEWAYS("客运索道 (台)", "passengerRopeways", "9000"), PASSENGER_ROPEWAYS("客运索道 (台)", "passengerRopeways", "9000"),
MANUFACTURING_UNITS("制造单位 (家)", "manufacturingUnits", ""), MANUFACTURING_UNITS("制造单位 (家)", "manufacturingUnits", ""),
CONSTRUCTION_UNITS("安改维单位 (家)", "constructionUnits", ""), CONSTRUCTION_UNITS("安改维单位 (家)", "constructionUnits", ""),
COMPANY_TOTAL("企业总量 (家)", "companyTotal", ""),
USERS_UNITS("使用单位 (家)", "usersUnits", ""), USERS_UNITS("使用单位 (家)", "usersUnits", ""),
PERMIT_UNITS("许可单位 (家)", "permitUnits", ""),
GAS_UNITS("充装单位 (家)", "gasUnits", ""), GAS_UNITS("充装单位 (家)", "gasUnits", ""),
DESIGN_UNITS("设计单位 (家)", "designUnits", ""), DESIGN_UNITS("设计单位 (家)", "designUnits", ""),
PERSON_TOTAL("人员总数 (人)", "personTotal", ""),
OPERATORS("作业人员 (人)", "operators", ""), OPERATORS("作业人员 (人)", "operators", ""),
DEVICE_COUNT("已纳管设备数", "deviceCount", ""), DEVICE_COUNT("已纳管设备数", "deviceCount", ""),
PERSON_ISSUES_COUNT("个人问题数", "个人", ""), PERSON_ISSUES_COUNT("个人问题数", "个人", ""),
......
...@@ -1162,7 +1162,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -1162,7 +1162,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
} }
private Long getStatisticCount(BoolQueryBuilder builder, String index) { public Long getStatisticCount(BoolQueryBuilder builder, String index) {
CountRequest countRequest = new CountRequest(); CountRequest countRequest = new CountRequest();
countRequest.indices(index); countRequest.indices(index);
CountResponse response = null; CountResponse response = null;
...@@ -2782,7 +2782,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -2782,7 +2782,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
return Collections.singletonList(result); return Collections.singletonList(result);
} }
private void buildPersonWithCompanyTypeGroupResult(Terms unitTypesTerms, Map<String, Object> result) { public void buildPersonWithCompanyTypeGroupResult(Terms unitTypesTerms, Map<String, Object> result) {
if (unitTypesTerms != null) { if (unitTypesTerms != null) {
for (Terms.Bucket bucket : unitTypesTerms.getBuckets()) { for (Terms.Bucket bucket : unitTypesTerms.getBuckets()) {
if (bucket.getKeyAsString().equals(UnitTypeEnum.sydw.getName())) { if (bucket.getKeyAsString().equals(UnitTypeEnum.sydw.getName())) {
......
...@@ -33,8 +33,10 @@ import com.yeejoin.amos.boot.module.jg.api.entity.SafetyProblemTracing; ...@@ -33,8 +33,10 @@ import com.yeejoin.amos.boot.module.jg.api.entity.SafetyProblemTracing;
import com.yeejoin.amos.boot.module.jg.api.enums.*; import com.yeejoin.amos.boot.module.jg.api.enums.*;
import com.yeejoin.amos.boot.module.jg.api.mapper.*; import com.yeejoin.amos.boot.module.jg.api.mapper.*;
import com.yeejoin.amos.boot.module.statistcs.biz.utils.JsonUtils; import com.yeejoin.amos.boot.module.statistcs.biz.utils.JsonUtils;
import com.yeejoin.amos.boot.module.statistcs.biz.utils.QueryBuilderUtils;
import com.yeejoin.amos.boot.module.statistics.api.dto.*; import com.yeejoin.amos.boot.module.statistics.api.dto.*;
import com.yeejoin.amos.boot.module.statistics.api.enums.RegulatoryUnitLevelEnum; import com.yeejoin.amos.boot.module.statistics.api.enums.RegulatoryUnitLevelEnum;
import com.yeejoin.amos.boot.module.statistics.api.enums.StatisticalAnalysisEnum;
import com.yeejoin.amos.boot.module.statistics.api.mapper.CylinderBusinessStatisticsMapper; import com.yeejoin.amos.boot.module.statistics.api.mapper.CylinderBusinessStatisticsMapper;
import com.yeejoin.amos.boot.module.statistics.api.mapper.JGStatisticsMapper; import com.yeejoin.amos.boot.module.statistics.api.mapper.JGStatisticsMapper;
import com.yeejoin.amos.boot.module.statistics.api.mapper.ZLStatisticsMapper; import com.yeejoin.amos.boot.module.statistics.api.mapper.ZLStatisticsMapper;
...@@ -270,6 +272,8 @@ public class JGDPStatisticsServiceImpl { ...@@ -270,6 +272,8 @@ public class JGDPStatisticsServiceImpl {
private final DataDictionaryServiceImpl iDataDictionaryService; private final DataDictionaryServiceImpl iDataDictionaryService;
private final ComprehensiveStatisticalAnalysisServiceImpl statisticalAnalysisService;
private List<LegendDataDto> buildLegendDataList() { private List<LegendDataDto> buildLegendDataList() {
List<LegendDataDto> legendDataDtos = new ArrayList<>(); List<LegendDataDto> legendDataDtos = new ArrayList<>();
...@@ -438,10 +442,25 @@ public class JGDPStatisticsServiceImpl { ...@@ -438,10 +442,25 @@ public class JGDPStatisticsServiceImpl {
private void staticsCenterMapCountDataForPerson(Map<String, Object> result, DPFilterParamDto dpFilterParamDto, String orgCode) { private void staticsCenterMapCountDataForPerson(Map<String, Object> result, DPFilterParamDto dpFilterParamDto, String orgCode) {
if (orgCode == null) { if (orgCode == null) {
result.put(DPMapStatisticsItemEnum.OPERATORS.getCode(), 0); result.put(DPMapStatisticsItemEnum.OPERATORS.getCode(), 0);
result.put(DPMapStatisticsItemEnum.PERSON_TOTAL.getCode(), 0);
return; return;
} }
Long num = userInfoMapper.countUserByPostAndAreaCode(orgCode, "6552", dpFilterParamDto.getCityCode()); staticsPersonCountByEs(orgCode, StatisticalAnalysisEnum.person.getKey(), result);
result.put(DPMapStatisticsItemEnum.OPERATORS.getCode(), num); }
private void staticsPersonCountByEs(String orgCode, String key, Map<String, Object> result) {
String index = StatisticalAnalysisEnum.person.getKey();
SearchRequest request = new SearchRequest();
SearchSourceBuilder builder = new SearchSourceBuilder();
builder.trackTotalHits(true);
request.indices(index);
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode));
Long personSum = statisticalAnalysisService.getStatisticCount(boolMust, index);
boolMust.must(QueryBuilders.matchQuery("newPost", "6552"));
Long operatorsNum = statisticalAnalysisService.getStatisticCount(boolMust, index);
result.put(DPMapStatisticsItemEnum.OPERATORS.getCode(), operatorsNum);
result.put(DPMapStatisticsItemEnum.PERSON_TOTAL.getCode(), personSum);
} }
private void staticsCenterMapCountDataForCompany(Map<String, Object> result, String orgCode, String cityCode) { private void staticsCenterMapCountDataForCompany(Map<String, Object> result, String orgCode, String cityCode) {
...@@ -450,11 +469,51 @@ public class JGDPStatisticsServiceImpl { ...@@ -450,11 +469,51 @@ public class JGDPStatisticsServiceImpl {
return; return;
} }
List<CountDto> countDtos = enterpriseInfoMapper.countByUnitTypeAndOrgCode(orgCode, cityCode, false); List<CountDto> countDtos = enterpriseInfoMapper.countByUnitTypeAndOrgCode(orgCode, cityCode, false);
result.put(DPMapStatisticsItemEnum.USERS_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_USE) || c.getKeyStr().contains(COMPANY_TYPE_PERSON)).mapToInt(CountDto::getIntValue).sum()); // 企业根据类型统计
staticsUnitTypeCountByEs(orgCode, StatisticalAnalysisEnum.company.getKey(), result);
result.put(DPMapStatisticsItemEnum.CONSTRUCTION_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_MAINTENANCE)).mapToInt(CountDto::getIntValue).sum()); result.put(DPMapStatisticsItemEnum.CONSTRUCTION_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_MAINTENANCE)).mapToInt(CountDto::getIntValue).sum());
result.put(DPMapStatisticsItemEnum.MANUFACTURING_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_MANUFACTURE)).mapToInt(CountDto::getIntValue).sum()); result.put(DPMapStatisticsItemEnum.MANUFACTURING_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_MANUFACTURE)).mapToInt(CountDto::getIntValue).sum());
result.put(DPMapStatisticsItemEnum.GAS_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_FILLING)).mapToInt(CountDto::getIntValue).sum()); result.put(DPMapStatisticsItemEnum.GAS_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_FILLING)).mapToInt(CountDto::getIntValue).sum());
result.put(DPMapStatisticsItemEnum.DESIGN_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_DESIGN)).mapToInt(CountDto::getIntValue).sum()); result.put(DPMapStatisticsItemEnum.DESIGN_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_DESIGN)).mapToInt(CountDto::getIntValue).sum());
}
private void staticsUnitTypeCountByEs(String orgCode, String index, Map<String, Object> result) {
SearchRequest request = new SearchRequest();
SearchSourceBuilder builder = new SearchSourceBuilder();
builder.trackTotalHits(true);
request.indices(index);
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode));
Long companySum = statisticalAnalysisService.getStatisticCount(boolMust, index);
// 聚合查询
builder.size(0);// 不返回任何文档,只返回聚合结果
String aggName = "unit_types_split";
QueryBuilderUtils.buildSplitFieldAggCondition(builder, "unitType.keyword", "#", aggName, "其他");
builder.query(boolMust);
request.source(builder);
Map<String, Object> mapCount = new HashMap<>();
try {
SearchResponse searchResponse = restHighLevelClient.search(request, RequestOptions.DEFAULT);
// 解析聚合结果
Terms unitTypesTerms = searchResponse.getAggregations().get(aggName);
statisticalAnalysisService.buildPersonWithCompanyTypeGroupResult(unitTypesTerms, mapCount);
} catch (Exception e) {
throw new RuntimeException(e);
}
Long sydwSum = mapCount.containsKey("sydw") ? Long.valueOf(mapCount.get("sydw").toString()) : 0L;
Long grztSum = mapCount.containsKey("grzt") ? Long.valueOf(mapCount.get("grzt").toString()) : 0L;
Long sjdwSum = mapCount.containsKey("sjdw") ? Long.valueOf(mapCount.get("sjdw").toString()) : 0L;
Long zzdwSum = mapCount.containsKey("zzdw") ? Long.valueOf(mapCount.get("zzdw").toString()) : 0L;
Long azgzwxdwSum = mapCount.containsKey("azgzwxdw") ? Long.valueOf(mapCount.get("azgzwxdw").toString()) : 0L;
Long czdwSum = mapCount.containsKey("czdw") ? Long.valueOf(mapCount.get("czdw").toString()) : 0L;
Long jyjgSum = mapCount.containsKey("jyjg") ? Long.valueOf(mapCount.get("jyjg").toString()) : 0L;
Long jcjgSum = mapCount.containsKey("jcjg") ? Long.valueOf(mapCount.get("jcjg").toString()) : 0L;
result.put(DPMapStatisticsItemEnum.COMPANY_TOTAL.getCode(), companySum);
result.put(DPMapStatisticsItemEnum.USERS_UNITS.getCode(), sydwSum + grztSum);
result.put(DPMapStatisticsItemEnum.PERMIT_UNITS.getCode(), sjdwSum + zzdwSum + azgzwxdwSum + czdwSum + jyjgSum + jcjgSum);
} }
private void staticsCompanyForSkjs(SkjsCountItemDto countItemDto, String orgCode, String cityCode) { private void staticsCompanyForSkjs(SkjsCountItemDto countItemDto, String orgCode, String cityCode) {
...@@ -540,7 +599,8 @@ public class JGDPStatisticsServiceImpl { ...@@ -540,7 +599,8 @@ public class JGDPStatisticsServiceImpl {
String cityCode = m.get("cityCode").toString(); String cityCode = m.get("cityCode").toString();
String orgCode = StCommonServiceImpl.getRegionCodeOrgCodeMap().get(cityCode); String orgCode = StCommonServiceImpl.getRegionCodeOrgCodeMap().get(cityCode);
if (StringUtils.isNotEmpty(orgCode)) { if (StringUtils.isNotEmpty(orgCode)) {
m.put(DPMapStatisticsItemEnum.USERS_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_USE) && c.getLabel().contains(orgCode)).mapToInt(CountDto::getIntValue).sum()); // m.put(DPMapStatisticsItemEnum.USERS_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_USE) && c.getLabel().contains(orgCode)).mapToInt(CountDto::getIntValue).sum());
staticsUnitTypeCountByEs(orgCode, StatisticalAnalysisEnum.company.getKey(), m);
m.put(DPMapStatisticsItemEnum.CONSTRUCTION_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_MAINTENANCE) && c.getLabel().contains(orgCode)).mapToInt(CountDto::getIntValue).sum()); m.put(DPMapStatisticsItemEnum.CONSTRUCTION_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_MAINTENANCE) && c.getLabel().contains(orgCode)).mapToInt(CountDto::getIntValue).sum());
m.put(DPMapStatisticsItemEnum.MANUFACTURING_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_MANUFACTURE) && c.getLabel().contains(orgCode)).mapToInt(CountDto::getIntValue).sum()); m.put(DPMapStatisticsItemEnum.MANUFACTURING_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_MANUFACTURE) && c.getLabel().contains(orgCode)).mapToInt(CountDto::getIntValue).sum());
m.put(DPMapStatisticsItemEnum.GAS_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_FILLING) && c.getLabel().contains(orgCode)).mapToInt(CountDto::getIntValue).sum()); m.put(DPMapStatisticsItemEnum.GAS_UNITS.getCode(), countDtos.stream().filter(c -> c.getKeyStr().contains(COMPANY_TYPE_FILLING) && c.getLabel().contains(orgCode)).mapToInt(CountDto::getIntValue).sum());
...@@ -553,6 +613,8 @@ public class JGDPStatisticsServiceImpl { ...@@ -553,6 +613,8 @@ public class JGDPStatisticsServiceImpl {
private void setDefaultCompanyCountData(Map<String, Object> m) { private void setDefaultCompanyCountData(Map<String, Object> m) {
m.put(DPMapStatisticsItemEnum.USERS_UNITS.getCode(), 0); m.put(DPMapStatisticsItemEnum.USERS_UNITS.getCode(), 0);
m.put(DPMapStatisticsItemEnum.COMPANY_TOTAL.getCode(), 0);
m.put(DPMapStatisticsItemEnum.PERMIT_UNITS.getCode(), 0);
m.put(DPMapStatisticsItemEnum.CONSTRUCTION_UNITS.getCode(), 0); m.put(DPMapStatisticsItemEnum.CONSTRUCTION_UNITS.getCode(), 0);
m.put(DPMapStatisticsItemEnum.MANUFACTURING_UNITS.getCode(), 0); m.put(DPMapStatisticsItemEnum.MANUFACTURING_UNITS.getCode(), 0);
m.put(DPMapStatisticsItemEnum.GAS_UNITS.getCode(), 0); m.put(DPMapStatisticsItemEnum.GAS_UNITS.getCode(), 0);
......
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