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

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.epa.EpaEvaluateDataVo;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;

import java.util.Map;

/**
 * @version V1.0
 * @ClassName: OilTest
 * @Description: 变压器绝缘试验-油色谱试验.
 * @Author: Arno
 * @Date: 2023/10/9 15:16
 */
@Slf4j
public class OilTest {

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


    public static Map<String, Object> calcThree(EpaEvaluateDataVo vo, Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step) {
      if(null == vo ){
          return CommonUtils.buildResult(step, 0d);
      }
        double calcWeight = calc(vo.getH2(), EvaluateConstant.H2, EvaluateConstant.H2, threeLevelMap, jsonArray, step, "变压器绝缘试验-油色谱-H2计算");
        double calcWeight2 = calc(vo.getCo(), EvaluateConstant.CO, EvaluateConstant.CO, threeLevelMap, jsonArray, step, "变压器绝缘试验-油色谱-CO计算");
        double calcWeight3 = calc(vo.getCo2(), EvaluateConstant.CO2, EvaluateConstant.CO2, threeLevelMap, jsonArray, step, "变压器绝缘试验-油色谱-CO2计算");
        double calcWeight4 = calc(vo.getCh4(), EvaluateConstant.CH4, EvaluateConstant.CH4, threeLevelMap, jsonArray, step, "变压器绝缘试验-油色谱-CH4计算");
        double calcWeight5 = calc(vo.getC2h2(), EvaluateConstant.C2H2, EvaluateConstant.C2H2, threeLevelMap, jsonArray, step, "变压器绝缘试验-油色谱-C2H2计算");
        double calcWeight6 = calc(vo.getC2h4(), EvaluateConstant.C2H4, EvaluateConstant.C2H4, threeLevelMap, jsonArray, step, "变压器绝缘试验-油色谱-C2H4计算");
        double calcWeight7 = calc(vo.getC2h6(), EvaluateConstant.C2H6, EvaluateConstant.C2H6, threeLevelMap, jsonArray, step, "变压器绝缘试验-油色谱-C2H6计算");
        double calcWeight8 = calc(vo.getZt(), EvaluateConstant.ZT, EvaluateConstant.ZT, threeLevelMap, jsonArray, step, "变压器绝缘试验-油色谱-ZT计算");
        double ysp = calcWeight + calcWeight2 + calcWeight3 + calcWeight4 + calcWeight5 + calcWeight6 + calcWeight7
                + calcWeight8;
        log.info("-->>变压器绝缘试验-油色谱-分项和计算结果:[{}]", ysp);
        return CommonUtils.buildResult(step, ysp);
    }

    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;
    }


}
