from sqlor.dbpools import DBPools from .const import * from appPublic.uniqueID import getID from datetime import datetime async def openAccount(sor, accounting_orgid, orgid, account_config): ns = { 'id':getID(), 'accounting_orgid':accounting_orgid, 'orgid':orgid, 'subjectid':account_config['subjectid'], 'balance_at':account_config['balance_side'], 'create_at':datetime.now(), 'max_detailno':0 } await sor.C('account', ns.copy()) print(ns, 'opened') async def openPartyAccounts(sor, accounting_orgid, orgid, party_type): sql = """select a.*, b.id as subjectid, b.balance_side from account_config a, subject b where a.subjectname = b.name and a.partytype=${partytype}$ """ recs = await sor.sqlExe(sql, {'partytype':party_type}) print(f'select account_config {recs=}', party_type) for r in recs: await openAccount(sor, accounting_orgid, orgid, r) async def _openPartyAccounts(accounting_orgid, orgid, party_type): db = DBPools() async with db.sqlorContext(DBNAME) as sor: await openPartyAccounts(sor, accounting_orgid, orgid, party_type) async def openResellerAccounts(sor, accounting_orgid, orgid): return await _openPartyAccounts(accounting_orgid, orgid, PARTY_RESELLER) async def openCustomerAccounts(sor, accounting_orgid, orgid): return await _openPartyAccounts(accounting_orgid, orgid, PARTY_CUSTOMER) async def openOwnerAccounts(sor, accounting_orgid): orgid = accounting_orgid return await _openPartyAccounts(accounting_orgid, orgid, PARTY_OWNER) async def openProviderAccounts(sor, accounting_orgid, orgid): return await _openPartyAccounts(accounting_orgid, orgid, PARTY_PROVIDER) async def openAllCustomerAccounts(sor, accounting_orgid): sql = """select * from organization where parentid=${accounting_orgid}$ and org_type in ('2', '3' )""" recs = await sor.sqlExe(sql, {'accounting_orgid':accounting_orgid}) print(f'{recs=}') for r in recs: await openCustomerAccounts(sor, accounting_orgid, r['id']) async def openAllResellerAccounts(sor, accounting_orgid): sql = """select * from organization where parentid=${accounting_orgid}$ and org_type = '1'""" recs = await sor.sqlExe(sql, {'accounting_orgid':accounting_orgid}) print(f'{recs=}') for r in recs: await openResellerAccounts(sor, accounting_orgid, r['id']) async def openAllProviderAccounts(sor, accounting_orgid): sql = """select * from organization where org_type = '4'""" recs = await sor.sqlExe(sql, {'accounting_orgid':accounting_orgid}) print(f'{recs=}') for r in recs: await openProviderAccounts(sor, accounting_orgid, r['id']) # 算力券发行方 async def openPublisherAccounts(sor, accounting_orgid, orgid): return await _openPartyAccounts(accounting_orgid, orgid, PARTY_PUBLISHER) # 算力券承销方 async def openUnderwriterAccounts(sor, accounting_orgid, orgid): return await _openPartyAccounts(accounting_orgid, orgid, PARTY_UNDERWRITER)