From cfa9b321c4b6b4bdbde17e2fe82b72c539831788 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 13 Jul 2026 15:36:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AF=BC=E5=85=A5=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E5=86=97=E4=BD=99org=5Fid=E8=BF=87=E6=BB=A4=20+=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0providerid=E5=9B=9E=E5=A1=ABdspy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - import_category_products: 移除org_id条件(树控件已做过滤) - backfill_providerid: 从llm.providerid回填product.providerid --- wwwroot/api/backfill_providerid.dspy | 53 +++++++++++++++++++++++ wwwroot/api/import_category_products.dspy | 4 +- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 wwwroot/api/backfill_providerid.dspy diff --git a/wwwroot/api/backfill_providerid.dspy b/wwwroot/api/backfill_providerid.dspy new file mode 100644 index 0000000..bd88346 --- /dev/null +++ b/wwwroot/api/backfill_providerid.dspy @@ -0,0 +1,53 @@ +providerid = params_kw.get('providerid', '') +org_id = params_kw.get('org_id', '') + +# Build filter conditions +conditions = ["providerid IS NULL OR providerid = ''"] +params = {} +if providerid: + conditions.append("providerid = ${pid}$") + params['pid'] = providerid +if org_id: + conditions.append("org_id = ${oid}$") + params['oid'] = org_id + +where_clause = " AND ".join(conditions) + +# 1. Count products to update +async with DBPools().sqlorContext('sage') as sor: + count_rows = await sor.sqlExe( + f"SELECT COUNT(*) as cnt FROM product WHERE {where_clause}", + params + ) + total = count_rows[0].cnt if count_rows else 0 + +if total == 0: + return json.dumps({"status": "ok", "message": "没有需要回填的产品"}) + +# 2. Update providerid from llm table (product.resource_ref_id = llm.id) +async with DBPools().sqlorContext('llmage') as sor: + llms = await sor.sqlExe( + "SELECT id, providerid FROM llm WHERE status = 'published'", {} + ) + llm_pid = {r.id: r.providerid for r in llms if r.providerid} + +# 3. Get products and update +updated = 0 +async with DBPools().sqlorContext('sage') as sor: + rows = await sor.sqlExe( + f"SELECT id, resource_ref_id, product_name FROM product WHERE {where_clause}", + params + ) + for p in rows: + pid = llm_pid.get(p.resource_ref_id, '') + if pid: + await sor.sqlExe( + "UPDATE product SET providerid = ${pid}$ WHERE id = ${id}$", + {'pid': pid, 'id': p.id} + ) + updated += 1 + +return json.dumps({ + "status": "ok", + "message": f"回填完成: 共{total}条空providerid, 成功回填{updated}条" +}, ensure_ascii=False) diff --git a/wwwroot/api/import_category_products.dspy b/wwwroot/api/import_category_products.dspy index 8de959e..efe388c 100644 --- a/wwwroot/api/import_category_products.dspy +++ b/wwwroot/api/import_category_products.dspy @@ -12,8 +12,8 @@ try: # Get the selected category's resource_module async with DBPools().sqlorContext(dbname) as sor: rows = await sor.sqlExe( - "SELECT id, name, resource_module, org_id FROM product_category WHERE id = ${id}$ AND org_id = ${org_id}$", - {'id': category_id, 'org_id': org_id} + "SELECT id, name, resource_module FROM product_category WHERE id = ${id}$", + {'id': category_id} ) if not rows: raise ValueError('类别不存在或无权操作')