From 81e9ebc04191d29e1df0a0e083046aa2a0586e2a Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 24 Mar 2026 11:34:01 +0800 Subject: [PATCH] bugfix --- json/pricing_program_timing.json | 41 +++++++++++++++++++ pricing/init.py | 4 +- pricing/pricing.py | 35 ++++++++++++++-- wwwroot/download_pricing_pattern.dspy | 3 ++ wwwroot/get_platform_providers.dspy | 4 ++ wwwroot/load_pricing_data.ui | 31 ++++++++++++++ .../pricing_item/get_spec_fields_by_psid.dspy | 6 +++ wwwroot/upload_pricing_data.dspy | 6 +++ 8 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 wwwroot/download_pricing_pattern.dspy create mode 100644 wwwroot/get_platform_providers.dspy create mode 100644 wwwroot/load_pricing_data.ui create mode 100644 wwwroot/pricing_item/get_spec_fields_by_psid.dspy create mode 100644 wwwroot/upload_pricing_data.dspy diff --git a/json/pricing_program_timing.json b/json/pricing_program_timing.json index 4e19cd6..cac7763 100644 --- a/json/pricing_program_timing.json +++ b/json/pricing_program_timing.json @@ -17,6 +17,47 @@ "icon": "{{entire_url('/pricing/imgs/pricing_item.svg')}}", "subtable": "pricing_item" } + ], + "toolbar":{ + "tools":[ + { + "name": "download_pattern", + "label": "定价模版", + "selected_row": true, + "icon": "{{entire_url('/bricks/imgs/download.svg')}}" + }, + { + "name": "upload_pricing_data", + "label": "上传定价数据", + "icon": "{{entire_url('/bricks/imgs/upload.svg')}}" + } + ] + }, + "binds": [ + { + "wid": "self", + "event": "download_pattern", + "actiontype": "urlwidget", + "target": "self", + "options":{ + "params": { + "ppid": "{{params_kw.ppid}}" + }, + "url": "{{entire_url('../download_pricing_pattern.dspy')}}" + } + }, + { + "wid": "self", + "event": "upload_pricing_data", + "actiontype": "urlwidget", + "target": "self", + "options": { + "params": { + "ppid": "{{params_kw.ppid}}" + }, + "url": "{{entire_url('../uplaod_pricing_data.dspy')}}" + } + } ] } } diff --git a/pricing/init.py b/pricing/init.py index c7f7367..2878ef7 100644 --- a/pricing/init.py +++ b/pricing/init.py @@ -6,5 +6,7 @@ from ahserver.serverenv import ServerEnv def load_pricing(): env = ServerEnv() - env.write_patten = PricingProgram.write_patten + env.write_pricing_patten = PricingProgram.write_pricing_patten + env.load_pricing_data = PricingProgram.load_pricing_data + env.get_pricing_program = pricingProgram.get_pricing_program env.calculate_prices = PricingProgram.pricing diff --git a/pricing/pricing.py b/pricing/pricing.py index eb184d7..713ee7c 100644 --- a/pricing/pricing.py +++ b/pricing/pricing.py @@ -157,10 +157,39 @@ def check_value(field, spec_value, data_value): class PricingProgram: @staticmethod - async def load_pricing(ppid, webpath_xlsx): - pass + async def get_pricing_program(ppid): + env = ServerEnv() + async with get_sor_context(env, 'pricing') as sor: + recs = await sor.R('pricing_program', {'id': ppid}) + if recs: + return recs[0] + e = f'pricing_program(id={ppid}) not found' + raise e + e = f'read pricing_program(id={ppid}) failed') + raise e + @staticmethod - async def write_patten(request, ppid): + async def load_pricing_data(pptid, webpath_xlsx): + fs = FileStorage() + fp = fs.realPath(webpath_xlsx) + d = load_xlsx_pricing(fp) + async with get_sor_context(env, 'pricing') as sor: + ppts = await sor.R('pricing_program_timing', {'id': pptid}) + if ppts: + ppt = ppts[0] + ppt.pricing_data = yaml.dump(dd) + await sor.U('pricing_program_timing', { + 'id': ppt.id, + 'pricing_data': ppt.pricing_data + }) + return True + e = f'pricing_program_timing(id={pptid}) not found') + raise e + e = f'pricing_program_timing(id={pptid}) read failed') + raise e + + @staticmethod + async def write_pricing_patten(request, ppid): async with get_sor_context(request._run_ns, 'pricing') as sor: env = request._run_ns recs = await sor.R('pricing_program', {'id': ppid}) diff --git a/wwwroot/download_pricing_pattern.dspy b/wwwroot/download_pricing_pattern.dspy new file mode 100644 index 0000000..95f6508 --- /dev/null +++ b/wwwroot/download_pricing_pattern.dspy @@ -0,0 +1,3 @@ +debug(f'download_pricing_pattern.dspy{params_kw=}') +url = await write_patten(request, params_kw.ppid) +await redirect(url) diff --git a/wwwroot/get_platform_providers.dspy b/wwwroot/get_platform_providers.dspy new file mode 100644 index 0000000..b0b67fa --- /dev/null +++ b/wwwroot/get_platform_providers.dspy @@ -0,0 +1,4 @@ +ret = [{None:None}] +ret += await get_platform_providers() +return ret + diff --git a/wwwroot/load_pricing_data.ui b/wwwroot/load_pricing_data.ui new file mode 100644 index 0000000..06b4b74 --- /dev/null +++ b/wwwroot/load_pricing_data.ui @@ -0,0 +1,31 @@ +{% set pp = get_pricing_program(params_kw.ppid) %} +{ + "widgettype": "Form", + "options": { + "title": "{{pp.id}}", + "description": "{{pp.description}}", + "fields":[ + { + "name": "xlsx_file", + "label": "定价文件", + "uitype": "file", + "required": true + } + ] + }, + "binds": [ + { + "wid": "self", + "event": "submit", + "actiontype": "urlwidget", + "target": "self", + "options": { + "url": "{{entire_url('upload_pricing_data.dspy')}}", + "params": { + "pptid": "{{params_kw.id}}", + "ppid": "{{params_kw.ppid}}" + } + } + } + ] +} diff --git a/wwwroot/pricing_item/get_spec_fields_by_psid.dspy b/wwwroot/pricing_item/get_spec_fields_by_psid.dspy new file mode 100644 index 0000000..d3b904b --- /dev/null +++ b/wwwroot/pricing_item/get_spec_fields_by_psid.dspy @@ -0,0 +1,6 @@ +id = params_kw.id +async with get_sor_context(request._run_ns, 'pricing') as sor: + recs = await sor.R('pricing_spec', {'id': id}) + if len(recs): + return recs.spec_names +return [] diff --git a/wwwroot/upload_pricing_data.dspy b/wwwroot/upload_pricing_data.dspy new file mode 100644 index 0000000..bbf335e --- /dev/null +++ b/wwwroot/upload_pricing_data.dspy @@ -0,0 +1,6 @@ +debug(f'uplaod_pricing_data.dspy: {params_kw=}') +try: + x = await load_pricing_data(params_kw.pptid, xlsx_file) + return UiMessage(title='load pricing data', message='data load successful') +except Exception as e: + return UiError(title='load pricing data', message=f'data load failed({e})')