66 lines
2.3 KiB
Plaintext
66 lines
2.3 KiB
Plaintext
async def get_children(parent_id, data):
|
|
children = []
|
|
for item in data:
|
|
if item['parentid'] == parent_id:
|
|
child = {'id': item['id'], 'codeid': item['codeid'], 'parentid': item['parentid'], 'k': item['k'], 'v': item['v']}
|
|
grandchildren = await get_children(item['id'], data)
|
|
if grandchildren:
|
|
child['son'] = grandchildren
|
|
children.append(child)
|
|
return children
|
|
|
|
async def transform_data(data):
|
|
result = []
|
|
for item in data:
|
|
if item['parentid'] is None or item['parentid'] == '':
|
|
parent = {'id': item['id'], 'codeid': item['codeid'], 'parentid': item['parentid'], 'k': item['k'], 'v': item['v']}
|
|
children = await get_children(item['id'], data)
|
|
if children:
|
|
parent['son'] = children
|
|
result.append(parent)
|
|
return result
|
|
|
|
async def appCodesSearch(ns={}):
|
|
"""
|
|
search new appcodes
|
|
`id` VARCHAR(32) 'id',
|
|
`name` VARCHAR(255) '编码名称',
|
|
`hierarchy_flg` VARCHAR(1) '多级标志',
|
|
`del_flg` VARCHAR(1) DEFAULT '0' comment '删除标志',
|
|
`create_at` TIMESTAMP comment '创建时间戳'
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
ns['del_flg'] = '0'
|
|
ns['sort'] = 'create_at'
|
|
ns['order'] = 'desc'
|
|
ns['page'] = ns.get('page') if ns.get('page') else 1
|
|
if ns.get('kv'):
|
|
if not ns.get('codeid'):
|
|
return {
|
|
"status": False,
|
|
"msg": "appCodes_kv search failed, the codeid is empty",
|
|
"data": ""
|
|
}
|
|
app_code_result = await sor.R('appcodes_kv', ns)
|
|
app_code_result = await transform_data(app_code_result.get('rows'))
|
|
else:
|
|
app_code_result = await sor.R('appcodes',ns)
|
|
return {
|
|
"status": True,
|
|
"msg": "appCodes search success",
|
|
"data": app_code_result
|
|
}
|
|
except Exception as e:
|
|
return {
|
|
"status": False,
|
|
"msg": "appCodes search failed",
|
|
"data": ""
|
|
}
|
|
|
|
|
|
ret = await appCodesSearch(params_kw)
|
|
return ret |