| | |
| | | package com.moral.service.impl; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | |
| | |
| | | |
| | | @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"); |
| | |
| | | hashMap.put("cityCode", code); |
| | | 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); |
| | | Map<String,Object> kunShanMap=new HashMap<>(); |
| | | kunShanMap.put("name1","苏州市"); |
| | | kunShanMap.put("parentName","江苏省"); |
| | | kunShanMap.put("cityCode",320500); |
| | | hashSet.add(kunShanMap); |
| | | |
| | | List<Element> elements = Dom4jUtils.readDocument(); |
| | | String cityID = "101190404"; |
| | | for (Map<String, Object> map : hashSet) { |
| | |
| | | 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(); |
| | |
| | | jsonMap.put("condition","80"); |
| | | }else if(text.equals("阴")){ |
| | | jsonMap.put("condition","60"); |
| | | }else if(text.equals("雷阵雨")){ |
| | | }else if(text.equals("雷阵雨")||text.equals("阵雨")){ |
| | | jsonMap.put("condition","40"); |
| | | }else if(text.equals("小雨")){ |
| | | jsonMap.put("condition","20"); |
| | |
| | | resultMap.put("json",JSONObject.toJSONString(jsonMap)); |
| | | resultList.add(resultMap); |
| | | } |
| | | return realWeatherMapper.insertRealWeather(null); |
| | | realWeatherMapper.deleteRealWeather(sdf1.format(now)); |
| | | return realWeatherMapper.insertRealWeather(resultList); |
| | | } |
| | | } |