package com.ruoyi.project.tool.weather.controller;
|
|
|
import com.ruoyi.project.tool.cityCode.domain.CityCode;
|
import com.ruoyi.project.tool.cityCode.service.ICityCodeService;
|
import com.ruoyi.project.tool.weather.dto.WeatherDto;
|
import com.ruoyi.project.tool.weather.service.WeatherManager;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.List;
|
|
|
@RestController
|
@RequestMapping("/api")
|
public class WeatherAPIContoller {
|
|
@Autowired
|
WeatherManager weatherManager;
|
|
@Autowired
|
private ICityCodeService cityCodeService;
|
|
|
/**
|
* 天气数据
|
* @param cityName
|
* @return
|
*/
|
//@RequestMapping(value = "/city/{id:1[0-9]{8}}", method = RequestMethod.GET)
|
@GetMapping("/city")
|
public WeatherDto loadApi(String cityName){
|
CityCode city = new CityCode();
|
city.setCityName(cityName);
|
|
List<CityCode> cityCodeList = cityCodeService.selectCityCodeList(city);
|
if (cityCodeList.size()>0){
|
String id = cityCodeList.get(0).getCityCode().toString();
|
|
return weatherManager.getById(id);
|
}else{
|
throw new RuntimeException("no_city_Name");
|
}
|
|
}
|
|
|
//@GetMapping("/importCity")
|
//public void importCity(){
|
// File f = new File("F:\\wm\\SVN\\TR\\TroubleAndRisk\\src\\main\\resources\\citycode-2019-08-23.json");
|
// String city = JsonTool.readJsonFile(f);
|
// List<CityCode> cityCodeList = JSON.parseArray(city,CityCode.class);
|
//
|
// for(CityCode cityCode : cityCodeList){
|
// cityCodeService.insertCityCode(cityCode);
|
// }
|
//
|
//}
|
|
|
}
|