You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.9 KiB
50 lines
1.9 KiB
package com.ccsens.basicserver.api;
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.ccsens.basicserver.bean.vo.weather.WeatherTangVo;
|
|
import com.ccsens.basicserver.bean.vo.weather.WeatherVo;
|
|
import com.ccsens.basicserver.util.BasicServerCodeError;
|
|
import com.ccsens.basicserver.util.BasicServerConstant;
|
|
import com.ccsens.util.JsonResponse;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
/**
|
|
* @description:
|
|
* @author: whj
|
|
* @time: 2022/3/10 9:21
|
|
*/
|
|
@Api(tags = "天气" )
|
|
@RestController
|
|
@RequestMapping("/weather")
|
|
@Slf4j
|
|
public class WeatherController {
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "天气查询", notes = "来源:汤同伟提供")
|
|
@ApiImplicitParams({
|
|
})
|
|
@RequestMapping(value = "tang", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
|
|
public JsonResponse<WeatherVo.Weather> tang() {
|
|
log.info("天气查询,路径:{}", BasicServerConstant.Tang.WEATHER_AND_EPIDEMIC_URL);
|
|
String result = HttpUtil.get(BasicServerConstant.Tang.WEATHER_AND_EPIDEMIC_URL);
|
|
log.info("天气查询返回:{}", result);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
if (resultJson.getIntValue(BasicServerConstant.Tang.ERROR_ERROR_CODE) != BasicServerConstant.Tang.CURRENT_CODE) {
|
|
return JsonResponse.newInstance().fail(BasicServerCodeError.THIRD_ERROR.getCode(), resultJson.getString(BasicServerConstant.Tang.ERROR_MSG));
|
|
}
|
|
WeatherTangVo.Weather weather = JSONObject.parseObject(resultJson.getString(BasicServerConstant.Tang.DATA), WeatherTangVo.Weather.class);
|
|
return JsonResponse.newInstance().ok(weather.transform());
|
|
}
|
|
|
|
|
|
}
|
|
|