package services

import (
	"encoding/json"
	"fmt"
	"hongze/hongze_edb_lib/utils"

	"github.com/rdlucklib/rdluck_tools/http"
)

type EdbDataFromLt struct {
	Close map[int64]interface{} `json:"CLOSE"`
	Value map[int64]interface{} `json:"VALUE"`
}

// GetEdbDataFromLt 获取路透数据
func GetEdbDataFromLt(edbCode, startDate, endDate string) (dataList map[int64]interface{}, err error) {
	dataList = make(map[int64]interface{})
	ltUrl := utils.Hz_LT_Data_Url + `edbInfo/ek?EdbCode=%s&StartDate=%s&EndDate=%s`
	ltUrl = fmt.Sprintf(ltUrl, edbCode, startDate, endDate)
	utils.FileLog.Info("ltUrl:%s", ltUrl)
	body, err := http.Get(ltUrl)
	utils.FileLog.Info("lt result:%s", string(body))

	if err != nil {
		return
	}
	item := new(EdbDataFromLt)
	err = json.Unmarshal(body, &item)

	if err != nil {
		return
	}
	if len(item.Close) > 0 {
		dataList = item.Close
	} else {
		dataList = item.Value
	}
	return
}
