diff --git a/platformbiz/businessdate.py b/platformbiz/businessdate.py new file mode 100644 index 0000000..227d868 --- /dev/null +++ b/platformbiz/businessdate.py @@ -0,0 +1,39 @@ +from sqlor.dbpools import DBPools +from appPublic.timeUtils import strdate_add +from .excep import BusinessDateParamsError +from .const import * +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 BusinessDateParamsError + + if sor: + return await _f(sor) + db = DBPools() + 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() + 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) +