From f13651e83033e3345c62ce649b4ce3967f05941a Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Mon, 22 Jun 2026 13:59:18 +0800 Subject: [PATCH] fix: product_category tree root node query + parent_id normalization - get_product_category: accept NULL/empty/'0' as root (parent_id IS NULL OR '' OR '0') - new_product_category: normalize empty/0 parent_id to NULL --- .../get_product_category.dspy | 8 ++++---- .../new_product_category.dspy | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/wwwroot/product_category_tree/get_product_category.dspy b/wwwroot/product_category_tree/get_product_category.dspy index 235b1d6..09186da 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: +if id and id != '0' and id != 'null' and id != 'undefined': sql += " and parent_id = ${id}$" else: - sql += " and parent_id is null" + sql += " and (parent_id is null or parent_id = '' or parent_id = '0')" -sql += " order by name " +sql += " order by sort_order, 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 [] \ No newline at end of file +return [] diff --git a/wwwroot/product_category_tree/new_product_category.dspy b/wwwroot/product_category_tree/new_product_category.dspy index 1b67e6e..f891e68 100644 --- a/wwwroot/product_category_tree/new_product_category.dspy +++ b/wwwroot/product_category_tree/new_product_category.dspy @@ -1,15 +1,19 @@ ns = params_kw.copy() for k,v in ns.items(): - if v == 'NaN' or v == 'null': + if v == 'NaN' or v == 'null' or v == 'undefined' or v == '': ns[k] = None -id = params_kw.id -if not id or len(id) > 32: + +# 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 = uuid() ns['id'] = id - - userorgid = await get_userorgid() if not userorgid: return { @@ -54,4 +58,4 @@ return { "timeout":3, "message":"failed" } -} \ No newline at end of file +}