|
@@ -64,7 +64,7 @@ func HandleApiIndex(indexCodes []string) (errMsg string, err error) {
|
|
|
err = errors.New(resp.Message)
|
|
|
return
|
|
|
}
|
|
|
- indexInfoMap, err := GetMySteelChemicalIndexNameMap(indexCodes)
|
|
|
+ indexInfoMap, err := GetMySteelChemicalIndexNameMap()
|
|
|
if err != nil {
|
|
|
errMsg = "获取指标数据失败"
|
|
|
return
|
|
@@ -531,14 +531,39 @@ func GetEdbDataFromMySteelChemical(indexCodes []string, startTime, endTime, orde
|
|
|
}
|
|
|
|
|
|
// GetMySteelChemicalIndexNameMap 获取钢联化工的所有指标的信息
|
|
|
-func GetMySteelChemicalIndexNameMap(indexCodes []string) (indexNameMap map[string]*models.MySteelChemicalApiInfoItem, err error) {
|
|
|
+func GetMySteelChemicalIndexNameMap() (indexNameMap map[string]*models.MySteelChemicalApiInfoItem, err error) {
|
|
|
if utils.MysteelChemicalApiToken == "" {
|
|
|
err = errors.New("钢联接口token未配置")
|
|
|
return
|
|
|
}
|
|
|
+ item, err := getPageIndexInfoMap(1, 200)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ indexNameMap = make(map[string]*models.MySteelChemicalApiInfoItem)
|
|
|
+ for _, v := range item.Data.List {
|
|
|
+ indexNameMap[v.IndexCode] = v
|
|
|
+ }
|
|
|
+ // 如果总条数大于200,则继续获取
|
|
|
+ if item.Data.Total > 200 || item.Data.Pages > 1 {
|
|
|
+ for i := 2; i <= item.Data.Pages; i++ {
|
|
|
+ item, err = getPageIndexInfoMap(i, 200)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range item.Data.List {
|
|
|
+ indexNameMap[v.IndexCode] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func getPageIndexInfoMap(pageNum, pageSize int) (item *models.MySteelChemicalApiInfoResp, err error) {
|
|
|
m := new(MySteelChemicalApiInfoBody)
|
|
|
- m.PageNum = 1
|
|
|
- m.PageSize = 100 // 看官方api最多也就十几条指标,先固定设置100应该足够了
|
|
|
+ m.PageNum = pageNum
|
|
|
+ m.PageSize = pageSize
|
|
|
m.IncludeInfo = true
|
|
|
postData, er := json.Marshal(m)
|
|
|
if er != nil {
|
|
@@ -546,24 +571,20 @@ func GetMySteelChemicalIndexNameMap(indexCodes []string) (indexNameMap map[strin
|
|
|
return
|
|
|
}
|
|
|
postUrl := `https://mds.mysteel.com/dynamic/order/api/fcAbRA`
|
|
|
- body, err := MySteelChemicalPost(postUrl, "info", postData)
|
|
|
- if err != nil {
|
|
|
+ body, er := MySteelChemicalPost(postUrl, "info", postData)
|
|
|
+ if er != nil {
|
|
|
+ err = er
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- var item *models.MySteelChemicalApiInfoResp
|
|
|
err = json.Unmarshal(body, &item)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
if !item.Success {
|
|
|
err = errors.New(item.Message)
|
|
|
+ utils.FileLog.Info("code:" + item.Code + " message:" + item.Message)
|
|
|
return
|
|
|
}
|
|
|
- indexNameMap = make(map[string]*models.MySteelChemicalApiInfoItem)
|
|
|
- for _, v := range item.Data.List {
|
|
|
- indexNameMap[v.IndexCode] = v
|
|
|
- }
|
|
|
return
|
|
|
}
|
|
|
|