Bladeren bron

优化数据刷新

317699326@qq.com 1 week geleden
bovenliggende
commit
e1fcfdc03e
2 gewijzigde bestanden met toevoegingen van 27 en 1 verwijderingen
  1. 13 1
      services/data/base_edb_lib.go
  2. 14 0
      utils/config.go

+ 13 - 1
services/data/base_edb_lib.go

@@ -111,9 +111,21 @@ func RefreshPredictEdbCalculateData(edbInfoId int, edbCode, startDate string) (r
 	return
 }
 
+var step int //计数器
+
 // postRefreshEdbData 刷新指标数据
 func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *models.BaseResponse, err error) {
-	postUrl := utils.EDB_LIB_URL + urlStr
+	var postUrl string
+	edbLibUrlListLen := len(utils.EDB_LIB_URL_LIST)
+	if edbLibUrlListLen <= 0 {
+		postUrl = utils.EDB_LIB_URL
+	} else {
+		rn := step % edbLibUrlListLen
+		postUrl = utils.EDB_LIB_URL_LIST[rn].Url
+	}
+	postUrl = postUrl + urlStr
+	step++
+
 	postData, err := json.Marshal(param)
 	if err != nil {
 		return

+ 14 - 0
utils/config.go

@@ -1,6 +1,7 @@
 package utils
 
 import (
+	"encoding/json"
 	"fmt"
 	beego "github.com/beego/beego/v2/adapter"
 	"github.com/beego/beego/v2/server/web"
@@ -42,10 +43,15 @@ var (
 // 经济数据库
 var (
 	EDB_LIB_URL         string
+	EDB_LIB_URL_LIST    []EtaLibUrlList
 	APP_EDB_LIB_NAME_EN string
 	EDB_LIB_Md5_KEY     string
 )
 
+type EtaLibUrlList struct {
+	Url string
+}
+
 // 公共数据服务接口参数
 var (
 	APPID  string
@@ -236,6 +242,14 @@ func init() {
 		EDB_LIB_URL = config["edb_lib_url"]
 		APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
 		EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
+		if EDB_LIB_URL == "" {
+			EDB_LIB_URL = "http://127.0.0.1:8300/edbapi/"
+		} else {
+			err = json.Unmarshal([]byte(EDB_LIB_URL), &EDB_LIB_URL_LIST)
+			if err != nil {
+				fmt.Println("eta_lib_url 配置错误,请检查,Err:" + err.Error())
+			}
+		}
 	}
 
 	APPID = config["appid"]