From cc5803d4a7f29df1ab3cac8b56527854c50fef3a Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 29 May 2026 12:07:55 +0800 Subject: [PATCH] refactor: optimize debug output - use debug_params, truncate SQL; add CRUD definitions --- wwwroot/uapi/add_uapi.dspy | 37 ++++ wwwroot/uapi/delete_uapi.dspy | 33 +++ wwwroot/uapi/get_uapi.dspy | 155 ++++++++++++++ wwwroot/uapi/index.ui | 291 ++++++++++++++++++++++++++ wwwroot/uapi/update_uapi.dspy | 36 ++++ wwwroot/uapiio/add_uapiio.dspy | 37 ++++ wwwroot/uapiio/delete_uapiio.dspy | 33 +++ wwwroot/uapiio/get_uapiio.dspy | 72 +++++++ wwwroot/uapiio/index.ui | 103 +++++++++ wwwroot/uapiio/update_uapiio.dspy | 36 ++++ wwwroot/upapp/add_upapp.dspy | 54 +++++ wwwroot/upapp/delete_upapp.dspy | 47 +++++ wwwroot/upapp/get_upapp.dspy | 129 ++++++++++++ wwwroot/upapp/index.ui | 258 +++++++++++++++++++++++ wwwroot/upapp/update_upapp.dspy | 73 +++++++ wwwroot/upappkey/add_upappkey.dspy | 71 +++++++ wwwroot/upappkey/delete_upappkey.dspy | 61 ++++++ wwwroot/upappkey/get_upappkey.dspy | 133 ++++++++++++ wwwroot/upappkey/index.ui | 189 +++++++++++++++++ wwwroot/upappkey/update_upappkey.dspy | 92 ++++++++ wwwroot/uptask_callback.dspy | 2 +- wwwroot/viducallback/index.dspy | 2 +- 22 files changed, 1942 insertions(+), 2 deletions(-) create mode 100644 wwwroot/uapi/add_uapi.dspy create mode 100644 wwwroot/uapi/delete_uapi.dspy create mode 100644 wwwroot/uapi/get_uapi.dspy create mode 100644 wwwroot/uapi/index.ui create mode 100644 wwwroot/uapi/update_uapi.dspy create mode 100644 wwwroot/uapiio/add_uapiio.dspy create mode 100644 wwwroot/uapiio/delete_uapiio.dspy create mode 100644 wwwroot/uapiio/get_uapiio.dspy create mode 100644 wwwroot/uapiio/index.ui create mode 100644 wwwroot/uapiio/update_uapiio.dspy create mode 100644 wwwroot/upapp/add_upapp.dspy create mode 100644 wwwroot/upapp/delete_upapp.dspy create mode 100644 wwwroot/upapp/get_upapp.dspy create mode 100644 wwwroot/upapp/index.ui create mode 100644 wwwroot/upapp/update_upapp.dspy create mode 100644 wwwroot/upappkey/add_upappkey.dspy create mode 100644 wwwroot/upappkey/delete_upappkey.dspy create mode 100644 wwwroot/upappkey/get_upappkey.dspy create mode 100644 wwwroot/upappkey/index.ui create mode 100644 wwwroot/upappkey/update_upappkey.dspy diff --git a/wwwroot/uapi/add_uapi.dspy b/wwwroot/uapi/add_uapi.dspy new file mode 100644 index 0000000..34e742d --- /dev/null +++ b/wwwroot/uapi/add_uapi.dspy @@ -0,0 +1,37 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None +id = params_kw.id +if not id or len(id) > 32: + id = uuid() +ns['id'] = id + + + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.C('uapi', ns.copy()) + return { + "widgettype":"Message", + "options":{ + "cwidth":16, + "cheight":9, + "title":"Add Success", + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Add Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/uapi/delete_uapi.dspy b/wwwroot/uapi/delete_uapi.dspy new file mode 100644 index 0000000..6cb7df1 --- /dev/null +++ b/wwwroot/uapi/delete_uapi.dspy @@ -0,0 +1,33 @@ + +ns = { + 'id':params_kw['id'], +} + + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.D('uapi', ns) + debug('delete success'); + return { + "widgettype":"Message", + "options":{ + "title":"Delete Success", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"ok" + } + } + +debug('Delete failed'); +return { + "widgettype":"Error", + "options":{ + "title":"Delete Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/uapi/get_uapi.dspy b/wwwroot/uapi/get_uapi.dspy new file mode 100644 index 0000000..ad31a14 --- /dev/null +++ b/wwwroot/uapi/get_uapi.dspy @@ -0,0 +1,155 @@ + +ns = params_kw.copy() + + +debug_params('get_uapi', ns) +if not ns.get('page'): + ns['page'] = 1 +if not ns.get('sort'): + + + ns['sort'] = 'name' + + + +sql = '''select a.*, b.httpmethod_text, c.need_auth_text, d.stream_text, e.ioid_text +from (select * from uapi where 1=1 [[filterstr]]) a left join (select k as httpmethod, + v as httpmethod_text from appcodes_kv where parentid='httpmethod') b on a.httpmethod = b.httpmethod left join (select k as need_auth, + v as need_auth_text from appcodes_kv where parentid='yesno') c on a.need_auth = c.need_auth left join (select k as stream, + v as stream_text from appcodes_kv where parentid='resp_mode') d on a.stream = d.stream left join (select id as ioid, + name as ioid_text from uapiio where 1 = 1) e on a.ioid = e.ioid''' + +filterjson = params_kw.get('data_filter') +fields_str=r'''[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32 + }, + { + "name": "upappid", + "title": "上位系统ID", + "type": "str", + "length": 32 + }, + { + "name": "name", + "title": "api名称", + "type": "str", + "length": 200 + }, + { + "name": "title", + "title": "API标题", + "type": "str", + "length": 100 + }, + { + "name": "description", + "title": "接口描述", + "type": "text" + }, + { + "name": "need_auth", + "title": "需要鉴权", + "type": "str", + "length": 1, + "default": "0" + }, + { + "name": "stream", + "title": "流式输出", + "type": "str", + "length": 20 + }, + { + "name": "path", + "title": "path", + "type": "str", + "length": 4000 + }, + { + "name": "httpmethod", + "title": "http方法", + "type": "str", + "length": 20, + "nullable": "yes", + "default": "GET" + }, + { + "name": "chunk_match", + "title": "流式匹配串", + "type": "str", + "length": 100 + }, + { + "name": "headers", + "title": "headers模版", + "type": "text", + "nullable": "yes" + }, + { + "name": "params", + "title": "参数模版", + "type": "text", + "nullable": "yes" + }, + { + "name": "data", + "title": "数据模版", + "type": "text", + "nullable": "yes" + }, + { + "name": "response", + "title": "响应模版", + "type": "text", + "nullable": "yes" + }, + { + "name": "ioid", + "title": "输入输出id", + "type": "str", + "length": 32, + "nullable": "yes" + }, + { + "name": "callbackurl", + "title": "回调url", + "type": "str", + "length": 1000, + "nullable": "yes" + } +]''' +ori_fields = json.loads(fields_str) +if not filterjson: + fields = [ f['name'] for f in ori_fields ] + 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({len(sql)}ch): {sql[:200]}') +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.sqlPaging(sql, ns) + return r +return { + "total":0, + "rows":[] +} \ No newline at end of file diff --git a/wwwroot/uapi/index.ui b/wwwroot/uapi/index.ui new file mode 100644 index 0000000..7860011 --- /dev/null +++ b/wwwroot/uapi/index.ui @@ -0,0 +1,291 @@ + +{ + "id":"uapi_tbl", + "widgettype":"Tabular", + "options":{ + "width":"100%", + "height":"100%", + + + "title":"API", + + + + "description":"API定义", + + + "toolbar":{ + "tools": [ + { + "selected_row": true, + "name": "test", + "icon": "{{entire_url('/imgs/test.svg')}}", + "label": "api测试" + } + ] +}, + + "css":"card", + + + "editable":{ + + "new_data_url":"{{entire_url('add_uapi.dspy')}}", + + + "delete_data_url":"{{entire_url('delete_uapi.dspy')}}", + + + "update_data_url":"{{entire_url('update_uapi.dspy')}}" + + }, + + + "data_url":"{{entire_url('./get_uapi.dspy')}}", + + "data_method":"GET", + "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, + "row_options":{ + + + + "browserfields": { + "exclouded": [ + "id" + ], + "alters": {} +}, + + + "editexclouded":[ + "id" +], + + "fields":[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "id" + }, + { + "name": "upappid", + "title": "上位系统ID", + "type": "str", + "length": 32, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "上位系统ID" + }, + { + "name": "name", + "title": "api名称", + "type": "str", + "length": 200, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "api名称" + }, + { + "name": "title", + "title": "API标题", + "type": "str", + "length": 100, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "API标题" + }, + { + "name": "description", + "title": "接口描述", + "type": "text", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "接口描述" + }, + { + "name": "need_auth", + "title": "需要鉴权", + "type": "str", + "length": 1, + "default": "0", + "label": "需要鉴权", + "uitype": "code", + "valueField": "need_auth", + "textField": "need_auth_text", + "params": { + "dbname": "{{get_module_dbname('uapi')}}", + "table": "appcodes_kv", + "tblvalue": "k", + "tbltext": "v", + "valueField": "need_auth", + "textField": "need_auth_text", + "cond": "parentid='yesno'" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "stream", + "title": "流式输出", + "type": "str", + "length": 20, + "label": "流式输出", + "uitype": "code", + "valueField": "stream", + "textField": "stream_text", + "params": { + "dbname": "{{get_module_dbname('uapi')}}", + "table": "appcodes_kv", + "tblvalue": "k", + "tbltext": "v", + "valueField": "stream", + "textField": "stream_text", + "cond": "parentid='resp_mode'" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "path", + "title": "path", + "type": "str", + "length": 4000, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "path" + }, + { + "name": "httpmethod", + "title": "http方法", + "type": "str", + "length": 20, + "nullable": "yes", + "default": "GET", + "label": "http方法", + "uitype": "code", + "valueField": "httpmethod", + "textField": "httpmethod_text", + "params": { + "dbname": "{{get_module_dbname('uapi')}}", + "table": "appcodes_kv", + "tblvalue": "k", + "tbltext": "v", + "valueField": "httpmethod", + "textField": "httpmethod_text", + "cond": "parentid='httpmethod'" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "chunk_match", + "title": "流式匹配串", + "type": "str", + "length": 100, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "流式匹配串" + }, + { + "name": "headers", + "title": "headers模版", + "type": "text", + "nullable": "yes", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "headers模版" + }, + { + "name": "params", + "title": "参数模版", + "type": "text", + "nullable": "yes", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "参数模版" + }, + { + "name": "data", + "title": "数据模版", + "type": "text", + "nullable": "yes", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "数据模版" + }, + { + "name": "response", + "title": "响应模版", + "type": "text", + "nullable": "yes", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "响应模版" + }, + { + "name": "ioid", + "title": "输入输出id", + "type": "str", + "length": 32, + "nullable": "yes", + "label": "输入输出id", + "uitype": "code", + "valueField": "ioid", + "textField": "ioid_text", + "params": { + "dbname": "{{get_module_dbname('uapi')}}", + "table": "uapiio", + "tblvalue": "id", + "tbltext": "name", + "valueField": "ioid", + "textField": "ioid_text" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "callbackurl", + "title": "回调url", + "type": "str", + "length": 1000, + "nullable": "yes", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "回调url" + } +] + }, + + + + "page_rows":160, + "cache_limit":5 + } + + ,"binds":[ + { + "wid": "self", + "event": "test", + "actiontype": "urlwidget", + "target": "PopupWindow", + "options": { + "methid": "POST", + "params": {}, + "url": "{{entire_url('/uapi/uapi_test.ui')}}" + } + } +] + +} \ No newline at end of file diff --git a/wwwroot/uapi/update_uapi.dspy b/wwwroot/uapi/update_uapi.dspy new file mode 100644 index 0000000..ccfbec3 --- /dev/null +++ b/wwwroot/uapi/update_uapi.dspy @@ -0,0 +1,36 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None + + + + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + + r = await sor.U('uapi', ns) + debug('update success'); + return { + "widgettype":"Message", + "options":{ + "title":"Update Success", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/uapiio/add_uapiio.dspy b/wwwroot/uapiio/add_uapiio.dspy new file mode 100644 index 0000000..8a40cd3 --- /dev/null +++ b/wwwroot/uapiio/add_uapiio.dspy @@ -0,0 +1,37 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None +id = params_kw.id +if not id or len(id) > 32: + id = uuid() +ns['id'] = id + + + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.C('uapiio', ns.copy()) + return { + "widgettype":"Message", + "options":{ + "cwidth":16, + "cheight":9, + "title":"Add Success", + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Add Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/uapiio/delete_uapiio.dspy b/wwwroot/uapiio/delete_uapiio.dspy new file mode 100644 index 0000000..112d14b --- /dev/null +++ b/wwwroot/uapiio/delete_uapiio.dspy @@ -0,0 +1,33 @@ + +ns = { + 'id':params_kw['id'], +} + + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.D('uapiio', ns) + debug('delete success'); + return { + "widgettype":"Message", + "options":{ + "title":"Delete Success", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"ok" + } + } + +debug('Delete failed'); +return { + "widgettype":"Error", + "options":{ + "title":"Delete Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/uapiio/get_uapiio.dspy b/wwwroot/uapiio/get_uapiio.dspy new file mode 100644 index 0000000..99908ed --- /dev/null +++ b/wwwroot/uapiio/get_uapiio.dspy @@ -0,0 +1,72 @@ + +ns = params_kw.copy() + + +debug_params('get_uapiio', ns) +if not ns.get('page'): + ns['page'] = 1 +if not ns.get('sort'): + + + ns['sort'] = 'name' + + + +sql = '''select * from uapiio where 1=1 [[filterstr]]''' + +filterjson = params_kw.get('data_filter') +fields_str=r'''[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32 + }, + { + "name": "name", + "title": "类型名", + "type": "str", + "length": 100 + }, + { + "name": "description", + "title": "类型说明", + "type": "text" + }, + { + "name": "input_fields", + "title": "输入字段", + "type": "text" + } +]''' +ori_fields = json.loads(fields_str) +if not filterjson: + fields = [ f['name'] for f in ori_fields ] + 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({len(sql)}ch): {sql[:200]}') +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.sqlPaging(sql, ns) + return r +return { + "total":0, + "rows":[] +} \ No newline at end of file diff --git a/wwwroot/uapiio/index.ui b/wwwroot/uapiio/index.ui new file mode 100644 index 0000000..f299e93 --- /dev/null +++ b/wwwroot/uapiio/index.ui @@ -0,0 +1,103 @@ + +{ + "id":"uapiio_tbl", + "widgettype":"Tabular", + "options":{ + "width":"100%", + "height":"100%", + + + "title":"API输入输出", + + + + "description":"API的输入输出定义", + + + "css":"card", + + + "editable":{ + + "new_data_url":"{{entire_url('add_uapiio.dspy')}}", + + + "delete_data_url":"{{entire_url('delete_uapiio.dspy')}}", + + + "update_data_url":"{{entire_url('update_uapiio.dspy')}}" + + }, + + + "data_url":"{{entire_url('./get_uapiio.dspy')}}", + + "data_method":"GET", + "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, + "row_options":{ + + + + "browserfields": { + "exclouded": [ + "id" + ], + "alters": {} +}, + + + "editexclouded":[ + "id" +], + + "fields":[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "id" + }, + { + "name": "name", + "title": "类型名", + "type": "str", + "length": 100, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "类型名" + }, + { + "name": "description", + "title": "类型说明", + "type": "text", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "类型说明" + }, + { + "name": "input_fields", + "title": "输入字段", + "type": "text", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "输入字段" + } +] + }, + + + + "page_rows":160, + "cache_limit":5 + } + + ,"binds":[] + +} \ No newline at end of file diff --git a/wwwroot/uapiio/update_uapiio.dspy b/wwwroot/uapiio/update_uapiio.dspy new file mode 100644 index 0000000..6d17571 --- /dev/null +++ b/wwwroot/uapiio/update_uapiio.dspy @@ -0,0 +1,36 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None + + + + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + + r = await sor.U('uapiio', ns) + debug('update success'); + return { + "widgettype":"Message", + "options":{ + "title":"Update Success", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/upapp/add_upapp.dspy b/wwwroot/upapp/add_upapp.dspy new file mode 100644 index 0000000..63a8593 --- /dev/null +++ b/wwwroot/upapp/add_upapp.dspy @@ -0,0 +1,54 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None +id = params_kw.id +if not id or len(id) > 32: + id = uuid() +ns['id'] = id + +if params_kw.get('secretkey'): + ns['secretkey'] = password_encode(params_kw.get('secretkey')) + + + +userorgid = await get_userorgid() +if not userorgid: + return { + "widgettype":"Error", + "options":{ + "title":"Authorization Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"Please login" + } + } +ns['ownerid'] = userorgid + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.C('upapp', ns.copy()) + return { + "widgettype":"Message", + "options":{ + "cwidth":16, + "cheight":9, + "title":"Add Success", + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Add Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/upapp/delete_upapp.dspy b/wwwroot/upapp/delete_upapp.dspy new file mode 100644 index 0000000..3e25a6a --- /dev/null +++ b/wwwroot/upapp/delete_upapp.dspy @@ -0,0 +1,47 @@ + +ns = { + 'id':params_kw['id'], +} + + +userorgid = await get_userorgid() +if not userorgid: + return { + "widgettype":"Error", + "options":{ + "title":"Authorization Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"Please login" + } + } +ns['ownerid'] = userorgid + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.D('upapp', ns) + debug('delete success'); + return { + "widgettype":"Message", + "options":{ + "title":"Delete Success", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"ok" + } + } + +debug('Delete failed'); +return { + "widgettype":"Error", + "options":{ + "title":"Delete Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/upapp/get_upapp.dspy b/wwwroot/upapp/get_upapp.dspy new file mode 100644 index 0000000..f2ca27a --- /dev/null +++ b/wwwroot/upapp/get_upapp.dspy @@ -0,0 +1,129 @@ + +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['ownerid'] = userorgid +ns['userorgid'] = userorgid + +debug_params('get_upapp', ns) +if not ns.get('page'): + ns['page'] = 1 +if not ns.get('sort'): + + + ns['sort'] = 'name' + + + +sql = '''select a.*, b.ownerid_text +from (select * from upapp where 1=1 [[filterstr]]) a left join (select id as ownerid, + orgname as ownerid_text from organization where 1 = 1) b on a.ownerid = b.ownerid''' + +filterjson = params_kw.get('data_filter') +fields_str=r'''[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32 + }, + { + "name": "name", + "title": "上位应用名", + "type": "str", + "length": 200 + }, + { + "name": "description", + "title": "描述", + "type": "text", + "default": "0" + }, + { + "name": "ownerid", + "title": "所属机构", + "type": "str", + "length": 32, + "nullable": "yes" + }, + { + "name": "apisetid", + "title": "api集id", + "type": "str", + "length": 32 + }, + { + "name": "secretkey", + "title": "加密密钥", + "type": "str", + "length": 100 + }, + { + "name": "baseurl", + "title": "系统url", + "type": "str", + "length": 500 + }, + { + "name": "myappid", + "title": "我的appid", + "type": "str", + "length": 100 + }, + { + "name": "dynamic_func", + "title": "动态headers函数", + "type": "str", + "length": 255 + }, + { + "name": "auth_apiname", + "title": "认证API名", + "type": "str", + "length": 200, + "nullable": "yes" + } +]''' +ori_fields = json.loads(fields_str) +if not filterjson: + fields = [ f['name'] for f in ori_fields ] + 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({len(sql)}ch): {sql[:200]}') +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.sqlPaging(sql, ns) + return r +return { + "total":0, + "rows":[] +} \ No newline at end of file diff --git a/wwwroot/upapp/index.ui b/wwwroot/upapp/index.ui new file mode 100644 index 0000000..cd85b4d --- /dev/null +++ b/wwwroot/upapp/index.ui @@ -0,0 +1,258 @@ + +{ + "id":"upapp_tbl", + "widgettype":"Tabular", + "options":{ + "width":"100%", + "height":"100%", + + + "title":"上位系统", + + + + "description":"上位系统", + + + "toolbar":{ + "tools": [ + { + "name": "jumpin", + "label": "跳转到", + "selected_data": true + }, + { + "selected_row": true, + "name": "upappkey", + "icon": "{{entire_url('/imgs/upappkey.svg')}}", + "label": "APIKEY" + }, + { + "selected_row": true, + "name": "uapi", + "icon": "{{entire_url('/imgs/uapi.svg')}}", + "label": "API" + } + ] +}, + + "css":"card", + + + "editable":{ + + "new_data_url":"{{entire_url('add_upapp.dspy')}}", + + + "delete_data_url":"{{entire_url('delete_upapp.dspy')}}", + + + "update_data_url":"{{entire_url('update_upapp.dspy')}}" + + }, + + + "data_url":"{{entire_url('./get_upapp.dspy')}}", + + "data_method":"GET", + "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, + "row_options":{ + + + + "browserfields": { + "exclouded": [ + "ownerid" + ], + "alters": {} +}, + + + "editexclouded":[ + "ownerid" +], + + "fields":[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "id" + }, + { + "name": "name", + "title": "上位应用名", + "type": "str", + "length": 200, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "上位应用名" + }, + { + "name": "description", + "title": "描述", + "type": "text", + "default": "0", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "描述" + }, + { + "name": "ownerid", + "title": "所属机构", + "type": "str", + "length": 32, + "nullable": "yes", + "label": "所属机构", + "uitype": "code", + "valueField": "ownerid", + "textField": "ownerid_text", + "params": { + "dbname": "{{get_module_dbname('uapi')}}", + "table": "organization", + "tblvalue": "id", + "tbltext": "orgname", + "valueField": "ownerid", + "textField": "ownerid_text" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "apisetid", + "title": "api集id", + "type": "str", + "length": 32, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "api集id" + }, + { + "name": "secretkey", + "title": "加密密钥", + "type": "str", + "length": 100, + "cwidth": 18, + "uitype": "password", + "datatype": "str", + "label": "加密密钥" + }, + { + "name": "baseurl", + "title": "系统url", + "type": "str", + "length": 500, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "系统url" + }, + { + "name": "myappid", + "title": "我的appid", + "type": "str", + "length": 100, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "我的appid" + }, + { + "name": "dynamic_func", + "title": "动态headers函数", + "type": "str", + "length": 255, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "动态headers函数" + }, + { + "name": "auth_apiname", + "title": "认证API名", + "type": "str", + "length": 200, + "nullable": "yes", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "认证API名" + } +] + }, + + + + "page_rows":160, + "cache_limit":5 + } + + ,"binds":[ + { + "wid": "self", + "event": "jumpin", + "actiontype": "urlwidget", + "target": "self", + "options": { + "url": "{{entire_url('/uapi/jump_in.dspy')}}" + } + }, + { + "wid": "self", + "event": "upappkey", + "actiontype": "urlwidget", + "target": "PopupWindow", + "popup_options": { + "title": "APIKEY", + "icon": "{{entire_url('/appbase/get_icon.dspy')}}?id=upappkey", + "resizable": true, + "height": "70%", + "width": "70%" + }, + "params_mapping": { + "mapping": { + "id": "upappid", + "referer_widget": "referer_widget" + }, + "need_other": false + }, + "options": { + "method": "POST", + "params": {}, + "url": "{{entire_url('../upappkey')}}" + } + }, + { + "wid": "self", + "event": "uapi", + "actiontype": "urlwidget", + "target": "PopupWindow", + "popup_options": { + "title": "API", + "icon": "{{entire_url('/appbase/get_icon.dspy')}}?id=uapi", + "resizable": true, + "height": "70%", + "width": "70%" + }, + "params_mapping": { + "mapping": { + "id": "upappid", + "referer_widget": "referer_widget" + }, + "need_other": false + }, + "options": { + "method": "POST", + "params": {}, + "url": "{{entire_url('../uapi')}}" + } + } +] + +} \ No newline at end of file diff --git a/wwwroot/upapp/update_upapp.dspy b/wwwroot/upapp/update_upapp.dspy new file mode 100644 index 0000000..0a95885 --- /dev/null +++ b/wwwroot/upapp/update_upapp.dspy @@ -0,0 +1,73 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None + + +userorgid = await get_userorgid() +if not userorgid: + return { + "widgettype":"Error", + "options":{ + "title":"Authorization Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"Please login" + } + } +ns['ownerid'] = userorgid + + +if params_kw.get('secretkey'): + ns['secretkey'] = password_encode(params_kw.get('secretkey')) + + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + + ns1 = { + + "ownerid": userorgid, + + + "id": params_kw.id + } + recs = await sor.R('upapp', ns1) + if len(recs) < 1: + return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"Record no exist or with wrong ownership" + } + } + + r = await sor.U('upapp', ns) + debug('update success'); + return { + "widgettype":"Message", + "options":{ + "title":"Update Success", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/upappkey/add_upappkey.dspy b/wwwroot/upappkey/add_upappkey.dspy new file mode 100644 index 0000000..65b9a75 --- /dev/null +++ b/wwwroot/upappkey/add_upappkey.dspy @@ -0,0 +1,71 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None +id = params_kw.id +if not id or len(id) > 32: + id = uuid() +ns['id'] = id + +if params_kw.get('apikey'): + ns['apikey'] = password_encode(params_kw.get('apikey')) + +if params_kw.get('apipasswd'): + ns['apipasswd'] = password_encode(params_kw.get('apipasswd')) + + +userid = await get_user() +if not userid: + return { + "widgettype":"Error", + "options":{ + "title":"Authorization Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"Please login" + } + } +ns['ownerid'] = userid + + +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 + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.C('upappkey', ns.copy()) + return { + "widgettype":"Message", + "options":{ + "cwidth":16, + "cheight":9, + "title":"Add Success", + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Add Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/upappkey/delete_upappkey.dspy b/wwwroot/upappkey/delete_upappkey.dspy new file mode 100644 index 0000000..9277b1f --- /dev/null +++ b/wwwroot/upappkey/delete_upappkey.dspy @@ -0,0 +1,61 @@ + +ns = { + 'id':params_kw['id'], +} + +userid = await get_user() +if not userid: + return { + "widgettype":"Error", + "options":{ + "title":"Authorization Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"Please login" + } + } +ns['ownerid'] = userid + + +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 + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.D('upappkey', ns) + debug('delete success'); + return { + "widgettype":"Message", + "options":{ + "title":"Delete Success", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"ok" + } + } + +debug('Delete failed'); +return { + "widgettype":"Error", + "options":{ + "title":"Delete Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/upappkey/get_upappkey.dspy b/wwwroot/upappkey/get_upappkey.dspy new file mode 100644 index 0000000..603eb10 --- /dev/null +++ b/wwwroot/upappkey/get_upappkey.dspy @@ -0,0 +1,133 @@ + +ns = params_kw.copy() + +userid = await get_user() +if not userid: + return { + "widgettype":"Error", + "options":{ + "title":"Authorization Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"Please login" + } + } +ns['ownerid'] = userid +ns['userid'] = userid + + +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_params('get_upappkey', ns) +if not ns.get('page'): + ns['page'] = 1 +if not ns.get('sort'): + + ns['sort'] = 'id' + + +sql = '''select a.*, b.ownerid_text, c.upappid_text, d.orgid_text, e.is_first_text +from (select * from upappkey where 1=1 [[filterstr]]) a left join (select id as ownerid, + username as ownerid_text from users where 1 = 1) b on a.ownerid = b.ownerid left join (select id as upappid, + name as upappid_text from upapp where 1 = 1) c on a.upappid = c.upappid left join (select id as orgid, + orgname as orgid_text from organization where 1 = 1) d on a.orgid = d.orgid left join (select k as is_first, + v as is_first_text from appcodes_kv where parentid='yesno') e on a.is_first = e.is_first''' + +filterjson = params_kw.get('data_filter') +fields_str=r'''[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32 + }, + { + "name": "upappid", + "title": "应用id", + "type": "str", + "length": 32 + }, + { + "name": "ownerid", + "title": "属主id", + "type": "str", + "length": 32, + "default": "0" + }, + { + "name": "apikey", + "title": "api密钥", + "type": "str", + "length": 4000, + "default": "0" + }, + { + "name": "apiuser", + "title": "api用户", + "type": "str", + "length": 100 + }, + { + "name": "apipasswd", + "title": "api密码", + "type": "str", + "length": 100 + }, + { + "name": "orgid", + "title": "属主机构id", + "type": "str", + "length": 32 + }, + { + "name": "is_first", + "title": "是否第一用户", + "type": "str", + "length": 1 + } +]''' +ori_fields = json.loads(fields_str) +if not filterjson: + fields = [ f['name'] for f in ori_fields ] + 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({len(sql)}ch): {sql[:200]}') +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + r = await sor.sqlPaging(sql, ns) + return r +return { + "total":0, + "rows":[] +} \ No newline at end of file diff --git a/wwwroot/upappkey/index.ui b/wwwroot/upappkey/index.ui new file mode 100644 index 0000000..ba1364e --- /dev/null +++ b/wwwroot/upappkey/index.ui @@ -0,0 +1,189 @@ + +{ + "id":"upappkey_tbl", + "widgettype":"Tabular", + "options":{ + "width":"100%", + "height":"100%", + + + "title":"上位系统密码", + + + + "description":"上位系统密码", + + + "css":"card", + + + "editable":{ + + "new_data_url":"{{entire_url('add_upappkey.dspy')}}", + + + "delete_data_url":"{{entire_url('delete_upappkey.dspy')}}", + + + "update_data_url":"{{entire_url('update_upappkey.dspy')}}" + + }, + + + "data_url":"{{entire_url('./get_upappkey.dspy')}}", + + "data_method":"GET", + "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, + "row_options":{ + + + + "browserfields": { + "exclouded": [ + "id", + "ownerid", + "orgid" + ], + "alters": {} +}, + + + "editexclouded":[ + "id", + "upappid", + "ownerid", + "orgid" +], + + "fields":[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "id" + }, + { + "name": "upappid", + "title": "应用id", + "type": "str", + "length": 32, + "label": "应用id", + "uitype": "code", + "valueField": "upappid", + "textField": "upappid_text", + "params": { + "dbname": "{{get_module_dbname('uapi')}}", + "table": "upapp", + "tblvalue": "id", + "tbltext": "name", + "valueField": "upappid", + "textField": "upappid_text" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "ownerid", + "title": "属主id", + "type": "str", + "length": 32, + "default": "0", + "label": "属主id", + "uitype": "code", + "valueField": "ownerid", + "textField": "ownerid_text", + "params": { + "dbname": "{{get_module_dbname('uapi')}}", + "table": "users", + "tblvalue": "id", + "tbltext": "username", + "valueField": "ownerid", + "textField": "ownerid_text" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "apikey", + "title": "api密钥", + "type": "str", + "length": 4000, + "default": "0", + "cwidth": 18, + "uitype": "password", + "datatype": "str", + "label": "api密钥" + }, + { + "name": "apiuser", + "title": "api用户", + "type": "str", + "length": 100, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "api用户" + }, + { + "name": "apipasswd", + "title": "api密码", + "type": "str", + "length": 100, + "cwidth": 18, + "uitype": "password", + "datatype": "str", + "label": "api密码" + }, + { + "name": "orgid", + "title": "属主机构id", + "type": "str", + "length": 32, + "label": "属主机构id", + "uitype": "code", + "valueField": "orgid", + "textField": "orgid_text", + "params": { + "dbname": "{{get_module_dbname('uapi')}}", + "table": "organization", + "tblvalue": "id", + "tbltext": "orgname", + "valueField": "orgid", + "textField": "orgid_text" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "is_first", + "title": "是否第一用户", + "type": "str", + "length": 1, + "label": "是否第一用户", + "uitype": "code", + "valueField": "is_first", + "textField": "is_first_text", + "params": { + "dbname": "{{get_module_dbname('uapi')}}", + "table": "appcodes_kv", + "tblvalue": "k", + "tbltext": "v", + "valueField": "is_first", + "textField": "is_first_text", + "cond": "parentid='yesno'" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + } +] + }, + + + + "page_rows":160, + "cache_limit":5 + } + + ,"binds":[] + +} \ No newline at end of file diff --git a/wwwroot/upappkey/update_upappkey.dspy b/wwwroot/upappkey/update_upappkey.dspy new file mode 100644 index 0000000..460ab81 --- /dev/null +++ b/wwwroot/upappkey/update_upappkey.dspy @@ -0,0 +1,92 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None + +userid = await get_user() +if not userid: + return { + "widgettype":"Error", + "options":{ + "title":"Authorization Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"Please login" + } + } +ns['ownerid'] = userid + + +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 + + +if params_kw.get('apikey'): + ns['apikey'] = password_encode(params_kw.get('apikey')) + +if params_kw.get('apipasswd'): + ns['apipasswd'] = password_encode(params_kw.get('apipasswd')) + + +db = DBPools() +dbname = get_module_dbname('uapi') +async with db.sqlorContext(dbname) as sor: + + ns1 = { + + "orgid": userorgid, + + + "ownerid": userid, + + "id": params_kw.id + } + recs = await sor.R('upappkey', ns1) + if len(recs) < 1: + return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"Record no exist or with wrong ownership" + } + } + + r = await sor.U('upappkey', ns) + debug('update success'); + return { + "widgettype":"Message", + "options":{ + "title":"Update Success", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/uptask_callback.dspy b/wwwroot/uptask_callback.dspy index 219a9ad..e06b2e6 100644 --- a/wwwroot/uptask_callback.dspy +++ b/wwwroot/uptask_callback.dspy @@ -1,4 +1,4 @@ -debug(f'{params_kw=}') +debug_params('params_kw', params_kw) if parmas_kw.task_id is None: e = Exception(f'need a task_id') raise e diff --git a/wwwroot/viducallback/index.dspy b/wwwroot/viducallback/index.dspy index 62b85c3..6ab62cd 100644 --- a/wwwroot/viducallback/index.dspy +++ b/wwwroot/viducallback/index.dspy @@ -1,4 +1,4 @@ -debug(f'{params_kw=} +debug_params('params_kw', params_kw) taskid = params_kw.id async with get_sor_context(request._run_ns, 'uapi') as sor: llmusage = await get_llmlage_by_taskid(taskid)