package agent import ( "context" "wechat-api/internal/svc" "wechat-api/internal/types" "wechat-api/internal/utils/dberrorhandler" "github.com/suyuan32/simple-admin-common/msg/errormsg" "github.com/zeromicro/go-zero/core/logx" ) type CreateAgentLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewCreateAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAgentLogic { return &CreateAgentLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *CreateAgentLogic) CreateAgent(req *types.AgentInfo) (*types.BaseMsgResp, error) { organizationId := l.ctx.Value("organizationId").(uint64) _, err := l.svcCtx.DB.Agent.Create(). SetNotNilName(req.Name). SetNotNilRole(req.Role). //SetNotNilStatus(req.Status). SetOrganizationID(organizationId). SetNotNilBackground(req.Background). SetNotNilExamples(req.Examples). Save(l.ctx) if err != nil { return nil, dberrorhandler.DefaultEntError(l.Logger, err, req) } return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil }