修复(履约绑定): 启动对账优先处理待收敛订单
This commit is contained in:
@@ -2432,6 +2432,100 @@ class TestBindingAndCompletion(_Base):
|
||||
assert event.detail_json["previousBindTaskId"] == pending_task.id
|
||||
assert event.detail_json["targetRoleName"] == "丛未停息的雨"
|
||||
|
||||
def test_startup_reconcile_prioritizes_role_ready_tasks(self):
|
||||
"""大量历史订单占用 limit 时,role_ready 自愈不能被饿死。"""
|
||||
older = self._allocated()
|
||||
older.source_order_item_id = "older-active-order"
|
||||
older.binding_status = "failed"
|
||||
older.execution_status = "manual_required"
|
||||
self.session.commit()
|
||||
|
||||
task = PlatformFulfillmentTask(
|
||||
source_system="order_site",
|
||||
source_order_id="priority-active-order",
|
||||
source_order_item_id="priority-active-order",
|
||||
source_fulfillment_id="priority-active-order",
|
||||
platform_order_id="PRIORITY-ACTIVE-ORDER",
|
||||
provider="91kaquan",
|
||||
shop_id="shop-1",
|
||||
shop_name="测试店",
|
||||
sku_code=INTERNAL_SKU,
|
||||
sku_name=INTERNAL_SKU,
|
||||
internal_sku_key=INTERNAL_SKU,
|
||||
quantity=1,
|
||||
order_amount_fen=9900,
|
||||
target_platform="douyu",
|
||||
scope="elite",
|
||||
commodity_mapping_id=older.commodity_mapping_id,
|
||||
commodity_id=older.commodity_id,
|
||||
required_points=older.required_points,
|
||||
customer_role_name="丛未停息的雨",
|
||||
account_id=older.account_id,
|
||||
lease_id=older.lease_id,
|
||||
binding_status="role_ready",
|
||||
execution_status="role_ready",
|
||||
exchange_status="not_started",
|
||||
source_snapshot_json={"order_no": "PRIORITY-ACTIVE-ORDER"},
|
||||
paid_at=NOW,
|
||||
created_at=NOW,
|
||||
updated_at=NOW,
|
||||
)
|
||||
self.session.add(task)
|
||||
self.session.flush()
|
||||
account = self.session.get(Account, task.account_id)
|
||||
account.game_name = "丛未停息的雨"
|
||||
account.game_channel = "手Q · 苹果(iOS)"
|
||||
account.role_bind_status = "bound"
|
||||
pending_task = DouyuTask(
|
||||
batch_id="priority-stale-pending",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
result={
|
||||
"role_name": "TuT小玉",
|
||||
"baseline_role_name": "真心似有若无",
|
||||
"bind_ready_for_confirm": True,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "role_ready",
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(pending_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = pending_task.id
|
||||
observation = DouyuTask(
|
||||
batch_id="priority-confirmed-observation",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="query_game_name",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
platform_task_id=None,
|
||||
result={
|
||||
"act_alias": "20260120QYOOB",
|
||||
"action_act_aliases": ["20260120QYOOB"],
|
||||
"role_name": "丛未停息的雨",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "苹果(iOS)",
|
||||
"is_bound_act": True,
|
||||
"bind_confirmed": True,
|
||||
"bind_phase": "confirmed",
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(observation)
|
||||
self.session.commit()
|
||||
|
||||
reconciled = service.reconcile_binding_observations(self.session, limit=1)
|
||||
|
||||
self.session.refresh(task)
|
||||
assert reconciled == 1
|
||||
assert task.binding_status == "bound"
|
||||
assert task.execution_status == "bound"
|
||||
assert task.bind_task_id == observation.id
|
||||
|
||||
def test_startup_recovers_lost_confirm_callback(self):
|
||||
"""确认任务已成功落库但回调丢失时,启动对账能收敛为 bound。"""
|
||||
task = self._allocated()
|
||||
|
||||
Reference in New Issue
Block a user