eic.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta/eta_task/models/data_manage"
  5. "eta/eta_task/utils"
  6. "fmt"
  7. "time"
  8. )
  9. // 天然气
  10. func SyncRankingFromEic() (err error) {
  11. var startDate string
  12. maxDate, err := data_manage.GetBaseFromEicIndexMaxDate()
  13. if err != nil || maxDate.IsZero() {
  14. startDate = time.Now().AddDate(0, 0, -1).Format(utils.FormatDate) + " 00:00:00"
  15. } else {
  16. startDate = maxDate.AddDate(0, 0, 1).Format(utils.FormatDate) + " 00:00:00"
  17. }
  18. method := `index/list`
  19. data := make(map[string]interface{})
  20. data["Source"] = utils.DATA_SOURCE_GIE
  21. data["StartDate"] = startDate
  22. //data["EndDate"] = endDate
  23. result, err := HttpPost("SyncRankingFromEic", method, data)
  24. utils.FileLog.Info(result)
  25. fmt.Println(result)
  26. respObj := new(data_manage.EicIndexResp)
  27. err = json.Unmarshal([]byte(result), &respObj)
  28. if err != nil {
  29. return err
  30. }
  31. //获取所有指标信息 某一天的
  32. allIndex, err := data_manage.GetBaseFromEicIndexAll(startDate)
  33. if err != nil {
  34. return
  35. }
  36. existIndexMap := make(map[int]*data_manage.BaseFromTradeEicIndexV2)
  37. for _, v := range allIndex {
  38. existIndexMap[v.BaseFromEicIndexId] = v
  39. }
  40. for _, zv := range respObj.Data {
  41. if _, ok := existIndexMap[zv.BaseFromEicIndexId]; !ok {
  42. newID, err := data_manage.AddBaseFromEicIndexV2(zv)
  43. if err != nil {
  44. fmt.Println("insert error:", err)
  45. }
  46. fmt.Println("insert new indexID:", newID)
  47. }
  48. }
  49. return err
  50. }