fix(procurement): normalize integer wire fields before commands

This commit is contained in:
2026-10-10 08:48:15 +08:00
parent 84488adf12
commit fb062b5ec4
2 changed files with 52 additions and 3 deletions
@@ -32,8 +32,12 @@ interface LooseboardDetailPayload {
function normalizePage<TPayload, TResult>(payload: PagePayload<TPayload>, normalize: (value: TPayload) => TResult): OverseasBusinessPage<TResult> {
return { records: (payload.records || []).map(normalize), page: Number(payload.page), size: Number(payload.size), total: Number(payload.total), pages: Number(payload.pages) }
}
function procurementInteger(value: unknown): number {
if ((typeof value !== 'number' && typeof value !== 'string') || !/^\d+$/.test(String(value)) || !Number.isSafeInteger(Number(value))) throw new Error('采购数据中的数量或版本无效,请刷新后重试')
return Number(value)
}
function procurementSummary(value: ProcurementSummaryPayload): OverseasPurchaseSummary {
return { ...value, id: String(value.id), purchaseWarehouseId: value.purchaseWarehouseId == null ? null : String(value.purchaseWarehouseId), budgetUnitPrice: value.budgetUnitPrice == null ? null : String(value.budgetUnitPrice) }
return { ...value, version: procurementInteger(value.version), purchaseQuantity: procurementInteger(value.purchaseQuantity), id: String(value.id), purchaseWarehouseId: value.purchaseWarehouseId == null ? null : String(value.purchaseWarehouseId), budgetUnitPrice: value.budgetUnitPrice == null ? null : String(value.budgetUnitPrice) }
}
function truckSummary(value: TruckSummaryPayload): LocalTransportOrder {
return { ...value, id: String(value.id), totalWeightKg: String(value.totalWeightKg), totalVolumeCbm: String(value.totalVolumeCbm), budgetAmount: value.budgetAmount == null ? null : String(value.budgetAmount) }
@@ -63,6 +67,22 @@ export async function listOverseasPurchases(query: OverseasPurchaseQuery = {}) {
export async function getOverseasPurchase(orderNo: string, customerId: string) {
const response = await http.get<ApiEnvelope<PlatformProcurement>, ApiEnvelope<PlatformProcurement>>(`${procurementBasePath}/${encodeURIComponent(orderNo)}`, { params: { customerId } })
const detail = unwrapApiResponse(response)
detail.customerView.order.version = procurementInteger(detail.customerView.order.version)
detail.customerView.order.purchaseQuantity = procurementInteger(detail.customerView.order.purchaseQuantity)
for (const row of [...detail.customerView.boxes, ...detail.customerView.shipments]) row.quantity = procurementInteger(row.quantity)
for (const fee of detail.customerView.fees) if (fee.version != null) fee.version = procurementInteger(fee.version)
if (detail.purchaseFacts?.purchased_quantity != null) detail.purchaseFacts.purchased_quantity = procurementInteger(detail.purchaseFacts.purchased_quantity)
if (detail.physical.packingVersion != null) detail.physical.packingVersion = procurementInteger(detail.physical.packingVersion)
for (const row of detail.physical.receipts) {
row.goodQuantity = procurementInteger(row.goodQuantity); row.damagedQuantity = procurementInteger(row.damagedQuantity); row.extraQuantity = procurementInteger(row.extraQuantity)
}
for (const row of [...detail.physical.dispositions, ...detail.controls.remaining, ...detail.controls.closureItems]) row.quantity = procurementInteger(row.quantity)
for (const row of [...detail.physical.cartons, ...detail.transport.overseasCargo, ...detail.transport.domesticCargo]) {
row.quantity = procurementInteger(row.quantity)
for (const source of row.sources) source.quantity = procurementInteger(source.quantity)
}
for (const fee of detail.fees) fee.feeVersion = procurementInteger(fee.feeVersion)
for (const file of detail.files) file.sizeBytes = procurementInteger(file.sizeBytes)
if (detail.purchaseFacts?.actual_warehouse_id != null) detail.purchaseFacts.actual_warehouse_id = String(detail.purchaseFacts.actual_warehouse_id)
detail.physical.dispositions = detail.physical.dispositions.map(row => ({ ...row, id: String(row.id), source_carton_id: row.source_carton_id == null ? null : String(row.source_carton_id), receipt_id: row.receipt_id == null ? null : String(row.receipt_id), voucher_file_id: String(row.voucher_file_id) }))
detail.physical.receipts = detail.physical.receipts.map(row => ({ ...row, id: String(row.id), sourceCartonId: row.sourceCartonId == null ? null : String(row.sourceCartonId) }))
@@ -76,6 +96,8 @@ export async function getOverseasPurchase(orderNo: string, customerId: string) {
detail.files = detail.files.map(file => ({ ...file, id: String(file.id), fileId: String(file.fileId) }))
for (const leg of ['overseasCargo', 'domesticCargo'] as const) detail.transport[leg] = detail.transport[leg].map(row => ({ ...row, cartonId: String(row.cartonId), packagingRecordId: row.packagingRecordId == null ? null : String(row.packagingRecordId), sources: row.sources.map(source => ({ ...source, receiptId: String(source.receiptId) })) }))
for (const labels of [detail.transport.overseasLabels, detail.transport.domesticLabels]) if (labels) {
labels.version = procurementInteger(labels.version)
for (const label of labels.labels) label.page = procurementInteger(label.page)
labels.id = String(labels.id); labels.manifestId = String(labels.manifestId)
labels.labels = labels.labels.map(row => ({ ...row, cartonId: String(row.cartonId), fileId: String(row.fileId) }))
}
@@ -83,7 +105,10 @@ export async function getOverseasPurchase(orderNo: string, customerId: string) {
}
export async function getOverseasPurchaseEditor(orderNo: string, customerId: string) {
const response = await http.get<ApiEnvelope<OverseasPurchaseEditorDetail>, ApiEnvelope<OverseasPurchaseEditorDetail>>(`${procurementBasePath}/${encodeURIComponent(orderNo)}`, { params: { customerId } })
return unwrapApiResponse(response)
const detail = unwrapApiResponse(response)
detail.customerView.order.version = procurementInteger(detail.customerView.order.version)
detail.customerView.order.purchaseQuantity = procurementInteger(detail.customerView.order.purchaseQuantity)
return detail
}
export async function updateOverseasPurchase(orderNo: string, customerId: string, payload: UpdateOverseasPurchaseRequest) {
const response = await http.patch<ApiEnvelope<ProcurementDetailPayload>, ApiEnvelope<ProcurementDetailPayload>>(`${procurementBasePath}/${encodeURIComponent(orderNo)}`, { version: payload.version, remark: payload.remark }, { params: { customerId } })