From 558fd49ec120ee4d9655c5030c01f639efce441c Mon Sep 17 00:00:00 2001 From: qhd <1766646056@qq.com> Date: Fri, 29 May 2026 18:06:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6=E4=B8=BA=E7=A9=BA=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/model_dao.go | 50 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/dao/model_dao.go b/dao/model_dao.go index b6644bd..50f379c 100644 --- a/dao/model_dao.go +++ b/dao/model_dao.go @@ -2,10 +2,12 @@ package dao import ( "context" + "fmt" "model-gateway/consts/public" "model-gateway/model/dto" "model-gateway/model/entity" "strconv" + "strings" "gitea.com/red-future/common/db/gfdb" "github.com/gogf/gf/v2/frame/g" @@ -58,17 +60,49 @@ func (d *modelDao) Delete(ctx context.Context, req *entity.AsynchModel) (rows in // Get 按ID获取(带租户隔离,只查当前租户) func (d *modelDao) Get(ctx context.Context, req *entity.AsynchModel, fields ...string) (m *entity.AsynchModel, err error) { - r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameModel). - OmitEmpty(). - Where(entity.AsynchModelCol.Id, req.Id). - Where(entity.AsynchModelCol.Creator, req.Creator). - Where(entity.AsynchModelCol.IsChatModel, req.IsChatModel). - Where(entity.AsynchModelCol.ModelName, req.ModelName). - Fields(fields).One() + //r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameModel). + // OmitEmpty(). + // Where(entity.AsynchModelCol.Id, req.Id). + // Where(entity.AsynchModelCol.Creator, req.Creator). + // Where(entity.AsynchModelCol.IsChatModel, req.IsChatModel). + // Where(entity.AsynchModelCol.ModelName, req.ModelName). + // Fields(fields).One() + //if err != nil { + // return + //} + //err = r.Struct(&m) + + var whereCondition strings.Builder + var queryParams []interface{} + if !g.IsEmpty(req.Id) { + whereCondition.WriteString(fmt.Sprintf(" AND %s = (?) ", entity.AsynchModelCol.Id)) + queryParams = append(queryParams, req.Id) + } + if !g.IsEmpty(req.Creator) { + whereCondition.WriteString(fmt.Sprintf(" AND %s = (?) ", entity.AsynchModelCol.Creator)) + queryParams = append(queryParams, req.Creator) + } + if !g.IsEmpty(req.IsChatModel) { + whereCondition.WriteString(fmt.Sprintf(" AND %s = (?) ", entity.AsynchModelCol.IsChatModel)) + queryParams = append(queryParams, req.IsChatModel) + } + if !g.IsEmpty(req.ModelName) { + whereCondition.WriteString(fmt.Sprintf(" AND %s = (?) ", entity.AsynchModelCol.ModelName)) + queryParams = append(queryParams, req.ModelName) + } + // 完整 SQL + sql := `SELECT * FROM "asynch_models" WHERE "deleted_at" IS NULL` + whereCondition.String() + r, err := gfdb.DB(ctx, public.DbNameModelGateway).GetAll(ctx, sql, queryParams...) if err != nil { return } - err = r.Struct(&m) + var i []*entity.AsynchModel + if err = r.Structs(&i); err != nil { + return nil, err + } + for _, item := range i { + m = item + } return }