zxl
11 小时以前 3b0516a2959e25576e4f3fda697a3b025d06c8c9
ycl-server/src/main/java/com/ycl/calculate/IndexCalculationUtils.java
@@ -1,9 +1,16 @@
package com.ycl.calculate;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ycl.platform.base.CheckIndex;
import com.ycl.platform.domain.entity.YwPoint;
import com.ycl.platform.mapper.YwPointMapper;
import constant.ApiConstants;
import constant.CheckConstants;
import enumeration.general.PublishType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -11,18 +18,20 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Slf4j
public class IndexCalculationUtils {
    //检查是否存在当日数据
    public <T extends CheckIndex> T getCheckIndex(String key, List<T> checkIndexList, Class<T> clazz) {
        T checkIndex;
        // 检查是否已存在今日数据
        Optional<T> existingIndex = checkIndexList.stream()
                .filter(index -> key.startsWith(ApiConstants.Province) ?
                        CheckConstants.Examine_Tag_Province.equals(index.getExamineTag()) && key.split("_")[1].equals(index.getDeptId().toString())
                        : key.startsWith(ApiConstants.Dept) ? CheckConstants.Examine_Tag_Dept.equals(index.getExamineTag()) && key.split("_")[1].equals(index.getDeptId().toString())
                        : CheckConstants.Examine_Tag_County.equals(index.getExamineTag()) && key.equals(index.getDeptId().toString()))
                .findFirst();
@@ -31,9 +40,11 @@
        } else {
            try {
                checkIndex = clazz.getDeclaredConstructor().newInstance();
                checkIndex.setDeptId(key.startsWith(ApiConstants.Province) ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key));
                checkIndex.setExamineTag(key.startsWith(ApiConstants.Province) ? CheckConstants.Examine_Tag_Province : CheckConstants.Examine_Tag_County);
                checkIndex.setDeptId(key.startsWith(ApiConstants.Province) || key.startsWith(ApiConstants.Dept) ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key));
                checkIndex.setExamineTag(key.startsWith(ApiConstants.Province) ? CheckConstants.Examine_Tag_Province : key.startsWith(ApiConstants.Dept) ? CheckConstants.Examine_Tag_Dept : CheckConstants.Examine_Tag_County);
                checkIndex.setCreateTime(new Date());
                //默认发布
                checkIndex.setPublish(PublishType.PUBLISHED.getCode());
            } catch (Exception e) {
                checkIndex = null;
                log.error("无法创建 checkIndex 实例", e);
@@ -42,7 +53,9 @@
        return checkIndex;
    }
    /** --------指标算法---------*/
    /**
     * --------指标算法---------
     */
    //一机一档合格率
    public BigDecimal monitorQualify(Map<String, Object> param) {
@@ -105,9 +118,9 @@
    //视图库对接稳定性
    public BigDecimal viewConnectStability(Map<String, Object> param) {
        BigDecimal totalDataSum = new BigDecimal((Integer) param.get("totalDataSum"));
        BigDecimal avgCount = (BigDecimal) param.get("avgCount");
        log.info("视图库对接稳定性,totalDataSum:{},avgCount:{}",totalDataSum,avgCount);
        return BigDecimal.ZERO.compareTo(totalDataSum) == 0 ? BigDecimal.ZERO : avgCount.divide(totalDataSum, 4, RoundingMode.HALF_UP);
        BigDecimal lastCount = (BigDecimal) param.get("lastCount");
        log.info("视图库对接稳定性,totalDataSum:{},lastCount:{}", totalDataSum, lastCount);
        return totalDataSum.divide(lastCount, 4, RoundingMode.HALF_UP);
    }
    //标注正确率