fix: add tenant_domain_list.dspy with LEFT JOIN orgname resolution

This commit is contained in:
yumoqing 2026-07-10 10:32:57 +08:00
parent 770d6b9b55
commit 52a36d7b1a
2 changed files with 83 additions and 0 deletions

View File

@ -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')}}"

View File

@ -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": []}