package com.yuchen.saas.park.service.util;


import com.yuchen.saas.park.api.enums.WindDirectEnum;

/**
 * @Author 任业政
 * @Date 2021/8/27 14:39
 * @Description 室外风向、室外风速等级、的转换
 */
public class WindSwitchUtils {


    /**
     * 风向信息
     */
    private static final String NE = "东北风";

    private static final String EAST = "东风";

    private static final String SE = "东南风";

    private static final String SOUTH = "南风";

    private static final String SW = "西南风";

    private static final String WEST = "西风";

    private static final String NW = "西北风";

    private static final String NORTH = "北风";


    /**
     * 风速级别信息
     */
    private static final String ONE_LEVEL = "1";

    private static final String TWO_LEVEL = "2";

    private static final String THREE_LEVEL = "3";

    private static final String FOUR_LEVEL = "4";

    private static final String FIVE_LEVEL = "5";

    private static final String SIX_LEVEL = "6";

    private static final String SEVEN_LEVEL = "7";

    private static final String EIGHT_LEVEL = "8";

    private static final String NINE_LEVEL = "9";

    private static final String TEN_LEVEL = "10";

    private static final String ELEVEN_LEVEL = "11";

    private static final String TWELVE_LEVEL = "12";

    private static final String THIRTEEN_LEVEL = "13";

    /**
     * 土壤酸碱度 PH
     */
    private static final String ONE_PH = "6";

    private static final String TWO_PH = "4";

    private static final String THREE_PH = "2";

    private static final String FOUR_PH = "1";

    private static final String FIVE_PH = "3";

    private static final String SIX_PH = "5";

    private static final String SEVEN_PH = "7";

    /**
     * 降雨量
     */
    private static final String ONE_RAIN = "1";

    private static final String TWO_RAIN = "2";

    private static final String THREE_RAIN = "3";

    private static final String FOUR_RAIN = "4";

    private static final String FIVE_RAIN = "5";

    private static final String SIX_RAIN = "6";

    private static final String SEVEN_RAIN = "7";


    /**
     * 湿度
     */
    private static final String ONE_DRY = "1";

    private static final String TWO_DRY = "2";

    private static final String THREE_DRY = "3";


    /**
     * PM25
     */
    private static final String ONE_PM25 = "1";

    private static final String TWO_PM25 = "2";

    private static final String THREE_PM25 = "3";

    private static final String FOUR_PM25 = "4";

    private static final String FIVE_PM25 = "5";

    private static final String SIX_PM25 = "6";

    /**
     * PM10
     */
    private static final String ONE_PM10 = "1";

    private static final String TWO_PM10 = "2";

    private static final String THREE_PM10 = "3";

    /**
     * 噪音
     */
    private static final String ONE_NOISE = "1";

    private static final String TWO_NOISE = "2";

    private static final String THREE_NOISE = "3";

    private static final String FOUR_NOISE = "4";


    /**
     * 室内外温度
     */
    private static final String ONE_TEMP = "1";

    private static final String TWO_TEMP = "2";

    private static final String THREE_TEMP = "3";

    private static final String FOUR_TEMP = "4";

    private static final String FIVE_TEMP = "5";

    private static final String SIX_TEMP = "6";

    private static final String SEVEN_TEMP = "7";

    /**
     * 风向转换    0-360°   90°->西北风
     * @param value 对应的值
     * @return 转换后的值
     */
    public static String getWindDirection(Double value) {

        long val = Double.doubleToLongBits(value);

         //1.东北风
        if(val >= Double.doubleToLongBits(WindDirectEnum.NE_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.NE_END.getValue())){
            return NE;
        }

        //2.东风
        if(val >= Double.doubleToLongBits(WindDirectEnum.EAST_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.EAST_END.getValue())){
            return EAST;
        }

        //3.东南风
        if(val >= Double.doubleToLongBits(WindDirectEnum.SE_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.SE_END.getValue())){
            return SE;
        }

        //4.南风
        if(val >= Double.doubleToLongBits(WindDirectEnum.SOUTH_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.SOUTH_END.getValue())){
            return SOUTH;
        }

        //5.西南风
        if(val >= Double.doubleToLongBits(WindDirectEnum.SW_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.SW_END.getValue())){
            return SW;
        }

        //6.西风
        if(val >= Double.doubleToLongBits(WindDirectEnum.WEST_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.WEST_END.getValue())){
            return WEST;
        }

        //7.西北风
        if(val >= Double.doubleToLongBits(WindDirectEnum.NW_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.NW_END.getValue())){
            return NW;
        }

        return NORTH;
    }


    /**
     * 根据风速匹配风速级别
     * @param value 室外风速 ： 30m/s
     * @return
     */
    public static String getWindLevel(Double value){

        long val = Double.doubleToLongBits(value);

        //1.无风
        if(val <= Double.doubleToLongBits(WindDirectEnum.START_LEVEL.getValue())){
            return ONE_LEVEL;
        }

        //2.软风
        if(val >= Double.doubleToLongBits(WindDirectEnum.ONE_LEVEL_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.ONE_LEVEL_END.getValue())){
            return TWO_LEVEL;
        }

        //3.轻风
        if(val >= Double.doubleToLongBits(WindDirectEnum.TWO_LEVEL_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.TWO_LEVEL_END.getValue())){
            return THREE_LEVEL;
        }

        //4.微风
        if(val >= Double.doubleToLongBits(WindDirectEnum.THREE_LEVEL_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.THREE_LEVEL_END.getValue())){
            return FOUR_LEVEL;
        }

        //5.和风
        if(val >= Double.doubleToLongBits(WindDirectEnum.FOUR_LEVEL_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.FOUR_LEVEL_END.getValue())){
            return FIVE_LEVEL;
        }

        //6.清劲风
        if(val >= Double.doubleToLongBits(WindDirectEnum.FIVE_LEVEL_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.FIVE_LEVEL_END.getValue())){
            return SIX_LEVEL;
        }

        //7.强风
        if(val >= Double.doubleToLongBits(WindDirectEnum.SIX_LEVEL_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.SIX_LEVEL_END.getValue())){
            return SEVEN_LEVEL;
        }

        //8.疾风
        if(val >= Double.doubleToLongBits(WindDirectEnum.SEVEN_LEVEL_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.SEVEN_LEVEL_END.getValue())){
            return EIGHT_LEVEL;
        }

        //9.大风
        if(val >= Double.doubleToLongBits(WindDirectEnum.EIGHT_LEVEL_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.EIGHT_LEVEL_END.getValue())){
            return NINE_LEVEL;
        }

        //10.烈风
        if(val >= Double.doubleToLongBits(WindDirectEnum.NINE_LEVEL_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.NINE_LEVEL_END.getValue())){
            return TEN_LEVEL;
        }

        //11.狂风
        if(val >= Double.doubleToLongBits(WindDirectEnum.TEN_LEVEL_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.TEN_LEVEL_END.getValue())){
            return ELEVEN_LEVEL;
        }

        //11.暴风
        if(val >= Double.doubleToLongBits(WindDirectEnum.ELEVEN_LEVEL_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.ELEVEN_LEVEL_END.getValue())){
            return TWELVE_LEVEL;
        }

        return THIRTEEN_LEVEL;
    }

    /**
     * 土壤酸碱度 等级
     * @param value
     * @return
     */
    public static String getPhLevel(Double value){

        long val = Double.doubleToLongBits(value);

        // 1.极强酸性
        if(val < Double.doubleToLongBits(WindDirectEnum.START_PH.getValue())){
            return ONE_PH;
        }

        //2.强酸性
        if(val >= Double.doubleToLongBits(WindDirectEnum.ONE_PH_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.ONE_PH_END.getValue())){
            return TWO_PH;
        }

        //3.酸性
        if(val >= Double.doubleToLongBits(WindDirectEnum.TWO_PH_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.TWO_PH_END.getValue())){
            return THREE_PH;
        }

        //4.中性
        if(val >= Double.doubleToLongBits(WindDirectEnum.THREE_PH_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.THREE_PH_END.getValue())){
            return FOUR_PH;
        }

        //5.碱性
        if(val >= Double.doubleToLongBits(WindDirectEnum.FOUR_PH_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.FOUR_PH_END.getValue())){
            return FIVE_PH;
        }

        //6.强碱性
        if(val >= Double.doubleToLongBits(WindDirectEnum.FIVE_PH_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.FIVE_PH_END.getValue())){
            return SIX_PH;
        }

        return SEVEN_PH;
    }


    /**
     * 降雨 等级
     * @param value
     * @return
     */
    public static String getRainLevel(Double value){

        long val = Double.doubleToLongBits(value);

        // 1.无雨
        if(val <= Double.doubleToLongBits(WindDirectEnum.START_RAIN.getValue())){
            return ONE_RAIN;
        }

        //2.小雨
        if(val >= Double.doubleToLongBits(WindDirectEnum.ONE_RAIN_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.ONE_RAIN_END.getValue())){
            return TWO_RAIN;
        }

        //3.中雨
        if(val >= Double.doubleToLongBits(WindDirectEnum.TWO_RAIN_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.TWO_RAIN_END.getValue())){
            return THREE_RAIN;
        }

        //4.大雨
        if(val >= Double.doubleToLongBits(WindDirectEnum.THREE_RAIN_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.THREE_RAIN_END.getValue())){
            return FOUR_RAIN;
        }

        //5.暴雨
        if(val >= Double.doubleToLongBits(WindDirectEnum.FOUR_RAIN_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.FOUR_RAIN_END.getValue())){
            return FIVE_RAIN;
        }

        //6.大暴雨
        if(val >= Double.doubleToLongBits(WindDirectEnum.FIVE_RAIN_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.FIVE_RAIN_END.getValue())){
            return SIX_RAIN;
        }

        return SEVEN_RAIN;
    }


    /**
     * 湿度 等级
     * @param value
     * @return
     */
    public static String getHumidityLevel(Double value){

        long val = Double.doubleToLongBits(value);

        // 1.干燥
        if(val < Double.doubleToLongBits(WindDirectEnum.START_HU.getValue())){
            return ONE_DRY;
        }

        //2.适宜
        if(val >= Double.doubleToLongBits(WindDirectEnum.START_HU.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.ONE_HU.getValue())){
            return TWO_DRY;
        }

        return THREE_DRY;
    }

    /**
     * 【室外pm2.5】：优：0~35μg/m³、良：35~75μg/m³、轻度污染：75~115μg/m³、中度污染：115~150μg/m³、重度污染：150~250μg/m³、严重污染：大于250μg/m³及以上
     * @param value
     * @return
     */
    public static String getPm25Level(Double value){

        long val = Double.doubleToLongBits(value);

        // 1.优
        if(val <= Double.doubleToLongBits(WindDirectEnum.START_PM25.getValue())){
            return ONE_PM25;
        }

        //2.良
        if(val >= Double.doubleToLongBits(WindDirectEnum.ONE_PM25_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.ONE_PM25_END.getValue())){
            return TWO_PM25;
        }

        //3.轻度污染
        if(val >= Double.doubleToLongBits(WindDirectEnum.TWO_PM25_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.TWO_PM25_END.getValue())){
            return THREE_PM25;
        }

        //4.中度污染
        if(val >= Double.doubleToLongBits(WindDirectEnum.THREE_PM25_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.THREE_PM25_END.getValue())){
            return FOUR_PM25;
        }

        //5.重度污染
        if(val >= Double.doubleToLongBits(WindDirectEnum.FOUR_PM25_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.FOUR_PM25_END.getValue())){
            return FIVE_PM25;
        }

        return SIX_PM25;
    }

    /**
     * 【室外pm10】：正常：低于50ug/m³、轻微污染：50-150ug/m³、严重污染：150ug/m³以上；
     * @param value
     * @return
     */
    public static String getPm10Level(Double value){

        long val = Double.doubleToLongBits(value);

        // 1.正常
        if(val <= Double.doubleToLongBits(WindDirectEnum.START_PM10.getValue())){
            return ONE_PM10;
        }

        //2.轻微污染
        if(val >= Double.doubleToLongBits(WindDirectEnum.ONE_PM10_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.ONE_PM10_END.getValue())){
            return TWO_PM10;
        }

        return THREE_PM10;
    }

    /**
     * 【室外噪音】：无噪音：低于30db、轻微噪音：30～59db、中度噪音：60～89db、严重噪音：90～120db
     * @param value
     * @return
     */
    public static String getNoiseLevel(Double value){

        long val = Double.doubleToLongBits(value);

        // 1.无噪音
        if(val <= Double.doubleToLongBits(WindDirectEnum.START_NOISE.getValue())){
            return ONE_NOISE;
        }

        //2.轻微噪音
        if(val >= Double.doubleToLongBits(WindDirectEnum.ONE_NOISE_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.ONE_NOISE_END.getValue())){
            return TWO_NOISE;
        }

        //3.中度噪音
        if(val >= Double.doubleToLongBits(WindDirectEnum.TWO_NOISE_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.TWO_NOISE_END.getValue())){
            return THREE_NOISE;
        }
        return FOUR_NOISE;
    }

    /**
     * 【室内外温度】：0度以下：严寒、0-9度：寒冷、10-18度：凉爽、19-24度：舒适、25-29度：温暖、30-36度：炎热、36度以上：酷热
     * @param value
     * @return
     */
    public static String getTempLevel(Double value){

        long val = Double.doubleToLongBits(value);

        // 1.严寒
        if(val <= Double.doubleToLongBits(WindDirectEnum.START_TEMP.getValue())){
            return ONE_TEMP;
        }

        //2.寒冷
        if(val >= Double.doubleToLongBits(WindDirectEnum.ONE_TEMP_START.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.ONE_TEMP_END.getValue())){
            return TWO_TEMP;
        }

        //3.凉爽
        if(val >= Double.doubleToLongBits(WindDirectEnum.TWO_TEMP_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.TWO_TEMP_END.getValue())){
            return THREE_TEMP;
        }

        //4.舒适
        if(val >= Double.doubleToLongBits(WindDirectEnum.THREE_TEMP_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.THREE_TEMP_END.getValue())){
            return FOUR_TEMP;
        }

        //5.温暖
        if(val >= Double.doubleToLongBits(WindDirectEnum.FOUR_TEMP_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.FOUR_TEMP_END.getValue())){
            return FIVE_TEMP;
        }

        //5.炎热
        if(val >= Double.doubleToLongBits(WindDirectEnum.FIVE_TEMP_BEGIN.getValue()) && val <= Double.doubleToLongBits(WindDirectEnum.FIVE_TEMP_END.getValue())){
            return SIX_TEMP;
        }
        return SEVEN_TEMP;
    }
}
