Browse Source

通用数据查询接口完善

cuixubin 3 years ago
parent
commit
f8880d7d5c

+ 34 - 9
src/main/java/com/persagy/framework/dto/DataQueryParam.java

@@ -6,6 +6,8 @@ import java.util.Map;
 
 import com.persagy.core.enumeration.SpecialOperator;
 import com.persagy.framework.util.DateUtils;
+import com.persagy.framework.util.DateUtils.TimeNum;
+import com.persagy.functions.weather.constant.Const.ErrorTag;
 
 public class DataQueryParam {
 	public String cityName;
@@ -17,6 +19,31 @@ public class DataQueryParam {
 	public TimeSpanCondition timeSpan;
 	public Map<String, String> fieldEqualMap = new HashMap<>();
 
+	public boolean timeRight(Date timeParam) {
+		if(time != null) {
+			return time.equals(timeParam);
+		}
+		
+		if(timeSpan != null) {
+			boolean leftbol = timeSpan.optLeft == SpecialOperator.$gt ? timeParam.after(timeSpan.timeLeft) : !timeParam.before(timeSpan.timeLeft);
+			if(leftbol) {
+				return timeSpan.optRight == SpecialOperator.$lt ? timeParam.before(timeSpan.timeRight) : !timeParam.after(timeSpan.timeRight);
+			}
+		}
+		return false;
+	}
+	
+	public boolean timeSpanCheck(int maxDays) throws Exception {
+		try {
+			long timeSpanNum = timeSpan.timeRight.getTime() - timeSpan.timeLeft.getTime();
+			if(timeSpanNum > 0 && timeSpanNum >= (maxDays * TimeNum.day)) {
+				return true;
+			}
+		}catch (Exception e) {
+			throw new Exception(ErrorTag.timeSpanLack);
+		}
+		return false;
+	}
 	
 	public DataQueryParam(Map<String, Object> paramMap) throws Exception {
 		cityName = (String) paramMap.get("cityName");
@@ -26,13 +53,11 @@ public class DataQueryParam {
 		latitude = (Double) paramMap.get("latitude");
 		
 		if(cityCheck()) {
-			throw new Exception("参数缺少城市信息");
+			throw new Exception(ErrorTag.paramMis);
 		}
 		
 		Object timeObj = paramMap.get("time");
-		if(timeObj == null) {
-			throw new Exception("参数缺少时间信息");
-		}else {
+		if(timeObj != null) {
 			try {
 				if(timeObj instanceof Map) {
 					Map<String, Object> timeSpanMap = (Map<String, Object>) timeObj;
@@ -45,7 +70,7 @@ public class DataQueryParam {
 						timeSpan.optLeft = SpecialOperator.$gt;
 						timeSpan.timeLeft = DateUtils.long2Date((long) timeSpanMap.get("$gt"));
 					}else {
-						throw new Exception("时间区间不完整。");
+						throw new Exception(ErrorTag.timeSpanLack);
 					}
 
 					if(timeSpanMap.containsKey("$lt")) {
@@ -55,19 +80,19 @@ public class DataQueryParam {
 						timeSpan.optRight = SpecialOperator.$lte;
 						timeSpan.timeRight = DateUtils.long2Date((long) timeSpanMap.get("$lte"));
 					}else {
-						throw new Exception("时间区间不完整。");
+						throw new Exception(ErrorTag.timeSpanLack);
 					}
 					
 					if(!timeSpan.timeLeft.before(timeSpan.timeRight)) {
-						throw new Exception("时间跨度异常。");
+						throw new Exception(ErrorTag.timeEndBeforeStart);
 					}
 				}else if(timeObj instanceof Long) {
 					time = DateUtils.long2Date((long) timeObj);
 				}else {
-					throw new Exception("时间参数格式错误");
+					throw new Exception(ErrorTag.paramFormat);
 				}
 			}catch (Exception e) {
-				throw new Exception("时间参数不合法。" + e.getMessage());
+				throw new Exception("time param error: " + e.getMessage());
 			}
 		}
 	}

+ 8 - 1
src/main/java/com/persagy/framework/util/DateUtils.java

@@ -35,7 +35,14 @@ public class DateUtils extends org.apache.commons.lang.time.DateUtils{
 	public static final String SDFMONTH2 = "yyyy.MM";
 	public static final String SDF_YEAR = "yyyy-01-01";
 	public static final String SDF_ONLY_HOUR_MINUTE = "HH:mm";
-
+	
+	public static class TimeNum {
+		public static final long second = 1000;
+		public static final long minute = 60 * second;
+		public static final long hour = 60 * minute;
+		public static final long day = 24 * hour;
+	}
+	
 	public static Date long2Date(long timeLong) throws ParseException {
 		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 		String d = format.format(timeLong); 

+ 44 - 1
src/main/java/com/persagy/framework/util/WServiceUtil.java

@@ -164,6 +164,26 @@ public class WServiceUtil {
 	 * @param start >=-2, <15
 	 * @param end >-2, <=15
 	 * @return
+	 * 
+	 * [
+	 * 	{
+	 * 		"date": "2021-02-07",
+	 * 		"text_day": "晴",
+	 * 		"code_day": "0",
+	 * 		"text_night": "晴",
+	 * 		"code_night": "1",
+	 * 		"high": "6",
+	 * 		"low": "-5",
+	 * 		"rainfall": "0.0",
+	 * 		"precip": "",
+	 * 		"wind_direction": "东北",
+	 * 		"wind_direction_degree": "45",
+	 * 		"wind_speed": "3.0",
+	 * 		"wind_scale": "1",
+	 * 		"humidity": "35"
+	 * 	}
+	 * ]
+	 * 
 	 */
 	public static List<Map<String, Object>> getDayPredict(String location, int start, int end) {
 		List<Map<String, Object>> dailyArray = new ArrayList<Map<String, Object>>();
@@ -231,7 +251,30 @@ public class WServiceUtil {
 	/**
 	 * 获取24小时逐小时天气预报
 	 * @param location
-	 * @return {"location":{}, "hourly":[]}
+	 * @return 
+	 * 
+	* {
+	* 	"location": {
+	* 		"id": "WX4FBXXFKE4F",
+	* 		"name": "北京",
+	* 		"country": "CN",
+	* 		"path": "北京,北京,中国",
+	* 		"timezone": "Asia/Shanghai",
+	* 		"timezone_offset": "+08:00"
+	* 	},
+	* 	"hourly": [
+	* 		{
+	* 			"time": "2021-02-07T11:00:00+08:00",
+	* 			"text": "晴",
+	* 			"code": "0",
+	* 			"temperature": "2",
+	* 			"humidity": "24",
+	* 			"wind_direction": "北",
+	* 			"wind_speed": "10"
+	* 		}
+	* 	]
+	* } 
+	 * 
 	 */
 	public static Map<String, Object> getHour24PredictWithLocation(String location) {
 		Map<String, Object> dataItem = new HashMap<>();

+ 1 - 9
src/main/java/com/persagy/functions/weather/business/v2020/DisasterWarningQuery.java

@@ -42,7 +42,7 @@ public class DisasterWarningQuery extends BaseBusinessService<Map> implements Bu
 		String level = (String) dto.get("level");
 
 		String cityId = ConfigUtil.getLocationStrict(cityName, cityCode, projectId);
-		if (StringUtils.isEmpty(cityName)) {
+		if (StringUtils.isEmpty(cityId)) {
 			throw new Exception(Const.ErrorTag.cityNotFound);
 		}
 		Date dateStart = startTime == null ? DateUtils.getHourOff(new Date(), -24)
@@ -51,14 +51,6 @@ public class DisasterWarningQuery extends BaseBusinessService<Map> implements Bu
 		if (DateUtils.getYear(dateStart) != DateUtils.getYear(dateEnd)) {
 			throw new Exception(Const.ErrorTag.timeToLong);
 		}
-		DisasterWarning disasterQuery = new DisasterWarning();
-		disasterQuery.setCityId(cityId);
-		if (type != null) {
-			disasterQuery.setType(type);
-		}
-		if (level != null) {
-			disasterQuery.setLevel(level);
-		}
 		List<DisasterWarning> disasterList = this.service.query(cityId, type, level, dateStart, dateEnd);
 		if (!CollectionUtils.isEmpty(disasterList)) {
 			for (DisasterWarning obj : disasterList) {

+ 116 - 0
src/main/java/com/persagy/functions/weather/business/v2021/ComputeSunRiseSet.java

@@ -0,0 +1,116 @@
+package com.persagy.functions.weather.business.v2021;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.stereotype.Service;
+
+import com.persagy.core.enumeration.SpecialOperator;
+import com.persagy.core.utils.DateUtils;
+import com.persagy.framework.construct.RequestProcessor;
+import com.persagy.framework.dto.DataQueryParam;
+import com.persagy.framework.util.ConfigUtil;
+import com.persagy.framework.util.SunComputeUtil;
+import com.persagy.functions.weather.constant.Const;
+import com.persagy.functions.weather.dto.CityDTO;
+
+/**
+ * 日出日落数据
+ */
+@Service("sunRiseSet")
+public class ComputeSunRiseSet implements RequestProcessor {
+
+	@Override
+	public Object handle(DataQueryParam param) throws Exception {
+		List<Map<String, Object>> resultList = new ArrayList<>();
+		
+		Map<String, Object> paramMap = analysisParam(param);
+		Date dayStart = (Date) paramMap.get("dayStart");
+		Date dayEnd = (Date) paramMap.get("dayEnd");
+		Double longitude = (Double) paramMap.get("longitude");
+		Double latitude = (Double) paramMap.get("latitude");
+		
+		Date dayIndex = dayStart;
+		do {
+			Map<String, Object> item = new HashMap<>();
+			item.put("sunRise", SunComputeUtil.getSunrise(longitude, latitude, dayIndex));
+			item.put("sunSet", SunComputeUtil.getSunset(longitude, latitude, dayIndex));
+			resultList.add(item);
+			dayIndex = DateUtils.getDayOff(dayIndex, 1);
+		}while(dayIndex.before(dayEnd));
+		
+		return resultList;
+	}
+	
+	private Map<String, Object> analysisParam(DataQueryParam param) throws Exception {
+		Map<String, Object> result = new HashMap<>();
+		
+		String cityName = param.cityName;
+		String cityCode = param.cityCode;
+		String projectId = param.projectId;
+		Double longitude = param.longitude;
+		Double latitude = param.longitude;
+		Date dayStart = param.timeSpan.timeLeft;
+		Date dayEnd = param.timeSpan.timeRight;
+		if(param.timeSpan.optLeft == SpecialOperator.$gt) {
+			dayStart = DateUtils.getDayOff(dayStart, 1);
+		}
+		if(param.timeSpan.optRight == SpecialOperator.$lte) {
+			dayEnd = DateUtils.getDayOff(dayEnd, 1);
+		}
+		
+		if(null != cityCode && cityCode.length() != 6) {
+			throw new Exception(Const.ErrorTag.paramUnrecognized + " : cityCode="+cityCode);
+		}
+		
+		if(null != projectId && projectId.length() != 12) {
+			throw new Exception(Const.ErrorTag.paramUnrecognized + " : projectId="+projectId);
+		}
+		
+		if((longitude != null) ^ (latitude != null)) {
+			throw new Exception(Const.ErrorTag.paramMis + " longitude or latitude");
+		}
+		
+		if(!param.timeSpanCheck(366)) {
+			throw new Exception(Const.ErrorTag.timeToLong);
+		}
+		
+		result.put("dayStart", dayStart);
+		result.put("dayEnd", dayEnd);
+		
+		if(longitude != null) {
+			result.put("longitude", longitude);
+			result.put("latitude", latitude);
+		}else {
+			CityDTO cityInfo = ConfigUtil.dicCityObjMap().get(cityCode);
+			if(null == cityInfo && projectId != null) {
+				cityInfo = ConfigUtil.dicCityObjMap().get(projectId.substring(2, 8));
+			}
+			
+			if(null == cityInfo && cityName != null) {
+				cityInfo = ConfigUtil.dicCityObjMap().get(ConfigUtil.dicName2DicCodeMap().get(cityName));
+				
+				if(null == cityInfo) {
+					for(String name : ConfigUtil.dicName2DicCodeMap().keySet()) {
+						if(name.startsWith(cityName) || cityName.startsWith(name)) {
+							cityInfo = ConfigUtil.dicCityObjMap().get(ConfigUtil.dicName2DicCodeMap().get(name));
+							break;
+						}
+					}
+				}
+			}
+			
+			if(null == cityInfo || cityInfo.getLongitude() == null || cityInfo.getLatitude() == null) {
+				throw new Exception(Const.ErrorTag.cityUnsupport);
+			}
+			
+			result.put("longitude", Double.parseDouble(cityInfo.getLongitude()));
+			result.put("latitude", Double.parseDouble(cityInfo.getLatitude()));
+		}
+		
+		return result;
+	}
+}

+ 69 - 0
src/main/java/com/persagy/functions/weather/business/v2021/QueryDisaster.java

@@ -0,0 +1,69 @@
+package com.persagy.functions.weather.business.v2021;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import com.persagy.core.enumeration.SpecialOperator;
+import com.persagy.core.utils.DateUtils;
+import com.persagy.ems.pojo.wz.DisasterWarning;
+import com.persagy.framework.construct.RequestProcessor;
+import com.persagy.framework.dto.DataQueryParam;
+import com.persagy.framework.util.ConfigUtil;
+import com.persagy.functions.weather.constant.Const;
+import com.persagy.functions.weather.service.DisasterWarningService;
+
+/**
+ * 灾害预警数据
+ */
+@Service("disaster")
+public class QueryDisaster implements RequestProcessor {
+	@Resource
+	private DisasterWarningService service;
+
+	@Override
+	public Object handle(DataQueryParam param) throws Exception {
+		List<Map<String, Object>> resultList = new ArrayList<>();
+		
+		String location = ConfigUtil.getLocationStrict(param.cityName, param.cityCode, param.projectId);
+		if (StringUtils.isEmpty(location)) {
+			throw new Exception(Const.ErrorTag.cityNotFound);
+		}
+		
+		if(param.timeSpanCheck(366)) {
+			Date startDay = param.timeSpan.timeLeft;
+			Date endDay = param.timeSpan.timeRight;
+			if(param.timeSpan.optLeft == SpecialOperator.$gt) {
+				startDay = DateUtils.getDayOff(startDay, 1);
+			}
+			if(param.timeSpan.optRight == SpecialOperator.$lte) {
+				endDay = DateUtils.getDayOff(endDay, 1);
+			}
+			
+			List<DisasterWarning> disasterList = this.service.query(location, null, null, startDay, endDay);
+			if (!disasterList.isEmpty()) {
+				for (DisasterWarning obj : disasterList) {
+					Map<String, Object> item = new HashMap<>();
+					item.put("title", obj.getTitle());
+					item.put("type", obj.getType());
+					item.put("level", obj.getLevel());
+					item.put("description", obj.getDescription());
+					item.put("pubTime", obj.getPubTime().getTime());
+					resultList.add(item);
+				}
+			}
+		}else {
+			throw new Exception(Const.ErrorTag.timeToLong);
+		}
+		
+		return resultList;
+	}
+	
+}

+ 72 - 0
src/main/java/com/persagy/functions/weather/business/v2021/QueryHistoryDay.java

@@ -0,0 +1,72 @@
+package com.persagy.functions.weather.business.v2021;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Service;
+
+import com.persagy.core.enumeration.SpecialOperator;
+import com.persagy.core.utils.DateUtils;
+import com.persagy.ems.pojo.wz.DayHisRecord;
+import com.persagy.framework.construct.RequestProcessor;
+import com.persagy.framework.dto.DataQueryParam;
+import com.persagy.framework.util.ConfigUtil;
+import com.persagy.functions.weather.constant.Const;
+import com.persagy.functions.weather.service.DayHisRecordService;
+
+/**
+ * 日历史数据
+ */
+@Service("historyDay")
+public class QueryHistoryDay implements RequestProcessor {
+	@Resource
+	private DayHisRecordService dayHisRecordService;
+
+	@Override
+	public Object handle(DataQueryParam param) throws Exception {
+		List<Map<String, Object>> resultList = new ArrayList<>();
+		
+		String location = ConfigUtil.getLocation(param.cityName, param.cityCode, param.projectId);
+		
+		if(param.timeSpanCheck(366 * 3)) {
+			Date startDay = param.timeSpan.timeLeft;
+			Date endDay = param.timeSpan.timeRight;
+			if(param.timeSpan.optLeft == SpecialOperator.$gt) {
+				startDay = DateUtils.getDayOff(startDay, 1);
+			}
+			if(param.timeSpan.optRight == SpecialOperator.$lte) {
+				endDay = DateUtils.getDayOff(endDay, 1);
+			}
+			
+			List<DayHisRecord> list = dayHisRecordService.query(location, startDay, endDay);
+			for(DayHisRecord obj : list) {
+				Map<String, Object> item = new HashMap<>();
+				item.put("codeDay", obj.getCode_day());
+				item.put("codeNight", obj.getCode_night());
+				item.put("time", obj.getDayTime().getTime());
+				item.put("temperatureHigh", obj.getHigh());
+				item.put("humidity", obj.getHumidity());
+				item.put("temperatureLow", obj.getLow());
+				item.put("textDay", obj.getText_day());
+				item.put("textNight", obj.getText_night());
+				item.put("windDirection", obj.getWind_direction());
+				item.put("windDirectionDegree", obj.getWind_direction_degree());
+				item.put("windScale", obj.getWind_scale());
+				item.put("windSpeed", obj.getWind_speed());
+				item.put("rainfall", obj.getRainfall());
+				item.put("precip", obj.getPrecip());
+				resultList.add(item);
+			}
+		}else {
+			throw new Exception(Const.ErrorTag.timeToLong);
+		}
+		
+		return resultList;
+	}
+	
+}

+ 74 - 0
src/main/java/com/persagy/functions/weather/business/v2021/QueryHistoryHour.java

@@ -0,0 +1,74 @@
+package com.persagy.functions.weather.business.v2021;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Service;
+
+import com.persagy.ems.pojo.wz.HourRecordData;
+import com.persagy.framework.construct.RequestProcessor;
+import com.persagy.framework.dto.DataQueryParam;
+import com.persagy.framework.util.ConfigUtil;
+import com.persagy.functions.weather.constant.Const;
+import com.persagy.functions.weather.service.HourRecordService;
+
+/**
+ * 小时历史数据
+ */
+@Service("historyHour")
+public class QueryHistoryHour implements RequestProcessor {
+	@Resource
+	private HourRecordService hourDataService;
+
+	@Override
+	public Object handle(DataQueryParam param) throws Exception {
+		List<Map<String, Object>> resultList = new ArrayList<>();
+		
+		String location = ConfigUtil.getHourCity(param.cityName, param.cityCode, param.projectId);
+		if(null == location) {
+			throw new Exception(Const.ErrorTag.cityUnsupport);
+		}
+		
+		if(param.timeSpanCheck(31)) {
+			List<HourRecordData> list = hourDataService.query(location, param.timeSpan);
+			for(HourRecordData record : list) {
+				resultList.add(getResultItem(record));
+			}
+		}else {
+			throw new Exception(Const.ErrorTag.timeToLong);
+		}
+		
+		return resultList;
+	}
+	
+	private Map<String, Object> getResultItem(HourRecordData record) throws Exception {
+		Map<String, Object> item = new HashMap<>();
+		item.put("time", record.getHourTime().getTime());
+		item.put("temperature", record.getTemperature());
+		item.put("text", record.getText());
+		item.put("windSpeed", record.getWind_speed());
+		item.put("humidity", record.getHumidity());
+		item.put("quality", record.getQuality());
+		item.put("feelsLike", record.getFeels_like());
+		item.put("code", record.getCode());
+		item.put("windDirection", record.getWind_direction());
+		item.put("windDirectionDegree", record.getWind_direction_degree());
+		item.put("windScale", record.getWind_scale());
+		item.put("pressure", record.getPressure());
+		item.put("visibility", record.getVisibility());
+		item.put("clouds", record.getClouds());
+		item.put("pm25", record.getPm25());
+		item.put("pm10", record.getPm10());
+		item.put("so2", record.getSo2());
+		item.put("no2", record.getNo2());
+		item.put("co", record.getCo());
+		item.put("o3", record.getO3());
+		item.put("aqi", record.getAqi());
+		item.put("primaryPollutant", record.getPrimary_pollutant());
+		return item;
+	}
+}

+ 101 - 0
src/main/java/com/persagy/functions/weather/business/v2021/QueryPredictDay.java

@@ -0,0 +1,101 @@
+package com.persagy.functions.weather.business.v2021;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Service;
+
+import com.persagy.ems.pojo.wz.DayPredictRecord;
+import com.persagy.framework.construct.RequestProcessor;
+import com.persagy.framework.dto.DataQueryParam;
+import com.persagy.framework.util.ConfigUtil;
+import com.persagy.framework.util.DateUtils;
+import com.persagy.framework.util.WServiceUtil;
+import com.persagy.functions.weather.constant.Const;
+import com.persagy.functions.weather.constant.Const.ErrorTag;
+import com.persagy.functions.weather.dto.DayPredictDTO;
+import com.persagy.functions.weather.service.DayHisRecordService;
+
+/**
+ * 15日(含今日)预报
+ */
+@Service("predictDay")
+public class QueryPredictDay implements RequestProcessor {
+	@Resource
+	private DayHisRecordService dayHisRecordService;
+
+	@Override
+	public Object handle(DataQueryParam param) throws Exception {
+		List<Map<String, Object>> resultList = new ArrayList<>();
+		
+		String location = ConfigUtil.getLocationStrict(param.cityName, param.cityCode, param.projectId);
+	    if(null == location) {
+	    	throw new Exception(Const.ErrorTag.cityNotFound);
+	    }
+	    
+	    Date dateStart = DateUtils.getShortDate(new Date(), 3);
+	    Date dateEnd = DateUtils.getDayOff(dateStart, 15);
+		
+	    List<DayPredictRecord> list = dayHisRecordService.queryPredictData(location, dateStart, dateEnd);
+	    if(null != list && list.size() == 15) {
+	    	Date temp = null;
+	    	for(DayPredictRecord item : list) {
+	    		temp = item.getDayTime();
+	    		Map<String, Object> resultMap = new HashMap<>();
+    			resultMap.put("time", temp.getTime());
+    			resultMap.put("textDay", item.getText_day());
+    			resultMap.put("codeDay", item.getCode_day());
+    			resultMap.put("textNight", item.getText_night());
+    			resultMap.put("codeNight", item.getCode_night());
+    			resultMap.put("humidity", item.getHumidity());
+    			resultMap.put("rainfall", item.getRainfall());
+    			resultMap.put("windDirection", item.getWind_direction());
+    			resultMap.put("windDirectionDegree", item.getWind_direction_degree());
+    			resultMap.put("windScale", item.getWind_scale());
+    			resultMap.put("windSpeed", item.getWind_speed());
+    			resultMap.put("temperatureLow", item.getLow());
+    			resultMap.put("temperatureHigh", item.getHigh());
+    			resultList.add(resultMap);
+	    	}
+	    }else {
+	    	List<DayPredictDTO> predicDataList = WServiceUtil.getDayPredictObj(location, 0, 15);
+	    	
+	    	if (!predicDataList.isEmpty()) {
+	    		String dayTmp = null;
+	    		for (DayPredictDTO item : predicDataList) {
+	    			dayTmp = item.getDate();
+	    			
+	    			Map<String, Object> resultMap = new HashMap<>();
+	    			resultMap.put("time", DateUtils.str2Date(dayTmp, DateUtils.SDF_DAY).getTime());
+	    			resultMap.put("textDay", item.getText_day());
+	    			resultMap.put("codeDay", item.getCode_day());
+	    			resultMap.put("textNight", item.getText_night());
+	    			resultMap.put("codeNight", item.getCode_night());
+	    			resultMap.put("humidity", item.getHumidity());
+	    			resultMap.put("rainfall", item.getRainfall());
+	    			resultMap.put("windDirection", item.getWind_direction());
+	    			resultMap.put("windDirectionDegree", item.getWind_direction_degree());
+	    			resultMap.put("windScale", item.getWind_scale());
+	    			resultMap.put("windSpeed", item.getWind_speed());
+	    			resultMap.put("temperatureLow", item.getLow());
+	    			resultMap.put("temperatureHigh", item.getHigh());
+	    			resultList.add(resultMap);
+	    		}
+	    		
+	    		try {
+	    			dayHisRecordService.coverPredictRecordUseDTO(location, predicDataList);
+	    		}catch (Exception e) {
+					e.printStackTrace();
+				}
+	    	}else {
+	    		throw new Exception(ErrorTag.service3rd);
+	    	}
+	    }
+		return resultList;
+	}
+}

+ 63 - 0
src/main/java/com/persagy/functions/weather/business/v2021/QueryPredictHour.java

@@ -0,0 +1,63 @@
+package com.persagy.functions.weather.business.v2021;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Service;
+
+import com.persagy.framework.construct.RequestProcessor;
+import com.persagy.framework.dto.DataQueryParam;
+import com.persagy.framework.util.ConfigUtil;
+import com.persagy.framework.util.DateUtils;
+import com.persagy.framework.util.WServiceUtil;
+import com.persagy.functions.weather.constant.Const;
+import com.persagy.functions.weather.service.HourRecordService;
+
+/**
+ * 24小时(含当前小时)预报
+ */
+@Service("predictHour")
+public class QueryPredictHour implements RequestProcessor {
+	@Resource
+	private HourRecordService hourDataService;
+
+	@Override
+	public Object handle(DataQueryParam param) throws Exception {
+		List<Map<String, Object>> resultList = new ArrayList<>();
+		
+		String location = ConfigUtil.getLocation(param.cityName, param.cityCode, param.projectId);
+		if(null == location) {
+			throw new Exception(Const.ErrorTag.cityNotFound);
+		}
+		
+		try {
+			Map<String, Object> dataMap = WServiceUtil.getHour24PredictWithLocation(location);
+			if (!dataMap.isEmpty()) {
+				List<Map<String, Object>> hourly = (List<Map<String, Object>>) dataMap.get("hourly");
+				for(Map<String, Object> item : hourly) {
+					Date hourTime = DateUtils.t8DateStr2Date(item.get("time")+"");
+					
+					Map<String, Object> resultItem = new HashMap<>();
+					resultItem.put("temperature", item.get("temperature"));
+					resultItem.put("text", item.get("text"));
+					resultItem.put("code", item.get("code"));
+					resultItem.put("humidity", item.get("humidity"));
+					resultItem.put("windDirection", item.get("wind_direction"));
+					resultItem.put("windSpeed", item.get("wind_speed"));
+					resultItem.put("time", hourTime.getTime());
+					
+					resultList.add(resultItem);
+				}
+			}
+		} catch (Exception e) {
+			throw new Exception(Const.ErrorTag.service3rd);
+		}
+		
+		return resultList;
+	}
+}

+ 3 - 0
src/main/java/com/persagy/functions/weather/business/v2021/QueryPresent.java

@@ -15,6 +15,9 @@ import com.persagy.framework.util.WServiceUtil;
 import com.persagy.functions.weather.constant.Const;
 import com.persagy.functions.weather.service.HourRecordService;
 
+/**
+ * 实时数据
+ */
 @Service("present")
 public class QueryPresent implements RequestProcessor {
 	@Resource

+ 103 - 0
src/main/java/com/persagy/functions/weather/business/v2021/QueryStatisticDay.java

@@ -0,0 +1,103 @@
+package com.persagy.functions.weather.business.v2021;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Service;
+
+import com.persagy.core.enumeration.SpecialOperator;
+import com.persagy.core.utils.DateUtils;
+import com.persagy.ems.pojo.wz.DayStaticMoreRecord;
+import com.persagy.ems.pojo.wz.DayStaticRecord;
+import com.persagy.framework.construct.RequestProcessor;
+import com.persagy.framework.dto.DataQueryParam;
+import com.persagy.framework.util.ConfigUtil;
+import com.persagy.functions.weather.constant.Const;
+import com.persagy.functions.weather.service.DayStaticService;
+
+/**
+ * 日统计数据
+ */
+@Service("statisticDay")
+public class QueryStatisticDay implements RequestProcessor {
+	@Resource
+	private DayStaticService dayStaticService;
+
+	@Override
+	public Object handle(DataQueryParam param) throws Exception {
+		List<Map<String, Object>> resultList = new ArrayList<>();
+		
+		String location = ConfigUtil.getHourCity(param.cityName, param.cityCode, param.projectId);
+		if(null == location) {
+			throw new Exception(Const.ErrorTag.cityUnsupport);
+		}
+		
+		if(param.timeSpanCheck(366 * 3)) {
+			Date startDay = param.timeSpan.timeLeft;
+			Date endDay = param.timeSpan.timeRight;
+			if(param.timeSpan.optLeft == SpecialOperator.$gt) {
+				startDay = DateUtils.getDayOff(startDay, 1);
+			}
+			if(param.timeSpan.optRight == SpecialOperator.$lte) {
+				endDay = DateUtils.getDayOff(endDay, 1);
+			}
+			
+			Map<Date, DayStaticRecord> maxMap = new HashMap<>();
+			List<DayStaticRecord> listMax = dayStaticService.query(location, startDay, endDay);
+			if(null != listMax) {
+				for(DayStaticRecord obj : listMax) {
+					maxMap.put(obj.getDayTime(), obj);
+				}
+			}
+			
+			Map<Date, DayStaticMoreRecord> avgMap = new HashMap<>();
+			List<DayStaticMoreRecord> listAvg = dayStaticService.queryMore(location, startDay, endDay);
+			if(null != listAvg) {
+				for(DayStaticMoreRecord obj : listAvg) {
+					avgMap.put(obj.getDayTime(), obj);
+				}
+			}
+			
+			Date timeKey = startDay;
+			while(timeKey.before(endDay)) {
+				DayStaticRecord maxObj = maxMap.get(timeKey);
+				DayStaticMoreRecord avgObj = avgMap.get(timeKey);
+				
+				Map<String, Object> item = new HashMap<>();
+				resultList.add(item);
+				item.put("time", timeKey.getTime());
+				if(null != maxObj) {
+					item.put("maxHumidity", maxObj.getMaxHumidity());
+					item.put("maxPressure", maxObj.getMaxPressure());
+					item.put("maxTemp", maxObj.getMaxTemp());
+					item.put("maxVisibility", maxObj.getMaxVisibility());
+					item.put("maxWindSpeed", maxObj.getMaxWindSpeed());
+					item.put("minHumidity", maxObj.getMinHumidity());
+					item.put("minPressure", maxObj.getMinPressure());
+					item.put("minTemp", maxObj.getMinTemp());
+					item.put("minVisibility", maxObj.getMinVisibility());
+					item.put("minWindSpeed", maxObj.getMinWindSpeed());
+				}
+				if(avgObj != null) {
+					item.put("avgHumidity", avgObj.getAvgHumidity());
+					item.put("avgPressure", avgObj.getAvgPressure());
+					item.put("avgTemp", avgObj.getAvgTemp());
+					item.put("avgVisibility", avgObj.getAvgVisibility());
+					item.put("avgWindSpeed", avgObj.getAvgWindSpeed());
+				}
+				
+				timeKey = DateUtils.getDayOff(timeKey, 1);
+			}
+		}else {
+			throw new Exception(Const.ErrorTag.timeToLong);
+		}
+		
+		return resultList;
+	}
+	
+}

+ 6 - 2
src/main/java/com/persagy/functions/weather/constant/Const.java

@@ -69,12 +69,16 @@ public class Const {
 	}
 	
 	public static class ErrorTag {
-		public static String paramMis = "required parameters missing";
+		public static String paramMis = "necessary parameters missing";
 		public static String paramFormat = "parameter format error";
 		public static String paramUnrecognized = "unrecognized parameter value";
 		public static String paramValueError = "parameter value error";
-		public static String timeToLong = "time between start and end is too long";
+		public static String timeToLong = "time span is too long";
+		public static String timeEndBeforeStart = "timeStart > timeEnd";
+		public static String timeSpanLack = "timeStart or timeEnd is unidentified";
 		public static String cityNotFound = "can not find the right city";
 		public static String cityUnsupport = "city unsupported";
+		public static String service3rd = "3rd service error";
+		public static String service = "dao service error";
 	}
 }

+ 1 - 0
src/main/java/com/persagy/functions/weather/service/DayHisRecordService.java

@@ -5,6 +5,7 @@ import java.util.List;
 
 import com.persagy.ems.pojo.wz.DayHisRecord;
 import com.persagy.ems.pojo.wz.DayPredictRecord;
+import com.persagy.framework.dto.TimeSpanCondition;
 import com.persagy.functions.weather.dto.DayPredictDTO;
 
 public interface DayHisRecordService {

+ 3 - 0
src/main/java/com/persagy/functions/weather/service/HourRecordService.java

@@ -4,6 +4,7 @@ import java.util.Date;
 import java.util.List;
 
 import com.persagy.ems.pojo.wz.HourRecordData;
+import com.persagy.framework.dto.TimeSpanCondition;
 
 public interface HourRecordService {
 	public void deleteOneDayOfCity(String cityId, Date dayDate) throws Exception;
@@ -15,6 +16,8 @@ public interface HourRecordService {
 	public void saveBatch(List<HourRecordData> list) throws Exception;
 	
 	public List<HourRecordData> query(String cityId, Date start, Date end) throws Exception;
+	
+	public List<HourRecordData> query(String cityId, TimeSpanCondition timeCondition) throws Exception;
 
 	public List<HourRecordData> queryForRightHour(String cityId, Date hourTime) throws Exception;
 }

+ 14 - 0
src/main/java/com/persagy/functions/weather/service/impl/HourRecordServiceImpl.java

@@ -11,6 +11,7 @@ import com.persagy.core.enumeration.EMSOrder;
 import com.persagy.core.enumeration.SpecialOperator;
 import com.persagy.core.mvc.service.CoreService;
 import com.persagy.ems.pojo.wz.HourRecordData;
+import com.persagy.framework.dto.TimeSpanCondition;
 import com.persagy.framework.util.ConfigUtil;
 import com.persagy.framework.util.DateUtils;
 import com.persagy.functions.weather.service.HourRecordService;
@@ -87,4 +88,17 @@ public class HourRecordServiceImpl implements HourRecordService {
 	    return null;
 	}
 
+	@Override
+	public List<HourRecordData> query(String cityId, TimeSpanCondition timeCondition) throws Exception {
+		HourRecordData queryObj = new HourRecordData();
+	    queryObj.setCityId(cityId);
+	    queryObj.setBuildingForContainer(ConfigUtil.getComputeStr(cityId));
+	    
+	    queryObj.setSpecialOperation("hourTime", timeCondition.optLeft, timeCondition.timeLeft);
+	    queryObj.setSpecialOperation("hourTime", timeCondition.optRight, timeCondition.timeRight);
+	    
+	    return this.coreService.query(queryObj);
+	}
+
+
 }

+ 1 - 1
src/main/resources/config/schema.json

@@ -1,5 +1,5 @@
 {
-    "ems": "ems_dev",
+    "ems": "persagy_weather",
     "emsvdata": "emsvdata_dev",
     "udm": "db_udm",
     "objectdata": "db_public",