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

import java.util.Map;

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


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


    public static Map<String, Object> calcThree(TransformerEvaluateDataVo transformerEvaluateDataVo, Map<String, BusiParamTransformerVo> map, JSONArray jsonArray, int step) {
        String waterInOil = transformerEvaluateDataVo.getWaterInOil();
        String oillMedium = transformerEvaluateDataVo.getOillMedium();
        String oilBreakdownVoltage = transformerEvaluateDataVo.getOilBreakdownVoltage();

        Double calcWeight = calc(waterInOil, EvaluateConstant.YZSY_WS, "油中微水", map, jsonArray, step, "变压器绝缘试验-油质试验-油中微水计算");
        Double calcWeight2 = calc(oillMedium, EvaluateConstant.YZSY_YJS, "油介损", map, jsonArray, step, "变压器绝缘试验-油质试验-油介质计算");
        Double calcWeight3 = calc(oilBreakdownVoltage, EvaluateConstant.YZSY_YJCDY, "油击穿电压", map, jsonArray, step, "变压器绝缘试验-油质试验-油击穿电压计算");
        Double yzsy = calcWeight + calcWeight2 + calcWeight3;
        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;
    }
}
