Files
hm-server/app/main/api/internal/logic/admin_feature/adminupdatefeaturelogic.go

60 lines
1.6 KiB
Go
Raw Normal View History

2025-09-21 18:27:25 +08:00
package admin_feature
import (
"context"
2025-09-30 17:44:18 +08:00
"tydata-server/app/main/api/internal/svc"
"tydata-server/app/main/api/internal/types"
"tydata-server/common/xerr"
2025-09-21 18:27:25 +08:00
2025-09-30 17:44:18 +08:00
"github.com/pkg/errors"
2025-09-21 18:27:25 +08:00
"github.com/zeromicro/go-zero/core/logx"
)
type AdminUpdateFeatureLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAdminUpdateFeatureLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminUpdateFeatureLogic {
return &AdminUpdateFeatureLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AdminUpdateFeatureLogic) AdminUpdateFeature(req *types.AdminUpdateFeatureReq) (resp *types.AdminUpdateFeatureResp, err error) {
2025-09-30 17:44:18 +08:00
// 1. 参数验证
if req.Id <= 0 {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.PARAM_VERIFICATION_ERROR),
"功能ID必须大于0, id: %d", req.Id)
}
// 2. 查询记录是否存在
record, err := l.svcCtx.FeatureModel.FindOne(l.ctx, req.Id)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR),
"查找功能失败, err: %v, id: %d", err, req.Id)
}
// 3. 直接更新record的字段只更新非空字段
if req.ApiId != nil && *req.ApiId != "" {
record.ApiId = *req.ApiId
}
if req.Name != nil && *req.Name != "" {
record.Name = *req.Name
}
// 4. 执行更新操作
err = l.svcCtx.FeatureModel.UpdateWithVersion(l.ctx, nil, record)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR),
"更新功能失败, err: %v, id: %d", err, req.Id)
}
2025-09-21 18:27:25 +08:00
2025-09-30 17:44:18 +08:00
// 5. 返回成功结果
return &types.AdminUpdateFeatureResp{Success: true}, nil
2025-09-21 18:27:25 +08:00
}