| | |
| | | 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.LinkedHashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.apache.jasper.compiler.JspUtil;
|
| | | import org.dom4j.Element;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.ObjectUtils;
|
| | | import org.springframework.web.client.RestTemplate;
|
| | |
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.moral.common.util.Dom4jUtils;
|
| | | import com.moral.common.util.ValidateUtil;
|
| | | 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.RealWeatherMapper;
|
| | | import com.moral.service.OrganizationService;
|
| | | import com.moral.service.WeatherService;
|
| | |
|
| | |
| | | private MonitorPointMapper monitorPointMapper;
|
| | |
|
| | | @Resource
|
| | | private ForecastWeatherMapper forecastWeatherMapper;
|
| | |
|
| | | @Resource
|
| | | private AreaMapper areaMapper;
|
| | |
|
| | | @Resource
|
| | |
| | |
|
| | | @Resource
|
| | | private ProvinceMapper provinceMapper;
|
| | |
|
| | | @Resource
|
| | | private RealWeatherMapper realWeatherMapper;
|
| | |
|
| | | @Resource
|
| | | private DeviceMapper deviceMapper;
|
| | |
|
| | | @Resource
|
| | | private HistoryHourlyMapper historyHourlyMapper;
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getWeatherDataByRegion(Map<String, Object> parameters) {
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> getNextDayWeatherDataByRegion(Map<String, Object> parameters) throws ParseException {
|
| | | public List<Map<String, Object>> getForecastAndReal(Map<String, Object> parameters) throws ParseException {
|
| | | parameters.put("typeFormat", "%Y-%m-%d %H:%i:%s");
|
| | | String monitorPointId = parameters.get("monitorPointId").toString();
|
| | | MonitorPoint monitorPoint = monitorPointMapper.selectByPrimaryKey(Integer.valueOf(monitorPointId));
|
| | | Integer cityCode = monitorPoint.getCityCode();
|
| | | Integer areaCode = monitorPoint.getAreaCode();
|
| | | String name1 = "";
|
| | | String parentName = "";
|
| | | if (areaCode != null) {
|
| | | Area area = areaMapper.selectByPrimaryKey(areaCode);
|
| | | name1 = area.getAreaName();
|
| | | City city = cityMapper.selectByPrimaryKey(area.getCityCode());
|
| | | parentName = city.getCityName();
|
| | | if ("市辖区".equals(area.getAreaName())) {
|
| | | name1 = parentName;
|
| | | parentName = provinceMapper.selectByPrimaryKey(city.getProvinceCode()).getProvinceName();
|
| | | }
|
| | | } else {
|
| | | City city = cityMapper.selectByPrimaryKey(cityCode);
|
| | | name1 = city.getCityName();
|
| | | parentName = provinceMapper.selectByPrimaryKey(city.getProvinceCode()).getProvinceName();
|
| | | }
|
| | | List<Element> elements = Dom4jUtils.readDocument();
|
| | | String cityID = "101190404";
|
| | | for (Element element : elements) {
|
| | | String name2 = element.element("name").getText();
|
| | | if (name1.equals(name2)) {
|
| | | cityID = element.element("Fweathercn").getText();
|
| | | break;
|
| | | }
|
| | | if (name2.endsWith(name1)) {
|
| | | if (name2.startsWith(parentName)) {
|
| | | cityID = element.element("Fweathercn").getText();
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | RestTemplate restTemplate = new RestTemplate();
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | | String time = parameters.get("time").toString() + " 00:00:00";
|
| | | Calendar c = Calendar.getInstance();
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH");
|
| | | String now = sdf.format(c.getTime());
|
| | | String selectTime = parameters.get("time").toString();
|
| | | Date t1 = sdf.parse(selectTime);
|
| | | Date t2 = sdf.parse(now);
|
| | | c.setTime(sdf.parse(time));
|
| | | c.add(Calendar.HOUR_OF_DAY, 1);
|
| | | time = sdf.format(c.getTime());
|
| | | c.add(Calendar.DAY_OF_MONTH, 1);
|
| | | String nextDay = sdf.format(c.getTime());
|
| | | parameters.put("start", sdf.parse(time));
|
| | | parameters.put("end", sdf.parse(nextDay));
|
| | | MonitorPoint monitorPoint = monitorPointMapper.selectByPrimaryKey(Integer.valueOf(monitorPointId));
|
| | | if (monitorPoint.getAreaCode() == null) {
|
| | | parameters.put("cityCode", monitorPoint.getCityCode());
|
| | | } else {
|
| | | parameters.put("cityCode", monitorPoint.getAreaCode());
|
| | | }
|
| | | List<Map<String, Object>> aqiList = hangzhouAqiMapper.getAqiDataByAreaCode(parameters);
|
| | | List<Map<String, Object>> forecastList = forecastWeatherMapper.getForecastHour(parameters);
|
| | |
|
| | | if (aqiList.size() == 0) {
|
| | | parameters.put("cityCode", monitorPoint.getCityCode());
|
| | | aqiList = hangzhouAqiMapper.getAqiDataByAreaCode(parameters);
|
| | | }
|
| | | for (Map<String, Object> map : aqiList) {
|
| | | String O3 = map.get("O3").toString().replace("\"", "");
|
| | | map.put("O3", O3);
|
| | | }
|
| | |
|
| | | List<Map<String, Object>> resultList = new ArrayList<>();
|
| | | if (t1.getTime() > t2.getTime()) {
|
| | | parameters.put("now", now);
|
| | | Map<String, Object> map = restTemplate.getForObject("https://yiketianqi.com/api?version=v9&appid=68884517&appsecret=St9sFnvi&cityid={1}", Map.class, cityID);
|
| | | ArrayList<Map<String, Object>> dataList = (ArrayList<Map<String, Object>>) map.get("data");
|
| | | ArrayList<Map<String, Object>> arrayList = new ArrayList<>();
|
| | | String start = parameters.get("now").toString();
|
| | | String end = parameters.get("time").toString();
|
| | | for (Map<String, Object> dataMap : dataList) {
|
| | | String date = dataMap.get("date").toString();
|
| | | ArrayList<Map<String, Object>> list = (ArrayList<Map<String, Object>>) dataMap.get("hours");
|
| | | if (date.equals(start)) {
|
| | | for (int i = list.size() - 7; i < list.size(); i++) {
|
| | | Map<String, Object> resultMap = list.get(i);
|
| | | arrayList.add(resultMap);
|
| | | }
|
| | | if (forecastList.size() == 0 && aqiList.size() == 0) {
|
| | | return new ArrayList<>();
|
| | | } else if (forecastList.size() == 0) {
|
| | | for (Map<String, Object> aqiMap : aqiList) {
|
| | | Map<String, Object> map = new HashMap<>();
|
| | | List<String> values = new ArrayList<>();
|
| | | String hour = aqiMap.get("time").toString().split(" ")[1].split(":")[0];
|
| | | if (hour.equals("00")) {
|
| | | hour = "24";
|
| | | }
|
| | | if (date.equals(end)) {
|
| | | for (int i = 0; i < 17; i++) {
|
| | | Map<String, Object> resultMap = list.get(i);
|
| | | arrayList.add(resultMap);
|
| | | }
|
| | | }
|
| | | map.put("time", Integer.valueOf(hour));
|
| | | values.add("");
|
| | | values.add(aqiMap.get("O3").toString());
|
| | | map.put("values", values);
|
| | | resultList.add(map);
|
| | | }
|
| | |
|
| | | for (Map<String, Object> resultMap : arrayList) {
|
| | | Map<String, Object> hashMap = new LinkedHashMap<>();
|
| | | } else if (aqiList.size() == 0) {
|
| | | for (Map<String, Object> forecastMap : forecastList) {
|
| | | Map<String, Object> map = new HashMap<>();
|
| | | List<String> values = new ArrayList<>();
|
| | | String hour = resultMap.get("hours").toString().replaceAll("[\u4e00-\u9fa5]+", "");
|
| | | values.add(resultMap.get("tem").toString());
|
| | | values.add("");
|
| | | hashMap.put("values", values);
|
| | | hashMap.put("time", Integer.valueOf(hour));
|
| | | if (Integer.valueOf(hour) == 0) {
|
| | | hashMap.put("time", 24);
|
| | | String hour = forecastMap.get("time").toString().split(" ")[1].split(":")[0];
|
| | | if (hour.equals("00")) {
|
| | | hour = "24";
|
| | | }
|
| | | resultList.add(hashMap);
|
| | | map.put("time", Integer.valueOf(hour));
|
| | | if (forecastMap.get("result") != null) {
|
| | | values.add(forecastMap.get("result").toString().replace("\"", ""));
|
| | | } else {
|
| | | values.add("");
|
| | | }
|
| | | values.add("");
|
| | | map.put("values", values);
|
| | | resultList.add(map);
|
| | | }
|
| | | } else {
|
| | | parameters.put("start", selectTime);
|
| | | c.setTime(sdf.parse(selectTime));
|
| | | c.add(Calendar.DAY_OF_MONTH, 1);
|
| | | c.add(Calendar.HOUR_OF_DAY, 1);
|
| | | String end = sdf1.format(c.getTime());
|
| | | parameters.put("end", end);
|
| | | parameters.put("sensors", "O3C");
|
| | | parameters.put("sensors1", "O3");
|
| | | parameters.put("sensors2", parameters.get("sensors1").toString());
|
| | | List<Map<String, Object>> areaList = new ArrayList<>();
|
| | | if (areaCode == null) {
|
| | | parameters.put("areaCode", cityCode);
|
| | | areaList = hangzhouAqiMapper.getAreaAvgDataByAreaCode(parameters);
|
| | | } else {
|
| | | parameters.put("areaCode", areaCode);
|
| | | areaList = hangzhouAqiMapper.getAreaAvgDataByAreaCode(parameters);
|
| | | if (areaList.size() == 0) {
|
| | | parameters.put("areaCode", cityCode);
|
| | | areaList = hangzhouAqiMapper.getAreaAvgDataByAreaCode(parameters);
|
| | | }
|
| | | }
|
| | | areaList.remove(0);
|
| | | for (Map<String, Object> areaMap : areaList) {
|
| | | Map<String, Object> hashMap = new LinkedHashMap<>();
|
| | | for (Map<String, Object> forecastMap : forecastList) {
|
| | | Map<String, Object> map = new HashMap<>();
|
| | | List<String> values = new ArrayList<>();
|
| | | values.add("");
|
| | | values.add(areaMap.get("O3").toString());
|
| | | hashMap.put("values", values);
|
| | | String hour = areaMap.get("time").toString().split(" ")[1];
|
| | | hashMap.put("time", Integer.valueOf(hour));
|
| | | if (Integer.valueOf(hour) == 0) {
|
| | | hashMap.put("time", 24);
|
| | | String hour = forecastMap.get("time").toString().split(" ")[1].split(":")[0];
|
| | | if (hour.equals("00")) {
|
| | | hour = "24";
|
| | | }
|
| | | resultList.add(hashMap);
|
| | | map.put("time", Integer.valueOf(hour));
|
| | | 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("O3").toString());
|
| | | }
|
| | | }
|
| | | map.put("values", values);
|
| | | resultList.add(map);
|
| | | }
|
| | | }
|
| | | for (Map<String, Object> resultMap : resultList) {
|
| | | ArrayList<String> values = (ArrayList<String>) resultMap.get("values");
|
| | | if (values.size() == 1) {
|
| | | values.add("");
|
| | | }
|
| | | }
|
| | | return resultList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> getWeatherData(Map<String, Object> parameters) throws ParseException {
|
| | | parameters.put("typeFormat", "%Y-%m-%d %H:%i:%s");
|
| | | String cityName = parameters.get("city").toString();
|
| | | Area area = areaMapper.getAreaByName(cityName);
|
| | | Integer code = 0;
|
| | | String name = "";
|
| | | if (area == null) {
|
| | | City city = cityMapper.getCityByName(cityName);
|
| | | if (city == null) {
|
| | | Province province = provinceMapper.getProvinceByName(cityName);
|
| | | code = province.getProvinceCode();
|
| | | name = province.getProvinceName();
|
| | | } else {
|
| | | code = city.getCityCode();
|
| | | name = city.getCityName();
|
| | | }
|
| | | } else {
|
| | | code = area.getAreaCode();
|
| | | name = area.getAreaName();
|
| | | }
|
| | |
|
| | | parameters.put("cityCode", code);
|
| | | parameters.put("name", name);
|
| | | 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 + " 01:00:00");
|
| | | Calendar cal = Calendar.getInstance();
|
| | | cal.setTime(selectTime);
|
| | | cal.add(Calendar.DAY_OF_MONTH, 1);
|
| | | Date end = cal.getTime();
|
| | | cal.setTime(sdf.parse(time));
|
| | | cal.add(Calendar.DAY_OF_MONTH, -1);
|
| | | String beforeDay = sdf.format(cal.getTime());
|
| | | parameters.put("start", selectTime);
|
| | | parameters.put("end", end);
|
| | | Integer fcode = 0;
|
| | | List<Map<String, Object>> forecastList = forecastWeatherMapper.getForecast(parameters);
|
| | | if (forecastList.size() == 0) {
|
| | | List<Area> areaList = areaMapper.getAreaByCityCode(code);
|
| | | for (Area area1 : areaList) {
|
| | | if (area1 != null) {
|
| | | parameters.put("cityCode", area1.getAreaCode());
|
| | | fcode = area1.getAreaCode();
|
| | | forecastList = forecastWeatherMapper.getForecast(parameters);
|
| | | if (forecastList.size() != 0) {
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | } else {
|
| | | fcode = Integer.valueOf(parameters.get("cityCode").toString());
|
| | | }
|
| | |
|
| | | List<Map<String, Object>> foreList = new ArrayList<>();
|
| | | for (Map<String, Object> forecastMap : forecastList) {
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("time", forecastMap.get("time").toString());
|
| | | hashMap.put("type", "预测");
|
| | | hashMap.put("TVOC", "");
|
| | | hashMap.put("altitude", "");
|
| | | hashMap.put("vegetation", "");
|
| | | hashMap.put("river", "");
|
| | | 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("name").toString());
|
| | | hashMap.put("code", fcode);
|
| | | if (sdf.parse(time).getTime() <= now.getTime()) {
|
| | | hashMap.put("fxTime", (beforeDay + " 15:00").substring(5, 16));
|
| | | } else {
|
| | | String format = sdf1.format(now).split(" ")[0];
|
| | | Date date1 = sdf1.parse(format + " 07:00:00");
|
| | | Date date2 = sdf1.parse(format + " 15:00:00");
|
| | | if (now.getTime() > date2.getTime()) {
|
| | | hashMap.put("fxTime", (beforeDay + " 15:00").substring(5, 16));
|
| | | } else if (now.getTime() > date1.getTime() && (now.getTime() < date2.getTime() || now.getTime() == date2.getTime())) {
|
| | | hashMap.put("fxTime", (beforeDay + " 07:00").substring(5, 16));
|
| | | }
|
| | | }
|
| | | Map<String, Object> jsonMap = (Map<String, Object>) JSONObject.parse(forecastMap.get("json").toString());
|
| | | hashMap.putAll(jsonMap);
|
| | | foreList.add(hashMap);
|
| | | }
|
| | |
|
| | | for (Map<String, Object> foreMap : foreList) {
|
| | | String ftime = foreMap.get("time").toString();
|
| | | Date endTime = sdf1.parse(ftime);
|
| | | cal.setTime(endTime);
|
| | | cal.add(Calendar.HOUR, -6);
|
| | | Date startTime = cal.getTime();
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("start", startTime);
|
| | | hashMap.put("end", endTime);
|
| | | hashMap.put("cityCode", Integer.valueOf(parameters.get("cityCode").toString()));
|
| | | Map<String, Object> precip6HourMap = forecastWeatherMapper.getPrecip6Hour(hashMap);
|
| | | foreMap.put("precip6", "");
|
| | | if (precip6HourMap != null) {
|
| | | foreMap.put("precip6", precip6HourMap.get("precip6").toString());
|
| | | }
|
| | | }
|
| | |
|
| | | String ac = parameters.get("cityCode").toString();
|
| | | List<Map<String, Object>> aqiList = hangzhouAqiMapper.getAqi(parameters);
|
| | | if (aqiList.size() == 0) {
|
| | | parameters.put("cityCode", code);//320500
|
| | | aqiList = hangzhouAqiMapper.getAqi(parameters);
|
| | | if (aqiList.size() == 0) {
|
| | | List<Area> areaList = areaMapper.getAreaByCityCode(code);
|
| | | for (Area area1 : areaList) {
|
| | | if (area1 != null) {
|
| | | parameters.put("cityCode", area1.getAreaCode());
|
| | | aqiList = hangzhouAqiMapper.getAqi(parameters);
|
| | | if (aqiList.size() != 0) {
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | List<Map<String, Object>> realAqilist = new ArrayList<>();
|
| | | for (Map<String, Object> aqiMap : aqiList) {
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | 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("name").toString());
|
| | | realAqilist.add(hashMap);
|
| | | }
|
| | | for (Map<String, Object> map : realAqilist) {
|
| | | Date endTime = sdf1.parse(map.get("time").toString());
|
| | | cal.setTime(endTime);
|
| | | cal.add(Calendar.HOUR, -8);
|
| | | Date startTime = cal.getTime();
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("cityCode", Integer.valueOf(parameters.get("cityCode").toString()));
|
| | | hashMap.put("start", startTime);
|
| | | hashMap.put("end", endTime);
|
| | | Map<String, Object> O3Map = hangzhouAqiMapper.getAvgO3EightHours(hashMap);
|
| | | map.put("O3C_8H", O3Map.get("O3C_8H").toString());
|
| | | }
|
| | | //光照
|
| | |
|
| | | Map<String, Object> params = new HashMap<>();
|
| | | if (ac.endsWith("00")) {
|
| | | params.put("cityCode", Integer.valueOf(ac));
|
| | | } else {
|
| | | params.put("areaCode", Integer.valueOf(ac));
|
| | | }
|
| | | 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<String> macList1 = new ArrayList<>();
|
| | | List<Map<String, Object>> beamList = new ArrayList<>();
|
| | | List<Map<String, Object>> tvocList=new ArrayList<>();
|
| | | if (deviceList.size() != 0) {
|
| | | for (Device device : deviceList) {
|
| | | macList.add(device.getMac());
|
| | | }
|
| | |
|
| | | parameters.put("macs", macList);
|
| | | beamList = historyHourlyMapper.getBeamByMacs(parameters);
|
| | | Map<String, Object> map = new HashMap<>();
|
| | | if (name.equals("沧州市")) {
|
| | | List<Integer> list=new ArrayList<>();
|
| | | list.add(48);
|
| | | List<Device> pointIds = deviceMapper.getDeviceListByMonitorPointIds(list);
|
| | | for (Device device : pointIds) {
|
| | | if (device.getId() != 1075) {
|
| | | macList1.add(device.getMac());
|
| | | }
|
| | | }
|
| | | }else {
|
| | | macList1=macList;
|
| | | }
|
| | | map.put("macs", macList1);
|
| | | map.put("start", parameters.get("start"));
|
| | | map.put("end", parameters.get("end"));
|
| | | tvocList = historyHourlyMapper.getTVOCByMacs(map);
|
| | | }
|
| | | 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("name").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", Math.floor((Double) beamMap.get("beam")));
|
| | | }
|
| | | }
|
| | |
|
| | | Date endTime = sdf1.parse(rtime);
|
| | | cal.setTime(endTime);
|
| | | cal.add(Calendar.HOUR, -6);
|
| | | Date startTime = cal.getTime();
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("cityCode", Integer.valueOf(parameters.get("cityCode").toString()));
|
| | | hashMap.put("start", startTime);
|
| | | hashMap.put("end", endTime);
|
| | |
|
| | | Map<String, Object> precip6HourMap = realWeatherMapper.getPrecip6Hour(hashMap);
|
| | |
|
| | | if (precip6HourMap != null) {
|
| | | realMap.put("precip6", precip6HourMap.get("precip6").toString());
|
| | | }
|
| | |
|
| | | for (Map<String, Object> tvocMap : tvocList) {
|
| | | String ttime = tvocMap.get("time").toString();
|
| | | if (ttime.equals(rtime)) {
|
| | | realMap.put("TVOC", tvocMap.get("TVOC").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.removeAll(Collections.singleton(null));
|
| | | for (Map<String, Object> map : list) {
|
| | | map.put("type", "实测");
|
| | | map.put("city", parameters.get("name").toString());
|
| | | }
|
| | |
|
| | | List<Map<String, Object>> resultList = new ArrayList<>();
|
| | |
|
| | | for (Map<String, Object> foreMap : foreList) {
|
| | | for (Map<String, Object> realMap : list) {
|
| | | if (foreMap.get("time").equals(realMap.get("time"))) {
|
| | | resultList.add(foreMap);
|
| | | resultList.add(realMap);
|
| | | }
|
| | | }
|
| | | }
|
| | | 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("city", parameters.get("name").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", "");
|
| | | }
|
| | | }
|
| | | if ((!map.containsKey("SO2C")) && map.containsKey("SO2")) {
|
| | | map.put("SO2C", map.get("SO2").toString());
|
| | | }
|
| | | if ((!map.containsKey("NO2C")) && map.containsKey("NO2")) {
|
| | | map.put("NO2C", map.get("NO2").toString());
|
| | | }
|
| | | if ((!map.containsKey("O3C")) && map.containsKey("O3")) {
|
| | | map.put("O3C", map.get("O3").toString());
|
| | | }
|
| | | if ((!map.containsKey("COC")) && map.containsKey("CO")) {
|
| | | map.put("COC", map.get("CO").toString());
|
| | | }
|
| | | if ((!map.containsKey("PM25C")) && map.containsKey("PM2_5")) {
|
| | | map.put("PM25C", map.get("PM2_5").toString());
|
| | | }
|
| | | if ((!map.containsKey("PM10C")) && map.containsKey("PM10")) {
|
| | | map.put("PM10C", map.get("PM10").toString());
|
| | | }
|
| | |
|
| | | }
|
| | | 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);
|
| | | hashMap.put("cityCode", Integer.valueOf(map.get("code").toString()));
|
| | | Map<String, Object> jsonMap = new HashMap<>();
|
| | | for (String key : map.keySet()) {
|
| | | if (!key.equals("city") && !key.equals("time") && !key.equals("type") && !key.equals("fxTime") && !key.equals("code")) {
|
| | | String value = map.get(key).toString();
|
| | | jsonMap.put(key, value);
|
| | | }
|
| | | }
|
| | | hashMap.put("json", JSONObject.toJSONString(jsonMap));
|
| | | forecastWeatherMapper.updateForecastWeather(hashMap);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|