package com.ycl.calculate; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ycl.platform.base.CheckIndex; import com.ycl.platform.domain.entity.CheckIndexCar; import com.ycl.platform.domain.entity.TMonitor; import com.ycl.platform.domain.result.HK.SnapshotDataMonitorResult; import com.ycl.platform.service.ITMonitorService; import constant.CheckConstants; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; /** * 计算公式 */ @Component @Slf4j public class IndexCalculationServe { //点位在线率 public BigDecimal siteOnline(Map param) { BigDecimal totalSites = new BigDecimal((Integer) param.get("totalSites")); BigDecimal offlineSites = new BigDecimal((Integer) param.get("offlineSites")); BigDecimal onlineSites = totalSites.subtract(offlineSites); return onlineSites.divide(totalSites, 4, RoundingMode.HALF_UP); } //视图库对接稳定性 public BigDecimal viewConnectStability(Map param) { BigDecimal totalDataSum = new BigDecimal((Integer) param.get("totalDataSum")); BigDecimal avgCount = new BigDecimal((Integer) param.get("avgCount")); return avgCount.divide(totalDataSum, 4, RoundingMode.HALF_UP); } //标注正确率 public BigDecimal infoAccuracy(Map param) { BigDecimal totalSitesCount = new BigDecimal((Integer) param.get("totalSites")); BigDecimal qualifySiteCount = new BigDecimal((Integer) param.get("qualifySite")); return qualifySiteCount.divide(totalSitesCount, 4, RoundingMode.HALF_UP); } //数据上传及时性 public BigDecimal snapshopDelay(Map param) { BigDecimal totalCount = new BigDecimal((Integer) param.get("totalCount")); BigDecimal delayCount1 = new BigDecimal((Integer) param.get("delayCount1")); BigDecimal delayCount2 = new BigDecimal((Integer) param.get("delayCount2")); BigDecimal delayCount3 = new BigDecimal((Integer) param.get("delayCount3")); BigDecimal result = delayCount1.divide(totalCount, 10, RoundingMode.HALF_UP).multiply(BigDecimal.ONE) .add(delayCount2.divide(totalCount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("0.8"))) .add(delayCount3.divide(totalCount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("0.6"))); return result.setScale(4, RoundingMode.HALF_UP); } //车辆数据完整性 public BigDecimal dataIntegrity(Map param) { BigDecimal totalSites = new BigDecimal((Integer) param.get("totalSites")); BigDecimal importantTotalSites = new BigDecimal((Integer) param.get("importantTotalSites")); BigDecimal integritySites = new BigDecimal((Integer) param.get("integritySites")); BigDecimal importantIntegritySites = new BigDecimal((Integer) param.get("importantIntegritySites")); BigDecimal result = integritySites.divide(totalSites, 10, RoundingMode.HALF_UP) .add(importantIntegritySites.divide(importantTotalSites, 10, RoundingMode.HALF_UP)); return result.setScale(4, RoundingMode.HALF_UP); } //车辆数据完整性 public BigDecimal dataAccuracy(Map param) { BigDecimal totalSites = new BigDecimal((Integer) param.get("totalSites")); BigDecimal importantTotalSites = new BigDecimal((Integer) param.get("importantTotalSites")); BigDecimal accuracySites = new BigDecimal((Integer) param.get("accuracySites")); BigDecimal importantAccuracySites = new BigDecimal((Integer) param.get("importantAccuracySites")); BigDecimal result = accuracySites.divide(totalSites, 10, RoundingMode.HALF_UP) .add(importantAccuracySites.divide(importantTotalSites, 10, RoundingMode.HALF_UP)); return result.setScale(4, RoundingMode.HALF_UP); } //时钟准确性 public BigDecimal clockAccuracy(Map param) { BigDecimal totalSitesCount = new BigDecimal((Integer) param.get("totalSites")); BigDecimal accuracySites = new BigDecimal((Integer) param.get("accuracySites")); return accuracySites.divide(totalSitesCount, 4, RoundingMode.HALF_UP); } //url可用性 public BigDecimal urlUsability(Map param) { BigDecimal totalSitesCount = new BigDecimal((Integer) param.get("totalSites")); BigDecimal urlQualifySites = new BigDecimal((Integer) param.get("urlQualifySites")); return urlQualifySites.divide(totalSitesCount, 4, RoundingMode.HALF_UP); } //大图可用性 public BigDecimal picUsability(Map param) { BigDecimal totalSitesCount = new BigDecimal((Integer) param.get("totalSites")); BigDecimal picUsabilitySites = new BigDecimal((Integer) param.get("picUsabilitySites")); return picUsabilitySites.divide(totalSitesCount, 4, RoundingMode.HALF_UP); } //图片合格率 public BigDecimal dataQualify(Map param) { BigDecimal totalSitesCount = new BigDecimal((Integer) param.get("totalSites")); BigDecimal picQualifySites = new BigDecimal((Integer) param.get("picQualifySites")); return picQualifySites.divide(totalSitesCount, 4, RoundingMode.HALF_UP); } //返回省厅国标码集合 public List getProvince() { // TODO: 分省厅市局 需要补充集合数据 List list = new ArrayList<>(); return list; } //返回重点点位集合 public List getImportant() { // TODO: 重点点位 需要补充集合数据 List list = new ArrayList<>(); return list; } //检查是否存在当日数据 public T getCheckIndex(String key, List checkIndexList, Class clazz) { T checkIndex; // 检查是否已存在今日数据 Optional existingIndex = checkIndexList.stream() .filter(index -> key.equals(index.getDeptId().toString()) && (key.startsWith("Province_") ? CheckConstants.Examine_Tag_City.equals(index.getExamineTag()) : CheckConstants.Examine_Tag_County.equals(index.getExamineTag()))) .findFirst(); if (existingIndex.isPresent()) { checkIndex = existingIndex.get(); } else { try { checkIndex = clazz.getDeclaredConstructor().newInstance(); checkIndex.setDeptId(key.startsWith("Province_") ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key)); checkIndex.setExamineTag(key.startsWith("Province_") ? CheckConstants.Examine_Tag_City : CheckConstants.Examine_Tag_County); checkIndex.setCreateTime(new Date()); } catch (Exception e) { checkIndex = null; log.error("无法创建 checkIndex 实例", e); } } return checkIndex; } }