changes_visitors_covid.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package services
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_task_trial/models/data_manage"
  6. "hongze/hongze_task_trial/utils"
  7. "time"
  8. )
  9. // 谷歌出现数据
  10. func SyncChangesVisitorsCovid() (err error) {
  11. var startDate string
  12. maxDate, err := data_manage.GetChangesVisitorsCovidMaxDate()
  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_GOOGLE_TRAVEL
  21. data["StartDate"] = startDate
  22. //data["EndDate"] = endDate
  23. bytesData, _ := json.Marshal(data)
  24. result, err := HttpPost(method, bytesData)
  25. utils.FileLog.Info(result)
  26. fmt.Println(result)
  27. respObj := new(data_manage.ChangesVisitorsCovidIndexResp)
  28. err = json.Unmarshal([]byte(result), &respObj)
  29. if err != nil {
  30. return err
  31. }
  32. //获取所有指标信息 某一天的
  33. allIndex, err := data_manage.GetChangesVisitorsCovidAll(startDate)
  34. if err != nil {
  35. return
  36. }
  37. existIndexMap := make(map[uint64]*data_manage.BaseFromChangesVisitorsCovid)
  38. for _, v := range allIndex {
  39. existIndexMap[v.Id] = v
  40. }
  41. for _, zv := range respObj.Data {
  42. if _, ok := existIndexMap[zv.Id]; !ok {
  43. err := data_manage.AddBaseFromChangesVisitorsCovid(zv)
  44. if err != nil {
  45. fmt.Println("insert error:", err)
  46. }
  47. }
  48. }
  49. return err
  50. }