rbac/wwwroot/provider/get_organization.dspy

160 lines
3.6 KiB
Plaintext

ns = params_kw.copy()
debug(f'get_organization.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = 'orgname'
sql = '''select a.*, b.province_id_text, c.city_id_text, d.distinct_id_text
from (select * from organization where 1=1 [[filterstr]]) a left join (select k as province_id,
v as province_id_text from appcodes_kv where parentid='chnaddr') b on a.province_id = b.province_id left join (select k as city_id,
v as city_id_text from appcodes_kv where parentid='city') c on a.city_id = c.city_id left join (select k as distinct_id,
v as distinct_id_text from appcodes_kv where parentid='distinct') d on a.distinct_id = d.distinct_id'''
filterjson = params_kw.get('data_filter')
if not filterjson:
fields = [ f['name'] for f in [
{
"name": "id",
"title": "机构编码",
"type": "str",
"length": 32
},
{
"name": "orgname",
"title": "机构名称",
"type": "str",
"length": 255
},
{
"name": "orgabbr",
"title": "机构简称",
"type": "str",
"length": 100
},
{
"name": "alias_name",
"title": "机构别名",
"type": "str",
"length": 255
},
{
"name": "contactor",
"title": "联系人",
"type": "str",
"length": 32
},
{
"name": "contactor_phone",
"title": "联系人电话",
"type": "str",
"length": 100
},
{
"name": "province_id",
"title": "所在省id",
"type": "str",
"length": 32
},
{
"name": "city_id",
"title": "所在城市id",
"type": "str",
"length": 32
},
{
"name": "distinct_id",
"title": "所在地区id",
"type": "str",
"length": 32
},
{
"name": "emailaddress",
"title": "邮箱",
"type": "str",
"length": 256
},
{
"name": "address",
"title": "地址",
"type": "str",
"length": 400
},
{
"name": "main_business",
"title": "主营业务描述",
"type": "str",
"length": 1000
},
{
"name": "orgcode",
"title": "组织结构代码",
"type": "str",
"length": 100
},
{
"name": "license_img",
"title": "营业执照",
"type": "str",
"length": 400
},
{
"name": "id_img",
"title": "身份证",
"type": "str",
"length": 400
},
{
"name": "parentid",
"title": "父机构id",
"type": "str",
"length": 32
},
{
"name": "org_type",
"title": "机构类型",
"type": "str",
"length": 32
},
{
"name": "sitename",
"title": "网站域名",
"type": "str",
"length": 300
}
] ]
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":[]
}