From c60311f48e7ec07c56a4df31536f795ba62751ce Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Fri, 09 Oct 2020 16:44:42 +0800 Subject: [PATCH] 昆山,沧州大数据预测O3 --- src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java | 115 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 87 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java b/src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java index e483ba2..8e4d4e9 100644 --- a/src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java +++ b/src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java @@ -1,5 +1,6 @@ package com.moral.service.impl; +import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -23,6 +24,7 @@ import com.moral.entity.Area; import com.moral.entity.City; import com.moral.entity.MonitorPoint; +import com.moral.entity.Province; import com.moral.mapper.AreaMapper; import com.moral.mapper.CityMapper; import com.moral.mapper.MonitorPointMapper; @@ -51,6 +53,7 @@ @Override public int insertRealWeather() throws ParseException { + DecimalFormat df = new DecimalFormat("0.0"); Calendar c = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -63,36 +66,65 @@ Integer areaCode = monitorPoint.getAreaCode(); Integer cityCode = monitorPoint.getCityCode(); Integer provinceCode = monitorPoint.getProvinceCode(); - String parentName = ""; - String name1 = ""; - Integer code = 0; + String parentName; + String name1; + Integer code; + Integer parentCode; if (areaCode != null) { Area area = areaMapper.getAreaByAreaCode(areaCode); City city = cityMapper.getCityByCityCode(cityCode); name1 = area.getAreaName(); parentName = city.getCityName(); + parentCode = cityCode; code = areaCode; if ("���������".equals(name1)) { name1 = parentName; - parentName = provinceMapper.getProvinceByProvinceCode(provinceCode).getProvinceName(); + Province province = provinceMapper.getProvinceByProvinceCode(provinceCode); + parentName = province.getProvinceName(); + parentCode = provinceCode; code = cityCode; } } else { - City city = cityMapper.getCityByCityCode(cityCode); - name1 = city.getCityName(); - parentName = provinceMapper.getProvinceByProvinceCode(provinceCode).getProvinceName(); - code = cityCode; - if ("���������".equals(name1)) { - name1 = parentName; - parentName = ""; + if (cityCode != null) { + City city = cityMapper.getCityByCityCode(cityCode); + name1 = city.getCityName(); + code = cityCode; + Province province = provinceMapper.getProvinceByProvinceCode(provinceCode); + parentName = province.getProvinceName(); + parentCode = provinceCode; + if ("���������".equals(name1)) { + name1 = parentName; + code = provinceCode; + } + } else { code = provinceCode; + Province province = provinceMapper.getProvinceByProvinceCode(provinceCode); + name1 = province.getProvinceName(); + parentCode = provinceCode; + parentName = name1; } } hashMap.put("name1", name1); hashMap.put("parentName", parentName); hashMap.put("cityCode", code); + hashMap.put("parentCode", parentCode); hashSet.add(hashMap); } + + Map<String, Object> smap = new HashMap<>(); + smap.put("name1", "���������"); + smap.put("parentName", "���������"); + smap.put("cityCode", 320500); + smap.put("parentCode", 320000); + hashSet.add(smap); + + Map<String, Object> bmap = new HashMap<>(); + bmap.put("name1", "���������"); + bmap.put("parentName", "���������"); + bmap.put("cityCode", 110000); + bmap.put("parentCode", 110000); + hashSet.add(bmap); + List<Element> elements = Dom4jUtils.readDocument(); String cityID = "101190404"; for (Map<String, Object> map : hashSet) { @@ -130,31 +162,58 @@ map.put("data", nowMap); } - List<Map<String,Object>> resultList=new ArrayList<>(); + List<Map<String, Object>> resultList = new ArrayList<>(); for (Map<String, Object> map : hashSet) { - Map<String,Object> resultMap=new HashMap<>(); - resultMap.put("cityCode",map.get("cityCode").toString()); - resultMap.put("time",now); + Map<String, Object> resultMap = new HashMap<>(); + resultMap.put("cityCode", map.get("cityCode").toString()); + resultMap.put("time", now); Map<String, Object> jsonMap = (Map<String, Object>) map.get("data"); + + //������km/h->m/s + Double windSpeed = Double.valueOf(jsonMap.get("windSpeed").toString()); + windSpeed = windSpeed * 1000 / 3600; + jsonMap.put("windSpeed", df.format(windSpeed)); jsonMap.remove("obsTime"); jsonMap.remove("icon"); String text = jsonMap.get("text").toString(); - if(text.equals("���")){ - jsonMap.put("condition","100"); - }else if(text.equals("������")){ - jsonMap.put("condition","80"); - }else if(text.equals("���")){ - jsonMap.put("condition","60"); - }else if(text.equals("���������")){ - jsonMap.put("condition","40"); - }else if(text.equals("������")){ - jsonMap.put("condition","20"); - }else if(text.equals("���")){ - jsonMap.put("condition","0"); + String condition; + if ("���".equals(text)) { + condition = "100"; + } else if ("���".equals(text)) { + condition = "90"; + } else if ("������".equals(text)) { + condition = "80"; + } else if ("���".equals(text)) { + condition = "70"; + } else if ("���".equals(text) || "������".equals(text) || "������".equals(text) || "".equals(text)) { + condition = "60"; + } else if ("������".equals(text)) { + condition = "45"; + } else if ("���������".equals(text)) { + condition = "40"; + } else if ("������������������".equals(text) || "���������������".equals(text)) { + condition = "30"; + } else if ("������".equals(text)) { + condition = "20"; + } else if ("���".equals(text)) { + condition = "10"; + } else if ("������������������".equals(text)) { + condition = "5"; + } else if ("������������������".equals(text)) { + condition = "4"; + } else if ("������".equals(text) || "������".equals(text) || "������".equals(text) + || "������".equals(text) || "������".equals(text) || "������".equals(text) + || "���������".equals(text) || "���������������������������".equals(text) || "������".equals(text) + ) { + condition = "0"; + } else { + condition = "50"; } - resultMap.put("json",JSONObject.toJSONString(jsonMap)); + jsonMap.put("condition", condition); + resultMap.put("json", JSONObject.toJSONString(jsonMap)); resultList.add(resultMap); } + realWeatherMapper.deleteRealWeather(sdf1.format(now)); return realWeatherMapper.insertRealWeather(resultList); } } -- Gitblit v1.8.0