Files
pda-overseas-uniapp/src/api/receiving-adapter.js
T

98 lines
4.1 KiB
JavaScript
Raw Normal View History

2026-08-24 19:29:41 +08:00
export const RECEIVING_PHOTO_ROLES = ['LICENSE_PLATE', 'CONTAINER_SEAL', 'DOOR_OPEN']
const number = (value) => Math.max(0, Number(value || 0))
2026-09-07 15:07:54 +08:00
const text = (value) => typeof value === 'string' ? value.trim() : ''
function warehouseContractError(message) {
return Object.assign(new Error(message), { code: 'RECEIVING_WAREHOUSE_CONTRACT_INVALID' })
}
export function normalizeReceivingWarehouseProfile(value = {}) {
const profile = {
warehouseId: value.warehouseId === null || value.warehouseId === undefined ? '' : String(value.warehouseId),
warehouseCode: text(value.warehouseCode),
warehouseName: text(value.warehouseName)
}
if (!profile.warehouseId || !profile.warehouseCode || !profile.warehouseName) {
throw warehouseContractError('当前 PDA 绑定仓信息不完整,请联系管理员检查账号绑定')
}
return profile
}
export function assertReceivingWarehouse(value, profile, label = '当前柜') {
const expectedCode = text(profile?.warehouseCode)
const expectedName = text(profile?.warehouseName)
const actualCode = text(value?.overseasWarehouseCode)
const actualName = text(value?.overseasWarehouseName)
if (!expectedCode || !expectedName) {
throw warehouseContractError('当前 PDA 绑定仓信息不完整,暂停接柜作业')
}
if (!actualCode || !actualName) {
throw warehouseContractError(`${label}缺少已分配海外接柜仓信息,暂停操作并请联系管理员`)
}
if (actualCode !== expectedCode) {
throw Object.assign(new Error(`${label}已分配至其他海外接柜仓,当前仓不可操作`), { code: 'RECEIVING_WAREHOUSE_MISMATCH' })
}
return value
}
2026-08-24 19:29:41 +08:00
export function normalizeReceivingInbound(value = {}) {
return {
...value,
plannedPalletCount: number(value.plannedPalletCount),
totalPackages: number(value.totalPackages),
receivedPackages: number(value.receivedPackages),
pendingPackages: number(value.pendingPackages)
}
}
export function normalizeReceivingCandidate(value = {}) {
return {
...value,
2026-08-28 13:54:38 +08:00
sourceContainerBookingId: typeof value.sourceContainerBookingId === 'string' ? value.sourceContainerBookingId.trim() : '',
containerNo: String(value.containerNo || '').trim(),
2026-09-07 15:07:54 +08:00
overseasWarehouseCode: text(value.overseasWarehouseCode),
overseasWarehouseName: text(value.overseasWarehouseName),
2026-08-28 13:54:38 +08:00
plannedArrivalAt: typeof value.plannedArrivalAt === 'string' && value.plannedArrivalAt.trim() ? value.plannedArrivalAt.trim() : null,
totalOrderCount: number(value.totalOrderCount),
planCount: number(value.planCount),
inboundCodeCount: number(value.inboundCodeCount),
2026-08-28 13:54:38 +08:00
missingInboundCodeCount: number(value.missingInboundCodeCount),
plannedInboundCodeCount: number(value.plannedInboundCodeCount),
pendingPlanCount: number(value.pendingPlanCount),
2026-08-24 19:29:41 +08:00
destinationCodes: Array.isArray(value.destinationCodes) ? value.destinationCodes.filter(Boolean) : [],
plannedPalletCount: number(value.plannedPalletCount),
totalPackages: number(value.totalPackages),
receivedPackages: number(value.receivedPackages),
2026-08-28 13:54:38 +08:00
currentAccount: value.currentAccount === true,
allPlansReady: value.allPlansReady === true,
operable: value.operable === true,
blockReason: typeof value.blockReason === 'string' ? value.blockReason.trim() : ''
2026-08-24 19:29:41 +08:00
}
}
export function normalizeReceivingSession(value) {
if (!value) return null
2026-08-26 15:24:51 +08:00
const photos = Array.isArray(value.photos)
? value.photos.map((photo) => ({ ...photo, fileId: String(photo.fileId) }))
: []
2026-08-24 19:29:41 +08:00
return {
...value,
2026-09-07 15:07:54 +08:00
overseasWarehouseCode: text(value.overseasWarehouseCode),
overseasWarehouseName: text(value.overseasWarehouseName),
2026-08-26 15:59:08 +08:00
photos: RECEIVING_PHOTO_ROLES.map((role) => photos.find((photo) => photo?.role === role && photo?.fileId)).filter(Boolean),
2026-08-24 19:29:41 +08:00
totalPackages: number(value.totalPackages),
receivedPackages: number(value.receivedPackages),
pendingPackages: number(value.pendingPackages),
inbounds: Array.isArray(value.inbounds) ? value.inbounds.map(normalizeReceivingInbound) : []
}
}
export function isNoCurrentReceiving(error) {
return ['404', 'A0404', 'B0404'].includes(String(error?.code || ''))
}
export function isReceivingConflict(error) {
return ['409', 'A0409', 'B0409'].includes(String(error?.code || ''))
}