create_msg_logic.go 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package Msg
  2. import (
  3. "context"
  4. "wechat-api/internal/svc"
  5. "wechat-api/internal/types"
  6. "wechat-api/internal/utils/dberrorhandler"
  7. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type CreateMsgLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewCreateMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateMsgLogic {
  16. return &CreateMsgLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. func (l *CreateMsgLogic) CreateMsg(req *types.MsgInfo) (*types.BaseMsgResp, error) {
  23. _, err := l.svcCtx.DB.Msg.Create().
  24. SetNotNilStatus(req.Status).
  25. SetNotNilFromwxid(req.Fromwxid).
  26. SetNotNilToid(req.Toid).
  27. SetNotNilMsgtype(req.Msgtype).
  28. SetNotNilMsg(req.Msg).
  29. SetNotNilBatchNo(req.BatchNo).
  30. Save(l.ctx)
  31. if err != nil {
  32. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  33. }
  34. return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
  35. }