70 lines
2.8 KiB
TypeScript
70 lines
2.8 KiB
TypeScript
/**
|
|
* 完成工单前置校验 — 纯逻辑(无 API 依赖,便于单测)。
|
|
*/
|
|
import type { ProductionWorkOrderItem } from '@/api/production-work-order'
|
|
import { extractProductionTaskSteps } from '@/utils/production-labels'
|
|
|
|
export function needsProductionReceptionGate(row: ProductionWorkOrderItem): boolean {
|
|
// 仅入库生产(细胞存储/科研捐赠)需要生产接收登记;扩增传代(temporary)、出库等不需要。
|
|
// 注意:临时工单 DB 默认 reception_source=cell_storage,不可仅凭来源判断。
|
|
const woType = String(row.workOrderType || 'inbound').trim() || 'inbound'
|
|
if (woType !== 'inbound') return false
|
|
const src = String(row.receptionSource || '').trim()
|
|
return src === 'cell_storage' || src === 'research_donation'
|
|
}
|
|
|
|
export type CompleteWorkOrderTaskListDecision =
|
|
| { kind: 'no_tasks' }
|
|
| { kind: 'all_done' }
|
|
| { kind: 'check_incomplete'; incomplete: Record<string, any>[] }
|
|
|
|
/** 完成工单任务门禁:无任务拦截;仅剩已完成/已作废则放行;否则校验未完成任务步骤。 */
|
|
export function classifyTasksForCompleteWorkOrderGate(
|
|
tasks: Record<string, any>[]
|
|
): CompleteWorkOrderTaskListDecision {
|
|
const list = Array.isArray(tasks) ? tasks : []
|
|
if (!list.length) return { kind: 'no_tasks' }
|
|
const incomplete = list.filter((t) => {
|
|
const status = String(t.taskStatus || '').trim()
|
|
return status !== 'yzf' && status !== 'ywc'
|
|
})
|
|
if (!incomplete.length) return { kind: 'all_done' }
|
|
return { kind: 'check_incomplete', incomplete }
|
|
}
|
|
|
|
export function findTaskStepGateIssue(detail: Record<string, any>): {
|
|
message: string
|
|
stepId?: string
|
|
} | null {
|
|
const steps = extractProductionTaskSteps(detail)
|
|
for (const step of steps) {
|
|
const processName = String(step.processName || '').trim() || '未命名步骤'
|
|
const assigneeIds = Array.isArray(step.assigneeUserIds) ? step.assigneeUserIds : []
|
|
if (!assigneeIds.length) {
|
|
return {
|
|
message: `请先为步骤「${processName}」指定负责人`,
|
|
stepId: step.id ? String(step.id) : undefined
|
|
}
|
|
}
|
|
if (!String(step.plannedStartTime || '').trim()) {
|
|
return {
|
|
message: `请先为步骤「${processName}」填写计划开始时间`,
|
|
stepId: step.id ? String(step.id) : undefined
|
|
}
|
|
}
|
|
const outputs = Array.isArray(step.outputs) ? step.outputs : []
|
|
for (const out of outputs) {
|
|
if (!String(out?.outputBarcode || '').trim()) {
|
|
const outputName = String(out?.outputName || '').trim()
|
|
return {
|
|
message: outputName
|
|
? `请补全步骤「${processName}」产出物「${outputName}」的条码`
|
|
: `请补全步骤「${processName}」产出物条码`,
|
|
stepId: step.id ? String(step.id) : undefined
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null
|
|
}
|