Przeglądaj źródła

fix:同花顺指标 因为table里面的value有的时候返回的是string,有的是float64,所以需要用interface来反射取值

Roc 2 lat temu
rodzic
commit
5ccf9f4337
1 zmienionych plików z 15 dodań i 12 usunięć
  1. 15 12
      services/base_from_ths.go

+ 15 - 12
services/base_from_ths.go

@@ -53,18 +53,18 @@ func getEdbDataFromThs(edbCode, startDate, endDate string, num int) (item *EdbDa
 		err = errors.New(" Err:" + err.Error() + ";result:" + string(body))
 		err = errors.New(" Err:" + err.Error() + ";result:" + string(body))
 		return
 		return
 	}
 	}
-	items := new(EdbDataFromThsInterface)
 
 
-	err = json.Unmarshal(body, &item)
+	tmpItems := new(EdbDataFromThsInterface)
+	err = json.Unmarshal(body, &tmpItems)
 	if err != nil {
 	if err != nil {
 		err = errors.New("GetEdbDataFromThs json.Unmarshal Err:" + err.Error())
 		err = errors.New("GetEdbDataFromThs json.Unmarshal Err:" + err.Error())
 		return
 		return
 	}
 	}
-	if item.Errorcode != 0 {
+	if tmpItems.Errorcode != 0 {
 
 
 		//session has expired,please re-login after using the system
 		//session has expired,please re-login after using the system
 		//如果是同花顺登录session失效了,那么就重新请求获取数据
 		//如果是同花顺登录session失效了,那么就重新请求获取数据
-		if item.Errorcode == -1020 && num == 0 {
+		if tmpItems.Errorcode == -1020 && num == 0 {
 			return getEdbDataFromThs(edbCode, startDate, endDate, 1)
 			return getEdbDataFromThs(edbCode, startDate, endDate, 1)
 		}
 		}
 
 
@@ -74,17 +74,20 @@ func getEdbDataFromThs(edbCode, startDate, endDate string, num int) (item *EdbDa
 
 
 	// 因为table里面的value有的时候返回的是string,有的是float64,所以需要用interface来反射取值
 	// 因为table里面的value有的时候返回的是string,有的是float64,所以需要用interface来反射取值
 	tablesList := make([]Tables, 0)
 	tablesList := make([]Tables, 0)
-	for _, table := range items.Tables {
+	for _, table := range tmpItems.Tables {
 		tableIdList := make([]string, 0)
 		tableIdList := make([]string, 0)
 		tableTimeList := make([]string, 0)
 		tableTimeList := make([]string, 0)
 		tableValueList := make([]float64, 0)
 		tableValueList := make([]float64, 0)
+
 		for _, tableId := range table.ID {
 		for _, tableId := range table.ID {
-			tableTimeList = append(tableTimeList, tableId)
+			tableIdList = append(tableIdList, tableId)
 		}
 		}
 		for _, tableTime := range table.Time {
 		for _, tableTime := range table.Time {
-			tableIdList = append(tableIdList, tableTime)
+			tableTimeList = append(tableTimeList, tableTime)
 		}
 		}
-		for _, tmpValue := range table.Time {
+
+		//指标数据
+		for _, tmpValue := range table.Value {
 			var tableValue float64
 			var tableValue float64
 			if reflect.TypeOf(tmpValue).Kind() == reflect.Float64 {
 			if reflect.TypeOf(tmpValue).Kind() == reflect.Float64 {
 				tableValue = reflect.ValueOf(tmpValue).Float()
 				tableValue = reflect.ValueOf(tmpValue).Float()
@@ -109,10 +112,10 @@ func getEdbDataFromThs(edbCode, startDate, endDate string, num int) (item *EdbDa
 		tablesList = append(tablesList, tmpTable)
 		tablesList = append(tablesList, tmpTable)
 	}
 	}
 	item = &EdbDataFromThs{
 	item = &EdbDataFromThs{
-		DataVol:   items.DataVol,
-		Errmsg:    items.Errmsg,
-		Errorcode: items.Errorcode,
-		Perf:      items.Perf,
+		DataVol:   tmpItems.DataVol,
+		Errmsg:    tmpItems.Errmsg,
+		Errorcode: tmpItems.Errorcode,
+		Perf:      tmpItems.Perf,
 		Tables:    tablesList,
 		Tables:    tablesList,
 	}
 	}
 	return item, nil
 	return item, nil