fix(dispatch): invalidate resource evidence and bind uploads to review rounds

This commit is contained in:
2026-10-26 19:21:11 +08:00
parent f6d9991955
commit a5befc9bad
15 changed files with 138 additions and 51 deletions
@@ -296,9 +296,10 @@ export async function ensureFleetLoadingDocuments(context, module, proof, token)
const read = () => command(context, module, 'GET', path, undefined, '回查本车装车资料', token)
let documents = await read()
const initialStage = documents.stage
const reviewRound = id(documents.reviewRound)
const complete = value => LOADING_PHOTO_SLOTS.every(slot => value.photos?.some(photo => photo.slot === slot && id(photo.fileId)))
const validate = value => {
if (value.dispatchNo !== proof.dispatchNo || !['LOADING', 'AFTER_LOADING', 'DELIVERING'].includes(value.stage)
if (value.dispatchNo !== proof.dispatchNo || !/^[1-9]\d*$/.test(reviewRound) || id(value.reviewRound) !== reviewRound || !['LOADING', 'AFTER_LOADING', 'DELIVERING'].includes(value.stage)
|| value.complete !== complete(value)) throw Error('本车装车资料身份、阶段或五框完整性不匹配')
}
validate(documents)
@@ -307,7 +308,8 @@ export async function ensureFleetLoadingDocuments(context, module, proof, token)
if (documents.photos?.some(photo => photo.slot === slot && id(photo.fileId))) continue
if (!documents.editable || typeof context.requestMultipart !== 'function') throw Error('缺少本车装车照片写入资格或上传能力')
const content = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aH1kAAAAASUVORK5CYII=', 'base64')
const upload = { slot, path: `${path}/${slot}/uploads?idempotencyKey=${key(proof, `PHOTO_UPLOAD_${slot}`)}`,
const uploadKey = key(proof, `PHOTO_UPLOAD_${slot}`)
const upload = { slot, path: `${path}/${slot}/uploads?idempotencyKey=${uploadKey}&reviewRound=${reviewRound}`,
name: `${proof.marker}-TEST-${slot}.png`, sha256: createHash('sha256').update(content).digest('hex'), status: 'PREPARED' }
if (proof.loadingDocuments.uploads.some(item => item.slot === slot)) throw Error('该照片上传已开始,保留原键和结果排查,不自动重发')
proof.loadingDocuments.uploads.push(upload); await context.checkpoint?.()
@@ -319,7 +321,7 @@ export async function ensureFleetLoadingDocuments(context, module, proof, token)
await context.checkpoint?.()
const photo = context.apiSuccess(module, '上传本轮TEST合成装车照片', response, '', OPTIONS)
if (response?.http !== 200 || String(response?.body?.code) !== '200' || photo?.slot !== slot || !id(photo.fileId)) throw Error('装车照片上传未确认,停止绑定及发车')
const body = { recordVersion: documents.recordVersion, idempotencyKey: key(proof, `PHOTO_BIND_${slot}`), fileId: id(photo.fileId) }
const body = { recordVersion: documents.recordVersion, idempotencyKey: key(proof, `PHOTO_BIND_${slot}`), fileId: id(photo.fileId), uploadKey }
const bound = await command(context, module, 'PUT', `${path}/${slot}`, body, '保存本车装车照片', token)
validate(bound)
check(context, module, '绑定回执保留本槽文件', bound.photos.some(item => item.slot === slot && id(item.fileId) === id(photo.fileId)))