create_xunji_logic.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package xunji
  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 CreateXunjiLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewCreateXunjiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateXunjiLogic {
  16. return &CreateXunjiLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. func (l *CreateXunjiLogic) CreateXunji(req *types.XunjiInfo) (*types.BaseMsgResp, error) {
  23. organizationId := l.ctx.Value("organizationId").(uint64)
  24. _, err := l.svcCtx.DB.Xunji.Create().
  25. SetStatus(1).
  26. SetNotNilAppKey(req.AppKey).
  27. SetNotNilAppSecret(req.AppSecret).
  28. SetNotNilToken(req.Token).
  29. SetNotNilEncodingKey(req.EncodingKey).
  30. SetNotNilAgentID(req.AgentId).
  31. SetOrganizationID(organizationId).
  32. SetNotNilWxid(req.Wxid).
  33. SetNotNilAPIBase(req.ApiBase).
  34. SetNotNilAPIKey(req.ApiKey).
  35. Save(l.ctx)
  36. if err != nil {
  37. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  38. }
  39. return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
  40. }