trade_dalian.go 1.5 KB

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