From f05eea19e55c57b7e6b17b1d7285c00bb019de20 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Mon, 22 Jun 2026 14:03:41 +0800 Subject: [PATCH] fix: remove parent_id default '0' from product_category model - Root nodes should have parent_id=NULL, not '0' - Tree query already checks 'parent_id IS NULL' - Revert direct edits to generated dspy files --- models/product_category.json | 3 +-- .../get_product_category.dspy | 8 ++++---- .../new_product_category.dspy | 16 ++++++---------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/models/product_category.json b/models/product_category.json index c86dd84..da3115e 100644 --- a/models/product_category.json +++ b/models/product_category.json @@ -21,8 +21,7 @@ "name": "parent_id", "title": "父类别ID", "type": "str", - "length": 32, - "default": "0" + "length": 32 }, { "name": "name", diff --git a/wwwroot/product_category_tree/get_product_category.dspy b/wwwroot/product_category_tree/get_product_category.dspy index 09186da..235b1d6 100644 --- a/wwwroot/product_category_tree/get_product_category.dspy +++ b/wwwroot/product_category_tree/get_product_category.dspy @@ -2,15 +2,15 @@ ns = params_kw.copy() sql = '''select * from product_category where 1 = 1''' id = ns.get('id') -if id and id != '0' and id != 'null' and id != 'undefined': +if id: sql += " and parent_id = ${id}$" else: - sql += " and (parent_id is null or parent_id = '' or parent_id = '0')" + sql += " and parent_id is null" -sql += " order by sort_order, name " +sql += " order by name " db = DBPools() dbname = get_module_dbname('product_management') async with db.sqlorContext(dbname) as sor: r = await sor.sqlExe(sql, ns) return r -return [] +return [] \ No newline at end of file diff --git a/wwwroot/product_category_tree/new_product_category.dspy b/wwwroot/product_category_tree/new_product_category.dspy index f891e68..1b67e6e 100644 --- a/wwwroot/product_category_tree/new_product_category.dspy +++ b/wwwroot/product_category_tree/new_product_category.dspy @@ -1,19 +1,15 @@ ns = params_kw.copy() for k,v in ns.items(): - if v == 'NaN' or v == 'null' or v == 'undefined' or v == '': + if v == 'NaN' or v == 'null': ns[k] = None - -# Normalize parent_id: empty/0/None all mean root node (NULL) -pid = ns.get('parent_id') -if not pid or pid == '0': - ns['parent_id'] = None - -id = params_kw.get('id') -if not id or len(str(id)) > 32: +id = params_kw.id +if not id or len(id) > 32: id = uuid() ns['id'] = id + + userorgid = await get_userorgid() if not userorgid: return { @@ -58,4 +54,4 @@ return { "timeout":3, "message":"failed" } -} +} \ No newline at end of file