提交
This commit is contained in:
1 parent
03226cac2a
commit
195c89e6b7
34 files changed
+7360
-5462
No files matched your search
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 完成工单前置校验 — 纯逻辑(无 API 依赖,便于单测)。
|
||||
*/
|
||||
import type { ProductionWorkOrderItem } from '@/api/production-work-order'
|
||||
import { extractProductionTaskSteps } from '@/utils/production-labels'
|
||||
|
||||
export function needsProductionReceptionGate(row: ProductionWorkOrderItem): boolean {
|
||||
const src = String(row.receptionSource || '').trim()
|
||||
return src === 'cell_storage' || src === 'research_donation'
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
findTaskStepGateIssue,
|
||||
needsProductionReceptionGate
|
||||
} from './production-complete-work-order-gate-logic'
|
||||
|
||||
describe('needsProductionReceptionGate', () => {
|
||||
it('true for cell_storage and research_donation', () => {
|
||||
assert.equal(needsProductionReceptionGate({ receptionSource: 'cell_storage' } as any), true)
|
||||
assert.equal(
|
||||
needsProductionReceptionGate({ receptionSource: 'research_donation' } as any),
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
it('false for outbound/temporary', () => {
|
||||
assert.equal(needsProductionReceptionGate({ receptionSource: 'outbound' } as any), false)
|
||||
assert.equal(needsProductionReceptionGate({} as any), false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('findTaskStepGateIssue', () => {
|
||||
it('requires assignee', () => {
|
||||
const issue = findTaskStepGateIssue({
|
||||
steps: [{ id: 's1', processName: '分离', assigneeUserIds: [], plannedStartTime: '2026-01-01' }]
|
||||
})
|
||||
assert.ok(issue)
|
||||
assert.match(issue!.message, /负责人/)
|
||||
assert.equal(issue!.stepId, 's1')
|
||||
})
|
||||
|
||||
it('requires planned start time', () => {
|
||||
const issue = findTaskStepGateIssue({
|
||||
steps: [{ id: 's1', processName: '分离', assigneeUserIds: ['u1'], plannedStartTime: '' }]
|
||||
})
|
||||
assert.ok(issue)
|
||||
assert.match(issue!.message, /计划开始时间/)
|
||||
})
|
||||
|
||||
it('requires barcode on existing output rows', () => {
|
||||
const issue = findTaskStepGateIssue({
|
||||
steps: [
|
||||
{
|
||||
id: 's1',
|
||||
processName: '分离',
|
||||
assigneeUserIds: ['u1'],
|
||||
plannedStartTime: '2026-01-01',
|
||||
outputs: [{ outputName: '细胞袋', outputBarcode: '' }]
|
||||
}
|
||||
]
|
||||
})
|
||||
assert.ok(issue)
|
||||
assert.match(issue!.message, /条码/)
|
||||
})
|
||||
|
||||
it('allows empty outputs', () => {
|
||||
assert.equal(
|
||||
findTaskStepGateIssue({
|
||||
steps: [
|
||||
{
|
||||
id: 's1',
|
||||
processName: '分离',
|
||||
assigneeUserIds: ['u1'],
|
||||
plannedStartTime: '2026-01-01',
|
||||
outputs: []
|
||||
}
|
||||
]
|
||||
}),
|
||||
null
|
||||
)
|
||||
})
|
||||
|
||||
it('passes when all filled', () => {
|
||||
assert.equal(
|
||||
findTaskStepGateIssue({
|
||||
steps: [
|
||||
{
|
||||
id: 's1',
|
||||
processName: '分离',
|
||||
assigneeUserIds: ['u1'],
|
||||
plannedStartTime: '2026-01-01',
|
||||
outputs: [{ outputName: '细胞袋', outputBarcode: 'BC-1' }]
|
||||
}
|
||||
]
|
||||
}),
|
||||
null
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* 完成工单前置校验:生产接收登记 + 步骤负责人/计划开始时间/产出物条码。
|
||||
*/
|
||||
import type { ProductionWorkOrderItem } from '@/api/production-work-order'
|
||||
import {
|
||||
fetchProductionTaskDetail,
|
||||
fetchProductionTaskList
|
||||
} from '@/api/production-task'
|
||||
import { fetchProductionReceptionBySampleCode } from '@/api/sample-production-reception'
|
||||
import {
|
||||
findTaskStepGateIssue,
|
||||
needsProductionReceptionGate
|
||||
} from '@/utils/production-complete-work-order-gate-logic'
|
||||
|
||||
export {
|
||||
findTaskStepGateIssue,
|
||||
needsProductionReceptionGate
|
||||
} from '@/utils/production-complete-work-order-gate-logic'
|
||||
|
||||
export type CompleteWorkOrderGateOk = { ok: true }
|
||||
|
||||
export type CompleteWorkOrderGateBlock =
|
||||
| { ok: false; action: 'sample_reception'; message: string }
|
||||
| { ok: false; action: 'no_tasks'; message: string }
|
||||
| {
|
||||
ok: false
|
||||
action: 'open_task_execution'
|
||||
message: string
|
||||
taskId: string
|
||||
taskName: string
|
||||
stepId?: string
|
||||
}
|
||||
|
||||
export type CompleteWorkOrderGateResult = CompleteWorkOrderGateOk | CompleteWorkOrderGateBlock
|
||||
|
||||
export async function checkCompleteProductionWorkOrderGate(
|
||||
row: ProductionWorkOrderItem
|
||||
): Promise<CompleteWorkOrderGateResult> {
|
||||
if (needsProductionReceptionGate(row)) {
|
||||
const sampleCode = String(row.sampleCode || '').trim()
|
||||
if (!sampleCode) {
|
||||
return {
|
||||
ok: false,
|
||||
action: 'sample_reception',
|
||||
message: '缺少样本编码,无法校验生产接收登记,请先完善样本信息'
|
||||
}
|
||||
}
|
||||
const receptionRes = await fetchProductionReceptionBySampleCode({
|
||||
sampleCode,
|
||||
sourceType: row.receptionSource
|
||||
})
|
||||
const acceptConclusion = String(receptionRes?.qcReception?.acceptConclusion || '').trim()
|
||||
if (acceptConclusion && acceptConclusion !== 'js') {
|
||||
// 质检拒收等:无需生产接收登记
|
||||
} else {
|
||||
const prod = receptionRes?.productionReception
|
||||
if (!prod || !String(prod.id || '').trim()) {
|
||||
return {
|
||||
ok: false,
|
||||
action: 'sample_reception',
|
||||
message: '请先填写生产接收登记'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const tasksRes = await fetchProductionTaskList({
|
||||
workOrderId: row.id,
|
||||
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) {
|
||||
return {
|
||||
ok: false,
|
||||
action: 'no_tasks',
|
||||
message: '请先派发生产任务后再完成工单'
|
||||
}
|
||||
}
|
||||
|
||||
const details = await Promise.all(
|
||||
tasks.map((t: Record<string, any>) => fetchProductionTaskDetail(String(t.id)))
|
||||
)
|
||||
|
||||
for (let i = 0; i < details.length; i++) {
|
||||
const detail = details[i] || {}
|
||||
const task = tasks[i] || {}
|
||||
const issue = findTaskStepGateIssue(detail)
|
||||
if (!issue) continue
|
||||
return {
|
||||
ok: false,
|
||||
action: 'open_task_execution',
|
||||
message: issue.message,
|
||||
taskId: String(detail.id || task.id || ''),
|
||||
taskName: String(detail.taskName || task.taskName || ''),
|
||||
stepId: issue.stepId
|
||||
}
|
||||
}
|
||||
|
||||
return { ok: true }
|
||||
}
|
||||
@@ -4,7 +4,11 @@ import {
|
||||
buildTaskListDisplayItems,
|
||||
pickSharedRemarkAndAttachments,
|
||||
companyGroupProgress,
|
||||
uniqueAssigneeNames
|
||||
uniqueAssigneeNames,
|
||||
sortThirdPartyTasksByCompany,
|
||||
allThirdPartyCardSubtitle,
|
||||
thirdPartyCompanyDisplayName,
|
||||
countDistinctThirdPartyCompanies
|
||||
} from './qc-company-task-group'
|
||||
|
||||
type TestQcTask = {
|
||||
@@ -36,7 +40,7 @@ function task(partial: Partial<TestQcTask> & Pick<TestQcTask, 'id' | 'taskType'>
|
||||
}
|
||||
|
||||
describe('buildTaskListDisplayItems', () => {
|
||||
it('keeps lab tasks as single cards and groups third-party by companyId', () => {
|
||||
it('keeps lab tasks as single cards and merges all third-party into one card', () => {
|
||||
const tasks = [
|
||||
task({ id: 'l1', taskType: 'sysz', itemName: '无菌' }),
|
||||
task({
|
||||
@@ -59,30 +63,71 @@ describe('buildTaskListDisplayItems', () => {
|
||||
companyId: 'c2',
|
||||
companyName: '迪安',
|
||||
itemName: 'HIV'
|
||||
})
|
||||
}),
|
||||
task({ id: 't0', taskType: 'dsfjc', companyId: '', companyName: '', itemName: '孤儿' })
|
||||
]
|
||||
const items = buildTaskListDisplayItems(tasks)
|
||||
assert.equal(items.length, 3)
|
||||
assert.equal(items.length, 2)
|
||||
assert.equal(items[0].kind, 'lab')
|
||||
assert.equal(items[0].kind === 'lab' && items[0].task.id, 'l1')
|
||||
assert.equal(items[1].kind, 'company')
|
||||
if (items[1].kind === 'company') {
|
||||
assert.equal(items[1].companyId, 'c1')
|
||||
assert.equal(items[1].tasks.length, 2)
|
||||
}
|
||||
assert.equal(items[2].kind, 'company')
|
||||
if (items[2].kind === 'company') {
|
||||
assert.equal(items[2].companyId, 'c2')
|
||||
assert.equal(items[1].kind, 'all-third')
|
||||
if (items[1].kind === 'all-third') {
|
||||
assert.equal(items[1].tasks.length, 4)
|
||||
assert.deepEqual(
|
||||
items[1].tasks.map((t) => t.id),
|
||||
['t1', 't2', 't3', 't0']
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('falls back to single lab-like card when third-party has empty companyId', () => {
|
||||
it('merges orphan third-party into all-third card', () => {
|
||||
const tasks = [
|
||||
task({ id: 't0', taskType: 'dsfjc', companyId: '', companyName: '', itemName: '孤儿' })
|
||||
]
|
||||
const items = buildTaskListDisplayItems(tasks)
|
||||
assert.equal(items.length, 1)
|
||||
assert.equal(items[0].kind, 'orphan-third')
|
||||
assert.equal(items[0].kind, 'all-third')
|
||||
if (items[0].kind === 'all-third') {
|
||||
assert.equal(items[0].tasks[0].id, 't0')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('sortThirdPartyTasksByCompany', () => {
|
||||
it('groups by company first-seen order and puts orphans last', () => {
|
||||
const sorted = sortThirdPartyTasksByCompany([
|
||||
task({ id: 'a1', taskType: 'dsfjc', companyId: 'c2', companyName: '迪安' }),
|
||||
task({ id: 'o1', taskType: 'dsfjc', companyId: '' }),
|
||||
task({ id: 'b1', taskType: 'dsfjc', companyId: 'c1', companyName: '金域' }),
|
||||
task({ id: 'a2', taskType: 'dsfjc', companyId: 'c2', companyName: '迪安' }),
|
||||
task({ id: 'b2', taskType: 'dsfjc', companyId: 'c1', companyName: '金域' })
|
||||
])
|
||||
assert.deepEqual(
|
||||
sorted.map((t) => t.id),
|
||||
['a1', 'a2', 'b1', 'b2', 'o1']
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('allThirdPartyCardSubtitle / company helpers', () => {
|
||||
it('counts distinct companies excluding unassigned', () => {
|
||||
const tasks = [
|
||||
task({ id: '1', taskType: 'dsfjc', companyId: 'c1', companyName: '金域' }),
|
||||
task({ id: '2', taskType: 'dsfjc', companyId: 'c1', companyName: '金域' }),
|
||||
task({ id: '3', taskType: 'dsfjc', companyId: 'c2', companyName: '迪安' }),
|
||||
task({ id: '4', taskType: 'dsfjc', companyId: '' })
|
||||
]
|
||||
assert.equal(countDistinctThirdPartyCompanies(tasks), 2)
|
||||
assert.equal(allThirdPartyCardSubtitle(tasks), '第三方 · 4 个检测项目 · 2 家公司')
|
||||
assert.equal(
|
||||
allThirdPartyCardSubtitle([task({ id: '4', taskType: 'dsfjc', companyId: '' })]),
|
||||
'第三方 · 1 个检测项目'
|
||||
)
|
||||
assert.equal(thirdPartyCompanyDisplayName({ companyId: '', companyName: '' }), '未归属公司')
|
||||
assert.equal(
|
||||
thirdPartyCompanyDisplayName({ companyId: 'c1', companyName: '金域' }),
|
||||
'金域'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,58 +1,86 @@
|
||||
import type { QcTask } from '../api/qc-task'
|
||||
|
||||
export type QcTaskListLabItem = { kind: 'lab'; task: QcTask }
|
||||
export type QcTaskListOrphanThirdItem = { kind: 'orphan-third'; task: QcTask }
|
||||
export type QcTaskListCompanyItem = {
|
||||
kind: 'company'
|
||||
companyId: string
|
||||
companyName: string
|
||||
tasks: QcTask[]
|
||||
}
|
||||
export type QcTaskListDisplayItem =
|
||||
| QcTaskListLabItem
|
||||
| QcTaskListOrphanThirdItem
|
||||
| QcTaskListCompanyItem
|
||||
/** 批次内全部第三方任务合一卡 */
|
||||
export type QcTaskListAllThirdItem = { kind: 'all-third'; tasks: QcTask[] }
|
||||
export type QcTaskListDisplayItem = QcTaskListLabItem | QcTaskListAllThirdItem
|
||||
|
||||
export const UNASSIGNED_THIRD_PARTY_COMPANY_LABEL = '未归属公司'
|
||||
export const ALL_THIRD_PARTY_CARD_TITLE = '第三方质检项目'
|
||||
|
||||
function trimId(v?: string) {
|
||||
return (v || '').trim()
|
||||
}
|
||||
|
||||
/** 自检卡在前(原序);有 companyId 的第三方按首次出现公司顺序分组;无 companyId 降级为 orphan-third */
|
||||
export function buildTaskListDisplayItems(tasks: QcTask[]): QcTaskListDisplayItem[] {
|
||||
const lab: QcTaskListDisplayItem[] = []
|
||||
const orphans: QcTaskListDisplayItem[] = []
|
||||
const companyOrder: string[] = []
|
||||
const companyMap = new Map<string, QcTaskListCompanyItem>()
|
||||
export function thirdPartyCompanyDisplayName(task: Pick<QcTask, 'companyId' | 'companyName'>): string {
|
||||
if (!trimId(task.companyId)) return UNASSIGNED_THIRD_PARTY_COMPANY_LABEL
|
||||
return (task.companyName || '').trim() || UNASSIGNED_THIRD_PARTY_COMPANY_LABEL
|
||||
}
|
||||
|
||||
/** 有非空 companyId 的去重公司数(不含未归属) */
|
||||
export function countDistinctThirdPartyCompanies(tasks: QcTask[]): number {
|
||||
const ids = new Set<string>()
|
||||
for (const t of tasks || []) {
|
||||
if ((t.taskType || '').trim() === 'sysz') {
|
||||
lab.push({ kind: 'lab', task: t })
|
||||
continue
|
||||
}
|
||||
if ((t.taskType || '').trim() !== 'dsfjc') {
|
||||
lab.push({ kind: 'lab', task: t })
|
||||
continue
|
||||
}
|
||||
const cid = trimId(t.companyId)
|
||||
if (cid) ids.add(cid)
|
||||
}
|
||||
return ids.size
|
||||
}
|
||||
|
||||
export function allThirdPartyCardSubtitle(tasks: QcTask[]): string {
|
||||
const list = tasks || []
|
||||
const n = list.length
|
||||
const m = countDistinctThirdPartyCompanies(list)
|
||||
if (m > 0) return `第三方 · ${n} 个检测项目 · ${m} 家公司`
|
||||
return `第三方 · ${n} 个检测项目`
|
||||
}
|
||||
|
||||
/**
|
||||
* 先按公司首次出现顺序分组,组内保持原序;无 companyId 的「未归属公司」组放最后。
|
||||
*/
|
||||
export function sortThirdPartyTasksByCompany(tasks: QcTask[]): QcTask[] {
|
||||
const list = [...(tasks || [])]
|
||||
const companyOrder: string[] = []
|
||||
const byCompany = new Map<string, QcTask[]>()
|
||||
const orphans: QcTask[] = []
|
||||
|
||||
for (const t of list) {
|
||||
const cid = trimId(t.companyId)
|
||||
if (!cid) {
|
||||
orphans.push({ kind: 'orphan-third', task: t })
|
||||
orphans.push(t)
|
||||
continue
|
||||
}
|
||||
let g = companyMap.get(cid)
|
||||
if (!g) {
|
||||
g = {
|
||||
kind: 'company',
|
||||
companyId: cid,
|
||||
companyName: (t.companyName || '').trim() || '第三方公司',
|
||||
tasks: []
|
||||
}
|
||||
companyMap.set(cid, g)
|
||||
if (!byCompany.has(cid)) {
|
||||
byCompany.set(cid, [])
|
||||
companyOrder.push(cid)
|
||||
}
|
||||
g.tasks.push(t)
|
||||
byCompany.get(cid)!.push(t)
|
||||
}
|
||||
|
||||
return [...lab, ...companyOrder.map((id) => companyMap.get(id)!), ...orphans]
|
||||
const sorted: QcTask[] = []
|
||||
for (const cid of companyOrder) {
|
||||
sorted.push(...(byCompany.get(cid) || []))
|
||||
}
|
||||
sorted.push(...orphans)
|
||||
return sorted
|
||||
}
|
||||
|
||||
/** 自检卡在前(原序);全部第三方(含无 companyId)合成一张 all-third 卡 */
|
||||
export function buildTaskListDisplayItems(tasks: QcTask[]): QcTaskListDisplayItem[] {
|
||||
const lab: QcTaskListDisplayItem[] = []
|
||||
const third: QcTask[] = []
|
||||
|
||||
for (const t of tasks || []) {
|
||||
if ((t.taskType || '').trim() === 'dsfjc') {
|
||||
third.push(t)
|
||||
continue
|
||||
}
|
||||
// sysz 及其他非第三方:按自检单卡展示(与旧逻辑一致)
|
||||
lab.push({ kind: 'lab', task: t })
|
||||
}
|
||||
|
||||
if (!third.length) return lab
|
||||
return [...lab, { kind: 'all-third', tasks: third }]
|
||||
}
|
||||
|
||||
export function companyGroupProgress(tasks: QcTask[]) {
|
||||
|
||||
@@ -13,10 +13,17 @@ function buildFallbackOptions(): Api.Dict.DictDataOption[] {
|
||||
return Object.entries(FALLBACK_LABELS).map(([value, label]) => ({ value, label }))
|
||||
}
|
||||
|
||||
let labelMap: Record<string, string> = { ...FALLBACK_LABELS }
|
||||
/** 响应式 labelMap:字典异步加载完成后触发依赖它的列表/标签重渲染 */
|
||||
const labelMapRef = shallowRef<Record<string, string>>({ ...FALLBACK_LABELS })
|
||||
let dictLoaded = false
|
||||
let loadPromise: Promise<void> | null = null
|
||||
|
||||
function ensureVoidTypeDictLoading(): void {
|
||||
if (!dictLoaded && !loadPromise) {
|
||||
void loadVoidTypeDict()
|
||||
}
|
||||
}
|
||||
|
||||
/** 作废类型下拉选项(响应式,供弹窗 v-for 绑定) */
|
||||
export const voidTypeOptionsRef = shallowRef<Api.Dict.DictDataOption[]>(buildFallbackOptions())
|
||||
|
||||
@@ -31,7 +38,7 @@ export async function loadVoidTypeDict(force = false): Promise<void> {
|
||||
try {
|
||||
const res = await fetchDictDataOptions(VOID_TYPE_DICT)
|
||||
voidTypeOptionsRef.value = res?.length ? res : buildFallbackOptions()
|
||||
labelMap = {
|
||||
labelMapRef.value = {
|
||||
...FALLBACK_LABELS,
|
||||
...Object.fromEntries(voidTypeOptionsRef.value.map((o) => [o.value, o.label]))
|
||||
}
|
||||
@@ -39,7 +46,7 @@ export async function loadVoidTypeDict(force = false): Promise<void> {
|
||||
} catch (e) {
|
||||
console.error('加载作废类型字典失败:', e)
|
||||
voidTypeOptionsRef.value = buildFallbackOptions()
|
||||
labelMap = { ...FALLBACK_LABELS }
|
||||
labelMapRef.value = { ...FALLBACK_LABELS }
|
||||
} finally {
|
||||
loadPromise = null
|
||||
}
|
||||
@@ -48,9 +55,11 @@ export async function loadVoidTypeDict(force = false): Promise<void> {
|
||||
}
|
||||
|
||||
export function resolveVoidTypeLabel(value: string): string {
|
||||
ensureVoidTypeDictLoading()
|
||||
const code = String(value || '').trim()
|
||||
if (!code) return ''
|
||||
return labelMap[code] || FALLBACK_LABELS[code] || code
|
||||
const map = labelMapRef.value
|
||||
return map[code] || FALLBACK_LABELS[code] || code
|
||||
}
|
||||
|
||||
export const voidTypeLabel = resolveVoidTypeLabel
|
||||
Reference in new issue
Block a user