edb_info_sync.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package data
  2. import (
  3. "eta_gn/eta_task/models/data_manage"
  4. "eta_gn/eta_task/utils"
  5. "strings"
  6. "sync"
  7. )
  8. var manualLock sync.Mutex
  9. // SyncManualDataBase 同步手工数据
  10. func SyncManualDataBase() {
  11. var err error
  12. errMsgList := make([]string, 0)
  13. manualLock.Lock()
  14. defer func() {
  15. manualLock.Unlock()
  16. if len(errMsgList) > 0 {
  17. errMsg := strings.Join(errMsgList, "\n")
  18. utils.FileLog.Info("SyncManualDataBase Err:" + errMsg)
  19. go utils.SendEmailByHongze("同步手工数据失败", "同步手工数据失败 Err:"+errMsg, utils.RefreshEdbInfoEmailSendToUsers, "", "")
  20. }
  21. }()
  22. var condition string
  23. var pars []interface{}
  24. condition += " AND source=? "
  25. //condition += " AND edb_code='W000156' "
  26. pars = append(pars, utils.DATA_SOURCE_MANUAL)
  27. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  28. if err != nil {
  29. errMsgList = append(errMsgList, "获取指标失败 ;Err:"+err.Error())
  30. return
  31. }
  32. for _, v := range items {
  33. startDate := v.StartDate.Format(utils.FormatDate)
  34. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  35. if err != nil {
  36. //return errors.New("RefreshEdbData Err:" + err.Error())
  37. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  38. continue
  39. }
  40. if resp.Ret != 200 {
  41. //return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  42. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  43. continue
  44. }
  45. }
  46. }