|
|
|
@ -1,6 +1,7 @@
|
|
|
|
package service
|
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"github.com/astaxie/beego/httplib"
|
|
|
|
"github.com/astaxie/beego/httplib"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
@ -13,6 +14,36 @@ type HttpWeatherService struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func SyncNmcCityAndNmcProvince() {
|
|
|
|
func SyncNmcCityAndNmcProvince() {
|
|
|
|
|
|
|
|
timeUnix := time.Now().Unix()
|
|
|
|
|
|
|
|
s := strconv.FormatInt(timeUnix, 10)
|
|
|
|
|
|
|
|
url := "http://www.nmc.cn/rest/province/all?_=" + s + "000"
|
|
|
|
|
|
|
|
//http://www.nmc.cn/rest/province/all?_=1741052160653
|
|
|
|
|
|
|
|
//http://www.nmc.cn/rest/province/all?_=1741052160653
|
|
|
|
|
|
|
|
fmt.Println(url)
|
|
|
|
|
|
|
|
req := httplib.Get(url)
|
|
|
|
|
|
|
|
provinceListJson, err := req.String()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(provinceListJson)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var provinces []models.NmcProvince
|
|
|
|
|
|
|
|
json.Unmarshal([]byte(provinceListJson), &provinces)
|
|
|
|
|
|
|
|
//fmt.Println(provinces)
|
|
|
|
|
|
|
|
//fmt.Println(len(provinces))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, item := range provinces {
|
|
|
|
|
|
|
|
if models.GetNmcProvince(&item) {
|
|
|
|
|
|
|
|
//存在
|
|
|
|
|
|
|
|
fmt.Println("存在")
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//不存在
|
|
|
|
|
|
|
|
models.NmcProvinceAdd(&item)
|
|
|
|
|
|
|
|
fmt.Println("不存在,插入数据库")
|
|
|
|
|
|
|
|
//http://www.nmc.cn/rest/province/ASX?_=1741055184606
|
|
|
|
|
|
|
|
//“http://www.nmc.cn/rest/province/" + code + "?_=" + String.valueOf(System.currentTimeMillis());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -20,7 +51,7 @@ func (s *HttpWeatherService) GetNmcNowWeather() {
|
|
|
|
citys := models.GetNmcCityList()
|
|
|
|
citys := models.GetNmcCityList()
|
|
|
|
fmt.Println(citys)
|
|
|
|
fmt.Println(citys)
|
|
|
|
fmt.Println(len(citys))
|
|
|
|
fmt.Println(len(citys))
|
|
|
|
if len(citys)==0 {
|
|
|
|
if len(citys) == 0 {
|
|
|
|
SyncNmcCityAndNmcProvince()
|
|
|
|
SyncNmcCityAndNmcProvince()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
@ -45,8 +76,8 @@ func (s *HttpWeatherService) GetNmcNowWeather() {
|
|
|
|
nmcNowWeather.Weather = str
|
|
|
|
nmcNowWeather.Weather = str
|
|
|
|
nmcNowWeather.Code = item.Code
|
|
|
|
nmcNowWeather.Code = item.Code
|
|
|
|
nmcNowWeather.WeatherDate = now.Format("2006-01-02")
|
|
|
|
nmcNowWeather.WeatherDate = now.Format("2006-01-02")
|
|
|
|
id,errInsert := models.AddNmcNowWeather(nmcNowWeather)
|
|
|
|
id, errInsert := models.AddNmcNowWeather(nmcNowWeather)
|
|
|
|
if errInsert!=nil {
|
|
|
|
if errInsert != nil {
|
|
|
|
println(errInsert.Error())
|
|
|
|
println(errInsert.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Println(id)
|
|
|
|
fmt.Println(id)
|
|
|
|
|