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['orgid'] = userorgid ns['userorgid'] = userorgid debug(f'get_users.dspy:{ns=}') if not ns.get('page'): ns['page'] = 1 if not ns.get('sort'): ns['sort'] = 'username' sql = '''select a.*, b.user_status_text, c.sync_from_text, d.orgid_text from (select * from users where 1=1 [[filterstr]]) a left join (select k as user_status, v as user_status_text from appcodes_kv where parentid='user_status') b on a.user_status = b.user_status left join (select id as sync_from, name as sync_from_text from downapp where 1 = 1) c on a.sync_from = c.sync_from left join (select id as orgid, orgname as orgid_text from organization where 1 = 1) d on a.orgid = d.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": "username", "title": "用户名", "type": "str", "length": 255 }, { "name": "password", "title": "密码", "type": "str", "length": 255 }, { "name": "email", "title": "邮件地址", "type": "str", "length": 255 }, { "name": "orgid", "title": "所属机构", "type": "str", "length": 32 }, { "name": "nick_name", "title": "显示名", "type": "str", "length": 255 }, { "name": "address", "title": "地址", "type": "str", "length": 255 }, { "name": "mobile", "title": "手机", "type": "str", "length": 255 }, { "name": "user_status", "title": "用户状态", "type": "str", "length": 1, "default": "0" }, { "name": "created_at", "title": "注册日期", "type": "date" }, { "name": "last_login", "title": "最后登录", "type": "timestamp", "nullable": true }, { "name": "login_fail_count", "title": "连续失败次数", "type": "short", "default": "0" }, { "name": "last_login_fail", "title": "最后登录失败时间", "type": "timestamp", "nullable": true }, { "name": "sync_from", "title": "同步应用id", "type": "str", "length": 32, "nullable": true } ] ] 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 = get_module_dbname('rbac') async with db.sqlorContext(dbname) as sor: r = await sor.sqlPaging(sql, ns) return r return { "total":0, "rows":[] }