优化
This commit is contained in:
@@ -174,14 +174,13 @@ async function prepareInboundStatus(context, target) {
|
||||
if (!inboundId || !tenantId) throw new Error(`${target} 未生成独立待测量入库单`)
|
||||
const detailPath = `/api/platform/inbounds/${query(inboundId)}?tenantId=${query(tenantId)}`
|
||||
|
||||
if (target === 'MEASURING') {
|
||||
const weightOcr = await import(new URL('./inbound-weight-ocr.mjs', import.meta.url))
|
||||
await weightOcr.run(context)
|
||||
}
|
||||
|
||||
context.request = async (method, path, body, token, headers) => {
|
||||
const isSubmit = path.includes(`/inbounds/${inboundId}/measurement/submit`)
|
||||
const isMeasurementQuery = method === 'GET' && path.includes(`/inbounds/${inboundId}/measurement?`)
|
||||
if (isMeasurementQuery) {
|
||||
const response = await originalRequest.call(context, method, path, body, token, headers)
|
||||
if (target === 'MEASURING' && ok(response) && data(response)?.measurementId) throw stop
|
||||
return response
|
||||
}
|
||||
if (target === 'MEASURE_PENDING' && isSubmit) {
|
||||
const response = await originalRequest.call(context, method, path, body, token, headers)
|
||||
if (!ok(response)) throw new Error(`MEASURE_PENDING 提交失败: HTTP=${response?.http}, code=${response?.body?.code}`)
|
||||
@@ -201,13 +200,15 @@ async function prepareInboundStatus(context, target) {
|
||||
}
|
||||
return originalRequest.call(context, method, path, body, token, headers)
|
||||
}
|
||||
try {
|
||||
const measurement = await import(new URL('./inbound-measurement.mjs', import.meta.url))
|
||||
await measurement.run(context)
|
||||
} catch (error) {
|
||||
if (error !== stop) throw error
|
||||
} finally {
|
||||
context.request = originalRequest
|
||||
if (target !== 'MEASURING') {
|
||||
try {
|
||||
const measurement = await import(new URL('./inbound-measurement.mjs', import.meta.url))
|
||||
await measurement.run(context)
|
||||
} catch (error) {
|
||||
if (error !== stop) throw error
|
||||
} finally {
|
||||
context.request = originalRequest
|
||||
}
|
||||
}
|
||||
|
||||
const response = await originalRequest.call(context, 'GET',
|
||||
@@ -232,6 +233,11 @@ async function prepareInboundStatus(context, target) {
|
||||
}
|
||||
|
||||
export async function run(context, matrix = context.createdResources.manualStateMatrix) {
|
||||
if (!matrix) {
|
||||
matrix = { marker: context.marker, generatedAt: new Date().toISOString(), pages: {} }
|
||||
context.createdResources.manualStateMatrix = matrix
|
||||
}
|
||||
matrix.pages ||= {}
|
||||
const loginResponse = await context.request('POST', '/api/auth/login',
|
||||
{ username: MERCHANT_USERNAME, password: MERCHANT_PASSWORD }, '')
|
||||
const token = context.apiSuccess(MODULE, 'IT 测试客户管理员登录', loginResponse)?.accessToken
|
||||
|
||||
Reference in New Issue
Block a user