fix(platform): 支持保留账号刷新绑定二维码
This commit is contained in:
@@ -2000,6 +2000,84 @@ class TestBindingAndCompletion(_Base):
|
|||||||
assert detail["task"]["bindTask"]["roleName"] == "测试角色"
|
assert detail["task"]["bindTask"]["roleName"] == "测试角色"
|
||||||
assert notified == [task.id]
|
assert notified == [task.id]
|
||||||
|
|
||||||
|
def test_refresh_qr_reuses_unexpired_qr_and_keeps_account(self):
|
||||||
|
task = self._allocated()
|
||||||
|
account_id = int(task.account_id or 0)
|
||||||
|
bind_task = DouyuTask(
|
||||||
|
batch_id="bind-valid-qr",
|
||||||
|
account_id=account_id,
|
||||||
|
account_assigned_to=self.admin_id,
|
||||||
|
task_type="get_bind_qr",
|
||||||
|
handbook_scope="elite",
|
||||||
|
status="success",
|
||||||
|
result={
|
||||||
|
"url": "https://example.com/current-qr",
|
||||||
|
"qr_expires_at": (NOW + timedelta(minutes=5)).isoformat(),
|
||||||
|
},
|
||||||
|
created_by=self.admin_id,
|
||||||
|
)
|
||||||
|
self.session.add(bind_task)
|
||||||
|
self.session.flush()
|
||||||
|
task.bind_task_id = bind_task.id
|
||||||
|
task.binding_status = "qr_pending"
|
||||||
|
task.execution_status = "waiting_bind"
|
||||||
|
self.session.commit()
|
||||||
|
|
||||||
|
detail = asyncio.run(
|
||||||
|
service.start_binding(
|
||||||
|
self.session,
|
||||||
|
task_id=task.id,
|
||||||
|
current=self.admin,
|
||||||
|
force_refresh=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.session.refresh(task)
|
||||||
|
assert task.bind_task_id == bind_task.id
|
||||||
|
assert task.account_id == account_id
|
||||||
|
assert detail["task"]["bindTask"]["id"] == bind_task.id
|
||||||
|
|
||||||
|
def test_refresh_expired_qr_reuses_same_account(self, monkeypatch):
|
||||||
|
task = self._allocated()
|
||||||
|
account_id = int(task.account_id or 0)
|
||||||
|
old_bind_task = DouyuTask(
|
||||||
|
batch_id="bind-expired-qr",
|
||||||
|
account_id=account_id,
|
||||||
|
account_assigned_to=self.admin_id,
|
||||||
|
task_type="get_bind_qr",
|
||||||
|
handbook_scope="elite",
|
||||||
|
status="success",
|
||||||
|
result={
|
||||||
|
"url": "https://example.com/expired-qr",
|
||||||
|
"qr_expires_at": (NOW - timedelta(minutes=1)).isoformat(),
|
||||||
|
},
|
||||||
|
created_by=self.admin_id,
|
||||||
|
)
|
||||||
|
self.session.add(old_bind_task)
|
||||||
|
self.session.flush()
|
||||||
|
task.bind_task_id = old_bind_task.id
|
||||||
|
task.binding_status = "qr_pending"
|
||||||
|
task.execution_status = "waiting_bind"
|
||||||
|
self.session.commit()
|
||||||
|
monkeypatch.setattr(service, "start_douyu_batch", lambda **_kwargs: None)
|
||||||
|
|
||||||
|
asyncio.run(
|
||||||
|
service.start_binding(
|
||||||
|
self.session,
|
||||||
|
task_id=task.id,
|
||||||
|
current=self.admin,
|
||||||
|
force_refresh=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.session.refresh(task)
|
||||||
|
assert task.account_id == account_id
|
||||||
|
assert task.bind_task_id != old_bind_task.id
|
||||||
|
refreshed_task = self.session.get(DouyuTask, task.bind_task_id)
|
||||||
|
assert refreshed_task is not None
|
||||||
|
assert refreshed_task.account_id == account_id
|
||||||
|
assert refreshed_task.task_type == "get_bind_qr"
|
||||||
|
|
||||||
def test_refresh_binding_ignores_legacy_same_role_pending(self):
|
def test_refresh_binding_ignores_legacy_same_role_pending(self):
|
||||||
task = self._allocated()
|
task = self._allocated()
|
||||||
bind_task = DouyuTask(
|
bind_task = DouyuTask(
|
||||||
|
|||||||
@@ -294,6 +294,11 @@ function canResetBinding(task: PlatformFulfillmentTask) {
|
|||||||
return task.bindingStatus === 'failed';
|
return task.bindingStatus === 'failed';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function canRefreshBindingQr(task: PlatformFulfillmentTask) {
|
||||||
|
if (!task.account) return false;
|
||||||
|
return !['role_ready', 'bound', 'completed', 'cancelled'].includes(task.executionStatus);
|
||||||
|
}
|
||||||
|
|
||||||
export default function PlatformFulfillmentPage() {
|
export default function PlatformFulfillmentPage() {
|
||||||
const user = getUser();
|
const user = getUser();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -917,9 +922,9 @@ export default function PlatformFulfillmentPage() {
|
|||||||
人工重试选号
|
人工重试选号
|
||||||
</Button>
|
</Button>
|
||||||
) : null}
|
) : null}
|
||||||
{['waiting_bind', 'binding_confirming'].includes(task.executionStatus) ? (
|
{canRefreshBindingQr(task) ? (
|
||||||
<Button size="small" icon={<ReloadOutlined />} onClick={() => void runTaskAction(() => platformFulfillmentApi.refreshBinding(task.id))}>
|
<Button size="small" icon={<ReloadOutlined />} onClick={() => void runTaskAction(() => platformFulfillmentApi.startBinding(task.id))}>
|
||||||
刷新绑定
|
刷新二维码
|
||||||
</Button>
|
</Button>
|
||||||
) : null}
|
) : null}
|
||||||
{task.executionStatus === 'role_ready' ? (
|
{task.executionStatus === 'role_ready' ? (
|
||||||
@@ -964,6 +969,14 @@ export default function PlatformFulfillmentPage() {
|
|||||||
释放并重新选号
|
释放并重新选号
|
||||||
</Button>
|
</Button>
|
||||||
) : null}
|
) : null}
|
||||||
|
{selected && canRefreshBindingQr(selected) ? (
|
||||||
|
<Button
|
||||||
|
icon={<ReloadOutlined />}
|
||||||
|
onClick={() => void runTaskAction(() => platformFulfillmentApi.startBinding(selected.id))}
|
||||||
|
>
|
||||||
|
刷新二维码
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
{selected.account &&
|
{selected.account &&
|
||||||
selected.executionStatus !== 'completed' &&
|
selected.executionStatus !== 'completed' &&
|
||||||
selected.executionStatus !== 'cancelled' &&
|
selected.executionStatus !== 'cancelled' &&
|
||||||
|
|||||||
Reference in New Issue
Block a user