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

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

import java.util.Map;

/**
 * @version V1.0
 * @ClassName: TransformerCoolingSystem
 * @Description: 变压器附件-变压器冷却系统.
 * @Author: Arno
 * @Date: 2023/10/10 14:58
 */
@Slf4j
public class TransformerCoolingSystem {


    public static Map<String, Object> calcTransformerCoolingWeight(TransformerEvaluateDataVo transformerEvaluateDataVo, Map<String, BusiParamTransformerVo> secondLevelMap,
                                                                   Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step,
                                                                   EpaRunStatusDataVo runStatusEvaluateData,
                                                                   EpaEnvironmentDataVo epaEnvironmentDataVo) {
        BusiParamTransformerVo secondVo = CommonUtils.getEvaluateObject(EvaluateConstant.BYQ_LQXT, secondLevelMap);
        if (null != secondVo) {
            if (CommonUtils.checkAttend(secondVo)) {
                Map<String, Object> threeResultMap = calcThree(transformerEvaluateDataVo, threeLevelMap, jsonArray, step, runStatusEvaluateData, epaEnvironmentDataVo);
                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,
                                                EpaRunStatusDataVo runStatusEvaluateData,
                                                EpaEnvironmentDataVo epaEnvironmentDataVo) {
//        //水压
//        String waterPressure = vo.getWaterPressure();
//        //水温(℃)
//        String waterTemperature = vo.getWaterTemperature();
//        //环境温度(℃)
//        String environmentTemperature = vo.getEnvironmentTemperature();


        //风机损坏检修次数
        String maintenanceCount = vo.getMaintenanceCount();
        Double calcWeight =0d;
        Double calcWeight2 =0d;
        Double calcWeight3 =0d;
        if(null !=  runStatusEvaluateData){
            String waterPressure = runStatusEvaluateData.getExitPressure();
            String waterTemperature = runStatusEvaluateData.getOutletTemperature();
             calcWeight = calc(waterPressure, EvaluateConstant.BYQ_LQXT_SY, "水压", threeLevelMap, jsonArray, step, "变压器附件-变压器冷却系统-水压量计算结果");
             calcWeight2 = calc(waterTemperature, EvaluateConstant.BYQ_LQXT_SW, "水温(℃)", threeLevelMap, jsonArray, step, "变压器附件-变压器冷却系统-水温(℃)计算结果");
        }
        if(null !=  epaEnvironmentDataVo){
            String environmentTemperature = epaEnvironmentDataVo.getTemperature();
             calcWeight3 = calc(environmentTemperature, EvaluateConstant.BYQ_LQXT_HJWD, "环境温度(℃)", threeLevelMap, jsonArray, step, "变压器附件-变压器冷却系统-/环境温度(℃)计算结果");
        }

        Double calcWeight4 = calc(maintenanceCount, EvaluateConstant.BYQ_LQXT_FJSHJXCS, "风机损坏检修次数", threeLevelMap, jsonArray, step, "变压器附件-变压器冷却系统-风机损坏检修次数计算结果");

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

}
