trade_zhengzhou.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 SyncRankingFromZhengzhou() (err error) {
  11. var startDate string
  12. maxDate, err := data_manage.GetBaseFromTradeZhengzhouIndexMaxDate()
  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_DL
  21. data["Source"] = utils.DATA_SOURCE_ZZ
  22. data["StartDate"] = startDate
  23. //data["EndDate"] = endDate
  24. result, err := HttpPost("SyncRankingFromZhengzhou", method, data)
  25. if err != nil {
  26. fmt.Println("SyncRankingFromZhengzhou HttpPost Err:", err.Error())
  27. }
  28. utils.FileLog.Info(result)
  29. fmt.Println("SyncRankingFromZhengzhou result:", result)
  30. respObj := new(data_manage.ZhengzhouIndexResp)
  31. err = json.Unmarshal([]byte(result), &respObj)
  32. if err != nil {
  33. return err
  34. }
  35. //获取所有指标信息 某一天的
  36. allIndex, err := data_manage.GetBaseFromTradeZhengzhouIndexAll(startDate)
  37. if err != nil {
  38. return
  39. }
  40. existIndexMap := make(map[int]*data_manage.BaseFromTradeZhengzhouIndex)
  41. for _, v := range allIndex {
  42. existIndexMap[v.BaseFromTradeZhengzhouIndexId] = v
  43. }
  44. for _, zv := range respObj.Data {
  45. if _, ok := existIndexMap[zv.BaseFromTradeZhengzhouIndexId]; !ok {
  46. newID, err := data_manage.AddBaseFromTradeZhengzhouIndex(zv)
  47. if err != nil {
  48. fmt.Println("insert error:", err)
  49. }
  50. fmt.Println("insert new indexID:", newID)
  51. }
  52. }
  53. return err
  54. }