58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
export const LAB_STORAGE_CODE_PLACEHOLDER = '{lab_storage_code}'
|
|
|
|
export type ProductionTaskSetItemPreview = {
|
|
taskName: string
|
|
routeId: string
|
|
routeName: string
|
|
description: string
|
|
remark: string
|
|
}
|
|
|
|
export function revertTaskNamePlaceholders(
|
|
taskName: string,
|
|
labStorageCode?: string | null
|
|
): string {
|
|
const text = String(taskName || '')
|
|
const code = String(labStorageCode || '').trim()
|
|
if (!code) return text
|
|
return text.split(code).join(LAB_STORAGE_CODE_PLACEHOLDER)
|
|
}
|
|
|
|
export function mapWorkOrderTasksToSetItems(
|
|
tasks: Record<string, any>[] | undefined,
|
|
options?: { labStorageCode?: string | null }
|
|
): {
|
|
items: ProductionTaskSetItemPreview[]
|
|
skippedEmptyNameCount: number
|
|
} {
|
|
const labStorageCode = options?.labStorageCode
|
|
const items: ProductionTaskSetItemPreview[] = []
|
|
let skippedEmptyNameCount = 0
|
|
for (const row of tasks || []) {
|
|
const taskName = String(row.taskName || '').trim()
|
|
if (!taskName) {
|
|
skippedEmptyNameCount += 1
|
|
continue
|
|
}
|
|
items.push({
|
|
taskName: revertTaskNamePlaceholders(taskName, labStorageCode),
|
|
routeId: String(row.routeId || '').trim(),
|
|
routeName: String(row.routeName || '').trim(),
|
|
description: String(row.description || '').trim(),
|
|
remark: String(row.remark || '').trim()
|
|
})
|
|
}
|
|
return { items, skippedEmptyNameCount }
|
|
}
|
|
|
|
export function resolveWorkOrderLabStorageCode(
|
|
row: Record<string, any> | null | undefined
|
|
): string {
|
|
if (!row) return ''
|
|
const fromRow = String(row.labStorageCode || '').trim()
|
|
if (fromRow) return fromRow
|
|
return String(
|
|
(row.reception as Record<string, any> | undefined)?.labStorageCode || ''
|
|
).trim()
|
|
}
|