117 lines
5.4 KiB
Plaintext
117 lines
5.4 KiB
Plaintext
async def get_user_role(ns={}):
|
|
sor = ns['sor']
|
|
# get role
|
|
ns['del_flg'] = '0'
|
|
res_role = await sor.R('userrole', ns)
|
|
if res_role:
|
|
user_role = res_role[0]
|
|
else:
|
|
return {
|
|
"status": False,
|
|
"msg": "userrole table, user id can not find..."
|
|
}
|
|
roleid = user_role.get('roleid')
|
|
# get role name
|
|
role_name = await sor.R('role', {'id': roleid})
|
|
if role_name:
|
|
role = role_name[0].get('role')
|
|
else:
|
|
return {
|
|
"status": False,
|
|
"msg": "role table, can not get role name"
|
|
}
|
|
|
|
return role
|
|
|
|
async def enterprise_audit_info_search(ns={}):
|
|
if not ns.get('url_link'):
|
|
return {
|
|
'status': False,
|
|
'msg': '请传递url_link'
|
|
}
|
|
|
|
# 分页
|
|
current_page = int(ns['current_page']) if ns.get('current_page') else 1
|
|
page_size = int(ns['page_size']) if ns.get('page_size') else 10
|
|
offset = (current_page - 1) * page_size
|
|
|
|
audit_status = ns.get('audit_status')
|
|
|
|
domain_name = ns.get('url_link').split("//")[1].split("/")[0]
|
|
if 'localhost' in domain_name:
|
|
domain_name = 'dev.opencomputing.cn'
|
|
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
# 检查orgid是否存在
|
|
if ns.get('userid'):
|
|
userid = ns.get('userid')
|
|
else:
|
|
userid = await get_user()
|
|
user_list = await sor.R('users', {'id': userid})
|
|
if not user_list:
|
|
return {
|
|
'status': False,
|
|
'msg': 'user not found'
|
|
}
|
|
orgid = user_list[0]['orgid']
|
|
user_role = await get_user_role({'userid': userid, 'sor': sor})
|
|
try:
|
|
if user_role == '客户' or user_role == '管理员': # 客户查询
|
|
count_sql = """SELECT COUNT(*) AS total_count FROM enterprise_audit_info WHERE orgid = '%s' AND del_flg = '0';""" % orgid
|
|
find_sql = """SELECT * FROM enterprise_audit_info WHERE orgid = '%s' AND del_flg = '0';""" % orgid
|
|
else: # 运营查询 enterprise_audit_info和organization表关联查询 enterprise_audit_info中的orgid和organization表中的id关联查询
|
|
count_sql = """SELECT COUNT(*) AS total_count FROM enterprise_audit_info AS eai LEFT JOIN organization as org ON eai.orgid = org.id WHERE org.parentid = '%s' AND eai.del_flg = '0';""" % orgid
|
|
find_sql = """SELECT eai.* FROM enterprise_audit_info AS eai LEFT JOIN organization as org ON eai.orgid = org.id WHERE org.parentid = '%s' AND eai.del_flg = '0' ORDER BY eai.update_time DESC LIMIT %s OFFSET %s;""" % (orgid, page_size, offset)
|
|
# 拆分find_sql 增加audit_status条件筛选
|
|
if audit_status:
|
|
# Split the audit_status string into individual statuses
|
|
statuses = [status.strip() for status in audit_status.split(',') if status.strip()]
|
|
if statuses:
|
|
# Create a properly escaped list of statuses for SQL
|
|
escaped_statuses = []
|
|
for status in statuses:
|
|
# Escape single quotes by doubling them (SQL standard)
|
|
escaped_status = status.replace("'", "''")
|
|
escaped_statuses.append(f"'{escaped_status}'")
|
|
|
|
# Join the escaped statuses for the IN clause
|
|
statuses_str = ','.join(escaped_statuses)
|
|
|
|
if statuses_str:
|
|
count_sql = count_sql.split("WHERE")[0] + f"WHERE eai.audit_status IN ({statuses_str}) AND " + count_sql.split("WHERE")[1]
|
|
find_sql = find_sql.split("WHERE")[0] + f"WHERE eai.audit_status IN ({statuses_str}) AND " + find_sql.split("WHERE")[1]
|
|
# 非pending
|
|
else:
|
|
count_sql = count_sql.split("WHERE")[0] + "WHERE eai.audit_status != 'pending' AND " + count_sql.split("WHERE")[1]
|
|
find_sql = find_sql.split("WHERE")[0] + "WHERE eai.audit_status != 'pending' AND " + find_sql.split("WHERE")[1]
|
|
|
|
# 执行查询
|
|
total_count = (await sor.sqlExe(count_sql, {}))[0]['total_count']
|
|
res = await sor.sqlExe(find_sql, {})
|
|
|
|
# 处理结果中的图片路径 增加前缀
|
|
for item in res:
|
|
if item.get('license_original_img'):
|
|
item['license_original_img'] = 'https://' + domain_name + '/idfile?path=' + item['license_original_img']
|
|
if item.get('license_copy_img'):
|
|
item['license_copy_img'] = 'https://' + domain_name + '/idfile?path=' + item['license_copy_img']
|
|
|
|
return {
|
|
'status': True,
|
|
'msg': 'enterprise audit info search successfully',
|
|
'data': {
|
|
'total_count': total_count,
|
|
'current_page': current_page,
|
|
'page_size': page_size,
|
|
'data': res
|
|
}
|
|
}
|
|
except Exception as e:
|
|
return {
|
|
'status': False,
|
|
'msg': 'Failed to search enterprise audit info, %s' % str(e)
|
|
}
|
|
|
|
ret = await enterprise_audit_info_search(params_kw)
|
|
return ret |