优化
This commit is contained in:
+2
-2
@@ -1,11 +1,11 @@
|
||||
import { overseasDownload, overseasRequest, overseasUpload } from '@/api/overseas.js'
|
||||
import { normalizeReceivingCandidate, normalizeReceivingSession } from '@/api/receiving-adapter.js'
|
||||
import { normalizeReceivingCandidate, normalizeReceivingSession, normalizeReceivingWarehouseProfile } from '@/api/receiving-adapter.js'
|
||||
|
||||
const RECEIVING_BASE = '/pda/v1/last-leg/receiving-containers'
|
||||
const current = (suffix = '') => `${RECEIVING_BASE}/current${suffix}`
|
||||
|
||||
export const listReceivingCandidates = async () => (await overseasRequest('GET', `${RECEIVING_BASE}/candidates`)).map(normalizeReceivingCandidate)
|
||||
export const getCurrentWarehouseProfile = () => overseasRequest('GET', `${RECEIVING_BASE}/warehouse-profile`)
|
||||
export const getCurrentWarehouseProfile = async () => normalizeReceivingWarehouseProfile(await overseasRequest('GET', `${RECEIVING_BASE}/warehouse-profile`))
|
||||
export const getReceivingContainer = async (containerNo) => normalizeReceivingSession(await overseasRequest('GET', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}`))
|
||||
export const prepareReceivingContainer = async (containerNo, request) => normalizeReceivingSession(await overseasRequest('POST', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}/prepare`, request))
|
||||
export const uploadCurrentUnloadPhoto = (filePath) => overseasUpload(current('/unload-photos/files'), filePath)
|
||||
|
||||
@@ -1,6 +1,40 @@
|
||||
export const RECEIVING_PHOTO_ROLES = ['LICENSE_PLATE', 'CONTAINER_SEAL', 'DOOR_OPEN']
|
||||
|
||||
const number = (value) => Math.max(0, Number(value || 0))
|
||||
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
|
||||
}
|
||||
|
||||
export function normalizeReceivingInbound(value = {}) {
|
||||
return {
|
||||
@@ -17,6 +51,8 @@ export function normalizeReceivingCandidate(value = {}) {
|
||||
...value,
|
||||
sourceContainerBookingId: typeof value.sourceContainerBookingId === 'string' ? value.sourceContainerBookingId.trim() : '',
|
||||
containerNo: String(value.containerNo || '').trim(),
|
||||
overseasWarehouseCode: text(value.overseasWarehouseCode),
|
||||
overseasWarehouseName: text(value.overseasWarehouseName),
|
||||
plannedArrivalAt: typeof value.plannedArrivalAt === 'string' && value.plannedArrivalAt.trim() ? value.plannedArrivalAt.trim() : null,
|
||||
totalOrderCount: number(value.totalOrderCount),
|
||||
planCount: number(value.planCount),
|
||||
@@ -42,6 +78,8 @@ export function normalizeReceivingSession(value) {
|
||||
: []
|
||||
return {
|
||||
...value,
|
||||
overseasWarehouseCode: text(value.overseasWarehouseCode),
|
||||
overseasWarehouseName: text(value.overseasWarehouseName),
|
||||
photos: RECEIVING_PHOTO_ROLES.map((role) => photos.find((photo) => photo?.role === role && photo?.fileId)).filter(Boolean),
|
||||
totalPackages: number(value.totalPackages),
|
||||
receivedPackages: number(value.receivedPackages),
|
||||
|
||||
Reference in New Issue
Block a user