Commit 16702b4b authored by 王果's avatar 王果

Merge remote-tracking branch 'origin/develop_tzs_register_to_0715' into…

Merge remote-tracking branch 'origin/develop_tzs_register_to_0715' into develop_tzs_register_to_0715
parents 771f5cd2 1dc663e5
package com.yeejoin.amos.boot.module.statistcs.biz.init; package com.yeejoin.amos.boot.module.statistcs.biz.init;
import com.yeejoin.amos.boot.module.statistcs.biz.service.impl.AQZSDPStatisticsServiceImpl; import com.yeejoin.amos.boot.module.statistcs.biz.service.impl.AQZSDPStatisticsServiceImpl;
import com.yeejoin.amos.boot.module.statistcs.biz.service.impl.JGDPStatisticsServiceImpl;
import com.yeejoin.amos.boot.module.statistcs.biz.service.impl.StCommonServiceImpl; import com.yeejoin.amos.boot.module.statistcs.biz.service.impl.StCommonServiceImpl;
import com.yeejoin.amos.component.robot.AmosRequestContext; import com.yeejoin.amos.component.robot.AmosRequestContext;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
...@@ -15,19 +14,14 @@ import org.typroject.tyboot.core.foundation.context.RequestContext; ...@@ -15,19 +14,14 @@ import org.typroject.tyboot.core.foundation.context.RequestContext;
@Component @Component
public class DataInitAfterRuning implements ApplicationRunner { public class DataInitAfterRuning implements ApplicationRunner {
private JGDPStatisticsServiceImpl jgdpStatisticsService;
private AQZSDPStatisticsServiceImpl aqzsdpStatisticsService;
private StCommonServiceImpl stCommonService; private StCommonServiceImpl stCommonService;
private AmosRequestContext amosRequestContext; private AmosRequestContext amosRequestContext;
public DataInitAfterRuning(JGDPStatisticsServiceImpl jgdpStatisticsService, StCommonServiceImpl stCommonService, AmosRequestContext amosRequestContext, AQZSDPStatisticsServiceImpl aqzsdpStatisticsService) { public DataInitAfterRuning(StCommonServiceImpl stCommonService, AmosRequestContext amosRequestContext) {
this.jgdpStatisticsService = jgdpStatisticsService;
this.stCommonService = stCommonService; this.stCommonService = stCommonService;
this.amosRequestContext = amosRequestContext; this.amosRequestContext = amosRequestContext;
this.aqzsdpStatisticsService = aqzsdpStatisticsService;
} }
@Override @Override
...@@ -36,8 +30,6 @@ public class DataInitAfterRuning implements ApplicationRunner { ...@@ -36,8 +30,6 @@ public class DataInitAfterRuning implements ApplicationRunner {
RequestContext.setAppKey(amosRequestContext.getAppKey()); RequestContext.setAppKey(amosRequestContext.getAppKey());
RequestContext.setProduct(amosRequestContext.getProduct()); RequestContext.setProduct(amosRequestContext.getProduct());
RequestContext.setToken(amosRequestContext.getToken()); RequestContext.setToken(amosRequestContext.getToken());
jgdpStatisticsService.init();
stCommonService.init(); stCommonService.init();
aqzsdpStatisticsService.init();
} }
} }
...@@ -11,14 +11,11 @@ import com.yeejoin.amos.boot.module.statistics.api.dto.EquipQuestionNumCountDto; ...@@ -11,14 +11,11 @@ import com.yeejoin.amos.boot.module.statistics.api.dto.EquipQuestionNumCountDto;
import com.yeejoin.amos.boot.module.statistics.api.dto.SecurityIndexCountItemDto; import com.yeejoin.amos.boot.module.statistics.api.dto.SecurityIndexCountItemDto;
import com.yeejoin.amos.boot.module.statistics.api.mapper.AQZSDPStatisticsMapper; import com.yeejoin.amos.boot.module.statistics.api.mapper.AQZSDPStatisticsMapper;
import com.yeejoin.amos.boot.module.statistics.api.mapper.CylinderStatisticsMapper; import com.yeejoin.amos.boot.module.statistics.api.mapper.CylinderStatisticsMapper;
import com.yeejoin.amos.boot.module.ymt.api.dto.EquipmentCategoryDto;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquimentEnum; import com.yeejoin.amos.boot.module.ymt.api.enums.EquimentEnum;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentClassifityEnum; import com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentClassifityEnum;
import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipTechParamPipelineMapper; import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipTechParamPipelineMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipmentCategoryMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.TzBaseEnterpriseInfoMapper; import com.yeejoin.amos.boot.module.ymt.api.mapper.TzBaseEnterpriseInfoMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.TzsUserInfoMapper; import com.yeejoin.amos.boot.module.ymt.api.mapper.TzsUserInfoMapper;
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;
...@@ -64,16 +61,6 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -64,16 +61,6 @@ public class AQZSDPStatisticsServiceImpl {
private final static String NO_DATA_STR = "--"; private final static String NO_DATA_STR = "--";
/** /**
* 压力容器设备种类
*/
private final static String EQU_LIST_CYLINDER = "2000";
/**
* 气瓶设备类别
*/
private final static String EQU_CATEGORY_CYLINDER = "2300";
/**
* 单位类型-使用单位 * 单位类型-使用单位
*/ */
private final static String COMPANY_TYPE_USE = "使用单位"; private final static String COMPANY_TYPE_USE = "使用单位";
...@@ -94,22 +81,12 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -94,22 +81,12 @@ public class AQZSDPStatisticsServiceImpl {
private final static String COMPANY_TYPE_FILLING = "充装单位"; private final static String COMPANY_TYPE_FILLING = "充装单位";
private static List<EquipmentCategoryDto> equipmentCategoryDtos;
private static List<RegionModel> regionModels = new ArrayList<>();
private RestHighLevelClient restHighLevelClient; private RestHighLevelClient restHighLevelClient;
private AQZSDPStatisticsMapper statisticsMapper; private AQZSDPStatisticsMapper statisticsMapper;
private EquipmentCategoryMapper equipmentCategoryMapper;
private EquipTechParamPipelineMapper techParamsPipelineMapper;
private TzBaseEnterpriseInfoMapper enterpriseInfoMapper; private TzBaseEnterpriseInfoMapper enterpriseInfoMapper;
...@@ -120,36 +97,10 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -120,36 +97,10 @@ public class AQZSDPStatisticsServiceImpl {
private StCommonServiceImpl stCommonService; private StCommonServiceImpl stCommonService;
public void init() {
// 数据不变所以放到内存,提高响应时间
equipmentCategoryDtos = equipmentCategoryMapper.selectClassify();
initReginCode();
}
private void initReginCode() {
Collection<RegionModel> result = Systemctl.regionClient.queryForTree(null).getResult();
result.forEach(r -> {
regionModels.add(r);
this.loopSetChildRegin(regionModels, r.getChildren());
});
}
private void loopSetChildRegin(List<RegionModel> regionModels, Collection<RegionModel> children) { public AQZSDPStatisticsServiceImpl(RestHighLevelClient restHighLevelClient, AQZSDPStatisticsMapper statisticsMapper, TzBaseEnterpriseInfoMapper enterpriseInfoMapper, TzsUserInfoMapper userInfoMapper, CylinderStatisticsMapper cylinderStatisticsMapper, StCommonServiceImpl stCommonService) {
if (children != null && children.size() > 0) {
children.forEach(c -> {
regionModels.add(c);
this.loopSetChildRegin(regionModels, c.getChildren());
});
}
}
public AQZSDPStatisticsServiceImpl(RestHighLevelClient restHighLevelClient, AQZSDPStatisticsMapper statisticsMapper, EquipmentCategoryMapper equipmentCategoryMapper, EquipTechParamPipelineMapper techParamsPipelineMapper, TzBaseEnterpriseInfoMapper enterpriseInfoMapper, TzsUserInfoMapper userInfoMapper, CylinderStatisticsMapper cylinderStatisticsMapper, StCommonServiceImpl stCommonService) {
this.restHighLevelClient = restHighLevelClient; this.restHighLevelClient = restHighLevelClient;
this.statisticsMapper = statisticsMapper; this.statisticsMapper = statisticsMapper;
this.equipmentCategoryMapper = equipmentCategoryMapper;
this.techParamsPipelineMapper = techParamsPipelineMapper;
this.enterpriseInfoMapper = enterpriseInfoMapper; this.enterpriseInfoMapper = enterpriseInfoMapper;
this.userInfoMapper = userInfoMapper; this.userInfoMapper = userInfoMapper;
this.cylinderStatisticsMapper = cylinderStatisticsMapper; this.cylinderStatisticsMapper = cylinderStatisticsMapper;
...@@ -210,7 +161,7 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -210,7 +161,7 @@ public class AQZSDPStatisticsServiceImpl {
} }
} }
public Map<String, Object> getChildEarlyWarning(DPFilterParamDto dpFilterParamDto) throws Exception { public Map<String, Object> getChildEarlyWarning(DPFilterParamDto dpFilterParamDto) {
List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto.getCityCode()); List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto.getCityCode());
Map<String, SecurityIndexCountItemDto> regionCodeSecurityIndexMap = getSecurityIndexCountItemDtoMap(regionModels); Map<String, SecurityIndexCountItemDto> regionCodeSecurityIndexMap = getSecurityIndexCountItemDtoMap(regionModels);
Set<String> legendData = getLegendForCyArea(); Set<String> legendData = getLegendForCyArea();
...@@ -358,15 +309,6 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -358,15 +309,6 @@ public class AQZSDPStatisticsServiceImpl {
countItemDto.setJianyanchaoqi("0"); countItemDto.setJianyanchaoqi("0");
} }
private void setDefaultZeroData(List<String> xuke, List<String> shiyongdengji, List<String> jianyanchaoqi, List<String> jianyanhege, List<String> czjc, List<String> czjchege) {
xuke.add("0");
shiyongdengji.add("0");
jianyanchaoqi.add("0");
jianyanhege.add("0");
czjc.add("0");
czjchege.add("0");
}
public Map<String, Object> mainBodyCount(String cityCode) { public Map<String, Object> mainBodyCount(String cityCode) {
Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> resultMap = new HashMap<>();
Map<String, Object> dataMap = new HashMap<>(); Map<String, Object> dataMap = new HashMap<>();
...@@ -861,11 +803,11 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -861,11 +803,11 @@ public class AQZSDPStatisticsServiceImpl {
return new HashMap<>(); return new HashMap<>();
} }
// 1.气瓶数量统计 // 1.气瓶数量统计
long cylinderNum = this.staticsCenterMapCountDataForCylinder(result, orgCode); long cylinderNum = stCommonService.staticsCenterMapCountDataForCylinder(result, orgCode);
//1.8大类设备数量统计,压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量 //1.8大类设备数量统计,压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量
this.staticsCenterMapCountDataForEquip(result, cylinderNum, orgCode); stCommonService.staticsCenterMapCountDataForEquip(result, cylinderNum, orgCode);
//2.压力管道长度统计 //2.压力管道长度统计
this.staticsCenterMapCountDataForPipeline(result, orgCode); stCommonService.staticsCenterMapCountDataForPipeline(result, orgCode);
//3.单位数量统计 //3.单位数量统计
this.staticsCenterMapCountDataForCompany(result, orgCode); this.staticsCenterMapCountDataForCompany(result, orgCode);
//4.人员数量统计 //4.人员数量统计
...@@ -879,7 +821,7 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -879,7 +821,7 @@ public class AQZSDPStatisticsServiceImpl {
List<Map<String, Object>> list = statisticsMapper.selectByOrg(orgCode); List<Map<String, Object>> list = statisticsMapper.selectByOrg(orgCode);
Map<String, Object> dataMap = new HashMap<>(); Map<String, Object> dataMap = new HashMap<>();
AtomicReference<Long> issueCount = new AtomicReference<>(0L); AtomicReference<Long> issueCount = new AtomicReference<>(0L);
list.stream().forEach(t -> { list.forEach(t -> {
dataMap.put(t.get("sourceType").toString(), t.get("count")); dataMap.put(t.get("sourceType").toString(), t.get("count"));
issueCount.updateAndGet(v -> v + Long.parseLong(t.get("count").toString())); issueCount.updateAndGet(v -> v + Long.parseLong(t.get("count").toString()));
}); });
...@@ -890,79 +832,6 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -890,79 +832,6 @@ public class AQZSDPStatisticsServiceImpl {
} }
private long staticsCenterMapCountDataForCylinder(Map<String, Object> result, String orgCode) {
long num = 0;
CountRequest request = new CountRequest();
request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
// 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 设备类别精确查询气瓶
boolMust.must(QueryBuilders.termsQuery("EQU_CATEGORY_CODE", EQU_CATEGORY_CYLINDER));
// 且在用状态设备
boolMust.must(QueryBuilders.termQuery("EQU_STATE", EquimentEnum.ZAIYONG.getCode()));
request.query(boolMust);
try {
CountResponse response = restHighLevelClient.count(request, RequestOptions.DEFAULT);
num = response.getCount();
} catch (IOException e) {
throw new RuntimeException(e);
}
result.put(DPMapStatisticsItemEnum.GAS.getCode(), num);
return num;
}
private void staticsCenterMapCountDataForEquip(Map<String, Object> result, long cylinderNum, String orgCode) {
SearchRequest request = new SearchRequest();
request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
// 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 且在用状态设备
boolMust.must(QueryBuilders.termQuery("EQU_STATE", EquimentEnum.ZAIYONG.getCode()));
SearchSourceBuilder builder = new SearchSourceBuilder();
builder.query(boolMust);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("count_by_equ_list_code").field("EQU_LIST_CODE");
builder.aggregation(aggregationBuilder);
request.source(builder);
try {
SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
Terms terms = response.getAggregations().get("count_by_equ_list_code");
Map<String, Long> countMap = new HashMap<>();
for (Terms.Bucket bucket : terms.getBuckets()) {
// 压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量
if (bucket.getKeyAsString().equals(EQU_LIST_CYLINDER)) {
countMap.put(bucket.getKeyAsString(), bucket.getDocCount() - cylinderNum);
} else {
countMap.put(bucket.getKeyAsString(), bucket.getDocCount());
}
}
// 按照8大类枚举,进行加工。目的:固定八大类防止没统计数据导致缺少分类、将设备种类的code换成前端定义的key
equipmentCategoryDtos.forEach(c -> {
result.put(this.castCategoryCode2WebCode(c.getCode()), countMap.getOrDefault(c.getCode(), 0L));
});
result.put(DPMapStatisticsItemEnum.TOTAL.getCode(), countMap.values().stream().mapToLong(e -> e).sum() + cylinderNum);
} catch (IOException e) {
throw new RuntimeException(e);
}
result.remove(DPMapStatisticsItemEnum.PRESSURE_PIPELINES.getCategory());
}
private String castCategoryCode2WebCode(String category) {
DPMapStatisticsItemEnum itemEnum = DPMapStatisticsItemEnum.getInstanceByCategory(category);
return itemEnum.getCode();
}
private void staticsCenterMapCountDataForPipeline(Map<String, Object> result, String orgCode) {
String length = techParamsPipelineMapper.sumPipeLengthByOrgCode(orgCode);
BigDecimal lengthDecimal = new BigDecimal(length);
if (lengthDecimal.compareTo(BigDecimal.ZERO) > 0) {
length = lengthDecimal.divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP).toPlainString();
}
result.put(DPMapStatisticsItemEnum.PRESSURE_PIPELINES.getCode(), length);
}
private void staticsCenterMapCountDataForCompany(Map<String, Object> result, String orgCode) { private void staticsCenterMapCountDataForCompany(Map<String, Object> result, String orgCode) {
if (orgCode == null) { if (orgCode == null) {
setDefaultCompanyCountData(result); setDefaultCompanyCountData(result);
...@@ -1028,11 +897,11 @@ public class AQZSDPStatisticsServiceImpl { ...@@ -1028,11 +897,11 @@ public class AQZSDPStatisticsServiceImpl {
return new HashMap<>(); return new HashMap<>();
} }
// 0. 气瓶数量统计 // 0. 气瓶数量统计
long cylinderNum = this.staticsCenterMapCountDataForCylinder(result, orgCode); long cylinderNum = stCommonService.staticsCenterMapCountDataForCylinder(result, orgCode);
// 1. 8大类设备数量统计,压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量 // 1. 8大类设备数量统计,压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量
this.staticsCenterMapCountDataForEquip(result, cylinderNum, orgCode); stCommonService.staticsCenterMapCountDataForEquip(result, cylinderNum, orgCode);
// 2. 压力管道长度统计 // 2. 压力管道长度统计
this.staticsCenterMapCountDataForPipeline(result, orgCode); stCommonService.staticsCenterMapCountDataForPipeline(result, orgCode);
// 3.单位数量统计 // 3.单位数量统计
this.staticsCenterMapCountDataForCompany(result, orgCode); this.staticsCenterMapCountDataForCompany(result, orgCode);
// 4. 人员数量统计 // 4. 人员数量统计
......
...@@ -16,11 +16,9 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.*; ...@@ -16,11 +16,9 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.*;
import com.yeejoin.amos.boot.module.statistics.api.mapper.ZLStatisticsMapper; import com.yeejoin.amos.boot.module.statistics.api.mapper.ZLStatisticsMapper;
import com.yeejoin.amos.boot.module.ymt.api.dto.EquipmentCategoryDto; import com.yeejoin.amos.boot.module.ymt.api.dto.EquipmentCategoryDto;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquimentEnum; import com.yeejoin.amos.boot.module.ymt.api.enums.EquimentEnum;
import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipTechParamPipelineMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipmentCategoryMapper; import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipmentCategoryMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.TzBaseEnterpriseInfoMapper; import com.yeejoin.amos.boot.module.ymt.api.mapper.TzBaseEnterpriseInfoMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.TzsUserInfoMapper; import com.yeejoin.amos.boot.module.ymt.api.mapper.TzsUserInfoMapper;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.RegionModel; import com.yeejoin.amos.feign.systemctl.model.RegionModel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -37,7 +35,6 @@ import org.elasticsearch.search.aggregations.AggregationBuilders; ...@@ -37,7 +35,6 @@ import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -49,7 +46,6 @@ import java.time.LocalDateTime; ...@@ -49,7 +46,6 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalAdjusters;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function; import java.util.function.Function;
...@@ -105,13 +101,8 @@ public class JGDPStatisticsServiceImpl { ...@@ -105,13 +101,8 @@ public class JGDPStatisticsServiceImpl {
private final static String REGION_NAME = "regionName"; private final static String REGION_NAME = "regionName";
@Autowired
private EquipmentCategoryMapper equipmentCategoryMapper;
private JgUseRegistrationMapper useRegistrationMapper; private JgUseRegistrationMapper useRegistrationMapper;
private EquipTechParamPipelineMapper techParamsPipelineMapper;
private JgEnableDisableMapper enableDisableMapper; private JgEnableDisableMapper enableDisableMapper;
private JgScrapCancelMapper scrapCancelMapper; private JgScrapCancelMapper scrapCancelMapper;
...@@ -122,24 +113,18 @@ public class JGDPStatisticsServiceImpl { ...@@ -122,24 +113,18 @@ public class JGDPStatisticsServiceImpl {
private CommonMapper commonMapper; private CommonMapper commonMapper;
private static List<EquipmentCategoryDto> equipmentCategoryDtos;
private TzsUserInfoMapper userInfoMapper; private TzsUserInfoMapper userInfoMapper;
private ZLStatisticsMapper zlStatisticsMapper; private ZLStatisticsMapper zlStatisticsMapper;
private static Map<String, String> regionCodeOrgCodeMap = new ConcurrentHashMap<>();
private static List<RegionModel> regionModels = new ArrayList<>();
private DPStatisticsMapper dpStatisticsMapper; private DPStatisticsMapper dpStatisticsMapper;
private JgUseRegistrationManageMapper jgUseRegistrationManageMapper; private JgUseRegistrationManageMapper jgUseRegistrationManageMapper;
public JGDPStatisticsServiceImpl(EquipmentCategoryMapper equipmentCategoryMapper, JgUseRegistrationMapper useRegistrationMapper, EquipTechParamPipelineMapper techParamsPipelineMapper, JgEnableDisableMapper enableDisableMapper, JgScrapCancelMapper scrapCancelMapper, RestHighLevelClient restHighLevelClient, TzBaseEnterpriseInfoMapper enterpriseInfoMapper, CommonMapper commonMapper, TzsUserInfoMapper userInfoMapper, ZLStatisticsMapper zlStatisticsMapper, DPStatisticsMapper dpStatisticsMapper, JgUseRegistrationManageMapper jgUseRegistrationManageMapper) { private StCommonServiceImpl stCommonService;
this.equipmentCategoryMapper = equipmentCategoryMapper;
public JGDPStatisticsServiceImpl(JgUseRegistrationMapper useRegistrationMapper, JgEnableDisableMapper enableDisableMapper, JgScrapCancelMapper scrapCancelMapper, RestHighLevelClient restHighLevelClient, TzBaseEnterpriseInfoMapper enterpriseInfoMapper, CommonMapper commonMapper, TzsUserInfoMapper userInfoMapper, ZLStatisticsMapper zlStatisticsMapper, DPStatisticsMapper dpStatisticsMapper, JgUseRegistrationManageMapper jgUseRegistrationManageMapper, StCommonServiceImpl stCommonService) {
this.useRegistrationMapper = useRegistrationMapper; this.useRegistrationMapper = useRegistrationMapper;
this.techParamsPipelineMapper = techParamsPipelineMapper;
this.enableDisableMapper = enableDisableMapper; this.enableDisableMapper = enableDisableMapper;
this.scrapCancelMapper = scrapCancelMapper; this.scrapCancelMapper = scrapCancelMapper;
this.restHighLevelClient = restHighLevelClient; this.restHighLevelClient = restHighLevelClient;
...@@ -149,15 +134,9 @@ public class JGDPStatisticsServiceImpl { ...@@ -149,15 +134,9 @@ public class JGDPStatisticsServiceImpl {
this.zlStatisticsMapper = zlStatisticsMapper; this.zlStatisticsMapper = zlStatisticsMapper;
this.dpStatisticsMapper = dpStatisticsMapper; this.dpStatisticsMapper = dpStatisticsMapper;
this.jgUseRegistrationManageMapper = jgUseRegistrationManageMapper; this.jgUseRegistrationManageMapper = jgUseRegistrationManageMapper;
this.stCommonService = stCommonService;
} }
public void init() {
// 数据不变所以放到内存,提高响应时间
equipmentCategoryDtos = equipmentCategoryMapper.selectClassify();
initReginCode();
}
private List<LegendDataDto> buildLegendDataList() { private List<LegendDataDto> buildLegendDataList() {
List<LegendDataDto> legendDataDtos = new ArrayList<>(); List<LegendDataDto> legendDataDtos = new ArrayList<>();
legendDataDtos.add(LegendDataDto.builder().dataKey("newDevice").value("新增登记设备").build()); legendDataDtos.add(LegendDataDto.builder().dataKey("newDevice").value("新增登记设备").build());
...@@ -175,9 +154,9 @@ public class JGDPStatisticsServiceImpl { ...@@ -175,9 +154,9 @@ public class JGDPStatisticsServiceImpl {
//2.1 图列数据构造 //2.1 图列数据构造
result.put("legendData", legendDataDtos); result.put("legendData", legendDataDtos);
//2.2 x轴数据构造 //2.2 x轴数据构造
result.put("xdata", this.getXData(equipmentCategoryDtos)); result.put("xdata", this.getXData(StCommonServiceImpl.getEquipmentCategory()));
//2.3 y轴数据构造 //2.3 y轴数据构造
this.buildYData(result, dpFilterParamDto, equipmentCategoryDtos); this.buildYData(result, dpFilterParamDto, StCommonServiceImpl.getEquipmentCategory());
return result; return result;
} }
...@@ -246,16 +225,16 @@ public class JGDPStatisticsServiceImpl { ...@@ -246,16 +225,16 @@ public class JGDPStatisticsServiceImpl {
public Map<String, Object> getCenterMapCountDataForGlobal(DPFilterParamDto dpFilterParamDto) { public Map<String, Object> getCenterMapCountDataForGlobal(DPFilterParamDto dpFilterParamDto) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
if (StringUtils.isEmpty(orgCode)) { if (StringUtils.isEmpty(orgCode)) {
return new HashMap<>(); return new HashMap<>();
} }
// 1.气瓶数量统计 // 1.气瓶数量统计
long cylinderNum = this.staticsCenterMapCountDataForCylinder(result, orgCode); long cylinderNum = stCommonService.staticsCenterMapCountDataForCylinder(result, orgCode);
//1.8大类设备数量统计,压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量 //1.8大类设备数量统计,压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量
this.staticsCenterMapCountDataForEquip(result, cylinderNum, orgCode); stCommonService.staticsCenterMapCountDataForEquip(result, cylinderNum, orgCode);
//2.压力管道长度统计 //2.压力管道长度统计
this.staticsCenterMapCountDataForPipeline(result, orgCode); stCommonService.staticsCenterMapCountDataForPipeline(result, orgCode);
//3.单位数量统计 //3.单位数量统计
this.staticsCenterMapCountDataForCompany(result, orgCode); this.staticsCenterMapCountDataForCompany(result, orgCode);
//4.人员数量统计 //4.人员数量统计
...@@ -265,16 +244,16 @@ public class JGDPStatisticsServiceImpl { ...@@ -265,16 +244,16 @@ public class JGDPStatisticsServiceImpl {
private Map<String, Object> getCenterMapOverviewData(DPFilterParamDto dpFilterParamDto) { private Map<String, Object> getCenterMapOverviewData(DPFilterParamDto dpFilterParamDto) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
if (StringUtils.isEmpty(orgCode)) { if (StringUtils.isEmpty(orgCode)) {
return new HashMap<>(); return new HashMap<>();
} }
// 0. 气瓶数量统计 // 0. 气瓶数量统计
long cylinderNum = this.staticsCenterMapCountDataForCylinder(result, orgCode); long cylinderNum = stCommonService.staticsCenterMapCountDataForCylinder(result, orgCode);
// 1. 8大类设备数量统计,压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量 // 1. 8大类设备数量统计,压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量
this.staticsCenterMapCountDataForEquip(result, cylinderNum, orgCode); stCommonService.staticsCenterMapCountDataForEquip(result, cylinderNum, orgCode);
// 2. 压力管道长度统计 // 2. 压力管道长度统计
this.staticsCenterMapCountDataForPipeline(result, orgCode); stCommonService.staticsCenterMapCountDataForPipeline(result, orgCode);
// 3. 人员数量统计 // 3. 人员数量统计
this.staticsCenterMapCountDataForPerson(result, dpFilterParamDto, orgCode); this.staticsCenterMapCountDataForPerson(result, dpFilterParamDto, orgCode);
return result; return result;
...@@ -301,79 +280,6 @@ public class JGDPStatisticsServiceImpl { ...@@ -301,79 +280,6 @@ public class JGDPStatisticsServiceImpl {
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());
} }
private long staticsCenterMapCountDataForCylinder(Map<String, Object> result, String orgCode) {
long num = 0;
CountRequest request = new CountRequest();
request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
// 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 设备类别精确查询气瓶
boolMust.must(QueryBuilders.termsQuery("EQU_CATEGORY_CODE", EQU_CATEGORY_CYLINDER));
// 且在用状态设备
boolMust.must(QueryBuilders.termQuery("EQU_STATE", EquimentEnum.ZAIYONG.getCode()));
request.query(boolMust);
try {
CountResponse response = restHighLevelClient.count(request, RequestOptions.DEFAULT);
num = response.getCount();
} catch (IOException e) {
throw new RuntimeException(e);
}
result.put(DPMapStatisticsItemEnum.GAS.getCode(), num);
return num;
}
private void staticsCenterMapCountDataForPipeline(Map<String, Object> result, String orgCode) {
String length = techParamsPipelineMapper.sumPipeLengthByOrgCode(orgCode);
BigDecimal lengthDecimal = new BigDecimal(length);
if (lengthDecimal.compareTo(BigDecimal.ZERO) > 0) {
length = lengthDecimal.divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP).toPlainString();
}
result.put(DPMapStatisticsItemEnum.PRESSURE_PIPELINES.getCode(), length);
}
private void staticsCenterMapCountDataForEquip(Map<String, Object> result, long cylinderNum, String orgCode) {
SearchRequest request = new SearchRequest();
request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
// 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 且在用状态设备
boolMust.must(QueryBuilders.termQuery("EQU_STATE", EquimentEnum.ZAIYONG.getCode()));
SearchSourceBuilder builder = new SearchSourceBuilder();
builder.query(boolMust);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("count_by_equ_list_code").field("EQU_LIST_CODE");
builder.aggregation(aggregationBuilder);
request.source(builder);
try {
SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
Terms terms = response.getAggregations().get("count_by_equ_list_code");
Map<String, Long> countMap = new HashMap<>();
for (Terms.Bucket bucket : terms.getBuckets()) {
// 压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量
if (bucket.getKeyAsString().equals(EQU_LIST_CYLINDER)) {
countMap.put(bucket.getKeyAsString(), bucket.getDocCount() - cylinderNum);
} else {
countMap.put(bucket.getKeyAsString(), bucket.getDocCount());
}
}
// 按照8大类枚举,进行加工。目的:固定八大类防止没统计数据导致缺少分类、将设备种类的code换成前端定义的key
equipmentCategoryDtos.forEach(c -> {
result.put(this.castCategoryCode2WebCode(c.getCode()), countMap.getOrDefault(c.getCode(), 0L));
});
result.put(DPMapStatisticsItemEnum.TOTAL.getCode(), countMap.values().stream().mapToLong(e -> e).sum() + cylinderNum);
} catch (IOException e) {
throw new RuntimeException(e);
}
result.remove(DPMapStatisticsItemEnum.PRESSURE_PIPELINES.getCategory());
}
private String castCategoryCode2WebCode(String category) {
DPMapStatisticsItemEnum itemEnum = DPMapStatisticsItemEnum.getInstanceByCategory(category);
return itemEnum.getCode();
}
public Map<String, Object> useRegisterCount(DPFilterParamDto dpFilterParamDto) { public Map<String, Object> useRegisterCount(DPFilterParamDto dpFilterParamDto) {
// 2.按照前端约定格式返回数据 // 2.按照前端约定格式返回数据
...@@ -413,7 +319,7 @@ public class JGDPStatisticsServiceImpl { ...@@ -413,7 +319,7 @@ public class JGDPStatisticsServiceImpl {
} }
public List<Map<String, Object>> getCenterMapCountDataForOverview(DPFilterParamDto dpFilterParamDto) { public List<Map<String, Object>> getCenterMapCountDataForOverview(DPFilterParamDto dpFilterParamDto) {
List<RegionModel> regionModels = this.setRegionIfRootParent(dpFilterParamDto); List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto);
List<Map<String, Object>> result = regionModels.parallelStream().map(r -> { List<Map<String, Object>> result = regionModels.parallelStream().map(r -> {
DPFilterParamDto filterParamDto = new DPFilterParamDto(); DPFilterParamDto filterParamDto = new DPFilterParamDto();
filterParamDto.setCityCode(r.getRegionCode().toString()); filterParamDto.setCityCode(r.getRegionCode().toString());
...@@ -425,23 +331,12 @@ public class JGDPStatisticsServiceImpl { ...@@ -425,23 +331,12 @@ public class JGDPStatisticsServiceImpl {
return result; return result;
} }
private List<RegionModel> setRegionIfRootParent(DPFilterParamDto dpFilterParamDto) {
List<RegionModel> regions = regionModels.parallelStream().filter(e -> e.getParentRegionCode() != null && (e.getParentRegionCode().toString()).equals(dpFilterParamDto.getCityCode())).collect(Collectors.toList());
// 陕西省时需要在地图返回独立的地级市:韩城、杨凌、西咸
if (dpFilterParamDto.getCityCode().equals(TZSCommonConstant.SHAN_XI_REGION_CODE)) {
List<RegionModel> independentRegions = ReginStepEnum.enum2RegionList("map");
regions.addAll(independentRegions);
}
return regions;
}
private void setCompanyDataBatch(List<Map<String, Object>> result) { private void setCompanyDataBatch(List<Map<String, Object>> result) {
List<CountDto> countDtos = enterpriseInfoMapper.countByUnitTypeAndOrgCodeNoParam(); List<CountDto> countDtos = enterpriseInfoMapper.countByUnitTypeAndOrgCodeNoParam();
result.forEach(m -> { result.forEach(m -> {
String cityCode = m.get("cityCode").toString(); String cityCode = m.get("cityCode").toString();
String orgCode = regionCodeOrgCodeMap.get(cityCode); String orgCode = StCommonServiceImpl.getRegionCodeOrgCodeMap().get(cityCode);
if (orgCode != null) { 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());
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());
...@@ -459,22 +354,6 @@ public class JGDPStatisticsServiceImpl { ...@@ -459,22 +354,6 @@ public class JGDPStatisticsServiceImpl {
m.put(DPMapStatisticsItemEnum.GAS_UNITS.getCode(), 0); m.put(DPMapStatisticsItemEnum.GAS_UNITS.getCode(), 0);
} }
private void initReginCode() {
Collection<RegionModel> result = Systemctl.regionClient.queryForTree(null).getResult();
result.forEach(r -> {
regionModels.add(r);
this.loopSetChildRegin(regionModels, r.getChildren());
});
}
private void loopSetChildRegin(List<RegionModel> regionModels, Collection<RegionModel> children) {
if (children != null && children.size() > 0) {
children.forEach(c -> {
regionModels.add(c);
this.loopSetChildRegin(regionModels, c.getChildren());
});
}
}
public Map<String, Object> querySafetyIndex(DPFilterParamDto dpFilterParamDto) { public Map<String, Object> querySafetyIndex(DPFilterParamDto dpFilterParamDto) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
...@@ -534,7 +413,7 @@ public class JGDPStatisticsServiceImpl { ...@@ -534,7 +413,7 @@ public class JGDPStatisticsServiceImpl {
CountRequest request = new CountRequest(); CountRequest request = new CountRequest();
request.indices("idx_biz_view_jg_all"); request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery(); BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
String orgCode = getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 按照管辖机构区域信息模糊查询 // 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*")); boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 设备状态过滤 // 设备状态过滤
...@@ -574,7 +453,7 @@ public class JGDPStatisticsServiceImpl { ...@@ -574,7 +453,7 @@ public class JGDPStatisticsServiceImpl {
CountRequest request = new CountRequest(); CountRequest request = new CountRequest();
request.indices("idx_biz_view_jg_all"); request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery(); BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 按照管辖机构区域信息模糊查询 // 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*")); boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 且在用状态设备 // 且在用状态设备
...@@ -606,7 +485,7 @@ public class JGDPStatisticsServiceImpl { ...@@ -606,7 +485,7 @@ public class JGDPStatisticsServiceImpl {
CountRequest request = new CountRequest(); CountRequest request = new CountRequest();
request.indices("idx_biz_view_jg_all"); request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery(); BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 按照管辖机构区域信息模糊查询 // 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*")); boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 在用状态设备 // 在用状态设备
...@@ -662,14 +541,14 @@ public class JGDPStatisticsServiceImpl { ...@@ -662,14 +541,14 @@ public class JGDPStatisticsServiceImpl {
} }
private long countCompanyForCertDateTemporary(DPFilterParamDto dpFilterParamDto) { private long countCompanyForCertDateTemporary(DPFilterParamDto dpFilterParamDto) {
String orgCode = getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 临期6个月 // 临期6个月
String limitDate = DateUtil.offset(DateUtil.date(), DateField.DAY_OF_MONTH, 6).toDateStr(); String limitDate = DateUtil.offset(DateUtil.date(), DateField.DAY_OF_MONTH, 6).toDateStr();
return zlStatisticsMapper.countCompanyForCertDateTemporary(dpFilterParamDto, orgCode, limitDate); return zlStatisticsMapper.countCompanyForCertDateTemporary(dpFilterParamDto, orgCode, limitDate);
} }
private long countCompanyForCertDateTimeOut(DPFilterParamDto dpFilterParamDto) { private long countCompanyForCertDateTimeOut(DPFilterParamDto dpFilterParamDto) {
String orgCode = getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
String limitDate = DateUtil.today(); String limitDate = DateUtil.today();
return zlStatisticsMapper.countCompanyForCertDateTimeOut(dpFilterParamDto, orgCode, limitDate); return zlStatisticsMapper.countCompanyForCertDateTimeOut(dpFilterParamDto, orgCode, limitDate);
} }
...@@ -683,7 +562,7 @@ public class JGDPStatisticsServiceImpl { ...@@ -683,7 +562,7 @@ public class JGDPStatisticsServiceImpl {
} }
private long countCompanyByOperatingStatus(DPFilterParamDto dpFilterParamDto, String operatingStatus) { private long countCompanyByOperatingStatus(DPFilterParamDto dpFilterParamDto, String operatingStatus) {
String orgCode = getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
return enterpriseInfoMapper.countByOperatingStatusAndOrgCode(orgCode, operatingStatus, dpFilterParamDto.getCityCode()); return enterpriseInfoMapper.countByOperatingStatusAndOrgCode(orgCode, operatingStatus, dpFilterParamDto.getCityCode());
} }
...@@ -766,19 +645,19 @@ public class JGDPStatisticsServiceImpl { ...@@ -766,19 +645,19 @@ public class JGDPStatisticsServiceImpl {
} }
private Long countAllBizDataInFlowing(DPFilterParamDto dpFilterParamDto) { private Long countAllBizDataInFlowing(DPFilterParamDto dpFilterParamDto) {
String orgCode = getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
List<Long> inFlowingForDP = commonMapper.countAllInFlowingForDPNoFinishedBizData(orgCode, dpFilterParamDto); List<Long> inFlowingForDP = commonMapper.countAllInFlowingForDPNoFinishedBizData(orgCode, dpFilterParamDto);
return inFlowingForDP.stream().mapToLong(e -> e).sum(); return inFlowingForDP.stream().mapToLong(e -> e).sum();
} }
private List<Long> countBizDataInFlowing(DPFilterParamDto dpFilterParamDto) { private List<Long> countBizDataInFlowing(DPFilterParamDto dpFilterParamDto) {
String orgCode = getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
return commonMapper.countAllInFlowingForDPNoFinishedBizData(orgCode, dpFilterParamDto); return commonMapper.countAllInFlowingForDPNoFinishedBizData(orgCode, dpFilterParamDto);
} }
private List<Long> countBizFinishedNum(DPFilterParamDto dpFilterParamDto) { private List<Long> countBizFinishedNum(DPFilterParamDto dpFilterParamDto) {
// 1.统计各业务办理量注意要和x轴顺序一致 // 1.统计各业务办理量注意要和x轴顺序一致
String orgCode = getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 省、市、区县为按照行政区划进行编码的,公司的code为行政区划编码 // 省、市、区县为按照行政区划进行编码的,公司的code为行政区划编码
if (orgCode == null) { if (orgCode == null) {
return Arrays.asList(0L, 0L, 0L, 0L, 0L, 0L); return Arrays.asList(0L, 0L, 0L, 0L, 0L, 0L);
...@@ -786,23 +665,12 @@ public class JGDPStatisticsServiceImpl { ...@@ -786,23 +665,12 @@ public class JGDPStatisticsServiceImpl {
return commonMapper.countBizFinishedNumForDP(orgCode, dpFilterParamDto); return commonMapper.countBizFinishedNumForDP(orgCode, dpFilterParamDto);
} }
private String getAndSetOrgCode(String cityCode) {
String orgCode = regionCodeOrgCodeMap.get(cityCode);
if (orgCode == null) {
orgCode = commonMapper.getOrgCodeByCompanyCode(cityCode);
if (orgCode != null) {
regionCodeOrgCodeMap.put(cityCode, orgCode);
}
}
return orgCode;
}
public List<Map<String, Object>> equStateCount(DPFilterParamDto dpFilterParamDto) { public List<Map<String, Object>> equStateCount(DPFilterParamDto dpFilterParamDto) {
List<Map<String, Object>> resultList = new ArrayList<>(); List<Map<String, Object>> resultList = new ArrayList<>();
SearchRequest request = new SearchRequest(); SearchRequest request = new SearchRequest();
request.indices("idx_biz_view_jg_all"); request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery(); BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 按照管辖机构区域信息模糊查询 // 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*")); boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
SearchSourceBuilder builder = new SearchSourceBuilder(); SearchSourceBuilder builder = new SearchSourceBuilder();
...@@ -851,7 +719,7 @@ public class JGDPStatisticsServiceImpl { ...@@ -851,7 +719,7 @@ public class JGDPStatisticsServiceImpl {
SearchRequest request = new SearchRequest(); SearchRequest request = new SearchRequest();
request.indices("idx_biz_view_jg_all"); request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery(); BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 按照管辖机构区域信息模糊查询 // 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*")); boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
SearchSourceBuilder builder = new SearchSourceBuilder(); SearchSourceBuilder builder = new SearchSourceBuilder();
...@@ -966,7 +834,7 @@ public class JGDPStatisticsServiceImpl { ...@@ -966,7 +834,7 @@ public class JGDPStatisticsServiceImpl {
} }
public List<Map<String, Object>> maintenanceCountTopTen(DPFilterParamDto dpFilterParamDto) { public List<Map<String, Object>> maintenanceCountTopTen(DPFilterParamDto dpFilterParamDto) {
List<RegionModel> regionModels = setRegionIfRootParent(dpFilterParamDto); List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto);
List<Integer> regionCodeList = regionModels.stream().map(m -> m.getRegionCode()).collect(Collectors.toList()); List<Integer> regionCodeList = regionModels.stream().map(m -> m.getRegionCode()).collect(Collectors.toList());
Map<Integer, RegionModel> regionMap = regionModels.stream().collect(Collectors.toMap(RegionModel::getRegionCode, Function.identity())); Map<Integer, RegionModel> regionMap = regionModels.stream().collect(Collectors.toMap(RegionModel::getRegionCode, Function.identity()));
List<Map<String, Object>> list = dpStatisticsMapper.maintenanceCountTopTen(dpFilterParamDto, regionCodeList); List<Map<String, Object>> list = dpStatisticsMapper.maintenanceCountTopTen(dpFilterParamDto, regionCodeList);
...@@ -983,7 +851,7 @@ public class JGDPStatisticsServiceImpl { ...@@ -983,7 +851,7 @@ public class JGDPStatisticsServiceImpl {
} }
public Map<String, Object> maintenanceCount(DPFilterParamDto dpFilterParamDto) { public Map<String, Object> maintenanceCount(DPFilterParamDto dpFilterParamDto) {
List<RegionModel> regionModels = setRegionIfRootParent(dpFilterParamDto); List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto);
List<Integer> regionCodeList = regionModels.stream().map(m -> m.getRegionCode()).collect(Collectors.toList()); List<Integer> regionCodeList = regionModels.stream().map(m -> m.getRegionCode()).collect(Collectors.toList());
Map<Integer, RegionModel> regionMap = regionModels.stream().collect(Collectors.toMap(RegionModel::getRegionCode, Function.identity())); Map<Integer, RegionModel> regionMap = regionModels.stream().collect(Collectors.toMap(RegionModel::getRegionCode, Function.identity()));
List<Map<String, Object>> list = dpStatisticsMapper.maintenanceCount(dpFilterParamDto, regionCodeList); List<Map<String, Object>> list = dpStatisticsMapper.maintenanceCount(dpFilterParamDto, regionCodeList);
...@@ -1000,7 +868,7 @@ public class JGDPStatisticsServiceImpl { ...@@ -1000,7 +868,7 @@ public class JGDPStatisticsServiceImpl {
} }
public Map<String, Object> cityBusinessCount(DPFilterParamDto dpFilterParamDto) { public Map<String, Object> cityBusinessCount(DPFilterParamDto dpFilterParamDto) {
List<RegionModel> regionModels = setRegionIfRootParent(dpFilterParamDto); List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto);
Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> resultMap = new HashMap<>();
/** /**
* 业务类型0告知管理,1使用登记,2变更登记,3停用启用,4注销报废 * 业务类型0告知管理,1使用登记,2变更登记,3停用启用,4注销报废
...@@ -1515,7 +1383,7 @@ public class JGDPStatisticsServiceImpl { ...@@ -1515,7 +1383,7 @@ public class JGDPStatisticsServiceImpl {
} }
public List<Map<String, Object>> dataStatisticByReginCode(DPFilterParamDto dpFilterParamDto) { public List<Map<String, Object>> dataStatisticByReginCode(DPFilterParamDto dpFilterParamDto) {
List<RegionModel> regionModels = setRegionIfRootParent(dpFilterParamDto); List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto);
List<Map<String, Object>> result = regionModels.parallelStream().map(r -> { List<Map<String, Object>> result = regionModels.parallelStream().map(r -> {
DPFilterParamDto filterParamDto = new DPFilterParamDto(); DPFilterParamDto filterParamDto = new DPFilterParamDto();
filterParamDto.setCityCode(r.getRegionCode().toString()); filterParamDto.setCityCode(r.getRegionCode().toString());
...@@ -1530,15 +1398,11 @@ public class JGDPStatisticsServiceImpl { ...@@ -1530,15 +1398,11 @@ public class JGDPStatisticsServiceImpl {
private Map<String, Object> staticsCenterMapCountDataForRegin(DPFilterParamDto dpFilterParamDto) { private Map<String, Object> staticsCenterMapCountDataForRegin(DPFilterParamDto dpFilterParamDto) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
String orgCode = regionCodeOrgCodeMap.get(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
if (orgCode == null) { if (StringUtils.isEmpty(orgCode)) {
orgCode = getAndSetOrgCode(dpFilterParamDto.getCityCode()); result.put(DPMapStatisticsItemEnum.DEVICE_COUNT.getCode(), 0L);
if (orgCode == null) { result.put(DPMapStatisticsItemEnum.CERTIFICATE_COUNT.getCode(), 0L);
result.put(DPMapStatisticsItemEnum.DEVICE_COUNT.getCode(), 0L); return result;
result.put(DPMapStatisticsItemEnum.CERTIFICATE_COUNT.getCode(), 0L);
return result;
}
regionCodeOrgCodeMap.put(dpFilterParamDto.getCityCode(), orgCode);
} }
Long certificateCount = jgUseRegistrationManageMapper.countCertificateByReginCode(orgCode); Long certificateCount = jgUseRegistrationManageMapper.countCertificateByReginCode(orgCode);
Long deviceCount = countEquipByReginCode(orgCode); Long deviceCount = countEquipByReginCode(orgCode);
...@@ -1698,16 +1562,16 @@ public class JGDPStatisticsServiceImpl { ...@@ -1698,16 +1562,16 @@ public class JGDPStatisticsServiceImpl {
public Map<String, Object> JGCenterMapCountForGlobal(DPFilterParamDto dpFilterParamDto) { public Map<String, Object> JGCenterMapCountForGlobal(DPFilterParamDto dpFilterParamDto) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
if (StringUtils.isEmpty(orgCode)) { if (StringUtils.isEmpty(orgCode)) {
return new HashMap<>(); return new HashMap<>();
} }
// 0.气瓶数量统计 // 0.气瓶数量统计
long cylinderNum = this.staticsCenterMapCountDataForCylinder(result, orgCode); long cylinderNum = stCommonService.staticsCenterMapCountDataForCylinder(result, orgCode);
// 1.8大类设备数量统计,压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量 // 1.8大类设备数量统计,压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量
this.staticsCenterMapCountDataForEquip(result, cylinderNum, orgCode); stCommonService.staticsCenterMapCountDataForEquip(result, cylinderNum, orgCode);
// 2.压力管道长度统计 // 2.压力管道长度统计
this.staticsCenterMapCountDataForPipeline(result, orgCode); stCommonService.staticsCenterMapCountDataForPipeline(result, orgCode);
// 3.已纳管设备总数 // 3.已纳管设备总数
this.staticsCenterMapCountDataForEquipIsManage(result, orgCode); this.staticsCenterMapCountDataForEquipIsManage(result, orgCode);
// 4.登记证总数 // 4.登记证总数
...@@ -1772,7 +1636,7 @@ public class JGDPStatisticsServiceImpl { ...@@ -1772,7 +1636,7 @@ public class JGDPStatisticsServiceImpl {
} }
public List<Map<String, Object>> JGCenterMapCountForOverview(DPFilterParamDto dpFilterParamDto) { public List<Map<String, Object>> JGCenterMapCountForOverview(DPFilterParamDto dpFilterParamDto) {
List<RegionModel> regionModels = this.setRegionIfRootParent(dpFilterParamDto); List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto);
List<Map<String, Object>> result = regionModels.parallelStream().map(r -> { List<Map<String, Object>> result = regionModels.parallelStream().map(r -> {
DPFilterParamDto filterParamDto = new DPFilterParamDto(); DPFilterParamDto filterParamDto = new DPFilterParamDto();
filterParamDto.setCityCode(r.getRegionCode().toString()); filterParamDto.setCityCode(r.getRegionCode().toString());
......
...@@ -40,7 +40,6 @@ import java.time.LocalDateTime; ...@@ -40,7 +40,6 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalAdjusters;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -70,28 +69,23 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -70,28 +69,23 @@ public class JYJCDPStatisticsServiceImpl {
private TzsUserInfoMapper tzsUserInfoMapper; private TzsUserInfoMapper tzsUserInfoMapper;
private JyjcBaseMapper jyjcBaseMapper;
private JyjcInspectionResultMapper inspectionResultMapper; private JyjcInspectionResultMapper inspectionResultMapper;
private JyjcOpeningApplicationMapper openingApplicationMapper; private JyjcOpeningApplicationMapper openingApplicationMapper;
private static Map<String, String> regionCodeOrgCodeMap = new ConcurrentHashMap<>();
private static Map<String, List<RegionModel>> regionChildRegionMap = new ConcurrentHashMap<>();
private RestHighLevelClient restHighLevelClient; private RestHighLevelClient restHighLevelClient;
public JYJCDPStatisticsServiceImpl(EquipmentCategoryMapper equipmentCategoryMapper, JyjcInspectionApplicationEquipMapper inspectionApplicationEquipMapper, JyjcInspectionApplicationMapper inspectionApplicationMapper, TzsUserInfoMapper tzsUserInfoMapper, JyjcBaseMapper jyjcBaseMapper, JyjcInspectionResultMapper inspectionResultMapper, JyjcOpeningApplicationMapper openingApplicationMapper, RestHighLevelClient restHighLevelClient) { private StCommonServiceImpl stCommonService;
public JYJCDPStatisticsServiceImpl(EquipmentCategoryMapper equipmentCategoryMapper, JyjcInspectionApplicationEquipMapper inspectionApplicationEquipMapper, JyjcInspectionApplicationMapper inspectionApplicationMapper, TzsUserInfoMapper tzsUserInfoMapper, JyjcInspectionResultMapper inspectionResultMapper, JyjcOpeningApplicationMapper openingApplicationMapper, RestHighLevelClient restHighLevelClient, StCommonServiceImpl stCommonService) {
this.equipmentCategoryMapper = equipmentCategoryMapper; this.equipmentCategoryMapper = equipmentCategoryMapper;
this.inspectionApplicationEquipMapper = inspectionApplicationEquipMapper; this.inspectionApplicationEquipMapper = inspectionApplicationEquipMapper;
this.inspectionApplicationMapper = inspectionApplicationMapper; this.inspectionApplicationMapper = inspectionApplicationMapper;
this.tzsUserInfoMapper = tzsUserInfoMapper; this.tzsUserInfoMapper = tzsUserInfoMapper;
this.jyjcBaseMapper = jyjcBaseMapper;
this.inspectionResultMapper = inspectionResultMapper; this.inspectionResultMapper = inspectionResultMapper;
this.openingApplicationMapper = openingApplicationMapper; this.openingApplicationMapper = openingApplicationMapper;
this.restHighLevelClient = restHighLevelClient; this.restHighLevelClient = restHighLevelClient;
this.stCommonService = stCommonService;
} }
...@@ -113,7 +107,7 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -113,7 +107,7 @@ public class JYJCDPStatisticsServiceImpl {
} }
private void buildYData(Map<String, Object> result, List<BizTypeEnum> bizTypeEnums, DPFilterParamDto dpFilterParamDto, List<EquipmentCategoryDto> equipmentCategoryDtos) { private void buildYData(Map<String, Object> result, List<BizTypeEnum> bizTypeEnums, DPFilterParamDto dpFilterParamDto, List<EquipmentCategoryDto> equipmentCategoryDtos) {
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 待统计的数据本来sql可以单独统计,但是要求气瓶单独从压力容器里拎出来,与八大类同级,故java处理 // 待统计的数据本来sql可以单独统计,但是要求气瓶单独从压力容器里拎出来,与八大类同级,故java处理
List<InspectTimeCountDto> inspectTimeCountDtos = inspectionApplicationEquipMapper.countInspectTimeCountByTypeAndEquList(orgCode,dpFilterParamDto); List<InspectTimeCountDto> inspectTimeCountDtos = inspectionApplicationEquipMapper.countInspectTimeCountByTypeAndEquList(orgCode,dpFilterParamDto);
bizTypeEnums.forEach(bizTypeEnum -> { bizTypeEnums.forEach(bizTypeEnum -> {
...@@ -192,7 +186,7 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -192,7 +186,7 @@ public class JYJCDPStatisticsServiceImpl {
public Map<String, Object> inspectPersonCount(DPFilterParamDto dpFilterParamDto) { public Map<String, Object> inspectPersonCount(DPFilterParamDto dpFilterParamDto) {
// 2.按照前端约定格式返回数据 // 2.按照前端约定格式返回数据
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
List<RegionModel> childRegion = this.getRegionList(dpFilterParamDto); List<RegionModel> childRegion = stCommonService.setRegionIfRootParent(dpFilterParamDto);
if (childRegion.isEmpty()) { if (childRegion.isEmpty()) {
return new HashMap<>(0); return new HashMap<>(0);
} }
...@@ -203,21 +197,11 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -203,21 +197,11 @@ public class JYJCDPStatisticsServiceImpl {
return result; return result;
} }
private List<RegionModel> setRegionIfRootParent(String regionCode) throws Exception {
List<RegionModel> regionList = Systemctl.regionClient.queryByParentRegionCode(Integer.parseInt(regionCode)).getResult();
// 陕西省时需要在地图返回独立的地级市:韩城、杨凌、西咸
if (regionCode.equals(TZSCommonConstant.SHAN_XI_REGION_CODE)) {
List<RegionModel> independentRegions = ReginStepEnum.enum2RegionList("map");
regionList.addAll(independentRegions);
}
return regionList;
}
private void buildYDataForInspectPersonCount(Map<String, Object> result, List<RegionModel> childRegion) { private void buildYDataForInspectPersonCount(Map<String, Object> result, List<RegionModel> childRegion) {
List<Long> yData = new ArrayList<>(); List<Long> yData = new ArrayList<>();
childRegion.forEach(regionModel -> { childRegion.forEach(regionModel -> {
String orgCode = this.getAndSetOrgCode(regionModel.getRegionCode() + ""); String orgCode = stCommonService.getAndSetOrgCode(regionModel.getRegionCode() + "");
if (StringUtils.isEmpty(orgCode)) { if (StringUtils.isEmpty(orgCode)) {
yData.add(0L); yData.add(0L);
} else { } else {
...@@ -228,36 +212,11 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -228,36 +212,11 @@ public class JYJCDPStatisticsServiceImpl {
result.put("ydata", yData); result.put("ydata", yData);
} }
private String getAndSetOrgCode(String regionCode) {
String orgCode = regionCodeOrgCodeMap.get(regionCode);
if (orgCode == null) {
orgCode = jyjcBaseMapper.getOrgCodeByCompanyCode(regionCode);
if (orgCode == null) {
return "";
}
regionCodeOrgCodeMap.put(regionCode, orgCode);
}
return orgCode;
}
private List<String> getXDataForInspectPersonCount(List<RegionModel> childRegion) { private List<String> getXDataForInspectPersonCount(List<RegionModel> childRegion) {
return childRegion.stream().map(RegionModel::getRegionName).collect(Collectors.toList()); return childRegion.stream().map(RegionModel::getRegionName).collect(Collectors.toList());
} }
private List<RegionModel> getRegionList(DPFilterParamDto dpFilterParamDto) {
try {
if (regionChildRegionMap.get(dpFilterParamDto.getCityCode()) == null) {
List<RegionModel> regionModels = this.setRegionIfRootParent(dpFilterParamDto.getCityCode());
regionChildRegionMap.put(dpFilterParamDto.getCityCode(), regionModels);
return regionModels;
} else {
return regionChildRegionMap.get(dpFilterParamDto.getCityCode());
}
} catch (Exception e) {
log.error("查询行政区域失败:{}", e.getMessage());
}
return new ArrayList<>();
}
public Map<String, Object> queryAllFlowingAndFinishedInspectApp(DPFilterParamDto dpFilterParamDto) { public Map<String, Object> queryAllFlowingAndFinishedInspectApp(DPFilterParamDto dpFilterParamDto) {
// 1.查询条件构造未上送时间时,默认查询数据为近一个月数据 // 1.查询条件构造未上送时间时,默认查询数据为近一个月数据
...@@ -286,7 +245,7 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -286,7 +245,7 @@ public class JYJCDPStatisticsServiceImpl {
} }
private void buildYDataForPendingResultInspectApp(Map<String, Object> result, JYJCTypeEnum[] jyjcTypeEnums, DPFilterParamDto dpFilterParamDto) { private void buildYDataForPendingResultInspectApp(Map<String, Object> result, JYJCTypeEnum[] jyjcTypeEnums, DPFilterParamDto dpFilterParamDto) {
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
List<CountDto> countDtoList = inspectionApplicationMapper.queryAllPendingResultInspectApp(orgCode, dpFilterParamDto); List<CountDto> countDtoList = inspectionApplicationMapper.queryAllPendingResultInspectApp(orgCode, dpFilterParamDto);
fillJYJCYData(result, jyjcTypeEnums, countDtoList); fillJYJCYData(result, jyjcTypeEnums, countDtoList);
} }
...@@ -301,7 +260,7 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -301,7 +260,7 @@ public class JYJCDPStatisticsServiceImpl {
} }
private void buildYDataForFlowingAndFinishedInspectApp(Map<String, Object> result, JYJCTypeEnum[] jyjcTypeEnums, DPFilterParamDto dpFilterParamDto) { private void buildYDataForFlowingAndFinishedInspectApp(Map<String, Object> result, JYJCTypeEnum[] jyjcTypeEnums, DPFilterParamDto dpFilterParamDto) {
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
List<CountDto> countDtoList = inspectionApplicationMapper.queryAllFlowingAndFinishedInspectApp(orgCode, dpFilterParamDto); List<CountDto> countDtoList = inspectionApplicationMapper.queryAllFlowingAndFinishedInspectApp(orgCode, dpFilterParamDto);
fillJYJCYData(result, jyjcTypeEnums, countDtoList); fillJYJCYData(result, jyjcTypeEnums, countDtoList);
} }
...@@ -311,12 +270,12 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -311,12 +270,12 @@ public class JYJCDPStatisticsServiceImpl {
} }
public List<InspectionTimelinesDto> queryInspectionTimelinessTopXX(String top, DPFilterParamDto dpFilterParamDto) { public List<InspectionTimelinesDto> queryInspectionTimelinessTopXX(String top, DPFilterParamDto dpFilterParamDto) {
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
return inspectionResultMapper.queryInspectionTimelinessTopXX(top, orgCode, dpFilterParamDto); return inspectionResultMapper.queryInspectionTimelinessTopXX(top, orgCode, dpFilterParamDto);
} }
public List<PublicityInspectOrgInfoDto> queryInspectionOrgListForPublicity(DPFilterParamDto dpFilterParamDto) { public List<PublicityInspectOrgInfoDto> queryInspectionOrgListForPublicity(DPFilterParamDto dpFilterParamDto) {
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
return openingApplicationMapper.queryInspectionOrgListForPublicity(orgCode, dpFilterParamDto); return openingApplicationMapper.queryInspectionOrgListForPublicity(orgCode, dpFilterParamDto);
} }
...@@ -324,7 +283,7 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -324,7 +283,7 @@ public class JYJCDPStatisticsServiceImpl {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
// 1.查询条件构造未上送时间时,默认查询数据为近一个月数据 // 1.查询条件构造未上送时间时,默认查询数据为近一个月数据
this.setDefaultFilter(dpFilterParamDto); this.setDefaultFilter(dpFilterParamDto);
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 2.x轴数据构建 // 2.x轴数据构建
List<EquipmentCategoryDto> equipmentCategoryDtos = equipmentCategoryMapper.selectClassify(); List<EquipmentCategoryDto> equipmentCategoryDtos = equipmentCategoryMapper.selectClassify();
this.setXDataForInspectionEquipByEquList(result, equipmentCategoryDtos); this.setXDataForInspectionEquipByEquList(result, equipmentCategoryDtos);
...@@ -385,7 +344,7 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -385,7 +344,7 @@ public class JYJCDPStatisticsServiceImpl {
CountRequest request = new CountRequest(); CountRequest request = new CountRequest();
request.indices("idx_biz_view_jg_all"); request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery(); BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 按照管辖机构区域信息模糊查询 // 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*")); boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 且在用状态设备 // 且在用状态设备
...@@ -410,7 +369,7 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -410,7 +369,7 @@ public class JYJCDPStatisticsServiceImpl {
CountRequest request = new CountRequest(); CountRequest request = new CountRequest();
request.indices("idx_biz_view_jg_all"); request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery(); BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 按照管辖机构区域信息模糊查询 // 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*")); boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 在用状态设备 // 在用状态设备
...@@ -430,13 +389,15 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -430,13 +389,15 @@ public class JYJCDPStatisticsServiceImpl {
private void staticsCenterMapCountDataReporting(Map<String, Object> result, DPFilterParamDto dpFilterParamDto) { private void staticsCenterMapCountDataReporting(Map<String, Object> result, DPFilterParamDto dpFilterParamDto) {
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
CountDto countDto = inspectionApplicationMapper.queryAppByEquListForReporting(orgCode, dpFilterParamDto); CountDto countDto = inspectionApplicationMapper.queryAppByEquListForReporting(orgCode, dpFilterParamDto);
result.put("bjCount", countDto.getLongValue()); result.put("bjCount", countDto.getLongValue());
} }
public List<Map<String, Object>> getCenterMapCountDataForOverview(DPFilterParamDto dpFilterParamDto) { public List<Map<String, Object>> getCenterMapCountDataForOverview(DPFilterParamDto dpFilterParamDto) {
return getRegionList(dpFilterParamDto).parallelStream().map(r -> { List<RegionModel> regionList = stCommonService.setRegionIfRootParent(dpFilterParamDto);
return regionList.parallelStream().map(r -> {
DPFilterParamDto filterParamDto = new DPFilterParamDto(); DPFilterParamDto filterParamDto = new DPFilterParamDto();
filterParamDto.setCityCode(r.getRegionCode().toString()); filterParamDto.setCityCode(r.getRegionCode().toString());
Map<String, Object> itemResult = getCenterMapOverviewData(filterParamDto); Map<String, Object> itemResult = getCenterMapOverviewData(filterParamDto);
...@@ -483,7 +444,7 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -483,7 +444,7 @@ public class JYJCDPStatisticsServiceImpl {
SearchRequest request = new SearchRequest(); SearchRequest request = new SearchRequest();
request.indices("idx_biz_view_jg_all"); request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery(); BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 按照管辖机构区域信息模糊查询 // 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*")); boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 且在用状态设备 // 且在用状态设备
...@@ -520,7 +481,7 @@ public class JYJCDPStatisticsServiceImpl { ...@@ -520,7 +481,7 @@ public class JYJCDPStatisticsServiceImpl {
request.indices("idx_biz_view_jg_all"); request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery(); BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
// 区域信息模糊查询 // 区域信息模糊查询
String orgCode = this.getAndSetOrgCode(dpFilterParamDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
// 按照管辖机构区域信息模糊查询 // 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*")); boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 在用状态设备 // 在用状态设备
......
...@@ -2,12 +2,34 @@ package com.yeejoin.amos.boot.module.statistcs.biz.service.impl; ...@@ -2,12 +2,34 @@ package com.yeejoin.amos.boot.module.statistcs.biz.service.impl;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams; import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant; import com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
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.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.ymt.api.dto.EquipmentCategoryDto;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquimentEnum;
import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipTechParamPipelineMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipmentCategoryMapper;
import com.yeejoin.amos.feign.systemctl.Systemctl; 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.lucene.queryparser.classic.QueryParser;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.core.CountRequest;
import org.elasticsearch.client.core.CountResponse;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -18,17 +40,48 @@ import java.util.stream.Collectors; ...@@ -18,17 +40,48 @@ import java.util.stream.Collectors;
@Service @Service
public class StCommonServiceImpl { public class StCommonServiceImpl {
/**
* 压力容器设备种类
*/
public final static String EQU_LIST_CYLINDER = "2000";
/**
* 气瓶设备类别
*/
public final static String EQU_CATEGORY_CYLINDER = "2300";
private CommonBaseMapper commonMapper; private CommonBaseMapper commonMapper;
private RestHighLevelClient restHighLevelClient;
private EquipTechParamPipelineMapper techParamsPipelineMapper;
private EquipmentCategoryMapper equipmentCategoryMapper;
private static Map<String, String> regionCodeOrgCodeMap = new ConcurrentHashMap<>(); private static Map<String, String> regionCodeOrgCodeMap = new ConcurrentHashMap<>();
private static List<RegionModel> regionModels = new ArrayList<>(); private static List<RegionModel> regionModels = new ArrayList<>();
public StCommonServiceImpl(CommonBaseMapper commonMapper) { private static List<EquipmentCategoryDto> equipmentCategoryDtos;
public StCommonServiceImpl(CommonBaseMapper commonMapper, RestHighLevelClient restHighLevelClient, EquipTechParamPipelineMapper techParamsPipelineMapper, EquipmentCategoryMapper equipmentCategoryMapper) {
this.commonMapper = commonMapper; this.commonMapper = commonMapper;
this.restHighLevelClient = restHighLevelClient;
this.techParamsPipelineMapper = techParamsPipelineMapper;
this.equipmentCategoryMapper = equipmentCategoryMapper;
}
public static Map<String, String> getRegionCodeOrgCodeMap() {
return regionCodeOrgCodeMap;
}
public static List<EquipmentCategoryDto> getEquipmentCategory() {
return equipmentCategoryDtos;
} }
public void init() { public void init() {
// 数据不变所以放到内存,提高响应时间
equipmentCategoryDtos = equipmentCategoryMapper.selectClassify();
initReginCode(); initReginCode();
} }
...@@ -49,6 +102,18 @@ public class StCommonServiceImpl { ...@@ -49,6 +102,18 @@ public class StCommonServiceImpl {
} }
} }
public String getAndSetOrgCode(DPFilterParamDto dpFilterParamDto) {
String cityCode = dpFilterParamDto.getCityCode();
String orgCode = regionCodeOrgCodeMap.get(cityCode);
if (orgCode == null) {
orgCode = commonMapper.getOrgCodeByCompanyCode(cityCode);
if (orgCode != null) {
regionCodeOrgCodeMap.put(cityCode, orgCode);
}
}
return orgCode;
}
public String getAndSetOrgCode(String cityCode) { public String getAndSetOrgCode(String cityCode) {
String orgCode = regionCodeOrgCodeMap.get(cityCode); String orgCode = regionCodeOrgCodeMap.get(cityCode);
if (orgCode == null) { if (orgCode == null) {
...@@ -62,7 +127,7 @@ public class StCommonServiceImpl { ...@@ -62,7 +127,7 @@ public class StCommonServiceImpl {
public List<RegionModel> getUserRegionCode(ReginParams selectedOrgInfo) { public List<RegionModel> getUserRegionCode(ReginParams selectedOrgInfo) {
String regionCode = selectedOrgInfo.getCompany().getCompanyCode(); String regionCode = selectedOrgInfo.getCompany().getCompanyCode();
Optional<RegionModel> op = regionModels.stream().filter(e->e.getRegionCode().toString().equals(regionCode)).findFirst(); Optional<RegionModel> op = regionModels.stream().filter(e -> e.getRegionCode().toString().equals(regionCode)).findFirst();
RegionModel model = op.orElse(new RegionModel()); RegionModel model = op.orElse(new RegionModel());
RegionModel result = new RegionModel(); RegionModel result = new RegionModel();
result.setRegionName(model.getRegionName()); result.setRegionName(model.getRegionName());
...@@ -70,18 +135,101 @@ public class StCommonServiceImpl { ...@@ -70,18 +135,101 @@ public class StCommonServiceImpl {
return Collections.singletonList(result); return Collections.singletonList(result);
} }
public List<RegionModel> setRegionIfRootParent(String regionCode) throws Exception { public List<RegionModel> setRegionIfRootParent(DPFilterParamDto dpFilterParamDto) {
List<RegionModel> regionList = Systemctl.regionClient.queryByParentRegionCode(Integer.parseInt(regionCode)).getResult(); List<RegionModel> regions = regionModels.parallelStream().filter(e -> e.getParentRegionCode() != null && (e.getParentRegionCode().toString()).equals(dpFilterParamDto.getCityCode())).collect(Collectors.toList());
// 陕西省时需要在地图返回独立的地级市:韩城、杨凌、西咸
if (dpFilterParamDto.getCityCode().equals(TZSCommonConstant.SHAN_XI_REGION_CODE)) {
List<RegionModel> independentRegions = ReginStepEnum.enum2RegionList("map");
regions.addAll(independentRegions);
}
return regions;
}
public List<RegionModel> setRegionIfRootParent(String regionCode) {
List<RegionModel> regions = regionModels.parallelStream().filter(e -> e.getParentRegionCode() != null && (e.getParentRegionCode().toString()).equals(regionCode)).collect(Collectors.toList());
// 陕西省时需要在地图返回独立的地级市:韩城、杨凌、西咸 // 陕西省时需要在地图返回独立的地级市:韩城、杨凌、西咸
if (regionCode.equals(TZSCommonConstant.SHAN_XI_REGION_CODE)) { if (regionCode.equals(TZSCommonConstant.SHAN_XI_REGION_CODE)) {
List<RegionModel> independentRegions = ReginStepEnum.enum2RegionList("map"); List<RegionModel> independentRegions = ReginStepEnum.enum2RegionList("map");
regionList.addAll(independentRegions); regions.addAll(independentRegions);
} }
return regionList; return regions;
} }
public List<String> buildXData(List<RegionModel> regionList) { public List<String> buildXData(List<RegionModel> regionList) {
return regionList.stream().map(RegionModel::getRegionName).collect(Collectors.toList()); return regionList.stream().map(RegionModel::getRegionName).collect(Collectors.toList());
} }
public long staticsCenterMapCountDataForCylinder(Map<String, Object> result, String orgCode) {
long num = 0;
CountRequest request = new CountRequest();
request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
// 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 设备类别精确查询气瓶
boolMust.must(QueryBuilders.termsQuery("EQU_CATEGORY_CODE", EQU_CATEGORY_CYLINDER));
// 且在用状态设备
boolMust.must(QueryBuilders.termQuery("EQU_STATE", EquimentEnum.ZAIYONG.getCode()));
request.query(boolMust);
try {
CountResponse response = restHighLevelClient.count(request, RequestOptions.DEFAULT);
num = response.getCount();
} catch (IOException e) {
throw new RuntimeException(e);
}
result.put(DPMapStatisticsItemEnum.GAS.getCode(), num);
return num;
}
public void staticsCenterMapCountDataForEquip(Map<String, Object> result, long cylinderNum, String orgCode) {
SearchRequest request = new SearchRequest();
request.indices("idx_biz_view_jg_all");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
// 按照管辖机构区域信息模糊查询
boolMust.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"));
// 且在用状态设备
boolMust.must(QueryBuilders.termQuery("EQU_STATE", EquimentEnum.ZAIYONG.getCode()));
SearchSourceBuilder builder = new SearchSourceBuilder();
builder.query(boolMust);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("count_by_equ_list_code").field("EQU_LIST_CODE");
builder.aggregation(aggregationBuilder);
request.source(builder);
try {
SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
Terms terms = response.getAggregations().get("count_by_equ_list_code");
Map<String, Long> countMap = new HashMap<>();
for (Terms.Bucket bucket : terms.getBuckets()) {
// 压力容器里包括气瓶所以需要特殊处理,在统计压力容器时去掉气瓶的数量
if (bucket.getKeyAsString().equals(EQU_LIST_CYLINDER)) {
countMap.put(bucket.getKeyAsString(), bucket.getDocCount() - cylinderNum);
} else {
countMap.put(bucket.getKeyAsString(), bucket.getDocCount());
}
}
// 按照8大类枚举,进行加工。目的:固定八大类防止没统计数据导致缺少分类、将设备种类的code换成前端定义的key
equipmentCategoryDtos.forEach(c -> {
result.put(this.castCategoryCode2WebCode(c.getCode()), countMap.getOrDefault(c.getCode(), 0L));
});
result.put(DPMapStatisticsItemEnum.TOTAL.getCode(), countMap.values().stream().mapToLong(e -> e).sum() + cylinderNum);
} catch (IOException e) {
throw new RuntimeException(e);
}
result.remove(DPMapStatisticsItemEnum.PRESSURE_PIPELINES.getCategory());
}
private String castCategoryCode2WebCode(String category) {
DPMapStatisticsItemEnum itemEnum = DPMapStatisticsItemEnum.getInstanceByCategory(category);
return itemEnum.getCode();
}
public void staticsCenterMapCountDataForPipeline(Map<String, Object> result, String orgCode) {
String length = techParamsPipelineMapper.sumPipeLengthByOrgCode(orgCode);
BigDecimal lengthDecimal = new BigDecimal(length);
if (lengthDecimal.compareTo(BigDecimal.ZERO) > 0) {
length = lengthDecimal.divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP).toPlainString();
}
result.put(DPMapStatisticsItemEnum.PRESSURE_PIPELINES.getCode(), length);
}
} }
...@@ -3,11 +3,9 @@ package com.yeejoin.amos.boot.module.statistcs.biz.service.impl; ...@@ -3,11 +3,9 @@ package com.yeejoin.amos.boot.module.statistcs.biz.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto; import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
import com.yeejoin.amos.boot.module.common.api.entity.AlertRescueStatistics; import com.yeejoin.amos.boot.module.common.api.entity.AlertRescueStatistics;
import com.yeejoin.amos.boot.module.common.api.entity.AlertUseUnitStatistics; import com.yeejoin.amos.boot.module.common.api.entity.AlertUseUnitStatistics;
import com.yeejoin.amos.boot.module.common.api.enums.ReginStepEnum;
import com.yeejoin.amos.boot.module.statistics.api.dto.AlertUseUnitStatisticsDto; import com.yeejoin.amos.boot.module.statistics.api.dto.AlertUseUnitStatisticsDto;
import com.yeejoin.amos.boot.module.statistics.api.mapper.AlertRescueStatisticsMapper; import com.yeejoin.amos.boot.module.statistics.api.mapper.AlertRescueStatisticsMapper;
import com.yeejoin.amos.boot.module.statistics.api.mapper.AlertStatisticsMapper; import com.yeejoin.amos.boot.module.statistics.api.mapper.AlertStatisticsMapper;
...@@ -33,7 +31,6 @@ import org.elasticsearch.client.core.CountRequest; ...@@ -33,7 +31,6 @@ 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.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.Bean; import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.foundation.utils.DateTimeUtil; import org.typroject.tyboot.core.foundation.utils.DateTimeUtil;
...@@ -45,7 +42,6 @@ import java.time.LocalDate; ...@@ -45,7 +42,6 @@ import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -58,8 +54,6 @@ import java.util.stream.Collectors; ...@@ -58,8 +54,6 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class YJDPStatisticsServiceImpl { public class YJDPStatisticsServiceImpl {
private CommonBaseMapper commonBaseMapper;
private AlertCalledMapper alertCalledMapper; private AlertCalledMapper alertCalledMapper;
private AlertRescueStatisticsMapper alertRescueStatisticsMapper; private AlertRescueStatisticsMapper alertRescueStatisticsMapper;
...@@ -73,15 +67,12 @@ public class YJDPStatisticsServiceImpl { ...@@ -73,15 +67,12 @@ public class YJDPStatisticsServiceImpl {
private DispatchPaperMapper dispatchPaperMapper; private DispatchPaperMapper dispatchPaperMapper;
@Autowired
private RestHighLevelClient restHighLevelClient; private RestHighLevelClient restHighLevelClient;
private static Map<String, String> regionCodeOrgCodeMap = new ConcurrentHashMap<>(); private StCommonServiceImpl stCommonService;
private static Map<String, List<RegionModel>> regionChildRegionMap = new ConcurrentHashMap<>();
public YJDPStatisticsServiceImpl(CommonBaseMapper commonBaseMapper, AlertCalledMapper alertCalledMapper, AlertRescueStatisticsMapper alertRescueStatisticsMapper, AlertUseUnitStatisticsMapper alertUseUnitStatisticsMapper, AlertStatisticsMapper alertStatisticsMapper, DispatchTaskMapper dispatchTaskMapper, DispatchPaperMapper dispatchPaperMapper, RestHighLevelClient restHighLevelClient) { public YJDPStatisticsServiceImpl(AlertCalledMapper alertCalledMapper, AlertRescueStatisticsMapper alertRescueStatisticsMapper, AlertUseUnitStatisticsMapper alertUseUnitStatisticsMapper, AlertStatisticsMapper alertStatisticsMapper, DispatchTaskMapper dispatchTaskMapper, DispatchPaperMapper dispatchPaperMapper, RestHighLevelClient restHighLevelClient, StCommonServiceImpl stCommonService) {
this.commonBaseMapper = commonBaseMapper;
this.alertCalledMapper = alertCalledMapper; this.alertCalledMapper = alertCalledMapper;
this.alertRescueStatisticsMapper = alertRescueStatisticsMapper; this.alertRescueStatisticsMapper = alertRescueStatisticsMapper;
this.alertUseUnitStatisticsMapper = alertUseUnitStatisticsMapper; this.alertUseUnitStatisticsMapper = alertUseUnitStatisticsMapper;
...@@ -89,12 +80,13 @@ public class YJDPStatisticsServiceImpl { ...@@ -89,12 +80,13 @@ public class YJDPStatisticsServiceImpl {
this.dispatchTaskMapper = dispatchTaskMapper; this.dispatchTaskMapper = dispatchTaskMapper;
this.dispatchPaperMapper = dispatchPaperMapper; this.dispatchPaperMapper = dispatchPaperMapper;
this.restHighLevelClient = restHighLevelClient; this.restHighLevelClient = restHighLevelClient;
this.stCommonService = stCommonService;
} }
public JSONObject eventStatByDay(DPFilterParamDto dpFilterParamDto) throws Exception { public JSONObject eventStatByDay(DPFilterParamDto dpFilterParamDto) throws Exception {
String beginDate = DateUtil.formatDate(DateTimeUtil.addDays(new Date(), -6), DateUtil.Y_M_D); String beginDate = DateUtil.formatDate(DateTimeUtil.addDays(new Date(), -6), DateUtil.Y_M_D);
String endDate = DateUtil.getNow(DateUtil.Y_M_D); String endDate = DateUtil.getNow(DateUtil.Y_M_D);
String orgCode = this.getAndSetOrgCode(dpFilterParamDto); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto);
List<String> everyDay = this.getEveryDay(beginDate, endDate); List<String> everyDay = this.getEveryDay(beginDate, endDate);
JSONObject jsonObject = this.buildLegendData(null, "trapped", "困人"); JSONObject jsonObject = this.buildLegendData(null, "trapped", "困人");
...@@ -128,12 +120,12 @@ public class YJDPStatisticsServiceImpl { ...@@ -128,12 +120,12 @@ public class YJDPStatisticsServiceImpl {
} }
public JSONObject elevatorCountStat(DPFilterParamDto dpFilterParamDto) throws Exception { public JSONObject elevatorCountStat(DPFilterParamDto dpFilterParamDto) throws Exception {
List<RegionModel> regionList = this.getRegionList(dpFilterParamDto); List<RegionModel> regionList = stCommonService.setRegionIfRootParent(dpFilterParamDto);
List<String> xdata = regionList.stream().map(r -> r.getRegionName().toString()).collect(Collectors.toList()); List<String> xdata = regionList.stream().map(r -> r.getRegionName().toString()).collect(Collectors.toList());
List<Long> ydata = new ArrayList<>(); List<Long> ydata = new ArrayList<>();
regionList.stream().forEach(x -> { regionList.forEach(x -> {
String orgCode = this.getAndSetOrgCode(x.getRegionCode().toString()); String orgCode = stCommonService.getAndSetOrgCode(x.getRegionCode().toString());
ydata.add(elevatorCountByES(orgCode)); ydata.add(elevatorCountByES(orgCode));
}); });
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
...@@ -143,7 +135,7 @@ public class YJDPStatisticsServiceImpl { ...@@ -143,7 +135,7 @@ public class YJDPStatisticsServiceImpl {
} }
public JSONObject eventStatByLocation(DPFilterParamDto dpFilterParamDto) throws Exception { public JSONObject eventStatByLocation(DPFilterParamDto dpFilterParamDto) throws Exception {
String orgCode = this.getAndSetOrgCode(dpFilterParamDto); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto);
dpFilterParamDto.setBeginDate(DateUtil.formatDate(DateTimeUtil.getMinValueOfOneDay(DateTimeUtil.addMonths(new Date(), -1)), DateUtil.Y_M_D_HMS)); dpFilterParamDto.setBeginDate(DateUtil.formatDate(DateTimeUtil.getMinValueOfOneDay(DateTimeUtil.addMonths(new Date(), -1)), DateUtil.Y_M_D_HMS));
dpFilterParamDto.setEndDate(DateUtil.formatDate(DateTimeUtil.getMaxValueOfOneDay(new Date()), DateUtil.Y_M_D_HMS)); dpFilterParamDto.setEndDate(DateUtil.formatDate(DateTimeUtil.getMaxValueOfOneDay(new Date()), DateUtil.Y_M_D_HMS));
...@@ -158,7 +150,7 @@ public class YJDPStatisticsServiceImpl { ...@@ -158,7 +150,7 @@ public class YJDPStatisticsServiceImpl {
} }
public JSONObject faultCauseRatio(DPFilterParamDto dpFilterParamDto) throws Exception { public JSONObject faultCauseRatio(DPFilterParamDto dpFilterParamDto) throws Exception {
String orgCode = this.getAndSetOrgCode(dpFilterParamDto); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto);
List<Map<String, Object>> maps = alertCalledMapper.faultCauseRatio(orgCode); List<Map<String, Object>> maps = alertCalledMapper.faultCauseRatio(orgCode);
List<Object> xdata = maps.stream().map(item -> item.get("errorResult")).collect(Collectors.toList()); List<Object> xdata = maps.stream().map(item -> item.get("errorResult")).collect(Collectors.toList());
...@@ -240,8 +232,7 @@ public class YJDPStatisticsServiceImpl { ...@@ -240,8 +232,7 @@ public class YJDPStatisticsServiceImpl {
public JSONObject trappedUserCount(DPFilterParamDto dpFilterParamDto) throws Exception { public JSONObject trappedUserCount(DPFilterParamDto dpFilterParamDto) throws Exception {
String date = DateUtil.formatDate(new Date(), "yyyy-MM"); String date = DateUtil.formatDate(new Date(), "yyyy-MM");
String orgCode = this.getAndSetOrgCode(dpFilterParamDto); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto.getCityCode());
LambdaQueryWrapper<AlertRescueStatistics> lambda = new QueryWrapper<AlertRescueStatistics>().lambda(); LambdaQueryWrapper<AlertRescueStatistics> lambda = new QueryWrapper<AlertRescueStatistics>().lambda();
lambda.likeLeft(AlertRescueStatistics::getSupervisoryUnitOrgCode, orgCode); lambda.likeLeft(AlertRescueStatistics::getSupervisoryUnitOrgCode, orgCode);
lambda.eq(AlertRescueStatistics::getStatisticsDate, date); lambda.eq(AlertRescueStatistics::getStatisticsDate, date);
...@@ -262,7 +253,7 @@ public class YJDPStatisticsServiceImpl { ...@@ -262,7 +253,7 @@ public class YJDPStatisticsServiceImpl {
public List<AlertUseUnitStatisticsDto> trappedUserHighCompanyCount(DPFilterParamDto dpFilterParamDto) throws Exception { public List<AlertUseUnitStatisticsDto> trappedUserHighCompanyCount(DPFilterParamDto dpFilterParamDto) throws Exception {
String date = DateUtil.formatDate(new Date(), "yyyy-MM"); String date = DateUtil.formatDate(new Date(), "yyyy-MM");
String orgCode = this.getAndSetOrgCode(dpFilterParamDto); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto);
LambdaQueryWrapper<AlertUseUnitStatistics> lambda = new QueryWrapper<AlertUseUnitStatistics>().lambda(); LambdaQueryWrapper<AlertUseUnitStatistics> lambda = new QueryWrapper<AlertUseUnitStatistics>().lambda();
lambda.likeLeft(AlertUseUnitStatistics::getSupervisoryUnitOrgCode, orgCode); lambda.likeLeft(AlertUseUnitStatistics::getSupervisoryUnitOrgCode, orgCode);
...@@ -272,9 +263,9 @@ public class YJDPStatisticsServiceImpl { ...@@ -272,9 +263,9 @@ public class YJDPStatisticsServiceImpl {
} }
public List<Map<String, Object>> rankUnitByRescueTime(DPFilterParamDto dpFilterParamDto) { public List<Map<String, Object>> rankUnitByRescueTime(DPFilterParamDto dpFilterParamDto) {
String orgCode = this.getAndSetOrgCode(dpFilterParamDto); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto);
List<Map<String, Object>> maps = dispatchTaskMapper.rankUnitByRescueTime(orgCode); List<Map<String, Object>> maps = dispatchTaskMapper.rankUnitByRescueTime(orgCode);
maps.stream().forEach(x -> { maps.forEach(x -> {
String avgTime = ""; String avgTime = "";
Long seconds = Long.valueOf(x.get("avgTime").toString()); Long seconds = Long.valueOf(x.get("avgTime").toString());
long days = TimeUnit.SECONDS.toDays(seconds); long days = TimeUnit.SECONDS.toDays(seconds);
...@@ -298,12 +289,12 @@ public class YJDPStatisticsServiceImpl { ...@@ -298,12 +289,12 @@ public class YJDPStatisticsServiceImpl {
} }
public JSONObject regionEventRank(DPFilterParamDto dpFilterParamDto) throws Exception { public JSONObject regionEventRank(DPFilterParamDto dpFilterParamDto) throws Exception {
List<RegionModel> childRegion = this.getRegionList(dpFilterParamDto); List<RegionModel> childRegion = stCommonService.setRegionIfRootParent(dpFilterParamDto);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
Map<String, Long> map = new HashMap<>(); Map<String, Long> map = new HashMap<>();
childRegion.stream().forEach(x -> { childRegion.forEach(x -> {
String orgCode = this.getAndSetOrgCode(x.getRegionCode().toString()); String orgCode = stCommonService.getAndSetOrgCode(x.getRegionCode().toString());
if (ValidationUtil.isEmpty(orgCode)) { if (ValidationUtil.isEmpty(orgCode)) {
map.put(x.getRegionName(), 0L); map.put(x.getRegionName(), 0L);
} else { } else {
...@@ -324,56 +315,6 @@ public class YJDPStatisticsServiceImpl { ...@@ -324,56 +315,6 @@ public class YJDPStatisticsServiceImpl {
return jsonObject; return jsonObject;
} }
private List<RegionModel> getRegionList(DPFilterParamDto dpFilterParamDto) {
try {
if (regionChildRegionMap.get(dpFilterParamDto.getCityCode()) == null) {
List<RegionModel> regionModels = this.setRegionIfRootParent(dpFilterParamDto.getCityCode());
regionChildRegionMap.put(dpFilterParamDto.getCityCode(), regionModels);
return regionModels;
} else {
return regionChildRegionMap.get(dpFilterParamDto.getCityCode());
}
} catch (Exception e) {
log.error("查询行政区域失败:{}", e.getMessage());
}
return new ArrayList<>();
}
private List<RegionModel> setRegionIfRootParent(String regionCode) throws Exception {
List<RegionModel> regionList = Systemctl.regionClient.queryByParentRegionCode(Integer.parseInt(regionCode)).getResult();
// 陕西省时需要在地图返回独立的地级市:韩城、杨凌、西咸
if (regionCode.equals(TZSCommonConstant.SHAN_XI_REGION_CODE)) {
List<RegionModel> independentRegions = ReginStepEnum.enum2RegionList("map");
regionList.addAll(independentRegions);
}
regionList = regionList.stream().sorted(Comparator.comparing(RegionModel::getRegionCode, Comparator.naturalOrder())).collect(Collectors.toList());
return regionList;
}
private String getAndSetOrgCode(DPFilterParamDto dpFilterParamDto) {
this.getRegionList(dpFilterParamDto);
String orgCode = regionCodeOrgCodeMap.get(dpFilterParamDto.getCityCode());
if (orgCode == null) {
orgCode = commonBaseMapper.getOrgCodeByCompanyCode(dpFilterParamDto.getCityCode());
if (orgCode == null) {
return "";
}
regionCodeOrgCodeMap.put(dpFilterParamDto.getCityCode(), orgCode);
}
return orgCode;
}
private String getAndSetOrgCode(String cityCode) {
String orgCode = regionCodeOrgCodeMap.get(cityCode);
if (orgCode == null) {
orgCode = commonBaseMapper.getOrgCodeByCompanyCode(cityCode);
if (orgCode == null) {
return "";
}
regionCodeOrgCodeMap.put(cityCode, orgCode);
}
return orgCode;
}
/** /**
* 获取两个时间段之间的每一天 * 获取两个时间段之间的每一天
...@@ -409,10 +350,10 @@ public class YJDPStatisticsServiceImpl { ...@@ -409,10 +350,10 @@ public class YJDPStatisticsServiceImpl {
} }
public List<Map<String, Object>> getCenterMapCountDataForOverview(DPFilterParamDto dpFilterParamDto) { public List<Map<String, Object>> getCenterMapCountDataForOverview(DPFilterParamDto dpFilterParamDto) {
return getRegionList(dpFilterParamDto).parallelStream().map(r -> { return stCommonService.setRegionIfRootParent(dpFilterParamDto).parallelStream().map(r -> {
DPFilterParamDto filterParamDto = new DPFilterParamDto(); DPFilterParamDto filterParamDto = new DPFilterParamDto();
filterParamDto.setCityCode(r.getRegionCode().toString()); filterParamDto.setCityCode(r.getRegionCode().toString());
String orgCode = this.getAndSetOrgCode(filterParamDto); String orgCode = stCommonService.getAndSetOrgCode(filterParamDto);
this.setDefaultFilter(filterParamDto); this.setDefaultFilter(filterParamDto);
Map<String, Object> itemResult = getCenterMapOverviewData(orgCode, filterParamDto); Map<String, Object> itemResult = getCenterMapOverviewData(orgCode, filterParamDto);
itemResult.put("regionCode", r.getRegionCode()); itemResult.put("regionCode", r.getRegionCode());
...@@ -432,7 +373,7 @@ public class YJDPStatisticsServiceImpl { ...@@ -432,7 +373,7 @@ public class YJDPStatisticsServiceImpl {
public Map<String, Object> getCenterMapCountDataForGlobal(DPFilterParamDto dpFilterParamDto) { public Map<String, Object> getCenterMapCountDataForGlobal(DPFilterParamDto dpFilterParamDto) {
this.setDefaultFilter(dpFilterParamDto); this.setDefaultFilter(dpFilterParamDto);
String orgCode = this.getAndSetOrgCode(dpFilterParamDto); String orgCode = stCommonService.getAndSetOrgCode(dpFilterParamDto);
// 1.报检数量统计 // 1.报检数量统计
return this.getCenterMapOverviewData(orgCode, dpFilterParamDto); return this.getCenterMapOverviewData(orgCode, dpFilterParamDto);
} }
......
...@@ -29,7 +29,6 @@ import java.io.IOException; ...@@ -29,7 +29,6 @@ import java.io.IOException;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
...@@ -45,13 +44,14 @@ public class ZLDPStatisticsServiceImpl { ...@@ -45,13 +44,14 @@ public class ZLDPStatisticsServiceImpl {
private RestHighLevelClient restHighLevelClient; private RestHighLevelClient restHighLevelClient;
private static Map<String, String> regionCodeOrgCodeMap = new ConcurrentHashMap<>(); private StCommonServiceImpl stCommonService;
public ZLDPStatisticsServiceImpl(ZLStatisticsMapper screenMapper, DataDictionaryServiceImpl iDataDictionaryService, AlertStatisticsMapper alertStatisticsMapper, RestHighLevelClient restHighLevelClient) { public ZLDPStatisticsServiceImpl(ZLStatisticsMapper screenMapper, DataDictionaryServiceImpl iDataDictionaryService, AlertStatisticsMapper alertStatisticsMapper, RestHighLevelClient restHighLevelClient, StCommonServiceImpl stCommonService) {
this.screenMapper = screenMapper; this.screenMapper = screenMapper;
this.iDataDictionaryService = iDataDictionaryService; this.iDataDictionaryService = iDataDictionaryService;
this.alertStatisticsMapper = alertStatisticsMapper; this.alertStatisticsMapper = alertStatisticsMapper;
this.restHighLevelClient = restHighLevelClient; this.restHighLevelClient = restHighLevelClient;
this.stCommonService = stCommonService;
} }
...@@ -462,7 +462,7 @@ public class ZLDPStatisticsServiceImpl { ...@@ -462,7 +462,7 @@ public class ZLDPStatisticsServiceImpl {
SearchRequest searchRequest = new SearchRequest("idx_biz_view_jg_all"); SearchRequest searchRequest = new SearchRequest("idx_biz_view_jg_all");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
//设置模糊搜索 //设置模糊搜索
String orgCode = getAndSetOrgCode(screenDto.getCityCode()); String orgCode = stCommonService.getAndSetOrgCode(screenDto.getCityCode());
searchSourceBuilder.query(QueryBuilders.boolQuery() searchSourceBuilder.query(QueryBuilders.boolQuery()
.must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*"))); .must(QueryBuilders.wildcardQuery("ORG_BRANCH_CODE.keyword", QueryParser.escape(orgCode) + "*")));
searchSourceBuilder.aggregation(AggregationBuilders.terms("count_by_use_site_code").field("USE_SITE_CODE").size(500)); searchSourceBuilder.aggregation(AggregationBuilders.terms("count_by_use_site_code").field("USE_SITE_CODE").size(500));
...@@ -499,16 +499,6 @@ public class ZLDPStatisticsServiceImpl { ...@@ -499,16 +499,6 @@ public class ZLDPStatisticsServiceImpl {
return returnList; return returnList;
} }
private String getAndSetOrgCode(String cityCode) {
String orgCode = regionCodeOrgCodeMap.get(cityCode);
if (orgCode == null) {
orgCode = screenMapper.getOrgCodeByCompanyCode(cityCode);
if (orgCode != null) {
regionCodeOrgCodeMap.put(cityCode, orgCode);
}
}
return orgCode;
}
public Map<String,Object> userCountNew(DPFilterParamDto screenDto) { public Map<String,Object> userCountNew(DPFilterParamDto screenDto) {
List<String> unitTypeList = UnitTypeEnum.getNameListByType(screenDto.getCompanyType()); List<String> unitTypeList = UnitTypeEnum.getNameListByType(screenDto.getCompanyType());
...@@ -580,7 +570,7 @@ public class ZLDPStatisticsServiceImpl { ...@@ -580,7 +570,7 @@ public class ZLDPStatisticsServiceImpl {
jsonObject5.put("value", ValidationUtil.isEmpty(statistics.getAvgTime()) ? 0 : statistics.getAvgTime()); jsonObject5.put("value", ValidationUtil.isEmpty(statistics.getAvgTime()) ? 0 : statistics.getAvgTime());
jsonObject5.put("name", "平均救援时间"); jsonObject5.put("name", "平均救援时间");
String orgCode = this.getAndSetOrgCode(regionCode); String orgCode = stCommonService.getAndSetOrgCode(regionCode);
JSONObject jsonObject6 = new JSONObject(); JSONObject jsonObject6 = new JSONObject();
jsonObject6.put("key", "jycq"); jsonObject6.put("key", "jycq");
jsonObject6.put("value", this.getQuestionNumber("检验超期",params, orgCode)); jsonObject6.put("value", this.getQuestionNumber("检验超期",params, 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