48 lines
1.3 KiB
Python

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)