Browse Source

优化天气返回内容

develop
zhaoxianglong 9 months ago
parent
commit
46f561e456
  1. 263
      zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java

263
zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java

@ -19,14 +19,15 @@ import com.zc.common.core.websocket.WebSocketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import okhttp3.Response;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@ -259,7 +260,7 @@ public class WeatherForecastController extends BaseController {
if (jsonResult.getInteger("code") == UniversalEnum.TWO_HUNDRED.getNumber()) {
JSONArray data = jsonResult.getJSONArray("data");
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < data.size(); i++) {
for (int i = UniversalEnum.ZERO.getNumber(); i < data.size(); i++) {
JSONObject jsonObject = (JSONObject) JSON.toJSON(data.get(i));
String pre = jsonObject.getString("pre");
@ -268,14 +269,14 @@ public class WeatherForecastController extends BaseController {
String visLevel = jsonObject.getString("visLevel");
if (Objects.equals(visLevel, UniversalEnum.ONE.getValue()) || Objects.equals(visLevel, UniversalEnum.TWO.getValue())) {
jsonObject.put("weatherCondition", "晴天");
jsonObject.put("weatherConditionCode", "0");
jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber());
} else if (Objects.equals(visLevel, UniversalEnum.THREE.getValue()) || Objects.equals(visLevel, UniversalEnum.FOUR.getValue())) {
jsonObject.put("weatherCondition", "多云");
jsonObject.put("weatherConditionCode", "1");
jsonObject.put("weatherCondition", UniversalEnum.CLOUDY.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.CLOUDY.getNumber());
} else if (Objects.equals(visLevel, UniversalEnum.FIVE.getValue()) || Objects.equals(visLevel, UniversalEnum.SIX.getValue())) {
jsonObject.put("weatherCondition", "阴天");
jsonObject.put("weatherConditionCode", "2");
jsonObject.put("weatherCondition", UniversalEnum.OVERCAST_SKY.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.OVERCAST_SKY.getNumber());
}
} else {
@ -284,240 +285,120 @@ public class WeatherForecastController extends BaseController {
switch (preLevel) {
case "0":
//if (Objects.equals(pph, UniversalEnum.ONE.getValue())) {
jsonObject.put("weatherCondition", "晴天");
jsonObject.put("weatherConditionCode", "0");
//} else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) {
// jsonObject.put("weatherCondition", "");
// jsonObject.put("weatherConditionCode", "");
//} else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) {
// jsonObject.put("weatherCondition", "");
// jsonObject.put("weatherConditionCode", "");
//} else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) {
// jsonObject.put("weatherCondition", "");
// jsonObject.put("weatherConditionCode", "");
//} else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) {
// jsonObject.put("weatherCondition", "");
// jsonObject.put("weatherConditionCode", "");
//
//}
jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber());
break;
case "1":
case "2":
if (Objects.equals(pph, UniversalEnum.ONE.getValue())) {
jsonObject.put("weatherCondition", "小雨");
jsonObject.put("weatherConditionCode", "3");
jsonObject.put("weatherCondition", UniversalEnum.SPIT.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.SPIT.getNumber());
} else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) {
jsonObject.put("weatherCondition", "雨夹雪");
jsonObject.put("weatherConditionCode", "4");
jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber());
} else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) {
jsonObject.put("weatherCondition", "小雪");
jsonObject.put("weatherConditionCode", "5");
jsonObject.put("weatherCondition", UniversalEnum.LIGHT_SNOW.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.LIGHT_SNOW.getNumber());
} else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) {
jsonObject.put("weatherCondition", "冻雨");
jsonObject.put("weatherConditionCode", "6");
jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber());
} else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) {
jsonObject.put("weatherCondition", "晴天");
jsonObject.put("weatherConditionCode", "0");
jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber());
}
break;
case "3":
if (Objects.equals(pph, UniversalEnum.ONE.getValue())) {
jsonObject.put("weatherCondition", "中雨");
jsonObject.put("weatherConditionCode", "7");
jsonObject.put("weatherCondition", UniversalEnum.MODERATE_RAIN.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.MODERATE_RAIN.getNumber());
} else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) {
jsonObject.put("weatherCondition", "雨夹雪");
jsonObject.put("weatherConditionCode", "4");
jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber());
} else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) {
jsonObject.put("weatherCondition", "中雪");
jsonObject.put("weatherConditionCode", "8");
jsonObject.put("weatherCondition", UniversalEnum.MODERATE_SNOW.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.MODERATE_SNOW.getNumber());
} else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) {
jsonObject.put("weatherCondition", "冻雨");
jsonObject.put("weatherConditionCode", "6");
jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber());
} else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) {
jsonObject.put("weatherCondition", "晴天");
jsonObject.put("weatherConditionCode", "0");
jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber());
}
break;
case "4":
if (Objects.equals(pph, UniversalEnum.ONE.getValue())) {
jsonObject.put("weatherCondition", "大雨");
jsonObject.put("weatherConditionCode", "9");
jsonObject.put("weatherCondition", UniversalEnum.HEAVY_RAIN.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.HEAVY_RAIN.getNumber());
} else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) {
jsonObject.put("weatherCondition", "雨夹雪");
jsonObject.put("weatherConditionCode", "4");
jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber());
} else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) {
jsonObject.put("weatherCondition", "大雪");
jsonObject.put("weatherConditionCode", "10");
jsonObject.put("weatherCondition", UniversalEnum.HEAVY_SNOW.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.HEAVY_SNOW.getNumber());
} else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) {
jsonObject.put("weatherCondition", "冻雨");
jsonObject.put("weatherConditionCode", "6");
jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber());
} else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) {
jsonObject.put("weatherCondition", "晴天");
jsonObject.put("weatherConditionCode", "0");
jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber());
}
break;
case "5":
if (Objects.equals(pph, UniversalEnum.ONE.getValue())) {
jsonObject.put("weatherCondition", "暴雨");
jsonObject.put("weatherConditionCode", "11");
jsonObject.put("weatherCondition", UniversalEnum.RAINSTORM.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.RAINSTORM.getNumber());
} else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) {
jsonObject.put("weatherCondition", "雨夹雪");
jsonObject.put("weatherConditionCode", "4");
jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber());
} else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) {
jsonObject.put("weatherCondition", "暴雪");
jsonObject.put("weatherConditionCode", "12");
jsonObject.put("weatherCondition", UniversalEnum.BLIZZARD.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.BLIZZARD.getNumber());
} else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) {
jsonObject.put("weatherCondition", "冻雨");
jsonObject.put("weatherConditionCode", "6");
jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber());
} else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) {
jsonObject.put("weatherCondition", "晴天");
jsonObject.put("weatherConditionCode", "0");
jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber());
}
break;
case "6":
if (Objects.equals(pph, UniversalEnum.ONE.getValue())) {
jsonObject.put("weatherCondition", "大暴雨");
jsonObject.put("weatherConditionCode", "13");
jsonObject.put("weatherCondition", UniversalEnum.BIG_RAINSTORM.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.BIG_RAINSTORM.getNumber());
} else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) {
jsonObject.put("weatherCondition", "雨夹雪");
jsonObject.put("weatherConditionCode", "4");
jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber());
} else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) {
jsonObject.put("weatherCondition", "大暴雪");
jsonObject.put("weatherConditionCode", "14");
jsonObject.put("weatherCondition", UniversalEnum.BIG_BLIZZARD.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.BIG_BLIZZARD.getNumber());
} else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) {
jsonObject.put("weatherCondition", "冻雨");
jsonObject.put("weatherConditionCode", "6");
jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber());
} else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) {
jsonObject.put("weatherCondition", "晴天");
jsonObject.put("weatherConditionCode", "0");
jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber());
}
break;
case "7":
if (Objects.equals(pph, UniversalEnum.ONE.getValue())) {
jsonObject.put("weatherCondition", "特大暴雨");
jsonObject.put("weatherConditionCode", "15");
jsonObject.put("weatherCondition", UniversalEnum.EXTREMELY_HEAVY_RAINSTORM.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.EXTREMELY_HEAVY_RAINSTORM.getNumber());
} else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) {
jsonObject.put("weatherCondition", "雨夹雪");
jsonObject.put("weatherConditionCode", "4");
jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber());
} else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) {
jsonObject.put("weatherCondition", "特大暴雪");
jsonObject.put("weatherConditionCode", "16");
jsonObject.put("weatherCondition", UniversalEnum.HEAVY_SNOWSTORM.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.HEAVY_SNOWSTORM.getNumber());
} else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) {
jsonObject.put("weatherCondition", "冻雨");
jsonObject.put("weatherConditionCode", "6");
jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber());
} else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) {
jsonObject.put("weatherCondition", "晴天");
jsonObject.put("weatherConditionCode", "0");
jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue());
jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber());
}
break;
}
//if (Objects.equals(preLevel, "0")) {
// if (Objects.equals(pph, "1")) {
//
// }else if (Objects.equals(pph, "2")) {
//
// }else if (Objects.equals(pph, "3")) {
//
// }else if (Objects.equals(pph, "4")) {
//
// }else if (Objects.equals(pph, "0")) {
//
// }
//} else if (Objects.equals(preLevel, "1")) {
//
// if (Objects.equals(pph, "1")) {
//
// }else if (Objects.equals(pph, "2")) {
//
// }else if (Objects.equals(pph, "3")) {
//
// }else if (Objects.equals(pph, "4")) {
//
// }else if (Objects.equals(pph, "0")) {
//
// }
//} else if (Objects.equals(preLevel, "2")) {
//
// if (Objects.equals(pph, "1")) {
//
// }else if (Objects.equals(pph, "2")) {
//
// }else if (Objects.equals(pph, "3")) {
//
// }else if (Objects.equals(pph, "4")) {
//
// }else if (Objects.equals(pph, "0")) {
//
// }
//} else if (Objects.equals(preLevel, "3")) {
//
// if (Objects.equals(pph, "1")) {
//
// }else if (Objects.equals(pph, "2")) {
//
// }else if (Objects.equals(pph, "3")) {
//
// }else if (Objects.equals(pph, "4")) {
//
// }else if (Objects.equals(pph, "0")) {
//
// }
//} else if (Objects.equals(preLevel, "4")) {
//
// if (Objects.equals(pph, "1")) {
//
// }else if (Objects.equals(pph, "2")) {
//
// }else if (Objects.equals(pph, "3")) {
//
// }else if (Objects.equals(pph, "4")) {
//
// }else if (Objects.equals(pph, "0")) {
//
// }
//} else if (Objects.equals(preLevel, "5")) {
//
// if (Objects.equals(pph, "1")) {
//
// }else if (Objects.equals(pph, "2")) {
//
// }else if (Objects.equals(pph, "3")) {
//
// }else if (Objects.equals(pph, "4")) {
//
// }else if (Objects.equals(pph, "0")) {
//
// }
//} else if (Objects.equals(preLevel, "6")) {
//
// if (Objects.equals(pph, "1")) {
//
// }else if (Objects.equals(pph, "2")) {
//
// }else if (Objects.equals(pph, "3")) {
//
// }else if (Objects.equals(pph, "4")) {
//
// }else if (Objects.equals(pph, "0")) {
//
// }
//} else if (Objects.equals(preLevel, "7")) {
//
// if (Objects.equals(pph, "1")) {
//
// }else if (Objects.equals(pph, "2")) {
//
// }else if (Objects.equals(pph, "3")) {
//
// }else if (Objects.equals(pph, "4")) {
//
// }else if (Objects.equals(pph, "0")) {
//
// }
//}
}
jsonArray.add(i,jsonObject);
};

Loading…
Cancel
Save