12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package services
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/http"
- "hongze/hongze_edb_lib/services/alarm_msg"
- "hongze/hongze_edb_lib/utils"
- "math/rand"
- "time"
- )
- type EdbDataFromWind struct {
- Close map[string]float64 `json:"CLOSE"`
- Dt map[string]int64 `json:"DT"`
- ErrorCode map[string]int64 `json:"ErrorCode"`
- ErrMsg string
- }
- // GetEdbDataFromWind 获取wind数据
- func GetEdbDataFromWind(edbCode, startDate, endDate string) (item *EdbDataFromWind, err error) {
- windUrl := getRandWindUrl()
- thsUrl := windUrl + `edbInfo/wind?EdbCode=%s&StartDate=%s&EndDate=%s`
- thsUrl = fmt.Sprintf(thsUrl, edbCode, startDate, endDate)
- utils.FileLog.Info(fmt.Sprintf("windUrl:%s", thsUrl))
- body, err := http.Get(thsUrl)
- fmt.Println("GetEdbDataByWind body:")
- fmt.Println(string(body))
- utils.FileLog.Info(fmt.Sprint("wind result:", string(body)))
- if err != nil {
- return
- }
- item = new(EdbDataFromWind)
- err = json.Unmarshal(body, &item)
- //异常的话,需要邮件通知
- if len(item.ErrorCode) > 0 {
- if item.ErrorCode["0"] != 0 {
- go alarm_msg.SendAlarmMsg(fmt.Sprintf("wind数据服务异常,edbCode:%s,ErrorCode:%d", edbCode, item.ErrorCode["0"]), 3)
- }
- }
- return
- }
- // getRandWindUrl 获取wind的url
- func getRandWindUrl() string {
- windUrlLen := len(utils.Hz_Wind_Data_Url_LIST)
- rand.Seed(time.Now().UnixNano())
- i := rand.Intn(windUrlLen) //生成随机整数(不包含最右边的整数,所以不需要将域名的长度-1)
- return utils.Hz_Wind_Data_Url_LIST[i]
- }
|