新增查看页面
This commit is contained in:
@@ -2,8 +2,8 @@ package com.jeesite.modules.app;
|
||||
|
||||
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.modules.app.dao.DailyWeather;
|
||||
import com.jeesite.modules.app.dao.MyWorkInfo;
|
||||
import com.jeesite.modules.app.dao.RealTimeWeather;
|
||||
import com.jeesite.modules.app.utils.MyUtils;
|
||||
import com.jeesite.modules.app.utils.WeatherUtils;
|
||||
import com.jeesite.modules.biz.entity.BizCalendarSchedule;
|
||||
@@ -52,8 +52,8 @@ public class appStart {
|
||||
public MyWorkInfo list() {
|
||||
User user = UserUtils.getUser();
|
||||
WeatherUtils weather = new WeatherUtils(API_KEY);
|
||||
RealTimeWeather timeWeather = weather.getRealTimeWeather(LOCATION);
|
||||
String weatherText = MyUtils.concatParams("今日", timeWeather.getText(), ",温度:{", timeWeather.getTemp(), "℃-", timeWeather.getHumidity(), "℃},", timeWeather.getWindDir());
|
||||
DailyWeather dailyWeather = weather.getTodayWeather(LOCATION);
|
||||
String weatherText = MyUtils.concatParams("今日", dailyWeather.getTextDay(), ";夜间:", dailyWeather.getTextNight(), ";温度:{", dailyWeather.getTempMin(), "°C 至 ", dailyWeather.getTempMax(), "°C};", MyUtils.getPath(dailyWeather.getWindDirDay(), dailyWeather.getWindScaleDay()), "级");
|
||||
// 日程
|
||||
BizCalendarSchedule schedule = new BizCalendarSchedule();
|
||||
schedule.setParticipantUser(user.getLoginCode());
|
||||
|
||||
@@ -105,6 +105,44 @@ public class WeatherUtils {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取今日天气(从未来3天预报中提取当日数据)
|
||||
*
|
||||
* @param location 位置(城市ID/经纬度,如101010100=北京)
|
||||
* @return 今日天气的DailyWeather实体类对象,失败返回null
|
||||
*/
|
||||
public DailyWeather getTodayWeather(String location) {
|
||||
// 1. 参数校验:位置不能为空
|
||||
if (location == null || location.trim().isEmpty()) {
|
||||
System.err.println("位置参数不能为空");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. 调用3天预报接口(免费版默认支持,取第一个元素即为今日)
|
||||
Map<String, Object> responseMap = sendRequest("/weather/3d", location);
|
||||
if (responseMap == null || !responseMap.containsKey("daily")) {
|
||||
System.err.println("获取今日天气失败:API响应异常或无daily字段");
|
||||
return null;
|
||||
}
|
||||
// 3. 提取daily列表中的第一个元素(索引0 = 今日)
|
||||
List<Map<String, Object>> dailyList = (List<Map<String, Object>>) responseMap.get("daily");
|
||||
if (dailyList == null || dailyList.isEmpty()) {
|
||||
System.err.println("获取今日天气失败:daily列表为空");
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> todayMap = dailyList.get(0);
|
||||
return new DailyWeather(
|
||||
(String) todayMap.get("fxDate"), // 今日日期
|
||||
(String) todayMap.get("tempMin"), // 今日最低温
|
||||
(String) todayMap.get("tempMax"), // 今日最高温
|
||||
(String) todayMap.get("textDay"), // 今日白天天气
|
||||
(String) todayMap.get("textNight"), // 今日夜间天气
|
||||
(String) todayMap.get("windDirDay"),// 今日白天风向
|
||||
(String) todayMap.get("windScaleDay")// 今日白天风力
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询实时天气
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user