feat: 增加顺丰月结列表,支持导出、结算和补填运费

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-10-21 20:17:45 +08:00
1 parent 77e8c78cb6
commit a81f177cb6
4 files changed
+532

No files matched your search

@@ -0,0 +1,17 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { buildSfExpressExportRows } from './sf-express-settlement-export.ts'
test('export rows match the settlement list columns', () => {
const rows = buildSfExpressExportRows([
{
waybillNo: '',
createByName: '张三',
createTime: '2026-10-21 09:00:00',
settleStatusLabel: '未结算',
freightAmountLabel: '月结',
settleTime: ''
}
])
assert.deepEqual(rows[0], ['—', '张三', '2026-10-21 09:00:00', '未结算', '月结', '—'])
})
@@ -0,0 +1,30 @@
import ExcelJS from 'exceljs'
import FileSaver from 'file-saver'
const HEADERS = ['顺丰单号', '创建人', '创建时间', '结算状态', '运费', '结算时间']
export function buildSfExpressExportRows(list: Array<Record<string, string>>) {
return list.map((row) => [
row.waybillNo || '—',
row.createByName || '—',
row.createTime || '—',
row.settleStatusLabel || '—',
row.freightAmountLabel || '—',
row.settleTime || '—'
])
}
export async function saveSfExpressSettlementWorkbook(list: Array<Record<string, string>>) {
const workbook = new ExcelJS.Workbook()
const sheet = workbook.addWorksheet('顺丰月结')
sheet.addRow(HEADERS)
buildSfExpressExportRows(list).forEach((line) => sheet.addRow(line))
const buffer = await workbook.xlsx.writeBuffer()
const blob = new Blob([buffer], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
})
const stamp = new Date()
const pad = (value: number) => String(value).padStart(2, '0')
const name = `顺丰月结-${stamp.getFullYear()}${pad(stamp.getMonth() + 1)}${pad(stamp.getDate())}${pad(stamp.getHours())}${pad(stamp.getMinutes())}${pad(stamp.getSeconds())}.xlsx`
FileSaver.saveAs(blob, name)
}