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

import java.util.Map;

/**
 * @version V1.0
 * @ClassName: TransformerBody
 * @Description: 变压器附件-变压器器身.
 * @Author: Arno
 * @Date: 2023/10/10 13:47
 */
@Slf4j
public class TransformerBody {



    public static Map<String, Object> calcTransformerBodyWeight(TransformerEvaluateDataVo transformerEvaluateDataVo, Map<String, BusiParamTransformerVo> secondLevelMap,
                                                                 Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step,
                                                                EpaSoundVibrationVo soundEvaluateData) {
        //二级类型
        BusiParamTransformerVo secondVo = CommonUtils.getEvaluateObject(EvaluateConstant.BYQ_BT, secondLevelMap);
        if (null != secondVo) {
            if (CommonUtils.checkAttend(secondVo)) {
                Map<String, Object> threeResultMap = calcThree(transformerEvaluateDataVo, threeLevelMap, jsonArray, step,soundEvaluateData);
                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,EpaSoundVibrationVo soundEvaluateData) {
        //油位下降(%)
        String oilLevelDrop = vo.getOilLevelDrop();
        //漏油次数
        String oilLeaksCount = vo.getOilLeaksCount();
//        //变压器噪声(dB)
//        String transformerNoise = vo.getTransformerNoise();

        Double calcWeight3 =0d;
        if(null != soundEvaluateData){
            String transformerNoise = soundEvaluateData.getNoisePoint();
             calcWeight3 = calc(transformerNoise, EvaluateConstant.BYQ_BT_BYQZS, "变压器噪声(dB)", threeLevelMap, jsonArray, step, "变压器附件-变压器器身-变压器噪声(dB)计算结果");
        }
        Double calcWeight = calc(oilLevelDrop, EvaluateConstant.BYQ_BT_YWXJ, "油位下降(%)", threeLevelMap, jsonArray, step, "变压器附件-变压器器身-油位下降(%)量计算结果");
        Double calcWeight2 = calc(oilLeaksCount, EvaluateConstant.BYQ_BT_LYCS, "漏油次数", threeLevelMap, jsonArray, step, "变压器附件-变压器器身-漏油次数计算结果");


        Double zdsy = calcWeight + calcWeight2 + calcWeight3;
        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;
    }

}
