dao.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package dao
  2. import (
  3. "context"
  4. v1pb "go-common/app/service/live/xanchor/api/grpc/v1"
  5. "go-common/app/service/live/xanchor/conf"
  6. "go-common/library/cache/redis"
  7. xsql "go-common/library/database/sql"
  8. )
  9. type refValue struct {
  10. field string
  11. v interface{}
  12. }
  13. // Dao dao
  14. type Dao struct {
  15. c *conf.Config
  16. redis *redis.Pool
  17. db *xsql.DB
  18. dbLiveApp *xsql.DB
  19. }
  20. // New init mysql db
  21. func New(c *conf.Config) (dao *Dao) {
  22. dao = &Dao{
  23. c: c,
  24. redis: redis.NewPool(c.Redis),
  25. db: xsql.NewMySQL(c.MySQL),
  26. dbLiveApp: xsql.NewMySQL(c.LiveAppMySQL),
  27. }
  28. return
  29. }
  30. // Close close the resource.
  31. func (d *Dao) Close() {
  32. d.redis.Close()
  33. d.db.Close()
  34. return
  35. }
  36. // Ping dao ping
  37. func (d *Dao) Ping(c context.Context) error {
  38. // TODO: if you need use mc,redis, please add
  39. return d.db.Ping(c)
  40. }
  41. // FetchRoomByIDs implementation
  42. // FetchRoomByIDs 查询房间信息
  43. func (d *Dao) FetchRoomByIDs(ctx context.Context, req *v1pb.RoomByIDsReq) (resp *v1pb.RoomByIDsResp, err error) {
  44. return d.fetchRoomByIDs(ctx, req)
  45. }
  46. // RoomOnlineList implementation
  47. // RoomOnlineList 在线房间列表
  48. func (d *Dao) RoomOnlineList(ctx context.Context, req *v1pb.RoomOnlineListReq) (resp *v1pb.RoomOnlineListResp, err error) {
  49. return d.roomOnlineList(ctx, req)
  50. }
  51. // RoomCreate implementation
  52. // RoomCreate 房间创建
  53. func (d *Dao) RoomCreate(ctx context.Context, req *v1pb.RoomCreateReq) (resp *v1pb.RoomCreateResp, err error) {
  54. return d.roomCreate(ctx, req)
  55. }
  56. // RoomUpdate implementation
  57. // RoomUpdate 房间更新
  58. func (d *Dao) RoomUpdate(ctx context.Context, req *v1pb.RoomUpdateReq) (resp *v1pb.UpdateResp, err error) {
  59. return d.roomUpdate(ctx, req)
  60. }
  61. // RoomBatchUpdate implementation
  62. // RoomBatchUpdate 房间更新
  63. func (d *Dao) RoomBatchUpdate(ctx context.Context, req *v1pb.RoomBatchUpdateReq) (resp *v1pb.UpdateResp, err error) {
  64. return d.roomBatchUpdate(ctx, req)
  65. }
  66. // RoomExtendUpdate implementation
  67. // RoomExtendUpdate 房间更新
  68. func (d *Dao) RoomExtendUpdate(ctx context.Context, req *v1pb.RoomExtendUpdateReq) (resp *v1pb.UpdateResp, err error) {
  69. return d.roomExtendUpdate(ctx, req)
  70. }
  71. // RoomExtendBatchUpdate implementation
  72. // RoomExtendBatchUpdate 房间更新
  73. func (d *Dao) RoomExtendBatchUpdate(ctx context.Context, req *v1pb.RoomExtendBatchUpdateReq) (resp *v1pb.UpdateResp, err error) {
  74. return d.roomExtendBatchUpdate(ctx, req)
  75. }
  76. // RoomExtendIncre implementation
  77. // RoomExtendIncre 房间增量更新
  78. func (d *Dao) RoomExtendIncre(ctx context.Context, req *v1pb.RoomExtendIncreReq) (resp *v1pb.UpdateResp, err error) {
  79. return d.roomExtendIncre(ctx, req)
  80. }
  81. // RoomExtendBatchIncre implementation
  82. // RoomExtendBatchIncre 房间增量更新
  83. func (d *Dao) RoomExtendBatchIncre(ctx context.Context, req *v1pb.RoomExtendBatchIncreReq) (resp *v1pb.UpdateResp, err error) {
  84. return d.roomExtendBatchIncre(ctx, req)
  85. }
  86. // RoomTagSet implementation
  87. // RoomTagSet 房间Tag更新
  88. func (d *Dao) RoomTagSet(ctx context.Context, req *v1pb.RoomTagSetReq) (resp *v1pb.UpdateResp, err error) {
  89. return d.roomTagSet(ctx, req)
  90. }
  91. // AnchorUpdate implementation
  92. // AnchorUpdate 主播更新
  93. func (d *Dao) AnchorUpdate(ctx context.Context, req *v1pb.AnchorUpdateReq) (resp *v1pb.UpdateResp, err error) {
  94. return d.anchorUpdate(ctx, req)
  95. }
  96. // AnchorBatchUpdate implementation
  97. // AnchorBatchUpdate 主播更新
  98. func (d *Dao) AnchorBatchUpdate(ctx context.Context, req *v1pb.AnchorBatchUpdateReq) (resp *v1pb.UpdateResp, err error) {
  99. return d.anchorBatchUpdate(ctx, req)
  100. }
  101. // AnchorIncre implementation
  102. // AnchorIncre 主播增量更新
  103. func (d *Dao) AnchorIncre(ctx context.Context, req *v1pb.AnchorIncreReq) (resp *v1pb.UpdateResp, err error) {
  104. return d.anchorIncre(ctx, req)
  105. }
  106. // AnchorBatchIncre implementation
  107. // AnchorBatchIncre 主播增量更新
  108. func (d *Dao) AnchorBatchIncre(ctx context.Context, req *v1pb.AnchorBatchIncreReq) (resp *v1pb.UpdateResp, err error) {
  109. return d.anchorBatchIncre(ctx, req)
  110. }
  111. // AnchorTagSet implementation
  112. // AnchorTagSet 主播Tag更新
  113. func (d *Dao) AnchorTagSet(ctx context.Context, req *v1pb.AnchorTagSetReq) (resp *v1pb.UpdateResp, err error) {
  114. return d.anchorTagSet(ctx, req)
  115. }