|
@@ -22,6 +22,7 @@ import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.Statement;
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.ZonedDateTime;
|
|
@@ -34,85 +35,6 @@ import java.util.stream.Collectors;
|
|
|
public class GetWeather {
|
|
|
@Resource
|
|
|
private WeixinPush weixinPush;
|
|
|
- /*public void download() {
|
|
|
-
|
|
|
- List<String> areaCodes = new ArrayList<>();
|
|
|
- List<DistrictCodeDO> districtCodeDOList = new ArrayList<>();
|
|
|
-
|
|
|
- try {
|
|
|
- List<Entity> dictList = Db.use().findAll("system_dict_data");
|
|
|
- for (Entity entity : dictList) {
|
|
|
- String name = entity.getStr("label");
|
|
|
- if (name.contains("area_code")) {
|
|
|
- String code = entity.getStr("value");
|
|
|
- String[] s = code.split(",");
|
|
|
- areaCodes = Arrays.asList(s);
|
|
|
- }
|
|
|
- }
|
|
|
- List<Entity> districtCodes = Db.use().findAll("jy_district_code");
|
|
|
- for (Entity e : districtCodes) {
|
|
|
- DistrictCodeDO districtCodeDO = new DistrictCodeDO();
|
|
|
- districtCodeDO.setCode(Integer.parseInt(e.getStr("code")));
|
|
|
- districtCodeDO.setName(e.getStr("name"));
|
|
|
- districtCodeDO.setLevel(Integer.parseInt(e.getStr("level")));
|
|
|
- districtCodeDO.setType(Integer.parseInt(e.getStr("type")));
|
|
|
- districtCodeDO.setAbname(e.getStr("abname"));
|
|
|
- districtCodeDO.setPid(Integer.parseInt(e.getStr("pid")));
|
|
|
- districtCodeDO.setLat(!Objects.equals(e.getStr("lat"), "") && e.getStr("lat") != null ? new BigDecimal(e.getStr("lat")).setScale(6, RoundingMode.HALF_UP).doubleValue() : 0d);
|
|
|
- districtCodeDO.setLng(!Objects.equals(e.getStr("lng"), "") && e.getStr("lng") != null ? new BigDecimal(e.getStr("lng")).setScale(6, RoundingMode.HALF_UP).doubleValue() : 0d);
|
|
|
- districtCodeDOList.add(districtCodeDO);
|
|
|
- }
|
|
|
- String jdbcUrl = "jdbc:TAOS://192.168.12.241:29500/etadm_local?user=root&password=taosdata";
|
|
|
- Properties connProps = new Properties();
|
|
|
- connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
|
|
- connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
|
|
- connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
|
|
- Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
|
|
|
- //省份
|
|
|
- for (String code : areaCodes) {
|
|
|
- List<DistrictCodeDO> shiList = districtCodeDOList.stream().filter(item -> item.getPid().toString().equals(code)).collect(Collectors.toList());
|
|
|
- //市
|
|
|
- for (DistrictCodeDO d : shiList) {
|
|
|
- List<DistrictCodeDO> quList = districtCodeDOList.stream().filter(item -> item.getPid().toString().equals(d.getCode().toString())).collect(Collectors.toList());
|
|
|
- log.info("开始下载地区:{} 的天气数据", d.getName());
|
|
|
- String hefeng24;
|
|
|
- String caiyun24;
|
|
|
- String hefengDay;
|
|
|
- String caiyunDay;
|
|
|
- //!!!!!!!!!!拼的彩云的辐照度!!!!!!!!!!!!!
|
|
|
- //和风逐小时数据
|
|
|
- hefeng24 = "https://devapi.qweather.com/v7/grid-weather/24h?location=" + d.getLng() + "," + d.getLat() + "&key=54d9633382814e148836ce6be2d003fb";
|
|
|
- //彩云逐小时数据
|
|
|
- caiyun24 = "https://api.caiyunapp.com/v2.6/SRQIFijX5MGtdmhe/" + d.getLng() + "," + d.getLat() + "/hourly?hourlysteps=24";
|
|
|
- //和风逐日数据
|
|
|
- hefengDay = "https://devapi.qweather.com/v7/grid-weather/7d?location=" + d.getLng() + "," + d.getLat() + "&key=54d9633382814e148836ce6be2d003fb";
|
|
|
- //彩云逐日数据
|
|
|
- caiyunDay = "https://api.caiyunapp.com/v2.6/SRQIFijX5MGtdmhe/" + d.getLng() + "," + d.getLat() + "/daily?dailysteps=7";
|
|
|
- analysis24(hefeng24, caiyun24, d.getCode(), d.getName(), conn);
|
|
|
- analysisDay(hefengDay, caiyunDay, d.getCode(), d.getName(), conn);
|
|
|
- //区
|
|
|
- for (DistrictCodeDO q : quList) {
|
|
|
- log.info("开始下载地区:{} 的天气数据", q.getName());
|
|
|
- //和风逐小时数据
|
|
|
- hefeng24 = "https://devapi.qweather.com/v7/grid-weather/24h?location=" + q.getLng() + "," + q.getLat() + "&key=54d9633382814e148836ce6be2d003fb";
|
|
|
- //彩云逐小时数据
|
|
|
- caiyun24 = "https://api.caiyunapp.com/v2.6/SRQIFijX5MGtdmhe/" + q.getLng() + "," + q.getLat() + "/hourly?hourlysteps=24";
|
|
|
- //和风逐日数据
|
|
|
- hefengDay = "https://devapi.qweather.com/v7/grid-weather/7d?location=" + q.getLng() + "," + q.getLat() + "&key=54d9633382814e148836ce6be2d003fb";
|
|
|
- //彩云逐日数据
|
|
|
- caiyunDay = "https://api.caiyunapp.com/v2.6/SRQIFijX5MGtdmhe/" + q.getLng() + "," + q.getLat() + "/daily?dailysteps=7";
|
|
|
- analysis24(hefeng24, caiyun24, q.getCode(), q.getName(), conn);
|
|
|
- analysisDay(hefengDay, caiyunDay, q.getCode(), q.getName(), conn);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- conn.close();
|
|
|
- log.info("天气数据全部下载完毕");
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }*/
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 根据风速获取对应风力等级
|
|
@@ -185,141 +107,10 @@ public class GetWeather {
|
|
|
return Timestamp.valueOf(localDate.atStartOfDay()); // 转换为当天的开始时间
|
|
|
}
|
|
|
|
|
|
- /*public void analysis24(String hefeng24url, String caiyun24url, int areaCode, String name, Connection conn) {
|
|
|
- try {
|
|
|
- Statement ps = conn.createStatement();
|
|
|
- String caiyunBody = HttpUtil.createGet(caiyun24url).execute().charset("utf-8").body();
|
|
|
- JSONObject caiyunjsonObject = JSONUtil.parseObj(caiyunBody);
|
|
|
- JSONObject caiyunResult = JSONUtil.parseObj(caiyunjsonObject.get("result"));
|
|
|
- JSONObject hourly = JSONUtil.parseObj(caiyunResult.get("hourly"));
|
|
|
- JSONArray dswrf = JSONUtil.parseArray(hourly.get("dswrf"));
|
|
|
-
|
|
|
- String hefengBody = HttpUtil.createGet(hefeng24url).execute().charset("utf-8").body();
|
|
|
- JSONObject jsonObject = JSONUtil.parseObj(hefengBody);
|
|
|
- JSONArray hefengList = JSONUtil.parseArray(jsonObject.get("hourly"));
|
|
|
- List<HeFengHour> list = new ArrayList<>();
|
|
|
- hefengList.forEach(item -> {
|
|
|
- JSONObject jsonObject1 = JSONUtil.parseObj(item);
|
|
|
- try {
|
|
|
- HeFengHour weather = new HeFengHour();
|
|
|
- String s = jsonObject1.getStr("fxTime");
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mmXXX");
|
|
|
- ZonedDateTime zonedDateTime = ZonedDateTime.parse(s, formatter);
|
|
|
- Instant instant = zonedDateTime.toInstant();
|
|
|
- Timestamp timestamp = Timestamp.from(instant);
|
|
|
- weather.setTs(timestamp);
|
|
|
- weather.setTemp(new BigDecimal(jsonObject1.getStr("temp")).floatValue());
|
|
|
- weather.setAreaCode(String.valueOf(areaCode));
|
|
|
- weather.setText(jsonObject1.getStr("text"));
|
|
|
- weather.setWindDir(jsonObject1.getStr("windDir"));
|
|
|
- weather.setWind360(new BigDecimal(jsonObject1.getStr("wind360")).floatValue());
|
|
|
- weather.setWindSpeed(new BigDecimal(jsonObject1.getStr("windSpeed")).divide(new BigDecimal("3.6"), 2, RoundingMode.HALF_UP).floatValue());
|
|
|
- weather.setWindScale(new BigDecimal(jsonObject1.getStr("windScale")).floatValue());
|
|
|
- weather.setHumidity(new BigDecimal(jsonObject1.getStr("humidity")).floatValue());
|
|
|
- weather.setCloud(new BigDecimal(jsonObject1.getStr("cloud")).floatValue());
|
|
|
- weather.setPrecip(new BigDecimal(jsonObject1.getStr("precip")).floatValue());
|
|
|
- weather.setDew(new BigDecimal(jsonObject1.getStr("dew")).floatValue());
|
|
|
- weather.setPressure(new BigDecimal(jsonObject1.getStr("pressure")).floatValue());
|
|
|
- list.add(weather);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- });
|
|
|
- if (!dswrf.isEmpty()) {
|
|
|
- if (list.size() != 24) {
|
|
|
- log.error("地区:{} 24小时天气数据下载失败,和风天气数据不全", name);
|
|
|
- } else {
|
|
|
- if (dswrf.size() != 24) {
|
|
|
- log.error("地区:{} 24小时天气数据下载失败,心知天气数据不全", name);
|
|
|
- } else {
|
|
|
- for (int i = 0; i < 24; i++) {
|
|
|
- Map ds = (Map) dswrf.get(i);
|
|
|
- list.get(i).setDswrf(new BigDecimal(ds.get("value").toString()).floatValue());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- for (HeFengHour item : list) {
|
|
|
- String insertSql = " INSERT INTO hefeng_hour_unit_" + areaCode + " USING hefeng_hour_unit TAGS('" + areaCode + "') values('" + item.getTs() + "', " + item.getTemp() + ", '" + item.getText() + "', '" + item.getWindDir() + "', " + item.getWind360() + ", " + item.getWindSpeed() + ", " + item.getWindScale() + ", " + item.getHumidity() + ", " + item.getCloud() + ", " + item.getPrecip() + ", " + item.getDew() + ", " + item.getPressure() + ", " + item.getDswrf() + ")";
|
|
|
- int affectedRows = ps.executeUpdate(insertSql);
|
|
|
- }
|
|
|
- if (ps != null)
|
|
|
- ps.close();
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("地区:{} 24小时天气数据下载失败JSON格式化错误", name);
|
|
|
- }
|
|
|
- log.info("地区:{} 24小时天气数据下载完成", name);
|
|
|
- }
|
|
|
-
|
|
|
- public void analysisDay(String hefeng24url, String caiyun24url, int areaCode, String name, Connection conn) {
|
|
|
- try {
|
|
|
- Statement ps = conn.createStatement();
|
|
|
- String caiyunBody = HttpUtil.createGet(caiyun24url).execute().charset("utf-8").body();
|
|
|
- JSONObject caiyunjsonObject = JSONUtil.parseObj(caiyunBody);
|
|
|
- JSONObject caiyunResult = JSONUtil.parseObj(caiyunjsonObject.get("result"));
|
|
|
- JSONObject daily = JSONUtil.parseObj(caiyunResult.get("daily"));
|
|
|
- JSONArray dswrf = JSONUtil.parseArray(daily.get("dswrf"));
|
|
|
-
|
|
|
- String hefengBody = HttpUtil.createGet(hefeng24url).execute().charset("utf-8").body();
|
|
|
- JSONObject jsonObject = JSONUtil.parseObj(hefengBody);
|
|
|
- JSONArray hefengList = JSONUtil.parseArray(jsonObject.get("daily"));
|
|
|
- List<HeFengDay> list = new ArrayList<>();
|
|
|
- hefengList.forEach(item -> {
|
|
|
- JSONObject jsonObject1 = JSONUtil.parseObj(item);
|
|
|
- try {
|
|
|
- HeFengDay weather = new HeFengDay();
|
|
|
- String s = jsonObject1.getStr("fxDate");
|
|
|
- LocalDate localDate = LocalDate.parse(s);
|
|
|
- // 将 LocalDate 转换为 Instant,然后再转换为 Timestamp
|
|
|
- Timestamp timestamp = Timestamp.valueOf(localDate.atStartOfDay(ZoneOffset.UTC).toLocalDateTime());
|
|
|
- weather.setTs(timestamp);
|
|
|
- weather.setAreaCode(String.valueOf(areaCode));
|
|
|
- weather.setTempMax(new BigDecimal(jsonObject1.getStr("tempMax")).floatValue());
|
|
|
- weather.setTempMin(new BigDecimal(jsonObject1.getStr("tempMin")).floatValue());
|
|
|
- weather.setTextDay(jsonObject1.getStr("textDay"));
|
|
|
- weather.setTextNight(jsonObject1.getStr("textNight"));
|
|
|
- weather.setWind360Day(new BigDecimal(jsonObject1.getStr("wind360Day")).floatValue());
|
|
|
- weather.setWind360Night(new BigDecimal(jsonObject1.getStr("wind360Night")).floatValue());
|
|
|
- weather.setWindDirDay(jsonObject1.getStr("windDirDay"));
|
|
|
- weather.setWindDirNight(jsonObject1.getStr("windDirNight"));
|
|
|
- weather.setWindScaleDay(new BigDecimal(jsonObject1.getStr("windScaleDay")).floatValue());
|
|
|
- weather.setWindScaleNight(new BigDecimal(jsonObject1.getStr("windScaleNight")).floatValue());
|
|
|
- weather.setWindSpeedDay(new BigDecimal(jsonObject1.getStr("windSpeedDay")).divide(new BigDecimal("3.6"), 2, RoundingMode.HALF_UP).floatValue());
|
|
|
- weather.setWindSpeedNight(new BigDecimal(jsonObject1.getStr("windSpeedNight")).divide(new BigDecimal("3.6"), 2, RoundingMode.HALF_UP).floatValue());
|
|
|
- weather.setHumidity(new BigDecimal(jsonObject1.getStr("humidity")).floatValue());
|
|
|
- weather.setPrecip(new BigDecimal(jsonObject1.getStr("precip")).floatValue());
|
|
|
- weather.setPressure(new BigDecimal(jsonObject1.getStr("pressure")).floatValue());
|
|
|
- list.add(weather);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- });
|
|
|
- if (!dswrf.isEmpty()) {
|
|
|
- if (list.size() != 7) {
|
|
|
- log.error("地区:{} 日天气数据下载失败,和风天气数据不全", name);
|
|
|
- } else {
|
|
|
- for (HeFengDay heFengDay : list) {
|
|
|
- Map ds = (Map) dswrf.get(0);
|
|
|
- heFengDay.setDswrf(new BigDecimal(ds.get("max").toString()).floatValue());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- for (HeFengDay item : list) {
|
|
|
- String insertSQL = "INSERT INTO hefeng_day_unit_" + item.getAreaCode() + " USING hefeng_day_unit TAGS('" + item.getAreaCode() + "') values('" + item.getTs() + "', " + item.getTempMax() + ", " + item.getTempMin() + ", '" + item.getTextDay() + "', '" + item.getTextNight() + "', " + item.getWind360Day() + ", '" + item.getWindDirDay() + "', " + item.getWindScaleDay() + ", " + item.getWindSpeedDay() + ", " + item.getWind360Night() + ", '" + item.getWindDirNight() + "', " + item.getWindScaleNight() + ", " + item.getWindSpeedNight() + ", " + item.getHumidity() + ", " + item.getPrecip() + ", " + item.getPressure() + ", " + item.getDswrf() + ")";
|
|
|
- int affectedRows = ps.executeUpdate(insertSQL);
|
|
|
- }
|
|
|
- if (ps != null)
|
|
|
- ps.close();
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("地区:{} 日天气数据下载失败JSON格式化错误", name);
|
|
|
- }
|
|
|
- log.info("地区:{} 日天气数据下载完成", name);
|
|
|
- }*/
|
|
|
-
|
|
|
public void download() {
|
|
|
List<String> areaCodes = new ArrayList<>();
|
|
|
List<DistrictCodeDO> districtCodeDOList = new ArrayList<>();
|
|
|
+ List<DistrictCodeDO> districtCodeDOList1 = new ArrayList<>();
|
|
|
boolean isApiQuotaExhausted = false; // 引入标志变量
|
|
|
String startDate = DateUtil.today();
|
|
|
String endDate = DateUtil.offsetDay(DateUtil.date(), 15).toString("yyyy-MM-dd");
|
|
@@ -336,7 +127,7 @@ public class GetWeather {
|
|
|
List<Entity> districtCodes = Db.use().findAll("jy_district_code");
|
|
|
for (Entity e : districtCodes) {
|
|
|
DistrictCodeDO districtCodeDO = new DistrictCodeDO();
|
|
|
- districtCodeDO.setCode(Integer.parseInt(e.getStr("code")));
|
|
|
+ districtCodeDO.setCode(e.getStr("code"));
|
|
|
districtCodeDO.setName(e.getStr("name"));
|
|
|
districtCodeDO.setLevel(Integer.parseInt(e.getStr("level")));
|
|
|
districtCodeDO.setType(Integer.parseInt(e.getStr("type")));
|
|
@@ -346,6 +137,15 @@ public class GetWeather {
|
|
|
districtCodeDO.setLng(!Objects.equals(e.getStr("lng"), "") && e.getStr("lng") != null ? new BigDecimal(e.getStr("lng")).setScale(6, RoundingMode.HALF_UP).doubleValue() : 0d);
|
|
|
districtCodeDOList.add(districtCodeDO);
|
|
|
}
|
|
|
+ List<Entity> districtCodes1 = Db.use().findAll("jy_power_station");
|
|
|
+ for (Entity e : districtCodes1) {
|
|
|
+ DistrictCodeDO districtCodeDO = new DistrictCodeDO();
|
|
|
+ districtCodeDO.setCode(e.getStr("code"));
|
|
|
+ districtCodeDO.setName(e.getStr("name"));
|
|
|
+ districtCodeDO.setLat(!Objects.equals(e.getStr("lat"), "") && e.getStr("lat") != null ? new BigDecimal(e.getStr("lat")).setScale(6, RoundingMode.HALF_UP).doubleValue() : 0d);
|
|
|
+ districtCodeDO.setLng(!Objects.equals(e.getStr("lng"), "") && e.getStr("lng") != null ? new BigDecimal(e.getStr("lng")).setScale(6, RoundingMode.HALF_UP).doubleValue() : 0d);
|
|
|
+ districtCodeDOList1.add(districtCodeDO);
|
|
|
+ }
|
|
|
String jdbcUrl = "jdbc:TAOS://192.168.12.241:29500/etadm_local?user=root&password=taosdata";
|
|
|
Properties connProps = new Properties();
|
|
|
connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
|
@@ -361,9 +161,9 @@ public class GetWeather {
|
|
|
//市
|
|
|
for (DistrictCodeDO d : shiList) {
|
|
|
if (isApiQuotaExhausted) break; // 检查标志变量
|
|
|
- List<DistrictCodeDO> quList = districtCodeDOList.stream().filter(item -> item.getPid().toString().equals(d.getCode().toString())).collect(Collectors.toList());
|
|
|
+ List<DistrictCodeDO> quList = districtCodeDOList.stream().filter(item -> item.getPid().toString().equals(d.getCode())).collect(Collectors.toList());
|
|
|
String xmoUrl;
|
|
|
- //彩云综合数据查询
|
|
|
+ //xmo综合数据查询
|
|
|
xmoUrl = "https://weather-api.xm-opt.com/v1/forecastDaily?latitude=" + d.getLat() + "&longitude=" + d.getLng() + "&daily=weather_code,temperature_2m_max,rain_sum,wind_speed_10m_max,wind_direction_10m_dominant,shortwave_radiation_sum,temperature_2m_min,precipitation_sum&timezone=Asia%2FShanghai&start_date=" + startDate + "&end_date=" + endDate;
|
|
|
isApiQuotaExhausted = analysisXMO(xmoUrl, d.getCode(), d.getName(), conn); // 传递标志变量
|
|
|
if (isApiQuotaExhausted) break; // 检查标志变量
|
|
@@ -378,13 +178,20 @@ public class GetWeather {
|
|
|
//Thread.sleep(5000);
|
|
|
}
|
|
|
}
|
|
|
+ //2025-07-18 新增 甘肃库里 powerstation表里场站的经纬度也获取数据, td表的tag是场站编号而不是地区编号
|
|
|
+ for (DistrictCodeDO d : districtCodeDOList1) {
|
|
|
+ String xmoUrl = "https://weather-api.xm-opt.com/v1/forecastDaily?latitude=" + d.getLat() + "&longitude=" + d.getLng() + "&daily=weather_code,temperature_2m_max,rain_sum,wind_speed_10m_max,wind_direction_10m_dominant,shortwave_radiation_sum,temperature_2m_min,precipitation_sum&timezone=Asia%2FShanghai&start_date=" + startDate + "&end_date=" + endDate;
|
|
|
+ if (isApiQuotaExhausted) break; // 检查标志变量
|
|
|
+ isApiQuotaExhausted = analysisXMO(xmoUrl, d.getCode(), d.getName(), conn); // 传递标志变量
|
|
|
+ if (isApiQuotaExhausted) break; // 检查标志变量
|
|
|
+ }
|
|
|
} else {
|
|
|
if (isApiQuotaExhausted) break; // 检查标志变量
|
|
|
List<DistrictCodeDO> shiList = districtCodeDOList.stream().filter(item -> item.getPid().toString().equals(code)).collect(Collectors.toList());
|
|
|
//市
|
|
|
for (DistrictCodeDO d : shiList) {
|
|
|
if (isApiQuotaExhausted) break; // 检查标志变量
|
|
|
- List<DistrictCodeDO> quList = districtCodeDOList.stream().filter(item -> item.getPid().toString().equals(d.getCode().toString())).collect(Collectors.toList());
|
|
|
+ List<DistrictCodeDO> quList = districtCodeDOList.stream().filter(item -> item.getPid().toString().equals(d.getCode())).collect(Collectors.toList());
|
|
|
String caiyun;
|
|
|
//彩云综合数据查询
|
|
|
caiyun = "https://api.caiyunapp.com/v2.6/SRQIFijX5MGtdmhe/" + d.getLng() + "," + d.getLat() + "/weather?alert=true&dailysteps=7&hourlysteps=72";
|
|
@@ -408,16 +215,6 @@ public class GetWeather {
|
|
|
String description = "接口调用异常";
|
|
|
if (isApiQuotaExhausted) {
|
|
|
//给企业微信发送消息
|
|
|
- /* WeixinPush weixinPush = new WeixinPush();
|
|
|
- WeixinMessage weixinMessage = new WeixinMessage();
|
|
|
- weixinMessage.setToUser("WangHongChen|XiuWei|DouZhi");
|
|
|
- //获取今天的ymd
|
|
|
- String ymd = DateUtil.format(DateUtil.date(), "yyyy-MM-dd");
|
|
|
- weixinMessage.setContent(ymd + "日 电力交易系统在获取天气数据时报错, 彩云天气API 额度已用尽");
|
|
|
- weixinMessage.setMsgType("text");
|
|
|
- weixinMessage.setAgentid(1000009); // 确保 agentid 正确
|
|
|
- weixinPush.sendMessage(weixinMessage);
|
|
|
- */
|
|
|
weixinPush.sendMessageBot(alarm, description);
|
|
|
} else {
|
|
|
alarm = "电力交易系统每日天气数据全部下载完毕";
|
|
@@ -430,7 +227,7 @@ public class GetWeather {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public boolean analysis(String caiyun, int areaCode, String name, Connection conn) {
|
|
|
+ public boolean analysis(String caiyun, String areaCode, String name, Connection conn) {
|
|
|
log.info("开始下载地区:{} 的天气数据", name);
|
|
|
try {
|
|
|
Statement ps = conn.createStatement();
|
|
@@ -551,7 +348,7 @@ public class GetWeather {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public boolean analysisXMO(String xmoUrl, int areaCode, String name, Connection conn) {
|
|
|
+ public boolean analysisXMO(String xmoUrl, String areaCode, String name, Connection conn) {
|
|
|
log.info("开始下载地区:{} 的天气数据", name);
|
|
|
try {
|
|
|
Statement ps = conn.createStatement();
|
|
@@ -588,6 +385,7 @@ public class GetWeather {
|
|
|
HeFengDay heFengDay = new HeFengDay();
|
|
|
heFengDay.setTs(convertStringToTimestamp(time));
|
|
|
heFengDay.setWindSpeedDay(windSpeedDay.get(i) == null ? -0.99f : new BigDecimal(windSpeedDay.get(i).toString()).floatValue());
|
|
|
+ heFengDay.setWindScaleDay(speedLevel(windSpeedDay.get(i) == null ? "0" : windSpeedDay.get(i).toString()));
|
|
|
heFengDay.setWind360Day(direction.get(i).toString() == null ? -0.99f : new BigDecimal(direction.get(i).toString()).floatValue());
|
|
|
heFengDay.setPrecip(precip.get(i) == null ? -0.99f : new BigDecimal(precip.get(i).toString()).floatValue());
|
|
|
heFengDay.setTextDay(ConversionWeatherCodeXmo(code.get(i).toString() == null ? "0" : code.get(i).toString()));
|
|
@@ -602,9 +400,15 @@ public class GetWeather {
|
|
|
}
|
|
|
for (HeFengDay item : heFengDayList) {
|
|
|
String insertSQL = "INSERT INTO hefeng_day_unit_" + areaCode + " USING hefeng_day_unit TAGS('" + areaCode + "') " +
|
|
|
- "(ts,wind_speed_day,wind_360_Day,precip,text_day,temp_max,temp_min,humidity,dswrf) values('"
|
|
|
- + item.getTs() + "', " + item.getWindSpeedDay() + ", " + item.getWind360Day() + ", " + item.getPrecip() + ", '"
|
|
|
- + item.getTextDay() + "', " + item.getTempMax() + ", " + item.getTempMin() + ", " + item.getHumidity() + ", "
|
|
|
+ "(ts,wind_speed_day,wind_scale_day,wind_360_Day,precip,text_day,temp_max,temp_min,humidity,dswrf) values('"
|
|
|
+ + item.getTs() + "', " + item.getWindSpeedDay() + ", " + item.getWindScaleDay() + ", " + item.getWind360Day() + ", "
|
|
|
+ + item.getPrecip() + ", '" + item.getTextDay() + "', " + item.getTempMax() + ", " + item.getTempMin() + ", " + item.getHumidity() + ", "
|
|
|
+ + item.getDswrf() + ")";
|
|
|
+ SimpleDateFormat simpleFormatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String insertSnap = "INSERT INTO weather_day_snap_" + areaCode + "_" + simpleFormatter.format(new Date()) + " USING hefeng_day_unit TAGS('" + areaCode + "','" + simpleFormatter.format(new Date()) + "') " +
|
|
|
+ "(ts,wind_speed_day,wind_scale_day,wind_360_Day,precip,text_day,temp_max,temp_min,humidity,dswrf) values('"
|
|
|
+ + item.getTs() + "', " + item.getWindSpeedDay() + ", " + item.getWindScaleDay() + ", " + item.getWind360Day() + ", "
|
|
|
+ + item.getPrecip() + ", '" + item.getTextDay() + "', " + item.getTempMax() + ", " + item.getTempMin() + ", " + item.getHumidity() + ", "
|
|
|
+ item.getDswrf() + ")";
|
|
|
int affectedRows = ps.executeUpdate(insertSQL);
|
|
|
}
|