import type { QcWorkOrder } from '@/api/qc-work-order' const INBOUND_SAMPLE_SOURCES = new Set(['cell_storage', 'research_donation']) function isInboundSampleWorkOrder(row: QcWorkOrder) { if ((row.workOrderType || 'inbound') !== 'inbound') return false return INBOUND_SAMPLE_SOURCES.has((row.receptionSource || '').trim()) } /** 入库样本组勾选/导出:按 receptionSource + sampleCode 聚合 sibling 工单 */ export function resolveInboundSampleSelectionKey(row: QcWorkOrder): string { const sampleCode = (row.sampleCode || '').trim() if (!sampleCode) return row.id const source = (row.receptionSource || 'cell_storage').trim() return `${source}:${sampleCode}` } export function collectInboundSampleSiblingIds( workOrderId: string, rows: QcWorkOrder[] ): string[] { const row = rows.find((item) => item.id === workOrderId) if (!row || !isInboundSampleWorkOrder(row)) return [workOrderId] const key = resolveInboundSampleSelectionKey(row) const siblingIds = rows .filter((item) => isInboundSampleWorkOrder(item) && resolveInboundSampleSelectionKey(item) === key) .map((item) => item.id) return siblingIds.length ? siblingIds : [workOrderId] } export function expandInboundWorkOrderIdsForExport( selectedIds: string[], rows: QcWorkOrder[] ): string[] { const expanded = new Set() for (const id of selectedIds) { for (const siblingId of collectInboundSampleSiblingIds(id, rows)) { expanded.add(siblingId) } } return [...expanded] }