edb_info_sync.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package data
  2. import (
  3. "hongze/hongze_task/models/data_manage"
  4. "hongze/hongze_task/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 lzLock sync.Mutex
  44. //同步隆重数据
  45. func SyncLzDataBase() {
  46. lzLock.Lock()
  47. var err error
  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. pars = append(pars, utils.DATA_SOURCE_LZ)
  58. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  59. if err != nil {
  60. return
  61. }
  62. for _, v := range items {
  63. err = data_manage.RefreshEdbDataByLz(v.EdbInfoId, v.EdbCode, v.StartDate.Format(utils.FormatDate), "")
  64. if err != nil {
  65. return
  66. }
  67. item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  68. if err != nil {
  69. return
  70. }
  71. if item != nil {
  72. err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  73. if err != nil {
  74. return
  75. }
  76. }
  77. }
  78. lzLock.Unlock()
  79. }
  80. var smmLock sync.Mutex
  81. //同步有色数据
  82. func SyncSmmDataBase() {
  83. smmLock.Lock()
  84. var err error
  85. defer func() {
  86. if err != nil {
  87. utils.FileLog.Info("SyncSmmDataBase Err:" + err.Error())
  88. go utils.SendEmailByHongze("同步有色数据失败", "同步隆众数据失败 Err:"+err.Error(), utils.RefreshEdbInfoEmailSendToUsers, "", "")
  89. }
  90. }()
  91. var condition string
  92. var pars []interface{}
  93. condition += " AND source=? "
  94. pars = append(pars, utils.DATA_SOURCE_YS)
  95. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  96. if err != nil {
  97. return
  98. }
  99. for _, v := range items {
  100. err = data_manage.RefreshEdbDataByYs(v.EdbInfoId, v.EdbCode, v.StartDate.Format(utils.FormatDate), "")
  101. if err != nil {
  102. return
  103. }
  104. item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  105. if err != nil {
  106. return
  107. }
  108. if item != nil {
  109. err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  110. if err != nil {
  111. return
  112. }
  113. }
  114. }
  115. smmLock.Unlock()
  116. }
  117. var manualLock sync.Mutex
  118. //同步手工数据
  119. func SyncManualDataBase() {
  120. var err error
  121. manualLock.Lock()
  122. defer func() {
  123. if err != nil {
  124. utils.FileLog.Info("SyncLzDataBase Err:" + err.Error())
  125. go utils.SendEmailByHongze("同步手工数据失败", "同步手工数据失败 Err:"+err.Error(), utils.RefreshEdbInfoEmailSendToUsers, "", "")
  126. }
  127. }()
  128. var condition string
  129. var pars []interface{}
  130. condition += " AND source=? "
  131. //condition += " AND edb_code='W000156' "
  132. pars = append(pars, utils.DATA_SOURCE_MANUAL)
  133. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  134. if err != nil {
  135. return
  136. }
  137. for _, v := range items {
  138. err = data_manage.RefreshManual(v)
  139. if err != nil {
  140. return
  141. }
  142. item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  143. if err != nil {
  144. return
  145. }
  146. if item != nil {
  147. err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  148. if err != nil {
  149. return
  150. }
  151. }
  152. }
  153. manualLock.Unlock()
  154. }