refactor(model): 优化模型网关的数据解析和任务处理逻辑

This commit is contained in:
2026-06-17 14:34:49 +08:00
parent 0d52b631b9
commit eb28c2d1e0
4 changed files with 58 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ package dao
import (
"context"
"fmt"
"prompts-core/consts/public"
"prompts-core/model/entity"
@@ -28,23 +29,57 @@ func (d *providerProtocolDao) Insert(ctx context.Context, req *entity.ProviderPr
return r.LastInsertId()
}
// Get 查询协议配置
func (d *providerProtocolDao) Get(ctx context.Context, req *entity.ProviderProtocol, fields ...string) (res *entity.ProviderProtocol, err error) {
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameProviderProtocol).
NoTenantId(ctx).
OmitEmpty().
Where(entity.ProviderProtocolCol.Id, req.Id).
Where(entity.ProviderProtocolCol.ProviderName, req.ProviderName). //主要是根据运营商查询
Where(entity.ProviderProtocolCol.Status, 1).
Fields(fields).One()
//// Get 查询协议配置
//func (d *providerProtocolDao) Get(ctx context.Context, req *entity.ProviderProtocol, fields ...string) (res *entity.ProviderProtocol, err error) {
// r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameProviderProtocol).
// NoTenantId(ctx).
// OmitEmpty().
// Where(entity.ProviderProtocolCol.Id, req.Id).
// Where(entity.ProviderProtocolCol.ProviderName, req.ProviderName). //主要是根据运营商查询
// Where(entity.ProviderProtocolCol.Status, 1).
// Fields(fields).One()
// if err != nil {
// return nil, err
// }
// if r.IsEmpty() {
// return nil, nil
// }
// err = r.Struct(&res)
// return
//}
// Get 获取协议配置
func (d *providerProtocolDao) Get(ctx context.Context, req *entity.ProviderProtocol, fields ...string) (*entity.ProviderProtocol, error) {
sql := fmt.Sprintf(`SELECT * FROM %s WHERE deleted_at IS NULL AND status = 1`, public.TableNameProviderProtocol)
args := make([]any, 0)
if req.Id != 0 {
sql += ` AND id = ?`
args = append(args, req.Id)
}
if req.ProviderName != "" {
sql += ` AND provider_name = ?`
args = append(args, req.ProviderName)
}
sql += ` LIMIT 1`
r, err := gfdb.DB(ctx, public.DbNameModelGateway).GetAll(ctx, sql, args...)
if err != nil {
return nil, err
}
if r.IsEmpty() {
return nil, nil
}
err = r.Struct(&res)
return
var list []*entity.ProviderProtocol
if err = r.Structs(&list); err != nil {
return nil, err
}
if len(list) == 0 {
return nil, nil
}
return list[0], nil
}
// List 列表查询