config_offset.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package model
  2. import (
  3. "time"
  4. )
  5. // LoopOffset single table offset
  6. type LoopOffset struct {
  7. IsLoop bool
  8. OffsetID int64
  9. OffsetTime string
  10. TempOffsetID int64
  11. TempOffsetTime string
  12. RecoverID int64
  13. RecoverTime string
  14. TempRecoverID int64
  15. TempRecoverTime string
  16. ReviewID int64
  17. ReviewTime int64
  18. }
  19. // SetLoop .
  20. func (lo *LoopOffset) SetLoop(isLoop bool) {
  21. lo.IsLoop = isLoop
  22. }
  23. // SetReview .
  24. func (lo *LoopOffset) SetReview(rid int64, rtime int64) {
  25. lo.ReviewID = rid
  26. lo.ReviewTime = rtime
  27. }
  28. // SetOffset .
  29. func (lo *LoopOffset) SetOffset(id int64, t string) {
  30. if id != 0 {
  31. lo.OffsetID = id
  32. }
  33. if t != "" {
  34. lo.OffsetTime = t
  35. if !lo.IsLoop {
  36. if local, err := time.LoadLocation("Local"); err == nil {
  37. if t2, e := time.ParseInLocation("2006-01-02 15:04:05", t, local); e == nil && t2.Unix()-lo.ReviewTime > 0 {
  38. lo.OffsetTime = time.Unix(t2.Unix()-lo.ReviewTime, 0).Format("2006-01-02 15:04:05") //往前推ReviewTime
  39. }
  40. }
  41. }
  42. }
  43. }
  44. // SetTempOffset .
  45. func (lo *LoopOffset) SetTempOffset(id int64, time string) {
  46. if id != 0 {
  47. lo.TempOffsetID = id
  48. }
  49. if time != "" {
  50. lo.TempOffsetTime = time
  51. }
  52. }
  53. // SetRecoverOffset .
  54. func (lo *LoopOffset) SetRecoverOffset(recoverID int64, recoverTime string) {
  55. if recoverID >= 0 {
  56. lo.RecoverID = recoverID
  57. }
  58. if recoverTime != "" {
  59. lo.RecoverTime = recoverTime
  60. }
  61. }
  62. // SetRecoverTempOffset .
  63. func (lo *LoopOffset) SetRecoverTempOffset(recoverID int64, recoverTime string) {
  64. if recoverID >= 0 {
  65. lo.TempRecoverID = recoverID
  66. }
  67. if recoverTime != "" {
  68. lo.TempRecoverTime = recoverTime
  69. }
  70. }
  71. // LoopOffsets more tables offset
  72. type LoopOffsets map[int]*LoopOffset
  73. // SetLoops .
  74. func (los LoopOffsets) SetLoops(i int, isLoop bool) {
  75. if _, ok := los[i]; ok {
  76. los[i].IsLoop = isLoop
  77. }
  78. }
  79. // SetOffsets .
  80. func (los LoopOffsets) SetOffsets(i int, id int64, time string) {
  81. if id != 0 {
  82. los[i].OffsetID = id
  83. }
  84. if time != "" {
  85. los[i].OffsetTime = time
  86. }
  87. }
  88. // SetTempOffsets .
  89. func (los LoopOffsets) SetTempOffsets(i int, id int64, time string) {
  90. if id != 0 {
  91. los[i].TempOffsetID = id
  92. }
  93. if time != "" {
  94. los[i].TempOffsetTime = time
  95. }
  96. }
  97. // SetRecoverOffsets .
  98. func (los LoopOffsets) SetRecoverOffsets(i int, recoverID int64, recoverTime string) {
  99. if recoverID >= 0 {
  100. los[i].RecoverID = recoverID
  101. }
  102. if recoverTime != "" {
  103. los[i].RecoverTime = recoverTime
  104. }
  105. }
  106. // SetRecoverTempOffsets .
  107. func (los LoopOffsets) SetRecoverTempOffsets(i int, recoverID int64, recoverTime string) {
  108. if recoverID >= 0 {
  109. los[i].TempRecoverID = recoverID
  110. }
  111. if recoverTime != "" {
  112. los[i].TempRecoverTime = recoverTime
  113. }
  114. }