From 48bb075f91c5daf35cff0a16abe1136f132aafb4 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Mon, 28 Sep 2020 15:40:26 +0800
Subject: [PATCH] 不同天气给定不同分数

---
 src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java |   80 +++++++++++++++++++++++++++++++---------
 1 files changed, 62 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java b/src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java
index f1f07f7..8dac48c 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;
 
@@ -51,6 +52,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");
@@ -93,6 +95,21 @@
             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);
+
         List<Element> elements = Dom4jUtils.readDocument();
         String cityID = "101190404";
         for (Map<String, Object> map : hashSet) {
@@ -130,31 +147,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);
         }
-        return realWeatherMapper.insertRealWeather(null);
+        realWeatherMapper.deleteRealWeather(sdf1.format(now));
+        return realWeatherMapper.insertRealWeather(resultList);
     }
 }

--
Gitblit v1.8.0