优化
This commit is contained in:
@@ -25,6 +25,9 @@ const same = (a, b) => JSON.stringify(canonical(a)) === JSON.stringify(canonical
|
||||
/** Internal authorized TEST module; entrypoint owns registration, credentials and execution. No direct fetch, SQL or historical fixtures. */
|
||||
export async function run(context, { pollAttempts = 60, pollDelayMs = 1000 } = {}) {
|
||||
if (!context.marker || !context.createdResources) throw new Error('公司车辆成本验收须有独立marker和本轮资源上下文')
|
||||
const resources = context.options?.fixedCompanyCostResources
|
||||
if (!resources || !['supplierId', 'vehicleId'].every(key => typeof resources[key] === 'string' && /^[1-9]\d*$/.test(resources[key])))
|
||||
throw new Error('公司成本验收必须配置既有供应商和车辆,禁止自动创建主档')
|
||||
if (context.createdResources.fleetCompanyCostAcceptance) throw new Error('本轮已存在公司成本验收记录;保留原证据,不自动重新造数')
|
||||
if (!Number.isInteger(pollAttempts) || pollAttempts < 1 || pollAttempts > 120 || !Number.isFinite(pollDelayMs) || pollDelayMs < 0 || pollDelayMs > 5000)
|
||||
throw new Error('公司成本轮询范围无效')
|
||||
@@ -73,17 +76,15 @@ export async function run(context, { pollAttempts = 60, pollDelayMs = 1000 } = {
|
||||
proof.exchangeRate = { month, usdToCnyAverage: id(exchange.usdToCnyAverage), recordVersion: id(exchange.recordVersion) }
|
||||
proof.customerBefore = await snapshotCustomer('操作前')
|
||||
check('本轮marker尚无客户费用污染,禁止覆盖旧验收', proof.customerBefore.companyFeePoolRows === 0)
|
||||
proof.supplierRequest = { name: `${context.marker} 公司成本专用供应商`, category: 'TRUCKING', carrierCodes: [], region: 'TEST-OVERSEAS',
|
||||
legalRepresentative: '受控验收', contactName: '受控验收', phone: '00000000000', email: null, address: '受控测试地点',
|
||||
businessLicenseNo: null, licenseFileId: null, status: 'ACTIVE', settlementPeriod: 'IMMEDIATE', remark: context.marker, truckingScope: 'OVERSEAS' }
|
||||
proof.supplierId = id(await request('POST', '/api/platform/v1/suppliers?tenantId=0', proof.supplierRequest, '创建本轮独占公司成本供应商'))
|
||||
check('供应商创建返回真实标识', /^[1-9]\d*$/.test(proof.supplierId))
|
||||
const supplier = await request('GET', `/api/platform/v1/suppliers/${encodeURIComponent(proof.supplierId)}?tenantId=0`, undefined, '核对本轮独占供应商')
|
||||
check('供应商确属本轮独占样本', id(supplier.id) === proof.supplierId && supplier.status === 'ACTIVE' && supplier.remark === context.marker && supplier.name === proof.supplierRequest.name)
|
||||
const vehicle = await request('POST', `${MASTER}/vehicles`, { plateNumber: `FC-${randomUUID().slice(0, 12)}`, model: 'Company cost TEST', fuelConsumptionPer100Km: 10,
|
||||
mileageKm: 100, region: 'OVERSEAS', ownership: 'OWNED', status: 'IN_SERVICE', remark: context.marker }, '创建本轮公司成本专用车辆')
|
||||
check('车辆返回稳定身份', Boolean(vehicle.id && vehicle.plateNumber))
|
||||
proof.vehicleId = id(vehicle.id); proof.plateNumber = vehicle.plateNumber; proof.cleanup = 'PENDING'
|
||||
proof.supplierId = id(resources.supplierId)
|
||||
const supplier = await request('GET', `/api/platform/v1/suppliers/${encodeURIComponent(proof.supplierId)}?tenantId=0`, undefined, '核对已配置的既有供应商')
|
||||
check('复用供应商为平台启用海外拖车供应商', id(supplier.id) === proof.supplierId && id(supplier.tenantId) === '0'
|
||||
&& supplier.status === 'ACTIVE' && supplier.category === 'TRUCKING' && supplier.truckingScope === 'OVERSEAS')
|
||||
const vehicle = await request('GET', `${MASTER}/vehicles/${encodeURIComponent(id(resources.vehicleId))}`, undefined, '核对已配置的既有公司车辆')
|
||||
check('复用车辆为海外自有在役车辆', id(vehicle.id) === id(resources.vehicleId) && Boolean(vehicle.plateNumber)
|
||||
&& vehicle.region === 'OVERSEAS' && vehicle.ownership === 'OWNED' && vehicle.status === 'IN_SERVICE')
|
||||
proof.vehicleId = id(vehicle.id); proof.plateNumber = vehicle.plateNumber
|
||||
proof.reusedMasterData = true; proof.cleanup = 'REUSED_UNCHANGED'
|
||||
const care = `/api/platform/v1/last-leg/fleet/vehicles/${encodeURIComponent(proof.vehicleId)}/records`
|
||||
for (const [recordType, currency, originalAmount] of [['REPAIR', 'CNY', 27.31], ['RESCUE', 'USD', 10]]) {
|
||||
const scenario = { recordType, status: 'CHECKING', commands: [] }; proof.cases.push(scenario)
|
||||
@@ -188,15 +189,5 @@ export async function run(context, { pollAttempts = 60, pollDelayMs = 1000 } = {
|
||||
}
|
||||
proof.status = 'VERIFIED'
|
||||
} catch (error) { failure = error; proof.status = 'FAILED'; proof.error = error instanceof Error ? error.message : String(error) }
|
||||
finally {
|
||||
if (proof.vehicleId) {
|
||||
try {
|
||||
const path = `${MASTER}/vehicles/${encodeURIComponent(proof.vehicleId)}`
|
||||
const vehicle = await request('GET', path, undefined, '结束前读取本轮专用车辆')
|
||||
const ended = await request('PATCH', `${path}/status`, { recordVersion: vehicle.recordVersion, status: 'INACTIVE' }, '停用本轮专用车辆,保留财务与运维证据')
|
||||
check('本轮专用车辆已停用', ended.status === 'INACTIVE'); proof.cleanup = 'INACTIVE'
|
||||
} catch (error) { proof.cleanup = 'FAILED'; proof.cleanupError = error instanceof Error ? error.message : String(error); proof.status = 'FAILED'; failure ??= error }
|
||||
}
|
||||
}
|
||||
if (failure) throw failure
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user