You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.3 KiB
75 lines
2.3 KiB
import type { ShipmentRow } from "@/types/mail";
|
|
import { mapChannel } from "@/services/parse/channel-map";
|
|
|
|
const FBA_CODES = [
|
|
"ABQ2", "FTW1", "ONT8", "LAX9", "SCK4", "PHX7", "DFW7", "IND9", "TEB9", "BOS7",
|
|
];
|
|
const CHANNELS = ["卡派", "UPS", "FEDEX", "DHL", "自提", "未知渠道XYZ"];
|
|
|
|
function pad(n: number, w = 6) {
|
|
return String(n).padStart(w, "0");
|
|
}
|
|
|
|
/** 单元测试用卡派行生成器(不进业务库) */
|
|
export function generateM2Shipments(): ShipmentRow[] {
|
|
const rows: ShipmentRow[] = [];
|
|
const firstTwo: Array<Partial<ShipmentRow>> = [
|
|
{
|
|
F_FBACode: "ABQ2",
|
|
F_Transporter: "TRUCK",
|
|
F_CTNS: 1,
|
|
F_FBAID: "FBA19G5XJLV4",
|
|
F_ReferenceId: "3NHUDF7E",
|
|
F_ShipmentID: "BAZUS001799251",
|
|
F_CBM: 0.09,
|
|
F_Weight: 10.69,
|
|
F_Remark: "转POC2",
|
|
channel_raw: "卡派",
|
|
},
|
|
{
|
|
F_FBACode: "FTW1",
|
|
F_Transporter: "TRUCK",
|
|
F_CTNS: 4,
|
|
F_FBAID: "FBA19GLHTHQ2",
|
|
F_ReferenceId: "5ELVT8ED",
|
|
F_ShipmentID: "",
|
|
F_CBM: 0.21,
|
|
F_Weight: 85.08,
|
|
channel_raw: "卡派",
|
|
},
|
|
];
|
|
|
|
for (let i = 0; i < 327; i++) {
|
|
const row_index = i + 1;
|
|
if (i < 2) {
|
|
rows.push({ row_index, row_status: "VALID", ...firstTwo[i] });
|
|
continue;
|
|
}
|
|
const isInvalid = i % 40 === 0;
|
|
const rawChannel = CHANNELS[i % CHANNELS.length];
|
|
const mapped = mapChannel(rawChannel);
|
|
const code = FBA_CODES[i % FBA_CODES.length];
|
|
const ctns = isInvalid ? 0 : (i % 8) + 1;
|
|
const warnings: string[] = [];
|
|
if (mapped.unmapped && !isInvalid) warnings.push("CHANNEL_UNMAPPED");
|
|
|
|
rows.push({
|
|
row_index,
|
|
row_status: isInvalid ? "INVALID" : "VALID",
|
|
invalid_reasons: isInvalid ? ["CTNS<=0 或仓库ID缺失"] : undefined,
|
|
warnings: warnings.length ? warnings : undefined,
|
|
F_FBACode: isInvalid && i % 80 === 0 ? "" : code,
|
|
F_Transporter: mapped.transporter || undefined,
|
|
F_CTNS: ctns,
|
|
F_CBM: Number(((i % 20) * 0.07 + 0.05).toFixed(2)),
|
|
F_Weight: Number(((i % 50) * 2.3 + 5).toFixed(2)),
|
|
F_FBAID: `FBA${pad(1900000 + i, 10)}`,
|
|
F_ReferenceId: `REF${pad(i, 8)}`,
|
|
F_ShipmentID: i % 3 === 0 ? "" : `BAZUS${pad(1799251 + i, 9)}`,
|
|
F_Remark: i % 17 === 0 ? "备注样例" : null,
|
|
channel_raw: rawChannel,
|
|
});
|
|
}
|
|
return rows;
|
|
}
|