优化
This commit is contained in:
@@ -258,23 +258,25 @@ async function loadPublishedAutomaticFee(context, resource) {
|
||||
actualWeightKg: responseWeightKg, actualVolumeCbm: responseVolumeCbm }
|
||||
}
|
||||
|
||||
export async function loadSupplier(context, category) {
|
||||
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(item => id(item?.id) && item.status === 'ACTIVE' && (!category || item.category === category))
|
||||
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) && detail?.status === 'ACTIVE' && (!category || detail.category === category)) return detail
|
||||
if (id(detail?.id) === id(candidate.id) && matches(detail)) return detail
|
||||
blocker(context, '复用供应商已变化', '候选详情不匹配,不创建替代供应商')
|
||||
return null
|
||||
}
|
||||
if (!records.length || page * 100 >= Number(data.total ?? records.length)) break
|
||||
if (!records.length || page * Number(data.size || 100) >= Number(data.total ?? records.length)) break
|
||||
}
|
||||
blocker(context, '缺少可复用供应商', `需要 ACTIVE ${category || '任意类别'} 供应商;禁止自动创建`)
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user