Compare commits
5 Commits
2539bede3c
...
42c883fe7d
| Author | SHA1 | Date | |
|---|---|---|---|
| 42c883fe7d | |||
| ee25b8fd23 | |||
| d666bbd4ed | |||
| e707f3673d | |||
| 1e6c006360 |
@ -256,6 +256,14 @@ async def mom_outbound_webhook(
|
||||
product.status = "OUTBOUND"
|
||||
changed = True
|
||||
|
||||
# 🚚 同步出清厂内位置(与 _recalc_product_location 的「货发走就离场」对齐):
|
||||
# 本回调的匹配条件之一就是 current_location_id == "virtual_warehouse",
|
||||
# 即设备此刻还挂在仓库池里。既然 MOM 已确认发货,就不该再显示为厂内仓库/工位。
|
||||
# 置空后产品列表的「当前位置」显示为「—」。
|
||||
if product.current_location_id is not None:
|
||||
product.current_location_id = None
|
||||
changed = True
|
||||
|
||||
# 记录出库日志(优先"在库"任务,其次该产品最新任务)
|
||||
outbound_task = (
|
||||
await db.execute(
|
||||
|
||||
@ -29,21 +29,35 @@ PHASE_LABELS = {
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# 售后专属工序名 — 一旦选中即代表设备进入售后生命周期
|
||||
# 售后专属工序名
|
||||
# ============================================================
|
||||
STEP_SHIP_TEST = "发货测试" # 售后返修后的出货测试
|
||||
STEP_SHIP_TEST = "发货测试" # 出厂 / 发货前测试
|
||||
STEP_AFTER_SALES_REPAIR = "售后维修" # 售后返修本体
|
||||
|
||||
# 售后区独立成列所用的两个工序名(前端分列 / 大屏返厂统计仍以它为准)
|
||||
AFTER_SALES_ONLY_STEPS = frozenset({STEP_SHIP_TEST, STEP_AFTER_SALES_REPAIR})
|
||||
|
||||
# 🔧 工序语义细分(2026-09-17)——「售后专属」不等于「回流返厂」:
|
||||
# · 出厂质检(发货测试):设备可能压根没回厂,只是补做发货前测试。
|
||||
# 它【不】构成回流信号,选中它不应把设备永久烙进售后生命周期。
|
||||
# · 明确修机指令(售后维修):设备确实是回厂返修 → 判定回流。
|
||||
# 历史缺陷:两者混为一谈,导致「已出库 + 发货测试」被打上不可回退的
|
||||
# AFTER_SALES 烙印(售后死锁),而「已出库」的物理终态也被抹掉。
|
||||
OUTBOUND_QC_STEPS = frozenset({STEP_SHIP_TEST})
|
||||
AFTER_SALES_REPAIR_STEPS = frozenset({STEP_AFTER_SALES_REPAIR})
|
||||
|
||||
# ============================================================
|
||||
# 各阶段合法的工序名 / 宏观状态名
|
||||
# ============================================================
|
||||
|
||||
# ── 生产制造阶段(原有词表,一字未改,保证存量流程不受影响)──
|
||||
# ── 生产制造阶段 ──
|
||||
# 🔧 2026-09-17 补入「发货测试」:出厂质检现在被允许在生产阶段执行
|
||||
# (设备的 lifecycle_phase 不再因选中它而翻成售后)。若不补,
|
||||
# _enforce_step_isolation 会把「已出库设备的发货测试」直接 400 掉。
|
||||
PRODUCTION_TASK_STEPS = ("备货", "生产", "测试", "维修", "在库")
|
||||
PRODUCTION_OVERALL_STEPS = (
|
||||
"备货", "生产", "测试", "维修", "在库", "待仓库收货", "已入库", "已出库",
|
||||
STEP_SHIP_TEST,
|
||||
)
|
||||
|
||||
# ── 售后回流阶段:只保留「发货测试 / 售后维修 / 入库出库」──
|
||||
@ -99,12 +113,15 @@ def is_placeholder_step(step: str | None) -> bool:
|
||||
|
||||
|
||||
def resolve_phase_for_step(current_phase: str | None, step: str | None) -> str:
|
||||
"""选定售后专属工序 → 设备进入售后生命周期(单向,不可回退)
|
||||
"""选定【明确修机指令】→ 设备进入售后生命周期(单向,不可回退)
|
||||
|
||||
这是"无历史记录的老设备"进入售后阶段的唯一入口:它首次选定
|
||||
「发货测试 / 售后维修」时即被判定为售后回流设备。
|
||||
⚠️ 只有「售后维修」触发,出厂质检(发货测试)【不】触发。
|
||||
「已出库的设备补做发货测试」不代表它回厂返修;若在此烙印,
|
||||
设备会被永久打成售后(该标志单向不可回退),这就是售后死锁的第二个入口。
|
||||
|
||||
这是"无历史记录的老设备"进入售后阶段的入口:首次选定「售后维修」即判定回流。
|
||||
"""
|
||||
if step and step.strip() in AFTER_SALES_ONLY_STEPS:
|
||||
if step and step.strip() in AFTER_SALES_REPAIR_STEPS:
|
||||
return LIFECYCLE_AFTER_SALES
|
||||
return current_phase or LIFECYCLE_PRODUCTION
|
||||
|
||||
|
||||
@ -53,6 +53,14 @@ class ProductResponse(BaseModel):
|
||||
current_location_name: str | None = None
|
||||
macro_status: str | None = None # 🔧 后端预计算的任务树状态(免前端逐条展开)
|
||||
overall_status: str | None = None
|
||||
# 【当前工序】—— 只反映"此刻在做什么",绝不拿历史工序冒充。
|
||||
# · 有活跃主干任务(WIP/PENDING) → 该任务工序名
|
||||
# · 否则产品处于宏观终态(待仓库收货/已入库/在库/已出库) → 该终态(表达"货在哪")
|
||||
# · 否则(活已干完、只剩工序名残留)→ ""(前端显示「—」)
|
||||
# ⚠️ 必须与 overall_status 分开:ProductResponse.overall_status 会被"最新主干任务名"
|
||||
# 覆盖(见 product_service 的 overall_names),于是已 COMPLETED 的历史工序
|
||||
# (扫码出库 / 测试 / 发货测试…)会被当成"当前工序"长期展示。
|
||||
current_step: str = ""
|
||||
status: str
|
||||
# 🔧 生命周期阶段:PRODUCTION(生产制造/发货测试) | AFTER_SALES(出库后返厂售后维修)
|
||||
lifecycle_phase: str = "PRODUCTION"
|
||||
|
||||
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
from pydantic import BaseModel, Field, field_validator, model_validator
|
||||
|
||||
|
||||
# ============================================================
|
||||
@ -79,7 +79,13 @@ class TaskRejectRequest(BaseModel):
|
||||
class TaskTransferBranch(BaseModel):
|
||||
"""裂变分支"""
|
||||
task_name: str = Field(..., max_length=200, description="工序名称")
|
||||
assignees: list[str] = Field(..., min_length=1, description="接收人列表")
|
||||
assignees: list[str] = Field(
|
||||
default_factory=list, min_length=0,
|
||||
description=(
|
||||
"接收人列表。允许为空数组,但仅当 finish_directly=True 时合法——"
|
||||
"空分支不产生任何下游任务(见 TaskTransferRequest 的校验)。"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class TaskTransferRequest(BaseModel):
|
||||
@ -88,6 +94,29 @@ class TaskTransferRequest(BaseModel):
|
||||
next_task_name: str | None = Field(None, max_length=200, description="[旧版] 下一道工序名称")
|
||||
next_tasks: list[TaskTransferBranch] | None = Field(None, description="[新版] 多分支任务列表")
|
||||
note: str | None = Field(None, description="交接备注")
|
||||
finish_directly: bool = Field(
|
||||
False,
|
||||
description=(
|
||||
"直接完结:闭环当前任务但【不产生任何下游任务】。"
|
||||
"它只是一个任务闭环动作,【不改动】产品的 overall_status —— "
|
||||
"已出库的设备完结后依然是已出库(不入库,也不会变成「待仓库收货」)。"
|
||||
"权限:仅 SUPER_ADMIN / SUPERVISOR 可调用,其余角色 403。"
|
||||
"置 True 时忽略 next_tasks / next_assignees。"
|
||||
),
|
||||
)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _reject_silent_empty_branch(self):
|
||||
"""空 assignees 分支会让「转交」静默退化成「直接完结」——任务闭环了却没人接手,
|
||||
是个丢件级隐患。想直接完结必须显式传 finish_directly=true,不能靠漏填凑合。"""
|
||||
if self.finish_directly:
|
||||
return self
|
||||
if any(not b.assignees for b in (self.next_tasks or [])):
|
||||
raise ValueError(
|
||||
"分支 assignees 不能为空;若意图是「直接完结该任务」,"
|
||||
"请改为传 finish_directly=true"
|
||||
)
|
||||
return self
|
||||
|
||||
|
||||
class TaskRecordCreate(BaseModel):
|
||||
|
||||
@ -918,9 +918,13 @@ async def get_wip_matrix(
|
||||
- task_name: 按当前工序聚合(dimension_key 为工序名,附主负责人)
|
||||
"""
|
||||
from datetime import timezone as dt_timezone
|
||||
from sqlalchemy.orm import aliased
|
||||
from app.models.task import Task
|
||||
from app.models.product import Product
|
||||
|
||||
# 外层已 join 了 tasks,内层判活跃任务必须换别名,否则语义无歧义
|
||||
_ActiveTask = aliased(Task, name="active_task")
|
||||
|
||||
# 每台设备按主任务创建时间倒序,取第一条即「最新主任务」
|
||||
result = await db.execute(
|
||||
select(
|
||||
@ -936,6 +940,15 @@ async def get_wip_matrix(
|
||||
Product.overall_status,
|
||||
Product.status,
|
||||
Product.lifecycle_phase,
|
||||
# 🔧 该产品名下是否还有 ANY 活跃任务(含协助分支)——
|
||||
# 注意:这比下面的 is_active 更宽。is_active 只看"最新一条主干任务",
|
||||
# 而这里扫描该产品的全部任务,用于 is_terminal 兜底判定。
|
||||
# ⚠️ 必须用别名:外层 FROM 里已有一个 tasks,同名会让 SQLAlchemy
|
||||
# 自动关联掉内层 FROM 而报 "no FROM clauses"。别名后语义才无歧义。
|
||||
select(_ActiveTask.id).where(
|
||||
_ActiveTask.product_id == Product.id,
|
||||
_ActiveTask.status.in_(["WIP", "PENDING"]),
|
||||
).exists().label("has_any_active"),
|
||||
)
|
||||
.outerjoin(Task, Task.product_id == Product.id)
|
||||
.where(
|
||||
@ -952,7 +965,7 @@ async def get_wip_matrix(
|
||||
# 每台设备 → (spec, 当前工序/负责人, 当前负责人ID)
|
||||
device_cur: dict[str, tuple] = {}
|
||||
seen: set[str] = set()
|
||||
for pid, spec, product_name, task_name, assignee, tstatus, created, completed, loc, overall_status, product_status, lifecycle in rows:
|
||||
for pid, spec, product_name, task_name, assignee, tstatus, created, completed, loc, overall_status, product_status, lifecycle, has_any_active in rows:
|
||||
if pid in seen:
|
||||
continue
|
||||
seen.add(pid)
|
||||
@ -975,6 +988,13 @@ async def get_wip_matrix(
|
||||
or overall_status in ("待仓库收货", "已入库", "在库", "已出库")
|
||||
or str(product_status).upper() in ("ARCHIVED", "OUTBOUND")
|
||||
or task_name in ("扫码入库", "扫码出库")
|
||||
# 🔧 兜底(2026-09-17):设备名下【再无任何活跃任务】= 真的没活了 → 视同终结态。
|
||||
# 历史缺陷:生产设备被【直接完结】后 overall_status 停在工序名(如「测试」),
|
||||
# 既不满足上面任何一条,又因 is_terminal=False 对时间筛选完全免疫 ——
|
||||
# 于是它永远挂在看板上冒充"在制"(报表游魂)。
|
||||
# 补上这一条后,它照常接受 since~until 过滤,不再污染在制口径。
|
||||
# 仍保留原有的终结态判定(本条件是「或」,只会让更多设备被正确归类为终结)。
|
||||
or not has_any_active
|
||||
)
|
||||
if is_terminal:
|
||||
if anchor is not None and anchor.tzinfo is None:
|
||||
@ -1094,11 +1114,15 @@ async def get_wip_matrix_detail(
|
||||
按其在库三态(已完成/已入库/已出库)或工序名归类到 process。
|
||||
"""
|
||||
from datetime import timezone as dt_timezone
|
||||
from sqlalchemy.orm import aliased
|
||||
from app.models.task import Task
|
||||
from app.models.product import Product
|
||||
from app.models.holiday import Holiday
|
||||
from app.core.time_utils import get_beijing_time, to_beijing, working_duration_hours
|
||||
|
||||
# 与外层 join 的 tasks 区分开(理由见 get_wip_matrix)
|
||||
_ActiveTask = aliased(Task, name="active_task")
|
||||
|
||||
hres = await db.execute(select(Holiday.day))
|
||||
holidays = {r[0] for r in hres}
|
||||
|
||||
@ -1119,6 +1143,12 @@ async def get_wip_matrix_detail(
|
||||
Task.created_at,
|
||||
Task.completed_at,
|
||||
Task.received_at,
|
||||
# 🔧 与 get_wip_matrix 同口径:该产品名下是否还有 ANY 活跃任务
|
||||
# (同样必须用别名,理由见 get_wip_matrix 处注释)
|
||||
select(_ActiveTask.id).where(
|
||||
_ActiveTask.product_id == Product.id,
|
||||
_ActiveTask.status.in_(["WIP", "PENDING"]),
|
||||
).exists().label("has_any_active"),
|
||||
)
|
||||
.outerjoin(Task, Task.product_id == Product.id)
|
||||
.where(
|
||||
@ -1137,7 +1167,7 @@ async def get_wip_matrix_detail(
|
||||
matched: list[WipMatrixDetailRow] = []
|
||||
raw_names: set[str] = set()
|
||||
|
||||
for pid, serial, ext, mat_name, spec, loc, overall, pstatus, lifecycle, task_name, assignee, tstatus, created, completed, received in rows:
|
||||
for pid, serial, ext, mat_name, spec, loc, overall, pstatus, lifecycle, task_name, assignee, tstatus, created, completed, received, has_any_active in rows:
|
||||
if pid in seen:
|
||||
continue
|
||||
seen.add(pid)
|
||||
@ -1154,11 +1184,15 @@ async def get_wip_matrix_detail(
|
||||
is_active = tstatus in ("WIP", "PENDING")
|
||||
|
||||
# ── 动静分离:仅终结(收口/在库/出库)设备按 since~until 过滤;在制设备无条件全量 ──
|
||||
# ⚠️ 必须与 get_wip_matrix 一字不差同步,否则会出现
|
||||
# 「矩阵格子里有数、点进来下钻却是空的」。
|
||||
is_terminal = (not is_active) and (
|
||||
loc == "virtual_warehouse"
|
||||
or overall in ("待仓库收货", "已入库", "在库", "已出库")
|
||||
or str(pstatus).upper() in ("ARCHIVED", "OUTBOUND")
|
||||
or task_name in ("扫码入库", "扫码出库")
|
||||
# 🔧 兜底:名下再无任何活跃任务 → 视同终结态,接受时间筛选(防报表游魂)
|
||||
or not has_any_active
|
||||
)
|
||||
if is_terminal:
|
||||
if anchor is not None and anchor.tzinfo is None:
|
||||
|
||||
@ -673,6 +673,8 @@ async def get_all_products(
|
||||
|
||||
# 🔧 动态主干状态名:只从主干任务中获取最高优先级任务的 task_name(宏观状态名)
|
||||
overall_names: dict[uuid.UUID, str] = {}
|
||||
# 🔧 【当前工序】专用:仅「活跃主干任务」的工序名(见下方 main_stmt 循环填充)
|
||||
active_step_map: dict[uuid.UUID, str] = {}
|
||||
if product_ids:
|
||||
from sqlalchemy import and_, func as sa_func, case as sa_case
|
||||
main_where = and_(
|
||||
@ -694,7 +696,7 @@ async def get_all_products(
|
||||
.group_by(Task.product_id)
|
||||
).subquery("mp")
|
||||
main_stmt = (
|
||||
select(Task.product_id, Task.task_name)
|
||||
select(Task.product_id, Task.task_name, Task.status)
|
||||
.join(max_prio, and_(
|
||||
Task.product_id == max_prio.c.product_id,
|
||||
prio_expr == max_prio.c.prio,
|
||||
@ -706,6 +708,11 @@ async def get_all_products(
|
||||
main_result = await db.execute(main_stmt)
|
||||
for row in main_result:
|
||||
overall_names[row[0]] = row[1]
|
||||
# 🔧 供【当前工序】专用:只收【活跃】主干任务的工序名。
|
||||
# overall_names 保持原语义不动(它连 COMPLETED 的任务也收,
|
||||
# 是"最新主干任务名",被 overall_status 复用,改动影响面太大)。
|
||||
if row[2] in ("WIP", "PENDING"):
|
||||
active_step_map[row[0]] = row[1]
|
||||
|
||||
# 🔧 当前位置:汇总所有活跃任务(WIP/PENDING,不分主线/分支)的负责人,去重保序
|
||||
active_assignees_map: dict[uuid.UUID, list[str]] = {}
|
||||
@ -825,6 +832,28 @@ async def get_all_products(
|
||||
return "COMPLETED"
|
||||
return macro_map.get(p.id) or "PENDING"
|
||||
|
||||
# 宏观终态 —— 表达的是"货在哪",不是"在做什么"。
|
||||
# 这类值即使当前没有活跃任务也必须照常展示(业务要求保留物理标识)。
|
||||
_TERMINAL_OVERALL = ("待仓库收货", "已入库", "在库", "已出库")
|
||||
|
||||
def _resolve_current_step(p: Product) -> str:
|
||||
"""【当前工序】—— 只反映"此刻在做什么",绝不拿已完结的历史工序冒充。
|
||||
|
||||
· 有活跃主干任务(WIP/PENDING) → 该任务工序名
|
||||
· 否则产品处于宏观终态 → 该终态("货在哪",保留)
|
||||
· 否则(活已干完、只剩工序名残留)→ ""(前端显示「—」)
|
||||
|
||||
历史缺陷:ProductResponse.overall_status 会被"最新主干任务名"覆盖
|
||||
(见上方 overall_names),于是已 COMPLETED 的「扫码出库 / 测试 / 发货测试」
|
||||
会长期冒充"当前工序",误导管理者以为活还在干。
|
||||
"""
|
||||
raw = (p.overall_status or "").strip()
|
||||
if not raw:
|
||||
return ""
|
||||
if raw in _TERMINAL_OVERALL:
|
||||
return raw
|
||||
return active_step_map.get(p.id, "")
|
||||
|
||||
return [
|
||||
ProductResponse(
|
||||
id=p.id,
|
||||
@ -849,6 +878,7 @@ async def get_all_products(
|
||||
),
|
||||
macro_status=_resolve_macro_status(p),
|
||||
overall_status=overall_names.get(p.id) or p.overall_status,
|
||||
current_step=_resolve_current_step(p),
|
||||
status=p.status,
|
||||
lifecycle_phase=p.lifecycle_phase,
|
||||
created_at=p.created_at,
|
||||
|
||||
@ -11,6 +11,7 @@ from app.models.task import Task, TaskRecord, TASK_STATUS_PENDING, TASK_STATUS_W
|
||||
from app.models.notification import Notification, NOTIFY_TRANSFER, NOTIFY_REJECT
|
||||
from app.core.time_utils import get_beijing_time
|
||||
from app.core.lifecycle import (
|
||||
AFTER_SALES_REPAIR_STEPS,
|
||||
LIFECYCLE_AFTER_SALES,
|
||||
PRODUCTION_ONLY_STEPS,
|
||||
allowed_steps,
|
||||
@ -91,26 +92,61 @@ async def _recalc_product_location(
|
||||
result = await db.execute(stmt)
|
||||
main_task = result.scalar_one_or_none()
|
||||
|
||||
# 上面的排序把 WIP(3) > PENDING(2) 放最前,所以取到的这条即最高优先级:
|
||||
# 它是 WIP/PENDING 说明产品仍有活跃主线任务,否则视为闲置。
|
||||
has_active_main = main_task is not None and main_task.status in (
|
||||
TASK_STATUS_WIP, TASK_STATUS_PENDING,
|
||||
)
|
||||
|
||||
new_location = main_task.assignee_id if main_task else None
|
||||
|
||||
# 🚚 「货发走就离场」——已出库且闲置的设备,厂内不再有它的位置。
|
||||
# 直接完结后若继续停在最后经手人名下(或残留 virtual_warehouse),
|
||||
# 列表里会与「已出库」自相矛盾。置空后前端统一显示「—」。
|
||||
# ⚠️ 只清「已出库」:已入库 / 在库 的设备确实还在仓库里,位置必须保留。
|
||||
if product.overall_status == "已出库" and not has_active_main:
|
||||
new_location = None
|
||||
|
||||
if product.current_location_id != new_location:
|
||||
product.current_location_id = new_location
|
||||
await db.flush() # 唯一的落盘点
|
||||
|
||||
|
||||
# 绝对物理终态 — 描述「设备此刻物理上在哪」的宏观状态,由 MOM 仓储/发货回调驱动。
|
||||
# 接收 / 派发 / 转交任务时【禁止】用任务名覆写它们:否则「已出库」会被
|
||||
# 「发货测试」这类工序名静默抹掉,设备在按终态口径统计的报表里就不再是已出库
|
||||
# (WIP 矩阵因为优先看活跃任务而看不出问题,但全局概览 / 大屏会把它移出已完结)。
|
||||
#
|
||||
# ⚠️ 刻意不含「待仓库收货」:那是「车间完工待实收」的过渡态,设备随后仍会被
|
||||
# 重新派活,宏观状态理应随工序更新。
|
||||
PHYSICAL_TERMINAL_OVERALL = ("已入库", "在库", "已出库")
|
||||
|
||||
|
||||
def _is_physical_terminal(overall: str | None) -> bool:
|
||||
"""该宏观状态是否为「绝对物理终态」(不应被任务名覆写)"""
|
||||
return (overall or "").strip() in PHYSICAL_TERMINAL_OVERALL
|
||||
|
||||
|
||||
async def _mark_after_sales_if_reactivated(
|
||||
db: AsyncSession, product_id: uuid.UUID,
|
||||
steps: str | list[str | None] | None = None,
|
||||
) -> bool:
|
||||
"""出库后又被派发新任务 = 设备回流返厂 → 生命周期切到 AFTER_SALES。
|
||||
"""出库后又接到【明确修机指令】= 设备回流返厂 → 生命周期切到 AFTER_SALES。
|
||||
|
||||
判定依据:产品当前处于「已出库」终态(overall_status == '已出库' 或
|
||||
status == 'OUTBOUND'),却又产生了新的在制任务。
|
||||
判定依据(必须同时满足):
|
||||
1. 产品当前处于「已出库」终态(overall_status == '已出库' 或 status == 'OUTBOUND')
|
||||
2. 本次接到的工序是明确修机指令(售后维修)
|
||||
|
||||
⚠️ 出厂质检(发货测试)【不】触发。设备可能压根没回厂,只是补做发货前测试。
|
||||
历史缺陷:两者混为一谈,导致「已出库 + 发货测试」被打上不可回退的
|
||||
AFTER_SALES 烙印(售后死锁),且设备的物理终态「已出库」被工序名抹掉。
|
||||
|
||||
该标志单向:一旦进入 AFTER_SALES 不再回退,这样前端就能把
|
||||
生产阶段的「发货测试」与回流后的「售后维修」区分开。
|
||||
|
||||
调用时机必须早于调用方改写 overall_status,否则会漏判。
|
||||
|
||||
:param steps: 本次接到的工序名;转交场景可能多分支,故接受列表。
|
||||
返回是否发生了翻转。product 已在本 session 加载时 db.get 直接命中
|
||||
identity map,不产生额外查询。
|
||||
"""
|
||||
@ -118,6 +154,10 @@ async def _mark_after_sales_if_reactivated(
|
||||
if product is None or product.lifecycle_phase == LIFECYCLE_AFTER_SALES:
|
||||
return False
|
||||
|
||||
names = [steps] if isinstance(steps, str) else [s for s in (steps or []) if s]
|
||||
if not any(n.strip() in AFTER_SALES_REPAIR_STEPS for n in names):
|
||||
return False
|
||||
|
||||
is_outbound = (
|
||||
product.overall_status == "已出库"
|
||||
or (product.status or "").upper() == "OUTBOUND"
|
||||
@ -376,11 +416,18 @@ async def create_task(db: AsyncSession, data: TaskCreate) -> TaskResponse:
|
||||
product_result = await db.execute(select(Product).where(Product.id == data.product_id))
|
||||
product = product_result.scalar_one_or_none()
|
||||
if product:
|
||||
# 🔧 出库后再次派发任务 = 设备回流返厂 → 切到售后生命周期(须早于下方改写 overall_status)
|
||||
await _mark_after_sales_if_reactivated(db, data.product_id)
|
||||
# 🔧 出库后又接到【明确修机指令】= 设备回流返厂 → 切到售后生命周期
|
||||
# (须早于下方改写 overall_status)。出厂质检(发货测试)不触发。
|
||||
await _mark_after_sales_if_reactivated(db, data.product_id, data.task_name)
|
||||
# 🔧 选项隔离:售后回流设备禁止被排回「备货 / 生产」等前期工序(防伪造传参)
|
||||
_enforce_step_isolation(product, data.task_name, action="创建任务")
|
||||
if data.task_name and (not data.parent_task_id or data.task_type in ("TRANSFER", "RECOVERY")):
|
||||
# 🔒 只主线任务同步宏观状态;且【绝对物理终态保护】—— 设备已是
|
||||
# 已入库/在库/已出库 时禁止用任务名覆写,否则「已出库」会被工序名抹掉。
|
||||
if (
|
||||
data.task_name
|
||||
and (not data.parent_task_id or data.task_type in ("TRANSFER", "RECOVERY"))
|
||||
and not _is_physical_terminal(product.overall_status)
|
||||
):
|
||||
product.overall_status = "已入库" if "virtual_warehouse" in data.task_name else data.task_name
|
||||
# 🔧 双字段同步:overall_status 改动后必须对齐 status,
|
||||
# 否则出库回流设备的 status 会永远停在 OUTBOUND,污染统计口径
|
||||
@ -675,17 +722,27 @@ async def receive_task(
|
||||
product_result = await db.execute(select(Product).where(Product.id == task.product_id))
|
||||
product = product_result.scalar_one_or_none()
|
||||
if product:
|
||||
# 🔧 出库后任务被重新接收 = 设备回流返厂 → 切到售后生命周期(须早于下方改写 overall_status)
|
||||
await _mark_after_sales_if_reactivated(db, task.product_id)
|
||||
# 🔧 出库后任务被重新接收 = 设备回流返厂 → 切到售后生命周期
|
||||
# (须早于下方改写 overall_status)。出厂质检(发货测试)不触发。
|
||||
await _mark_after_sales_if_reactivated(
|
||||
db, task.product_id, task_name or task.task_name,
|
||||
)
|
||||
# 🔧 选项隔离:接收时选定的工序必须落在该产品当前生命周期阶段的合法集合内
|
||||
#(task_name 为 None 时表示本次未指定工序,跳过校验,不阻断 PC 端「直接接收」)
|
||||
_enforce_step_isolation(product, task_name, action="接收任务")
|
||||
if task.assignee_id:
|
||||
product.current_location_id = task.assignee_id
|
||||
if task_name and (
|
||||
not task.parent_task_id or task.task_type in ("TRANSFER", "RECOVERY")
|
||||
# 🔒 只主线任务同步宏观状态;且【绝对物理终态保护】——
|
||||
# 设备已是 已入库/在库/已出库 时禁止用任务名覆写。
|
||||
# 这是「发货测试 抹掉 已出库」的关键拦截点:若不拦,设备会在
|
||||
# 概览/大屏等按终态口径统计的报表里不再是已出库,而矩阵因优先看
|
||||
# 活跃任务看不出问题(跨报表口径就此打架)。
|
||||
if (
|
||||
task_name
|
||||
and (not task.parent_task_id or task.task_type in ("TRANSFER", "RECOVERY"))
|
||||
and not _is_physical_terminal(product.overall_status)
|
||||
):
|
||||
product.overall_status = task_name # 只主线任务同步宏观状态
|
||||
product.overall_status = task_name
|
||||
# 🔧 双字段同步:无条件对齐一次,顺带治愈历史残留
|
||||
# (如整体已是「发货测试」而 status 还停在 OUTBOUND)
|
||||
sync_product_status(product)
|
||||
@ -844,6 +901,12 @@ async def transfer_task(
|
||||
- 如果包含 'virtual_warehouse',则将 Product 的 current_location_id 设为 'virtual_warehouse'。
|
||||
- 为每一个 assignee_id(非 virtual_warehouse)新建一条 Task 记录(状态 PENDING)。
|
||||
|
||||
动作 2'(直接完结 finish_directly=True):
|
||||
- 不解析任何下家,分支强制为空,直接落入下方"无下家"兜底分支。
|
||||
- 用于「售后返厂直接发走 / 半成品被提走」这类**无需入库**的收官场景:
|
||||
工人不必再借道「入库(virtual_warehouse)」来关闭任务,
|
||||
从而避免把产品误标成「待仓库收货」并卡住 MOM 对账。
|
||||
|
||||
裂变逻辑:
|
||||
- 如果 len(next_assignees) > 1:多路裂变 → 所有新任务挂到当前任务下(parent_task_id = 当前任务ID)。
|
||||
- 如果当前任务本身就是子任务(有 parent_task_id):单路转交也挂到同一父任务下。
|
||||
@ -855,6 +918,18 @@ async def transfer_task(
|
||||
# 权限校验:本人 或 管理员/主管 可转交
|
||||
_check_permission(task.assignee_id, operator_id, operator_role)
|
||||
|
||||
# ── 🏁 直接完结:额外收紧为「仅管理员/主管」──
|
||||
# 这是【正向】拦截(非管理员一律拒绝),刻意不复用 _check_permission 的反向写法:
|
||||
# 后者在 operator_id 为空时会静默放行,而直接完结是不可逆的收官动作
|
||||
# (不产生下游任务、产品落终态),必须默认拒绝。
|
||||
# ⚠️ 判据只能是 operator_role —— 它来自签名保护的 JWT;
|
||||
# operator_id 是客户端可通过 ?operator_id= 自行填写的,不可作为权限依据。
|
||||
if request.finish_directly and not (operator_role and operator_role in ADMIN_ROLES):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="仅超管和主管有权限进行直接完结操作",
|
||||
)
|
||||
|
||||
# 校验:不能重复完成
|
||||
if task.status == TASK_STATUS_COMPLETED:
|
||||
raise HTTPException(
|
||||
@ -879,6 +954,16 @@ async def transfer_task(
|
||||
now = get_beijing_time()
|
||||
|
||||
# --- 动作 1:闭环当前节点 ---
|
||||
# 🔧 直接完结走独立文案:action_type 沿用 "complete"(不新增取值,避免扰动现有
|
||||
# 看板的完成数口径),仅在 remark 里区分,审计时可按文本筛出「直接完结」。
|
||||
finish_directly = bool(request.finish_directly)
|
||||
if finish_directly:
|
||||
log_remark = request.note or f"直接完结任务「{task.task_name}」(无下游,不入库)"
|
||||
record_remark = request.note or "[直接完结] 无下游任务,产品宏观状态保持不变"
|
||||
else:
|
||||
log_remark = request.note or f"完成任务「{task.task_name}」,转交至下一道工序"
|
||||
record_remark = request.note or "[完工转交] 移交下一工序"
|
||||
|
||||
task.status = TASK_STATUS_COMPLETED
|
||||
task.completed_at = now
|
||||
|
||||
@ -886,11 +971,11 @@ async def transfer_task(
|
||||
db, task_id,
|
||||
action_type="complete",
|
||||
operator_id=operator_id,
|
||||
remark=request.note or f"完成任务「{task.task_name}」,转交至下一道工序",
|
||||
remark=log_remark,
|
||||
task_assignee_id=task.assignee_id,
|
||||
)
|
||||
db.add(TaskRecord(task_id=task.id,
|
||||
remark=(request.note or f"[完工转交] 移交下一工序") + _admin_proxy_note(operator_id, task.assignee_id),
|
||||
remark=record_remark + _admin_proxy_note(operator_id, task.assignee_id),
|
||||
images="[]"))
|
||||
|
||||
# --- 动作 2:解析下家 & 裂变 ---
|
||||
@ -901,13 +986,11 @@ async def transfer_task(
|
||||
)
|
||||
product = product_result.scalar_one_or_none()
|
||||
|
||||
# 🔧 出库后又被转交出新任务 = 设备回流返厂 → 切到售后生命周期。
|
||||
# 必须在阶段校验之前执行,否则"已出库设备被转交到生产工序"会被误放行。
|
||||
if product:
|
||||
await _mark_after_sales_if_reactivated(db, task.product_id)
|
||||
|
||||
# 兼容新旧格式
|
||||
if request.next_tasks:
|
||||
# 🔧 直接完结:不解析任何下家,分支强制为空,直接命中下方"无下家"兜底分支。
|
||||
if finish_directly:
|
||||
branches: list[tuple[str | None, str]] = []
|
||||
elif request.next_tasks:
|
||||
branches = [
|
||||
(b.task_name, a)
|
||||
for b in request.next_tasks
|
||||
@ -922,6 +1005,17 @@ async def transfer_task(
|
||||
has_warehouse = any(a == VIRTUAL_WAREHOUSE for _, a in branches)
|
||||
real_branches = [(tn, a) for tn, a in branches if a != VIRTUAL_WAREHOUSE]
|
||||
|
||||
# 🔧 出库后又接到【明确修机指令】= 设备回流返厂 → 切到售后生命周期。
|
||||
# 必须在下方阶段校验之前执行,否则"已出库设备被转交到生产工序"会被误放行。
|
||||
# (故本调用安排在分支解析之后、_reject_cross_phase_steps 之前。)
|
||||
# ⚠️ 直接完结【不产生新任务】,不构成"回流返厂"信号,必须跳过:
|
||||
# 否则一台已出库设备的正常收官,会把产品误翻成售后机(该标志单向不可回退)。
|
||||
# ⚠️ 出厂质检(发货测试)同样不触发 —— 详见 _mark_after_sales_if_reactivated。
|
||||
if product and not finish_directly:
|
||||
await _mark_after_sales_if_reactivated(
|
||||
db, task.product_id, [tn for tn, _ in real_branches],
|
||||
)
|
||||
|
||||
# 🔧 选项隔离:售后回流设备不允许被转交到「备货 / 生产 / 测试 / 维修」。
|
||||
# 转交允许自由填写工序名(喷漆/老化…),故只精准拦跨阶段词,不用白名单。
|
||||
if product:
|
||||
@ -993,20 +1087,44 @@ async def transfer_task(
|
||||
task_id=nt.id,
|
||||
))
|
||||
|
||||
# --- 更新 Product 的 current_location_id ---
|
||||
# --- 更新 Product 的 current_location_id / overall_status ---
|
||||
# 🏁 直接完结【不改动 overall_status】:它只是一个「任务闭环动作」,
|
||||
# 不改变产品的物理状态。已出库的设备完结后依然是已出库,
|
||||
# 从而回归 WIP 矩阵的【已出库】列(无活跃任务 → 落终结态判定)。
|
||||
# 下方 has_warehouse / real_branches 两个分支对直接完结均为假,
|
||||
# overall_status 自然原样保留。
|
||||
if product:
|
||||
if has_warehouse and not real_branches:
|
||||
# 转入虚拟仓库池:位置一定改(下一手才能在这里看到并接手),
|
||||
# 但宏观状态要分情况 ——
|
||||
# · 绝对物理终态(已入库 / 在库 / 已出库):禁止改写成「待仓库收货」。
|
||||
# 已出库设备售后返修时选择【入库】是为了「放回池子让下一个人继续转」,
|
||||
# 改成「待仓库收货」会抹掉它的物理终态,且与 MOM 侧「已发货」的记录冲突
|
||||
# (MOM 认为货已出门,Track 却说「等仓库收货」,双方对不上账)。
|
||||
# 已入库 / 在库设备本就在仓库,再入库更不该回退成「待收货」。
|
||||
# · 普通生产设备(备货/生产/测试/维修…):维持原行为,正常置为「待仓库收货」。
|
||||
product.current_location_id = VIRTUAL_WAREHOUSE
|
||||
product.overall_status = "待仓库收货"
|
||||
if not _is_physical_terminal(product.overall_status):
|
||||
product.overall_status = "待仓库收货"
|
||||
elif real_branches:
|
||||
product.current_location_id = real_branches[0][1]
|
||||
if not task.parent_task_id or task.task_type in ("TRANSFER", "RECOVERY"):
|
||||
# 🔒 只主线任务同步宏观状态;且【绝对物理终态保护】——
|
||||
# 设备已是 已入库/在库/已出库 时禁止用任务名覆写,
|
||||
# 否则「已出库」会被「发货测试」这类工序名抹掉。
|
||||
if (
|
||||
(not task.parent_task_id or task.task_type in ("TRANSFER", "RECOVERY"))
|
||||
and not _is_physical_terminal(product.overall_status)
|
||||
):
|
||||
product.overall_status = real_branches[0][0]
|
||||
# 🔧 双字段同步:两个分支统一在这里对齐一次(原先只有入库分支硬编码
|
||||
# 🔧 双字段同步:各分支统一在这里对齐一次(原先只有入库分支硬编码
|
||||
# product.status="COMPLETED",普通转交分支完全没同步 → 残留 OUTBOUND)
|
||||
# 注意顺序:必须在上面的 overall_status 赋值【之后】,否则 status 同步到旧值。
|
||||
sync_product_status(product)
|
||||
|
||||
# 🔧 位置回溯:如果有新任务创建,优先新任务负责人;否则回溯到父任务
|
||||
# 「直接完结」(finish_directly) 与旧版空分支都落到这里:
|
||||
# current_location_id 回溯到最后一手经手人(业务确认:位置停在经手人合理)。
|
||||
# 注意它只改 location,不碰 overall_status,故上面的终态不会被覆盖。
|
||||
if not real_branches and not has_warehouse:
|
||||
await _recalc_product_location(db, task.product_id, task_id)
|
||||
|
||||
@ -1019,19 +1137,25 @@ async def transfer_task(
|
||||
await db.refresh(nt)
|
||||
created_task_responses.append(_to_response(nt))
|
||||
|
||||
assignee_list = ", ".join(a for _, a in real_branches) if real_branches else "仓库"
|
||||
location_info = ""
|
||||
if has_warehouse:
|
||||
location_info = ",产品已入库(virtual_warehouse)"
|
||||
# 🔧 直接完结没有下家,不能套用"已创建 N 个任务(接收人: 仓库)"的模板
|
||||
# (否则会拼出「已创建 0 个下一道工序任务「None」(接收人: 仓库)」这种误导文案)
|
||||
if finish_directly:
|
||||
message = f"任务「{task.task_name}」已直接完结(无下游任务,产品状态保持不变)"
|
||||
else:
|
||||
assignee_list = ", ".join(a for _, a in real_branches) if real_branches else "仓库"
|
||||
location_info = ""
|
||||
if has_warehouse:
|
||||
location_info = ",产品已入库(virtual_warehouse)"
|
||||
message = (
|
||||
f"任务「{task.task_name}」已完成,"
|
||||
f"已创建 {len(created_tasks)} 个下一道工序任务「{request.next_task_name}」"
|
||||
f"(接收人: {assignee_list}){location_info}"
|
||||
)
|
||||
|
||||
return TaskTransferResponse(
|
||||
completed_task=_to_response(refreshed_task),
|
||||
created_tasks=created_task_responses,
|
||||
message=(
|
||||
f"任务「{task.task_name}」已完成,"
|
||||
f"已创建 {len(created_tasks)} 个下一道工序任务「{request.next_task_name}」"
|
||||
f"(接收人: {assignee_list}){location_info}"
|
||||
),
|
||||
message=message,
|
||||
)
|
||||
|
||||
|
||||
@ -1101,8 +1225,11 @@ async def complete_task(
|
||||
# --- 4. 可选:创建下一步任务(转交) ---
|
||||
next_task = None
|
||||
if request.next_task_name and request.next_assignee_id:
|
||||
# 🔧 出库后又被转交出新任务 = 设备回流返厂 → 切到售后生命周期
|
||||
await _mark_after_sales_if_reactivated(db, task.product_id)
|
||||
# 🔧 出库后又接到【明确修机指令】= 设备回流返厂 → 切到售后生命周期
|
||||
# (出厂质检「发货测试」不触发)
|
||||
await _mark_after_sales_if_reactivated(
|
||||
db, task.product_id, request.next_task_name,
|
||||
)
|
||||
# 🚀 智能父节点继承算法
|
||||
# 主线任务转交 → 保持平级继承(主分支永远在一维主干上)
|
||||
# 协助分支转交 → 认当前任务为父(形成向外无限延伸的孙子节点树枝)
|
||||
|
||||
@ -19,7 +19,8 @@ import {
|
||||
} from "../../services/taskApi";
|
||||
import { useToast } from "../ui/Toast";
|
||||
import type { ProductScanResponse, TaskResponse } from "../../types/api";
|
||||
import { getStatusConfig } from "../../constants/task";
|
||||
import { getStatusConfig, isAdminRole } from "../../constants/task";
|
||||
import { useAuth } from "../../contexts/AuthContext";
|
||||
import ImageUploader from "../ui/ImageUploader";
|
||||
import { extractErrorMessage } from "../../utils/errorMessage";
|
||||
|
||||
@ -237,14 +238,45 @@ export const TransferModal = memo(function TransferModal({
|
||||
task: TaskResponse | null;
|
||||
submitting: boolean;
|
||||
onClose: () => void;
|
||||
onSubmit: (nextTaskName: string, assignees: string[], note: string) => void;
|
||||
onSubmit: (
|
||||
nextTaskName: string,
|
||||
assignees: string[],
|
||||
note: string,
|
||||
finishDirectly: boolean
|
||||
) => void;
|
||||
}) {
|
||||
const [nextTaskName, setNextTaskName] = useState("");
|
||||
const [assigneeInput, setAssigneeInput] = useState("");
|
||||
const [assignees, setAssignees] = useState<string[]>([]);
|
||||
const [useWarehouse, setUseWarehouse] = useState(false);
|
||||
// 🏁 直接完结:无下游、不入库。与「转交个人 / 入库」互斥
|
||||
const [finishDirectly, setFinishDirectly] = useState(false);
|
||||
const [note, setNote] = useState("");
|
||||
|
||||
// 🔄 每次打开都重置:TransferModal 被 memo 后常驻挂载(task 为 null 时只是 return null),
|
||||
// 状态会跨次打开残留,必须显式清零。
|
||||
// ⚠️ 必须放在 `if (!task) return null` 之前 —— 否则是条件提前返回后再调 Hook,
|
||||
// 违反 Rules of Hooks,task 从 null 变非 null 时 Hook 数量错位会直接崩。
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
setNextTaskName("");
|
||||
setAssigneeInput("");
|
||||
setAssignees([]);
|
||||
setUseWarehouse(false);
|
||||
setFinishDirectly(false);
|
||||
setNote("");
|
||||
}, [open]);
|
||||
|
||||
// 🔒 直接完结入口仅超管/主管【可见】:普通人看不到这个选项,而不是点了才被后端 403。
|
||||
// 后端那道硬拦截依然保留 —— 这里是体验层,角色来自客户端存储、可被伪造。
|
||||
const { user } = useAuth();
|
||||
const canFinishDirectly = isAdminRole(user?.role);
|
||||
|
||||
// 防御:非管理员若因任何原因残留了选中态,强制清掉,避免提交出 finish_directly
|
||||
useEffect(() => {
|
||||
if (!canFinishDirectly) setFinishDirectly(false);
|
||||
}, [canFinishDirectly]);
|
||||
|
||||
if (!task) return null;
|
||||
|
||||
function handleAddAssignee() {
|
||||
@ -271,44 +303,80 @@ export const TransferModal = memo(function TransferModal({
|
||||
|
||||
function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
const name = nextTaskName.trim();
|
||||
if (!name) return;
|
||||
|
||||
const finalAssignees = [...assignees];
|
||||
if (useWarehouse) {
|
||||
finalAssignees.push("virtual_warehouse");
|
||||
// 🏁 直接完结:不需要工序名与接收人,只闭环当前任务
|
||||
if (!finishDirectly) {
|
||||
const name = nextTaskName.trim();
|
||||
if (!name) return;
|
||||
|
||||
const finalAssignees = [...assignees];
|
||||
if (useWarehouse) {
|
||||
finalAssignees.push("virtual_warehouse");
|
||||
}
|
||||
if (finalAssignees.length === 0) return;
|
||||
|
||||
onSubmit(name, finalAssignees, note.trim(), false);
|
||||
} else {
|
||||
onSubmit("", [], note.trim(), true);
|
||||
}
|
||||
if (finalAssignees.length === 0) return;
|
||||
// ⚠️ 此处刻意不重置表单:请求是异步的,父组件要等 await 结束才关闭弹窗。
|
||||
// 若在此清空,提交等待期间标题/预览会从「直接完结」闪回普通转交。
|
||||
// 统一改由下方的「打开时重置」负责。
|
||||
}
|
||||
|
||||
onSubmit(name, finalAssignees, note.trim());
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
setNextTaskName("");
|
||||
setAssignees([]);
|
||||
setAssigneeInput("");
|
||||
setUseWarehouse(false);
|
||||
setFinishDirectly(false);
|
||||
setNote("");
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
setNextTaskName("");
|
||||
setAssignees([]);
|
||||
setAssigneeInput("");
|
||||
setUseWarehouse(false);
|
||||
setNote("");
|
||||
resetForm();
|
||||
onClose();
|
||||
}
|
||||
|
||||
// 🏁 直接完结时,下游相关字段全部失效(禁用而非清空,便于用户反悔切回)
|
||||
const downstreamDisabled = finishDirectly;
|
||||
// 互斥:勾选直接完结即撤掉入库,避免两个开关同时生效
|
||||
function handleToggleFinishDirectly(checked: boolean) {
|
||||
setFinishDirectly(checked);
|
||||
if (checked) setUseWarehouse(false);
|
||||
}
|
||||
|
||||
const allAssignees = [
|
||||
...assignees,
|
||||
...(useWarehouse ? ["virtual_warehouse"] : []),
|
||||
];
|
||||
|
||||
return (
|
||||
<Modal open={open} onClose={handleClose} title="完工转交 — 裂变到下道工序">
|
||||
<div className="mb-4 rounded-lg bg-green-50 px-3 py-2.5 text-sm text-green-700">
|
||||
<Modal
|
||||
open={open}
|
||||
onClose={handleClose}
|
||||
title={
|
||||
finishDirectly
|
||||
? "完工转交 — 🏁 直接完结(无下游,不入库)"
|
||||
: "完工转交 — 裂变到下道工序"
|
||||
}
|
||||
>
|
||||
<div
|
||||
className={`mb-4 rounded-lg px-3 py-2.5 text-sm ${
|
||||
finishDirectly
|
||||
? "bg-amber-50 text-amber-700"
|
||||
: "bg-green-50 text-green-700"
|
||||
}`}
|
||||
>
|
||||
<p className="font-medium">{task.task_name}</p>
|
||||
<p className="mt-0.5 text-xs text-green-500">
|
||||
完成任务并批量创建下一道工序任务,支持多路裂变分支
|
||||
<p
|
||||
className={`mt-0.5 text-xs ${
|
||||
finishDirectly ? "text-amber-500" : "text-green-500"
|
||||
}`}
|
||||
>
|
||||
{finishDirectly
|
||||
? "结束本任务且不创建下游任务,产品状态保持原样"
|
||||
: "完成任务并批量创建下一道工序任务,支持多路裂变分支"}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@ -324,7 +392,8 @@ export const TransferModal = memo(function TransferModal({
|
||||
onChange={(e) => setNextTaskName(e.target.value)}
|
||||
placeholder="如:组装、质检、包装"
|
||||
maxLength={200}
|
||||
className="w-full rounded-lg border border-gray-200 px-3 py-2 text-sm focus:border-green-400 focus:outline-none focus:ring-2 focus:ring-green-100"
|
||||
disabled={downstreamDisabled}
|
||||
className="w-full rounded-lg border border-gray-200 px-3 py-2 text-sm focus:border-green-400 focus:outline-none focus:ring-2 focus:ring-green-100 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:text-gray-400"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
@ -375,12 +444,13 @@ export const TransferModal = memo(function TransferModal({
|
||||
onKeyDown={handleAssigneeKeyDown}
|
||||
placeholder="输入接收人 ID,按 Enter 添加"
|
||||
maxLength={64}
|
||||
className="flex-1 rounded-lg border border-gray-200 px-3 py-2 text-sm focus:border-green-400 focus:outline-none focus:ring-2 focus:ring-green-100"
|
||||
disabled={downstreamDisabled}
|
||||
className="flex-1 rounded-lg border border-gray-200 px-3 py-2 text-sm focus:border-green-400 focus:outline-none focus:ring-2 focus:ring-green-100 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:text-gray-400"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleAddAssignee}
|
||||
disabled={!assigneeInput.trim()}
|
||||
disabled={!assigneeInput.trim() || downstreamDisabled}
|
||||
className="flex items-center gap-1 rounded-lg border border-gray-200 px-3 py-2 text-sm text-gray-600 hover:bg-gray-50 disabled:opacity-40"
|
||||
>
|
||||
<Plus className="h-3.5 w-3.5" />
|
||||
@ -390,11 +460,16 @@ export const TransferModal = memo(function TransferModal({
|
||||
</div>
|
||||
|
||||
{/* 虚拟入库 */}
|
||||
<label className="flex items-center gap-2 cursor-pointer select-none">
|
||||
<label
|
||||
className={`flex items-center gap-2 select-none ${
|
||||
downstreamDisabled ? "cursor-not-allowed opacity-40" : "cursor-pointer"
|
||||
}`}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={useWarehouse}
|
||||
onChange={(e) => setUseWarehouse(e.target.checked)}
|
||||
disabled={downstreamDisabled}
|
||||
className="h-4 w-4 rounded border-gray-300 text-purple-600 focus:ring-purple-500"
|
||||
/>
|
||||
<Warehouse className="h-4 w-4 text-purple-500" />
|
||||
@ -403,6 +478,32 @@ export const TransferModal = memo(function TransferModal({
|
||||
</span>
|
||||
</label>
|
||||
|
||||
{/* 🏁 直接完结 — 与转交/入库互斥。仅超管/主管可见 */}
|
||||
{canFinishDirectly && (
|
||||
<div>
|
||||
<label className="flex items-center gap-2 cursor-pointer select-none">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={finishDirectly}
|
||||
onChange={(e) => handleToggleFinishDirectly(e.target.checked)}
|
||||
className="h-4 w-4 rounded border-gray-300 text-amber-600 focus:ring-amber-500"
|
||||
/>
|
||||
<span className="text-sm font-medium text-gray-700">
|
||||
🏁 直接完结(无下游,不入库)
|
||||
</span>
|
||||
</label>
|
||||
{finishDirectly && (
|
||||
<p className="mt-1.5 rounded-lg bg-amber-50 px-3 py-2 text-xs text-amber-700">
|
||||
任务将直接完结,不创建任何下游任务。
|
||||
<span className="font-semibold">它只是一个任务闭环动作,不改动产品状态</span>
|
||||
:已出库的设备完结后依然是<span className="font-semibold">「已出库」</span>
|
||||
,回归 WIP 矩阵的已出库列;不会变成「待仓库收货」,也无需仓库扫码实收。
|
||||
适用于售后返厂直接发走、半成品被直接提走等无需入库的收官场景。
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 备注 */}
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium text-gray-700">
|
||||
@ -417,8 +518,21 @@ export const TransferModal = memo(function TransferModal({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 预览 — 🏁 直接完结走独立文案,不能套用「将创建 N 个任务」模板 */}
|
||||
{finishDirectly && (
|
||||
<div className="rounded-lg bg-amber-50 px-3 py-2.5 text-xs text-amber-700">
|
||||
<p className="font-medium">🏁 直接完结预览:</p>
|
||||
<p className="mt-1">
|
||||
任务「<span className="font-semibold">{task.task_name}</span>
|
||||
」将直接结束,
|
||||
<span className="font-semibold">不创建任何下游任务</span>
|
||||
;产品宏观状态与当前位置保持不变。
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 预览 */}
|
||||
{allAssignees.length > 0 && nextTaskName.trim() && (
|
||||
{!finishDirectly && allAssignees.length > 0 && nextTaskName.trim() && (
|
||||
<div className="rounded-lg bg-gray-50 px-3 py-2.5 text-xs text-gray-500">
|
||||
<p className="font-medium text-gray-600">裂变预览:</p>
|
||||
<p className="mt-1">
|
||||
@ -460,13 +574,17 @@ export const TransferModal = memo(function TransferModal({
|
||||
type="submit"
|
||||
disabled={
|
||||
submitting ||
|
||||
!nextTaskName.trim() ||
|
||||
allAssignees.length === 0
|
||||
(!finishDirectly &&
|
||||
(!nextTaskName.trim() || allAssignees.length === 0))
|
||||
}
|
||||
className="flex items-center gap-1.5 rounded-lg bg-green-600 px-4 py-2 text-sm font-medium text-white hover:bg-green-700 disabled:opacity-50"
|
||||
className={`flex items-center gap-1.5 rounded-lg px-4 py-2 text-sm font-medium text-white disabled:opacity-50 ${
|
||||
finishDirectly
|
||||
? "bg-amber-600 hover:bg-amber-700"
|
||||
: "bg-green-600 hover:bg-green-700"
|
||||
}`}
|
||||
>
|
||||
{submitting && <Loader2 className="h-3.5 w-3.5 animate-spin" />}
|
||||
确认转交
|
||||
{finishDirectly ? "🏁 确认直接完结" : "确认转交"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
@ -573,7 +691,8 @@ export default function TaskTreeViewer() {
|
||||
async function handleTransfer(
|
||||
nextTaskName: string,
|
||||
assignees: string[],
|
||||
note: string
|
||||
note: string,
|
||||
finishDirectly: boolean
|
||||
) {
|
||||
if (!modalTarget) return;
|
||||
setSubmitting(true);
|
||||
@ -582,7 +701,8 @@ export default function TaskTreeViewer() {
|
||||
modalTarget.task.id,
|
||||
assignees,
|
||||
nextTaskName,
|
||||
note || undefined
|
||||
note || undefined,
|
||||
finishDirectly
|
||||
);
|
||||
toast(result.message, "success");
|
||||
setModalTarget(null);
|
||||
|
||||
@ -200,8 +200,17 @@ export const AFTER_SALES_OVERALL_OPTIONS = [
|
||||
export function taskOptionsFor(
|
||||
phase: string | null | undefined,
|
||||
hasHistory = true,
|
||||
overallStatus?: string | null,
|
||||
): string[] {
|
||||
if (phase === LIFECYCLE_PHASE.AFTER_SALES) return AFTER_SALES_TASK_OPTIONS;
|
||||
// 🔧 出库设备与售后生命周期同等待遇(与 track-uniapp/src/utils/lifecycle.js 同步):
|
||||
// 后端为消除不可回退的售后烙印,已不再把「正常已出库做质检」的设备翻成
|
||||
// AFTER_SALES。若这里仍只认 phase,工人永远选不到「发货测试 / 售后维修」。
|
||||
if (
|
||||
phase === LIFECYCLE_PHASE.AFTER_SALES ||
|
||||
String(overallStatus || "").trim() === "已出库"
|
||||
) {
|
||||
return AFTER_SALES_TASK_OPTIONS;
|
||||
}
|
||||
if (!hasHistory) return [...PRODUCTION_TASK_OPTIONS, ...AFTER_SALES_ONLY_STEPS];
|
||||
return PRODUCTION_TASK_OPTIONS;
|
||||
}
|
||||
@ -217,6 +226,22 @@ export function overallOptionsFor(
|
||||
}
|
||||
|
||||
/** 列表筛选枚举 — 两阶段并集(用于筛选,不是录入项) */
|
||||
/**
|
||||
* 管理角色 — 必须与后端 task_service.ADMIN_ROLES 保持一致。
|
||||
*
|
||||
* ⚠️ 收敛到这里的理由:此前这段判断散落在多处(TaskFlowView / AdminProductsPage),
|
||||
* 而移动端那份只判了 SUPER_ADMIN、漏了 SUPERVISOR,导致主管被前端误挡。
|
||||
* 新增判断一律用 isAdminRole(),不要再手写 === 比较。
|
||||
*
|
||||
* 注意:这是【体验层】判断,角色来自客户端存储、可被伪造。
|
||||
* 真正的拦截在后端(transfer_task 对 finish_directly 有 403 硬校验)。
|
||||
*/
|
||||
export const ADMIN_ROLES = ["SUPER_ADMIN", "SUPERVISOR"] as const;
|
||||
|
||||
export function isAdminRole(role?: string | null): boolean {
|
||||
return !!role && (ADMIN_ROLES as readonly string[]).includes(role);
|
||||
}
|
||||
|
||||
export const ALL_OVERALL_OPTIONS = [
|
||||
...PRODUCTION_OVERALL_OPTIONS, ...AFTER_SALES_ONLY_STEPS,
|
||||
];
|
||||
|
||||
@ -114,15 +114,19 @@ export default function AdminTasksPage() {
|
||||
render: (p) => <div className="text-xs text-gray-500 truncate">{p.spec_model || p.material_name || p.material_id || "—"}</div>,
|
||||
},
|
||||
{
|
||||
key: "overall_status", label: "当前工序", colSpan: 1,
|
||||
filterType: "enum", getFilterValue: (p) => p.overall_status || "—",
|
||||
key: "current_step", label: "当前工序", colSpan: 1,
|
||||
// 🔧 改用后端派生的 current_step,而不是 overall_status ——
|
||||
// 后者的取值被"最新主干任务名"覆盖(含已 COMPLETED 的历史工序),
|
||||
// 会让「扫码出库 / 测试 / 发货测试」等已完结工序冒充"当前工序"。
|
||||
// current_step 只认活跃主干任务;无活跃任务时返回终态或空。
|
||||
filterType: "enum", getFilterValue: (p) => p.current_step || "—",
|
||||
// 🔧 筛选用两阶段并集:售后设备的「发货测试 / 售后维修」也要能被筛出来
|
||||
enumOptions: ALL_OVERALL_OPTIONS.map((v) => ({ value: v, label: v })),
|
||||
render: (p) => {
|
||||
const lb = lifecycleBadge(p.overall_status, p.lifecycle_phase);
|
||||
const lb = lifecycleBadge(p.current_step, p.lifecycle_phase);
|
||||
return (
|
||||
<span className="flex items-center gap-1.5">
|
||||
<span className="text-xs font-medium text-gray-700">{p.overall_status || "—"}</span>
|
||||
<span className="text-xs font-medium text-gray-700">{p.current_step || "—"}</span>
|
||||
{lb && (
|
||||
<span className={`shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-bold leading-none ${lb.className}`}>
|
||||
{lb.label}
|
||||
@ -528,12 +532,13 @@ export default function AdminTasksPage() {
|
||||
nextTaskName: string,
|
||||
assignees: string[],
|
||||
note: string,
|
||||
finishDirectly: boolean,
|
||||
) {
|
||||
if (!modalTarget) return;
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const result = await transferTask(
|
||||
modalTarget.task.id, assignees, nextTaskName, note || undefined,
|
||||
modalTarget.task.id, assignees, nextTaskName, note || undefined, finishDirectly,
|
||||
);
|
||||
toast(result.message, "success");
|
||||
const sn = modalTarget.task.product_sn || "";
|
||||
|
||||
@ -114,20 +114,25 @@ export async function rejectTask(
|
||||
/**
|
||||
* 完工裂变转交 — → COMPLETED,批量创建下家任务。
|
||||
* 对应后端 POST /api/v1/tasks/{taskId}/transfer
|
||||
*
|
||||
* finishDirectly=true 时走「直接完结」通道:next_tasks 留空 + finish_directly=true,
|
||||
* 后端据此跳过分支解析,只闭环任务【不产生下游任务】、且不改产品宏观状态
|
||||
* (不会把产品误标成「待仓库收货」)。用于售后返厂直接发走 / 半成品被提走等无需入库的收官场景。
|
||||
*/
|
||||
export async function transferTask(
|
||||
taskId: string,
|
||||
nextAssignees: string[],
|
||||
nextTaskName: string,
|
||||
note?: string
|
||||
note?: string,
|
||||
finishDirectly = false
|
||||
): Promise<TaskTransferResponse> {
|
||||
const payload: TaskTransferPayload = finishDirectly
|
||||
? { next_tasks: [], finish_directly: true, note }
|
||||
: { next_assignees: nextAssignees, next_task_name: nextTaskName, note };
|
||||
|
||||
const { data } = await api.post<TaskTransferResponse>(
|
||||
`/tasks/${taskId}/transfer`,
|
||||
{
|
||||
next_assignees: nextAssignees,
|
||||
next_task_name: nextTaskName,
|
||||
note,
|
||||
} satisfies TaskTransferPayload
|
||||
payload
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -17,6 +17,14 @@ export interface ProductResponse {
|
||||
current_location_name: string | null;
|
||||
macro_status: string | null;
|
||||
overall_status: string | null;
|
||||
/**
|
||||
* 【当前工序】— 只反映"此刻在做什么",绝不拿已完结的历史工序冒充。
|
||||
* · 有活跃主干任务(WIP/PENDING) → 该工序名
|
||||
* · 否则处于宏观终态(待仓库收货/已入库/在库/已出库) → 该终态
|
||||
* · 否则(活已干完)→ ""(列表显示「—」)
|
||||
* ⚠️ 不要用 overall_status 渲染该列:它会被"最新主干任务名"覆盖,含已 COMPLETED 的。
|
||||
*/
|
||||
current_step?: string;
|
||||
status: string;
|
||||
/** 🔧 生命周期阶段:PRODUCTION(生产制造/发货测试) | AFTER_SALES(出库后返厂售后维修) */
|
||||
lifecycle_phase?: LifecyclePhase;
|
||||
|
||||
@ -86,9 +86,23 @@ export interface TaskRejectPayload {
|
||||
images: string[];
|
||||
}
|
||||
|
||||
/** 裂变分支 — assignees 允许为空数组,但【仅当】finish_directly=true 时合法;
|
||||
* 否则后端 TaskTransferRequest 校验会直接 422 拒绝(防「转交」静默退化成「直接完结」的丢件隐患)。 */
|
||||
export interface TaskTransferBranch {
|
||||
task_name: string;
|
||||
assignees: string[];
|
||||
}
|
||||
|
||||
export interface TaskTransferPayload {
|
||||
next_assignees: string[];
|
||||
next_task_name: string;
|
||||
/** [旧版] 下一道工序接收人列表 — 与 next_tasks 二选一 */
|
||||
next_assignees?: string[];
|
||||
/** [旧版] 下一道工序名称 — 与 next_tasks 二选一 */
|
||||
next_task_name?: string;
|
||||
/** [新版] 多分支任务列表 */
|
||||
next_tasks?: TaskTransferBranch[];
|
||||
/** 🏁 直接完结:闭环当前任务但【不产生任何下游任务】,产品 overall_status 保持原样
|
||||
* (不入库 → 不会变成「待仓库收货」)。置 true 时后端忽略 next_tasks / next_assignees。 */
|
||||
finish_directly?: boolean;
|
||||
note?: string;
|
||||
}
|
||||
|
||||
|
||||
@ -38,10 +38,10 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="product && product.current_location_id === 'virtual_warehouse' && !hasMyActiveTask"
|
||||
class="warehouse-transfer-banner" @tap="openWarehouseTransfer">
|
||||
<text class="wt-icon">📤</text>
|
||||
<text class="wt-text">该产品在仓库中 — 点击此处转出并派发给指定人员</text>
|
||||
<view v-if="showDispatchBanner"
|
||||
class="warehouse-transfer-banner" @tap="openCreateFirstTask">
|
||||
<text class="wt-icon">{{ dispatchBannerIcon }}</text>
|
||||
<text class="wt-text">{{ dispatchBannerText }}</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -148,7 +148,7 @@
|
||||
</template>
|
||||
<template v-if="actionPopup.type === 'transfer'">
|
||||
<text class="popup-title">完工转交</text>
|
||||
<view class="field-label">接收人 <text class="required">*</text></view>
|
||||
<view class="field-label">接收人 / 处理方式 <text class="required">*</text></view>
|
||||
<view class="user-grid">
|
||||
<view v-for="u in userGridOptions" :key="u.id"
|
||||
:class="['user-grid-item', transferForm.selectedUserId === u.id ? 'user-grid-active' : '']"
|
||||
@ -156,10 +156,14 @@
|
||||
</view>
|
||||
<view class="field-label" style="margin-top:12px;">或</view>
|
||||
<view :class="['user-grid-item', transferForm.isWarehouse ? 'user-grid-active' : '']" style="width:100%;" @tap="toggleWarehouse">📦 入库 (virtual_warehouse)</view>
|
||||
<template v-if="showFinishDirect">
|
||||
<view :class="['user-grid-item', transferForm.isFinishDirect ? 'user-grid-active' : '']" style="width:100%;margin-top:8px;" @tap="toggleFinishDirect">🏁 直接完结 (不入库)</view>
|
||||
<text class="popup-hint">🏁 直接完结:结束本任务且不创建下游任务,不改动产品状态(已出库的设备完结后依然是「已出库」)。用于售后返厂直接发走、半成品被直接提走等无需入库的场景</text>
|
||||
</template>
|
||||
<view class="field-label" style="margin-top:12px;">交接备注 <text class="required">*</text></view>
|
||||
<textarea v-model="transferForm.note" class="popup-textarea" placeholder="请填写交接备注(必填)" :maxlength="500" />
|
||||
<view v-if="transferForm.isWarehouse || transferForm.selectedUserId" class="preview-hint">{{ transferForm.isWarehouse ? '产品将入库并从个人待办中移除' : '将创建新任务指派给 ' + (transferUserName || '—') }}</view>
|
||||
<view class="popup-btns"><button class="btn-cancel" @tap="closeActionPopup">取消</button><button class="btn-primary" :disabled="actionLoading || (!transferForm.isWarehouse && !transferForm.selectedUserId) || !transferForm.note.trim()" @tap="doTransfer">{{ actionLoading ? '提交中...' : (transferForm.isWarehouse ? '📦 确认入库' : '确认转交') }}</button></view>
|
||||
<view v-if="transferMode" class="preview-hint">{{ transferPreview }}</view>
|
||||
<view class="popup-btns"><button class="btn-cancel" @tap="closeActionPopup">取消</button><button class="btn-primary" :disabled="actionLoading || !transferMode || !transferForm.note.trim()" @tap="doTransfer">{{ actionLoading ? '提交中...' : transferSubmitLabel }}</button></view>
|
||||
</template>
|
||||
<template v-if="actionPopup.type === 'spawn'">
|
||||
<text class="popup-title">➕ 派发协助分支</text>
|
||||
@ -250,7 +254,7 @@ export default {
|
||||
actionPopup: { visible: false, type: "", task: null }, actionLoading: false, rejectReason: "", receiveRemark: "", receiveTaskName: "",
|
||||
// 📷 驳回异常图片(选填):与追加记录共用同一套选图/上传流程
|
||||
rejectForm: { images: [], pendingCount: 0 },
|
||||
transferForm: { selectedUserId: "", isWarehouse: false, note: "" },
|
||||
transferForm: { selectedUserId: "", isWarehouse: false, isFinishDirect: false, note: "" },
|
||||
spawnForm: { assignee_id: "", remark: "" },
|
||||
// 🛡️ 双重确认倒计时:避免误触
|
||||
confirming: "", // 当前倒计时中的操作 key('' = 无)
|
||||
@ -271,6 +275,64 @@ export default {
|
||||
userLabels() { return this.users.map(u => `${u.full_name} (${u.username})`); },
|
||||
canDeleteImage() { if (!this.recordPopup.task) return true; if (!this.currentUser) return true; const frozen = ["COMPLETED","REJECTED","ARCHIVED","CANCELED"]; if (frozen.includes(this.recordPopup.task.status)) return false; const assignee = this.recordPopup.task.assignee_id; return assignee == this.currentUserId || assignee == this.currentUsername || (this.currentUser && this.currentUser.id == assignee) || (this.currentUser && this.currentUser.username == assignee); },
|
||||
transferUserName() { const u = this.userOptions.find(u => u.id === this.transferForm.selectedUserId); return u ? u.name : ""; },
|
||||
// 🔒 直接完结入口仅超管/主管【可见】——普通人看不到,而不是点了才被后端 403。
|
||||
// ⚠️ 必须两个角色都判:本文件既有的 canEditOverallStatus 只判了 SUPER_ADMIN、
|
||||
// 漏了 SUPERVISOR,导致主管被前端误挡。此处与后端 ADMIN_ROLES 对齐。
|
||||
// 🔒 管理角色判定(超管 / 主管)—— 与后端 ADMIN_ROLES 对齐,作为各处权限判断的唯一入口
|
||||
isAdminUser() { const r = (this.currentUser && this.currentUser.role) || this.currentUserRole || ''; return r === 'SUPER_ADMIN' || r === 'SUPERVISOR'; },
|
||||
canFinishDirectly() { return this.isAdminUser; },
|
||||
// 📤 产品是否空闲:没有任何活跃的【主线】任务(WIP/PENDING)。
|
||||
// 只算主干(无父任务 或 TRANSFER/RECOVERY):协助分支(SPAWN)不阻塞派发,
|
||||
// 否则一个挂着的协助分支会把产品永久锁死。
|
||||
hasActiveMainTask() {
|
||||
const walk = (tasks) => {
|
||||
if (!tasks) return false;
|
||||
for (const t of tasks) {
|
||||
const isMain = !t.parent_task_id || t.task_type === 'TRANSFER' || t.task_type === 'RECOVERY';
|
||||
if (isMain && (t.status === 'WIP' || t.status === 'PENDING')) return true;
|
||||
if (walk(t.child_tasks)) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
return this.product ? walk(this.product.task_tree) : false;
|
||||
},
|
||||
// 📤 派发新任务入口的显示条件 —— 2026-09-17 解绑「派发权限」与「仓库位置」。
|
||||
//
|
||||
// 原实现硬性要求 current_location_id === 'virtual_warehouse',于是
|
||||
// 【直接完结】后的设备(位置停在最后经手人名下、又不在仓库池)派发入口
|
||||
// 彻底消失,产品变成再也无法流转的孤儿数据。
|
||||
// 但物理上除非设备报废,永远存在派发新任务的需求,故增加豁免:
|
||||
// · 在仓库且我本人没有待办 → 转出派发(原有行为,保持不动)
|
||||
// · 产品空闲(无活跃主线任务)且我是超管/主管 → 直接派发新任务
|
||||
// (已出库设备尤其如此:位置在工人名下也不该挡住派发)
|
||||
showDispatchBanner() {
|
||||
if (!this.product) return false;
|
||||
if (this.product.current_location_id === 'virtual_warehouse' && !this.hasMyActiveTask) return true;
|
||||
return this.isAdminUser && !this.hasActiveMainTask;
|
||||
},
|
||||
dispatchBannerText() {
|
||||
return this.product && this.product.current_location_id === 'virtual_warehouse'
|
||||
? '该产品在仓库中 — 点击此处转出并派发给指定人员'
|
||||
: '当前任务已完结 — 点击此处直接派发新任务';
|
||||
},
|
||||
dispatchBannerIcon() {
|
||||
return this.product && this.product.current_location_id === 'virtual_warehouse' ? '📤' : '🚀';
|
||||
},
|
||||
// 🛡️ 直接完结的【场景】门槛:角色够 + 产品确实是「已出库」。
|
||||
// 为什么必须卡状态:普通生产中的设备若被直接完结,产品既无下游任务、
|
||||
// 又不在仓库池中,会变成卡在工人名下的**孤儿数据**;而且售后往往要多步
|
||||
// 流转(发货测试 → 维修 → 入库 → …),提前完结会把任务流彻底切断。
|
||||
// 生产中的设备只能走「入库」或「转交个人」,回归正常流转。
|
||||
showFinishDirect() {
|
||||
return this.canFinishDirectly
|
||||
&& !!this.product
|
||||
&& this.product.overall_status === '已出库';
|
||||
},
|
||||
// 🏁 转交弹窗的三选一模式:'' = 未选 | 'user' 转交个人 | 'warehouse' 入库 | 'direct' 直接完结
|
||||
// direct 分支额外校验 角色 + 场景 双门槛,防御残留选中态把 finish_directly 发出去
|
||||
transferMode() { const f = this.transferForm; if (f.isFinishDirect && this.showFinishDirect) return 'direct'; if (f.isWarehouse) return 'warehouse'; return f.selectedUserId ? 'user' : ''; },
|
||||
transferSubmitLabel() { return { direct: '🏁 确认直接完结', warehouse: '📦 确认入库', user: '确认转交' }[this.transferMode] || '确认转交'; },
|
||||
transferPreview() { return { direct: '任务将直接完结,不创建下游任务;不改动产品状态(已出库的设备完结后依然是「已出库」)', warehouse: '产品将入库并从个人待办中移除', user: '将创建新任务指派给 ' + (this.transferUserName || '—') }[this.transferMode] || ''; },
|
||||
spawnUserName() { const u = this.userOptions.find(u => u.id === this.spawnForm.assignee_id); return u ? u.name : ""; },
|
||||
userGridOptions() { return (this.userOptions || []).map(u => ({ id: u.id, name: u.name })); },
|
||||
modeToggleLabel() { if (this.currentMode === 'workspace') return '📇 流转卡片'; if (this.currentMode === 'swipe') return '🌳 流转树'; return '🛠️ 工作区'; },
|
||||
@ -334,7 +396,13 @@ export default {
|
||||
return overallOptionsFor(this.product && this.product.lifecycle_phase, this.hasHistory);
|
||||
},
|
||||
availableTaskOptions() {
|
||||
return taskOptionsFor(this.product && this.product.lifecycle_phase, this.hasHistory);
|
||||
// 🔧 第三个参数 overall_status:已出库设备同样要走售后词表(发货测试 / 售后维修),
|
||||
// 否则出库后补做质检的工人永远选不到对应工序(鸡生蛋死锁)。
|
||||
return taskOptionsFor(
|
||||
this.product && this.product.lifecycle_phase,
|
||||
this.hasHistory,
|
||||
this.product && this.product.overall_status,
|
||||
);
|
||||
},
|
||||
},
|
||||
onLoad(options) { this.loadUsers(); this.loadCurrentUser(); const sn = options.serial || ""; if (sn) { this.doQuery(sn); return; } /* 🚀 兜底: 从 taskId 反查 product */ const tid = options.taskId || ""; if (tid) this.doQueryByTask(tid); },
|
||||
@ -392,9 +460,20 @@ export default {
|
||||
|
||||
onTaskNameChange(e) { const idx = e.detail.value; this.firstForm.taskNameIdx = idx; this.firstForm.task_name = this.availableTaskOptions[idx]; },
|
||||
onAssigneeChange(e) { const idx = e.detail.value; const u = this.users[idx]; if (u) { this.firstForm.assigneeIdx = idx; this.firstForm.assignee_id = u.username; this.firstForm.assigneeLabel = `${u.full_name} (${u.username})`; } },
|
||||
openCreateFirstTask() { this.isWarehouseTransfer = false; if (this.currentMode === 'tree') this.currentMode = 'workspace'; this.firstForm = { assignee_id: "", assigneeLabel: "", note: "" }; this.createFirstVisible = true; },
|
||||
// 🚀 打开「派发新任务」弹窗。标题由 isWarehouseTransfer 决定,
|
||||
// 而该标志【必须在此处按产品实际位置重新推导】——
|
||||
// 原先 openWarehouseTransfer 先置 true、再调用本方法被立刻重置为 false,
|
||||
// 导致弹窗标题永远显示「发起首道工序」,仓库转出场景的文案从未生效。
|
||||
openCreateFirstTask() {
|
||||
this.isWarehouseTransfer = !!(this.product && this.product.current_location_id === 'virtual_warehouse');
|
||||
if (this.currentMode === 'tree') this.currentMode = 'workspace';
|
||||
this.firstForm = { assignee_id: "", assigneeLabel: "", note: "" };
|
||||
this.createFirstVisible = true;
|
||||
},
|
||||
handleOverallBarClick() { if (!this.product.task_tree || !this.product.task_tree.length) { this.openCreateFirstTask(); } else if (this.canEditOverallStatus) { this.showStatusPicker = true; } else { uni.showToast({ title: '仅超级管理员或当前主线负责人可修改状态', icon: 'none', duration: 2500 }); } },
|
||||
openWarehouseTransfer() { this.isWarehouseTransfer = true; this.openCreateFirstTask(); },
|
||||
// 注:原 openWarehouseTransfer() 已移除 —— 它的 isWarehouseTransfer=true 会被
|
||||
// openCreateFirstTask 立刻覆盖(死代码)。现在 banner 直接调用 openCreateFirstTask,
|
||||
// 由后者按产品实际位置推导标题。
|
||||
async doCreateFirstTask() { this.firstSaving = true; try { await post("/tasks/", { product_id: this.product.id, task_name: "待确认", assignee_id: this.firstForm.assignee_id, notify_parent_on_complete: false, remark: this.firstForm.note.trim() || undefined }); if (this.product.current_location_id === 'virtual_warehouse') { try { await patch(`/products/${this.product.id}`, { current_location_id: this.firstForm.assignee_id }); } catch {} } uni.showToast({ title: "任务已派发,待接收", icon: "success" }); this.createFirstVisible = false; this.doQuery(this.product.serial_number); } catch {} finally { this.firstSaving = false; } },
|
||||
|
||||
// savedCount = 打开弹窗时已落库的图片张数。列表里 [0, savedCount) 是服务端已有的,
|
||||
@ -488,7 +567,7 @@ export default {
|
||||
if (type === "transfer" || type === "spawn") { uni.showLoading({ title: "加载数据..." }); try { if (!this.userOptions.length) await this.loadUsers(); this.processOptions = ["🏭 入库 (virtual_warehouse)", ...this.availableTaskOptions]; } finally { uni.hideLoading(); } }
|
||||
this.actionPopup = { visible: true, type, task }; this.rejectReason = ""; this.receiveRemark = ""; this.receiveTaskName = "";
|
||||
this.rejectForm = { images: [], pendingCount: 0 }; this.isUploading = false;
|
||||
this.transferForm = { selectedUserId: "", isWarehouse: false, note: "" };
|
||||
this.transferForm = { selectedUserId: "", isWarehouse: false, isFinishDirect: false, note: "" };
|
||||
this.spawnForm = { assignee_id: "", remark: "" };
|
||||
},
|
||||
handleViewRecords(task) { uni.navigateTo({ url: `/pages/scan/records?taskId=${task.id}` }); },
|
||||
@ -598,9 +677,28 @@ export default {
|
||||
// 驳回:reason 必填,images 选填(编号错误等场景允许空数组)
|
||||
async doReject() { if (this.isUploading) return; this.actionLoading = true; try { const opId = this.currentUsername || this.currentUserId; await post(`/tasks/${this.actionPopup.task.id}/reject?operator_id=${encodeURIComponent(opId)}`, { reason: this.rejectReason.trim(), images: this.rejectForm.images }); uni.showToast({ title: "已驳回", icon: "success" }); this.closeActionPopup(); this.doQuery(this.product.serial_number); } catch (e) { this.handleNetworkFailure(e, "驳回任务"); } finally { this.actionLoading = false; } },
|
||||
// 转交 — 互斥选择
|
||||
selectTransferUser(userId) { this.transferForm.selectedUserId = userId; this.transferForm.isWarehouse = false; },
|
||||
toggleWarehouse() { this.transferForm.isWarehouse = !this.transferForm.isWarehouse; if (this.transferForm.isWarehouse) this.transferForm.selectedUserId = ""; },
|
||||
async doTransfer() { this.actionLoading = true; try { const assignees = this.transferForm.isWarehouse ? ["virtual_warehouse"] : [this.transferForm.selectedUserId]; const taskName = this.transferForm.isWarehouse ? "🏭 入库 (virtual_warehouse)" : "待确认"; await post(`/tasks/${this.actionPopup.task.id}/transfer`, { next_tasks: [{ task_name: taskName, assignees }], note: this.transferForm.note.trim() || undefined }); uni.showToast({ title: this.transferForm.isWarehouse ? "已入库" : "转交成功", icon: "success" }); this.closeActionPopup(); this.doQuery(this.product.serial_number); } catch (e) { this.handleNetworkFailure(e, this.transferForm.isWarehouse ? "入库" : "转交"); } finally { this.actionLoading = false; } },
|
||||
selectTransferUser(userId) { this.transferForm.selectedUserId = userId; this.transferForm.isWarehouse = false; this.transferForm.isFinishDirect = false; },
|
||||
toggleWarehouse() { this.transferForm.isWarehouse = !this.transferForm.isWarehouse; if (this.transferForm.isWarehouse) { this.transferForm.selectedUserId = ""; this.transferForm.isFinishDirect = false; } },
|
||||
// 🏁 直接完结:与前两者互斥。不发往仓库 → 后端落入"无下家"分支,overall_status 原样保留
|
||||
toggleFinishDirect() { this.transferForm.isFinishDirect = !this.transferForm.isFinishDirect; if (this.transferForm.isFinishDirect) { this.transferForm.selectedUserId = ""; this.transferForm.isWarehouse = false; } },
|
||||
async doTransfer() {
|
||||
this.actionLoading = true;
|
||||
const { isWarehouse, isFinishDirect } = this.transferForm;
|
||||
try {
|
||||
const note = this.transferForm.note.trim() || undefined;
|
||||
// 🏁 直接完结:next_tasks 留空 + finish_directly=true,
|
||||
// 后端据此跳过分支解析,只闭环任务、不改产品宏观状态(不会变成"待仓库收货")
|
||||
const payload = isFinishDirect
|
||||
? { next_tasks: [], finish_directly: true, note }
|
||||
: { next_tasks: [{ task_name: isWarehouse ? "🏭 入库 (virtual_warehouse)" : "待确认", assignees: isWarehouse ? ["virtual_warehouse"] : [this.transferForm.selectedUserId] }], note };
|
||||
await post(`/tasks/${this.actionPopup.task.id}/transfer`, payload);
|
||||
uni.showToast({ title: isFinishDirect ? "已直接完结" : (isWarehouse ? "已入库" : "转交成功"), icon: "success" });
|
||||
this.closeActionPopup();
|
||||
this.doQuery(this.product.serial_number);
|
||||
} catch (e) {
|
||||
this.handleNetworkFailure(e, isFinishDirect ? "直接完结" : (isWarehouse ? "入库" : "转交"));
|
||||
} finally { this.actionLoading = false; }
|
||||
},
|
||||
// 派发协助分支
|
||||
async doSpawn() { this.actionLoading = true; try { const opId = this.currentUsername || this.currentUserId; await post(`/tasks/${this.actionPopup.task.id}/spawn?operator_id=${encodeURIComponent(opId)}`, { task_name: "待确认", assignee_id: this.spawnForm.assignee_id, remark: this.spawnForm.remark.trim() || undefined }); uni.showToast({ title: "协助分支已派发", icon: "success" }); this.closeActionPopup(); this.doQuery(this.product.serial_number); } catch (e) { this.handleNetworkFailure(e, "派发协助分支"); } finally { this.actionLoading = false; } },
|
||||
// 💬 留言板
|
||||
|
||||
@ -20,6 +20,16 @@ export const LIFECYCLE_PHASE = {
|
||||
export const STEP_SHIP_TEST = "发货测试";
|
||||
export const STEP_AFTER_SALES_REPAIR = "售后维修";
|
||||
|
||||
/**
|
||||
* 绝对物理终态之一:设备已发货出库。
|
||||
*
|
||||
* 🔧 出库设备也要按售后环节给选项:设备出库后仍可能被叫回来补做
|
||||
* 「发货测试 / 售后维修」,但后端已不再因「正常已出库做质检」而把
|
||||
* lifecycle_phase 翻成 AFTER_SALES(避免不可回退的售后烙印)。
|
||||
* 若选项渲染仍只认 phase,工人就永远选不到那两个工序 —— 鸡生蛋死锁。
|
||||
*/
|
||||
export const OUTBOUND_OVERALL = "已出库";
|
||||
|
||||
const AFTER_SALES_ONLY_STEPS = [STEP_SHIP_TEST, STEP_AFTER_SALES_REPAIR];
|
||||
|
||||
// ── 生产制造阶段合法工序(原有词表,一字未改)──
|
||||
@ -40,9 +50,22 @@ export const AFTER_SALES_OVERALL_OPTIONS = [
|
||||
* hasHistory = false(无任何历史任务的首次激活 / 老设备)时返回**并集**:
|
||||
* 这类设备既可能是新投产,也可能是直接返厂售后的老设备,让操作员自己声明。
|
||||
* 一旦选定售后专属工序,后端即把设备判为 AFTER_SALES,之后下拉自动收窄。
|
||||
*
|
||||
* @param phase lifecycle_phase
|
||||
* @param hasHistory 是否有历史任务
|
||||
* @param overallStatus 产品当前宏观状态 — 【已出库】同样走售后词表,见下方说明
|
||||
*/
|
||||
export function taskOptionsFor(phase, hasHistory = true) {
|
||||
if (phase === LIFECYCLE_PHASE.AFTER_SALES) return AFTER_SALES_TASK_OPTIONS;
|
||||
export function taskOptionsFor(phase, hasHistory = true, overallStatus = null) {
|
||||
// 🔧 出库设备与售后生命周期同等待遇(2026-09-17 修复「鸡生蛋」死锁):
|
||||
// 后端为消除不可回退的售后烙印,已不再把「正常已出库做质检」的设备
|
||||
// 翻成 AFTER_SALES。若这里仍只认 phase,工人就永远选不到
|
||||
// 「发货测试 / 售后维修」—— 而选不到就无法进入售后,phase 也就永远不变。
|
||||
if (
|
||||
phase === LIFECYCLE_PHASE.AFTER_SALES ||
|
||||
String(overallStatus || "").trim() === OUTBOUND_OVERALL
|
||||
) {
|
||||
return AFTER_SALES_TASK_OPTIONS;
|
||||
}
|
||||
if (!hasHistory) return [...PRODUCTION_TASK_OPTIONS, ...AFTER_SALES_ONLY_STEPS];
|
||||
return PRODUCTION_TASK_OPTIONS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user