create_agent_logic.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package agent
  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 CreateAgentLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewCreateAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAgentLogic {
  16. return &CreateAgentLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. func (l *CreateAgentLogic) CreateAgent(req *types.AgentInfo) (*types.BaseMsgResp, error) {
  23. organizationId := l.ctx.Value("organizationId").(uint64)
  24. _, err := l.svcCtx.DB.Agent.Create().
  25. SetNotNilName(req.Name).
  26. SetNotNilRole(req.Role).
  27. //SetNotNilStatus(req.Status).
  28. SetOrganizationID(organizationId).
  29. SetNotNilBackground(req.Background).
  30. SetNotNilExamples(req.Examples).
  31. Save(l.ctx)
  32. if err != nil {
  33. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  34. }
  35. return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
  36. }