fix(fulfillment): 对齐客户确认状态并展示角色接口日志
- 客户页 bindReadyForConfirm 与平台任务 role_ready 对齐 - 详情返回 douyu_role_api_logs 最近 40 条 - 详情页增加角色接口日志诊断表 - 补充客户确认、日志读取回归测试 - 文档记录 11.22 成功 HAR 与角色日志时间线
This commit is contained in:
@@ -557,3 +557,34 @@ GET bindInfo?actAlias=20260120QYOOB
|
||||
`order_site` 侧不需要改协议:客户页读 live-hub 的 `bindReadyForConfirm`,
|
||||
确认时调 live-hub 的 `customer-sessions/{id}/binding/confirm`。修复后两侧读同
|
||||
一层 `role_ready`,order_site 只是如实展示 live-hub 的结果。
|
||||
|
||||
### 9.10 角色接口日志表 `douyu_role_api_logs`
|
||||
|
||||
绑定问题分析不出来,不是没数据,而是数据没被接到工作台详情里:
|
||||
|
||||
- `douyu_tasks.result` 只保留最后一次归一化结果;
|
||||
- `platform_fulfillment_events` 只记状态事件;
|
||||
- 每个 alias、每次轮询、actBind 前后的原始响应在
|
||||
**`douyu_role_api_logs`**(`stage / source / act_alias / role_name /
|
||||
is_bound_act / change_role_wait_time / response_json`)。
|
||||
|
||||
订单 2632801844205946(任务 7871)的实际时间线:
|
||||
|
||||
```text
|
||||
06:26:29 bind_qr.preflight QYOOB 坏小萌瑶瑶 bindAct=1;cjm 空
|
||||
06:26:45 binding_poll.action_alias QYOOB 坏小萌瑶瑶 bindAct=1
|
||||
06:29:35 binding_poll.legacy_changed cjm 雨佑佑 bindAct=0, bindRole=1
|
||||
→ 绑定任务 success / role_ready
|
||||
→ 平台任务被 QYOOB-only 门禁卡在 qr_pending
|
||||
```
|
||||
|
||||
这组日志一眼就能看出“客户已经在 cjm 扫到新角色,QYOOB 还是旧角色”,
|
||||
而不是靠猜 `douyu_tasks.result`。
|
||||
|
||||
已做:
|
||||
|
||||
- `get_task_detail` 增加 `bindingLogs`(最近 40 条,按 task 的绑定任务关联);
|
||||
- 履约详情页增加“角色接口日志(诊断)”表:时间、阶段、通道、角色、
|
||||
bindAct、换绑等待、错误/消息;
|
||||
- 以后先看这张表,再看平台任务状态,不再把“绑定任务 role_ready”和
|
||||
“平台任务 qr_pending”混为一谈。
|
||||
|
||||
@@ -21,6 +21,7 @@ from web.backend.models import (
|
||||
AutomationJob,
|
||||
DouyuExternalOrder,
|
||||
DouyuGoodsSnapshot,
|
||||
DouyuRoleApiLog,
|
||||
DouyuTask,
|
||||
IntegrationOutbox,
|
||||
PlatformCommodityMapping,
|
||||
@@ -2913,6 +2914,57 @@ class TestBindingAndCompletion(_Base):
|
||||
assert evidence["targetRole"] == "同对角色"
|
||||
assert evidence["confirmable"] is False
|
||||
|
||||
def test_task_detail_includes_binding_role_api_logs(self):
|
||||
task = self._allocated()
|
||||
qr_task = DouyuTask(
|
||||
batch_id="role-log-qr",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
platform_task_id=task.id,
|
||||
result={"bind_ready_for_confirm": True, "bind_phase": "role_ready"},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(qr_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = qr_task.id
|
||||
task.binding_status = "role_ready"
|
||||
task.execution_status = "role_ready"
|
||||
self.session.add(
|
||||
DouyuRoleApiLog(
|
||||
account_id=task.account_id,
|
||||
task_id=qr_task.id,
|
||||
scope="elite",
|
||||
stage="binding_poll.legacy_changed",
|
||||
source="douyu_task.get_bind_qr",
|
||||
act_alias="cjm",
|
||||
role_name="雨佑佑",
|
||||
area_name="手Q",
|
||||
plat_name="苹果(iOS)",
|
||||
is_bound_act=False,
|
||||
is_bound_role=True,
|
||||
need_bind_act=False,
|
||||
need_bind_role=True,
|
||||
change_role_wait_time=0,
|
||||
response_json={"error": 0, "msg": "请求正常"},
|
||||
created_at=NOW,
|
||||
)
|
||||
)
|
||||
self.session.commit()
|
||||
|
||||
detail = service.get_task_detail(self.session, task.id)
|
||||
|
||||
assert detail["bindingLogs"]
|
||||
log = detail["bindingLogs"][0]
|
||||
assert log["stage"] == "binding_poll.legacy_changed"
|
||||
assert log["actAlias"] == "cjm"
|
||||
assert log["roleName"] == "雨佑佑"
|
||||
assert log["bindAct"] is False
|
||||
assert log["error"] == 0
|
||||
assert log["message"] == "请求正常"
|
||||
|
||||
def test_binding_evidence_does_not_treat_baseline_as_scanned(self):
|
||||
task = self._allocated()
|
||||
account = self.session.get(Account, task.account_id)
|
||||
|
||||
@@ -17,6 +17,7 @@ from ...models import (
|
||||
AccountLease,
|
||||
DouyuExternalOrder,
|
||||
DouyuGoodsSnapshot,
|
||||
DouyuRoleApiLog,
|
||||
DouyuTask,
|
||||
PlatformCommodityMapping,
|
||||
PlatformFulfillmentEvent,
|
||||
@@ -541,6 +542,14 @@ def get_task_detail(db: Session, task_id: int) -> dict[str, Any]:
|
||||
else {}
|
||||
)
|
||||
bind_task_ids: set[int] = set()
|
||||
if task.bind_task_id:
|
||||
bind_task_ids.add(int(task.bind_task_id))
|
||||
bind_task_ids.update(
|
||||
int(row.id)
|
||||
for row in db.query(DouyuTask.id)
|
||||
.filter(DouyuTask.platform_task_id == int(task.id))
|
||||
.all()
|
||||
)
|
||||
for event in events:
|
||||
detail = event.detail_json or {}
|
||||
raw_id = (
|
||||
@@ -562,8 +571,48 @@ def get_task_detail(db: Session, task_id: int) -> dict[str, Any]:
|
||||
if bind_task_ids
|
||||
else {}
|
||||
)
|
||||
role_logs = (
|
||||
db.query(DouyuRoleApiLog)
|
||||
.filter(DouyuRoleApiLog.task_id.in_(bind_task_ids))
|
||||
.order_by(DouyuRoleApiLog.id.desc())
|
||||
.limit(40)
|
||||
.all()
|
||||
if bind_task_ids
|
||||
else []
|
||||
)
|
||||
return {
|
||||
"task": _task_out(db, task, include_qr=True, include_exchange_task=True),
|
||||
"bindingLogs": [
|
||||
{
|
||||
"id": int(log.id),
|
||||
"taskId": int(log.task_id) if log.task_id else None,
|
||||
"stage": str(log.stage or ""),
|
||||
"source": str(log.source or ""),
|
||||
"actAlias": str(log.act_alias or ""),
|
||||
"apiVersion": str(log.api_version or ""),
|
||||
"roleName": str(log.role_name or ""),
|
||||
"areaName": str(log.area_name or ""),
|
||||
"platName": str(log.plat_name or ""),
|
||||
"bindAct": bool(log.is_bound_act),
|
||||
"bindRole": bool(log.is_bound_role),
|
||||
"needBindAct": bool(log.need_bind_act),
|
||||
"needBindRole": bool(log.need_bind_role),
|
||||
"changeRoleWaitTime": log.change_role_wait_time,
|
||||
"canChangeTime": log.can_change_time,
|
||||
"error": (
|
||||
log.response_json.get("error")
|
||||
if isinstance(log.response_json, dict)
|
||||
else None
|
||||
),
|
||||
"message": (
|
||||
log.response_json.get("msg")
|
||||
if isinstance(log.response_json, dict)
|
||||
else ""
|
||||
),
|
||||
"createdAt": log.created_at,
|
||||
}
|
||||
for log in role_logs
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"id": event.id,
|
||||
|
||||
@@ -2594,9 +2594,31 @@ export interface PlatformFulfillmentEvent {
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface PlatformFulfillmentBindingLog {
|
||||
id: number;
|
||||
taskId: number | null;
|
||||
stage: string;
|
||||
source: string;
|
||||
actAlias: string;
|
||||
apiVersion: string;
|
||||
roleName: string;
|
||||
areaName: string;
|
||||
platName: string;
|
||||
bindAct: boolean;
|
||||
bindRole: boolean;
|
||||
needBindAct: boolean;
|
||||
needBindRole: boolean;
|
||||
changeRoleWaitTime: number | null;
|
||||
canChangeTime: number | null;
|
||||
error: unknown;
|
||||
message: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface PlatformFulfillmentDetail {
|
||||
task: PlatformFulfillmentTask;
|
||||
events: PlatformFulfillmentEvent[];
|
||||
bindingLogs?: PlatformFulfillmentBindingLog[];
|
||||
}
|
||||
|
||||
export interface PlatformFulfillmentAllocationResult extends PlatformFulfillmentDetail {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Alert, Button, Card, Col, DatePicker, Descriptions, Drawer, Empty, Inpu
|
||||
import { CheckCircleOutlined, CopyOutlined, CreditCardOutlined, DownloadOutlined, GiftOutlined, LinkOutlined, QrcodeOutlined, ReloadOutlined, SettingOutlined, ShoppingOutlined, SyncOutlined, UndoOutlined, UserSwitchOutlined } from '@ant-design/icons';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import { douyuApi, platformFulfillmentApi } from '../api/modules';
|
||||
import type { DouyuGoodsItem, DouyuTaskItem, PlatformFulfillmentDetail, PlatformFulfillmentMapping, PlatformFulfillmentSettings, PlatformFulfillmentTask } from '../api/modules';
|
||||
import type { DouyuGoodsItem, DouyuTaskItem, PlatformFulfillmentBindingLog, PlatformFulfillmentDetail, PlatformFulfillmentMapping, PlatformFulfillmentSettings, PlatformFulfillmentTask } from '../api/modules';
|
||||
import ExchangeResultImage from '../components/ExchangeResultImage';
|
||||
import { copyImageToClipboard, fetchExchangeImageBlob, getExchangeImage, isExchangeTask } from '../utils/exchangeImage';
|
||||
import { TASK_STATUS_COLORS, TASK_STATUS_LABELS, taskQrUrl } from './douyu-tasks/config';
|
||||
@@ -1889,6 +1889,49 @@ export default function PlatformFulfillmentPage() {
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Card size="small" title="角色接口日志(诊断)">
|
||||
{detail?.bindingLogs?.length ? (
|
||||
<Table<PlatformFulfillmentBindingLog>
|
||||
size="small"
|
||||
rowKey="id"
|
||||
pagination={false}
|
||||
dataSource={detail.bindingLogs}
|
||||
scroll={{ x: 980, y: 260 }}
|
||||
columns={[
|
||||
{
|
||||
title: '时间',
|
||||
dataIndex: 'createdAt',
|
||||
width: 150,
|
||||
render: (value: string) => formatTime(value),
|
||||
},
|
||||
{ title: '阶段', dataIndex: 'stage', width: 170 },
|
||||
{ title: '通道', dataIndex: 'actAlias', width: 140 },
|
||||
{ title: '角色', dataIndex: 'roleName', width: 120 },
|
||||
{
|
||||
title: 'bindAct',
|
||||
dataIndex: 'bindAct',
|
||||
width: 76,
|
||||
render: (value: boolean) => (value ? '1' : '0'),
|
||||
},
|
||||
{
|
||||
title: '换绑等待',
|
||||
dataIndex: 'changeRoleWaitTime',
|
||||
width: 96,
|
||||
render: (value: number | null) => value ?? '-',
|
||||
},
|
||||
{
|
||||
title: '结果',
|
||||
dataIndex: 'message',
|
||||
render: (value: string, row: PlatformFulfillmentBindingLog) =>
|
||||
row.error === 0 ? 'OK' : `${String(row.error ?? '')} ${value || ''}`.trim(),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
) : (
|
||||
<Text type="secondary">暂无接口日志</Text>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Card size="small" title="精英宝典操作">
|
||||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
||||
<Text type="secondary">
|
||||
|
||||
Reference in New Issue
Block a user