This commit is contained in:
2026-10-27 17:44:41 +08:00
parent 57cd211973
commit db0e72daeb
37 changed files with 701 additions and 671 deletions
@@ -32,20 +32,6 @@ export function supplierCategoryForFeeItem(item) {
? item.supplierCategory : null
}
export function buildSupplierBody(marker, category) {
const suffix = String(marker || '').replace(/[^0-9A-Za-z]/g, '').slice(-24)
return {
name: `财务验收供应商-${suffix}`,
category,
truckingScope: category === 'TRUCKING' ? 'DOMESTIC' : null,
...(category === 'BOOKING' ? { carrierCodes: ['MATSON'] } : {}),
region: '宁波', legalRepresentative: '财务验收法人', contactName: '财务验收联系人',
phone: '13800000000', email: `finance-supplier-${suffix || 'fixture'}@example.com`,
address: '财务验收地址', businessLicenseNo: `FIN${suffix}`.slice(0, 64),
licenseFileId: null, status: 'ACTIVE', settlementPeriod: 'MONTHLY_30', remark: marker,
}
}
async function createOrder(context, suffix, pricingProfile = null) {
if (context.financeFixtureHooks?.createOrder) return context.financeFixtureHooks.createOrder(context, suffix, pricingProfile)
const originalMarker = context.marker
@@ -260,41 +246,25 @@ async function loadPublishedAutomaticFee(context, resource) {
export async function loadSupplier(context, category, { carrierCode, truckingScope } = {}) {
if (context.financeFixtureHooks?.loadSupplier) return context.financeFixtureHooks.loadSupplier(context, category)
if (context.options?.fixedCustomerId) {
const matches = item => id(item?.id) && item.status === 'ACTIVE' && (!category || item.category === category)
&& (!carrierCode || item.carrierCodes?.includes(carrierCode)) && (!truckingScope || item.truckingScope === truckingScope)
for (let page = 1; ; page += 1) {
const response = await request(context, 'GET', `/api/platform/v1/suppliers?tenantId=0&status=ACTIVE&page=${page}&size=100`)
const data = context.apiSuccess(MODULE, '读取可复用的现有供应商', response, '', OPTIONS)
if (!data) return null
const records = rows(data)
const candidate = records.find(matches)
if (candidate) {
const detailResponse = await request(context, 'GET', `/api/platform/v1/suppliers/${encodeURIComponent(candidate.id)}?tenantId=0`)
const detail = context.apiSuccess(MODULE, '核对复用供应商状态与类别', detailResponse, '', OPTIONS)
if (id(detail?.id) === id(candidate.id) && matches(detail)) return detail
blocker(context, '复用供应商已变化', '候选详情不匹配,不创建替代供应商')
return null
}
if (!records.length || page * Number(data.size || 100) >= Number(data.total ?? records.length)) break
const matches = item => id(item?.id) && item.status === 'ACTIVE' && (!category || item.category === category)
&& (!carrierCode || item.carrierCodes?.includes(carrierCode)) && (!truckingScope || item.truckingScope === truckingScope)
for (let page = 1; ; page += 1) {
const response = await request(context, 'GET', `/api/platform/v1/suppliers?tenantId=0&status=ACTIVE&page=${page}&size=100`)
const data = context.apiSuccess(MODULE, '读取可复用的现有供应商', response, '', OPTIONS)
if (!data) return null
const records = rows(data)
const candidate = records.find(matches)
if (candidate) {
const detailResponse = await request(context, 'GET', `/api/platform/v1/suppliers/${encodeURIComponent(candidate.id)}?tenantId=0`)
const detail = context.apiSuccess(MODULE, '核对复用供应商状态与类别', detailResponse, '', OPTIONS)
if (id(detail?.id) === id(candidate.id) && matches(detail)) return detail
blocker(context, '复用供应商已变化', '候选详情不匹配,不创建替代供应商')
return null
}
blocker(context, '缺少可复用供应商', `需要 ACTIVE ${category || '任意类别'} 供应商;禁止自动创建`)
return null
if (!records.length || page * Number(data.size || 100) >= Number(data.total ?? records.length)) break
}
const effectiveCategory = category || 'BOOKING'
const body = buildSupplierBody(context.marker, effectiveCategory)
const response = await request(context, 'POST', '/api/platform/v1/suppliers?tenantId=0', body)
const supplierId = id(context.apiSuccess(MODULE, '创建本轮 Finance 隔离供应商', response,
`category=${effectiveCategory}`, OPTIONS))
if (!supplierId) return null
const detailResponse = await context.request('GET', `/api/platform/v1/suppliers/${encodeURIComponent(supplierId)}?tenantId=0`)
const detail = context.apiSuccess(MODULE, '回读本轮 Finance 隔离供应商', detailResponse,
`supplierId=${supplierId}`, OPTIONS)
context.assert(MODULE, 'Finance 供应商为 ACTIVE 且类别匹配费用项目', detailResponse,
id(detail?.id) === supplierId && detail?.status === 'ACTIVE' && (!category || detail?.category === category)
&& detail?.name === body.name,
`supplierId=${supplierId}, status=${detail?.status || 'missing'}, category=${detail?.category || 'missing'}`, OPTIONS)
return detail?.status === 'ACTIVE' && (!category || detail?.category === category) ? detail : null
blocker(context, '缺少可复用供应商', `需要 ACTIVE ${category || '任意类别'} 供应商;禁止自动创建`)
return null
}
async function uploadVoucher(context, customerId) {