Browse Source

Merge branch 'feature/eta1.2.2_edb_source' into debug

xyxie 1 năm trước cách đây
mục cha
commit
8e43dc008e

+ 1 - 1
services/base_from_pb.go

@@ -55,7 +55,7 @@ func GetEdbDataFromPbFinance(companyCode, edbCode, startDate, endDate, edbTermin
 		err = errors.New("彭博接口未配置")
 		return
 	}*/
-	terminal, err := GetFirstTerminal(utils.DATA_SOURCE_PB_FINANCE, edbTerminalCode)
+	terminal, err := GetTerminal(utils.DATA_SOURCE_PB_FINANCE, edbTerminalCode)
 	if err != nil {
 		err = fmt.Errorf("获取彭博接口配置出错 Err: %s", err)
 		return

+ 7 - 8
services/base_from_ths.go

@@ -177,7 +177,6 @@ type FutureGoodDataFromThsInterface struct {
 }
 
 func GetFutureGoodDataFromThs(edbCode, startDate, endDate, edbTerminalCode string) (item future_good.FutureGoodDataFromThs, err error) {
-	// todo 商品获取终端逻辑修改,默认取第一个终端
 	terminal, err := GetFirstTerminal(utils.DATA_SOURCE_THS, edbTerminalCode)
 	if err != nil {
 		err = fmt.Errorf("获取同花顺接口配置出错 Err: %s", err)
@@ -189,16 +188,16 @@ func GetFutureGoodDataFromThs(edbCode, startDate, endDate, edbTerminalCode strin
 	}
 
 	if edbTerminalCode == "" {
-		// todo 修改缓存名称,防止和普通指标数据重复,设置指标与终端关系的缓存
-		terminalCodeCacheKey := utils.CACHE_EDB_TERMINAL_CODE_URL + edbCode
+		terminalCodeCacheKey := utils.CACHE_EDB_TERMINAL_CODE_GOOD_URL + edbCode
 		_ = utils.Rc.Put(terminalCodeCacheKey, terminal.TerminalCode, utils.GetTodayLastSecond())
 	}
-	var token string
-	token, err = GetAccessToken(false, terminal.Value)
-	if err != nil {
-		return
-	}
+
 	if utils.ThsDataMethod == "" || utils.ThsDataMethod == "api" { // 生产环境走官方http请求,测试环境走终端
+		var token string
+		token, err = GetAccessToken(false, terminal.Value)
+		if err != nil {
+			return
+		}
 		return getFutureGoodDataFromThsHttp(edbCode, startDate, endDate, terminal.Value, token)
 	} else {
 		return getFutureGoodDataFromThsApp(edbCode, startDate, endDate, 0, terminal.ServerUrl)

+ 4 - 5
services/base_from_ths_http.go

@@ -232,10 +232,10 @@ func GetAccessToken(isRefresh bool, thsRefreshToken string) (token string, err e
 			go alarm_msg.SendAlarmMsg("获取同花顺的token失败,ERR:"+err.Error(), 3)
 		}
 	}()
-	token, redisErr := utils.Rc.RedisString(tokenRedisKey)
+	redisKey := utils.CACHE_EDB_THS_SERVER_TOKEN + thsRefreshToken + ":"
+	token, redisErr := utils.Rc.RedisString(redisKey)
 	//如果从redis中accessToken 获取失败或者token为空了,再或者需要强制刷新了,那么重新获取accessToken
 	if redisErr != nil || token == `` || isRefresh {
-		// todo 上线后 有可能直接从redis中获取token,导致terminalCode 为空
 		token, _ = refreshAccessToken(thsRefreshToken)
 		return
 	}
@@ -249,7 +249,6 @@ func refreshAccessToken(thsRefreshToken string) (token string, err error) {
 			go alarm_msg.SendAlarmMsg("刷新同花顺的token失败;ERR:"+err.Error(), 3)
 		}
 	}()
-	// todo 刷新后的token容易和缓存中的不一致,导致保存了错误的终端信息
 	tokenInfo, tmpErr := getAccessToken(thsRefreshToken)
 	if tmpErr != nil {
 		err = tmpErr
@@ -266,12 +265,12 @@ func refreshAccessToken(thsRefreshToken string) (token string, err error) {
 	//token存入redis
 	//err = utils.Rc.Put(tokenRedisKey, token, time.Duration(expireTime.Unix()-600)*time.Second)
 	// 本来是要设置下600s的过期时间,但因为不是强制刷新token,就不获取了
-	err = utils.Rc.Put(tokenRedisKey, token, time.Duration(expireTime.Unix())*time.Second)
+	redisKey := utils.CACHE_EDB_THS_SERVER_TOKEN + thsRefreshToken + ":"
+	err = utils.Rc.Put(redisKey, token, time.Duration(expireTime.Unix())*time.Second)
 	if err != nil {
 		err = fmt.Errorf("获取同花顺的token成功;同花顺token存入redis失败,ERR:%s", err.Error())
 		return
 	}
-
 	return
 }
 

+ 1 - 2
services/edb_terminal.go

@@ -51,10 +51,9 @@ func GetTerminal(source int, oldTerminalCode string) (edbTerminal *models.EdbTer
 		return
 	}
 	num := 0
-	edbTerminal = new(models.EdbTerminal)
 	for _, v := range terminalList {
 		tmpNum := terminalNumMap[v.TerminalCode]
-		if edbTerminal.TerminalId == 0 {
+		if edbTerminal == nil {
 			edbTerminal = v
 			num = tmpNum
 		} else if tmpNum < num {

+ 8 - 6
utils/constants.go

@@ -197,12 +197,14 @@ const (
 )
 
 const (
-	CACHE_EDB_DATA_ADD          = "CACHE_EDB_DATA_ADD_"
-	CACHE_EDB_DATA_REFRESH      = "CACHE_EDB_DATA_REFRESH_"
-	CACHE_WIND_URL              = "CACHE_WIND_URL"
-	CACHE_CHART_INFO_DATA       = "chart:info:data:"             //图表数据
-	CACHE_STOCK_PLANT_CALCULATE = "CACHE_STOCK_PLANT_CALCULATE_" // 库存装置减产计算
-	CACHE_EDB_TERMINAL_CODE_URL = "edb:terminal_code:edb_code:"  // 指标与终端关系的缓存
+	CACHE_EDB_DATA_ADD               = "CACHE_EDB_DATA_ADD_"
+	CACHE_EDB_DATA_REFRESH           = "CACHE_EDB_DATA_REFRESH_"
+	CACHE_WIND_URL                   = "CACHE_WIND_URL"
+	CACHE_CHART_INFO_DATA            = "chart:info:data:"                 //图表数据
+	CACHE_STOCK_PLANT_CALCULATE      = "CACHE_STOCK_PLANT_CALCULATE_"     // 库存装置减产计算
+	CACHE_EDB_TERMINAL_CODE_URL      = "edb:terminal_code:edb_code:"      // 指标与终端关系的缓存
+	CACHE_EDB_TERMINAL_CODE_GOOD_URL = "edb:terminal_code:good:edb_code:" // 指标与终端关系的缓存, 商品期货
+	CACHE_EDB_THS_SERVER_TOKEN       = "edb:ths_server_token:"            //同花顺调用凭证
 )
 
 // 图表类型