trade_ine.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 SyncRankingFromIne() (err error) {
  11. var startDate string
  12. maxDate, err := data_manage.GetBaseFromTradeIneIndexMaxDate()
  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.Format(utils.FormatDate) + " 00:00:00"
  17. }
  18. method := `index/list`
  19. data := make(map[string]interface{})
  20. data["Source"] = utils.DATA_SOURCE_SHFE
  21. data["StartDate"] = startDate
  22. //data["EndDate"] = endDate
  23. result, err := HttpPost("SyncRankingFromIne", method, data)
  24. utils.FileLog.Info(result)
  25. fmt.Println(result)
  26. respObj := new(data_manage.IneIndexResp)
  27. err = json.Unmarshal([]byte(result), &respObj)
  28. if err != nil {
  29. return err
  30. }
  31. //获取所有指标信息 某一天的
  32. allIndex, err := data_manage.GetBaseFromTradeIneIndexAll(startDate)
  33. if err != nil {
  34. return
  35. }
  36. existIndexMap := make(map[int]*data_manage.BaseFromTradeIneIndex)
  37. for _, v := range allIndex {
  38. existIndexMap[v.BaseFromTradeIneIndexId] = v
  39. }
  40. for _, zv := range respObj.Data {
  41. if _, ok := existIndexMap[zv.BaseFromTradeIneIndexId]; !ok {
  42. newID, err := data_manage.AddBaseFromTradeIneIndex(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. }