双重预防项目-国泰新华二开定制版
SZH
2022-08-20 f9f0687195e0fe349185437d22c495d74c8d4a20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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);
    //    }
    //
    //}
 
 
}