package agent import ( "context" "errors" "wechat-api/ent/agent" "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 UpdateAgentLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewUpdateAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAgentLogic { return &UpdateAgentLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *UpdateAgentLogic) UpdateAgent(req *types.AgentInfo) (*types.BaseMsgResp, error) { organizationId := l.ctx.Value("organizationId").(uint64) if *req.Id <= 0 { l.Error("记录ID不存在") return nil, errors.New("记录ID不存在") } item, err := l.svcCtx.DB.Agent.Query().Where(agent.ID(*req.Id), agent.OrganizationID(organizationId)).First(l.ctx) if item.ID == 0 { return nil, errors.New("记录不存在") } err = l.svcCtx.DB.Agent.UpdateOneID(*req.Id). SetNotNilName(req.Name). SetNotNilRole(req.Role). SetNotNilStatus(req.Status). SetNotNilBackground(req.Background). SetNotNilExamples(req.Examples). Exec(l.ctx) if err != nil { return nil, dberrorhandler.DefaultEntError(l.Logger, err, req) } return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil }