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

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

import java.util.Map;

/**
 * @version V1.0
 * @ClassName: TransformerHighVoltageBushing
 * @Description: 变压器附件-变压器高压套管.
 * @Author: Arno
 * @Date: 2023/10/10 15:52
 */
@Slf4j
public class TransformerHighVoltageBushing {


    public static Map<String, Object> calcHighVoltageWeight(TransformerEvaluateDataVo transformerEvaluateDataVo, Map<String, BusiParamTransformerVo> secondLevelMap,
                                                            Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step,
                                                            EpaInfraredMonitorDataVo epaInfraredMonitorDataVo,
                                                            EpaCapacitanceDataVo epaCapacitanceDataVo) {
        BusiParamTransformerVo secondVo = CommonUtils.getEvaluateObject(EvaluateConstant.BYQ_TG, secondLevelMap);
        if (null != secondVo) {
            if (CommonUtils.checkAttend(secondVo)) {
                Map<String, Object> threeResultMap = calcThree(transformerEvaluateDataVo, threeLevelMap, jsonArray, step, epaInfraredMonitorDataVo, epaCapacitanceDataVo);
                return CommonUtils.calcSecond(secondVo, threeResultMap, jsonArray, "变压器附件-变压器高压套管权重计算");
            }
        }
        log.error("-->变压器附件变压器高压套未设置评估参数");
        return null;
    }


    public static Map<String, Object> calcThree(TransformerEvaluateDataVo vo, Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step,
                                                EpaInfraredMonitorDataVo epaInfraredMonitorDataVo,
                                                EpaCapacitanceDataVo epaCapacitanceDataVo) {

        //容性电流
        String capacitiveCurrent = vo.getCapacitiveCurrent();
        //末屏绝缘电阻
        String endScreenInsulationResistance = vo.getEndScreenInsulationResistance();
        //阻性电流
        String resistiveCurrent = vo.getResistiveCurrent();

        //末屏介损
        String endScreenDielectricDamage = vo.getEndScreenDielectricDamage();
        //末屏绝缘电容
        String finalScreenInsulationCapacitance = vo.getFinalScreenInsulationCapacitance();
        //套管介损
        String casingDielectricLoss = vo.getCasingDielectricLoss();
        //套管H2
        String casingH2 = vo.getCasingH2();
        //套管CH4
        String casingCh4 = vo.getCasingCh4();
        //套管C2H2
        String casingC2h2 = vo.getCasingC2h2();

        Double calcWeight = calc(endScreenInsulationResistance, EvaluateConstant.BYQ_TG_MPJYDZ, "末屏绝缘电阻（MΩ）", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-末屏绝缘电阻（MΩ）计算结果");
        Double calcWeight2 = 0d;
        Double calcWeight12 = 0d;
        if (null != epaCapacitanceDataVo) {
            //全电流
            String totalCurrent = epaCapacitanceDataVo.getTotalCurrent();
            //电容量
            String capacitance = epaCapacitanceDataVo.getCapacitance();
            calcWeight2 = calc(totalCurrent, EvaluateConstant.BYQ_TG_QDL, "全电流(mA)", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-全电流(mA)计算结果");
            calcWeight12 = calc(capacitance, EvaluateConstant.BYQ_TG_MPJYDR, "电容量", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-电容量计算结果");
        }

        Double calcWeight3 = calc(capacitiveCurrent, EvaluateConstant.BYQ_TG_RXDL, "容性电流(mA)", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-容性电流(mA)计算结果");
        Double calcWeight4 = calc(resistiveCurrent, EvaluateConstant.BYQ_TG_ZXDL, "阻性电流(mA)", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-阻性电流(mA)计算结果");
        Double calcWeight5 = 0d;
        if (null != epaInfraredMonitorDataVo) {
            // 红外温度 在线数据
            String infraredTemperature = epaInfraredMonitorDataVo.getAvgTemp();
            calcWeight5 = calc(infraredTemperature, EvaluateConstant.BYQ_TG_HWWD, "红外温度(℃)", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-外温度(℃)计算结果");
        }

        Double calcWeight6 = calc(endScreenDielectricDamage, EvaluateConstant.BYQ_TG_MPJS, "末屏介损(tgδ)", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-末屏介损(tgδ)计算结果");

        Double calcWeight7 = calc(finalScreenInsulationCapacitance, EvaluateConstant.BYQ_TG_MPJYDR, "末屏绝缘电容（pF）", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-末屏绝缘电容（pF）计算结果");
        Double calcWeight8 = calc(casingDielectricLoss, EvaluateConstant.BYQ_TG_TGJS, "套管介损-例行试验(tgδ)", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-套管介损-例行试验(tgδ)计算结果");
        Double calcWeight9 = calc(casingH2, EvaluateConstant.BYQ_TG_TGH2, "套管H2(μL/L)", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-套管H2(μL/L)计算结果");

        Double calcWeight10 = calc(casingCh4, EvaluateConstant.BYQ_TG_TGCH4, "套管CH4(μL/L)", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-管CH4(μL/L)计算结果");
        Double calcWeight11 = calc(casingC2h2, EvaluateConstant.BYQ_TG_TGC2H2, "套管C2H2(μL/L)", threeLevelMap, jsonArray, step, "变压器附件-变压器高压套管-套管C2H2(μL/L)计算结果");

        Double total = calcWeight + calcWeight2 + calcWeight3 +
                calcWeight4 + calcWeight5 + calcWeight6 +
                calcWeight7 + calcWeight8 + calcWeight9 +
                calcWeight10 + calcWeight11+calcWeight12;
        log.info("-->>变压器附件-变压器高压套管-分项和计算结果: [{}]", total);
        step += 1;
        return CommonUtils.buildResult(step, total);
    }

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