This commit is contained in:
27942
2026-02-27 20:31:56 +08:00
parent 697616b4e5
commit c77fb302d2
3 changed files with 19 additions and 4 deletions

View File

@@ -69,6 +69,7 @@ def task_list(request):
validated = ser.validated_data.copy()
account_id = validated.pop("id", None) or validated.pop("account_id", None)
boss_id = (validated.pop("boss_id", "") or "").strip()
# form-data 可能把数字传成字符串
if account_id is not None:
try:
@@ -92,6 +93,18 @@ def task_list(request):
account_name = account.browser_name
req.worker_id = target_worker_id
req.account_name = account_name
# 指定 boss_id 时,按 BOSS 直聘用户 ID 查账号
elif boss_id:
account = BossAccount.objects.filter(boss_id=boss_id).first()
if not account:
return api_error(
http_status.HTTP_404_NOT_FOUND,
f"未找到 boss_id={boss_id} 的账号",
)
target_worker_id = account.worker_id
account_name = account.browser_name
req.worker_id = target_worker_id
req.account_name = account_name
if not target_worker_id and account_name:
target_worker_id = worker_manager.find_worker_by_account(account_name)
@@ -103,7 +116,7 @@ def task_list(request):
req.worker_id = target_worker_id
if not target_worker_id:
return api_error(http_status.HTTP_400_BAD_REQUEST, "请指定 id、worker_id 或 account_name")
return api_error(http_status.HTTP_400_BAD_REQUEST, "请指定 id、boss_id、worker_id 或 account_name")
if not worker_manager.is_online(target_worker_id):
return api_error(http_status.HTTP_503_SERVICE_UNAVAILABLE, f"Worker {target_worker_id} 不在线")

View File

@@ -39,6 +39,7 @@ class TaskCreateSerializer(serializers.Serializer):
task_type = serializers.CharField(max_length=64)
id = serializers.IntegerField(required=False, allow_null=True, default=None) # 账号 ID
account_id = serializers.IntegerField(required=False, allow_null=True, default=None) # 同上,别名
boss_id = serializers.CharField(max_length=64, required=False, allow_blank=True, default="") # BOSS 直聘用户 ID按此查账号
worker_id = serializers.CharField(max_length=64, required=False, allow_blank=True, default="")
account_name = serializers.CharField(max_length=128, required=False, allow_blank=True, default="")
params = serializers.JSONField(required=False, default=dict)