From 52a36d7b1aeaabf5edc9f637654bdb59b112dc4c Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 10 Jul 2026 10:32:57 +0800 Subject: [PATCH] fix: add tenant_domain_list.dspy with LEFT JOIN orgname resolution --- json/tenant_domain.json | 1 + wwwroot/api/tenant_domain_list.dspy | 82 +++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 wwwroot/api/tenant_domain_list.dspy diff --git a/json/tenant_domain.json b/json/tenant_domain.json index 5d0b9cb..4b671cf 100644 --- a/json/tenant_domain.json +++ b/json/tenant_domain.json @@ -28,6 +28,7 @@ }, "editexclouded": ["id", "created_at", "updated_at"], "editable": { + "get_data_url": "{{entire_url('../api/tenant_domain_list.dspy')}}", "new_data_url": "{{entire_url('../api/tenant_domain_create.dspy')}}", "update_data_url": "{{entire_url('../api/tenant_domain_update.dspy')}}", "delete_data_url": "{{entire_url('../api/tenant_domain_delete.dspy')}}" diff --git a/wwwroot/api/tenant_domain_list.dspy b/wwwroot/api/tenant_domain_list.dspy new file mode 100644 index 0000000..d015dbd --- /dev/null +++ b/wwwroot/api/tenant_domain_list.dspy @@ -0,0 +1,82 @@ +ns = params_kw.copy() + +userorgid = await get_userorgid() +if not userorgid: + return { + "widgettype": "Error", + "options": { + "title": "Authorization Error", + "timeout": 3, + "cwidth": 16, + "cheight": 9, + "message": "Please login" + } + } +ns['resellerid'] = userorgid +ns['userorgid'] = userorgid + +debug(f'tenant_domain_list.dspy:{ns=}') + +if not ns.get('page'): + ns['page'] = 1 +if not ns.get('sort'): + ns['sort'] = ["created_at desc"] + +sql = '''select a.*, b.resellerid_text, c.orgid_text +from (select * from tenant_domain where 1=1 [[filterstr]]) a +left join (select id as resellerid, orgname as resellerid_text from organization where 1=1) b on a.resellerid = b.resellerid +left join (select id as orgid, orgname as orgid_text from organization where 1=1) c on a.orgid = c.orgid''' + +filterjson = params_kw.get('data_filter') +if filterjson and isinstance(filterjson, str): + try: + filterjson = json.loads(filterjson) + except (json.JSONDecodeError, TypeError): + filterjson = None + +if not filterjson: + fields_str = '''[ + {"name": "id", "title": "主键ID", "type": "str", "length": 32, "nullable": "no"}, + {"name": "domain", "title": "域名", "type": "str", "length": 200, "nullable": "no"}, + {"name": "resellerid", "title": "分销商机构ID", "type": "str", "length": 32, "nullable": "no"}, + {"name": "orgid", "title": "所属平台机构ID", "type": "str", "length": 32, "nullable": "no"}, + {"name": "status", "title": "状态", "type": "str", "length": 10, "nullable": "no", "default": "active"}, + {"name": "created_at", "title": "创建时间", "type": "timestamp", "nullable": "no"}, + {"name": "updated_at", "title": "更新时间", "type": "timestamp", "nullable": "no"} + ]''' + ori_fields = json.loads(fields_str) + fields = [f['name'] for f in ori_fields] + filterjson = default_filterjson(fields, ns) + +if filterjson: + if not isinstance(filterjson, dict) or 'AND' not in filterjson: + filterjson = {'AND': [filterjson] if filterjson else []} + filterjson['AND'].append({'field': 'orgid', 'op': '=', 'var': '__logined_orgid__'}) + ns['__logined_orgid__'] = userorgid + +filterdic = ns.copy() +filterdic['filterstr'] = '' +filterdic['userorgid'] = '${userorgid}$' +filterdic['userid'] = '${userid}$' +if filterjson: + dbf = DBFilter(filterjson) + conds = dbf.gen(ns) + if conds: + ns.update(dbf.consts) + conds = f' and {conds}' + filterdic['filterstr'] = conds + +ac = ArgsConvert('[[', ']]') +vars = ac.findAllVariables(sql) +NameSpace = {v: '${' + v + '}$' for v in vars if v != 'filterstr'} +filterdic.update(NameSpace) +sql = ac.convert(sql, filterdic) + +debug(f'{sql=}') +db = DBPools() +dbname = get_module_dbname('tenant') +async with db.sqlorContext(dbname) as sor: + r = await sor.sqlPaging(sql, ns) + return r + +return {"total": 0, "rows": []}