bugfix
This commit is contained in:
parent
603c02e579
commit
0120300968
@ -1,6 +1,7 @@
|
||||
from pricing.pricing import (
|
||||
PricingProgram,
|
||||
test_pricing,
|
||||
buffered_charging,
|
||||
get_pricing_program
|
||||
)
|
||||
from ahserver.serverenv import ServerEnv
|
||||
@ -8,6 +9,7 @@ from ahserver.serverenv import ServerEnv
|
||||
def load_pricing():
|
||||
env = ServerEnv()
|
||||
env.get_pricing_program = get_pricing_program
|
||||
env.buffered_charging = buffered_charging
|
||||
env.write_pricing_patten = PricingProgram.write_pricing_patten
|
||||
env.pricing_program_charging = PricingProgram.charging
|
||||
env.load_pricing_data = PricingProgram.load_pricing_data
|
||||
|
||||
@ -4,6 +4,7 @@ from ahserver.serverenv import ServerEnv
|
||||
from ahserver.filestorage import FileStorage
|
||||
from sqlor.dbpools import DBPools, get_sor_context
|
||||
from appPublic.log import debug, exception
|
||||
from appPublic.timeUtils import curDateString
|
||||
from appPublic.dictObject import DictObject
|
||||
from .write_pattern import write_pattern_xlsx, load_xlsx_pricing
|
||||
import yaml
|
||||
@ -116,7 +117,7 @@ def typevalue(v, t):
|
||||
|
||||
def check_value(field, spec_value, data_value):
|
||||
if field.value_mode == 'between':
|
||||
arr = spec_value.split(' ')
|
||||
arr = spec_value.strip().split()
|
||||
if len(arr) < 2 or len(arr) > 3:
|
||||
e = f'{spec_value=} error'
|
||||
exception(e)
|
||||
@ -143,7 +144,7 @@ def check_value(field, spec_value, data_value):
|
||||
raise Exception(e)
|
||||
|
||||
if field.value_mode == 'in':
|
||||
arr = spec_value.split(' ')
|
||||
arr = spec_value.strip().split()
|
||||
arr = [ typevalue(a, field.type) for a in arr ]
|
||||
# debug(f'{arr=}, {data_value=}')
|
||||
return data_value in arr
|
||||
@ -159,7 +160,16 @@ def check_value(field, spec_value, data_value):
|
||||
x = eval(script, ns)
|
||||
return x
|
||||
|
||||
def data_mapping(ns, name, v):
|
||||
if 'mappings' in ns.keys():
|
||||
mappings = ns['mappings'].get(name)
|
||||
if mappings:
|
||||
return mappings.get(v, v)
|
||||
return v
|
||||
|
||||
class PricingProgram:
|
||||
pricing_data = {}
|
||||
|
||||
@staticmethod
|
||||
async def get_pricing_program(ppid):
|
||||
env = ServerEnv()
|
||||
@ -273,6 +283,53 @@ class PricingProgram:
|
||||
exception(e)
|
||||
raise Exception(e)
|
||||
|
||||
@staticmethod
|
||||
async def get_ppid_pricing(ppid):
|
||||
dat = curDateString()
|
||||
k = f'{ppid}.{dat}'
|
||||
d = PricingProgram.pricing_data.get(k)
|
||||
if d:
|
||||
return d
|
||||
env = ServerEnv()
|
||||
async with get_sor_context(env, 'pricing') as sor:
|
||||
sql = """select a.name, a.ownerid, a.providerid,
|
||||
pricing_belong, discount, b.pricing_data
|
||||
from pricing_program a, pricing_program_timing b
|
||||
where a.id = b.ppid
|
||||
and a.id = ${ppid}$
|
||||
and b.enabled_date <= ${biz_date}$
|
||||
and b.expired_date > ${biz_date}$
|
||||
order by b.enabled_date desc"""
|
||||
recs = await sor.sqlExe(sql, {
|
||||
'ppid': ppid,
|
||||
'biz_date': dat
|
||||
})
|
||||
if len(recs) == 0:
|
||||
e = Exception(f'{ppid=},{dat=} data not found')
|
||||
exception(f'{e}')
|
||||
raise
|
||||
d = recs[0]
|
||||
PricingProgram.pricing_data[k] = d
|
||||
dates = PricingProgram.pricing_data.get(ppid, [])
|
||||
dates.append(dat)
|
||||
dates_cnt = len(dates)
|
||||
if dates_cnt > 2:
|
||||
for i in range(dates_cnt - 2):
|
||||
dk = f'{ppid}.{dates[i]}'
|
||||
PricingProgram.pricing_data[dk]
|
||||
dates = dates[-2:]
|
||||
PricingProgram.pricing_data[ppid] = dates
|
||||
return d
|
||||
|
||||
async def buffered_charging(ppid, data):
|
||||
r = await PricingProgram.get_ppid_pricing(ppid)
|
||||
prices = PricingProgram.get_pricing_from_ymalstr(data,
|
||||
r.pricing_data)
|
||||
amt = 0.0
|
||||
for p in prices:
|
||||
p.cost = p.amount * r.discount
|
||||
return prices
|
||||
|
||||
async def charging(sor, ppid, data):
|
||||
if ppid is None:
|
||||
e = Exception(f'ppid is None, {data=}')
|
||||
@ -357,6 +414,7 @@ order by b.enabled_date desc"""
|
||||
exception(f'{e}')
|
||||
raise Exception(e)
|
||||
data_value = config_data.get(k)
|
||||
data_value = data_mapping(d, k, data_value) #需要mapping的数据转换
|
||||
if data_value is None:
|
||||
e = f'数据({config_data})没有({k})数据'
|
||||
exception(e)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user