fix(web-admin): 恢复采集大表导出并按运费批次归拢合并
去掉临时隐藏开关,导出自存/科研表时先按运费批次聚拢再合并单元格。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
95d6b6025f
commit
3ac30a6c2c
5 files changed
+152
-26
No files matched your search
@@ -1,8 +1,5 @@
|
||||
import type { ProtocolAuditFlatRow } from './protocol-audit-flatten'
|
||||
|
||||
/** 采集大表导出入口开关;验收未完成前隐藏按钮,改 true 即可恢复。 */
|
||||
export const COLLECTION_LEDGER_EXPORT_ENABLED = false
|
||||
|
||||
type Row = Record<string, unknown>
|
||||
type PayDetail = {
|
||||
installmentNo?: number | null
|
||||
@@ -341,6 +338,36 @@ function researchMaternalBloodText(value: unknown): string {
|
||||
return text(value) ? text(value) : '无母血'
|
||||
}
|
||||
|
||||
/**
|
||||
* 将同一运费批次的行聚拢到一起(按首次出现顺序),无批次行保持相对位置。
|
||||
* 模版要求同批次运输方式/运费合并单元格,故导出前先归拢再合并。
|
||||
*/
|
||||
export function groupFlatRowsByFreightBatch(
|
||||
rows: ProtocolAuditFlatRow[]
|
||||
): ProtocolAuditFlatRow[] {
|
||||
const groups = new Map<string, ProtocolAuditFlatRow[]>()
|
||||
const sequence: Array<{ kind: 'batch'; id: string } | { kind: 'single'; row: ProtocolAuditFlatRow }> =
|
||||
[]
|
||||
for (const row of rows) {
|
||||
const freightId = text(row.freightId)
|
||||
if (!freightId) {
|
||||
sequence.push({ kind: 'single', row })
|
||||
continue
|
||||
}
|
||||
if (!groups.has(freightId)) {
|
||||
groups.set(freightId, [])
|
||||
sequence.push({ kind: 'batch', id: freightId })
|
||||
}
|
||||
groups.get(freightId)!.push(row)
|
||||
}
|
||||
const arranged: ProtocolAuditFlatRow[] = []
|
||||
for (const item of sequence) {
|
||||
if (item.kind === 'single') arranged.push(item.row)
|
||||
else arranged.push(...(groups.get(item.id) || []))
|
||||
}
|
||||
return arranged
|
||||
}
|
||||
|
||||
/**
|
||||
* 相邻且 freightId 相同的导出行,合并运输方式/运费列(Excel 行号含表头)。
|
||||
* @param transportCol 运输方式列(1-based)
|
||||
@@ -626,9 +653,10 @@ export function buildCellStorageLedgerRows(rows: ProtocolAuditFlatRow[]): {
|
||||
rows: string[][]
|
||||
merges: LedgerMergeRange[]
|
||||
} {
|
||||
const freightIds = rows.map((row) => text(row.freightId))
|
||||
const built = rows.map((row, index) => storageLedgerRow(row, index, false))
|
||||
// 自存表:运输方式=53,运费=54
|
||||
const arranged = groupFlatRowsByFreightBatch(rows)
|
||||
const freightIds = arranged.map((row) => text(row.freightId))
|
||||
const built = arranged.map((row, index) => storageLedgerRow(row, index, false))
|
||||
// 自存表:运输方式=53,运费=54(对齐模版《自存表》)
|
||||
return { rows: built, merges: applyFreightMerges(built, freightIds, 53, 54) }
|
||||
}
|
||||
|
||||
@@ -636,9 +664,10 @@ export function buildResearchLedgerRows(rows: ProtocolAuditFlatRow[]): {
|
||||
rows: string[][]
|
||||
merges: LedgerMergeRange[]
|
||||
} {
|
||||
const freightIds = rows.map((row) => text(row.freightId))
|
||||
const built = rows.map((row, index) => storageLedgerRow(row, index, true))
|
||||
// 科研表:运输方式=17,运费=18
|
||||
const arranged = groupFlatRowsByFreightBatch(rows)
|
||||
const freightIds = arranged.map((row) => text(row.freightId))
|
||||
const built = arranged.map((row, index) => storageLedgerRow(row, index, true))
|
||||
// 科研表:运输方式=17,运费=18(对齐模版《科研表》)
|
||||
return { rows: built, merges: applyFreightMerges(built, freightIds, 17, 18) }
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user