Commit 9b38d2fb authored by 刘林's avatar 刘林

fix(Statistics):设备认领率统计

parent 38bd32dd
...@@ -32,4 +32,6 @@ public interface ZLStatisticsMapper { ...@@ -32,4 +32,6 @@ public interface ZLStatisticsMapper {
Long countCompanyForCertDateTimeOut(@Param("dto") DPFilterParamDto dpFilterParamDto, @Param("orgCode") String orgCode, @Param("limitDate") String limitDate); Long countCompanyForCertDateTimeOut(@Param("dto") DPFilterParamDto dpFilterParamDto, @Param("orgCode") String orgCode, @Param("limitDate") String limitDate);
Long countCompanyForCertDateTemporary(@Param("dto")DPFilterParamDto dpFilterParamDto, @Param("orgCode") String orgCode, @Param("limitDate") String limitDate); Long countCompanyForCertDateTemporary(@Param("dto")DPFilterParamDto dpFilterParamDto, @Param("orgCode") String orgCode, @Param("limitDate") String limitDate);
Long getEquipTotal(@Param("cityCode") String cityCode);
} }
...@@ -97,6 +97,10 @@ ...@@ -97,6 +97,10 @@
a.expiry_date >= current_date a.expiry_date >= current_date
and a.expiry_date <![CDATA[<=]]> #{limitDate} and a.expiry_date <![CDATA[<=]]> #{limitDate}
</select> </select>
<select id="getEquipTotal" resultType="java.lang.Long">
select equip_num from tzs_equip_claim_statistics where city_code = #{cityCode}
</select>
</mapper> </mapper>
...@@ -92,4 +92,15 @@ public class ZLDPStatisticsController { ...@@ -92,4 +92,15 @@ public class ZLDPStatisticsController {
} }
return ResponseHelper.buildResponse(statisticsService.statisticInfoByRegionAndDate(dpFilterParamDto)); return ResponseHelper.buildResponse(statisticsService.statisticInfoByRegionAndDate(dpFilterParamDto));
} }
/**
* 大屏-总览-左屏-设备纳管率
* @return Map
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/getEquipManagementRateStatistics")
@ApiOperation(httpMethod = "POST", value = "大屏-总览-左屏-设备纳管率", notes = "大屏-总览-左屏-设备纳管率")
public ResponseModel<Map<String, Object>> getEquipManagementRateStatistics(@RequestBody DPFilterParamDto screenDto){
return ResponseHelper.buildResponse(statisticsService.getEquipManagementRateStatistics(screenDto));
}
} }
...@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.statistcs.biz.service.impl; ...@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.statistcs.biz.service.impl;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.dto.CountDto;
import com.yeejoin.amos.boot.biz.common.entity.DataDictionary; import com.yeejoin.amos.boot.biz.common.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl; import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto; import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
...@@ -11,11 +12,14 @@ import com.yeejoin.amos.boot.module.common.api.enums.UserPostEnum; ...@@ -11,11 +12,14 @@ import com.yeejoin.amos.boot.module.common.api.enums.UserPostEnum;
import com.yeejoin.amos.boot.module.statistics.api.mapper.AlertStatisticsMapper; import com.yeejoin.amos.boot.module.statistics.api.mapper.AlertStatisticsMapper;
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.feign.systemctl.model.RegionModel;
import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.queryparser.classic.QueryParser;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient; 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.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.AggregationBuilders;
...@@ -26,8 +30,10 @@ import org.springframework.stereotype.Service; ...@@ -26,8 +30,10 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
...@@ -657,4 +663,83 @@ public class ZLDPStatisticsServiceImpl { ...@@ -657,4 +663,83 @@ public class ZLDPStatisticsServiceImpl {
private Long getQuestionNumber(String problemType, DPFilterParamDto params, String orgCode) { private Long getQuestionNumber(String problemType, DPFilterParamDto params, String orgCode) {
return alertStatisticsMapper.countProblemByTypeDateAndOrgCode(problemType, params, orgCode); return alertStatisticsMapper.countProblemByTypeDateAndOrgCode(problemType, params, orgCode);
} }
public Map<String, Object> getEquipManagementRateStatistics(DPFilterParamDto screenDto) {
Map<String, Object> result = new HashMap<>();
List<Map<String, Object>> legendData = new ArrayList<>();
legendData.add(createLegend("设备认领总数", "equipTotal"));
legendData.add(createLegend("设备认领率", "claimRate"));
List<RegionModel> regionList = stCommonService.setRegionIfRootParentAndNoAccessIf3Level("610000");
// 获取区域名称并过滤
List<String> xData = regionList.stream()
.map(RegionModel::getRegionName)
.filter(regionName -> !"西咸新区".equals(regionName))
.collect(Collectors.toList());
// 过滤掉 "西咸新区" 并获取 yData
List<CountDto> yData = getYDataForQZ(regionList);
result.put("legendData", legendData);
result.put("xData", xData);
result.put("equipTotal", yData.stream().map(CountDto::getLongValue).collect(Collectors.toList()));
result.put("claimRate", yData.stream().map(CountDto::getStrValue).collect(Collectors.toList()));
return result;
}
private List<CountDto> getYDataForQZ(List<RegionModel> regionList) {
DecimalFormat decimalFormat = new DecimalFormat("0.00");
return regionList.parallelStream()
.filter(region -> !"西咸新区".equals(region.getRegionName()))
.map(region -> {
CountDto dto = new CountDto();
Long equipTotal = screenMapper.getEquipTotal(region.getRegionCode().toString());
String orgCode = stCommonService.getAndSetOrgCode(region.getRegionCode().toString());
Long equipIsManageNum = staticsCenterMapCountDataForEquipIsManage(orgCode);
// 设置设备总数
dto.setLongValue(equipTotal);
// 计算并设置管理率
String claimRate = calculateClaimRate(equipTotal, equipIsManageNum, decimalFormat);
dto.setStrValue(claimRate);
return dto;
}).collect(Collectors.toList());
}
private Map<String, Object> createLegend(String value, String dataKey) {
return new HashMap<String, Object>() {{
put("value", value);
put("dataKey", dataKey);
}};
}
private String calculateClaimRate(Long equipTotal, Long equipIsManageNum, DecimalFormat decimalFormat) {
if (equipIsManageNum == 0 || equipTotal == 0) {
return "0%";
}
BigDecimal equipTotalDecimal = BigDecimal.valueOf(equipTotal);
BigDecimal equipIsManageDecimal = BigDecimal.valueOf(equipIsManageNum);
BigDecimal claimRate = equipIsManageDecimal.divide(equipTotalDecimal, 4, RoundingMode.HALF_UP)
.multiply(BigDecimal.valueOf(100));
return decimalFormat.format(claimRate) + "%";
}
private Long staticsCenterMapCountDataForEquipIsManage(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.termQuery("IS_INTO_MANAGEMENT", true));
// 且8大类,目的去掉脏数据
boolMust.must(QueryBuilders.termsQuery("EQU_LIST_CODE", StCommonServiceImpl.getEquipmentCategory().stream().map(EquipmentCategoryDto::getCode).collect(Collectors.toList())));
request.query(boolMust);
try {
CountResponse response = restHighLevelClient.count(request, RequestOptions.DEFAULT);
num = response.getCount();
} catch (IOException e) {
throw new RuntimeException(e);
}
return num;
}
} }
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