feat: 管理员代工模式 — 前端权限放开 + 后端审计留痕

前端:
  - WorkspaceArea 新增 currentUserRole prop
  - isAssignee/canRecall: SUPER_ADMIN/SUPERVISOR 上帝视角直接放行
  - 管理员代操作时显示黄色提示条: 正在以管理员身份代[原负责人]操作
  - detail.vue: loadCurrentUser 提取并保存 user.role

后端:
  - _create_task_log 新增 task_assignee_id 参数
  - operator_id!=task_assignee_id 时自动拼接 [管理员xx代办操作]
  - 12处调用点全部传入 task_assignee_id
  - receive_task 位置赋值确认为 task.assignee_id(非 operator_id)
This commit is contained in:
2026-08-12 15:24:50 +08:00
parent 49cbf22854
commit 1fdc607c07
3 changed files with 47 additions and 9 deletions

View File

@ -223,13 +223,19 @@ async def _create_task_log(
action_type: str,
operator_id: str | None = None,
remark: str | None = None,
task_assignee_id: str | None = None,
) -> TaskLog:
"""创建任务操作日志"""
"""创建任务操作日志。自动检测管理员代办并拼接审计标记。"""
final_remark = remark or ""
# 管理员代办检测:操作人 ≠ 任务负责人 → 拼接审计追述
if operator_id and task_assignee_id and operator_id != task_assignee_id:
proxy_note = f" [管理员 {operator_id} 代办操作]"
final_remark = (final_remark + proxy_note).strip()
log = TaskLog(
task_id=task_id,
operator_id=operator_id,
action_type=action_type,
remark=remark,
remark=final_remark or None,
)
db.add(log)
return log
@ -349,7 +355,8 @@ async def end_task(
task.completed_at = now
await _create_task_log(db, task_id, action_type="end",
operator_id=operator_id, remark=f"分支「{task.task_name}」已终止(无下游)")
operator_id=operator_id, remark=f"分支「{task.task_name}」已终止(无下游)",
task_assignee_id=task.assignee_id)
# 🔧 位置回溯:分支结束后优先回溯到父任务负责人
await _recalc_product_location(db, task.product_id, task.id)
@ -414,7 +421,8 @@ async def recall_task(
task.status = TASK_STATUS_CANCELED
task.completed_at = now
await _create_task_log(db, task_id, action_type="recall", operator_id=operator_id,
remark=f"撤回转交「{task.task_name}」→ {task.assignee_id}")
remark=f"撤回转交「{task.task_name}」→ {task.assignee_id}",
task_assignee_id=task.assignee_id)
db.add(TaskRecord(task_id=task.id, remark=f"[撤回] 转交至 {task.assignee_id} 已撤回", images="[]"))
# 2. 生成接力新任务(以撤回节点为父,还给操作人)
@ -432,7 +440,8 @@ async def recall_task(
db.add(recovery)
await db.flush()
await _create_task_log(db, recovery.id, action_type="create", operator_id=operator_id,
remark=f"撤回接力:撤回「{task.task_name}」→ {task.assignee_id} 后重新指派给 {operator_id}")
remark=f"撤回接力:撤回「{task.task_name}」→ {task.assignee_id} 后重新指派给 {operator_id}",
task_assignee_id=recovery.assignee_id)
db.add(TaskRecord(task_id=recovery.id, remark=f"[重新接手] 撤回转交后系统自动生成接力节点", images="[]"))
# 3. 更新产品位置
@ -479,7 +488,8 @@ async def spawn_subtask(
db.add(TaskRecord(task_id=task.id, remark=data.remark or f"[派发协助] 分配给 {data.assignee_id}", images="[]"))
await _create_task_log(db, child.id, action_type="create", operator_id=operator_id,
remark=f"协助分支(由「{task.task_name}」派发,分配给 {data.assignee_id}")
remark=f"协助分支(由「{task.task_name}」派发,分配给 {data.assignee_id}",
task_assignee_id=child.assignee_id)
await db.commit()
await db.refresh(child)
return _to_response(child)
@ -546,6 +556,7 @@ async def receive_task(
action_type="receive",
operator_id=operator_id,
remark=remark or f"操作员确认接收任务「{task.task_name}",
task_assignee_id=task.assignee_id,
)
db.add(TaskRecord(task_id=task.id, remark=remark or f"[接收] 操作员已确认接收", images="[]"))
@ -609,6 +620,7 @@ async def reject_task(
action_type="reject",
operator_id=operator_id,
remark=f"品质驳回: {request.reason}",
task_assignee_id=task.assignee_id,
)
# --- 2. 确定返工任务的负责人(追溯上一道工序的转交人) ---
@ -657,6 +669,7 @@ async def reject_task(
action_type="create",
operator_id=operator_id,
remark=f"返工任务(驳回自「{task.task_name}」,原因: {request.reason}),分配给 {rework_assignee_id}",
task_assignee_id=rework_task.assignee_id,
)
# 🔔 通知:品质驳回
@ -745,6 +758,7 @@ async def transfer_task(
action_type="complete",
operator_id=operator_id,
remark=request.note or f"完成任务「{task.task_name}」,转交至下一道工序",
task_assignee_id=task.assignee_id,
)
db.add(TaskRecord(task_id=task.id, remark=request.note or f"[完工转交] 移交下一工序", images="[]"))
@ -801,6 +815,7 @@ async def transfer_task(
action_type="create",
operator_id=operator_id,
remark=request.note or f"由任务「{task.task_name}」裂变转交创建,分配给 {nt.assignee_id}",
task_assignee_id=nt.assignee_id,
)
# 🔔 通知:新任务派发
if nt.assignee_id:
@ -910,6 +925,7 @@ async def complete_task(
action_type="complete",
operator_id=request.operator_id,
remark=request.remark or f"完成任务: {task.task_name}",
task_assignee_id=task.assignee_id,
)
# --- 4. 可选:创建下一步任务(转交) ---
@ -941,6 +957,7 @@ async def complete_task(
action_type="create",
operator_id=request.operator_id,
remark=f"由任务「{task.task_name}」完成后转交创建",
task_assignee_id=next_task.assignee_id,
)
# 🔧 位置回溯:老接口也触发(父任务优先)
@ -1000,6 +1017,7 @@ async def create_subtask(
action_type="create",
operator_id=data.assignee_id,
remark=f"创建子任务「{data.task_name}」,父任务: 「{parent.task_name}",
task_assignee_id=subtask.assignee_id,
)
await db.commit()