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 pname = 'business_date' and del_flg='0'" recs = await sor.sqlExe(sql, {}) if len(recs) > 0: return recs[0]['pvalue'] 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 pvalue=${new_dat}$, del_flg='0' where pname='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)