|  |  |  | 
|---|
|  |  |  | 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.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.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @ClassName WeatherController | 
|---|
|  |  |  | 
|---|
|  |  |  | * @Version TODO | 
|---|
|  |  |  | **/ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Api(tags = {"用户管理"}) | 
|---|
|  |  |  | @Api(tags = {"天气"}) | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/weather") | 
|---|
|  |  |  | @CrossOrigin(origins = "*", maxAge = 3600) | 
|---|
|  |  |  | public class WeatherController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | CityWeatherService cityWeatherService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Description: 根据地区码查询天气 | 
|---|
|  |  |  | * @Param: [regionCode] | 
|---|
|  |  |  | * @return: com.moral.constant.ResultMessage | 
|---|
|  |  |  | * @Author: 陈凯裕 | 
|---|
|  |  |  | * @Date: 2021/10/29 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("queryByRegionCode") | 
|---|
|  |  |  | public ResultMessage queryByRegionCode(String regionCode){ | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | public ResultMessage queryByRegionCode(Integer regionCode){ | 
|---|
|  |  |  | 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"); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(regionCode)){ | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map<String, Object> resultMap = cityWeatherService.dressingIndex(parameters); | 
|---|
|  |  |  | return ResultMessage.ok(resultMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|