| | |
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Collection;
|
| | | import java.util.Collections;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | |
| | | import com.moral.entity.Area;
|
| | | import com.moral.entity.AreaNames;
|
| | | import com.moral.entity.City;
|
| | | import com.moral.entity.Device;
|
| | | import com.moral.entity.MonitorPoint;
|
| | | import com.moral.entity.Organization;
|
| | | import com.moral.entity.Province;
|
| | | import com.moral.mapper.AreaMapper;
|
| | | import com.moral.mapper.CityMapper;
|
| | | import com.moral.mapper.DeviceMapper;
|
| | | import com.moral.mapper.ForecastWeatherMapper;
|
| | | import com.moral.mapper.HangzhouAqiMapper;
|
| | | import com.moral.mapper.HistoryHourlyMapper;
|
| | | import com.moral.mapper.MonitorPointMapper;
|
| | | import com.moral.mapper.ProvinceMapper;
|
| | | import com.moral.mapper.RealTimeWeatherMapper;
|
| | | import com.moral.mapper.RealWeatherMapper;
|
| | | import com.moral.service.OrganizationService;
|
| | | import com.moral.service.WeatherService;
|
| | |
|
| | |
| | | private ProvinceMapper provinceMapper;
|
| | |
|
| | | @Resource
|
| | | private RealTimeWeatherMapper realTimeWeatherMapper;
|
| | | private RealWeatherMapper realWeatherMapper;
|
| | |
|
| | | @Resource
|
| | | private DeviceMapper deviceMapper;
|
| | |
|
| | | @Resource
|
| | | private HistoryHourlyMapper historyHourlyMapper;
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getWeatherDataByRegion(Map<String, Object> parameters) {
|
| | |
| | | parameters.put("start", sdf.parse(time));
|
| | | parameters.put("end", sdf.parse(nextDay));
|
| | | List<Map<String, Object>> forecastList = forecastWeatherMapper.getForecastHour(parameters);
|
| | |
|
| | | MonitorPoint monitorPoint = monitorPointMapper.selectByPrimaryKey(Integer.valueOf(monitorPointId));
|
| | | parameters.put("areaCode", monitorPoint.getAreaCode());
|
| | | String sensors = "O3C";
|
| | |
| | | parameters.put("areaCode", monitorPoint.getCityCode());
|
| | | aqiList = hangzhouAqiMapper.getAqiDataByAreaCode(parameters);
|
| | | }
|
| | |
|
| | | for (Map<String, Object> map : aqiList) {
|
| | | String O3 = map.get("O3").toString().replace("\"", "");
|
| | | map.put("O3", O3);
|
| | |
| | | hour = "24";
|
| | | }
|
| | | map.put("time", Integer.valueOf(hour));
|
| | | values.add(forecastMap.get("result").toString().replace("\"", ""));
|
| | | if (forecastMap.get("result") != null) {
|
| | | values.add(forecastMap.get("result").toString().replace("\"", ""));
|
| | | } else {
|
| | | values.add("");
|
| | | }
|
| | | values.add("");
|
| | | map.put("values", values);
|
| | | resultList.add(map);
|
| | |
| | | hour = "24";
|
| | | }
|
| | | map.put("time", Integer.valueOf(hour));
|
| | | values.add(forecastMap.get("result").toString().replace("\"", ""));
|
| | | if (forecastMap.get("result") != null) {
|
| | | values.add(forecastMap.get("result").toString().replace("\"", ""));
|
| | | } else {
|
| | | values.add("");
|
| | | }
|
| | | for (Map<String, Object> aqiMap : aqiList) {
|
| | | if (forecastMap.get("time").equals(aqiMap.get("time"))) {
|
| | | values.add(aqiMap.get(sensor1).toString());
|
| | |
| | | parameters.put("monitorPointId", monitorPoint.getId());
|
| | | String time = parameters.get("time").toString();
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | | Date now = new Date();
|
| | | Date selectTime = sdf1.parse(time + " 00:00:00");
|
| | | Calendar c1 = Calendar.getInstance();
|
| | | c1.setTime(selectTime);
|
| | | c1.add(Calendar.DAY_OF_MONTH, -1);
|
| | | Date beforeDay = c1.getTime();
|
| | | String format = sdf.format(beforeDay);
|
| | | Calendar c = Calendar.getInstance();
|
| | | c.setTime(sdf.parse(time));
|
| | | c.add(Calendar.HOUR_OF_DAY, 1);
|
| | |
| | | parameters.put("start", start);
|
| | | parameters.put("end", end);
|
| | | List<Map<String, Object>> forecastList = forecastWeatherMapper.getForecast(parameters);
|
| | | List<Map<String, Object>> foreList = new ArrayList<>();
|
| | | for (Map<String, Object> map : forecastList) {
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("time", map.get("time").toString());
|
| | | hashMap.put("type", "预测");
|
| | | hashMap.put("TVOC", "");
|
| | | hashMap.put("altitude", "");
|
| | | hashMap.put("vegetation", "");
|
| | | hashMap.put("AQI", "");
|
| | | hashMap.put("SO2C", "");
|
| | | hashMap.put("NO2C", "");
|
| | | hashMap.put("COC", "");
|
| | | hashMap.put("O3C", "");
|
| | | hashMap.put("PM25C", "");
|
| | | hashMap.put("PM10C", "");
|
| | | hashMap.put("city", parameters.get("city").toString());
|
| | |
|
| | | if (selectTime.getTime() <= now.getTime()) {
|
| | | hashMap.put("fxTime", (format + " 15:00").substring(5, 16));
|
| | | } else {
|
| | | String s = sdf1.format(now).split(" ")[1].split(":")[0];
|
| | | Integer hour = Integer.valueOf(s);
|
| | | if (hour > 15) {
|
| | | hashMap.put("fxTime", (format + " 15:00").substring(5, 16));
|
| | | } else if (hour > 7 && hour < 15) {
|
| | | hashMap.put("fxTime", (format + " 07:00").substring(5, 16));
|
| | | }
|
| | | }
|
| | | Map<String, Object> jsonMap = (Map<String, Object>) JSONObject.parse(map.get("json").toString());
|
| | | hashMap.putAll(jsonMap);
|
| | | foreList.add(hashMap);
|
| | | }
|
| | |
|
| | | for (Map<String, Object> foreMap : foreList) {
|
| | | String ftime = foreMap.get("time").toString();
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | Date endTime = sdf1.parse(ftime);
|
| | | calendar.setTime(endTime);
|
| | | calendar.add(Calendar.HOUR, -6);
|
| | | Date startTime = calendar.getTime();
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("areaCode", Integer.valueOf(parameters.get("areaCode").toString()));
|
| | | hashMap.put("start", startTime);
|
| | | hashMap.put("end", endTime);
|
| | | hashMap.put("monitorPointId", Integer.valueOf(parameters.get("monitorPointId").toString()));
|
| | | Map<String, Object> precip6HourMap = forecastWeatherMapper.getPrecip6Hour(hashMap);
|
| | | if (precip6HourMap != null) {
|
| | | foreMap.put("precip6", precip6HourMap.get("precip6").toString());
|
| | | }
|
| | | }
|
| | |
|
| | | List<Map<String, Object>> aqiList = hangzhouAqiMapper.getAqi(parameters);
|
| | | if (aqiList.size() == 0) {
|
| | | parameters.put("areaCode", cityCode);
|
| | | aqiList = hangzhouAqiMapper.getAqi(parameters);
|
| | | }
|
| | | List<Map<String, Object>> list1 = new ArrayList<>();
|
| | | for (Map<String, Object> map : aqiList) {
|
| | |
|
| | | List<Map<String, Object>> realAqilist = new ArrayList<>();
|
| | | for (Map<String, Object> aqiMap : aqiList) {
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("time", map.get("time"));
|
| | | Map<String, Object> jsonMap = (Map<String, Object>) JSONObject.parse(map.get("json").toString());
|
| | | hashMap.put("time", aqiMap.get("time"));
|
| | | Map<String, Object> jsonMap = (Map<String, Object>) JSONObject.parse(aqiMap.get("json").toString());
|
| | | hashMap.putAll(jsonMap);
|
| | | hashMap.put("city", parameters.get("city").toString());
|
| | | list1.add(hashMap);
|
| | | realAqilist.add(hashMap);
|
| | | }
|
| | |
|
| | | List<Map<String, Object>> realTimeList = realTimeWeatherMapper.getRealTimeWeather(parameters);
|
| | | List<Map<String, Object>> realList = new ArrayList<>();
|
| | | for (Map<String, Object> map : realTimeList) {
|
| | | for (Map<String, Object> map : realAqilist) {
|
| | | Date endTime = sdf1.parse(map.get("time").toString());
|
| | | c.setTime(endTime);
|
| | | c.add(Calendar.HOUR, -8);
|
| | | Date startTime = c.getTime();
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("time", map.get("time"));
|
| | | hashMap.put("type", "实际");
|
| | | hashMap.put("city", parameters.get("city").toString());
|
| | | Map<String, Object> jsonMap = (Map<String, Object>) JSONObject.parse(map.get("json").toString());
|
| | | hashMap.putAll(jsonMap);
|
| | | realList.add(hashMap);
|
| | | hashMap.put("areaCode", Integer.valueOf(parameters.get("areaCode").toString()));
|
| | | hashMap.put("start", startTime);
|
| | | hashMap.put("end", endTime);
|
| | | Map<String, Object> O3Map = hangzhouAqiMapper.getAvgO3EightHours(hashMap);
|
| | | map.put("O3_8H", O3Map.get("O3_8H").toString());
|
| | | if (O3Map.get("O3C_8H") != null) {
|
| | | map.put("O3C_8H", O3Map.get("O3C_8H").toString());
|
| | | }
|
| | | }
|
| | |
|
| | | for (Map<String, Object> realTimeMap : realList) {
|
| | | for (Map<String, Object> aqiMap : list1) {
|
| | | if (aqiMap.get("time").equals(realTimeMap.get("time"))) {
|
| | | realTimeMap.putAll(aqiMap);
|
| | | //光照
|
| | | String code = parameters.get("areaCode").toString();
|
| | | Map<String, Object> params = new HashMap<>();
|
| | | if (code.endsWith("00")) {
|
| | | params.put("cityCode", Integer.valueOf(code));
|
| | | } else {
|
| | | params.put("areaCode", Integer.valueOf(code));
|
| | | }
|
| | |
|
| | | List<MonitorPoint> monitorList = monitorPointMapper.getMonitorList(params);
|
| | |
|
| | | List<Integer> pointList = new ArrayList<>();
|
| | | for (MonitorPoint point : monitorList) {
|
| | | Integer pointId = point.getId();
|
| | | pointList.add(pointId);
|
| | | }
|
| | |
|
| | | List<Device> deviceList = deviceMapper.getDeviceListByMonitorPointIds(pointList);
|
| | | List<String> macList = new ArrayList<>();
|
| | | List<Map<String, Object>> beamList = new ArrayList<>();
|
| | | if (deviceList.size() != 0) {
|
| | | for (Device device : deviceList) {
|
| | | String mac = device.getMac();
|
| | | macList.add(mac);
|
| | | }
|
| | |
|
| | | parameters.put("macs", macList);
|
| | | beamList = historyHourlyMapper.getBeamByMacs(parameters);
|
| | | }
|
| | |
|
| | |
|
| | | List<Map<String, Object>> realList = realWeatherMapper.getRealWeather(parameters);
|
| | | List<Map<String, Object>> realWeatherList = new ArrayList<>();
|
| | | for (Map<String, Object> realMap : realList) {
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("time", realMap.get("time"));
|
| | | Map<String, Object> jsonMap = (Map<String, Object>) JSONObject.parse(realMap.get("json").toString());
|
| | | hashMap.putAll(jsonMap);
|
| | | hashMap.put("city", parameters.get("city").toString());
|
| | | realWeatherList.add(hashMap);
|
| | | }
|
| | |
|
| | | for (Map<String, Object> realMap : realWeatherList) {
|
| | | String rtime = realMap.get("time").toString();
|
| | | for (Map<String, Object> beamMap : beamList) {
|
| | | String btime = beamMap.get("time").toString();
|
| | | if (btime.equals(rtime)) {
|
| | | realMap.put("beam", beamMap.get("beam").toString().split("\\.")[0]);
|
| | | }
|
| | | }
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | Date endTime = sdf1.parse(rtime);
|
| | | calendar.setTime(endTime);
|
| | | calendar.add(Calendar.HOUR, -6);
|
| | | Date startTime = calendar.getTime();
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("areaCode", Integer.valueOf(parameters.get("areaCode").toString()));
|
| | | hashMap.put("start", startTime);
|
| | | hashMap.put("end", endTime);
|
| | | hashMap.put("monitorPointId", Integer.valueOf(parameters.get("monitorPointId").toString()));
|
| | | Map<String, Object> precip6HourMap = realWeatherMapper.getPrecip6Hour(hashMap);
|
| | | realMap.put("precip6", precip6HourMap.get("precip6").toString());
|
| | | }
|
| | |
|
| | | List<Map<String, Object>> list = new ArrayList<>();
|
| | | for (int i = 0; i < 24; i++) {
|
| | | list.add(null);
|
| | | }
|
| | |
|
| | | for (Map<String, Object> map : realWeatherList) {
|
| | | Integer t1 = Integer.valueOf(map.get("time").toString().split(" ")[1].split(":")[0]);
|
| | | if (t1 == 0) {
|
| | | list.set(list.size() - 1, map);
|
| | | } else {
|
| | | list.set(t1 - 1, map);
|
| | | }
|
| | | }
|
| | |
|
| | | for (Map<String, Object> map : realAqilist) {
|
| | | Integer t1 = Integer.valueOf(map.get("time").toString().split(" ")[1].split(":")[0]);
|
| | | if (t1 == 0) {
|
| | | Map<String, Object> map1 = list.get(list.size() - 1);
|
| | | if (map1 == null) {
|
| | | list.set(list.size() - 1, map);
|
| | | } else {
|
| | | map1.putAll(map);
|
| | | list.set(list.size() - 1, map1);
|
| | | }
|
| | | } else {
|
| | | Map<String, Object> map1 = list.get(t1 - 1);
|
| | | if (map1 == null) {
|
| | | list.set(t1 - 1, map);
|
| | | } else {
|
| | | map1.putAll(map);
|
| | | list.set(t1 - 1, map1);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | List<Map<String, Object>> foreList = new ArrayList<>();
|
| | | for (Map<String, Object> forecastMap : forecastList) {
|
| | | Map<String, Object> jsonMap = (Map<String, Object>) JSONObject.parse(forecastMap.get("json").toString());
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("temp", jsonMap.get("tem"));
|
| | | hashMap.put("windDir", jsonMap.get("win"));
|
| | | hashMap.put("windLevel", jsonMap.get("win_speed"));
|
| | | hashMap.put("condition", jsonMap.get("wea"));
|
| | | hashMap.put("time", forecastMap.get("time").toString());
|
| | | hashMap.put("type", "预测");
|
| | | hashMap.put("city", parameters.get("city").toString());
|
| | | foreList.add(hashMap);
|
| | |
|
| | | list.removeAll(Collections.singleton(null));
|
| | |
|
| | |
|
| | | for (Map<String, Object> map : list) {
|
| | | map.put("type", "实测");
|
| | | map.put("city", parameters.get("city").toString());
|
| | | }
|
| | |
|
| | | List<Map<String, Object>> resultList = new ArrayList<>();
|
| | |
|
| | | for (Map<String, Object> foreMap : foreList) {
|
| | | for (Map<String, Object> realMap : realList) {
|
| | | for (Map<String, Object> realMap : list) {
|
| | | if (foreMap.get("time").equals(realMap.get("time"))) {
|
| | | resultList.add(foreMap);
|
| | | resultList.add(realMap);
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | for (int i = realList.size(); i < forecastList.size(); i++) {
|
| | | for (int i = list.size(); i < foreList.size(); i++) {
|
| | | Map<String, Object> map = foreList.get(i);
|
| | | resultList.add(map);
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("time", map.get("time").toString());
|
| | | hashMap.put("type", "实际");
|
| | | hashMap.put("type", "实测");
|
| | | hashMap.put("city", parameters.get("city").toString());
|
| | | resultList.add(hashMap);
|
| | | }
|
| | |
|
| | | for (Map<String, Object> map : resultList) {
|
| | | String date = map.get("time").toString().substring(0, 16);
|
| | | map.put("time", date);
|
| | | if (map.get("AQI") != null) {
|
| | | String aqi = map.get("AQI").toString().split("\\.")[0];
|
| | | map.put("AQI", aqi);
|
| | | }
|
| | | if (map.get("precip") != null) {
|
| | | String aqi = map.get("precip").toString();
|
| | | if (aqi.equals("0.0")) {
|
| | | map.put("precip", "");
|
| | | }
|
| | | }
|
| | | if (map.get("precip6") != null) {
|
| | | String aqi = map.get("precip6").toString();
|
| | | if (aqi.equals("0.0")) {
|
| | | map.put("precip6", "");
|
| | | }
|
| | | }
|
| | | }
|
| | | return resultList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void updateForecastWeather(Map<String, Object> parameters) {
|
| | | List<Integer> list = new ArrayList<>();
|
| | | List<Map<String, Object>> resultList = new ArrayList<>();
|
| | | for (int i = 0; i < 48; i++) {
|
| | | list.add(i);
|
| | | resultList.add(null);
|
| | | }
|
| | | for (Integer s : list) {
|
| | | Map<String, Object> map = new HashMap<>();
|
| | | for (String key : parameters.keySet()) {
|
| | | String replace = key.split("\\[")[0];
|
| | | if (replace.equals(s + "")) {
|
| | | String ss = key.split("\\[")[1].replace("]", "");
|
| | | map.put(ss, parameters.get(key).toString());
|
| | | }
|
| | | }
|
| | | resultList.set(s, map);
|
| | | }
|
| | | for (Map<String, Object> map : resultList) {
|
| | | if (map.get("type").equals("预测")) {
|
| | | String time = map.get("time").toString() + ":00";
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("time", time);
|
| | | String city = map.get("city").toString();
|
| | | Area area = areaMapper.getAreaByName(city);
|
| | | Map<String, Object> idMap = new HashMap<>();
|
| | | if (area == null) {
|
| | | Integer cityCode = cityMapper.getCityByName(city).getCityCode();
|
| | | idMap.put("cityCode", cityCode);
|
| | | } else {
|
| | | Integer areaCode = area.getAreaCode();
|
| | | idMap.put("areaCode", areaCode);
|
| | | }
|
| | |
|
| | | List<MonitorPoint> monitorList = monitorPointMapper.getMonitorList(idMap);
|
| | | Map<String, Object> jsonMap = new HashMap<>();
|
| | | for (String key : map.keySet()) {
|
| | | if (!key.equals("city") && !key.equals("time") && !key.equals("type") && !key.equals("fxTime")) {
|
| | | String value = map.get(key).toString();
|
| | | jsonMap.put(key, value);
|
| | | }
|
| | | }
|
| | |
|
| | | String json = JSONObject.toJSONString(jsonMap);
|
| | | hashMap.put("json", json);
|
| | | for (MonitorPoint monitorPoint : monitorList) {
|
| | | hashMap.put("monitorPointId", monitorPoint.getId());
|
| | | forecastWeatherMapper.updateForecastWeather(hashMap);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|