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 com.huatek.busi.vo.epa.EpaIcgeDataVo;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;

import java.util.Map;

/**
 * @version V1.0
 * @ClassName: DiagnosticTesting
 * @Description: 变压器绝缘试验-诊断性试验 权重计算.
 * @Author: Arno
 * @Date: 2023/10/10 10:58
 */
@Slf4j
public class DiagnosticTest {


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


    public static Map<String, Object> calcThree(TransformerEvaluateDataVo vo, Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step, EpaIcgeDataVo epaIcgeDataVo) {
        //绝缘纸含水量
        String waterPage = vo.getWaterInOil();
        //空载电流、空载损耗变化率（%）
        String noload = vo.getNoloadCurrentAndNoloadLossRate();
        //短路阻抗变化率(%)
        String shortCircuit = vo.getShortCircuitImpedanceChangeRate();
        //绕组直流泄漏电流（μA）
        String dcleak = vo.getDcLeakageCurrentWinding();
//        //铁芯接地电流
//        String coreGroundCurrent = vo.getCoreGroundCurrent();

        Double calcWeight = calc(waterPage, EvaluateConstant.ZDXSY_YJZHSL, "绝缘纸含水量", threeLevelMap, jsonArray, step, "变压器绝缘试验-诊断性试验-绝缘纸含水量计算结果");
        Double calcWeight2 = calc(noload, EvaluateConstant.ZDXSY_KZDL_KZSHL, "空载电流、空载损耗变化率（%）", threeLevelMap, jsonArray, step, "变压器绝缘试验-诊断性试验-空载电流、空载损耗变化率（%）计算结果");
        Double calcWeight3 = calc(shortCircuit, EvaluateConstant.ZDXSY_DLZKBHL, "短路阻抗变化率(%)", threeLevelMap, jsonArray, step, "变压器绝缘试验-诊断性试验-短路阻抗变化率(%)计算结果");

        //在线数据
        Double calcWeight4 = 0d;
        if (null != epaIcgeDataVo) {
            String coreGroundCurrent = epaIcgeDataVo.getTotalCoreCurrent();
             calcWeight4 = calc(coreGroundCurrent, EvaluateConstant.ZDXSY_TXJDDL, "铁芯接地电流(mA)", threeLevelMap, jsonArray, step, "变压器绝缘试验-诊断性试验-铁芯接地电流(mA)计算结果");
        }
        Double calcWeight5 = calc(dcleak, EvaluateConstant.ZDXSY_RZZL_XLDL, "绕组直流泄露电流（变化率%）", threeLevelMap, jsonArray, step, "变压器绝缘试验-诊断性试验-绕组直流泄露电流（变化率%）计算结果");

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

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