Browse Source

fix:随机获取wind数据,添加code异常提醒

Roc 2 years ago
parent
commit
9bfb92a36e
2 changed files with 30 additions and 9 deletions
  1. 24 4
      services/base_from_wind.go
  2. 6 5
      utils/constants.go

+ 24 - 4
services/base_from_wind.go

@@ -4,18 +4,23 @@ 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"`
-	ErrMsg string
+	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) {
-	thsUrl := utils.Hz_Wind_Data_Url + `edbInfo/wind?EdbCode=%s&StartDate=%s&EndDate=%s`
+	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)
@@ -28,5 +33,20 @@ func GetEdbDataFromWind(edbCode, startDate, endDate string) (item *EdbDataFromWi
 	}
 	item = new(EdbDataFromWind)
 	err = json.Unmarshal(body, &item)
+
+	//异常的话,需要邮件通知
+	if len(item.ErrorCode) > 0 {
+		if item.ErrorCode["0"] != 0 {
+			go alarm_msg.SendAlarmMsg(fmt.Sprint("wind数据服务异常,ErrorCode:", 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]
+}

+ 6 - 5
utils/constants.go

@@ -66,11 +66,12 @@ var (
 )
 
 var (
-	Hz_Ths_Data_Url  string                                   //同花顺,万得接口服务地址(阿里云windows服务器地址)
-	Hz_Wind_Data_Url = "http://datawind.hzinsights.com:8040/" //万得接口服务地址
-	Hz_Pb_Data_Url   = "http://datapb.hzinsights.com:8040/"   //彭博接口地址
-	Hz_LT_Data_Url   = "http://dataek.hzinsights.com:8040/"   //路透社接口地址
-	EDB_DATA_LIMIT   = 10
+	Hz_Ths_Data_Url       string                                   //同花顺,万得接口服务地址(阿里云windows服务器地址)
+	Hz_Wind_Data_Url      = "http://datawind.hzinsights.com:8040/" //万得接口服务地址
+	Hz_Pb_Data_Url        = "http://datapb.hzinsights.com:8040/"   //彭博接口地址
+	Hz_LT_Data_Url        = "http://dataek.hzinsights.com:8040/"   //路透社接口地址
+	EDB_DATA_LIMIT        = 10
+	Hz_Wind_Data_Url_LIST = []string{"http://datawind.hzinsights.com:8040/", "http://datawind2.hzinsights.com:8040/"}
 )
 
 const (