kboss/b/cpcc/cpclist/get_cpclist.dspy
2025-07-16 14:27:17 +08:00

117 lines
3.1 KiB
Plaintext

async def get_cpclist(params_kw={}):
orgid = await get_userorgid()
if not orgid:
orgid = params_kw.get("orgid",'000')
debug(f' >>> 当前用户组织ID: {orgid}')
ns['orgid'] = orgid
# 用户ID没用
#ns['userid'] = userid
#debug(f'get_cpclist.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = 'id'
#sql = '''select a.*, b.orgid_text from (select * from cpclist where 1=1 [[filterstr]]) a left join (select id as orgid, orgname as orgid_text from organization where 1 = 1) b on a.orgid = b.orgid'''
sql = f'''select * from cpclist where orgid="{orgid}"'''
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": "orgid",
"title": "属主机构id",
"type": "str",
"length": 32
},
{
"name": "pcapi_url",
"title": "pcapi网址",
"type": "str",
"length": 500
},
{
"name": "api_user",
"title": "接口用户",
"type": "str",
"length": 100
},
{
"name": "api_pwd",
"title": "接口密码",
"type": "str",
"length": 100
},
{
"name": "enable_date",
"title": "启用日期",
"type": "date",
"length": 255
},
{
"name": "expire_date",
"title": "停用日期",
"type": "date",
"length": 255
},
{
"name": "contactname",
"title": "联系人",
"type": "str",
"length": 100
},
{
"name": "contactphone",
"title": "联系电话",
"type": "str",
"length": 100
}
] ]
filterjson = default_filterjson(fields, ns)
filterdic = ns.copy()
filterdic['filterstr'] = ''
filterdic['orgid'] = '${orgid}$'
#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 = 'kboss'
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return {
'status': True,
'msg': '算力中心数据查询成功',
'data': r
}
return {
'status': False,
'msg': '算力中心数据查询失败'
}
ret = await get_cpclist(params_kw)
return ret