| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.text.DecimalFormat;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | |
| | | 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 com.moral.mapper.MonitorPointMapper;
|
| | | import com.moral.mapper.ProvinceMapper;
|
| | | import com.moral.mapper.RealWeatherMapper;
|
| | | import com.moral.mapper.ShAreaMapper;
|
| | | import com.moral.service.OrganizationService;
|
| | | import com.moral.service.WeatherService;
|
| | |
|
| | |
| | |
|
| | | @Resource
|
| | | private HistoryHourlyMapper historyHourlyMapper;
|
| | |
|
| | | @Resource
|
| | | private ShAreaMapper shAreaMapper;
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getWeatherDataByRegion(Map<String, Object> parameters) {
|
| | |
| | | @Override
|
| | | public List<Map<String, Object>> getWeatherData(Map<String, Object> parameters) throws ParseException {
|
| | | parameters.put("typeFormat", "%Y-%m-%d %H:%i:%s");
|
| | | if (parameters.get("city") == null) {
|
| | | return new ArrayList<Map<String, Object>>();
|
| | | }
|
| | | String cityName = parameters.get("city").toString();
|
| | | Area area = areaMapper.getAreaByName(cityName);
|
| | | Integer code = 0;
|
| | | String name = "";
|
| | | Integer code;
|
| | | String name;
|
| | | if (area == null) {
|
| | | City city = cityMapper.getCityByName(cityName);
|
| | | if (city == null) {
|
| | |
| | | String time = parameters.get("time").toString();
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | | SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH");
|
| | | Date now = new Date();
|
| | | Date selectTime = sdf1.parse(time + " 01:00:00");
|
| | | Calendar cal = Calendar.getInstance();
|
| | |
| | | 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) {
|
| | |
| | | hashMap.put("end", endTime);
|
| | | Map<String, Object> O3Map = forecastWeatherMapper.getO38Hours(hashMap);
|
| | | if (O3Map != null) {
|
| | | map.put("O3C_8H", O3Map.get("O3C_8H").toString());
|
| | | Double O3C_8H = Double.valueOf(O3Map.get("O3C_8H").toString());
|
| | | map.put("O3C_8H", String.valueOf(Math.round(O3C_8H)));
|
| | | }
|
| | | }
|
| | |
|
| | | String ac = parameters.get("cityCode").toString();
|
| | | if(name.equals("沧州市")){
|
| | | ac="130900";
|
| | | }
|
| | | List<Map<String, Object>> aqiList = hangzhouAqiMapper.getAqi(parameters);
|
| | | if (aqiList.size() == 0) {
|
| | | parameters.put("cityCode", code);
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | DecimalFormat df = new DecimalFormat(".####");
|
| | | 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());
|
| | | DecimalFormat df = new DecimalFormat(".####");
|
| | | double longitude = Double.valueOf(jsonMap.get("longitude").toString());
|
| | | double latitude = Double.valueOf(jsonMap.get("latitude").toString());
|
| | | jsonMap.put("longitude", df.format(longitude));
|
| | | jsonMap.put("latitude", df.format(latitude));
|
| | | hashMap.putAll(jsonMap);
|
| | | hashMap.put("city", parameters.get("name").toString());
|
| | | realAqilist.add(hashMap);
|
| | |
| | | } else {
|
| | | params.put("areaCode", Integer.valueOf(ac));
|
| | | }
|
| | | List<MonitorPoint> monitorList = monitorPointMapper.getMonitorList(params);
|
| | |
|
| | | List<MonitorPoint> monitorList = monitorPointMapper.getMonitorList(params);
|
| | | List<Integer> pointList = new ArrayList<>();
|
| | | for (MonitorPoint point : monitorList) {
|
| | | Integer pointId = point.getId();
|
| | |
| | | for (Device device : deviceList) {
|
| | | macList.add(device.getMac());
|
| | | }
|
| | |
|
| | | parameters.put("macs", macList);
|
| | | beamList = historyHourlyMapper.getBeamByMacs(parameters);
|
| | | Map<String, Object> map = new HashMap<>();
|
| | |
| | | for (Map<String, Object> tvocMap : tvocList) {
|
| | | String ttime = tvocMap.get("time").toString();
|
| | | if (ttime.equals(rtime)) {
|
| | | realMap.put("TVOC", tvocMap.get("TVOC").toString());
|
| | | Double tvoc = Double.valueOf(tvocMap.get("TVOC").toString());
|
| | | BigDecimal bd = new BigDecimal(tvoc);
|
| | | tvoc = bd.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
|
| | | realMap.put("TVOC", tvoc);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | }
|
| | |
|
| | | List<Map<String, Object>> resultList = new ArrayList<>();
|
| | |
|
| | | if (foreList.size() == 0) {
|
| | | for (Map<String, Object> map : realWeatherList) {
|
| | | Map<String,Object> hashMap=new LinkedHashMap<>();
|
| | | hashMap.put("time",map.get("time").toString());
|
| | | hashMap.put("type","预测");
|
| | | hashMap.put("city",map.get("city").toString());
|
| | | foreList.add(hashMap);
|
| | | }
|
| | | }
|
| | |
|
| | | for (Map<String, Object> foreMap : foreList) {
|
| | | for (Map<String, Object> realMap : list) {
|
| | |
| | | if ((!map.containsKey("PM10C")) && map.containsKey("PM10")) {
|
| | | map.put("PM10C", map.get("PM10").toString());
|
| | | }
|
| | |
|
| | | if (map.get("windScale") != null) {
|
| | | String windScale = map.get("windScale").toString().replace("-", "~");
|
| | | map.put("windScale", windScale);
|
| | | }
|
| | | }
|
| | |
|
| | | //后4小时保良值
|
| | | double value = 160.0 * 8;
|
| | | int nowHour = Integer.valueOf(sdf1.format(now).substring(11, 13));
|
| | | int nowMinute = Integer.valueOf(sdf1.format(now).substring(14, 16));
|
| | | String format = sdf1.format(now).substring(0, 13) + ":00:00";
|
| | | if (nowHour < 8) {
|
| | | return resultList;
|
| | | }
|
| | |
|
| | | if (nowMinute >= 46) {
|
| | | nowHour = nowHour + 1;
|
| | | cal.setTime(now);
|
| | | cal.add(Calendar.HOUR_OF_DAY, 1);
|
| | | format = sdf1.format(cal.getTime()).substring(0, 13) + ":00:00";
|
| | | }
|
| | |
|
| | | for (Map<String, Object> resultMap : resultList) {
|
| | | if (resultMap.get("type").equals("实测")) {
|
| | | String rtime = resultMap.get("time").toString() + ":00";
|
| | | int rhour = Integer.valueOf(rtime.substring(11, 13));
|
| | | cal.setTime(sdf1.parse(rtime));
|
| | | cal.add(Calendar.HOUR_OF_DAY, -7);
|
| | | Date startTime = cal.getTime();
|
| | | Date endTime=sdf1.parse(format);
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("cityCode", Integer.valueOf(parameters.get("cityCode").toString()));
|
| | | hashMap.put("start", startTime);
|
| | | hashMap.put("end", endTime);
|
| | | if (rhour == nowHour) {
|
| | | Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
|
| | | double v = value - Double.valueOf(sumO3Map.get("O3Sum").toString());
|
| | | resultMap.put("goodValue", v);
|
| | | } else if (rhour == nowHour + 1) {
|
| | | Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
|
| | | double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString())) / 2;
|
| | | resultMap.put("goodValue", v);
|
| | | } else if (rhour == nowHour + 2) {
|
| | | Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
|
| | | double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString())) / 3;
|
| | | resultMap.put("goodValue", v);
|
| | | } else if (rhour == nowHour + 3) {
|
| | | Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
|
| | | double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString()) / 4);
|
| | | resultMap.put("goodValue", v);
|
| | | if (sdf.parse(time).getTime() == sdf.parse(sdf.format(now)).getTime()) {
|
| | | String rtime = resultMap.get("time").toString() + ":00";
|
| | | int rhour = Integer.valueOf(rtime.substring(11, 13));
|
| | | cal.setTime(sdf1.parse(rtime));
|
| | | cal.add(Calendar.HOUR_OF_DAY, -7);
|
| | | Date startTime = cal.getTime();
|
| | | Date endTime = sdf1.parse(format);
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("cityCode", Integer.valueOf(parameters.get("cityCode").toString()));
|
| | | hashMap.put("start", startTime);
|
| | | hashMap.put("end", endTime);
|
| | | if (rhour == 0) {
|
| | | rhour = 24;
|
| | | }
|
| | |
|
| | | if (rhour == nowHour) {
|
| | | Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
|
| | | double v = value - Double.valueOf(sumO3Map.get("O3Sum").toString());
|
| | | resultMap.put("goodValue", v);
|
| | | } else if (rhour == nowHour + 1) {
|
| | | Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
|
| | | double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString())) / 2;
|
| | | resultMap.put("goodValue", String.valueOf(Math.round(v)));
|
| | | } else if (rhour == nowHour + 2) {
|
| | | Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
|
| | | double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString())) / 3;
|
| | | resultMap.put("goodValue", String.valueOf(Math.round(v)));
|
| | | } else if (rhour == nowHour + 3) {
|
| | | Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
|
| | | double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString())) / 4;
|
| | | resultMap.put("goodValue", String.valueOf(Math.round(v)));
|
| | | }
|
| | | }
|
| | | }
|
| | | if (resultMap.get("O3C_8H") != null && !resultMap.get("O3C_8H").equals("")) {
|
| | | Double O3C_8H = Double.valueOf(resultMap.get("O3C_8H").toString());
|
| | | resultMap.put("O3C_8H", String.valueOf(Math.round(O3C_8H)));
|
| | | }
|
| | |
|
| | | if (resultMap.get("PM25C") != null && !resultMap.get("PM25C").equals("")) {
|
| | | Double PM25C = Double.valueOf(resultMap.get("PM25C").toString());
|
| | | resultMap.put("PM25C", String.valueOf(Math.round(PM25C)));
|
| | | }
|
| | |
|
| | | if (resultMap.get("PM10C") != null && !resultMap.get("PM10C").equals("")) {
|
| | | Double PM10C = Double.valueOf(resultMap.get("PM10C").toString());
|
| | | resultMap.put("PM10C", String.valueOf(Math.round(PM10C)));
|
| | | }
|
| | |
|
| | | if (resultMap.get("O3C") != null && !resultMap.get("O3C").equals("")) {
|
| | | Double O3C = Double.valueOf(resultMap.get("O3C").toString());
|
| | | resultMap.put("O3C", String.valueOf(Math.round(O3C)));
|
| | | }
|
| | | }
|
| | |
|
| | | //地理特征
|
| | | Map<String, Object> point = shAreaMapper.getgeography(name);
|
| | | for (Map<String, Object> map : resultList) {
|
| | | double longitude = Double.valueOf(point.get("lng").toString());
|
| | | double latitude = Double.valueOf(point.get("lat").toString());
|
| | | map.put("longitude", df.format(longitude));
|
| | | map.put("latitude", df.format(latitude));
|
| | | if (point.get("altitude") != null) {
|
| | | map.put("altitude", point.get("altitude").toString());
|
| | | }
|
| | | if (point.get("vegetation") != null) {
|
| | | map.put("vegetation", point.get("vegetation").toString());
|
| | | }
|
| | | if (point.get("river") != null) {
|
| | | map.put("river", point.get("river").toString());
|
| | | }
|
| | | }
|
| | | return resultList;
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public void updateForecastWeather(Map<String, Object> parameters) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> getWeatherDataByDay(Map<String, Object> parameters) throws ParseException {
|
| | | String selectTime = parameters.get("time").toString();
|
| | | String cityName = parameters.get("city").toString();
|
| | | Area area = areaMapper.getAreaByName(cityName);
|
| | | Integer code;
|
| | | 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);
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|