积分消耗明细改版V1

This commit is contained in:
2026-08-12 11:49:53 +08:00
parent e3719eae09
commit eb7c60684e
39 changed files with 648 additions and 975 deletions
@@ -38,7 +38,7 @@ from app.services.redis_registry_service import (
utc_now,
)
from app.services.celery_runtime.runtime_service import CeleryRuntimeLease, RuntimeIdentity, runtime_lock_values
from app.services.llm_billing import LlmBillingContext, LlmPreDeductValidation, get_llm_ledger_states
from app.services.llm_billing import LlmBillingContext, LlmChargeValidation, get_llm_ledger_states
from app.tasks.celery_app import celery_app
logger = logging.getLogger("video_gen")
@@ -92,7 +92,7 @@ def _step_llm_billing_context(step: ModuleGenerationStep) -> LlmBillingContext:
source_step_id=str(step.id),
source_step_code=str(step.step_code),
related_id=str(step.id),
description_prefix="模块AI提词优化",
description_prefix="模块AI提词优化",
trace_id=f"module-recovery:{step.id}:attempt:{max(1, int(step.version or 1))}",
)
@@ -100,24 +100,24 @@ def _step_llm_billing_context(step: ModuleGenerationStep) -> LlmBillingContext:
async def _load_step_billing_validations(
db: AsyncSession,
steps: Iterable[ModuleGenerationStep],
) -> dict[str, LlmPreDeductValidation]:
) -> dict[str, LlmChargeValidation]:
step_list = list(steps)
if not step_list:
return {}
contexts = {str(step.id): _step_llm_billing_context(step) for step in step_list}
# 固定预扣已经在 API 层完成;恢复任务只认同一业务 attempt 的账务执行记录,
# 不再读取旧 SystemConfig 冻结配置;缺少固定预扣记录时直接终止恢复。
# 场景积分消费已经在 API 层完成;恢复任务只认同一业务 attempt 的账务执行记录,
# 不再读取旧 SystemConfig 冻结配置;缺少场景积分消费记录时直接终止恢复。
ledger_states = await get_llm_ledger_states(db, contexts.values())
output: dict[str, LlmPreDeductValidation] = {}
output: dict[str, LlmChargeValidation] = {}
for step_id, ctx in contexts.items():
ledger = ledger_states.get(
ctx.pre_deduct_biz_key,
LlmPreDeductValidation(False, 0.0, LlmBillingLedgerState.MISSING, "ledger_not_loaded"),
ctx.charge_biz_key,
LlmChargeValidation(False, 0.0, LlmBillingLedgerState.MISSING, "ledger_not_loaded"),
)
if ledger.state == LlmBillingLedgerState.ACTIVE:
output[step_id] = ledger
elif ledger.state == LlmBillingLedgerState.MISSING:
output[step_id] = LlmPreDeductValidation(
output[step_id] = LlmChargeValidation(
False,
0.0,
LlmBillingLedgerState.INVALID,