Commit 0327b460 authored by suhuiguang's avatar suhuiguang

1.大屏-区域安全指数接口优重写初稿

parent 197716b4
package com.yeejoin.amos.boot.module.statistics.api.dto;
import lombok.Data;
/**
* @author Administrator
*/
@Data
public class SecurityIndexCountItemDto {
private String regionCode;
private String regionName;
/**
* 充装检查率
*/
private String czjc;
/**
* 许可有效率
*/
String xuke;
/**
* 使用登记办理率
*/
String shiyongdengji;
/**
* 检验超期率
*/
String jianyanchaoqi;
/**
* 检验合格率
*/
String jianyanhege;
/**
* 充装检查率
*/
String czjchege;
}
......@@ -46,10 +46,10 @@ public interface AQZSDPStatisticsMapper {
/**
* 单位按照资质状态分组下的统计数量
*
* @param regionCode 区域
* @param orgCode 区域
* @return List<KeyValueDto>
*/
List<KeyValueDto> queryLicenseEfficiencyOfRegion(@Param(value = "regionCode") String regionCode);
List<KeyValueDto> queryLicenseEfficiencyOfRegion(@Param(value = "orgCode") String orgCode);
/**
* 查询单个单位的有效期信息
*
......@@ -58,8 +58,8 @@ public interface AQZSDPStatisticsMapper {
*/
KeyValueDto queryLicenseEfficiencyOneCompany(@Param(value = "appId") String appId);
Map<String, Object> getInspectionExpiredRate(@Param(value = "regionCode") String regionCode, @Param(value = "appId") String appId);
Map<String, Object> getInspectionExpiredRate(@Param(value = "orgCode") String orgCode, @Param(value = "appId") String appId);
Map<String, Object> getInspectionResultRate(@Param(value = "regionCode") String regionCode, @Param(value = "appId") String appId);
Map<String, Object> getInspectionResultRate(@Param(value = "orgCode") String orgCode, @Param(value = "appId") String appId);
}
......@@ -246,8 +246,8 @@
<where>
cu.data_sources = '陕西省内企业'
AND cu.unit_type LIKE '%充装单位%'
<if test="regionCode != null and regionCode != ''">
and cu.org_code like concat(#{regionCode}, '%')
<if test="orgCode != null and orgCode != ''">
and cu.supervise_org_code like concat(#{orgCode}, '%')
</if>
<if test="appId != null and appId != ''">
and cu.app_id = #{appId}
......@@ -264,8 +264,8 @@
<where>
cu.data_sources = '陕西省内企业'
AND cu.unit_type LIKE '%充装单位%'
<if test="regionCode != null and regionCode != ''">
and cu.org_code like concat( #{regionCode}, '%')
<if test="orgCode != null and orgCode != ''">
and cu.supervise_org_code like concat( #{orgCode}, '%')
</if>
<if test="appId != null and appId != ''">
and cu.app_id = #{appId}
......@@ -303,7 +303,7 @@
where
cu.data_sources = '陕西省内企业'
AND cu.unit_type LIKE '%充装单位%'
and cu.org_code like concat('%', #{regionCode}, '%')
and cu.supervise_org_code like concat(#{orgCode}, '%')
GROUP BY strKey
</select>
</mapper>
......
......@@ -20,7 +20,7 @@ import java.util.List;
import java.util.Map;
@RestController
@Api(tags = "大屏-安全追溯统计Api")
@Api(tags = "大屏-安全追溯及气瓶统计Api")
@RequestMapping(value = "/dp/aqzs")
public class AQZSDPStatisticsController {
......@@ -33,20 +33,19 @@ public class AQZSDPStatisticsController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(value = "大屏-气瓶-区域安全指数")
@PostMapping(value = "/security-index")
public ResponseModel<Map<String, Object>> getSecurityIndex(@RequestBody Map<String, Object> map) throws Exception {
Object regionCode = map.get("cityCode");
if (ObjectUtils.isEmpty(regionCode)) {
regionCode = "610000";
public ResponseModel<Map<String, Object>> getSecurityIndex(@Validated @RequestBody DPFilterParamDto dpFilterParamDto, BindingResult bindingResult) throws Exception {
List<FieldError> fieldErrors = bindingResult.getFieldErrors();
if (!fieldErrors.isEmpty()) {
throw new BadRequest(fieldErrors.get(0).getDefaultMessage());
}
Map<String, Object> result = statisticsService.getSecurityIndex(regionCode.toString());
Map<String, Object> result = statisticsService.getSecurityIndex(dpFilterParamDto);
return ResponseHelper.buildResponse(result);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/earlyWarning/child", method = RequestMethod.POST)
@ApiOperation(httpMethod = "POST", value = "大屏-气瓶-区域安全指数统计")
@RequestMapping(value = "/earlyWarning/child", method = RequestMethod.POST)
public ResponseModel<Map<String, Object>> getChildEarlyWarning(@RequestBody Map<String, Object> map) throws Exception {
Object regionCode = map.get("cityCode");
if (ObjectUtils.isEmpty(regionCode)) {
......
......@@ -8,9 +8,9 @@ import com.yeejoin.amos.boot.module.common.api.enums.IssueMainBodyEnum;
import com.yeejoin.amos.boot.module.common.api.enums.IssueTypeEnum;
import com.yeejoin.amos.boot.module.common.api.enums.ReginStepEnum;
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.mapper.AQZSDPStatisticsMapper;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentClassifityEnum;
import com.yeejoin.amos.boot.module.ymt.api.service.ITzBaseEnterpriseInfoService;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import com.yeejoin.amos.feign.systemctl.Systemctl;
......@@ -39,6 +39,7 @@ import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
......@@ -64,8 +65,8 @@ public class AQZSDPStatisticsServiceImpl {
private AQZSDPStatisticsMapper statisticsMapper;
private String getLicenseEfficiencyByRegion(String regionCode) {
List<KeyValueDto> keyValueDtos = statisticsMapper.queryLicenseEfficiencyOfRegion(regionCode);
private String getLicenseEfficiencyByRegion(String orgCode) {
List<KeyValueDto> keyValueDtos = statisticsMapper.queryLicenseEfficiencyOfRegion(orgCode);
int totalUnitNumber = keyValueDtos.stream().mapToInt(KeyValueDto::getIValue).sum();
int okUnitNumberNumber = keyValueDtos.stream().filter(k -> k.getStrKey().equals(LICENSE_IS_OK)).mapToInt(KeyValueDto::getIValue).sum();
if (totalUnitNumber == 0) {
......@@ -79,7 +80,6 @@ public class AQZSDPStatisticsServiceImpl {
private long searchEsCount(Boolean checkOk, Boolean resultOk, String regionCode, String appId) {
CountRequest countRequest = new CountRequest("cylinder_filling");
// countRequest.indices("cylinder_filling");
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
if (checkOk) {
//匹配充装前检查和充装后检查都有数据
......@@ -161,15 +161,6 @@ public class AQZSDPStatisticsServiceImpl {
xuke.add(String.format("%.4f", Double.parseDouble(value) / 100.0000));
}
}
if (!ValidationUtil.isEmpty(orgCode) && !isHavingUnitInRegion) {
shiyongdengji.add("0");
jianyanchaoqi.add("0");
jianyanhege.add("0");
shiyongdengji.add("0");
czjc.add("0");
czjchege.add("0");
continue;
}
// 2.使用登记办理率
shiyongdengji.add("1");
// 3.检验超期率
......@@ -216,122 +207,115 @@ public class AQZSDPStatisticsServiceImpl {
return regionList;
}
public Map<String, Object> getSecurityIndex(DPFilterParamDto dpFilterParamDto) throws Exception {
List<RegionModel> regionModels = this.setRegionIfRootParent(dpFilterParamDto.getCityCode());
Map<String, SecurityIndexCountItemDto> regionCodeSecurityIndexMap = getSecurityIndexCountItemDtoMap(regionModels);
List<Map<String, String>> data = new ArrayList<>();
List<Map<String, String>> finalData = data;
regionCodeSecurityIndexMap.forEach((k, v) -> {
Map<String, String> item = new HashMap<>();
item.put("name", v.getRegionName());
// 计算xuke的加权值
double xukeWeighted = Double.parseDouble(v.getXuke()) * 0.10;
// 剩余权重平均分配给四个因素,每个因素大约22.5%(但为了简化,我们这里用25%的剩余权重)
double remainingWeightPerFactor = 0.90 / 4;
// 计算其他四个因素的加权值
double jianyanchaoqiWeighted = Double.parseDouble(v.getJianyanchaoqi()) * remainingWeightPerFactor;
double jianyanhegeWeighted = Double.parseDouble(v.getJianyanhege()) * remainingWeightPerFactor;
double czjcWeighted = Double.parseDouble(v.getCzjc()) * remainingWeightPerFactor;
double czjchegeWeighted = Double.parseDouble(v.getCzjchege()) * remainingWeightPerFactor;
// 计算总指数
double totalIndex = xukeWeighted + jianyanchaoqiWeighted + jianyanhegeWeighted + czjcWeighted + czjchegeWeighted;
item.put("value", String.format("%.2f", totalIndex));
finalData.add(item);
});
data = finalData.stream()
.filter(map -> map.containsKey("value"))
.sorted(Comparator.comparingDouble(map -> {
// 检查并解析值,如果失败则返回Double.MIN_VALUE(或根据需要处理)
try {
return Double.parseDouble(map.get("value"));
} catch (NumberFormatException e) {
// 处理无法解析为double的情况,这里返回Double.MIN_VALUE表示最小
// 或者可以抛出自定义异常,记录日志等
return Double.MIN_VALUE;
}
}))
.collect(Collectors.toList());
Map<String, Object> result = new HashMap<>();
List<String> name = data.stream().map(map -> map.get("name")).collect(Collectors.toList());
Collections.reverse(name);
result.put("xdata", name);
List<String> value = data.stream().map(map -> map.get("value")).collect(Collectors.toList());
Collections.reverse(value);
result.put("ydata", value);
return result;
}
public Map<String, Object> getSecurityIndex(String regionCode) throws Exception {
List<RegionModel> regionModels = this.setRegionIfRootParent(regionCode);
List<String> collect = regionModels.stream().map(c -> c.getRegionCode().toString()).collect(Collectors.toList());
List<CompanyModel> companyModelList = Privilege.companyClient.queryListByCompanyCode(Strings.join(collect, ",")).getResult();
Map<String, CompanyModel> companyMap = companyModelList.stream().collect(Collectors.toMap(CompanyModel::getCompanyCode, c -> c));
List<String> xdata = new ArrayList<>();
List<String> xuke = new ArrayList<>();
List<String> shiyongdengji = new ArrayList<>();
List<String> jianyanchaoqi = new ArrayList<>();
List<String> jianyanhege = new ArrayList<>();
List<String> czjc = new ArrayList<>();
List<String> czjchege = new ArrayList<>();
for (RegionModel region : regionModels) {
CompanyModel companyModel = companyMap.get(region.getRegionCode().toString());
if (ObjectUtils.isEmpty(companyModel)) {
continue;
private Map<String, SecurityIndexCountItemDto> getSecurityIndexCountItemDtoMap(List<RegionModel> regionModels) {
List<SecurityIndexCountItemDto> countItemDtoList = getSecurityIndexCountDtoList(regionModels);
return countItemDtoList.stream().collect(Collectors.toMap(SecurityIndexCountItemDto::getRegionCode, Function.identity(), (k1, k2) -> k2));
}
// 是否有充装企业在指定区域下
Boolean isHavingUnitInRegion = true;
String orgCode = companyModel.getOrgCode();
xdata.add(region.getRegionName());
private List<SecurityIndexCountItemDto> getSecurityIndexCountDtoList(List<RegionModel> regionModels) {
return regionModels.parallelStream().map(r -> {
String orgCode = this.getAndSetOrgCode(r.getRegionCode().toString());
SecurityIndexCountItemDto countItemDto = new SecurityIndexCountItemDto();
countItemDto.setRegionCode(r.getRegionCode().toString());
countItemDto.setRegionName(r.getRegionName());
if (ObjectUtils.isEmpty(orgCode)) {
this.setDefaultZeroData(countItemDto);
} else {
// 1.许可有效率
if (!ValidationUtil.isEmpty(companyModel)) {
String value = this.getLicenseEfficiencyByRegion(orgCode);
if (NO_DATA_STR.equals(value)) {
value = "0";
xuke.add(value);
countItemDto.setXuke(value);
} else {
xuke.add(value);
}
}
if (!ValidationUtil.isEmpty(orgCode) && !isHavingUnitInRegion) {
shiyongdengji.add("0");
jianyanchaoqi.add("0");
jianyanhege.add("0");
shiyongdengji.add("0");
czjc.add("0");
czjchege.add("0");
continue;
countItemDto.setXuke(value);
}
// 2.使用登记办理率
shiyongdengji.add("100");
// 2.使用登记办理率 TODO
countItemDto.setShiyongdengji("100");
// 3.检验超期率
jianyanchaoqi.add(statisticsMapper.getInspectionExpiredRate(orgCode, null).get("expiredRate").toString());
countItemDto.setJianyanchaoqi(statisticsMapper.getInspectionExpiredRate(orgCode, null).get("expiredRate").toString());
// 4.检验合格率
jianyanhege.add(statisticsMapper.getInspectionResultRate(orgCode, null).get("resultRate").toString());
countItemDto.setJianyanhege(statisticsMapper.getInspectionResultRate(orgCode, null).get("resultRate").toString());
// 5.充装检查率
long totalAll = searchEsCount(false, false, orgCode, null);
long totalCheck = searchEsCount(true, false, orgCode, null);
long totalResult = searchEsCount(false, true, orgCode, null);
if (totalAll != 0) {
czjc.add(new DecimalFormat("#.00").format(((double) totalCheck / totalAll) * 100));
countItemDto.setCzjc(new DecimalFormat("#.00").format(((double) totalCheck / totalAll) * 100));
} else {
czjc.add("0");
countItemDto.setCzjc("0");
}
// 6.充装检查合格率
if (totalAll != 0) {
czjchege.add(new DecimalFormat("#.00").format(((double) totalResult / totalAll) * 100));
countItemDto.setCzjchege(new DecimalFormat("#.00").format(((double) totalResult / totalAll) * 100));
} else {
czjchege.add("0");
countItemDto.setCzjchege("0");
}
}
Map<String, Object> result = new HashMap<>();
List<Map<String, String>> data = new ArrayList<>();
// List<String> ydata = new ArrayList<>();
for (int i = 0; i < xdata.size(); i++) {
Map<String, String> item = new HashMap<>();
item.put("name", xdata.get(i));
// 计算xuke的加权值
double xukeWeighted = Double.parseDouble(xuke.get(i)) * 0.10; // 10%
// 剩余权重平均分配给四个因素,每个因素大约22.5%(但为了简化,我们这里用25%的剩余权重)
double remainingWeightPerFactor = 0.90 / 4; // 简化为每个因素25%的剩余权重
// 计算其他四个因素的加权值
double jianyanchaoqiWeighted = Double.parseDouble(jianyanchaoqi.get(i)) * remainingWeightPerFactor;
double jianyanhegeWeighted = Double.parseDouble(jianyanhege.get(i)) * remainingWeightPerFactor;
double czjcWeighted = Double.parseDouble(czjc.get(i)) * remainingWeightPerFactor;
double czjchegeWeighted = Double.parseDouble(czjchege.get(i)) * remainingWeightPerFactor;
// 计算总指数
double totalIndex = xukeWeighted + jianyanchaoqiWeighted + jianyanhegeWeighted + czjcWeighted + czjchegeWeighted;
item.put("value", String.format("%.2f", totalIndex));
data.add(item);
// ydata.add(String.format("%.2f", totalIndex));
return countItemDto;
}).collect(Collectors.toList());
}
data = data.stream()
.filter(map -> map.containsKey("value")) // 确保每个Map都包含指定的键
.sorted(Comparator.comparingDouble(map -> {
// 检查并解析值,如果失败则返回Double.MIN_VALUE(或根据需要处理)
try {
return Double.parseDouble(map.get("value"));
} catch (NumberFormatException e) {
// 处理无法解析为double的情况,这里返回Double.MIN_VALUE表示最小
// 或者可以抛出自定义异常,记录日志等
return Double.MIN_VALUE;
private void setDefaultZeroData(SecurityIndexCountItemDto countItemDto) {
countItemDto.setXuke("0");
countItemDto.setShiyongdengji("0");
countItemDto.setJianyanhege("0");
countItemDto.setCzjc("0");
countItemDto.setCzjchege("0");
countItemDto.setJianyanchaoqi("0");
}
}))
.collect(Collectors.toList());
List<String> name = data.stream().map(map -> map.get("name")).collect(Collectors.toList());
Collections.reverse(name);
result.put("xdata", name);
List<String> value = data.stream().map(map -> map.get("value")).collect(Collectors.toList());
Collections.reverse(value);
result.put("ydata", value);
return result;
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) {
......
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