update: 更新模型列表查询接口以支持私有化过滤 #2

Merged
WangLiZhao merged 1 commits from dev into master 2026-05-12 06:53:08 +00:00
4 changed files with 16 additions and 8 deletions
Showing only changes of commit adf1d0ae6e - Show all commits

View File

@@ -52,7 +52,7 @@ func (c *model) ListModel(ctx context.Context, req *dto.ListModelReq) (res *dto.
pageSize = req.PageSize pageSize = req.PageSize
} }
} }
list, total, err := service.Model.List(ctx, pageNum, pageSize, req.ModelName, req.ModelType) list, total, err := service.Model.List(ctx, pageNum, pageSize, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -90,7 +90,7 @@ func (d *modelDao) Get(ctx context.Context, id int64) (m *entity.AsynchModel, er
return return
} }
func (d *modelDao) List(ctx context.Context, pageNum, pageSize int, modelNameLike string, modelType int) (list []*entity.AsynchModel, total int64, err error) { func (d *modelDao) List(ctx context.Context, pageNum, pageSize int, modelNameLike string, modelType int, isPrivate int) (list []*entity.AsynchModel, total int64, err error) {
model := gfdb.DB(ctx).Model(ctx, public.TableNameModel). model := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
OrderDesc(entity.AsynchModelCol.CreatedAt) OrderDesc(entity.AsynchModelCol.CreatedAt)
if modelNameLike != "" { if modelNameLike != "" {
@@ -99,6 +99,9 @@ func (d *modelDao) List(ctx context.Context, pageNum, pageSize int, modelNameLik
if modelType != 0 { if modelType != 0 {
model = model.Where(entity.AsynchModelCol.ModelsType, modelType) model = model.Where(entity.AsynchModelCol.ModelsType, modelType)
} }
if isPrivate != 0 {
model = model.Where(entity.AsynchModelCol.IsPrivate, isPrivate)
}
if pageNum > 0 && pageSize > 0 { if pageNum > 0 && pageSize > 0 {
model = model.Page(pageNum, pageSize) model = model.Page(pageNum, pageSize)
} }
@@ -148,7 +151,7 @@ func (d *modelDao) ListByCreatorAndPlatform(ctx context.Context, creator string,
return return
} }
func (d *modelDao) GetByCreatorAndPlatform(ctx context.Context, creator string, modelNameLike string, modelType int) (list []*entity.AsynchModel, err error) { func (d *modelDao) GetByCreatorAndPlatform(ctx context.Context, creator string, modelNameLike string, modelType int, isPrivate int) (list []*entity.AsynchModel, err error) {
whereSQL := "deleted_at IS NULL AND (tenant_id = 1 OR creator = ?)" whereSQL := "deleted_at IS NULL AND (tenant_id = 1 OR creator = ?)"
args := []any{creator} args := []any{creator}
@@ -160,6 +163,10 @@ func (d *modelDao) GetByCreatorAndPlatform(ctx context.Context, creator string,
whereSQL += " AND models_type = ?" whereSQL += " AND models_type = ?"
args = append(args, modelType) args = append(args, modelType)
} }
if isPrivate != 0 {
whereSQL += " AND is_private = ?"
args = append(args, isPrivate)
}
querySQL := fmt.Sprintf("SELECT * FROM %s WHERE %s ORDER BY created_at DESC", public.TableNameModel, whereSQL) querySQL := fmt.Sprintf("SELECT * FROM %s WHERE %s ORDER BY created_at DESC", public.TableNameModel, whereSQL)

View File

@@ -82,6 +82,7 @@ type ListModelReq struct {
PageSize int `p:"pageSize" json:"pageSize" dc:"每页条数默认10"` PageSize int `p:"pageSize" json:"pageSize" dc:"每页条数默认10"`
ModelName string `p:"modelName" json:"modelName" dc:"模型名称(模糊查询,可选)"` ModelName string `p:"modelName" json:"modelName" dc:"模型名称(模糊查询,可选)"`
ModelType int `p:"modelType" json:"modelType" dc:"模型类型"` ModelType int `p:"modelType" json:"modelType" dc:"模型类型"`
IsPrivate int `p:"isPrivate" json:"isPrivate" dc:"是否私有化 0-私有 1-公共"`
} }
type ListModelRes struct { type ListModelRes struct {

View File

@@ -89,7 +89,7 @@ func (s *modelService) Get(ctx context.Context, id int64) (*entity.AsynchModel,
return model, nil return model, nil
} }
func (s *modelService) List(ctx context.Context, pageNum, pageSize int, modelNameLike string, modelType int) (list []*entity.AsynchModel, total int64, err error) { func (s *modelService) List(ctx context.Context, pageNum, pageSize int, req *dto.ListModelReq) (list []*entity.AsynchModel, total int64, err error) {
isSuperAdmin, err := IsSuperAdmin(ctx) isSuperAdmin, err := IsSuperAdmin(ctx)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
@@ -103,9 +103,9 @@ func (s *modelService) List(ctx context.Context, pageNum, pageSize int, modelNam
var count int64 var count int64
if isSuperAdmin { if isSuperAdmin {
models, count, err = dao.Model.List(ctx, pageNum, pageSize, modelNameLike, modelType) models, count, err = dao.Model.List(ctx, pageNum, pageSize, req.ModelName, req.ModelType, req.IsPrivate)
} else { } else {
models, count, err = s.getModelsWithDedup(ctx, user.UserName, pageNum, pageSize, modelNameLike, modelType) models, count, err = s.getModelsWithDedup(ctx, user.UserName, pageNum, pageSize, req.ModelName, req.ModelType, req.IsPrivate)
} }
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
@@ -122,9 +122,9 @@ func (s *modelService) List(ctx context.Context, pageNum, pageSize int, modelNam
} }
// getModelsWithDedup 获取普通用户的模型列表并去重 // getModelsWithDedup 获取普通用户的模型列表并去重
func (s *modelService) getModelsWithDedup(ctx context.Context, creator string, pageNum, pageSize int, modelNameLike string, modelType int) (list []*entity.AsynchModel, total int64, err error) { func (s *modelService) getModelsWithDedup(ctx context.Context, creator string, pageNum, pageSize int, modelNameLike string, modelType int, isPrivate int) (list []*entity.AsynchModel, total int64, err error) {
// 1. 查全量数据(不分页,便于去重) // 1. 查全量数据(不分页,便于去重)
allModels, err := dao.Model.GetByCreatorAndPlatform(ctx, creator, modelNameLike, modelType) allModels, err := dao.Model.GetByCreatorAndPlatform(ctx, creator, modelNameLike, modelType, isPrivate)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }