databus.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package dao
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/service/main/favorite/model"
  6. )
  7. func (d *Dao) send(c context.Context, mid int64, msg *model.Message) error {
  8. key := strconv.FormatInt(mid, 10)
  9. return d.jobDatabus.Send(c, key, msg)
  10. }
  11. // PubAddFav push the add resource event into databus.
  12. func (d *Dao) PubSortFavs(c context.Context, tp int8, mid, fid int64, sorts []model.SortFav) {
  13. msg := &model.Message{
  14. Field: model.FieldResource,
  15. Action: model.ActionSortFavs,
  16. Type: tp,
  17. Mid: mid,
  18. Fid: fid,
  19. SortFavs: sorts,
  20. }
  21. d.send(c, mid, msg)
  22. }
  23. // PubAddFav push the add resource event into databus.
  24. func (d *Dao) PubAddFav(c context.Context, tp int8, mid, fid, oid int64, attr int32, ts int64, otype int8) {
  25. msg := &model.Message{
  26. Field: model.FieldResource,
  27. Action: model.ActionAdd,
  28. Type: tp,
  29. Mid: mid,
  30. Fid: fid,
  31. Oid: oid,
  32. FolderAttr: attr,
  33. FTime: ts,
  34. Otype: otype,
  35. }
  36. d.send(c, mid, msg)
  37. }
  38. // PubDelFav push the delete favorite event into databus.
  39. func (d *Dao) PubDelFav(c context.Context, tp int8, mid, fid, oid int64, attr int32, ts int64, otype int8) {
  40. msg := &model.Message{
  41. Field: model.FieldResource,
  42. Action: model.ActionDel,
  43. Type: tp,
  44. Mid: mid,
  45. Fid: fid,
  46. Oid: oid,
  47. FolderAttr: attr,
  48. FTime: ts,
  49. Otype: otype,
  50. }
  51. d.send(c, mid, msg)
  52. }
  53. // PubInitRelationFids push the relationfids cache event into databus.
  54. func (d *Dao) PubInitRelationFids(c context.Context, tp int8, mid int64) {
  55. msg := &model.Message{
  56. Field: model.FieldResource,
  57. Action: model.ActionInitRelationFids,
  58. Type: tp,
  59. Mid: mid,
  60. }
  61. d.send(c, mid, msg)
  62. }
  63. // PubInitFolderRelations push the folder relations cache event into databus.
  64. func (d *Dao) PubInitFolderRelations(c context.Context, tp int8, mid, fid int64) {
  65. msg := &model.Message{
  66. Field: model.FieldResource,
  67. Action: model.ActionInitFolderRelations,
  68. Type: tp,
  69. Mid: mid,
  70. Fid: fid,
  71. }
  72. d.send(c, mid, msg)
  73. }
  74. // PubInitAllFolderRelations push the folder relations cache event into databus.
  75. func (d *Dao) PubInitAllFolderRelations(c context.Context, tp int8, mid, fid int64) {
  76. msg := &model.Message{
  77. Field: model.FieldResource,
  78. Action: model.ActionInitAllFolderRelations,
  79. Type: tp,
  80. Mid: mid,
  81. Fid: fid,
  82. }
  83. d.send(c, mid, msg)
  84. }
  85. // PubAddFolder push the add folder action event into databus.
  86. func (d *Dao) PubAddFolder(c context.Context, typ int8, mid, fid int64, attr int32) {
  87. msg := &model.Message{
  88. Field: model.FieldResource,
  89. Action: model.ActionFolderAdd,
  90. Type: typ,
  91. Mid: mid,
  92. Fid: fid,
  93. FolderAttr: attr,
  94. }
  95. d.send(c, mid, msg)
  96. }
  97. // PubDelFolder push the del folder action event into databus.
  98. func (d *Dao) PubDelFolder(c context.Context, typ int8, mid, fid int64, attr int32, ts int64) {
  99. msg := &model.Message{
  100. Field: model.FieldResource,
  101. Action: model.ActionFolderDel,
  102. Type: typ,
  103. Mid: mid,
  104. Fid: fid,
  105. FolderAttr: attr,
  106. FTime: ts,
  107. }
  108. d.send(c, mid, msg)
  109. }
  110. // PubMultiDelFavs push the multi del fav relations event into databus.
  111. func (d *Dao) PubMultiDelFavs(c context.Context, typ int8, mid, fid, rows int64, attr int32, oids []int64, ts int64) {
  112. msg := &model.Message{
  113. Field: model.FieldResource,
  114. Action: model.ActionMultiDel,
  115. Type: typ,
  116. Mid: mid,
  117. Fid: fid,
  118. Affected: rows,
  119. FolderAttr: attr,
  120. Oids: oids,
  121. FTime: ts,
  122. }
  123. d.send(c, mid, msg)
  124. }
  125. // PubMultiAddFavs push the multi add fav relations event into databus.
  126. func (d *Dao) PubMultiAddFavs(c context.Context, typ int8, mid, fid, rows int64, attr int32, oids []int64, ts int64) {
  127. msg := &model.Message{
  128. Field: model.FieldResource,
  129. Action: model.ActionMultiAdd,
  130. Type: typ,
  131. Mid: mid,
  132. Fid: fid,
  133. Affected: rows,
  134. FolderAttr: attr,
  135. Oids: oids,
  136. FTime: ts,
  137. }
  138. d.send(c, mid, msg)
  139. }
  140. // PubMoveFavs push the move resources event into databus.
  141. func (d *Dao) PubMoveFavs(c context.Context, typ int8, mid, ofid, nfid, rows int64, oids []int64, ts int64) {
  142. msg := &model.Message{
  143. Field: model.FieldResource,
  144. Action: model.ActionMove,
  145. Type: typ,
  146. Mid: mid,
  147. OldFid: ofid,
  148. NewFid: nfid,
  149. Affected: rows,
  150. Oids: oids,
  151. FTime: ts,
  152. }
  153. d.send(c, mid, msg)
  154. }
  155. // PubCopyFavs push the copy resources event into databus.
  156. func (d *Dao) PubCopyFavs(c context.Context, typ int8, mid, ofid, nfid, rows int64, oids []int64, ts int64) {
  157. msg := &model.Message{
  158. Field: model.FieldResource,
  159. Action: model.ActionCopy,
  160. Type: typ,
  161. Mid: mid,
  162. OldFid: ofid,
  163. NewFid: nfid,
  164. Affected: rows,
  165. Oids: oids,
  166. FTime: ts,
  167. }
  168. d.send(c, mid, msg)
  169. }
  170. // PubClean push the clean video event into databus.
  171. func (d *Dao) PubClean(c context.Context, typ int8, mid, fid, ftime int64) {
  172. msg := &model.Message{
  173. Field: model.FieldResource,
  174. Action: model.ActionClean,
  175. Type: typ,
  176. Mid: mid,
  177. Fid: fid,
  178. FTime: ftime,
  179. }
  180. d.send(c, mid, msg)
  181. }