This commit is contained in:
2026-08-20 15:20:05 +08:00
parent 6c7a670f1e
commit b55b049e77
30 changed files with 727 additions and 12 deletions
@@ -1,10 +1,12 @@
import { readFile } from 'node:fs/promises'
const MODULE = 'inbound-measurement'
const SCENARIO = 'mojia-carton-measurement'
const OPTIONS = { scenario: SCENARIO, deploymentBlocker: true }
const WEIGHING_IMAGE_COUNT = 1
const FIXTURE_PALLET_CAPACITY_CBM = 1.2
const WEIGHT_IMAGE = Uint8Array.from([137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82,
0, 0, 0, 1, 0, 0, 0, 1, 8, 6, 0, 0, 0, 31, 21, 196, 137, 0, 0, 0, 13, 73, 68, 65, 84,
8, 215, 99, 248, 207, 192, 240, 31, 0, 5, 0, 1, 255, 137, 153, 61, 29, 0, 0, 0, 0,
73, 69, 78, 68, 174, 66, 96, 130])
function asId(value) { return value == null ? '' : String(value) }
function asNumber(value) { return Number(value) }
@@ -77,10 +79,9 @@ async function provisionWarehouseResources(context, { inboundId, warehouseId, pa
}
async function createConfirmedWeightEvidence(context, { inboundId, tenantId, palletId }) {
const image = await readFile(new URL('../../../apps/pda-uniapp/static/c7.png', import.meta.url))
const uploadResponse = await context.requestMultipart('POST',
`/api/platform/v1/files/measurements/${tenantId}/${inboundId}`, {
content: image, type: 'image/png', name: `weight-${inboundId}.png`,
content: WEIGHT_IMAGE, type: 'image/png', name: `weight-${inboundId}.png`,
})
const upload = context.apiSuccess(MODULE, '上传称重图片并执行 OCR', uploadResponse,
`inboundId=${inboundId}`, OPTIONS)
@@ -153,8 +154,7 @@ function findIsolatedInbound(context) {
async function multipartRequest(context, path, data) {
const form = new FormData()
form.append('data', new Blob([JSON.stringify(data)], { type: 'application/json' }))
const image = await readFile(new URL('../../../apps/pda-uniapp/static/c7.png', import.meta.url))
form.append('image', new Blob([image], { type: 'image/png' }), 'carton-evidence.png')
form.append('image', new Blob([WEIGHT_IMAGE], { type: 'image/png' }), 'carton-evidence.png')
try {
const response = await fetch(`${context.options.gateway}${path}`, {
method: 'POST',
+1 -1
View File
@@ -17,7 +17,7 @@ const ORDER_ESTIMATE_VOLUME_CBM = BOXES.reduce((total, box) =>
function id(value) { return value == null ? '' : String(value) }
function records(value) { return Array.isArray(value?.records) ? value.records : [] }
function pageOk(value) { return Array.isArray(value?.records) && Number.isFinite(Number(value?.total)) }
function success(response) { return response.http === 200 && String(response.body?.code) === '200' }
function success(response) { return Boolean(response) && response.http === 200 && String(response.body?.code) === '200' }
function sleep(milliseconds) { return new Promise((resolve) => setTimeout(resolve, milliseconds)) }
function key(context, operation) { return `${context.marker}-${operation}`.slice(0, 128) }
export function approvedInboundReady(orderDetail, taskResponse, tenantId, orderId) {
@@ -144,6 +144,13 @@ export async function run(context) {
OPTIONS)
if (!selectedChannel) return
const channelName = selectedChannel.channelName
const supplierResponse = await context.request('GET',
'/api/platform/v1/suppliers?tenantId=0&category=BOOKING&status=ACTIVE&page=1&size=20')
const supplierPage = context.apiSuccess(MODULE, '读取 ACTIVE 订舱代理作为运输事实源', supplierResponse, '', OPTIONS)
const supplier = supplierPage?.records?.find?.((value) => value?.id && value?.name)
context.assert(MODULE, '存在可用于发布订舱的 ACTIVE 订舱代理', supplierResponse,
Boolean(supplier?.id && supplier?.name), `supplierId=${id(supplier?.id) || 'missing'}`, OPTIONS)
if (!supplier?.id) return
const primaryRequirement = { containerType: '40HC', containerKind: 'FCL', capacityCbm: 76, maxWeightKg: 28000 }
const realContainerNo = `TST-${suffix}-01`.slice(0, 64)
const wrongContainerNo = `TST-${suffix}-02`.slice(0, 64)
@@ -151,8 +158,8 @@ export async function run(context) {
customerId: tenantId, customerName: inbound?.summary?.customerName || `验收客户-${tenantId}`,
channelCode, warehouseId,
billOfLadingNo: `BL-${suffix}`.slice(0, 128),
shippingCompanyId: null, shippingCompanyName: null,
bookingAgentId: null, bookingAgentName: null,
shippingCompanyId: id(supplier.id), shippingCompanyName: supplier.name,
bookingAgentId: id(supplier.id), bookingAgentName: supplier.name,
vesselName: `验收船-${suffix}`.slice(0, 128), voyageNo: `V-${suffix}`.slice(0, 64),
departurePortCode: 'CNSZX', departurePortName: '深圳',
destinationPortCode: 'USLAX', destinationPortName: '洛杉矶', placeOfDelivery: 'LAX',
@@ -123,11 +123,20 @@ export async function run(context) {
const containerNo = `P3B-${suffix}`.slice(0, 64)
const smartLoadingBase = '/api/platform/v1/first-leg/smart-loading'
const pdaBase = '/api/platform/v1/first-leg/pda-loading'
const supplierResponse = await context.request('GET',
'/api/platform/v1/suppliers?tenantId=0&category=BOOKING&status=ACTIVE&page=1&size=20')
const supplierPage = context.apiSuccess(MODULE, '读取 ACTIVE 订舱代理作为运输事实源', supplierResponse, '', OPTIONS)
const supplier = supplierPage?.records?.find?.((value) => value?.id && value?.name)
context.assert(MODULE, '存在可用于发布订舱的 ACTIVE 订舱代理', supplierResponse,
Boolean(supplier?.id && supplier?.name), `supplierId=${id(supplier?.id) || 'missing'}`, OPTIONS)
if (!supplier?.id) return
const bookingDraft = {
customerId: tenantId, customerName: initial?.summary?.customerName,
warehouseId,
channelCode: initial?.summary?.channelCode,
billOfLadingNo: `P3BL-${suffix}`.slice(0, 128),
shippingCompanyId: id(supplier.id), shippingCompanyName: supplier.name,
bookingAgentId: id(supplier.id), bookingAgentName: supplier.name,
vesselName: `P3VESSEL-${suffix}`.slice(0, 128), voyageNo: `P3V-${suffix}`.slice(0, 64),
departurePortCode: 'CNSZX', departurePortName: '深圳', destinationPortCode: 'USLAX',
destinationPortName: '洛杉矶', placeOfDelivery: 'LAX', serviceTerm: 'CY-CY', freightTerm: 'NINGBO',
+26
View File
@@ -3551,3 +3551,29 @@ PREPARE schema_comments_025 FROM @ddl; EXECUTE schema_comments_025; DEALLOCATE P
-- ============================================================================
SET @ddl = (SELECT IF(EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema=DATABASE() AND table_name='ll_order' AND column_name='sub_order_status'), 'SELECT 1', 'ALTER TABLE ll_order ADD COLUMN sub_order_status VARCHAR(255) NULL COMMENT ''子单据状态汇总'' AFTER current_status'));
PREPARE ll_order_sub_status_026 FROM @ddl; EXECUTE ll_order_sub_status_026; DEALLOCATE PREPARE ll_order_sub_status_026;
-- ============================================================================
-- 2026-08-20 / 027
-- One tail-leg inbound plan per source tail-leg order; one container may carry many plans.
-- ============================================================================
USE baiyue_lastleg;
SET @ddl = (SELECT IF(EXISTS (SELECT 1 FROM information_schema.columns
WHERE table_schema=DATABASE() AND table_name='ll_inbound_plan' AND column_name='source_order_id'),
'SELECT 1',
'ALTER TABLE ll_inbound_plan ADD COLUMN source_order_id BIGINT NULL COMMENT ''来源尾程订单ID,一张入仓单对应一张入库计划'' AFTER customer_id'));
PREPARE ll_inbound_plan_source_order_027 FROM @ddl; EXECUTE ll_inbound_plan_source_order_027; DEALLOCATE PREPARE ll_inbound_plan_source_order_027;
-- Legacy plans were created per container and cannot be inferred back to a source order.
UPDATE ll_inbound_plan SET source_order_id=NULL WHERE source_order_id=0;
SET @ddl = (SELECT IF(EXISTS (SELECT 1 FROM information_schema.statistics
WHERE table_schema=DATABASE() AND table_name='ll_inbound_plan' AND index_name='uk_ll_inbound_plan_container'),
'ALTER TABLE ll_inbound_plan DROP INDEX uk_ll_inbound_plan_container', 'SELECT 1'));
PREPARE ll_inbound_plan_drop_container_unique_027 FROM @ddl; EXECUTE ll_inbound_plan_drop_container_unique_027; DEALLOCATE PREPARE ll_inbound_plan_drop_container_unique_027;
SET @ddl = (SELECT IF(EXISTS (SELECT 1 FROM information_schema.statistics
WHERE table_schema=DATABASE() AND table_name='ll_inbound_plan' AND index_name='uk_ll_inbound_plan_source_order'),
'SELECT 1',
'ALTER TABLE ll_inbound_plan ADD UNIQUE KEY uk_ll_inbound_plan_source_order (customer_id,source_order_id)'));
PREPARE ll_inbound_plan_source_order_unique_027 FROM @ddl; EXECUTE ll_inbound_plan_source_order_unique_027; DEALLOCATE PREPARE ll_inbound_plan_source_order_unique_027;