135 lines
3.1 KiB
Plaintext
135 lines
3.1 KiB
Plaintext
|
|
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['ownerid'] = userorgid
|
|
ns['userorgid'] = userorgid
|
|
|
|
debug_params('get_llm', ns)
|
|
if not ns.get('page'):
|
|
ns['page'] = 1
|
|
if not ns.get('sort'):
|
|
|
|
|
|
ns['sort'] = 'name'
|
|
|
|
|
|
|
|
sql = '''select a.*, b.providerid_text, c.iconid_text, d.upappid_text, e.ownerid_text
|
|
from (select * from llm where 1=1 [[filterstr]]) a left join (select id as providerid,
|
|
orgname as providerid_text from organization where 1 = 1) b on a.providerid = b.providerid left join (select id as iconid,
|
|
id as iconid_text from svgicon where 1 = 1) c on a.iconid = c.iconid left join (select id as upappid,
|
|
name as upappid_text from upapp where 1 = 1) d on a.upappid = d.upappid left join (select id as ownerid,
|
|
orgname as ownerid_text from organization where 1 = 1) e on a.ownerid = e.ownerid'''
|
|
|
|
filterjson = params_kw.get('data_filter')
|
|
fields_str=r'''[
|
|
{
|
|
"name": "id",
|
|
"title": "id",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "name",
|
|
"title": "名称",
|
|
"type": "str",
|
|
"length": 100
|
|
},
|
|
{
|
|
"name": "model",
|
|
"title": "识别名",
|
|
"type": "str",
|
|
"length": 100
|
|
},
|
|
{
|
|
"name": "description",
|
|
"title": "说明",
|
|
"type": "text",
|
|
"length": 500
|
|
},
|
|
{
|
|
"name": "iconid",
|
|
"title": "图标id",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "upappid",
|
|
"title": "上位系统id",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "providerid",
|
|
"title": "供应商id",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "ownerid",
|
|
"title": "所属机构id",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "enabled_date",
|
|
"title": "启用日期",
|
|
"type": "date"
|
|
},
|
|
{
|
|
"name": "expired_date",
|
|
"title": "失效日期",
|
|
"type": "date"
|
|
},
|
|
{
|
|
"name": "min_balance",
|
|
"title": "最低余额",
|
|
"type": "float",
|
|
"length": 20,
|
|
"default": 10
|
|
}
|
|
]'''
|
|
ori_fields = json.loads(fields_str)
|
|
if not filterjson:
|
|
fields = [ f['name'] for f in ori_fields ]
|
|
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({len(sql)}ch): {sql[:200]}')
|
|
db = DBPools()
|
|
dbname = get_module_dbname('llm')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
r = await sor.sqlPaging(sql, ns)
|
|
return r
|
|
return {
|
|
"total":0,
|
|
"rows":[]
|
|
} |