package com.gyee.wisdom.xfai.net3.service;

import com.gyee.wisdom.xfai.net3.utils.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

@Service
public class WeatherService {
    @Resource
    private RedisUtil redisUtil;

    public String redisget(String key){
        return redisUtil.get(key);
    }
    public String getWeather(String info){
        HashMap<String,String> weather=new HashMap<>();
        weather.put("01d","晴朗");
        weather.put("01n","晴朗");
        weather.put("02d","少云");
        weather.put("02n","少云");
        weather.put("03d","多云");
        weather.put("03n","多云");
        weather.put("04d","阴");
        weather.put("04n","阴");
        weather.put("09d","阵雨");
        weather.put("09n","阵雨");
        weather.put("10d","小雨");
        weather.put("10n","小雨");
        weather.put("11d","雷阵雨");
        weather.put("11n","雷阵雨");
        weather.put("13d","小雪");
        weather.put("13n","小雪");
        weather.put("50d","有雾");
        weather.put("50n","有雾");

        if(weather.containsKey(info)){
            return weather.get(info);
        }else{
            return info;
        }
    }
    public String getStation(String info){
        HashMap<String,String> station=new HashMap<>();
        station.put("MHS","MHS_FDC_WEATHER_WEATHER");
        station.put("NSS","NSS_FDC_WEATHER_WEATHER");
        station.put("QS","QS_FDC_WEATHER_WEATHER");
        station.put("SBQ","SBQ_FDC_WEATHER_WEATHER");
        station.put("XS","XS_FDC_WEATHER_WEATHER");
        station.put("DWK","DWK_GDC_WEATHER_WEATHER");
        station.put("PL","PL_GDC_WEATHER_WEATHER");
        station.put("XH","XH_GDC_WEATHER_WEATHER");
        station.put("YC","NX_QYGS_WEATHER_WEATHER");
        station.put("MCH","MCH_GDC_WEATHER_WEATHER");

        if(station.containsKey(info)){
            return station.get(info);
        }else{
            return info;
        }
    }
    public String getStation7(String info){
        HashMap<String,String> station=new HashMap<>();
        station.put("MHS","MHS_FDC_WEATHER_ONECALL");
        station.put("NSS","NSS_FDC_WEATHER_ONECALL");
        station.put("QS","QS_FDC_WEATHER_ONECALL");
        station.put("SBQ","SBQ_FDC_WEATHER_ONECALL");
        station.put("XS","XS_FDC_WEATHER_ONECALL");
        station.put("DWK","DWK_GDC_WEATHER_ONECALL");
        station.put("PL","PL_GDC_WEATHER_ONECALL");
        station.put("XH","XH_GDC_WEATHER_ONECALL");
        station.put("YC","NX_QYGS_WEATHER_ONECALL");
        station.put("MCH","MCH_GDC_WEATHER_ONECALL");

        if(station.containsKey(info)){
            return station.get(info);
        }else{
            return info;
        }
    }
    public String getIrradiance(String info){
        HashMap<String,String> station=new HashMap<>();
        station.put("DWK","DWKGGL.NX_GD_DWKG_YC_P1_L1_001_QXZ001");
        station.put("PL","PLGGL.NX_GD_PLG_YC_P1_L1_001_QXZ0001");
        station.put("XH","XHGGL.NX_GD_XHG_YC_P1_L1_001_QXZ001");
        station.put("MCH","MCHGGL.NX_GD_MCHG_YC_P1_L1_001_QXZ0001");

        if(station.containsKey(info)){
            return station.get(info);
        }else{
            return info;
        }
    }
    public String getWindSpeeds(String info){
        HashMap<String,String> station=new HashMap<>();
        station.put("MHS","MHSFCJSFW.NX_GD_MHSF_XX_XX_XXX_XXX_CI0134");
        station.put("NSS","NSSFCJSFW.NX_GD_NSSF_XX_XX_XXX_XXX_CI0134");
        station.put("QS","QSFCJSFW.NX_GD_QSF_XX_XX_XXX_XXX_CI0134");
        station.put("SBQ","SBQFCJSFW.NX_GD_SBQF_XX_XX_XXX_XXX_CI0134");
        station.put("XS","XSFCJSFW.NX_GD_XSF_XX_XX_XXX_XXX_CI0134");

        if(station.containsKey(info)){
            return station.get(info);
        }else{
            return info;
        }
    }
    public String getWindDirection(double fx){
        HashMap<String,String> map=new HashMap<>();
        if(fx>= 33.76 && fx<= 56.25)
        {
            map.put("fx","东北");
        }else if(fx>= 78.76 && fx<= 101.25)
        {
            map.put("fx","东");
        }else if(fx>= 123.76 && fx<= 146.25)
        {
            map.put("fx","东南");
        }else if(fx>= 168.76 && fx<= 191.25)
        {
            map.put("fx","南");
        }else if(fx>= 213.76 && fx<= 236.25)
        {
            map.put("fx","西南");
        }else if(fx>= 258.76 && fx<= 281.25)
        {
            map.put("fx","西");
        }else if(fx>= 303.76 && fx<= 326.25)
        {
            map.put("fx","西北");
        }else if(fx<= 11.25 && fx>= 348.76)
        {
            map.put("fx","北");
        }

        if(map.containsKey("fx")){
            return map.get("fx");
        }else{
            return "";
        }
    }
}
