commit 809ef778989ac200cb7f962d63aec9a406f48928 Author: yumoqing Date: Wed Jul 16 14:28:56 2025 +0800 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..f49cf56 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# appbase +基本应用包,主要是提供代码管理和系统参数管理能力 + +## 参数管理 +应用系统的参数集中管理,为系统提供可动态维护的参数 +业务日期,应用的业务日期存储在参数表中,并提供函数用于获得系统日期和设置心业务日期 + +## 代码管理 +提供系统键值对管理和维护能力 + diff --git a/appbase/__init__.py b/appbase/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/appbase/businessdate.py b/appbase/businessdate.py new file mode 100644 index 0000000..bb7b7e8 --- /dev/null +++ b/appbase/businessdate.py @@ -0,0 +1,47 @@ +from sqlor.dbpools import DBPools +from ahserver.serverenv import get_serverenv +from appPublic.timeUtils import strdate_add + +def get_dbname(): + f = get_serverenv('get_module_dbname') + if f is None: + raise Exception('get_module_dbname not found') + dbname = f('appbase') + +async def get_business_date(sor=None): + async def _f(sor): + sql = "select * from params where params_name = 'business_date'" + recs = await sor.sqlExe(sql, {}) + if len(recs) > 0: + return recs[0]['params_value'] + raise Exception('BusinessDateParamsError') + + if sor: + return await _f(sor) + db = DBPools() + dbname = get_dbname() + async with db.sqlorContext(dbname) as sor: + return await _f(sor) + +async def new_business_date(sor=None): + async def _f(sor): + dat = await get_business_date(sor) + new_dat = strdate_add(dat, days=1) + sql = "update params set params_value=${new_dat}$ where params_name='business_date'" + await sor.sqlExe(sql, {'new_dat':new_dat}) + + if sor: + return await _f(sor) + db = DBPools() + dbname = get_dbname() + async with db.sqlorContext(dbname) as sor: + return await _f(sor) + +async def previous_business_date(sor=None): + dat = await get_business_date(sor=sor) + return strdate_add(dat, days=-1) + +async def next_business_date(sor=None): + dat = await get_business_date(sor=sor) + return strdate_add(dat, days=1) + diff --git a/appbase/init.py b/appbase/init.py new file mode 100644 index 0000000..1fdf40e --- /dev/null +++ b/appbase/init.py @@ -0,0 +1,7 @@ +from appbase.businessdate import get_business_date, new_business_date +from ahserver.serverenv import ServerEnv + +def load_appbase(): + g = ServerEnv() + g.get_business_date = get_business_date + g.new_business_date = new_business_date diff --git a/appbase/params.py b/appbase/params.py new file mode 100644 index 0000000..c7fdcd2 --- /dev/null +++ b/appbase/params.py @@ -0,0 +1,6 @@ + +async def _get_params(sor, name): + ps = await sor.R('params', {'params_name': name}) + if len(ps) > 0: + return ps[0].params_value + diff --git a/appbase/version.py b/appbase/version.py new file mode 100644 index 0000000..b8023d8 --- /dev/null +++ b/appbase/version.py @@ -0,0 +1 @@ +__version__ = '0.0.1' diff --git a/json/appcodes.json b/json/appcodes.json new file mode 100644 index 0000000..019286a --- /dev/null +++ b/json/appcodes.json @@ -0,0 +1,22 @@ +{ + "tblname":"appcodes", + "title":"代码管理", + "params":{ + "sortby":"id", + "browserfields":{ + "exclouded":[], + "alters":{} + }, + "editexclouded":[], + "subtables":[ + { + "title":"代码键值管理", + "subtable":"appcodes_kv", + "params":{ + "hierarchy_flg":"${hierarchy_flg}" + }, + "field":"parentid" + } + ] + } +} diff --git a/json/appcodes_kv.json b/json/appcodes_kv.json new file mode 100644 index 0000000..1d7636c --- /dev/null +++ b/json/appcodes_kv.json @@ -0,0 +1,24 @@ +{ + "tblname":"appcodes_kv", + "title":"代码键值管理", + "params":{ + "sortby":["k", "v"], + "browserfields":{ + "exclouded":["id", "parentid" ], + "alters":{} + }, + "editexclouded":["id", "parentid" ], + "subtables_condition":" params_kw.hierarchy_flg == '1' ", + "subtables":[ + { + "title":"代码键值管理", + "params":{ + "hierarchy_flg":"{{params_kw.hierarchy_flg}}", + "parentid":"${id}" + }, + "subtable":"appcodes_kv", + "field":"parentid" + } + ] + } +} diff --git a/json/build.sh b/json/build.sh new file mode 100755 index 0000000..948b4ba --- /dev/null +++ b/json/build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/bash + +xls2ui -m ../models -o ../wwwroot appbase *.json diff --git a/json/params.json b/json/params.json new file mode 100644 index 0000000..9cee11f --- /dev/null +++ b/json/params.json @@ -0,0 +1,39 @@ +{ + "tblname":"params", + "params":{ + "title":"参数", + "description":"系统参数,可以动态增加修改参数", + "sortby":"params_name", + "toolbar":{ + "tools":[ + { + "name":"switch", + "icon":"newdate.png", + "selected_row": true, + "label":"切日" + } + ] + }, + "browserfields":{ + "exclouded":["id"], + "alters":{} + }, + "binds":[ + { + "wid":"self", + "event":"row_selected", + "actiontype":"script", + "target":"self", + "script":"console.log('test', params);" + }, + { + "wid":"self", + "event":"switch", + "actiontype":"script", + "target":"self", + "script":"console.log('swith event', params);" + } + ], + "editexclouded":["id"] + } +} diff --git a/models/appcodes.xlsx b/models/appcodes.xlsx new file mode 100644 index 0000000..4eb4548 Binary files /dev/null and b/models/appcodes.xlsx differ diff --git a/models/appcodes_kv.xlsx b/models/appcodes_kv.xlsx new file mode 100644 index 0000000..4f203d4 Binary files /dev/null and b/models/appcodes_kv.xlsx differ diff --git a/models/params.xlsx b/models/params.xlsx new file mode 100644 index 0000000..2ecfa79 Binary files /dev/null and b/models/params.xlsx differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..f1ac277 --- /dev/null +++ b/setup.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- + +from appbase.version import __version__ +try: + from setuptools import setup +except ImportError: + from distutils.core import setup +required = [] +with open('requirements.txt', 'r') as f: + ls = f.read() + required = ls.split('\n') + +with open('appbase/version.py', 'r') as f: + x = f.read() + y = x[x.index("'")+1:] + z = y[:y.index("'")] + version = z +with open("README.md", "r") as fh: + long_description = fh.read() + +name = "appbase" +description = "appbase" +author = "yumoqing" +email = "yumoqing@gmail.com" + +package_data = {} + +setup( + name="appbase", + version=version, + + # uncomment the following lines if you fill them out in release.py + description=description, + author=author, + author_email=email, + platforms='any', + install_requires=required , + packages=[ + "appbase" + ], + package_data=package_data, + keywords = [ + ], + url="https://github.com/yumoqing/appbase", + long_description=long_description, + long_description_content_type="text/markdown", + classifiers = [ + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3', + 'License :: OSI Approved :: MIT License', + ], +) diff --git a/wwwroot/get_appcodes_kv.dspy b/wwwroot/get_appcodes_kv.dspy new file mode 100644 index 0000000..56c0379 --- /dev/null +++ b/wwwroot/get_appcodes_kv.dspy @@ -0,0 +1,16 @@ +debug(params_kw) +ns = params_kw.copy() + +db = DBPools() +sql = f"""select id, k as {params_kw.valueField}, + v as {params_kw.textField} +from appcodes_kv where 1=1 """ +if params_kw.cond: + sql += f" and {params_kw.cond} " + +sql += f"order by {params_kw.textField}" + +async with db.sqlorContext(params_kw.dbname) as sor: + rs = await sor.sqlExe(sql, ns) + return rs +return [] diff --git a/wwwroot/get_code.dspy b/wwwroot/get_code.dspy new file mode 100644 index 0000000..0f5f998 --- /dev/null +++ b/wwwroot/get_code.dspy @@ -0,0 +1,27 @@ +debug(params_kw) +ns = params_kw.copy() + +db = DBPools() +sql = f"""select {params_kw.tblvalue} as {params_kw.valueField}, + {params_kw.tbltext} as {params_kw.textField} +from {params_kw.table} where 1=1 """ +if params_kw.cond: + sql += f" and {params_kw.cond} " + +sql += f"order by {params_kw.textField}" + +ac = ArgsConvert('[[', ']]') +vars = ac.findAllVariables(sql) +if 'userid' in vars: + ns['userid'] = await get_user() +if 'userorgid' in vars: + ns['userorgid'] = await get_userorgid() + +NameSpace = {v:'${' + v + '}$' for v in vars} +sql = ac.convert(sql, NameSpace) +debug(f'/appbase/get_code.dspy: {sql=}') + +async with db.sqlorContext(params_kw.dbname) as sor: + rs = await sor.sqlExe(sql, ns) + return rs +return [] diff --git a/wwwroot/menu.ui b/wwwroot/menu.ui new file mode 100644 index 0000000..47f3280 --- /dev/null +++ b/wwwroot/menu.ui @@ -0,0 +1,17 @@ +[ + { + "name":"codemgr", + "label":"代码管理", + "url":"{{entire_url('/appbase/appcodes')}}" + }, + { + "name":"params", + "label":"参数管理", + "url":"{{entire_url('/appbase/params')}}" + }, + { + "name":"jsonhttpapi", + "label":"json应用接口", + "url":"{{entire_url('/appbase/jsonhttpapi')}}" + } +]