Kaynağa Gözat

补充java对象

cuixubin 4 yıl önce
ebeveyn
işleme
6acfd2b1ec

+ 83 - 0
src/main/java/com/persagy/framework/dto/DataQueryParam.java

@@ -0,0 +1,83 @@
+package com.persagy.framework.dto;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.persagy.core.enumeration.SpecialOperator;
+import com.persagy.framework.util.DateUtils;
+
+public class DataQueryParam {
+	public String cityName;
+	public String projectId;
+	public String cityCode;
+	public Double longitude;
+	public Double latitude;
+	public Date time;
+	public TimeSpanCondition timeSpan;
+	public Map<String, String> fieldEqualMap = new HashMap<>();
+
+	
+	public DataQueryParam(Map<String, Object> paramMap) throws Exception {
+		cityName = (String) paramMap.get("cityName");
+		projectId = (String) paramMap.get("projectId");
+		cityCode = (String) paramMap.get("cityCode");
+		longitude = (Double) paramMap.get("longitude");
+		latitude = (Double) paramMap.get("latitude");
+		
+		if(cityCheck()) {
+			throw new Exception("参数缺少城市信息");
+		}
+		
+		Object timeObj = paramMap.get("time");
+		if(timeObj == null) {
+			throw new Exception("参数缺少时间信息");
+		}else {
+			try {
+				if(timeObj instanceof Map) {
+					Map<String, Object> timeSpanMap = (Map<String, Object>) timeObj;
+					
+					timeSpan = new TimeSpanCondition();
+					if(timeSpanMap.containsKey("$gte")) {
+						timeSpan.optLeft = SpecialOperator.$gte;
+						timeSpan.timeLeft = DateUtils.long2Date((long) timeSpanMap.get("$gte"));
+					}else if(timeSpanMap.containsKey("$gt")) {
+						timeSpan.optLeft = SpecialOperator.$gt;
+						timeSpan.timeLeft = DateUtils.long2Date((long) timeSpanMap.get("$gt"));
+					}else {
+						throw new Exception("时间区间不完整。");
+					}
+
+					if(timeSpanMap.containsKey("$lt")) {
+						timeSpan.optRight = SpecialOperator.$lt;
+						timeSpan.timeRight = DateUtils.long2Date((long) timeSpanMap.get("$lt"));
+					}else if(timeSpanMap.containsKey("$lte")) {
+						timeSpan.optRight = SpecialOperator.$lte;
+						timeSpan.timeRight = DateUtils.long2Date((long) timeSpanMap.get("$lte"));
+					}else {
+						throw new Exception("时间区间不完整。");
+					}
+					
+					if(!timeSpan.timeLeft.before(timeSpan.timeRight)) {
+						throw new Exception("时间跨度异常。");
+					}
+				}else if(timeObj instanceof Long) {
+					time = DateUtils.long2Date((long) timeObj);
+				}else {
+					throw new Exception("时间参数格式错误");
+				}
+			}catch (Exception e) {
+				throw new Exception("时间参数不合法。" + e.getMessage());
+			}
+		}
+	}
+	
+	/**
+	 * 判断城市信息参数是否全为null
+	 * @return
+	 */
+	public boolean cityCheck() {
+		return cityName==null && projectId==null && cityCode==null && (longitude==null || latitude==null);
+	}
+	
+}

+ 28 - 0
src/main/java/com/persagy/framework/dto/TimeSpanCondition.java

@@ -0,0 +1,28 @@
+package com.persagy.framework.dto;
+
+import java.util.Date;
+
+import com.persagy.core.enumeration.SpecialOperator;
+
+public class TimeSpanCondition {
+	public static SpecialOperator getOptLeft(String optStr) {
+		if("$lt".equals(optStr)) {
+			return SpecialOperator.$lt;
+		}else if("$lte".equals(optStr)) {
+			return SpecialOperator.$lte;
+		}
+		return null;
+	}
+	public static SpecialOperator getOptRight(String optStr) {
+		if("$gte".equals(optStr)) {
+			return SpecialOperator.$gte;
+		}else if("$gt".equals(optStr)) {
+			return SpecialOperator.$gt;
+		}
+		return null;
+	}
+	public Date timeLeft;
+	public SpecialOperator optLeft;
+	public Date timeRight;
+	public SpecialOperator optRight;
+}

+ 17 - 0
src/main/java/com/persagy/framework/dto/WeatherItemConfig.java

@@ -0,0 +1,17 @@
+package com.persagy.framework.dto;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class WeatherItemConfig {
+	private List<WeatherItemDTO> items = new ArrayList<>();
+
+	public List<WeatherItemDTO> getItems() {
+		return items;
+	}
+
+	public void setItems(List<WeatherItemDTO> items) {
+		this.items = items;
+	}
+	
+}

+ 42 - 0
src/main/java/com/persagy/framework/dto/WeatherItemDTO.java

@@ -0,0 +1,42 @@
+package com.persagy.framework.dto;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 气象指标
+ */
+public class WeatherItemDTO {
+	// 指标名
+	private String name;
+	// 指标编码
+	private String code;
+	// 单位说明
+	private String unitDescription;
+	// 所属数据类型编码集合
+	private List<String> dataTypeBelong = new ArrayList<>();
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	public String getCode() {
+		return code;
+	}
+	public void setCode(String code) {
+		this.code = code;
+	}
+	public String getUnitDescription() {
+		return unitDescription;
+	}
+	public void setUnitDescription(String unitDescription) {
+		this.unitDescription = unitDescription;
+	}
+	public List<String> getDataTypeBelong() {
+		return dataTypeBelong;
+	}
+	public void setDataTypeBelong(List<String> dataTypeBelong) {
+		this.dataTypeBelong = dataTypeBelong;
+	}
+}

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

@@ -0,0 +1,105 @@
+package com.persagy.functions.weather.business.v2021;
+
+import java.util.HashMap;
+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.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
+	private HourRecordService hourDataService;
+
+	@Override
+	public Object handle(DataQueryParam param) throws Exception {
+		Map<String, Object> resultMap = new HashMap<>();
+		String location = ConfigUtil.getHourCity(param.cityName, param.cityCode, param.projectId);
+		
+		if(null != location) {
+			HourRecordData obj = hourDataService.getPresent(location);
+			if(null != obj) {
+				resultMap.put("no2", obj.getNo2());
+				resultMap.put("pm25", obj.getPm25());
+				resultMap.put("o3", obj.getO3());
+				resultMap.put("so2", obj.getSo2());
+				resultMap.put("aqi", obj.getAqi());
+				resultMap.put("pm10", obj.getPm10());
+				resultMap.put("primaryPollutant", obj.getPrimary_pollutant());
+				resultMap.put("co", obj.getCo());
+				resultMap.put("quality", obj.getQuality());
+				
+				resultMap.put("code", obj.getCode());
+				resultMap.put("visibility", obj.getVisibility());
+				resultMap.put("windDirection", obj.getWind_direction());
+				resultMap.put("pressure", obj.getPressure());
+				resultMap.put("clouds", obj.getClouds());
+				resultMap.put("feelsLike", obj.getFeels_like());
+				resultMap.put("windScale", obj.getWind_scale());
+				resultMap.put("temperature", obj.getTemperature());
+				resultMap.put("humidity", obj.getHumidity());
+				resultMap.put("windDirectionDegree", obj.getWind_direction_degree());
+				resultMap.put("windSpeed", obj.getWind_speed());
+				resultMap.put("text", obj.getText());
+			}
+		}
+		
+		if(resultMap.isEmpty()) {
+			// 若查不到最新的小时数据,则直接访问第三方实时天气数据API
+			
+			location = ConfigUtil.getLocation(param.cityName, param.cityCode, param.projectId);
+			if(null != location) {
+				try {
+					Map<String, Object> dataMap = WServiceUtil.getNowAir(location);
+					if (!dataMap.isEmpty()) {
+						resultMap.put("no2", dataMap.get("no2"));
+						resultMap.put("pm25", dataMap.get("pm25"));
+						resultMap.put("o3", dataMap.get("o3"));
+						resultMap.put("so2", dataMap.get("so2"));
+						resultMap.put("aqi", dataMap.get("aqi"));
+						resultMap.put("pm10", dataMap.get("pm10"));
+						resultMap.put("primaryPollutant", dataMap.get("primary_pollutant"));
+						resultMap.put("co", dataMap.get("co"));
+						resultMap.put("quality", dataMap.get("quality"));
+					}
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+				
+				try {
+					Map<String, Object> dataMap = WServiceUtil.getNowWeather(location);
+					if (!dataMap.isEmpty()) {
+						resultMap.put("text", dataMap.get("text"));
+						resultMap.put("code", dataMap.get("code"));
+						resultMap.put("temperature", dataMap.get("temperature"));
+						resultMap.put("feelsLike", dataMap.get("feels_like"));
+						resultMap.put("pressure", dataMap.get("pressure"));
+						resultMap.put("humidity", dataMap.get("humidity"));
+						resultMap.put("visibility", dataMap.get("visibility"));
+						resultMap.put("windDirection", dataMap.get("wind_direction"));
+						resultMap.put("windDirectionDegree", dataMap.get("wind_direction_degree"));
+						resultMap.put("windSpeed", dataMap.get("wind_speed"));
+						resultMap.put("windScale", dataMap.get("wind_scale"));
+						resultMap.put("clouds", dataMap.get("clouds"));
+					}
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}else {
+				throw new Exception(Const.ErrorTag.cityNotFound);
+			}
+		}
+		
+		return resultMap;
+	}
+
+}

+ 5 - 0
src/main/java/com/persagy/functions/weather/dto/DataQueryParamBase.java

@@ -0,0 +1,5 @@
+package com.persagy.functions.weather.dto;
+
+public class DataQueryParamBase {
+
+}

+ 274 - 0
src/main/resources/config/business/weatherItem.json

@@ -0,0 +1,274 @@
+{
+    "items":[
+	    {
+		    "name":"气温实时值",
+		    "code":"temperature",
+		    "unitDescription":"c,摄氏度",
+		    "dataTypeBelong":["present", "historyHour", "predictHour"]
+		},
+		{
+		    "name":"体感温度",
+		    "code":"feelsLike",
+		    "unitDescription":"c,摄氏度",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"日最高温度",
+		    "code":"temperatureHigh",
+		    "unitDescription":"c,摄氏度",
+		    "dataTypeBelong":["predictDay", "historyDay"]
+		},
+		{
+		    "name":"日最低温度",
+		    "code":"temperatureLow",
+		    "unitDescription":"c,摄氏度",
+		    "dataTypeBelong":["predictDay", "historyDay"]
+		},
+		{
+		    "name":"统计温度最大值",
+		    "code":"temperatureMax",
+		    "unitDescription":"c,摄氏度",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"统计温度最小值",
+		    "code":"temperatureMin",
+		    "unitDescription":"c,摄氏度",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"统计温度均值",
+		    "code":"temperatureAvg",
+		    "unitDescription":"c,摄氏度",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"相对湿度",
+		    "code":"humidity",
+		    "unitDescription":"数值范围0~100,是百分比值",
+		    "dataTypeBelong":["present", "historyHour", "predictHour", "predictDay", "historyDay"]
+		},
+		{
+		    "name":"统计相对湿度最大值",
+		    "code":"humidityMax",
+		    "unitDescription":"数值范围0~100,是百分比值",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"统计相对湿度最小值",
+		    "code":"humidityMin",
+		    "unitDescription":"数值范围0~100,是百分比值",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"统计相对湿度均值",
+		    "code":"humidityAvg",
+		    "unitDescription":"数值范围0~100,是百分比值",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"气压",
+		    "code":"pressure",
+		    "unitDescription":"单位mbar,百帕",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"统计气压均值",
+		    "code":"pressureAvg",
+		    "unitDescription":"单位mbar,百帕",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"统计气压最大值",
+		    "code":"pressureMax",
+		    "unitDescription":"单位mbar,百帕",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"统计气压最小值",
+		    "code":"pressureMin",
+		    "unitDescription":"单位mbar,百帕",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"能见度",
+		    "code":"visibility",
+		    "unitDescription":"km,千米",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"统计能见度最大值",
+		    "code":"visibilityMax",
+		    "unitDescription":"km,千米",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"统计能见度最小值",
+		    "code":"visibilityMin",
+		    "unitDescription":"km,千米",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"统计能见度均值",
+		    "code":"visibilityAvg",
+		    "unitDescription":"km,千米",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"风速",
+		    "code":"windSpeed",
+		    "unitDescription":"km/h,千米每小时",
+		    "dataTypeBelong":["present", "historyHour", "predictHour", "predictDay", "historyDay"]
+		},
+		{
+		    "name":"统计风速最大值",
+		    "code":"windSpeedMax",
+		    "unitDescription":"km/h,千米每小时",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"统计风速最小值",
+		    "code":"windSpeedMin",
+		    "unitDescription":"km/h,千米每小时",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"统计风速均值",
+		    "code":"windSpeedAvg",
+		    "unitDescription":"km/h,千米每小时",
+		    "dataTypeBelong":["statisticDay"]
+		},
+		{
+		    "name":"风力等级",
+		    "code":"windScale",
+		    "unitDescription":"数值字符,>=0,无单位",
+		    "dataTypeBelong":["present", "historyHour", "predictDay", "historyDay"]
+		},
+		{
+		    "name":"风向文字",
+		    "code":"windDirection",
+		    "unitDescription":"无单位,描述信息,如:西南",
+		    "dataTypeBelong":["present", "historyHour", "predictHour", "predictDay", "historyDay"]
+		},
+		{
+		    "name":"风向角度",
+		    "code":"windDirectionDegree",
+		    "unitDescription":"角度数值,0~360,0为正北,90为正东,180为正南",
+		    "dataTypeBelong":["present", "historyHour", "predictDay", "historyDay"]
+		},
+		{
+		    "name":"降水量",
+		    "code":"rainfall",
+		    "unitDescription":"mm,毫米",
+		    "dataTypeBelong":["predictDay", "historyDay"]
+		},
+		{
+		    "name":"首要污染物",
+		    "code":"primaryPollutant",
+		    "unitDescription":"无单位,字符描述",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"气象文字描述",
+		    "code":"text",
+		    "unitDescription":"阴、晴、雨、雪...,无单位",
+		    "dataTypeBelong":["present", "historyHour", "predictHour"]
+		},
+		{
+		    "name":"白日气象文字描述",
+		    "code":"textDay",
+		    "unitDescription":"阴、晴、雨、雪...,无单位",
+		    "dataTypeBelong":["predictDay", "historyDay"]
+		},
+		{
+		    "name":"夜晚气象文字描述",
+		    "code":"textNight",
+		    "unitDescription":"阴、晴、雨、雪...,无单位",
+		    "dataTypeBelong":["predictDay", "historyDay"]
+		},
+		{
+		    "name":"气象编码",
+		    "code":"code",
+		    "unitDescription":"无单位",
+		    "dataTypeBelong":["present", "historyHour", "predictHour"]
+		},
+		{
+		    "name":"白日气象编码",
+		    "code":"codeDay",
+		    "unitDescription":"无单位",
+		    "dataTypeBelong":["predictDay", "historyDay"]
+		},
+		{
+		    "name":"夜晚气象编码",
+		    "code":"codeNight",
+		    "unitDescription":"无单位",
+		    "dataTypeBelong":["predictDay", "historyDay"]
+		},
+		{
+		    "name":"空气质量文字",
+		    "code":"quality",
+		    "unitDescription":"优、良、轻度污染...,无单位",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"云量",
+		    "code":"clouds",
+		    "unitDescription":"数值,0~100,无单位",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"pm25",
+		    "code":"pm25",
+		    "unitDescription":"1小时平均值。单位:μg/m³",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"pm10",
+		    "code":"pm10",
+		    "unitDescription":"1小时平均值。单位:μg/m³",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"so2",
+		    "code":"so2",
+		    "unitDescription":"1小时平均值。单位:μg/m³",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"no2",
+		    "code":"no2",
+		    "unitDescription":"1小时平均值。单位:μg/m³",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"co",
+		    "code":"co",
+		    "unitDescription":"1小时平均值。单位:μg/m³",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"o3",
+		    "code":"o3",
+		    "unitDescription":"1小时平均值。单位:μg/m³",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"aqi",
+		    "code":"aqi",
+		    "unitDescription":"数值,无单位",
+		    "dataTypeBelong":["present", "historyHour"]
+		},
+		{
+		    "name":"日出时间",
+		    "code":"sunRise",
+		    "unitDescription":"时间戳",
+		    "dataTypeBelong":["sunRiseSet"]
+		},
+		{
+		    "name":"日落时间",
+		    "code":"sunSet",
+		    "unitDescription":"时间戳",
+		    "dataTypeBelong":["sunRiseSet"]
+		}
+	]
+}