edb_info_sync.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package data
  2. import (
  3. "eta/eta_task/models/data_manage"
  4. "eta/eta_task/utils"
  5. "strings"
  6. "sync"
  7. )
  8. var lock sync.Mutex
  9. // 同步钢炼数据
  10. func SyncGlDataBase() {
  11. lock.Lock()
  12. var err error
  13. defer func() {
  14. if err != nil {
  15. utils.FileLog.Info("SyncGlDataBase Err:" + err.Error())
  16. }
  17. }()
  18. var condition string
  19. var pars []interface{}
  20. condition += " AND source=? "
  21. pars = append(pars, utils.DATA_SOURCE_GL)
  22. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  23. if err != nil {
  24. return
  25. }
  26. for _, v := range items {
  27. err = data_manage.RefreshEdbDataByGl(v.EdbInfoId, v.EdbCode, v.StartDate.Format(utils.FormatDate), "")
  28. if err != nil {
  29. return
  30. }
  31. item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, utils.DATA_SUB_SOURCE_EDB, v.EdbCode)
  32. if err != nil {
  33. return
  34. }
  35. if item != nil {
  36. err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  37. if err != nil {
  38. return
  39. }
  40. }
  41. }
  42. lock.Unlock()
  43. }
  44. var manualLock sync.Mutex
  45. // SyncManualDataBase 同步手工数据
  46. func SyncManualDataBase() {
  47. var err error
  48. errMsgList := make([]string, 0)
  49. manualLock.Lock()
  50. defer func() {
  51. manualLock.Unlock()
  52. if len(errMsgList) > 0 {
  53. errMsg := strings.Join(errMsgList, "\n")
  54. utils.FileLog.Info("SyncManualDataBase Err:" + errMsg)
  55. go utils.SendEmailByHongze("同步手工数据失败", "同步手工数据失败 Err:"+errMsg, utils.RefreshEdbInfoEmailSendToUsers, "", "")
  56. }
  57. }()
  58. var condition string
  59. var pars []interface{}
  60. condition += " AND source=? "
  61. //condition += " AND edb_code='W000156' "
  62. pars = append(pars, utils.DATA_SOURCE_MANUAL)
  63. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  64. if err != nil {
  65. errMsgList = append(errMsgList, "获取指标失败 ;Err:"+err.Error())
  66. return
  67. }
  68. for _, v := range items {
  69. startDate := v.StartDate.Format(utils.FormatDate)
  70. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
  71. if err != nil {
  72. //return errors.New("RefreshEdbData Err:" + err.Error())
  73. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  74. continue
  75. }
  76. if resp.Ret != 200 {
  77. //return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  78. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  79. continue
  80. }
  81. }
  82. }