base_from_ths.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/http"
  7. "hongze/hongze_edb_lib/utils"
  8. )
  9. type EdbDataFromThs struct {
  10. DataVol int64 `json:"dataVol"`
  11. Errmsg string `json:"errmsg"`
  12. Errorcode int64 `json:"errorcode"`
  13. Perf interface{} `json:"perf"`
  14. Tables []struct {
  15. ID []string `json:"id"`
  16. Time []string `json:"time"`
  17. Value []float64 `json:"value"`
  18. } `json:"tables"`
  19. }
  20. func GetEdbDataFromThs(edbCode, startDate, endDate string) (item *EdbDataFromThs, err error) {
  21. thsUrl := utils.Hz_Ths_Data_Url + `edbInfo/ths?EdbCode=%s&StartDate=%s&EndDate=%s`
  22. thsUrl = fmt.Sprintf(thsUrl, edbCode, startDate, endDate)
  23. utils.FileLog.Info("thsUrl:" + thsUrl)
  24. body, err := http.Get(thsUrl)
  25. utils.FileLog.Info("ths result:" + string(body))
  26. if err != nil {
  27. err = errors.New(" Err:" + err.Error() + ";result:" + string(body))
  28. return
  29. }
  30. item = new(EdbDataFromThs)
  31. err = json.Unmarshal(body, &item)
  32. if err != nil {
  33. err = errors.New("GetEdbDataFromThs json.Unmarshal Err:" + err.Error())
  34. return
  35. }
  36. if item.Errorcode != 0 {
  37. err = errors.New(string(body))
  38. return
  39. }
  40. return item, nil
  41. }