changes_visitors_covid.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 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. result, err := HttpPost("SyncChangesVisitorsCovid", method, data)
  24. utils.FileLog.Info(result)
  25. fmt.Println(result)
  26. respObj := new(data_manage.ChangesVisitorsCovidIndexResp)
  27. err = json.Unmarshal([]byte(result), &respObj)
  28. if err != nil {
  29. return err
  30. }
  31. //获取所有指标信息 某一天的
  32. allIndex, err := data_manage.GetChangesVisitorsCovidAll(startDate)
  33. if err != nil {
  34. return
  35. }
  36. existIndexMap := make(map[uint64]*data_manage.BaseFromChangesVisitorsCovid)
  37. for _, v := range allIndex {
  38. existIndexMap[v.Id] = v
  39. }
  40. for _, zv := range respObj.Data {
  41. if _, ok := existIndexMap[zv.Id]; !ok {
  42. err := data_manage.AddBaseFromChangesVisitorsCovid(zv)
  43. if err != nil {
  44. fmt.Println("insert error:", err)
  45. }
  46. }
  47. }
  48. return err
  49. }