| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | 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 java.util.Map;
|
| | |
| | | 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;
|
| | |
|
| | | @Service
|
| | | public class WeatherServiceImpl implements WeatherService {
|
| | | |
| | | @Resource
|
| | | private OrganizationService organizationService;
|
| | | |
| | | @Override
|
| | | public Map<String, Object> getWeatherDataByRegion(Map<String, Object> parameters) {
|
| | | Object organizationId = parameters.get("organizationId");
|
| | | ValidateUtil.notNull(organizationId, "param.is.null");
|
| | | String areaName = "昆山市";
|
| | | String parentName = "";
|
| | | Organization organization = organizationService.getOrganizationById(Integer.valueOf(parameters.get("organizationId").toString()));
|
| | | if(organization.getAreaNames()!=null){
|
| | | AreaNames areaNames = organization.getAreaNames();
|
| | | if (ObjectUtils.isEmpty(areaNames.getAreaName())) {
|
| | | if (ObjectUtils.isEmpty(areaNames.getCityName())) {
|
| | | areaName = areaNames.getProvinceName();
|
| | | } else {
|
| | | areaName = areaNames.getCityName();
|
| | | }
|
| | | } else {
|
| | | areaName = areaNames.getAreaName();
|
| | | parentName = areaNames.getCityName();
|
| | | if ("市辖区".equals(areaName)) {
|
| | | areaName = parentName;
|
| | | }
|
| | | }
|
| | | }
|
| | | List<Element> elements = Dom4jUtils.readDocument();
|
| | | String cityID = "1102";
|
| | | for (Element element : elements) {
|
| | | String name = element.element("name").getText();
|
| | | if (areaName.equals(name)) {
|
| | | cityID = element.element("Fid").getText();
|
| | | break;
|
| | | }
|
| | | if (name.endsWith(areaName)) {
|
| | | if (name.startsWith(parentName)) {
|
| | | cityID = element.element("Fid").getText();
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | RestTemplate restTemplate = new RestTemplate();
|
| | | Map<String, Object> map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID={1}&apiKey=aqi", Map.class,cityID);
|
| | | Map<String, Object> result = (Map<String, Object>) ((Map)map.get("data")).get("aqi");
|
| | | map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID={1}&apiKey=condition", Map.class,cityID);
|
| | | result.putAll((Map<? extends String, ? extends Object>) ((Map)map.get("data")).get("condition"));
|
| | | return result;
|
| | | }
|
| | | |
| | | @Override
|
| | | public Map<String, Object> get15DayWeatherDataByRegion(Map<String, Object> parameters) {
|
| | | Object organizationId = parameters.get("organizationId");
|
| | | ValidateUtil.notNull(organizationId, "param.is.null");
|
| | | String areaName = "昆山市";
|
| | | String parentName = "";
|
| | | Organization organization = organizationService.getOrganizationById(Integer.valueOf(parameters.get("organizationId").toString()));
|
| | | if(organization.getAreaNames()!=null){
|
| | | AreaNames areaNames = organization.getAreaNames();
|
| | | if (ObjectUtils.isEmpty(areaNames.getAreaName())) {
|
| | | if (ObjectUtils.isEmpty(areaNames.getCityName())) {
|
| | | areaName = areaNames.getProvinceName();
|
| | | } else {
|
| | | areaName = areaNames.getCityName();
|
| | | }
|
| | | } else {
|
| | | areaName = areaNames.getAreaName();
|
| | | parentName = areaNames.getCityName();
|
| | | if ("市辖区".equals(areaName)) {
|
| | | areaName = parentName;
|
| | | }
|
| | | }
|
| | | }
|
| | | List<Element> elements = Dom4jUtils.readDocument();
|
| | | String cityID = "1102";
|
| | | for (Element element : elements) {
|
| | | String name = element.element("name").getText();
|
| | | if (areaName.equals(name)) {
|
| | | cityID = element.element("Fid").getText();
|
| | | break;
|
| | | }
|
| | | if (name.endsWith(areaName)) {
|
| | | if (name.startsWith(parentName)) {
|
| | | cityID = element.element("Fid").getText();
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | RestTemplate restTemplate = new RestTemplate();
|
| | | Map<String, Object> map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID={1}&apiKey=aqi", Map.class,cityID);
|
| | | List<Map<String, Object>> result = new ArrayList<>();
|
| | | map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID={1}&apiKey=forecast15days", Map.class,cityID);
|
| | | result.addAll((Collection<? extends Map<String, Object>>) ((Map)map.get("data")).get("forecast"));
|
| | | for (Map<String, Object> map2 : result) {
|
| | | Map<String, Object> returnMap = new HashMap<>();
|
| | | String predictDate = map2.get("predictDate").toString();
|
| | | String time = parameters.get("time").toString();
|
| | | if (predictDate.equals(time)) {
|
| | | returnMap = map2;
|
| | | return returnMap;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Resource
|
| | | private OrganizationService organizationService;
|
| | |
|
| | | @Resource
|
| | | private HangzhouAqiMapper hangzhouAqiMapper;
|
| | |
|
| | | @Resource
|
| | | private MonitorPointMapper monitorPointMapper;
|
| | |
|
| | | @Resource
|
| | | private ForecastWeatherMapper forecastWeatherMapper;
|
| | |
|
| | | @Resource
|
| | | private AreaMapper areaMapper;
|
| | |
|
| | | @Resource
|
| | | private CityMapper cityMapper;
|
| | |
|
| | | @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) {
|
| | | Object organizationId = parameters.get("organizationId");
|
| | | ValidateUtil.notNull(organizationId, "param.is.null");
|
| | | String areaName = "昆山市";
|
| | | String parentName = "";
|
| | | Organization organization = organizationService.getOrganizationById(Integer.valueOf(parameters.get("organizationId").toString()));
|
| | | if (organization.getAreaNames() != null) {
|
| | | AreaNames areaNames = organization.getAreaNames();
|
| | | if (ObjectUtils.isEmpty(areaNames.getAreaName())) {
|
| | | if (ObjectUtils.isEmpty(areaNames.getCityName())) {
|
| | | areaName = areaNames.getProvinceName();
|
| | | } else {
|
| | | areaName = areaNames.getCityName();
|
| | | }
|
| | | } else {
|
| | | areaName = areaNames.getAreaName();
|
| | | parentName = areaNames.getCityName();
|
| | | if ("市辖区".equals(areaName)) {
|
| | | areaName = parentName;
|
| | | }
|
| | | }
|
| | | }
|
| | | List<Element> elements = Dom4jUtils.readDocument();
|
| | | String cityID = "1102";
|
| | | for (Element element : elements) {
|
| | | String name = element.element("name").getText();
|
| | | if (areaName.equals(name)) {
|
| | | cityID = element.element("Fid").getText();
|
| | | break;
|
| | | }
|
| | | if (name.endsWith(areaName)) {
|
| | | if (name.startsWith(parentName)) {
|
| | | cityID = element.element("Fid").getText();
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | RestTemplate restTemplate = new RestTemplate();
|
| | | Map<String, Object> map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID={1}&apiKey=aqi", Map.class, cityID);
|
| | | Map<String, Object> result = (Map<String, Object>) ((Map) map.get("data")).get("aqi");
|
| | | map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID={1}&apiKey=condition", Map.class, cityID);
|
| | | result.putAll((Map<? extends String, ? extends Object>) ((Map) map.get("data")).get("condition"));
|
| | | return result;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> get15DayWeatherDataByRegion(Map<String, Object> parameters) {
|
| | | Object organizationId = parameters.get("organizationId");
|
| | | ValidateUtil.notNull(organizationId, "param.is.null");
|
| | | String areaName = "昆山市";
|
| | | String parentName = "";
|
| | | Organization organization = organizationService.getOrganizationById(Integer.valueOf(parameters.get("organizationId").toString()));
|
| | | if (organization.getAreaNames() != null) {
|
| | | AreaNames areaNames = organization.getAreaNames();
|
| | | if (ObjectUtils.isEmpty(areaNames.getAreaName())) {
|
| | | if (ObjectUtils.isEmpty(areaNames.getCityName())) {
|
| | | areaName = areaNames.getProvinceName();
|
| | | } else {
|
| | | areaName = areaNames.getCityName();
|
| | | }
|
| | | } else {
|
| | | areaName = areaNames.getAreaName();
|
| | | parentName = areaNames.getCityName();
|
| | | if ("市辖区".equals(areaName)) {
|
| | | areaName = parentName;
|
| | | }
|
| | | }
|
| | | }
|
| | | List<Element> elements = Dom4jUtils.readDocument();
|
| | | String cityID = "1102";
|
| | | for (Element element : elements) {
|
| | | String name = element.element("name").getText();
|
| | | if (areaName.equals(name)) {
|
| | | cityID = element.element("Fid").getText();
|
| | | break;
|
| | | }
|
| | | if (name.endsWith(areaName)) {
|
| | | if (name.startsWith(parentName)) {
|
| | | cityID = element.element("Fid").getText();
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | RestTemplate restTemplate = new RestTemplate();
|
| | | Map<String, Object> map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID={1}&apiKey=aqi", Map.class, cityID);
|
| | | List<Map<String, Object>> result = new ArrayList<>();
|
| | | map = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID={1}&apiKey=forecast15days", Map.class, cityID);
|
| | | result.addAll((Collection<? extends Map<String, Object>>) ((Map) map.get("data")).get("forecast"));
|
| | | for (Map<String, Object> map2 : result) {
|
| | | Map<String, Object> returnMap = new HashMap<>();
|
| | | String predictDate = map2.get("predictDate").toString();
|
| | | String time = parameters.get("time").toString();
|
| | | if (predictDate.equals(time)) {
|
| | | returnMap = map2;
|
| | | return returnMap;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> getForecastAndReal(Map<String, Object> parameters) throws ParseException {
|
| | | String monitorPointId = parameters.get("monitorPointId").toString();
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | | String time = parameters.get("time").toString() + " 00:00:00";
|
| | | Calendar c = Calendar.getInstance();
|
| | | 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));
|
| | | List<Map<String, Object>> forecastList = forecastWeatherMapper.getForecastHour(parameters);
|
| | | MonitorPoint monitorPoint = monitorPointMapper.selectByPrimaryKey(Integer.valueOf(monitorPointId));
|
| | | parameters.put("areaCode", monitorPoint.getAreaCode());
|
| | | String sensors = "O3C";
|
| | | String sensor1 = "O3";
|
| | | parameters.put("sensors", sensors);
|
| | | parameters.put("sensors1", sensor1);
|
| | | parameters.put("sensors2", sensor1);
|
| | | List<Map<String, Object>> aqiList = hangzhouAqiMapper.getAqiDataByAreaCode(parameters);
|
| | | if (aqiList.size() == 0) {
|
| | | 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);
|
| | | }
|
| | |
|
| | | List<Map<String, Object>> resultList = new ArrayList<>();
|
| | | 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";
|
| | | }
|
| | | map.put("time", Integer.valueOf(hour));
|
| | | values.add("");
|
| | | values.add(aqiMap.get(sensor1).toString());
|
| | | map.put("values", values);
|
| | | resultList.add(map);
|
| | | }
|
| | |
|
| | | } else if (aqiList.size() == 0) {
|
| | | for (Map<String, Object> forecastMap : forecastList) {
|
| | | Map<String, Object> map = new HashMap<>();
|
| | | List<String> values = new ArrayList<>();
|
| | | String hour = forecastMap.get("time").toString().split(" ")[1].split(":")[0];
|
| | | if (hour.equals("00")) {
|
| | | hour = "24";
|
| | | }
|
| | | 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 {
|
| | | for (Map<String, Object> forecastMap : forecastList) {
|
| | | Map<String, Object> map = new HashMap<>();
|
| | | List<String> values = new ArrayList<>();
|
| | | String hour = forecastMap.get("time").toString().split(" ")[1].split(":")[0];
|
| | | if (hour.equals("00")) {
|
| | | hour = "24";
|
| | | }
|
| | | 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(sensor1).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 {
|
| | | String cityName = parameters.get("city").toString();
|
| | | Area area = areaMapper.getAreaByName(cityName);
|
| | | MonitorPoint monitorPoint;
|
| | | Integer areaCode = 0;
|
| | | Integer cityCode = 0;
|
| | | if (area == null) {
|
| | | City city = cityMapper.getCityByName(cityName);
|
| | | if (city == null) {
|
| | | Province province = provinceMapper.getProvinceByName(cityName);
|
| | | Integer provinceCode = province.getProvinceCode();
|
| | | monitorPoint = monitorPointMapper.getFirstMonitorPointByProvinceCode(provinceCode);
|
| | | parameters.put("areaCode", provinceCode);
|
| | | parameters.put("city", province.getProvinceName());
|
| | | } else {
|
| | | cityCode = city.getCityCode();
|
| | | monitorPoint = monitorPointMapper.getFirstMonitorPointByCityCode(cityCode);
|
| | | parameters.put("areaCode", cityCode);
|
| | | parameters.put("city", city.getCityName());
|
| | | }
|
| | | } else {
|
| | | areaCode = area.getAreaCode();
|
| | | monitorPoint = monitorPointMapper.getFirstMonitorPointByAreaCode(areaCode);
|
| | | cityCode = area.getCityCode();
|
| | | parameters.put("areaCode", areaCode);
|
| | | parameters.put("city", area.getAreaName());
|
| | | }
|
| | | if (monitorPoint == null) {
|
| | | return new ArrayList<>();
|
| | | }
|
| | | 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);
|
| | | Date start = c.getTime();
|
| | | c.add(Calendar.DAY_OF_MONTH, 1);
|
| | | Date end = c.getTime();
|
| | | 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>> 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("city").toString());
|
| | | realAqilist.add(hashMap);
|
| | | }
|
| | |
|
| | | 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("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());
|
| | | }
|
| | | }
|
| | |
|
| | | //光照
|
| | | 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());
|
| | | }
|
| | | }
|
| | | 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.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 : 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("city").toString());
|
| | | resultList.add(hashMap);
|
| | | }
|
| | |
|
| | | for (Map<String, Object> map : resultList) {
|
| | | String date = map.get("time").toString().substring(0, 16);
|
| | | map.put("time", date);
|
| | | }
|
| | | 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);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|