|
@@ -21,6 +21,9 @@ import java.util.*;
|
|
|
@Component
|
|
|
public class TaskWeatherGather {
|
|
|
|
|
|
+ private static final String[] directArr = new String[] { "北", "东北偏北", "东北", "东北偏东", "东", "东南偏东", "东南", "东南偏南", "南",
|
|
|
+ "西南偏南", "西南", "西南偏西", "西", "西北偏西", "西北", "西北偏北" };
|
|
|
+
|
|
|
//默认预测数据 40 天
|
|
|
private int days = 40;
|
|
|
public static Map<Integer, String> wp_map = new HashMap<>();
|
|
@@ -43,7 +46,7 @@ public class TaskWeatherGather {
|
|
|
* 每天凌晨1点执行一次
|
|
|
*/
|
|
|
@Scheduled(cron = "0 0 1 * * ?")
|
|
|
-// @Scheduled(initialDelay = 30 * 1000, fixedRate = 2 * 86400 * 1000)
|
|
|
+ //@Scheduled(initialDelay = 30 * 1000, fixedRate = 2 * 86400 * 1000)
|
|
|
public void gatherTask() {
|
|
|
for (int key : wp_map.keySet()) {
|
|
|
String[] value = wp_map.get(key).split("#");
|
|
@@ -69,14 +72,14 @@ public class TaskWeatherGather {
|
|
|
weatherfd.setTemperature1(new BigDecimal(list.get(0).getTemperature()).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
|
|
|
weatherfd.setRealfeel1(new BigDecimal(list.get(0).getTemperature()).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
|
|
|
weatherfd.setPrecipitation1(0.0);
|
|
|
- weatherfd.setWinddirection1(String.valueOf(new BigDecimal(list.get(0).getWindDir()).setScale(2, RoundingMode.HALF_EVEN).doubleValue()));
|
|
|
+ weatherfd.setWinddirection1(windDirectionSwitch(list.get(0).getWindDir()));
|
|
|
weatherfd.setSpeed1(new BigDecimal(list.get(0).getWindSpeed() * 2).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
|
|
|
weatherfd.setGust1(new BigDecimal(list.get(0).getWindSpeed()).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
|
|
|
//夜间
|
|
|
weatherfd.setTemperature2(new BigDecimal(list.get(list.size() - 1).getTemperature()).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
|
|
|
weatherfd.setRealfeel2(new BigDecimal(list.get(list.size() - 1).getTemperature()).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
|
|
|
weatherfd.setPrecipitation2(0.0);
|
|
|
- weatherfd.setWinddirection2(String.valueOf(new BigDecimal(list.get(list.size() - 1).getWindDir()).setScale(2, RoundingMode.HALF_EVEN).doubleValue()));
|
|
|
+ weatherfd.setWinddirection2(windDirectionSwitch(list.get(list.size() - 1).getWindDir()));
|
|
|
weatherfd.setSpeed2(new BigDecimal(list.get(list.size() - 1).getWindSpeed() * 2.8).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
|
|
|
weatherfd.setGust2(new BigDecimal(list.get(list.size() - 1).getWindSpeed()).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
|
|
|
|
|
@@ -120,6 +123,67 @@ public class TaskWeatherGather {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ N 北 0°
|
|
|
+ NNE 东北偏北 22.5°
|
|
|
+ NE 东北 45°
|
|
|
+ ENE 东北偏东 67.5°
|
|
|
+ E 东 90°
|
|
|
+ ESE 东南偏东 112.5°
|
|
|
+ SE 东南 135°
|
|
|
+ SSE 东南偏南 157.5°
|
|
|
+ S 南 180°
|
|
|
+ SSW 西南偏南 202.5°
|
|
|
+ SW 西南 225°
|
|
|
+ WSW 西南偏西 247.5°
|
|
|
+ W 西 270°
|
|
|
+ WNW 西北偏西 292.5°
|
|
|
+ NW 西北 315°
|
|
|
+ NNW 西北偏北 337.5°
|
|
|
+ */
|
|
|
+ public static String windDirectionSwitch(double degrees) {
|
|
|
+ int index = 0;
|
|
|
+ if (348.75 <= degrees && degrees <= 360) {
|
|
|
+ index = 0;
|
|
|
+ } else if (0 <= degrees && degrees <= 11.25) {
|
|
|
+ index = 0;
|
|
|
+ } else if (11.25 < degrees && degrees <= 33.75) {
|
|
|
+ index = 1;
|
|
|
+ } else if (33.75 < degrees && degrees <= 56.25) {
|
|
|
+ index = 2;
|
|
|
+ } else if (56.25 < degrees && degrees <= 78.75) {
|
|
|
+ index = 3;
|
|
|
+ } else if (78.75 < degrees && degrees <= 101.25) {
|
|
|
+ index = 4;
|
|
|
+ } else if (101.25 < degrees && degrees <= 123.75) {
|
|
|
+ index = 5;
|
|
|
+ } else if (123.75 < degrees && degrees <= 146.25) {
|
|
|
+ index = 6;
|
|
|
+ } else if (146.25 < degrees && degrees <= 168.75) {
|
|
|
+ index = 7;
|
|
|
+ } else if (168.75 < degrees && degrees <= 191.25) {
|
|
|
+ index = 8;
|
|
|
+ } else if (191.25 < degrees && degrees <= 213.75) {
|
|
|
+ index = 9;
|
|
|
+ } else if (213.75 < degrees && degrees <= 236.25) {
|
|
|
+ index = 10;
|
|
|
+ } else if (236.25 < degrees && degrees <= 258.75) {
|
|
|
+ index = 11;
|
|
|
+ } else if (258.75 < degrees && degrees <= 281.25) {
|
|
|
+ index = 12;
|
|
|
+ } else if (281.25 < degrees && degrees <= 303.75) {
|
|
|
+ index = 13;
|
|
|
+ } else if (303.75 < degrees && degrees <= 326.25) {
|
|
|
+ index = 14;
|
|
|
+ } else if (326.25 < degrees && degrees < 348.75) {
|
|
|
+ index = 15;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ return directArr[index];
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|