savemessagelogic.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package logic
  2. import (
  3. "context"
  4. quitl "app.yhyue.com/moapp/jybase/common"
  5. "app.yhyue.com/moapp/jybase/encrypt"
  6. util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
  7. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/internal/svc"
  8. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
  9. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/service"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type SaveMessageLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewSaveMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveMessageLogic {
  18. return &SaveMessageLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. // 聊天保存
  25. func (l *SaveMessageLogic) SaveMessage(in *messagecenter.MessageEntity) (*messagecenter.SaveMessageResp, error) {
  26. // todo: add your logic here and delete this line
  27. m := service.MessaggeService{}
  28. fool, error_message, content, messageId, nowTime := func() (fool bool, errorMsg string, content string, messageId, nowInt int64) {
  29. if in.ItemType != 2 && in.ItemType != 3 && in.ItemType != 9 {
  30. return m.SaveMessage(in)
  31. } else {
  32. return m.Chat(in)
  33. }
  34. }()
  35. error_code := util.SUCCESS_CODE
  36. if fool {
  37. error_code = util.SUCCESS_CODE
  38. } else {
  39. error_code = util.ERROR_CODE
  40. }
  41. return &messagecenter.SaveMessageResp{
  42. ErrorCode: error_code,
  43. ErrorMsg: error_message,
  44. Data: &messagecenter.MessageEntity{
  45. Content: content,
  46. MessageId: encrypt.SE.Encode2Hex(quitl.InterfaceToStr(messageId)),
  47. CreateTime: nowTime,
  48. },
  49. }, nil
  50. }