edb_info_sync.go 1.9 KB

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