meeting_probabilities.go 1.5 KB

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