package com.huatek.busi.task.transformer.utils.insulationtest;

import com.google.common.collect.Maps;
import com.huatek.busi.task.transformer.utils.CommonUtils;
import com.huatek.busi.util.EvaluateConstant;
import com.huatek.busi.vo.BusiParamTransformerVo;
import com.huatek.busi.vo.SoundVibrationParamsVo;
import com.huatek.busi.vo.epa.EpaSoundVibrationVo;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;

import java.util.Map;

/**
 * @version V1.0
 * @ClassName: SoundLevelVibration
 * @Description: 变压器绝缘试验-声级振动.
 * @Author: Arno
 * @Date: 2023/10/10 13:35
 */
@Slf4j
public class SoundLevelVibration {


    /**
     * @param epaSoundVibrationVo 评测数据
     * @param secondLevelMap         二级分析参数
     * @param threeLevelMap          三级分析参数
     * @return Double
     * @Title: calcOilQualityWeight
     * @Description: 变压器绝缘试验-油质试验 权重计算
     * @createDate: Sep 4, 2019 6:24:47 PM
     */
    public static Map<String, Object> calcSoundLevelVibrationWeight(EpaSoundVibrationVo epaSoundVibrationVo, Map<String, BusiParamTransformerVo> secondLevelMap,
                                                                    Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step) {
        BusiParamTransformerVo secondVo = CommonUtils.getEvaluateObject(EvaluateConstant.BYQ_SJZD, secondLevelMap);
        if (null != secondVo) {
            if (CommonUtils.checkAttend(secondVo)) {
                Map<String, Object> threeResultMap = calcThree(epaSoundVibrationVo, threeLevelMap, jsonArray, step);
                return CommonUtils.calcSecond(secondVo, threeResultMap, jsonArray, "变压器绝缘试验-声级振动权重计算");
            }
        }
        log.error("-- >>变压器绝缘试验-声级振动未设置评估参数");
        return null;
    }

    public static Map<String, Object> calcThree(EpaSoundVibrationVo vo, Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step) {
        Double calcWeight = 0d;
        Double calcWeight2 = 0d;
        Double calcWeight3 = 0d;
        Double calcWeight4 = 0d;
//
//        //中心
//        String centerPoint = vo.getCenterPoint();
//        //高压侧
//        String highPoint = vo.getHighPoint();
//        //底压侧
//        String lowPoint = vo.getLowPoint();
//        //噪声
//        String noisePoint = vo.getNoisePoint();
//
//        Double calcWeight = calc(centerPoint, EvaluateConstant.SJZD_ZXDDL, "中性点电流", threeLevelMap, jsonArray, step, "变压器绝缘试验-声级振动-中性点电流计算");
//        Double calcWeight2 = calc(highPoint, EvaluateConstant.SJZD_YBZD, "原边振动", threeLevelMap, jsonArray, step, "变压器绝缘试验-声级振动-原边振动计算");
//        Double calcWeight3 = calc(lowPoint, EvaluateConstant.SJZD_FBZD, "副边振动", threeLevelMap, jsonArray, step, "变压器绝缘试验-声级振动-副边振动计算");
//        Double calcWeight4 = calc(noisePoint, EvaluateConstant.SJZD_ZS, "噪声", threeLevelMap, jsonArray, step, "变压器绝缘试验-声级振动-噪声计算");
        if (null != vo) {
            //中心
            String centerPoint = vo.getCenterPoint();
            //高压侧
            String highPoint = vo.getHighPoint();
            //底压侧
            String lowPoint = vo.getLowPoint();
            //噪声
            String noisePoint = vo.getNoisePoint();
            calcWeight = calc(centerPoint, EvaluateConstant.SJZD_ZXDDL, "中性点电流", threeLevelMap, jsonArray, step, "变压器绝缘试验-声级振动-中性点电流计算");
            calcWeight2 = calc(highPoint, EvaluateConstant.SJZD_YBZD, "原边振动", threeLevelMap, jsonArray, step, "变压器绝缘试验-声级振动-原边振动计算");
            calcWeight3 = calc(lowPoint, EvaluateConstant.SJZD_FBZD, "副边振动", threeLevelMap, jsonArray, step, "变压器绝缘试验-声级振动-副边振动计算");
            calcWeight4 = calc(noisePoint, EvaluateConstant.SJZD_ZS, "噪声", threeLevelMap, jsonArray, step, "变压器绝缘试验-声级振动-噪声计算");
        }

        Double yzsy = calcWeight + calcWeight2 + calcWeight3 + calcWeight4;
        log.info("- >>变压器绝缘试验-诊断性试验-分项和计算结果: [{}]", yzsy);
        step += 1;
        return CommonUtils.buildResult(step, yzsy);
    }

    public static Double calc(String value, String type, String
            typeDesc, Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step, String stepName) {
        Double aDouble = CommonUtils.calcItemResult(value, type, typeDesc, threeLevelMap, jsonArray, step, stepName);
        log.info("-->>变压器绝缘试验-声级振动-{}计算结果{}", typeDesc, aDouble);
        return aDouble;
    }
}
