From fcbb7cbe05b6cdcdf91b8599f064b85738810996 Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Wed, 20 Apr 2022 16:20:37 +0800
Subject: [PATCH] 穿衣指数接口

---
 screen-api/src/main/java/com/moral/api/controller/WeatherController.java        |   23 ++++-
 screen-api/src/main/java/com/moral/api/service/CityWeatherService.java          |    9 ++
 screen-api/src/main/java/com/moral/api/service/impl/CityWeatherServiceImpl.java |   25 ++++++
 screen-common/src/main/java/com/moral/util/WeatherUtils.java                    |  163 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 216 insertions(+), 4 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/controller/WeatherController.java b/screen-api/src/main/java/com/moral/api/controller/WeatherController.java
index 65ae957..fd8d8c0 100644
--- a/screen-api/src/main/java/com/moral/api/controller/WeatherController.java
+++ b/screen-api/src/main/java/com/moral/api/controller/WeatherController.java
@@ -1,16 +1,19 @@
 package com.moral.api.controller;
 
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.moral.api.entity.CityWeather;
 import com.moral.api.service.CityWeatherService;
+import com.moral.constant.Constants;
+import com.moral.constant.ResponseCodeEnum;
 import com.moral.constant.ResultMessage;
+import com.moral.util.WebUtils;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -42,4 +45,16 @@
         Map<String, Object> value = cityWeatherService.queryWeatherByRegionCode(regionCode);
         return ResultMessage.ok(value);
     }
+
+    @RequestMapping(value = "dressingIndex", method = RequestMethod.GET)
+    public ResultMessage dressingIndex(HttpServletRequest request){
+        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
+        Object regionCode = parameters.get("regionCode");
+        Object time = parameters.get("time");
+        if (ObjectUtils.isEmpty(regionCode) || ObjectUtils.isEmpty(time)){
+            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+        }
+        Map<String, Object> resultMap = cityWeatherService.dressingIndex(parameters);
+        return ResultMessage.ok(resultMap);
+    }
 }
diff --git a/screen-api/src/main/java/com/moral/api/service/CityWeatherService.java b/screen-api/src/main/java/com/moral/api/service/CityWeatherService.java
index f38078e..6fcc1c7 100644
--- a/screen-api/src/main/java/com/moral/api/service/CityWeatherService.java
+++ b/screen-api/src/main/java/com/moral/api/service/CityWeatherService.java
@@ -22,4 +22,13 @@
             * @Date: 2021/10/29
             */
     Map<String,Object> queryWeatherByRegionCode(Integer regionCode);
+    
+    /**
+      *@Description: ������������������������������������������
+      *@Param: [map]
+      *@return: java.util.Map<java.lang.String,java.lang.Object> 
+      *@Author: lizijie
+      *@Date: 2022/4/15 17:00
+     **/
+    Map<String,Object> dressingIndex(Map map);
 }
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/CityWeatherServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/CityWeatherServiceImpl.java
index 2ecef67..7885edc 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/CityWeatherServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/CityWeatherServiceImpl.java
@@ -1,16 +1,20 @@
 package com.moral.api.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.moral.api.entity.CityWeather;
 import com.moral.api.mapper.CityWeatherMapper;
 import com.moral.api.service.CityWeatherService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.moral.constant.RedisConstants;
+import com.moral.util.WeatherUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -36,6 +40,27 @@
         return value;
     }
 
+    @Override
+    public Map<String, Object> dressingIndex(Map map) {
+        Map<String,Object> resultMap = new HashMap<>();
+        int city_code = Integer.parseInt(map.get("regionCode").toString());
+        String time = map.get("time").toString();
+        QueryWrapper<CityWeather> cityWeatherQueryWrapper = new QueryWrapper<>();
+        cityWeatherQueryWrapper.eq("city_code",city_code);
+        cityWeatherQueryWrapper.eq("time",time);
+        CityWeather cityWeather = cityWeatherMapper.selectOne(cityWeatherQueryWrapper);
+        if (ObjectUtils.isEmpty(cityWeather)){
+            return resultMap;
+        }
+        JSONObject jsonObject = JSONObject.parseObject(cityWeather.getValue());
+        Map<String,Object> weatherMap = new HashMap<>();
+        weatherMap.put("temp",jsonObject.get("temp"));
+        weatherMap.put("humidity",jsonObject.get("humidity"));
+        weatherMap.put("windScale",jsonObject.get("windScale"));
+        resultMap = WeatherUtils.dressingIndex(weatherMap);
+        return resultMap;
+    }
+
     /**
     * @Description: ������������������������������
             * @Param: [regionCode]
diff --git a/screen-common/src/main/java/com/moral/util/WeatherUtils.java b/screen-common/src/main/java/com/moral/util/WeatherUtils.java
new file mode 100644
index 0000000..bb80dfe
--- /dev/null
+++ b/screen-common/src/main/java/com/moral/util/WeatherUtils.java
@@ -0,0 +1,163 @@
+package com.moral.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @program: screen
+ * @description: ���������������������������������
+ * @author: lizijie
+ * @create: 2022-04-08 14:15
+ **/
+public class WeatherUtils {
+
+    public static Map<String,Object> dressingIndex(Map map){
+        //������
+        Double temp = Double.parseDouble(map.get("temp").toString());
+        //������
+        Double humidity = Double.parseDouble(map.get("humidity").toString());
+        //������������
+        Double windScale = Double.parseDouble(map.get("windScale").toString());
+        //Map<String,Object> resultMap = new HashMap<>();
+        String index = "";
+        String feel = "";
+        String clothingThickness = null;
+        String advise = "";
+        if(temp >= 40.0){
+            index = "0";
+            feel = "���������������������";
+            clothingThickness = "0mm";
+            advise = "���������������������������������������������������������������������";
+        }else if (temp >= 37.0){
+            index = "1-4";
+            feel = "������������������";
+            clothingThickness = "0mm";
+            advise = "���������������������������������������������������������������������������������������";
+        }else if (temp >= 35.0){
+            index = "1-3";
+            feel = "������������������";
+            clothingThickness = "0mm";
+            advise = "������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������";
+        }else if (temp >= 33.0){
+            index = "1-2";
+            feel = "������������������";
+            clothingThickness = "0mm";
+            advise = "���������������������������������������������������������T���������������������������������������������";
+        }else if (temp >= 28.0){
+            index = "1-1";
+            feel = "������������������";
+            clothingThickness = "0mm";
+            advise = "���������������������������������������������������������������T���������������������������������������������������������������";
+        }else if (temp >= 25.0){
+            if(humidity > 80){
+                index = "1-1";
+                feel = "������������������";
+                clothingThickness = "0mm";
+                advise = "���������������������������������������������������������������T���������������������������������������������������������������";
+            }else {
+                index = "2";
+                feel = "���������";
+                clothingThickness = "0~1.5mm";
+                advise = "������������������������������������������������������T������������������������������������������������������������������������";
+            }
+        }else if (temp >= 23.0){
+            index = "3";
+            feel = "���������";
+            clothingThickness = "1.5~2.4mm";
+            advise = "���������������������������������������������������������T���������������������������������������������������������������������������������������������������������������";
+        }else if (temp >= 21.0){
+            index = "4-1";
+            feel = "������";
+            clothingThickness = "2.41~4.0mm";
+            advise = "���������������������������������������������������������������������������������������������������������������������������������������+���������������������������������";
+        }else if (temp >= 18.0){
+            index = "4-2";
+            feel = "���������";
+            clothingThickness = "4.01~6.0mm";
+            advise = "���������������������������������������������������������������T���������������������������������������������������������������������������������������������������������������������������+������������������������������������������������";
+        }else if (temp >= 15.0){
+            index = "5";
+            feel = "������������������";
+            clothingThickness = "6.0~7.0mm";
+            advise = "���������������������������������������������������������������������������������������������������������������������������������������������������������������������";
+        }else if (temp >= 13.0){
+            index = "6-1";
+            feel = "������";
+            clothingThickness = "7.01~8.0mm";
+            advise = "���������������������������������������������������������������������������������+���������������������������������������������������������������������������������������������������";;
+        }else if (temp >= 11.0){
+            index = "6-2";
+            feel = "������";
+            clothingThickness = "8.01~9.0";
+            advise = "������������������������������������������������������������������������������������������������������������������������������������������������������������������";
+        }else if (temp >= 8.0){
+            index = "6-3";
+            feel = "���";
+            clothingThickness = "9.01~10.0mm";
+            advise = "������������������������������������������������������������������������������������������������������������������������������������������������������������������������������";
+        }else if (temp >= 5.0){
+            index = "7-1";
+            feel = "������";
+            clothingThickness = "10.01~11.0mm";
+            advise = "���������������������������������������������������������������������������������������������������������������������������������������������������������������������+���������������������������������������";
+        }else if (temp >= 0.0){
+            if (windScale >= 4 || humidity >= 80){
+                index = "7-3";
+                feel = "������";
+                clothingThickness = "12.01~13.0mm";
+                advise = "������������������������������������������������������������������������������������������������������������������������������������������������";
+            }else {
+                index = "7-2";
+                feel = "������";
+                clothingThickness = "11.01~12.0mm";
+                advise = "���������������������������������������������������������������������������������������������������������������������������������������";
+            }
+        }else if (temp >= -4.9){
+            if (windScale >= 4 || humidity >= 80){
+                index = "8-1";
+                feel = "������";
+                clothingThickness = ">=13.0.0mm";
+                advise = "������������������������������������������������������������������������������������������������������������������������������������������������������������";
+            }else {
+                index = "7-3";
+                feel = "���";
+                clothingThickness = "12.01~13.0";
+                advise = "������������������������������������������������������������������������������������������������������������������������������������������������";
+            }
+        }else if (temp >= -9.9){
+            if (windScale <= 4 || humidity < 80){
+                index = "8-1";
+                feel = "������";
+                clothingThickness = ">=13.0.0mm";
+                advise = "������������������������������������������������������������������������������������������������������������������������������������������������������������";
+            }else if (windScale <= 4 || humidity >= 80){
+                index = "8-2";
+                feel = "������";
+                clothingThickness = ">=15.0";
+                advise = "������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������";
+            }else if (windScale >= 4 || humidity < 80){
+                index = "8-2";
+                feel = "������";
+                clothingThickness = ">=15.0";
+                advise = "������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������";
+            }else if (windScale >= 4 || humidity >= 80){
+                index = "8-3";
+                feel = "������";
+                clothingThickness = ">=15.0";
+                advise = "������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������";
+            }
+        }else if (temp <= -10.0){
+            index = "8-3";
+            feel = "������";
+            clothingThickness = ">=15.0";
+            advise = "������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������";
+        }
+        map.put("index",index);
+        map.put("feel",feel);
+        map.put("clothingThickness",clothingThickness);
+        map.put("advise",advise);
+        System.out.println(map);
+        return map;
+    }
+
+}

--
Gitblit v1.8.0