From 885a52c7d884dc84a791e554f14c803bbe6afb75 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 5 Sep 2026 20:33:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(platform):=20apply=5Fmodel=5Fpricing?= =?UTF-8?q?=E5=B9=82=E7=AD=89=E4=BF=AE=E6=AD=A3(=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BA=A0=E6=AD=A3:=E6=97=B6=E5=BA=8F=E5=BA=94=E5=8F=AA?= =?UTF-8?q?=E4=B8=80=E6=9D=A1=E6=9C=89=E6=95=88=E8=A1=8C)=E2=80=94?= =?UTF-8?q?=E2=80=94=E5=86=85=E5=AE=B9=E6=97=A0=E5=8F=98=E5=8C=96=E8=B7=B3?= =?UTF-8?q?=E8=BF=87/=E5=90=8C=E6=97=A5=E5=90=AF=E7=94=A8=E5=8E=9F?= =?UTF-8?q?=E5=9C=B0=E6=9B=B4=E6=96=B0(=E9=98=B2=E9=9B=B6=E5=AE=BD?= =?UTF-8?q?=E6=AD=BB=E8=A1=8C)/=E4=BB=85=E5=8E=86=E5=8F=B2=E8=A1=8C?= =?UTF-8?q?=E6=8B=89=E9=93=BE;=E6=AD=A4=E5=89=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=A0=86=E5=9E=83=E5=9C=BE=E6=97=B6=E5=BA=8F?= =?UTF-8?q?=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pipeline_platform/platform_ability.py | 48 ++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/pipeline_platform/platform_ability.py b/pipeline_platform/platform_ability.py index 561b4ad..59fd7e0 100644 --- a/pipeline_platform/platform_ability.py +++ b/pipeline_platform/platform_ability.py @@ -720,16 +720,54 @@ async def _h_apply_model_pricing(sor, params, ctx): pp_desc = "定价出处:%s | 文档原文:%s" % (doc_url or "(未提供)", desc_quotes) now = time.strftime('%Y-%m-%d') if old_ppid: - # 幂等更新:新时序行(拉链——旧行 expired_date 截到今天) ppid = old_ppid + # 幂等核心(2026-09-05 用户纠正:时序应只有一条有效行,重复执行不得堆历史): + # 先取当前生效行比对内容—— + # 内容相同 → 跳过(不产生新时序行) + # 内容不同且生效行今天才启用 → 原地 UPDATE(同日替换无历史区间可保留, + # 拉链会产生 enabled==expired 的零宽死行,纯垃圾) + # 内容不同且生效行是历史日期 → 正常拉链(关旧行+插新行) + recs2 = await sor.sqlExe( + "SELECT id, pricing_data, enabled_date FROM pricing_program_timing " + "WHERE ppid=${p}$ AND expired_date='9999-12-31' " + "ORDER BY enabled_date DESC LIMIT 1", {"p": ppid}) + await sor.sqlExe("COMMIT", {}) + cur = recs2[0] if recs2 else None + same = False + if cur is not None: + try: + same = (yaml.safe_load(getattr(cur, 'pricing_data', '') or '{}') + == yaml.safe_load(yaml_str)) + except Exception: + same = (getattr(cur, 'pricing_data', '') or '') == yaml_str + await sor.sqlExe( + "UPDATE pricing_program SET description=${d}$ WHERE id=${i}$", + {"d": pp_desc[:1000], "i": ppid}) + await sor.sqlExe("COMMIT", {}) + if same: + results.append({"model": vmid, "ok": True, "ppid": ppid, + "action": "无变化(幂等跳过,未产生新时序行)", + "items": len(mitems), "factor": factor, + "dimensions": sorted(dims_all)}) + continue + if cur is not None and str(getattr(cur, 'enabled_date', ''))[:10] == now: + await sor.sqlExe( + "UPDATE pricing_program_timing SET pricing_data=${y}$, name=${n}$ " + "WHERE id=${i}$", + {"y": yaml_str, "n": "%s %s计价" % (vmid, factor), + "i": getattr(cur, 'id', '')}) + await sor.sqlExe("COMMIT", {}) + action = "原地更新(同日替换,不产生历史行)" + results.append({"model": vmid, "ok": True, "ppid": ppid, + "action": action, "items": len(mitems), + "factor": factor, "dimensions": sorted(dims_all)}) + continue + # 历史生效行 → 拉链 await sor.sqlExe( "UPDATE pricing_program_timing SET expired_date=${d}$ " "WHERE ppid=${p}$ AND expired_date='9999-12-31'", {"d": now, "p": ppid}) - await sor.sqlExe( - "UPDATE pricing_program SET description=${d}$ WHERE id=${i}$", - {"d": pp_desc[:1000], "i": ppid}) - action = "更新(新时序生效 %s)" % now + action = "更新(拉链:旧行截至今日,新时序生效 %s)" % now else: ppid = getID() await sor.C("pricing_program", {