提交
This commit is contained in:
1 parent
195c89e6b7
commit
d294ecad84
34 files changed
+8466
-7867
No files matched your search
@@ -9,6 +9,25 @@ export function needsProductionReceptionGate(row: ProductionWorkOrderItem): bool
|
||||
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
|
||||
|
||||
@@ -1,10 +1,43 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
classifyTasksForCompleteWorkOrderGate,
|
||||
findTaskStepGateIssue,
|
||||
needsProductionReceptionGate
|
||||
} from './production-complete-work-order-gate-logic'
|
||||
|
||||
describe('classifyTasksForCompleteWorkOrderGate', () => {
|
||||
it('no_tasks when list empty', () => {
|
||||
assert.deepEqual(classifyTasksForCompleteWorkOrderGate([]), { kind: 'no_tasks' })
|
||||
})
|
||||
|
||||
it('all_done when only completed or voided tasks remain', () => {
|
||||
assert.deepEqual(
|
||||
classifyTasksForCompleteWorkOrderGate([
|
||||
{ id: '1', taskStatus: 'ywc' },
|
||||
{ id: '2', taskStatus: 'yzf' }
|
||||
]),
|
||||
{ kind: 'all_done' }
|
||||
)
|
||||
})
|
||||
|
||||
it('check_incomplete returns unfinished tasks only', () => {
|
||||
const decision = classifyTasksForCompleteWorkOrderGate([
|
||||
{ id: '1', taskStatus: 'ywc' },
|
||||
{ id: '2', taskStatus: 'dpz' },
|
||||
{ id: '3', taskStatus: 'jxz' },
|
||||
{ id: '4', taskStatus: 'yzf' }
|
||||
])
|
||||
assert.equal(decision.kind, 'check_incomplete')
|
||||
if (decision.kind === 'check_incomplete') {
|
||||
assert.deepEqual(
|
||||
decision.incomplete.map((t) => t.id),
|
||||
['2', '3']
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('needsProductionReceptionGate', () => {
|
||||
it('true for cell_storage and research_donation', () => {
|
||||
assert.equal(needsProductionReceptionGate({ receptionSource: 'cell_storage' } as any), true)
|
||||
|
||||
@@ -8,11 +8,13 @@ import {
|
||||
} from '@/api/production-task'
|
||||
import { fetchProductionReceptionBySampleCode } from '@/api/sample-production-reception'
|
||||
import {
|
||||
classifyTasksForCompleteWorkOrderGate,
|
||||
findTaskStepGateIssue,
|
||||
needsProductionReceptionGate
|
||||
} from '@/utils/production-complete-work-order-gate-logic'
|
||||
|
||||
export {
|
||||
classifyTasksForCompleteWorkOrderGate,
|
||||
findTaskStepGateIssue,
|
||||
needsProductionReceptionGate
|
||||
} from '@/utils/production-complete-work-order-gate-logic'
|
||||
@@ -69,19 +71,19 @@ export async function checkCompleteProductionWorkOrderGate(
|
||||
pageSize: 100,
|
||||
includeStepSummary: true
|
||||
})
|
||||
const tasks = (tasksRes?.list || []).filter((t: Record<string, any>) => {
|
||||
const status = String(t.taskStatus || '').trim()
|
||||
return status !== 'yzf' && status !== 'ywc'
|
||||
})
|
||||
|
||||
if (!tasks.length) {
|
||||
const taskDecision = classifyTasksForCompleteWorkOrderGate(tasksRes?.list || [])
|
||||
if (taskDecision.kind === 'no_tasks') {
|
||||
return {
|
||||
ok: false,
|
||||
action: 'no_tasks',
|
||||
message: '请先派发生产任务后再完成工单'
|
||||
}
|
||||
}
|
||||
if (taskDecision.kind === 'all_done') {
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
const tasks = taskDecision.incomplete
|
||||
const details = await Promise.all(
|
||||
tasks.map((t: Record<string, any>) => fetchProductionTaskDetail(String(t.id)))
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user