db_login_logic.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package logic
  2. import (
  3. handler2 "call_center/db/rpc/internal/handler"
  4. "call_center/public/exception"
  5. "context"
  6. "io"
  7. "log"
  8. "call_center/db/rpc/internal/svc"
  9. "call_center/db/rpc/pb"
  10. "github.com/tal-tech/go-zero/core/logx"
  11. )
  12. type DbLoginLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewDbLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DbLoginLogic {
  18. return &DbLoginLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. func (l *DbLoginLogic) DbLogin(stream pb.Db_DbLoginServer) error {
  25. var err error
  26. exception.Try(func() {
  27. log.Println("<DbLogin>")
  28. for {
  29. req, err := stream.Recv()
  30. if err != nil {
  31. if err == io.EOF {
  32. }
  33. log.Println("<DbLogin> 连接断开, req:", req)
  34. break
  35. }
  36. cmd := req.Cmd
  37. cmdType := cmd.CmdType
  38. switch cmdType {
  39. case pb.EDbCommand_E_DB_COMMAND_PUSH_CHAT_LOG:
  40. handler2.PushChatLog(l.svcCtx, cmd)
  41. break
  42. case pb.EDbCommand_E_DB_COMMAND_PUSH_CHAT_RECORD:
  43. handler2.PushChatRecord(l.svcCtx, cmd)
  44. break
  45. }
  46. if err != nil {
  47. continue
  48. }
  49. }
  50. }).Catch(func(e exception.Exception) {
  51. err = e.(error)
  52. }).Finally(func() {
  53. })
  54. return err
  55. }