package cn.com.oa.controller;

import cn.com.v2.common.domain.AjaxResult;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * 获取天气
 *
 * @author: wangpx
 * @date: 2025-02-12 10:40
 */
@RestController
@RequestMapping("/api/common")
public class CommonController {

    @GetMapping("/weather")
    public AjaxResult getWeather() {
        HttpResponse response = HttpRequest.get("https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/25.9645%2C119.2197?unitGroup=metric&elements=datetime%2Ctemp%2Cpreciptype&include=hours&key=PA6TZ5RK5NS48644CHCKX6FGK&contentType=json").execute();
        Map<String, String> map = new HashMap<>();
        map.put("date", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        map.put("data", response.body());
        return AjaxResult.successData(200, map).put("msg","获取成功");
    }

    @GetMapping("/date")
    public AjaxResult getDate() {
        return AjaxResult.successData(200, LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))).put("msg","获取成功");
    }
}
