diff --git a/backend/app/api/qc.py b/backend/app/api/qc.py index cffd592c..b3edf5b7 100644 --- a/backend/app/api/qc.py +++ b/backend/app/api/qc.py @@ -449,6 +449,7 @@ class TaskCompleteWithResultBody(BaseModel): third_party_attachments: Optional[str] = Field(None, alias="thirdPartyAttachments") material_usages: Optional[List[Dict[str, Any]]] = Field(None, alias="materialUsages") task_status: Optional[str] = Field(None, alias="taskStatus") + operate_batch_id: Optional[str] = Field(None, alias="operateBatchId") @router.get("/qc-lab-test-items") @@ -1438,6 +1439,7 @@ async def complete_task_with_result( operator_user_name=str(user.get("nickName") or user.get("nick_name") or ""), before=before, after=after, + operate_batch_id=body.operate_batch_id, ) db.commit() db.refresh(obj) diff --git a/backend/app/crud/qc_task_result_change_log.py b/backend/app/crud/qc_task_result_change_log.py index d932e5ef..27b72f8d 100644 --- a/backend/app/crud/qc_task_result_change_log.py +++ b/backend/app/crud/qc_task_result_change_log.py @@ -144,12 +144,14 @@ def append_task_result_change_log( before: Dict[str, Any], after: Dict[str, Any], operate_time: Optional[datetime] = None, + operate_batch_id: Optional[str] = None, ) -> BizQcTaskResultChangeLog: """追加一条检测结果保存留痕(不 commit)。无字段差异也写入。""" now = operate_time or datetime.now() changes = build_result_changes(before, after) has_change = "1" if changes else "0" name = _resolve_operator_name(db, user_id, operator_user_name) + batch_id = _norm_text(operate_batch_id) or None obj = BizQcTaskResultChangeLog( id=generate_uuid(), task_id=task.id, @@ -159,6 +161,7 @@ def append_task_result_change_log( operate_time=now, operator_user_id=user_id, operator_user_name=name or None, + operate_batch_id=batch_id, has_field_change=has_change, changes_json=json.dumps(changes, ensure_ascii=False), tenant_no=tenant_no, @@ -194,6 +197,7 @@ def _row_to_dict(row: BizQcTaskResultChangeLog) -> Dict[str, Any]: "operateTime": _fmt_dt(row.operate_time), "operatorUserId": row.operator_user_id or "", "operatorUserName": row.operator_user_name or "", + "operateBatchId": row.operate_batch_id or "", "hasFieldChange": row.has_field_change == "1", "changes": changes, "createTime": _fmt_dt(row.create_time), diff --git a/backend/app/models/models.py b/backend/app/models/models.py index 7fb1eaf9..ea32bd44 100644 --- a/backend/app/models/models.py +++ b/backend/app/models/models.py @@ -2407,6 +2407,7 @@ class BizQcTaskResultChangeLog(Base): operate_time = Column(DateTime, nullable=False, comment="业务操作时间") operator_user_id = Column(String(64), nullable=True, comment="操作人用户ID") operator_user_name = Column(String(64), nullable=True, comment="操作人姓名快照") + operate_batch_id = Column(String(64), nullable=True, comment="同一次保存批次ID(多任务共用)") has_field_change = Column(CHAR(1), nullable=False, default="0", comment="1有字段变更 0仅保存无变更") changes_json = Column(Text, nullable=True, comment="变更明细JSON") tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号") diff --git a/docs/sql/migrations/2026-11-20-qc-task-result-change-log-batch-id.sql b/docs/sql/migrations/2026-11-20-qc-task-result-change-log-batch-id.sql new file mode 100644 index 00000000..265bd3db --- /dev/null +++ b/docs/sql/migrations/2026-11-20-qc-task-result-change-log-batch-id.sql @@ -0,0 +1,8 @@ +-- 质检检测结果留痕:同一次批量保存共用 operate_batch_id(Issue #153) +-- 历史行可为空;前端对无批次号的旧数据做短时窗口合并兜底。 + +ALTER TABLE `biz_qc_task_result_change_log` + ADD COLUMN `operate_batch_id` varchar(64) DEFAULT NULL COMMENT '同一次保存批次ID(多任务共用)' AFTER `operator_user_name`; + +ALTER TABLE `biz_qc_task_result_change_log` + ADD KEY `idx_qc_result_chg_batch` (`tenant_no`, `operate_batch_id`, `del_flag`); diff --git a/web-admin/src/api/qc-task-result.ts b/web-admin/src/api/qc-task-result.ts index 5ac3f3d7..58d31fa8 100644 --- a/web-admin/src/api/qc-task-result.ts +++ b/web-admin/src/api/qc-task-result.ts @@ -51,6 +51,7 @@ export function fetchCompleteTaskWithResult( remark?: string thirdPartyAttachments?: string taskStatus?: 'dzx' | 'jxz' | 'ywc' + operateBatchId?: string materialUsages?: Array<{ requisitionUsageId: string qty: number @@ -83,6 +84,7 @@ export type QcTaskResultChangeLog = { operateTime: string operatorUserId?: string operatorUserName?: string + operateBatchId?: string hasFieldChange: boolean changes: QcTaskResultChangeItem[] createTime?: string diff --git a/web-admin/src/views/quality-inspection/qc-work-order/QcCompanyTaskResultDialog.vue b/web-admin/src/views/quality-inspection/qc-work-order/QcCompanyTaskResultDialog.vue index 6cdeea6a..4a822096 100644 --- a/web-admin/src/views/quality-inspection/qc-work-order/QcCompanyTaskResultDialog.vue +++ b/web-admin/src/views/quality-inspection/qc-work-order/QcCompanyTaskResultDialog.vue @@ -380,6 +380,11 @@ const thirdPartyAttachments = financeAttachmentsToUrlString(attachments.value) const remarkVal = remark.value + // 同一次批量保存共用批次号,修改记录弹窗合并为一个时间线节点 + const operateBatchId = + typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function' + ? crypto.randomUUID().replace(/-/g, '').toUpperCase() + : `BATCH${Date.now()}${Math.random().toString(16).slice(2, 10)}`.toUpperCase() saving.value = true const failures: string[] = [] let successCount = 0 @@ -399,7 +404,8 @@ })), remark: remarkVal, thirdPartyAttachments, - taskStatus: item.saveStatus + taskStatus: item.saveStatus, + operateBatchId }, props.operateScope ) diff --git a/web-admin/src/views/quality-inspection/qc-work-order/QcTaskResultChangeLogDialog.vue b/web-admin/src/views/quality-inspection/qc-work-order/QcTaskResultChangeLogDialog.vue index 4039b08c..15e7da32 100644 --- a/web-admin/src/views/quality-inspection/qc-work-order/QcTaskResultChangeLogDialog.vue +++ b/web-admin/src/views/quality-inspection/qc-work-order/QcTaskResultChangeLogDialog.vue @@ -14,39 +14,112 @@ >
-
+
- +
- {{ entry.operateTime || '—' }} · {{ entry.operatorUserName || '—' }} -