cpcc/wwwroot/cpccluster/get_cpccluster.dspy
2025-07-16 14:32:09 +08:00

91 lines
2.2 KiB
Plaintext

ns = params_kw.copy()
debug(f'get_cpccluster.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = 'id'
sql = '''select a.*, b.clustertype_text, c.controllerid_text
from (select * from cpccluster where 1=1 [[filterstr]]) a left join (select k as clustertype,
v as clustertype_text from appcodes_kv where parentid='clustertype') b on a.clustertype = b.clustertype left join (select id as controllerid,
ip as controllerid_text from cpcnode where 1 = 1) c on a.controllerid = c.controllerid'''
filterjson = params_kw.get('data_filter')
if not filterjson:
fields = [ f['name'] for f in [
{
"name": "id",
"title": "id",
"type": "str",
"length": 32
},
{
"name": "name",
"title": "名称",
"type": "str",
"length": 255
},
{
"name": "cpcid",
"title": "算力中心id",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "clustertype",
"title": "集群类型",
"type": "str",
"length": 1
},
{
"name": "controllerid",
"title": "控制节点id",
"type": "str",
"length": 32
},
{
"name": "enable_date",
"title": "启用日期",
"type": "date",
"length": 255
},
{
"name": "export_date",
"title": "停用日期",
"type": "date",
"length": 255
}
] ]
filterjson = default_filterjson(fields, ns)
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 = await rfexe('get_module_dbname', 'cpcc')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}