2026-05-12 13:59:15 +08:00
|
|
|
|
package dao
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
"prompts-core/consts/public"
|
|
|
|
|
|
"prompts-core/model/entity"
|
|
|
|
|
|
|
|
|
|
|
|
"gitea.com/red-future/common/db/gfdb"
|
2026-05-15 09:45:51 +08:00
|
|
|
|
"gitea.com/red-future/common/utils"
|
2026-05-12 13:59:15 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var Model = &modelDao{}
|
|
|
|
|
|
|
|
|
|
|
|
type modelDao struct{}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *modelDao) GetByModelName(ctx context.Context, modelName string) (m *entity.AsynchModel, err error) {
|
|
|
|
|
|
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
|
|
|
|
|
|
Where(entity.AsynchModelCol.ModelName, modelName).
|
|
|
|
|
|
One()
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if r.IsEmpty() {
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
err = r.Struct(&m)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *modelDao) GetByIsChatModel(ctx context.Context) (m *entity.AsynchModel, err error) {
|
2026-05-15 09:45:51 +08:00
|
|
|
|
userInfo, err := utils.GetUserInfo(ctx)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
2026-05-12 13:59:15 +08:00
|
|
|
|
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
|
|
|
|
|
|
Where(entity.AsynchModelCol.IsChatModel, 1).
|
2026-05-15 09:45:51 +08:00
|
|
|
|
Where(entity.AsynchModelCol.Creator, userInfo.UserName).
|
2026-05-12 13:59:15 +08:00
|
|
|
|
One()
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if r.IsEmpty() {
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
err = r.Struct(&m)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetBySuperAdmin 查询超级管理员(tenant_id=1)的模型
|
|
|
|
|
|
func (d *modelDao) GetBySuperAdmin(ctx context.Context, modelName string) (m *entity.AsynchModel, err error) {
|
|
|
|
|
|
sql := fmt.Sprintf("SELECT * FROM %s WHERE model_name = ? AND tenant_id = 1 AND deleted_at IS NULL LIMIT 1", public.TableNameModel)
|
|
|
|
|
|
r, err := gfdb.DB(ctx).GetAll(ctx, sql, modelName)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if len(r) == 0 {
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = r[0].Struct(&m)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|