fix: 报价表识别国家子区与左开右闭重量段
All checks were successful
Build and Deploy Front / deploy (push) Successful in 3m35s

国家列续填并拼澳大利亚一区等子区;按行生成重量段并消掉 0.301 类微间隙,避免跨国串段。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-11-25 09:57:16 +08:00
parent 1cb4631480
commit 74a30cd78d
6 changed files with 330 additions and 100 deletions

View File

@ -62,8 +62,9 @@ description: >-
### 重量 ### 重量
- 区间 `0-0.1` / `0.101-0.2` → `weightStart` + `weightEnd` - 区间 `0-0.1` / `0.101-0.2` → `weightStart` + `weightEnd`(按表内原样提取即可)
- 单点一口价 `0.5` → 至少填 `weightEnd=0.5`;`weightStart` 可留空由前端按有序上界补成 `(prev-end]` - 单点一口价 `0.5` → 至少填 `weightEnd=0.5`;`weightStart` 可留空由前端按有序上界补成 `(prev-end]`
- OMS 存左开右闭:前端会把 `0.05-0.3` + `0.301-1` 收成 `(0.05-0.3]`、`(0.3-1]`
- 不要输出偏远邮编清单或条款长文 - 不要输出偏远邮编清单或条款长文
## 硬规则 ## 硬规则

View File

@ -54,9 +54,12 @@ const SKILL_CORE = `你是 OMS「渠道报价表提取」助手:从单个 Exce
- flat:一口价(包裹重量点/段 → 总价),填 flatTotal;freightPerKg/handling* 为 null - flat:一口价(包裹重量点/段 → 总价),填 flatTotal;freightPerKg/handling* 为 null
- unit_plus_fee:运费 RMB/KG + 处理费/挂号费 RMB/票,填 freightPerKg / handlingPerShipment / registrationPerShipment - unit_plus_fee:运费 RMB/KG + 处理费/挂号费 RMB/票,填 freightPerKg / handlingPerShipment / registrationPerShipment
## 重量 ## 重量与分区
- 区间 0-0.1 → weightStart=0, weightEnd=0.1 - 区间 0-0.1 → weightStart=0, weightEnd=0.1
- 单点 0.5 → 至少 weightEnd=0.5;weightStart 可空 - 单点 0.5 → 至少 weightEnd=0.5;weightStart 可空
- 表内写成 0.05-0.3 / 0.301-1 时,仍按单元格提取起止;前端会收成左开右闭连续段 (0.05-0.3]、(0.3-1]
- 国家列向下合并时要续填;澳大利亚旁有「一区/二区」时 zoneHint 写成「澳大利亚一区」「澳大利亚二区」
- 各国重量段互不借用:英国不要输出澳大利亚的 0.02-0.25
## JSON schema ## JSON schema
{ {
@ -349,6 +352,28 @@ export type WorkbookSheetPreview = {
colCount: number colCount: number
} }
/** 裁掉 Excel 错误 used-range 造成的超宽空列(如 A1:XDT48) */
function trimSparseMatrixColumns(
matrix: (string | number | null)[][],
): (string | number | null)[][] {
if (!matrix?.length) return matrix
let last = 0
const probe = Math.min(matrix.length, 80)
for (let r = 0; r < probe; r++) {
const row = matrix[r] || []
for (let c = 0; c < row.length; c++) {
const v = row[c]
if (v != null && String(v).trim() !== '') last = Math.max(last, c)
}
}
const width = last + 1
if (width <= 0) return []
// 仅当明显稀疏膨胀时裁剪
const maxLen = matrix.reduce((m, r) => Math.max(m, (r || []).length), 0)
if (maxLen <= width + 8) return matrix
return matrix.map((r) => (r || []).slice(0, width))
}
/** 浏览器端解析 xlsx → 各 sheet 预览 */ /** 浏览器端解析 xlsx → 各 sheet 预览 */
export async function parseQuoteWorkbook(file: File | ArrayBuffer): Promise<WorkbookSheetPreview[]> { export async function parseQuoteWorkbook(file: File | ArrayBuffer): Promise<WorkbookSheetPreview[]> {
const XLSX = await import('xlsx') const XLSX = await import('xlsx')
@ -357,11 +382,12 @@ export async function parseQuoteWorkbook(file: File | ArrayBuffer): Promise<Work
const out: WorkbookSheetPreview[] = [] const out: WorkbookSheetPreview[] = []
for (const name of wb.SheetNames || []) { for (const name of wb.SheetNames || []) {
const ws = wb.Sheets[name] const ws = wb.Sheets[name]
const matrix = (XLSX.utils.sheet_to_json(ws, { const rawMatrix = (XLSX.utils.sheet_to_json(ws, {
header: 1, header: 1,
defval: null, defval: null,
raw: true, raw: true,
}) || []) as (string | number | null)[][] }) || []) as (string | number | null)[][]
const matrix = trimSparseMatrixColumns(rawMatrix)
const full = sheetMatrixToTsv(matrix) const full = sheetMatrixToTsv(matrix)
const slim = sheetMatrixToTsv(matrix, { slimForAi: true }) const slim = sheetMatrixToTsv(matrix, { slimForAi: true })
const likelyNonPrice = isLikelyNonPriceSheetName(name) const likelyNonPrice = isLikelyNonPriceSheetName(name)

View File

@ -83,35 +83,89 @@ export function factorJsonKey(factor: string): string {
return f return f
} }
/** 将报价行重量规范为有序区间列表 (start-end] */ function nearlyEqualWeight(a: number, b: number): boolean {
return Math.abs(a - b) <= 1e-6
}
/**
* 报价表常见「闭区间书写」:0.05-0.3 / 0.301-1,中间留 0.001~0.01 空隙。
* OMS 重量因素是左开右闭,下一段左界应对齐上一段右界 → (0.05-0.3]、(0.3-1]。
*/
const WEIGHT_SEGMENT_MICRO_GAP = 0.05
/** 单行报价 → 重量段字符串;无 start 时用同分区上一行 end 作左界 */
export function formatQuoteRowWeightSegment(
row: ChannelQuotePriceRow,
fallbackPrevEnd = 0,
): string | null {
const end = Number(row.weightEnd)
if (!Number.isFinite(end) || end <= 0) return null
let start =
row.weightStart != null && Number.isFinite(Number(row.weightStart))
? Number(row.weightStart)
: fallbackPrevEnd
// 对齐上一段右界,消掉 0.301 / 0.101 / 0.26 这类书写空隙
if (
fallbackPrevEnd > 0 &&
start > fallbackPrevEnd &&
start - fallbackPrevEnd <= WEIGHT_SEGMENT_MICRO_GAP
) {
start = fallbackPrevEnd
}
if (!(end > start)) {
start = end > fallbackPrevEnd ? fallbackPrevEnd : 0
if (!(end > start)) start = 0
}
return formatWeightIntervalLeftOpenRightClosed(start, end)
}
/**
* 将报价行重量规范为有序区间列表 (start-end]。
* 按分区各自保留声明起止,再并集去重——避免英国吃到澳大利亚的 (0.02-0.25]。
*/
export function buildWeightIntervalsFromQuoteRows( export function buildWeightIntervalsFromQuoteRows(
rows: ChannelQuotePriceRow[], rows: ChannelQuotePriceRow[],
): { intervals: string[]; ends: number[] } { ): { intervals: string[]; ends: number[] } {
const ends = [ const byZone = new Map<string, ChannelQuotePriceRow[]>()
...new Set( for (const r of rows || []) {
rows const z = String(r.zoneHint || '').trim() || '_'
.map((r) => Number(r.weightEnd)) if (!byZone.has(z)) byZone.set(z, [])
.filter((n) => Number.isFinite(n) && n > 0), byZone.get(z)!.push(r)
), }
].sort((a, b) => a - b)
const intervals = ends.map((end, idx) => { const intervalList: string[] = []
// 优先使用同行声明的 start(按 end 匹配最近一行) const ends: number[] = []
const withStart = rows.find( const pushInterval = (seg: string) => {
(r) => if (intervalList.includes(seg)) return
Number(r.weightEnd) === end && const bounds = parseWeightIntervalBounds(seg)
r.weightStart != null && if (!bounds) return
Number.isFinite(Number(r.weightStart)), intervalList.push(seg)
) if (!ends.some((e) => nearlyEqualWeight(e, bounds.end))) ends.push(bounds.end)
const start = }
withStart != null
? Number(withStart.weightStart) for (const [, zoneRows] of byZone) {
: idx > 0 const sorted = [...zoneRows].sort((a, b) => Number(a.weightEnd) - Number(b.weightEnd))
? ends[idx - 1]! let prevEnd = 0
: 0 for (const row of sorted) {
return formatWeightIntervalLeftOpenRightClosed(start, end) const seg = formatQuoteRowWeightSegment(row, prevEnd)
if (!seg) continue
pushInterval(seg)
const bounds = parseWeightIntervalBounds(seg)
if (bounds) prevEnd = bounds.end
}
}
intervalList.sort((a, b) => {
const pa = parseWeightIntervalBounds(a)
const pb = parseWeightIntervalBounds(b)
if (pa && pb) {
if (pa.end !== pb.end) return pa.end - pb.end
return pa.start - pb.start
}
return a.localeCompare(b, 'zh', { numeric: true })
}) })
return { intervals, ends } ends.sort((a, b) => a - b)
return { intervals: intervalList, ends }
} }
function parseFactorValuesJson(raw: unknown): Record<string, string> { function parseFactorValuesJson(raw: unknown): Record<string, string> {
@ -348,42 +402,32 @@ export function buildChannelPriceApplyPreview(input: {
: [null] : [null]
for (const zoneValue of zones) { for (const zoneValue of zones) {
const zoneHint = const zoneMap =
zoneMaps.find((z) => z.zoneValue === zoneValue)?.zoneHint || zoneMaps.find((z) => z.zoneValue === zoneValue) ||
zoneLabelOf(zoneMaps, zoneValue) null
for (const weightSegment of weightIntervals) { const zoneHint = zoneMap?.zoneHint || zoneLabelOf(zoneMaps, zoneValue)
const zoneRows = (quote.rows || []).filter((r) => {
const rh = String(r.zoneHint || '').trim()
if (!rh) return false
if (!zoneMap) return false
return (
zoneMap.zoneHint === rh ||
zoneMap.zoneLabel.includes(rh) ||
rh.includes(zoneMap.zoneLabel) ||
zoneMap.zoneHint.includes(rh)
)
})
const sortedZoneRows = [...zoneRows].sort(
(a, b) => Number(a.weightEnd) - Number(b.weightEnd),
)
let prevEnd = 0
for (const picked of sortedZoneRows) {
const weightSegment = formatQuoteRowWeightSegment(picked, prevEnd)
if (!weightSegment) continue
const bounds = parseWeightIntervalBounds(weightSegment)
if (bounds) prevEnd = bounds.end
for (const cargo of cargos) { for (const cargo of cargos) {
const bounds = parseWeightIntervalBounds(weightSegment)
const quoteRows = quote.rows.filter((r) => {
const end = Number(r.weightEnd)
if (!bounds || !Number.isFinite(end)) return false
if (Math.abs(end - bounds.end) > 1e-9) return false
const rh = String(r.zoneHint || quote.destinationHints?.[0] || '').trim()
if (!rh) return true
// 行 zoneHint 需能映射到当前 zoneValue
const mapHit = zoneMaps.find(
(z) =>
z.zoneValue === zoneValue &&
(z.zoneHint === rh ||
z.zoneLabel.includes(rh) ||
rh.includes(z.zoneLabel) ||
z.zoneHint.includes(rh)),
)
return Boolean(mapHit) || (!zoneMaps.length && !rh)
})
// 若按 zoneHint 滤空,放宽:任意同重量行
const candidates =
quoteRows.length > 0
? quoteRows
: quote.rows.filter((r) => {
const end = Number(r.weightEnd)
return bounds && Number.isFinite(end) && Math.abs(end - bounds.end) < 1e-9
})
// 子类型:若报价带 serviceSubtype 且当前 cargo 不匹配则跳过金额(保留空?)——首期同一 cargo 绑定写全段
const picked = candidates[0]
if (!picked) continue
const { value, formula } = resolveAmountForItem(kind, quote.mode, picked) const { value, formula } = resolveAmountForItem(kind, quote.mode, picked)
if (value == null) continue if (value == null) continue

View File

@ -6,6 +6,7 @@ import type { ChannelQuoteExtracted, ChannelQuoteMode } from './channelQuoteAiSk
import { import {
buildWeightIntervalsFromQuoteRows, buildWeightIntervalsFromQuoteRows,
collectZoneHints, collectZoneHints,
formatQuoteRowWeightSegment,
type CostItemKind, type CostItemKind,
} from './channelQuoteApply' } from './channelQuoteApply'
@ -149,21 +150,32 @@ export function buildCandidateBuyPrice(card: QuoteModelCard): CandidateBuyPrice
const pushKind = (kind: CostItemKind, label: string, code: string) => { const pushKind = (kind: CostItemKind, label: string, code: string) => {
const cells: CandidateFeeCell[] = [] const cells: CandidateFeeCell[] = []
for (const weightSegment of intervals) { // 按行生成:分区各自用自己的重量起止,避免英国吃到澳大利亚段
const prevEndByZone = new Map<string, number>()
const zoneOrder = zoneHints.length ? zoneHints : [defaultZone]
const rowsSorted = [...(quote.rows || [])].sort((a, b) => {
const za = String(a.zoneHint || defaultZone).trim() || defaultZone
const zb = String(b.zoneHint || defaultZone).trim() || defaultZone
const zi = zoneOrder.indexOf(za)
const zj = zoneOrder.indexOf(zb)
const zcmp =
(zi < 0 ? 999 : zi) - (zj < 0 ? 999 : zj) || za.localeCompare(zb, 'zh')
if (zcmp !== 0) return zcmp
return Number(a.weightEnd) - Number(b.weightEnd)
})
for (const row of rowsSorted) {
const zh = String(row.zoneHint || defaultZone).trim() || defaultZone
const prev = prevEndByZone.get(zh) ?? 0
const weightSegment = formatQuoteRowWeightSegment(row, prev)
if (!weightSegment) continue
const bounds = parseWeightIntervalBounds(weightSegment) const bounds = parseWeightIntervalBounds(weightSegment)
if (!bounds) continue if (bounds) prevEndByZone.set(zh, bounds.end)
for (const row of quote.rows || []) { const cell = cellFor(kind, quote.mode, zh, weightSegment, row)
const end = Number(row.weightEnd) if (!cell) continue
if (!Number.isFinite(end) || Math.abs(end - bounds.end) > 1e-6) continue if (cells.some((c) => c.zoneHint === cell.zoneHint && c.weightSegment === cell.weightSegment)) {
const zh = String(row.zoneHint || defaultZone).trim() || defaultZone continue
const cell = cellFor(kind, quote.mode, zh, weightSegment, row)
if (!cell) continue
// 同 zone+weight 去重保留首个
if (cells.some((c) => c.zoneHint === cell.zoneHint && c.weightSegment === cell.weightSegment)) {
continue
}
cells.push(cell)
} }
cells.push(cell)
} }
if (!cells.length) return if (!cells.length) return
const formula = cells[0]!.formula const formula = cells[0]!.formula
@ -216,7 +228,12 @@ export function candidateDisplayFullTitle(c: CandidateBuyPrice): string {
return sub ? `${name}(${sub})` : String(name) return sub ? `${name}(${sub})` : String(name)
} }
/** 候选明细展平,供表格预览 */ function weightSegmentSortKey(seg: string): number {
const bounds = parseWeightIntervalBounds(seg)
return bounds?.end ?? Number.POSITIVE_INFINITY
}
/** 候选明细展平,供表格预览(同费用项内:国家 → 重量段) */
export function flattenCandidateCells(c: CandidateBuyPrice): Array<{ export function flattenCandidateCells(c: CandidateBuyPrice): Array<{
feeLabel: string feeLabel: string
kind: CostItemKind kind: CostItemKind
@ -245,5 +262,12 @@ export function flattenCandidateCells(c: CandidateBuyPrice): Array<{
}) })
} }
} }
rows.sort((a, b) => {
if (a.feeLabel !== b.feeLabel) return a.feeLabel.localeCompare(b.feeLabel, 'zh')
if (a.zoneHint !== b.zoneHint) return a.zoneHint.localeCompare(b.zoneHint, 'zh')
const dw = weightSegmentSortKey(a.weightSegment) - weightSegmentSortKey(b.weightSegment)
if (dw !== 0) return dw
return a.weightSegment.localeCompare(b.weightSegment, 'zh', { numeric: true })
})
return rows return rows
} }

View File

@ -49,25 +49,103 @@ function parseWeightBounds(raw: Cell): { start: number | null; end: number } | n
if (typeof raw === 'number' && Number.isFinite(raw) && raw > 0) { if (typeof raw === 'number' && Number.isFinite(raw) && raw > 0) {
return { start: null, end: raw } return { start: null, end: raw }
} }
const s = cellStr(raw).replace(/,/g, '').replace(/kg/gi, '').trim() let s = cellStr(raw)
.replace(/,/g, '')
.replace(/(/g, '(')
.replace(/)/g, ')')
.replace(/kg|公斤|千克/gi, '')
.replace(/\s+/g, '')
.trim()
if (!s) return null if (!s) return null
// ≤0.5 / <0.5 / 0.5以下 / 0.5以内
const upperOnly = s.match(/^(?:≤|<=|<|<)?(\d+(?:\.\d+)?)(?:以下|以内|及以下)?$/)
if (upperOnly && /≤|<=|<|<|以下|以内/.test(s)) {
const end = Number(upperOnly[1])
if (Number.isFinite(end) && end > 0) return { start: 0, end }
}
const range = s.match(/^(\d+(?:\.\d+)?)\s*[-~~—–到至]\s*(\d+(?:\.\d+)?)$/) const range = s.match(/^(\d+(?:\.\d+)?)\s*[-~~—–到至]\s*(\d+(?:\.\d+)?)$/)
if (range) { if (range) {
const a = Number(range[1]) const a = Number(range[1])
const b = Number(range[2]) const b = Number(range[2])
if (!Number.isFinite(a) || !Number.isFinite(b) || b <= 0) return null if (!Number.isFinite(a) || !Number.isFinite(b) || b <= 0) return null
return { start: a, end: b } return { start: Math.min(a, b), end: Math.max(a, b) }
} }
const n = Number(s) const n = Number(s)
if (!Number.isFinite(n) || n <= 0) return null if (!Number.isFinite(n) || n <= 0) return null
return { start: null, end: n } return { start: null, end: n }
} }
/** 真正的重量列表头(排除「重量KG/分区」这类轴标题;保留「分区/重量段」) */
function isWeightHeader(h: string): boolean {
if (!h) return false
if (/重量段/.test(h)) return true
if (/重量kg.?分区|重量.?分区|分区.?重量/.test(h)) return false
return /包裹重量|计费重量|^重量kg$|^重量$/.test(h)
}
/** 一区 / Zone1 等国家内子分区 */
function looksLikeSubZoneLabel(raw: string): boolean {
const s = cellStr(raw).trim()
if (!s || s.length > 12) return false
if (/^[一二三四五六七八九十]+区$/.test(s)) return true
if (/^\d+区$/.test(s)) return true
if (/^Zone\s*\d+$/i.test(s)) return true
if (/^[A-D]区$/i.test(s)) return true
return false
}
function composeZoneHint(country: string, subZone: string): string {
const c = country.trim()
const s = subZone.trim()
if (!c) return s
if (!s) return c
if (c.includes(s) || s.includes(c)) return c.length >= s.length ? c : s
return `${c}${s}`
}
/** 国家旁空列 /「分区」列:数据里出现多次「一区」则视为子分区列 */
function findSubZoneColumn(
matrix: Matrix,
headerIndex: number,
map: RoleMap,
countryIdx: number,
weightIdx: number,
): number {
const header = matrix[headerIndex] || []
const probeEnd = Math.min(matrix.length, headerIndex + 80)
let best = -1
let bestHits = 0
for (let c = 0; c < Math.max(header.length, 12); c++) {
if (c === countryIdx || c === weightIdx) continue
const role = map.roles[c] || 'ignore'
if (role !== 'ignore' && role !== 'country') continue
if (role === 'country' && c === countryIdx) continue
const h = normHeader(header[c])
if (h && /重量|运费|挂号|处理|操作|对接|时效|备注|说明/.test(h)) continue
let hits = 0
for (let r = headerIndex + 1; r < probeEnd; r++) {
if (looksLikeSubZoneLabel(cellStr(matrix[r]?.[c]))) hits += 1
}
const headerBonus = h && /^(分区|子区|区域|zone)$/.test(h) ? 2 : 0
const emptyHeaderBonus = !h && countryIdx >= 0 && Math.abs(c - countryIdx) === 1 ? 1 : 0
const score = hits + headerBonus + emptyHeaderBonus
if (hits >= 2 && score > bestHits) {
bestHits = score
best = c
}
}
return best
}
function isSectionTitleCountry(raw: string): boolean {
return /渠道说明|计费方式|走货属性|禁限运|附加费|返回目录|备注说明/.test(raw)
}
function isHeaderLike(h: string): boolean { function isHeaderLike(h: string): boolean {
if (!h) return false if (!h) return false
return ( return (
/对接代码|渠道代码|渠道编码|产品代码|服务代码/.test(h) || /对接代码|渠道代码|渠道编码|产品代码|服务代码/.test(h) ||
/重量段|包裹重量|计费重量|重量kg|^重量$/.test(h) || isWeightHeader(h) ||
/运费|处理费|操作费|挂号费|一口价|总价/.test(h) || /运费|处理费|操作费|挂号费|一口价|总价/.test(h) ||
/国家名称|^国家$|目的地|分区|zone/.test(h) /国家名称|^国家$|目的地|分区|zone/.test(h)
) )
@ -86,7 +164,7 @@ type ColRole =
function classifyHeader(h: string): ColRole { function classifyHeader(h: string): ColRole {
if (!h) return 'ignore' if (!h) return 'ignore'
if (/对接代码|渠道代码|渠道编码|产品代码|服务代码/.test(h)) return 'dock' if (/对接代码|渠道代码|渠道编码|产品代码|服务代码/.test(h)) return 'dock'
if (/重量段|包裹重量|计费重量|重量kg|^重量$/.test(h)) return 'weight' if (isWeightHeader(h)) return 'weight'
if (/挂号费/.test(h)) return 'registration' if (/挂号费/.test(h)) return 'registration'
if (/处理费|操作费/.test(h)) return 'handling' if (/处理费|操作费/.test(h)) return 'handling'
if (/运费/.test(h) && (/kg|公斤|千克/.test(h) || /rmb\/?kg|元\/?kg/.test(h))) return 'freightKg' if (/运费/.test(h) && (/kg|公斤|千克/.test(h) || /rmb\/?kg|元\/?kg/.test(h))) return 'freightKg'
@ -97,13 +175,15 @@ function classifyHeader(h: string): ColRole {
return 'ignore' return 'ignore'
} }
/** 国家/分区名:短中文或常见英文区名,且不是表头关键字 */ /** 国家/分区名:短中文或常见英文区名,且不是表头关键字 / 说明文案 */
function looksLikeZoneName(raw: string): boolean { function looksLikeZoneName(raw: string): boolean {
const s = cellStr(raw) const s = cellStr(raw)
if (!s || s.length > 24) return false if (!s || s.length > 24) return false
if (isHeaderLike(normHeader(s))) return false if (isHeaderLike(normHeader(s))) return false
if (/^(pak|wpx|doc|信封|文件)$/i.test(s.trim())) return false if (/^(pak|wpx|doc|信封|文件)$/i.test(s.trim())) return false
if (/条款|附加费|操作指南|目录|邮编/.test(s)) return false if (/条款|附加费|操作指南|目录|邮编/.test(s)) return false
// 服务说明 / 非国家列
if (/妥投|自然日|工作日|住宅|含.*费|时效|尺寸|要求|属性|走货|参考/.test(s)) return false
// 纯数字不当 zone // 纯数字不当 zone
if (/^[\d.\-]+$/.test(s)) return false if (/^[\d.\-]+$/.test(s)) return false
return /[\u4e00-\u9fffA-Za-z]/.test(s) return /[\u4e00-\u9fffA-Za-z]/.test(s)
@ -192,13 +272,16 @@ function findHeaderRow(matrix: Matrix): { index: number; map: RoleMap } | null {
if (map.roles.includes('handling')) score += 3 if (map.roles.includes('handling')) score += 3
if (map.roles.includes('flat') || map.zoneByCol.size) score += 3 if (map.roles.includes('flat') || map.zoneByCol.size) score += 3
if (map.roles.includes('country')) score += 2 if (map.roles.includes('country')) score += 2
score += map.roles.filter((r) => r === 'weight').length const weightCols = map.roles.filter((r) => r === 'weight').length
score += weightCols * 2
// 并排「包裹重量|国家|…|包裹重量|国家」明显优于「重量KG/分区」轴标题行
if (weightCols >= 2) score += 3
if (!best || score > best.score) best = { index: i, map, score } if (!best || score > best.score) best = { index: i, map, score }
} }
return best ? { index: best.index, map: best.map } : null return best ? { index: best.index, map: best.map } : null
} }
/** 公斤+票费:对接代码 + 重量段 + 运费/处理费 */ /** 公斤+票费:对接代码 + 重量段 + 运费/处理费(支持国家列向下填充 + 澳大利亚一区) */
function parseUnitPlusFee( function parseUnitPlusFee(
matrix: Matrix, matrix: Matrix,
sheetName: string, sheetName: string,
@ -215,6 +298,8 @@ function parseUnitPlusFee(
if (weightIdx < 0) return null if (weightIdx < 0) return null
if (freightIdx < 0 && handlingIdx < 0 && regIdx < 0) return null if (freightIdx < 0 && handlingIdx < 0 && regIdx < 0) return null
const subZoneIdx = findSubZoneColumn(matrix, headerIndex, map, countryIdx, weightIdx)
type Bucket = { type Bucket = {
code: string code: string
name: string | null name: string | null
@ -229,6 +314,8 @@ function parseUnitPlusFee(
'UNKNOWN' 'UNKNOWN'
let currentSubtype: string | null = null let currentSubtype: string | null = null
let currentName: string | null = null let currentName: string | null = null
let currentCountry = ''
let currentSubZone = ''
const ensure = (code: string) => { const ensure = (code: string) => {
const key = `${code}::${currentSubtype || ''}` const key = `${code}::${currentSubtype || ''}`
@ -259,13 +346,40 @@ function parseUnitPlusFee(
currentName = dock currentName = dock
} }
} }
if (countryIdx >= 0) {
const rawCountry = cellStr(row[countryIdx])
if (rawCountry) {
if (isSectionTitleCountry(rawCountry)) break
if (!looksLikeSubZoneLabel(rawCountry)) {
currentCountry = rawCountry
currentSubZone = ''
} else if (!currentCountry) {
// 极少见:国家列直接写「一区」
currentSubZone = rawCountry
}
}
}
if (subZoneIdx >= 0) {
const rawSub = cellStr(row[subZoneIdx])
if (rawSub && looksLikeSubZoneLabel(rawSub)) {
currentSubZone = rawSub
}
}
const w = parseWeightBounds(row[weightIdx]) const w = parseWeightBounds(row[weightIdx])
if (!w) continue if (!w) continue
const freight = freightIdx >= 0 ? cellNum(row[freightIdx]) : null const freight = freightIdx >= 0 ? cellNum(row[freightIdx]) : null
const handling = handlingIdx >= 0 ? cellNum(row[handlingIdx]) : null const handling = handlingIdx >= 0 ? cellNum(row[handlingIdx]) : null
const registration = regIdx >= 0 ? cellNum(row[regIdx]) : null const registration = regIdx >= 0 ? cellNum(row[regIdx]) : null
if (freight == null && handling == null && registration == null) continue if (freight == null && handling == null && registration == null) continue
const zone = countryIdx >= 0 ? cellStr(row[countryIdx]) || null : null
const zone =
countryIdx >= 0 || subZoneIdx >= 0
? composeZoneHint(currentCountry, currentSubZone) || null
: null
if (!zone && countryIdx >= 0) continue
const b = ensure(currentCode) const b = ensure(currentCode)
if (zone) b.destinations.add(zone) if (zone) b.destinations.add(zone)
b.rows.push({ b.rows.push({
@ -322,22 +436,30 @@ function parseFlatBlocks(
let i = 0 let i = 0
while (i < headers.length) { while (i < headers.length) {
const h = normHeader(headers[i]) const h = normHeader(headers[i])
if (/重量段|包裹重量|计费重量|重量kg|^重量$/.test(h)) { if (isWeightHeader(h)) {
const priceCols: Array<{ col: number; zone: string }> = [] const priceCols: Array<{ col: number; zone: string }> = []
let j = i + 1 let j = i + 1
while (j < headers.length) { while (j < headers.length) {
const hj = normHeader(headers[j]) const hj = normHeader(headers[j])
if (/重量段|包裹重量|计费重量|重量kg|^重量$/.test(hj)) break if (isWeightHeader(hj)) break
const zoneRaw = cellStr(headers[j]) const zoneRaw = cellStr(headers[j])
const role = classifyHeader(hj) const role = classifyHeader(hj)
if (role === 'ignore' && looksLikeZoneName(zoneRaw)) { if (role === 'ignore' && looksLikeZoneName(zoneRaw)) {
priceCols.push({ col: j, zone: zoneRaw }) priceCols.push({ col: j, zone: zoneRaw })
} else if (role === 'flat' || role === 'country') { } else if (role === 'flat' || role === 'country') {
// 「一口价」列:zone 可能在上一格或 sheet 名 // 「一口价」列:zone 可能在上一格或 sheet 名;假 zone(说明文案)跳过
priceCols.push({ const zone =
col: j, role === 'country'
zone: role === 'country' ? '' : zoneRaw || guessZoneFromSheet(sheetName) || '默认', ? ''
}) : looksLikeZoneName(zoneRaw)
? zoneRaw
: guessZoneFromSheet(sheetName) || '默认'
// buildRoleMap 可能把说明列标成 flat,这里再拦一次
if (role === 'flat' && zoneRaw && !looksLikeZoneName(zoneRaw) && !/一口价|总价|报价|单价|价格|金额/.test(hj)) {
j += 1
continue
}
priceCols.push({ col: j, zone })
} else if (role !== 'ignore') { } else if (role !== 'ignore') {
break break
} }
@ -449,6 +571,7 @@ function parseFlatLong(
const codeHint = guessChannelCodeFromSheetName(sheetName) const codeHint = guessChannelCodeFromSheetName(sheetName)
let currentSubtype: string | null = null let currentSubtype: string | null = null
let currentCountry = ''
const rows: ChannelQuoteRowRow[] = [] const rows: ChannelQuoteRowRow[] = []
for (let r = headerIndex + 1; r < matrix.length; r++) { for (let r = headerIndex + 1; r < matrix.length; r++) {
@ -459,12 +582,20 @@ function parseFlatLong(
currentSubtype = subtype currentSubtype = subtype
continue continue
} }
if (countryIdx >= 0) {
const rawCountry = cellStr(row[countryIdx])
if (rawCountry) {
if (isSectionTitleCountry(rawCountry)) break
currentCountry = rawCountry
}
}
const w = parseWeightBounds(row[weightIdx]) const w = parseWeightBounds(row[weightIdx])
if (!w) continue if (!w) continue
if (countryIdx >= 0 && flatIdx >= 0) { if (countryIdx >= 0 && flatIdx >= 0) {
const zone = cellStr(row[countryIdx]) || null const zone = currentCountry || null
const price = cellNum(row[flatIdx]) const price = cellNum(row[flatIdx])
if (price == null) continue if (price == null) continue
if (!zone) continue
rows.push({ rows.push({
weightStart: w.start, weightStart: w.start,
weightEnd: w.end, weightEnd: w.end,

View File

@ -266,11 +266,10 @@
<span class="cq-muted">{{ activeCandidate.feeItems.length }} 个费用项 · {{ activeCandidate.weightIntervals.length }} 个重量段</span> <span class="cq-muted">{{ activeCandidate.feeItems.length }} 个费用项 · {{ activeCandidate.weightIntervals.length }} 个重量段</span>
</div> </div>
<div class="cq-weights"> <div class="cq-weights">
<span class="label">重量段</span> <span class="label">重量段({{ activeCandidate.weightIntervals.length }})</span>
<a-tag v-for="w in activeCandidate.weightIntervals.slice(0, 30)" :key="w" size="small"> <a-tag v-for="w in activeCandidate.weightIntervals" :key="w" size="small">
{{ w }} {{ w }}
</a-tag> </a-tag>
<span v-if="activeCandidate.weightIntervals.length > 30" class="cq-muted">…</span>
</div> </div>
<ul v-if="activeCandidate.warnings.length" class="cq-warn-list"> <ul v-if="activeCandidate.warnings.length" class="cq-warn-list">
<li v-for="(w, i) in activeCandidate.warnings" :key="i">{{ w }}</li> <li v-for="(w, i) in activeCandidate.warnings" :key="i">{{ w }}</li>
@ -1705,14 +1704,16 @@ onMounted(() => {
.cq-upload-dragger { .cq-upload-dragger {
width: 100%; width: 100%;
height: 100%; height: 100%;
min-height: 72px; min-height: 96px;
border: 1px dashed #c9cdd4; border: 1px dashed #c9cdd4;
border-radius: 8px; border-radius: 8px;
background: #f7f8fa; background: #f7f8fa;
display: flex; display: flex;
flex-direction: column;
align-items: center; align-items: center;
gap: 10px; justify-content: center;
padding: 8px 12px; gap: 6px;
padding: 12px 16px;
cursor: pointer; cursor: pointer;
transition: all 0.2s; transition: all 0.2s;
box-sizing: border-box; box-sizing: border-box;
@ -1723,12 +1724,14 @@ onMounted(() => {
} }
} }
.cq-upload-content { .cq-upload-content {
flex: 1; width: 100%;
min-width: 0; min-width: 0;
text-align: left; text-align: center;
} }
.cq-upload-excel-icon { .cq-upload-excel-icon {
display: block;
flex-shrink: 0; flex-shrink: 0;
margin: 0 auto;
filter: drop-shadow(0 3px 8px rgba(22, 142, 45, 0.16)); filter: drop-shadow(0 3px 8px rgba(22, 142, 45, 0.16));
} }
.cq-upload-text { .cq-upload-text {
@ -1761,6 +1764,7 @@ onMounted(() => {
margin-top: 4px; margin-top: 4px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center;
gap: 4px; gap: 4px;
} }
.cq-native-file-input { .cq-native-file-input {