From 1833fa7eb9309fff6f1816a3c755566a7cdc2c05 Mon Sep 17 00:00:00 2001 From: zhaoxianglong Date: Mon, 8 Jul 2024 08:44:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=A9=E6=B0=94=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WeatherForecastController.java | 273 +++++++++++++++++- 1 file changed, 267 insertions(+), 6 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java b/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java index 7c5a0dfc..ed89e427 100644 --- a/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java +++ b/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java @@ -19,6 +19,7 @@ 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.*; @@ -257,13 +258,273 @@ public class WeatherForecastController extends BaseController { JSONObject jsonResult = JSONObject.parseObject(response.body().string()); if (jsonResult.getInteger("code") == UniversalEnum.TWO_HUNDRED.getNumber()) { JSONArray data = jsonResult.getJSONArray("data"); - //data.forEach(item->{ - // - //}); - if (data.size() != UniversalEnum.ZERO.getNumber()) { + JSONArray jsonArray = new JSONArray(); + for (int i = 0; i < data.size(); i++) { + + JSONObject jsonObject = (JSONObject) JSON.toJSON(data.get(i)); + String pre = jsonObject.getString("pre"); + if (Objects.equals(pre, UniversalEnum.ZERO.getValue())) { + + 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"); + } else if (Objects.equals(visLevel, UniversalEnum.THREE.getValue()) || Objects.equals(visLevel, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", "多云"); + jsonObject.put("weatherConditionCode", "1"); + } else if (Objects.equals(visLevel, UniversalEnum.FIVE.getValue()) || Objects.equals(visLevel, UniversalEnum.SIX.getValue())) { + jsonObject.put("weatherCondition", "阴天"); + jsonObject.put("weatherConditionCode", "2"); + } + } else { + + String preLevel = jsonObject.getString("preLevel"); + String pph = jsonObject.getString("pph"); + + 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", ""); + // + //} + break; + case "1": + case "2": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", "小雨"); + jsonObject.put("weatherConditionCode", "3"); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", "雨夹雪"); + jsonObject.put("weatherConditionCode", "4"); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", "小雪"); + jsonObject.put("weatherConditionCode", "5"); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", "冻雨"); + jsonObject.put("weatherConditionCode", "6"); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", "晴天"); + jsonObject.put("weatherConditionCode", "0"); + } + break; + case "3": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", "中雨"); + jsonObject.put("weatherConditionCode", "7"); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", "雨夹雪"); + jsonObject.put("weatherConditionCode", "4"); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", "中雪"); + jsonObject.put("weatherConditionCode", "8"); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", "冻雨"); + jsonObject.put("weatherConditionCode", "6"); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", "晴天"); + jsonObject.put("weatherConditionCode", "0"); + } + break; + case "4": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", "大雨"); + jsonObject.put("weatherConditionCode", "9"); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", "雨夹雪"); + jsonObject.put("weatherConditionCode", "4"); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", "大雪"); + jsonObject.put("weatherConditionCode", "10"); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", "冻雨"); + jsonObject.put("weatherConditionCode", "6"); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", "晴天"); + jsonObject.put("weatherConditionCode", "0"); + } + break; + case "5": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", "暴雨"); + jsonObject.put("weatherConditionCode", "11"); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", "雨夹雪"); + jsonObject.put("weatherConditionCode", "4"); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", "暴雪"); + jsonObject.put("weatherConditionCode", "12"); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", "冻雨"); + jsonObject.put("weatherConditionCode", "6"); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", "晴天"); + jsonObject.put("weatherConditionCode", "0"); + } + break; + case "6": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", "大暴雨"); + jsonObject.put("weatherConditionCode", "13"); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", "雨夹雪"); + jsonObject.put("weatherConditionCode", "4"); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", "大暴雪"); + jsonObject.put("weatherConditionCode", "14"); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", "冻雨"); + jsonObject.put("weatherConditionCode", "6"); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", "晴天"); + jsonObject.put("weatherConditionCode", "0"); + } + break; + case "7": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", "特大暴雨"); + jsonObject.put("weatherConditionCode", "15"); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", "雨夹雪"); + jsonObject.put("weatherConditionCode", "4"); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", "特大暴雪"); + jsonObject.put("weatherConditionCode", "16"); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", "冻雨"); + jsonObject.put("weatherConditionCode", "6"); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", "晴天"); + jsonObject.put("weatherConditionCode", "0"); + } + 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); + }; + if (jsonArray.size() != UniversalEnum.ZERO.getNumber()) { redisCache.deleteObject("currentWeatherAndForecastInformation" + numStake); - redisCache.setCacheObject("currentWeatherAndForecastInformation" + numStake, data); - return AjaxResult.success(data); + redisCache.setCacheObject("currentWeatherAndForecastInformation" + numStake, jsonArray); + return AjaxResult.success(jsonArray); } else { JSONArray cacheObject = redisCache.getCacheObject("currentWeatherAndForecastInformation" + numStake); return AjaxResult.success(cacheObject);