/*
 * 文 件 名:  WeatherController
 * 版    权:  华设设计集团股份有限公司
 * 描    述:  <描述>
 * 修 改 人:  lvwenbin
 * 修改时间:  2025/5/8
 * 跟踪单号:  <跟踪单号>
 * 修改单号:  <修改单号>
 * 修改内容:  <修改内容>
 */
package com.ruoyi.ems.controller;

import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.ems.service.IWeatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 天气相关API
 * <功能详细描述>
 *
 * @author lvwenbin
 * @version [版本号, 2025/5/8]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */

@RestController
@RequestMapping("/weather")
@Api(value = "WeatherController", description = "天气数据接口")
public class WeatherController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(WeatherController.class);

    @Autowired
    private IWeatherService weatherService;

    /**
     * 实时天气获取
     */
    @RequestMapping(value = "/getWeather", method = RequestMethod.GET)
    @ApiOperation(value = "/getWeather", notes = "获取实时天气")
    @ApiResponses({ @ApiResponse(code = 200, message = "success"),
        @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
    })
    public AjaxResult getWeather(@RequestParam(value = "adcode") String adcode) {
        return success(weatherService.getWeatherRt(adcode));
    }

    /**
     * 获取历史天气数据
     */
    @RequestMapping(value = "/getWeatherHis", method = RequestMethod.GET)
    @ApiOperation(value = "/getWeatherHis", notes = "获取天气历史")
    @ApiResponses({ @ApiResponse(code = 200, message = "success"),
        @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
    })
    public AjaxResult getWeatherHis(@RequestParam(value = "adcode") String adcode,
        @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) {
        return success(weatherService.getWeatherHis(adcode, startTime, endTime));
    }

    /**
     * 获取历史天气数据
     */
    @RequestMapping(value = "/getWeatherForecast", method = RequestMethod.GET)
    @ApiOperation(value = "/getWeatherForecast", notes = "获取天气预报")
    @ApiResponses({ @ApiResponse(code = 200, message = "success"),
        @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
    })
    public AjaxResult getWeatherForecast(@RequestParam(value = "adcode") String adcode,
        @RequestParam(value = "startTime", required = false) String startTime,
        @RequestParam(value = "endTime", required = false) String endTime) {
        return success(weatherService.getWeatherForecast(adcode, startTime, endTime));
    }
}