Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90b62d96d7 | ||
|
|
9984d73989 | ||
|
|
0807ee9b4a | ||
|
|
f609c97c49 |
No files matched your search
@@ -2371,7 +2371,15 @@ async def list_my_production_tasks(
|
||||
workOrderType: Optional[str] = None,
|
||||
receptionSource: Optional[str] = Query(None, alias="receptionSource"),
|
||||
bizType: Optional[str] = Query(None, alias="bizType"),
|
||||
scope: str = Query("current", description="current|history"),
|
||||
workOrderStatus: Optional[str] = Query(
|
||||
None, alias="workOrderStatus", description="工单状态,多个用英文逗号分隔"
|
||||
),
|
||||
scope: str = Query("current", description="current|history|all"),
|
||||
pageBy: Optional[str] = Query(
|
||||
None,
|
||||
alias="pageBy",
|
||||
description="分页单位:workOrder=按工单卡片分页(合并 current+history)",
|
||||
),
|
||||
includeStepSummary: bool = Query(False, alias="includeStepSummary"),
|
||||
excludeVoidProtocol: bool = Query(True, alias="excludeVoidProtocol"),
|
||||
plannedStartTimeStart: Optional[str] = Query(None, alias="plannedStartTimeStart"),
|
||||
@@ -2392,6 +2400,8 @@ async def list_my_production_tasks(
|
||||
work_order_type=workOrderType,
|
||||
reception_source=receptionSource,
|
||||
biz_type=bizType,
|
||||
work_order_status=workOrderStatus,
|
||||
page_by=pageBy,
|
||||
include_step_summary=includeStepSummary,
|
||||
exclude_void_protocol=excludeVoidProtocol,
|
||||
planned_start_time_start=plannedStartTimeStart,
|
||||
|
||||
@@ -1182,6 +1182,20 @@ async def list_my_qc_tasks(
|
||||
protocolStatus: Optional[str] = Query(
|
||||
None, alias="protocolStatus", description="协议/捐赠状态,多个用英文逗号分隔"
|
||||
),
|
||||
workOrderStatus: Optional[str] = Query(
|
||||
None, alias="workOrderStatus", description="工单状态,多个用英文逗号分隔"
|
||||
),
|
||||
triggerSource: Optional[str] = Query(None, alias="triggerSource"),
|
||||
sampleTypeId: Optional[str] = Query(None, alias="sampleTypeId"),
|
||||
createTimeStart: Optional[str] = Query(None, alias="createTimeStart"),
|
||||
createTimeEnd: Optional[str] = Query(None, alias="createTimeEnd"),
|
||||
infusionTimeStart: Optional[str] = Query(None, alias="infusionTimeStart"),
|
||||
infusionTimeEnd: Optional[str] = Query(None, alias="infusionTimeEnd"),
|
||||
pageBy: Optional[str] = Query(
|
||||
None,
|
||||
alias="pageBy",
|
||||
description="分页单位:workOrder=按工单卡片分页(total 为工单数,list 为当页工单下全部任务)",
|
||||
),
|
||||
db: Session = Depends(get_db),
|
||||
user: dict = Depends(require_menu_code("biz:myQcTask:list")),
|
||||
):
|
||||
@@ -1199,6 +1213,14 @@ async def list_my_qc_tasks(
|
||||
reception_source=receptionSource,
|
||||
biz_type=bizType,
|
||||
protocol_status=protocolStatus,
|
||||
work_order_status=workOrderStatus,
|
||||
trigger_source=triggerSource,
|
||||
sample_type_id=sampleTypeId,
|
||||
create_time_start=createTimeStart,
|
||||
create_time_end=createTimeEnd,
|
||||
infusion_time_start=infusionTimeStart,
|
||||
infusion_time_end=infusionTimeEnd,
|
||||
page_by=pageBy,
|
||||
tenant_no=tenant_no,
|
||||
)
|
||||
return success_response(_page_payload(items, total, page, pageSize))
|
||||
|
||||
@@ -1150,6 +1150,11 @@ def _enrich_tasks_with_step_summaries(
|
||||
item["steps"] = by_task.get(tid, [])
|
||||
|
||||
|
||||
def _is_mine_page_by_work_order(page_by: Optional[str]) -> bool:
|
||||
key = (page_by or "").strip().lower().replace("-", "").replace("_", "")
|
||||
return key in ("workorder",)
|
||||
|
||||
|
||||
def list_production_tasks(
|
||||
db: Session, *, tenant_no: str,
|
||||
page: int = 1, page_size: int = 10,
|
||||
@@ -1166,13 +1171,28 @@ def list_production_tasks(
|
||||
current_assignee_user_id: Optional[str] = None,
|
||||
step_assignee_user_id: Optional[str] = None,
|
||||
mine_history_user_id: Optional[str] = None,
|
||||
mine_combined_user_id: Optional[str] = None,
|
||||
work_order_type: Optional[str] = None,
|
||||
reception_source: Optional[str] = None,
|
||||
biz_type: Optional[str] = None,
|
||||
work_order_status: Optional[str] = None,
|
||||
page_by: Optional[str] = None,
|
||||
user_info=None,
|
||||
include_step_summary: bool = False,
|
||||
exclude_void_protocol: bool = True,
|
||||
) -> Tuple[List[Dict[str, Any]], int]:
|
||||
def _ensure_wo_join(q, joined_wo: bool):
|
||||
if joined_wo:
|
||||
return q, True
|
||||
q = q.join(
|
||||
BizProductionWorkOrder,
|
||||
and_(
|
||||
BizProductionWorkOrder.id == BizProductionTask.work_order_id,
|
||||
BizProductionWorkOrder.del_flag == 0,
|
||||
),
|
||||
)
|
||||
return q, True
|
||||
|
||||
def _filtered():
|
||||
q = db.query(BizProductionTask).filter(
|
||||
BizProductionTask.tenant_no == tenant_no,
|
||||
@@ -1227,15 +1247,7 @@ def list_production_tasks(
|
||||
pst_start = (planned_start_time_start or "").strip()
|
||||
pst_end = (planned_start_time_end or "").strip()
|
||||
if pst_start or pst_end:
|
||||
if not joined_wo:
|
||||
q = q.join(
|
||||
BizProductionWorkOrder,
|
||||
and_(
|
||||
BizProductionWorkOrder.id == BizProductionTask.work_order_id,
|
||||
BizProductionWorkOrder.del_flag == 0,
|
||||
),
|
||||
)
|
||||
joined_wo = True
|
||||
q, joined_wo = _ensure_wo_join(q, joined_wo)
|
||||
from app.crud.production_work_order import apply_planned_start_time_step_filter
|
||||
|
||||
q = apply_planned_start_time_step_filter(
|
||||
@@ -1249,8 +1261,41 @@ def list_production_tasks(
|
||||
ca_uid = (current_assignee_user_id or "").strip()
|
||||
if ca_uid:
|
||||
q = q.filter(BizProductionTask.current_assignee_user_id == ca_uid)
|
||||
mc_uid = (mine_combined_user_id or "").strip()
|
||||
if mc_uid:
|
||||
step_task_ids = (
|
||||
db.query(BizProductionTaskStep.task_id)
|
||||
.join(
|
||||
BizProductionTaskStepAssignee,
|
||||
BizProductionTaskStepAssignee.step_id == BizProductionTaskStep.id,
|
||||
)
|
||||
.filter(
|
||||
BizProductionTaskStepAssignee.user_id == mc_uid,
|
||||
BizProductionTaskStepAssignee.tenant_no == tenant_no,
|
||||
BizProductionTaskStepAssignee.del_flag == 0,
|
||||
BizProductionTaskStep.del_flag == 0,
|
||||
)
|
||||
.distinct()
|
||||
)
|
||||
handover_task_ids = (
|
||||
db.query(BizProductionTaskHandover.task_id)
|
||||
.filter(
|
||||
BizProductionTaskHandover.from_user_id == mc_uid,
|
||||
BizProductionTaskHandover.tenant_no == tenant_no,
|
||||
BizProductionTaskHandover.del_flag == 0,
|
||||
)
|
||||
.distinct()
|
||||
)
|
||||
# 当前负责人 ∪ 步骤负责人 ∪ 曾转发(与前端 current+history 合并一致)
|
||||
q = q.filter(
|
||||
or_(
|
||||
BizProductionTask.id.in_(step_task_ids),
|
||||
BizProductionTask.current_assignee_user_id == mc_uid,
|
||||
BizProductionTask.id.in_(handover_task_ids),
|
||||
)
|
||||
)
|
||||
sa_uid = (step_assignee_user_id or "").strip()
|
||||
if sa_uid:
|
||||
if sa_uid and not mc_uid:
|
||||
step_task_ids = (
|
||||
db.query(BizProductionTaskStep.task_id)
|
||||
.join(
|
||||
@@ -1272,7 +1317,7 @@ def list_production_tasks(
|
||||
)
|
||||
)
|
||||
mh_uid = (mine_history_user_id or "").strip()
|
||||
if mh_uid:
|
||||
if mh_uid and not mc_uid:
|
||||
handover_task_ids = (
|
||||
db.query(BizProductionTaskHandover.task_id)
|
||||
.filter(
|
||||
@@ -1288,67 +1333,116 @@ def list_production_tasks(
|
||||
)
|
||||
wo_type = (work_order_type or "").strip()
|
||||
if wo_type:
|
||||
if not joined_wo:
|
||||
q = q.join(
|
||||
BizProductionWorkOrder,
|
||||
and_(
|
||||
BizProductionWorkOrder.id == BizProductionTask.work_order_id,
|
||||
BizProductionWorkOrder.del_flag == 0,
|
||||
q, joined_wo = _ensure_wo_join(q, joined_wo)
|
||||
q = q.filter(BizProductionWorkOrder.work_order_type == wo_type)
|
||||
elif _is_mine_page_by_work_order(page_by):
|
||||
# 「所有」Tab:与前端一致,排除中试出库(含默认 pilot)
|
||||
q, joined_wo = _ensure_wo_join(q, joined_wo)
|
||||
q = q.filter(
|
||||
~and_(
|
||||
BizProductionWorkOrder.work_order_type == "outbound",
|
||||
or_(
|
||||
BizProductionWorkOrder.biz_type.is_(None),
|
||||
BizProductionWorkOrder.biz_type == "",
|
||||
BizProductionWorkOrder.biz_type == "pilot_service",
|
||||
BizProductionWorkOrder.biz_type == "clinical_application",
|
||||
),
|
||||
)
|
||||
joined_wo = True
|
||||
q = q.filter(BizProductionWorkOrder.work_order_type == wo_type)
|
||||
)
|
||||
rs = (reception_source or "").strip()
|
||||
if rs:
|
||||
if not joined_wo:
|
||||
q = q.join(
|
||||
BizProductionWorkOrder,
|
||||
and_(
|
||||
BizProductionWorkOrder.id == BizProductionTask.work_order_id,
|
||||
BizProductionWorkOrder.del_flag == 0,
|
||||
),
|
||||
)
|
||||
joined_wo = True
|
||||
q, joined_wo = _ensure_wo_join(q, joined_wo)
|
||||
q = q.filter(BizProductionWorkOrder.reception_source == rs)
|
||||
bt = (biz_type or "").strip()
|
||||
if bt:
|
||||
if not joined_wo:
|
||||
q = q.join(
|
||||
BizProductionWorkOrder,
|
||||
and_(
|
||||
BizProductionWorkOrder.id == BizProductionTask.work_order_id,
|
||||
BizProductionWorkOrder.del_flag == 0,
|
||||
),
|
||||
)
|
||||
joined_wo = True
|
||||
q, joined_wo = _ensure_wo_join(q, joined_wo)
|
||||
q = q.filter(BizProductionWorkOrder.biz_type == bt)
|
||||
st_raw = (work_order_status or "").strip()
|
||||
if st_raw:
|
||||
q, joined_wo = _ensure_wo_join(q, joined_wo)
|
||||
statuses = [s.strip() for s in st_raw.split(",") if s.strip()]
|
||||
if statuses:
|
||||
q = q.filter(BizProductionWorkOrder.work_order_status.in_(statuses))
|
||||
if user_info:
|
||||
from app.core.data_scope import apply_data_scope
|
||||
q = apply_data_scope(q, BizProductionTask, user_info, db, tenant_no)
|
||||
if exclude_void_protocol:
|
||||
if not joined_wo:
|
||||
q = q.join(
|
||||
BizProductionWorkOrder,
|
||||
and_(
|
||||
BizProductionWorkOrder.id == BizProductionTask.work_order_id,
|
||||
BizProductionWorkOrder.del_flag == 0,
|
||||
),
|
||||
)
|
||||
q, joined_wo = _ensure_wo_join(q, joined_wo)
|
||||
from app.crud.production_work_order import apply_exclude_inactive_protocol_filter
|
||||
|
||||
q = apply_exclude_inactive_protocol_filter(q, exclude=True)
|
||||
return q
|
||||
|
||||
total = _filtered().order_by(None).with_entities(func.count(BizProductionTask.id)).scalar() or 0
|
||||
page = max(1, page)
|
||||
page_size = min(max(1, page_size), 100)
|
||||
rows = (
|
||||
_filtered()
|
||||
.order_by(BizProductionTask.create_time.desc())
|
||||
.offset((page - 1) * page_size)
|
||||
.limit(page_size)
|
||||
.all()
|
||||
)
|
||||
page_by_work_order = _is_mine_page_by_work_order(page_by)
|
||||
wo_ids_arg = [x.strip() for x in (work_order_ids or []) if x and str(x).strip()]
|
||||
max_page_size = 500 if (page_by_work_order or wo_ids_arg) else 100
|
||||
page_size = min(max(1, page_size), max_page_size)
|
||||
|
||||
if page_by_work_order:
|
||||
# 按工单分页:total=工单数;list=当页工单下全部匹配任务
|
||||
total = (
|
||||
_filtered()
|
||||
.order_by(None)
|
||||
.with_entities(func.count(func.distinct(BizProductionTask.work_order_id)))
|
||||
.scalar()
|
||||
or 0
|
||||
)
|
||||
mine_wo_ids_subq = (
|
||||
_filtered()
|
||||
.order_by(None)
|
||||
.with_entities(BizProductionTask.work_order_id.label("wo_id"))
|
||||
.distinct()
|
||||
.subquery()
|
||||
)
|
||||
page_work_orders = (
|
||||
db.query(BizProductionWorkOrder)
|
||||
.filter(BizProductionWorkOrder.id.in_(db.query(mine_wo_ids_subq.c.wo_id)))
|
||||
.order_by(BizProductionWorkOrder.create_time.desc())
|
||||
.offset((page - 1) * page_size)
|
||||
.limit(page_size)
|
||||
.all()
|
||||
)
|
||||
page_wo_ids = [wo.id for wo in page_work_orders if getattr(wo, "id", None)]
|
||||
if not page_wo_ids:
|
||||
return [], int(total)
|
||||
task_page_size = min(max(page_size * 100, len(page_wo_ids) * 20), 500)
|
||||
rows = (
|
||||
_filtered()
|
||||
.filter(BizProductionTask.work_order_id.in_(page_wo_ids))
|
||||
.order_by(BizProductionTask.create_time.desc())
|
||||
.limit(task_page_size)
|
||||
.all()
|
||||
)
|
||||
# 按工单页序重排;同工单内保持 create_time DESC
|
||||
order_map = {wid: idx for idx, wid in enumerate(page_wo_ids)}
|
||||
rows = sorted(
|
||||
rows,
|
||||
key=lambda t: (
|
||||
order_map.get(t.work_order_id or "", 10**9),
|
||||
str(getattr(t, "create_time", None) or ""),
|
||||
),
|
||||
reverse=False,
|
||||
)
|
||||
# 同工单内再按时间倒序(稳定:先整体按 wo 序,再分组内倒排)
|
||||
by_wo: Dict[str, List[Any]] = {}
|
||||
for row in rows:
|
||||
by_wo.setdefault(row.work_order_id or "", []).append(row)
|
||||
ordered_rows: List[Any] = []
|
||||
for wid in page_wo_ids:
|
||||
group = by_wo.get(wid, [])
|
||||
group.sort(key=lambda t: str(getattr(t, "create_time", None) or ""), reverse=True)
|
||||
ordered_rows.extend(group)
|
||||
rows = ordered_rows
|
||||
else:
|
||||
total = _filtered().order_by(None).with_entities(func.count(BizProductionTask.id)).scalar() or 0
|
||||
rows = (
|
||||
_filtered()
|
||||
.order_by(BizProductionTask.create_time.desc())
|
||||
.offset((page - 1) * page_size)
|
||||
.limit(page_size)
|
||||
.all()
|
||||
)
|
||||
items = [_task_to_dict(x) for x in rows]
|
||||
# 批量补充路线名称
|
||||
route_ids = [x.route_id for x in rows if x.route_id]
|
||||
@@ -1577,6 +1671,8 @@ def list_mine_production_tasks(
|
||||
work_order_type: Optional[str] = None,
|
||||
reception_source: Optional[str] = None,
|
||||
biz_type: Optional[str] = None,
|
||||
work_order_status: Optional[str] = None,
|
||||
page_by: Optional[str] = None,
|
||||
include_step_summary: bool = False,
|
||||
exclude_void_protocol: bool = True,
|
||||
planned_start_time_start: Optional[str] = None,
|
||||
@@ -1589,6 +1685,29 @@ def list_mine_production_tasks(
|
||||
pst_end = (planned_start_time_end or "").strip()
|
||||
mine_planned_user_id = uid if (pst_start or pst_end) else None
|
||||
sc = (scope or "current").strip().lower()
|
||||
if _is_mine_page_by_work_order(page_by) or sc in ("all", "combined"):
|
||||
# 按工单分页时合并 current+history,与前端原全量合并行为一致
|
||||
items, total = list_production_tasks(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
keyword=keyword,
|
||||
task_status=task_status,
|
||||
mine_combined_user_id=uid,
|
||||
work_order_type=work_order_type,
|
||||
reception_source=reception_source,
|
||||
biz_type=biz_type,
|
||||
work_order_status=work_order_status,
|
||||
page_by="workOrder",
|
||||
include_step_summary=include_step_summary,
|
||||
exclude_void_protocol=exclude_void_protocol,
|
||||
planned_start_time_start=planned_start_time_start,
|
||||
planned_start_time_end=planned_start_time_end,
|
||||
planned_start_time_mine_user_id=mine_planned_user_id,
|
||||
)
|
||||
_enrich_handover_times(db, items, from_user_id=uid, tenant_no=tenant_no)
|
||||
return items, total
|
||||
if sc == "history":
|
||||
items, total = list_production_tasks(
|
||||
db,
|
||||
@@ -1601,6 +1720,7 @@ def list_mine_production_tasks(
|
||||
work_order_type=work_order_type,
|
||||
reception_source=reception_source,
|
||||
biz_type=biz_type,
|
||||
work_order_status=work_order_status,
|
||||
include_step_summary=include_step_summary,
|
||||
exclude_void_protocol=exclude_void_protocol,
|
||||
planned_start_time_start=planned_start_time_start,
|
||||
@@ -1620,6 +1740,7 @@ def list_mine_production_tasks(
|
||||
work_order_type=work_order_type,
|
||||
reception_source=reception_source,
|
||||
biz_type=biz_type,
|
||||
work_order_status=work_order_status,
|
||||
include_step_summary=include_step_summary,
|
||||
exclude_void_protocol=exclude_void_protocol,
|
||||
planned_start_time_start=planned_start_time_start,
|
||||
|
||||
+181
-17
@@ -13,6 +13,8 @@ from app.crud.collection_protocol import lookup_attachments_by_urls, urls_to_att
|
||||
from app.crud import sample_reception as sample_reception_svc
|
||||
from app.crud.qc_work_order import (
|
||||
_load_sample_type_name_map,
|
||||
_normalize_date_bound,
|
||||
_protocol_sample_ids_for_sample_type,
|
||||
_qc_biz_type_label,
|
||||
_reception_source_label,
|
||||
_resolve_reception_id_for_work_order_detail,
|
||||
@@ -30,9 +32,14 @@ from app.crud.qc_inbound_lab_storage_sort import (
|
||||
inbound_lab_storage_order_by_clauses,
|
||||
uses_inbound_lab_storage_list_sort,
|
||||
)
|
||||
from app.crud.qc_temporary_production_cluster_sort import (
|
||||
apply_temporary_production_cluster_order,
|
||||
uses_temporary_production_cluster_list_sort,
|
||||
)
|
||||
from app.models.models import (
|
||||
BizAttachment,
|
||||
BizCollectionProtocol,
|
||||
BizPilotInfusionSchedule,
|
||||
BizProtocolSample,
|
||||
BizQcTask,
|
||||
BizQcTaskAssignee,
|
||||
@@ -564,6 +571,26 @@ def list_tasks(
|
||||
return assignee_svc.enrich_tasks_with_assignees(db, items, tenant_no), int(total)
|
||||
|
||||
|
||||
def _is_mine_page_by_work_order(page_by: Optional[str]) -> bool:
|
||||
key = (page_by or "").strip().lower().replace("-", "").replace("_", "")
|
||||
return key in ("workorder",)
|
||||
|
||||
|
||||
def _reorder_mine_task_rows_by_work_order_ids(
|
||||
rows: List[Tuple[Any, Any]], work_order_ids: List[str]
|
||||
) -> List[Tuple[Any, Any]]:
|
||||
"""按工单分页顺序重排任务行,同工单内保持原相对顺序。"""
|
||||
order_map = {wid: idx for idx, wid in enumerate(work_order_ids)}
|
||||
return sorted(
|
||||
rows,
|
||||
key=lambda pair: (
|
||||
order_map.get(getattr(pair[0], "work_order_id", None) or "", 10**9),
|
||||
getattr(pair[1], "work_order_no", None) or "",
|
||||
getattr(pair[0], "task_no", None) or "",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def list_mine_tasks(
|
||||
db: Session,
|
||||
*,
|
||||
@@ -577,6 +604,14 @@ def list_mine_tasks(
|
||||
reception_source: Optional[str] = None,
|
||||
biz_type: Optional[str] = None,
|
||||
protocol_status: Optional[str] = None,
|
||||
work_order_status: Optional[str] = None,
|
||||
trigger_source: Optional[str] = None,
|
||||
sample_type_id: Optional[str] = None,
|
||||
create_time_start: Optional[str] = None,
|
||||
create_time_end: Optional[str] = None,
|
||||
infusion_time_start: Optional[str] = None,
|
||||
infusion_time_end: Optional[str] = None,
|
||||
page_by: Optional[str] = None,
|
||||
tenant_no: Optional[str] = None,
|
||||
) -> Tuple[List[Dict[str, Any]], int]:
|
||||
def _filtered():
|
||||
@@ -636,12 +671,93 @@ def list_mine_tasks(
|
||||
)
|
||||
else:
|
||||
q0 = q0.filter(BizQcWorkOrder.qc_biz_type == bt)
|
||||
else:
|
||||
# 「所有」Tab:与前端 workOrderMatchesTab(all) 一致,排除中试出库(含默认 pilot)
|
||||
q0 = q0.filter(
|
||||
~and_(
|
||||
BizQcWorkOrder.work_order_type == "outbound",
|
||||
or_(
|
||||
BizQcWorkOrder.biz_type.is_(None),
|
||||
BizQcWorkOrder.biz_type == "",
|
||||
BizQcWorkOrder.biz_type == "pilot_service",
|
||||
BizQcWorkOrder.biz_type == "clinical_application",
|
||||
),
|
||||
)
|
||||
)
|
||||
rs = (reception_source or "").strip()
|
||||
if rs:
|
||||
q0 = q0.filter(BizQcWorkOrder.reception_source == rs)
|
||||
bt_out = (biz_type or "").strip()
|
||||
if bt_out:
|
||||
q0 = q0.filter(BizQcWorkOrder.biz_type == bt_out)
|
||||
st_raw = (work_order_status or "").strip()
|
||||
if st_raw:
|
||||
statuses = [s.strip() for s in st_raw.split(",") if s.strip()]
|
||||
if statuses:
|
||||
q0 = q0.filter(BizQcWorkOrder.work_order_status.in_(statuses))
|
||||
ts = (trigger_source or "").strip()
|
||||
wt = (qc_biz_type or "").strip()
|
||||
if ts:
|
||||
if ts == "temp_manual":
|
||||
q0 = q0.filter(
|
||||
BizQcWorkOrder.work_order_type == "temporary",
|
||||
BizQcWorkOrder.trigger_source != "production",
|
||||
)
|
||||
elif ts == "temp_production":
|
||||
q0 = q0.filter(
|
||||
BizQcWorkOrder.work_order_type == "temporary",
|
||||
BizQcWorkOrder.trigger_source == "production",
|
||||
)
|
||||
elif ts == "manual" and wt == "temporary":
|
||||
q0 = q0.filter(BizQcWorkOrder.trigger_source != "production")
|
||||
elif ts == "production" and not wt:
|
||||
q0 = q0.filter(
|
||||
BizQcWorkOrder.trigger_source == "production",
|
||||
BizQcWorkOrder.work_order_type != "temporary",
|
||||
)
|
||||
else:
|
||||
q0 = q0.filter(BizQcWorkOrder.trigger_source == ts)
|
||||
use_infusion_time = wt == "outbound" and (
|
||||
(infusion_time_start or "").strip() or (infusion_time_end or "").strip()
|
||||
)
|
||||
if use_infusion_time:
|
||||
q0 = q0.join(
|
||||
BizPilotInfusionSchedule,
|
||||
eq_unicode(BizQcWorkOrder.infusion_schedule_id, BizPilotInfusionSchedule.id),
|
||||
).filter(
|
||||
BizPilotInfusionSchedule.del_flag == 0,
|
||||
BizPilotInfusionSchedule.tenant_no == tenant_no,
|
||||
)
|
||||
if (infusion_time_start or "").strip():
|
||||
q0 = q0.filter(
|
||||
BizPilotInfusionSchedule.infusion_time
|
||||
>= _normalize_date_bound(infusion_time_start.strip())
|
||||
)
|
||||
if (infusion_time_end or "").strip():
|
||||
q0 = q0.filter(
|
||||
BizPilotInfusionSchedule.infusion_time
|
||||
<= _normalize_date_bound(infusion_time_end.strip(), end_of_day=True)
|
||||
)
|
||||
else:
|
||||
if create_time_start:
|
||||
q0 = q0.filter(
|
||||
BizQcWorkOrder.create_time >= _normalize_date_bound(create_time_start)
|
||||
)
|
||||
if create_time_end:
|
||||
q0 = q0.filter(
|
||||
BizQcWorkOrder.create_time
|
||||
<= _normalize_date_bound(create_time_end, end_of_day=True)
|
||||
)
|
||||
stid = (sample_type_id or "").strip()
|
||||
if stid and tenant_no:
|
||||
ps_ids = _protocol_sample_ids_for_sample_type(db, tenant_no, stid, rs or None)
|
||||
if not ps_ids:
|
||||
q0 = q0.filter(BizQcWorkOrder.id.in_([]))
|
||||
else:
|
||||
q0 = q0.filter(
|
||||
BizQcWorkOrder.work_order_type == "inbound",
|
||||
BizQcWorkOrder.protocol_sample_id.in_(ps_ids),
|
||||
)
|
||||
q0 = apply_research_donation_protocol_status_filter(
|
||||
q0,
|
||||
protocol_status,
|
||||
@@ -649,28 +765,76 @@ def list_mine_tasks(
|
||||
)
|
||||
return q0
|
||||
|
||||
total = _filtered().order_by(None).with_entities(func.count(BizQcTask.id)).scalar() or 0
|
||||
page = max(1, page)
|
||||
page_size = min(max(1, page_size), 100)
|
||||
q_page = _filtered()
|
||||
if uses_inbound_lab_storage_list_sort(reception_source):
|
||||
q_page = q_page.order_by(
|
||||
*inbound_lab_storage_order_by_clauses(),
|
||||
BizQcWorkOrder.work_order_no.desc(),
|
||||
BizQcTask.task_no.asc(),
|
||||
page_by_work_order = _is_mine_page_by_work_order(page_by)
|
||||
|
||||
if page_by_work_order:
|
||||
total = (
|
||||
_filtered()
|
||||
.order_by(None)
|
||||
.with_entities(func.count(func.distinct(BizQcWorkOrder.id)))
|
||||
.scalar()
|
||||
or 0
|
||||
)
|
||||
mine_wo_ids_subq = (
|
||||
_filtered()
|
||||
.order_by(None)
|
||||
.with_entities(BizQcWorkOrder.id.label("wo_id"))
|
||||
.distinct()
|
||||
.subquery()
|
||||
)
|
||||
wo_q = db.query(BizQcWorkOrder).filter(
|
||||
BizQcWorkOrder.id.in_(db.query(mine_wo_ids_subq.c.wo_id))
|
||||
)
|
||||
wt_for_sort = (
|
||||
"temporary"
|
||||
if (qc_biz_type or "").strip() == "temporary"
|
||||
else ((qc_biz_type or "").strip() or "")
|
||||
)
|
||||
if uses_inbound_lab_storage_list_sort(reception_source):
|
||||
wo_q = wo_q.order_by(*inbound_lab_storage_order_by_clauses())
|
||||
elif uses_temporary_production_cluster_list_sort(wt_for_sort):
|
||||
wo_q = apply_temporary_production_cluster_order(wo_q)
|
||||
else:
|
||||
wo_q = wo_q.order_by(BizQcWorkOrder.create_time.desc())
|
||||
page_work_orders = (
|
||||
wo_q.offset((page - 1) * page_size).limit(page_size).all()
|
||||
)
|
||||
page_wo_ids = [wo.id for wo in page_work_orders if getattr(wo, "id", None)]
|
||||
if not page_wo_ids:
|
||||
return [], int(total)
|
||||
rows = (
|
||||
_filtered()
|
||||
.filter(BizQcTask.work_order_id.in_(page_wo_ids))
|
||||
.order_by(
|
||||
BizQcWorkOrder.work_order_no.desc(),
|
||||
BizQcTask.task_no.asc(),
|
||||
)
|
||||
.all()
|
||||
)
|
||||
rows = _reorder_mine_task_rows_by_work_order_ids(rows, page_wo_ids)
|
||||
else:
|
||||
q_page = q_page.order_by(
|
||||
BizQcTask.create_time.desc(),
|
||||
BizQcWorkOrder.work_order_no.desc(),
|
||||
BizQcTask.task_no.asc(),
|
||||
total = (
|
||||
_filtered().order_by(None).with_entities(func.count(BizQcTask.id)).scalar() or 0
|
||||
)
|
||||
rows = (
|
||||
q_page
|
||||
.offset((page - 1) * page_size)
|
||||
.limit(page_size)
|
||||
.all()
|
||||
)
|
||||
q_page = _filtered()
|
||||
if uses_inbound_lab_storage_list_sort(reception_source):
|
||||
q_page = q_page.order_by(
|
||||
*inbound_lab_storage_order_by_clauses(),
|
||||
BizQcWorkOrder.work_order_no.desc(),
|
||||
BizQcTask.task_no.asc(),
|
||||
)
|
||||
else:
|
||||
q_page = q_page.order_by(
|
||||
BizQcTask.create_time.desc(),
|
||||
BizQcWorkOrder.work_order_no.desc(),
|
||||
BizQcTask.task_no.asc(),
|
||||
)
|
||||
rows = (
|
||||
q_page.offset((page - 1) * page_size).limit(page_size).all()
|
||||
)
|
||||
|
||||
items = _task_rows_to_dicts(db, rows, tenant_no)
|
||||
items = _enrich_tasks_reception_fields(db, items)
|
||||
items = _enrich_mine_tasks_with_work_order_summaries(db, rows, items, tenant_no)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
"""我的任务按工单分页:辅助函数语义。"""
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app.crud.qc_task import (
|
||||
_is_mine_page_by_work_order,
|
||||
_reorder_mine_task_rows_by_work_order_ids,
|
||||
)
|
||||
from app.crud.production_task import _is_mine_page_by_work_order as prod_is_page_by_wo
|
||||
|
||||
|
||||
class TestMinePageByWorkOrderFlag(unittest.TestCase):
|
||||
def test_accepts_common_aliases(self):
|
||||
self.assertTrue(_is_mine_page_by_work_order("workOrder"))
|
||||
self.assertTrue(_is_mine_page_by_work_order("work_order"))
|
||||
self.assertTrue(_is_mine_page_by_work_order("work-order"))
|
||||
self.assertTrue(prod_is_page_by_wo("workOrder"))
|
||||
|
||||
def test_rejects_other_values(self):
|
||||
self.assertFalse(_is_mine_page_by_work_order(None))
|
||||
self.assertFalse(_is_mine_page_by_work_order(""))
|
||||
self.assertFalse(_is_mine_page_by_work_order("task"))
|
||||
|
||||
|
||||
class TestReorderMineTaskRows(unittest.TestCase):
|
||||
def test_preserves_work_order_page_order(self):
|
||||
rows = [
|
||||
(SimpleNamespace(work_order_id="b", task_no="t2"), SimpleNamespace(work_order_no="B")),
|
||||
(SimpleNamespace(work_order_id="a", task_no="t1"), SimpleNamespace(work_order_no="A")),
|
||||
(SimpleNamespace(work_order_id="b", task_no="t3"), SimpleNamespace(work_order_no="B")),
|
||||
]
|
||||
ordered = _reorder_mine_task_rows_by_work_order_ids(rows, ["a", "b"])
|
||||
self.assertEqual([r[0].work_order_id for r in ordered], ["a", "b", "b"])
|
||||
self.assertEqual([r[0].task_no for r in ordered], ["t1", "t2", "t3"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -88,7 +88,10 @@ export function fetchMyProductionTasks(params: {
|
||||
workOrderType?: string
|
||||
receptionSource?: string
|
||||
bizType?: string
|
||||
scope: 'current' | 'history'
|
||||
workOrderStatus?: string
|
||||
scope: 'current' | 'history' | 'all'
|
||||
/** workOrder=按工单卡片分页(合并 current+history) */
|
||||
pageBy?: 'workOrder'
|
||||
includeStepSummary?: boolean
|
||||
excludeVoidProtocol?: boolean
|
||||
plannedStartTimeStart?: string
|
||||
|
||||
@@ -172,6 +172,16 @@ export function fetchMyQcTaskList(params?: {
|
||||
bizType?: string
|
||||
/** 科研捐赠:协议/捐赠状态,多个逗号分隔;空串=不限制 */
|
||||
protocolStatus?: string
|
||||
/** 工单状态,多个逗号分隔 */
|
||||
workOrderStatus?: string
|
||||
triggerSource?: string
|
||||
sampleTypeId?: string
|
||||
createTimeStart?: string
|
||||
createTimeEnd?: string
|
||||
infusionTimeStart?: string
|
||||
infusionTimeEnd?: string
|
||||
/** workOrder=按工单卡片分页;total 为工单数,list 为当页工单下全部任务 */
|
||||
pageBy?: 'workOrder'
|
||||
}) {
|
||||
return request.get<PageList<QcTask>>({
|
||||
url: '/web/admin/qc-tasks/mine',
|
||||
|
||||
@@ -17,10 +17,13 @@ export type ProductionTaskMineFilters = {
|
||||
keyword?: string
|
||||
taskStatus?: string
|
||||
productionCategory?: string
|
||||
workOrderStatus?: string
|
||||
tabKey: ProductionWorkOrderTabKey
|
||||
excludeVoidProtocol?: boolean
|
||||
plannedStartTimeStart?: string
|
||||
plannedStartTimeEnd?: string
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export type MineWorkOrderSearchFilters = {
|
||||
@@ -143,55 +146,53 @@ export function buildPresetTasksMap(
|
||||
return map
|
||||
}
|
||||
|
||||
async function fetchMineTasksByScope(
|
||||
scope: 'current' | 'history',
|
||||
/** 按工单卡片分页拉取「我的生产任务」(合并 current+history,单次请求) */
|
||||
export async function fetchMineProductionTasksByWorkOrderPage(
|
||||
filters: ProductionTaskMineFilters
|
||||
): Promise<ProductionTaskRow[]> {
|
||||
): Promise<{ list: ProductionTaskRow[]; total: number }> {
|
||||
const tab = getProductionWorkOrderTab(filters.tabKey)!
|
||||
const listQuery = isAllProductionWorkOrderTab(filters.tabKey)
|
||||
? toAllTabListQuery(filters.productionCategory || '')
|
||||
: toWorkOrderListQuery(tab)
|
||||
const pageSize = MINE_TASK_FETCH_PAGE_SIZE
|
||||
let page = 1
|
||||
const all: ProductionTaskRow[] = []
|
||||
let total = 0
|
||||
while (true) {
|
||||
const res = await fetchMyProductionTasks({
|
||||
scope,
|
||||
page,
|
||||
pageSize,
|
||||
keyword: filters.keyword || undefined,
|
||||
taskStatus: filters.taskStatus || undefined,
|
||||
workOrderType: listQuery.workOrderType,
|
||||
receptionSource: listQuery.receptionSource,
|
||||
bizType: listQuery.bizType,
|
||||
includeStepSummary: true,
|
||||
excludeVoidProtocol: filters.excludeVoidProtocol,
|
||||
plannedStartTimeStart: filters.plannedStartTimeStart,
|
||||
plannedStartTimeEnd: filters.plannedStartTimeEnd
|
||||
})
|
||||
const list = res.list || []
|
||||
all.push(...list)
|
||||
total = res.total || 0
|
||||
if (!list.length || all.length >= total) break
|
||||
page += 1
|
||||
}
|
||||
return all
|
||||
const res = await fetchMyProductionTasks({
|
||||
scope: 'all',
|
||||
pageBy: 'workOrder',
|
||||
page: Math.max(1, filters.page || 1),
|
||||
pageSize: Math.min(100, Math.max(1, filters.pageSize || 10)),
|
||||
keyword: filters.keyword || undefined,
|
||||
taskStatus: filters.taskStatus || undefined,
|
||||
workOrderType: listQuery.workOrderType,
|
||||
receptionSource: listQuery.receptionSource,
|
||||
bizType: listQuery.bizType,
|
||||
workOrderStatus: filters.workOrderStatus || undefined,
|
||||
includeStepSummary: true,
|
||||
excludeVoidProtocol: filters.excludeVoidProtocol,
|
||||
plannedStartTimeStart: filters.plannedStartTimeStart,
|
||||
plannedStartTimeEnd: filters.plannedStartTimeEnd
|
||||
})
|
||||
return { list: res.list || [], total: res.total || 0 }
|
||||
}
|
||||
|
||||
/** 合并当前负责人任务与曾转发任务(方案 C:单列表) */
|
||||
/** @deprecated 保留兼容;新列表请用 fetchMineProductionTasksByWorkOrderPage */
|
||||
export async function fetchAllMineProductionTasks(
|
||||
filters: ProductionTaskMineFilters
|
||||
): Promise<ProductionTaskRow[]> {
|
||||
const [current, history] = await Promise.all([
|
||||
fetchMineTasksByScope('current', filters),
|
||||
fetchMineTasksByScope('history', filters)
|
||||
])
|
||||
const map = new Map<string, ProductionTaskRow>()
|
||||
for (const row of [...current, ...history]) {
|
||||
if (row.id) map.set(row.id, row)
|
||||
const pageSize = MINE_TASK_FETCH_PAGE_SIZE
|
||||
let page = 1
|
||||
const all: ProductionTaskRow[] = []
|
||||
while (true) {
|
||||
const res = await fetchMineProductionTasksByWorkOrderPage({
|
||||
...filters,
|
||||
page,
|
||||
pageSize
|
||||
})
|
||||
const list = res.list || []
|
||||
all.push(...list)
|
||||
if (!list.length || list.length < pageSize) break
|
||||
page += 1
|
||||
if (page > 50) break
|
||||
}
|
||||
return [...map.values()]
|
||||
return all
|
||||
}
|
||||
|
||||
export async function enrichMineEntriesWithWorkOrders(
|
||||
|
||||
@@ -29,6 +29,17 @@ export type QcTaskMineFilters = {
|
||||
taskStatus?: string
|
||||
/** 科研捐赠:协议状态逗号串;''=不限制;缺省不传 */
|
||||
protocolStatus?: string
|
||||
workOrderStatus?: string
|
||||
triggerSource?: string
|
||||
sampleTypeId?: string
|
||||
/** 「所有」Tab 的质检类型子筛选 */
|
||||
qcCategory?: string
|
||||
createTimeStart?: string
|
||||
createTimeEnd?: string
|
||||
infusionTimeStart?: string
|
||||
infusionTimeEnd?: string
|
||||
page?: number
|
||||
pageSize?: number
|
||||
tabKey: QcWorkOrderTabKey
|
||||
}
|
||||
|
||||
@@ -138,38 +149,62 @@ export function filterMineEntriesByWorkOrderSearch(
|
||||
})
|
||||
}
|
||||
|
||||
/** @deprecated 保留兼容;新列表请用 fetchMineTasksByWorkOrderPage */
|
||||
export async function fetchAllMineTasks(filters: QcTaskMineFilters): Promise<QcTask[]> {
|
||||
const tab = getQcWorkOrderTab(filters.tabKey)!
|
||||
const listQuery = isAllQcWorkOrderTab(filters.tabKey)
|
||||
? toAllTabListQuery('')
|
||||
: toWorkOrderListQuery(tab)
|
||||
const pageSize = MINE_TASK_FETCH_PAGE_SIZE
|
||||
let page = 1
|
||||
const all: QcTask[] = []
|
||||
let total = 0
|
||||
const protocolStatusParam =
|
||||
filters.tabKey === 'inbound_research_donation' ? (filters.protocolStatus ?? '') : undefined
|
||||
while (true) {
|
||||
const res = await fetchMyQcTaskList({
|
||||
const res = await fetchMineTasksByWorkOrderPage({
|
||||
...filters,
|
||||
page,
|
||||
pageSize,
|
||||
keyword: filters.keyword || undefined,
|
||||
taskType: filters.taskType || undefined,
|
||||
taskStatus: filters.taskStatus || undefined,
|
||||
qcBizType: listQuery.workOrderType,
|
||||
receptionSource: listQuery.receptionSource,
|
||||
bizType: listQuery.bizType,
|
||||
...(protocolStatusParam !== undefined ? { protocolStatus: protocolStatusParam } : {})
|
||||
pageSize
|
||||
})
|
||||
const list = res.list || []
|
||||
all.push(...list)
|
||||
total = res.total || 0
|
||||
if (!list.length || all.length >= total) break
|
||||
// 旧全量语义:按任务条数拼满;pageBy=workOrder 时 total 为工单数,这里用 list 耗尽结束
|
||||
if (!list.length) break
|
||||
if (list.length < pageSize) break
|
||||
page += 1
|
||||
if (page > 50) break
|
||||
}
|
||||
return all
|
||||
}
|
||||
|
||||
/** 按工单卡片分页拉取「我的质检任务」(单次请求,不再循环全量) */
|
||||
export async function fetchMineTasksByWorkOrderPage(
|
||||
filters: QcTaskMineFilters
|
||||
): Promise<{ list: QcTask[]; total: number }> {
|
||||
const tab = getQcWorkOrderTab(filters.tabKey)!
|
||||
const listQuery = isAllQcWorkOrderTab(filters.tabKey)
|
||||
? toAllTabListQuery(filters.qcCategory || '')
|
||||
: toWorkOrderListQuery(tab)
|
||||
const protocolStatusParam =
|
||||
filters.tabKey === 'inbound_research_donation' ? (filters.protocolStatus ?? '') : undefined
|
||||
const res = await fetchMyQcTaskList({
|
||||
page: Math.max(1, filters.page || 1),
|
||||
pageSize: Math.min(100, Math.max(1, filters.pageSize || 10)),
|
||||
pageBy: 'workOrder',
|
||||
keyword: filters.keyword || undefined,
|
||||
taskType: filters.taskType || undefined,
|
||||
taskStatus: filters.taskStatus || undefined,
|
||||
qcBizType: listQuery.workOrderType,
|
||||
receptionSource: listQuery.receptionSource,
|
||||
bizType: listQuery.bizType,
|
||||
workOrderStatus: filters.workOrderStatus || undefined,
|
||||
triggerSource: filters.triggerSource || undefined,
|
||||
sampleTypeId: filters.sampleTypeId || undefined,
|
||||
createTimeStart: filters.createTimeStart || undefined,
|
||||
createTimeEnd: filters.createTimeEnd || undefined,
|
||||
infusionTimeStart: filters.infusionTimeStart || undefined,
|
||||
infusionTimeEnd: filters.infusionTimeEnd || undefined,
|
||||
...(protocolStatusParam !== undefined ? { protocolStatus: protocolStatusParam } : {})
|
||||
})
|
||||
return { list: res.list || [], total: res.total || 0 }
|
||||
}
|
||||
|
||||
export async function enrichMineEntriesWithWorkOrders(
|
||||
entries: MineWorkOrderEntry[]
|
||||
): Promise<MineWorkOrderEntry[]> {
|
||||
|
||||
+10
-21
@@ -8,11 +8,9 @@ import {
|
||||
groupProductionTasksByWorkOrderId
|
||||
} from '@/api/production-task'
|
||||
import {
|
||||
fetchAllMineProductionTasks,
|
||||
fetchMineProductionTasksByWorkOrderPage,
|
||||
groupMineTasksByWorkOrder,
|
||||
enrichMineEntriesWithWorkOrders,
|
||||
filterMineEntriesByWorkOrderSearch,
|
||||
paginateMineEntries,
|
||||
buildMineTableRows
|
||||
} from '@/utils/production-mine-task-groups'
|
||||
import {
|
||||
@@ -82,18 +80,6 @@ export function useProductionWorkOrderTabPage(
|
||||
}
|
||||
}
|
||||
|
||||
function buildMineWorkOrderSearchFilters() {
|
||||
return {
|
||||
keyword: searchForm.keyword || undefined,
|
||||
workOrderStatus: searchForm.workOrderStatus.length
|
||||
? [...searchForm.workOrderStatus]
|
||||
: undefined,
|
||||
productionCategory: searchForm.productionCategory || undefined,
|
||||
tabKey: tabKey.value,
|
||||
excludeVoidProtocol: resolveExcludeVoidProtocolParam()
|
||||
}
|
||||
}
|
||||
|
||||
function enrichRowsWithPlannedStartTimeRange(
|
||||
rows: ProductionWorkOrderItem[],
|
||||
tasksMap: Record<string, Record<string, any>[]>
|
||||
@@ -132,22 +118,25 @@ export function useProductionWorkOrderTabPage(
|
||||
tasksBatchReady.value = false
|
||||
try {
|
||||
if (pageModeValue.value === 'mine') {
|
||||
const tasks = await fetchAllMineProductionTasks({
|
||||
const pageRes = await fetchMineProductionTasksByWorkOrderPage({
|
||||
page: pagination.page,
|
||||
pageSize: pagination.pageSize,
|
||||
keyword: searchForm.keyword || undefined,
|
||||
taskStatus: searchForm.taskStatus || undefined,
|
||||
productionCategory: searchForm.productionCategory || undefined,
|
||||
workOrderStatus: searchForm.workOrderStatus.length
|
||||
? joinWorkOrderStatusFilter(searchForm.workOrderStatus)
|
||||
: undefined,
|
||||
tabKey: tabKey.value,
|
||||
excludeVoidProtocol: resolveExcludeVoidProtocolParam(),
|
||||
...buildPlannedStartTimeParams()
|
||||
})
|
||||
let entries = groupMineTasksByWorkOrder(tasks)
|
||||
let entries = groupMineTasksByWorkOrder(pageRes.list || [])
|
||||
entries = await enrichMineEntriesWithWorkOrders(entries)
|
||||
entries = filterMineEntriesByWorkOrderSearch(entries, buildMineWorkOrderSearchFilters())
|
||||
const pageResult = paginateMineEntries(entries, pagination.page, pagination.pageSize)
|
||||
const tableModel = buildMineTableRows(pageResult.items)
|
||||
const tableModel = buildMineTableRows(entries)
|
||||
tableData.value = tableModel.rows
|
||||
presetTasksByWorkOrderId.value = tableModel.presetTasksByWorkOrderId
|
||||
pagination.total = pageResult.total
|
||||
pagination.total = pageRes.total || 0
|
||||
tasksBatchReady.value = true
|
||||
return
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,8 +16,8 @@
|
||||
>
|
||||
<div v-if="workOrder" class="attachment-wo-summary">
|
||||
<div class="attachment-wo-summary__row">
|
||||
<span class="attachment-wo-summary__label">工单号</span>
|
||||
<span class="attachment-wo-summary__value">{{ workOrder.workOrderNo || '—' }}</span>
|
||||
<span class="attachment-wo-summary__label">实验室入库编码</span>
|
||||
<span class="attachment-wo-summary__value">{{ workOrder.labStorageCode || '—' }}</span>
|
||||
</div>
|
||||
<div v-if="workOrder.sampleCode" class="attachment-wo-summary__row">
|
||||
<span class="attachment-wo-summary__label">样本编码</span>
|
||||
|
||||
+34
-55
@@ -3,12 +3,8 @@ import { fetchQcWorkOrderList, type QcWorkOrder } from '@/api/qc-work-order'
|
||||
import { fetchCellSampleTypeList } from '@/api/admin'
|
||||
import type { QcTask } from '@/api/qc-task'
|
||||
import {
|
||||
fetchAllMineTasks,
|
||||
fetchMineTasksByWorkOrderPage,
|
||||
groupMineTasksByWorkOrder,
|
||||
filterMineEntriesByWorkOrderSearch,
|
||||
sortMineEntriesForInboundLabStorage,
|
||||
sortMineEntriesForTemporary,
|
||||
paginateMineEntries,
|
||||
buildMineTableRows
|
||||
} from '@/utils/qc-mine-task-groups'
|
||||
import {
|
||||
@@ -106,50 +102,25 @@ export function useQcWorkOrderTabPage(
|
||||
const viewWorkOrderId = ref('')
|
||||
const viewTabKey = ref<QcWorkOrderTabKey>(tabKey.value)
|
||||
|
||||
function resolveSampleTypeFilterName() {
|
||||
const id = (searchForm.sampleTypeId || '').trim()
|
||||
if (!id) return ''
|
||||
return sampleTypeOptions.value.find((opt) => opt.id === id)?.label || ''
|
||||
}
|
||||
|
||||
function buildMineWorkOrderSearchFilters() {
|
||||
const tab = tabConfig.value
|
||||
const timeParams =
|
||||
isAllQcWorkOrderTab(tabKey.value) || !tabUsesInfusionTimeFilter(tab)
|
||||
? {
|
||||
createTimeStart: createTimeRange.value?.[0] || undefined,
|
||||
createTimeEnd: createTimeRange.value?.[1] || undefined
|
||||
}
|
||||
: {
|
||||
infusionTimeStart: createTimeRange.value?.[0] || undefined,
|
||||
infusionTimeEnd: createTimeRange.value?.[1] || undefined
|
||||
}
|
||||
return {
|
||||
keyword: searchForm.keyword || undefined,
|
||||
workOrderStatus: searchForm.workOrderStatus.length
|
||||
? [...searchForm.workOrderStatus]
|
||||
: undefined,
|
||||
protocolStatus:
|
||||
tabKey.value === 'inbound_research_donation'
|
||||
? [...searchForm.protocolStatus]
|
||||
: undefined,
|
||||
qcCategory: searchForm.qcCategory || undefined,
|
||||
triggerSource:
|
||||
shouldApplyTriggerSourceFilter(tabKey.value, tab.listLayout) && searchForm.triggerSource
|
||||
? searchForm.triggerSource
|
||||
: undefined,
|
||||
sampleTypeName: resolveSampleTypeFilterName() || undefined,
|
||||
tabKey: tabKey.value,
|
||||
...timeParams
|
||||
}
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
clearInsertedCards()
|
||||
loading.value = true
|
||||
try {
|
||||
if (pageModeValue.value === 'mine') {
|
||||
const tasks = await fetchAllMineTasks({
|
||||
const tab = tabConfig.value
|
||||
const timeParams =
|
||||
isAllQcWorkOrderTab(tabKey.value) || !tabUsesInfusionTimeFilter(tab)
|
||||
? {
|
||||
createTimeStart: createTimeRange.value?.[0] || undefined,
|
||||
createTimeEnd: createTimeRange.value?.[1] || undefined
|
||||
}
|
||||
: {
|
||||
infusionTimeStart: createTimeRange.value?.[0] || undefined,
|
||||
infusionTimeEnd: createTimeRange.value?.[1] || undefined
|
||||
}
|
||||
const pageRes = await fetchMineTasksByWorkOrderPage({
|
||||
page: pagination.page,
|
||||
pageSize: pagination.pageSize,
|
||||
keyword: searchForm.keyword || undefined,
|
||||
taskStatus: searchForm.taskStatus || undefined,
|
||||
taskType: searchForm.taskType || undefined,
|
||||
@@ -157,21 +128,29 @@ export function useQcWorkOrderTabPage(
|
||||
tabKey.value === 'inbound_research_donation'
|
||||
? joinProtocolStatusFilter(searchForm.protocolStatus)
|
||||
: undefined,
|
||||
tabKey: tabKey.value
|
||||
workOrderStatus: searchForm.workOrderStatus.length
|
||||
? joinWorkOrderStatusFilter(searchForm.workOrderStatus)
|
||||
: undefined,
|
||||
triggerSource:
|
||||
shouldApplyTriggerSourceFilter(tabKey.value, tab.listLayout) && searchForm.triggerSource
|
||||
? searchForm.triggerSource
|
||||
: undefined,
|
||||
sampleTypeId:
|
||||
isInboundSampleQcTab(tabKey.value) && searchForm.sampleTypeId
|
||||
? searchForm.sampleTypeId
|
||||
: undefined,
|
||||
qcCategory: isAllQcWorkOrderTab(tabKey.value)
|
||||
? searchForm.qcCategory || undefined
|
||||
: undefined,
|
||||
tabKey: tabKey.value,
|
||||
...timeParams
|
||||
})
|
||||
let entries = groupMineTasksByWorkOrder(tasks)
|
||||
entries = filterMineEntriesByWorkOrderSearch(entries, buildMineWorkOrderSearchFilters())
|
||||
if (isInboundSampleQcTab(tabKey.value)) {
|
||||
entries = sortMineEntriesForInboundLabStorage(entries)
|
||||
} else if (tabKey.value === 'temporary') {
|
||||
entries = sortMineEntriesForTemporary(entries)
|
||||
}
|
||||
const pageResult = paginateMineEntries(entries, pagination.page, pagination.pageSize)
|
||||
const tableModel = buildMineTableRows(pageResult.items)
|
||||
const entries = groupMineTasksByWorkOrder(pageRes.list || [])
|
||||
const tableModel = buildMineTableRows(entries)
|
||||
tableData.value = tableModel.rows
|
||||
presetTasksByWorkOrderId.value = tableModel.presetTasksByWorkOrderId
|
||||
presetBatchesByWorkOrderId.value = undefined
|
||||
pagination.total = pageResult.total
|
||||
pagination.total = pageRes.total || 0
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user