feat(P19ERP3-1,P19ERP3-2): 实现资产ERP摘要服务与建卡/流转出站联动
这个提交包含在:
@@ -41,6 +41,13 @@ function resolveProcurementExportEndpoint(config) {
|
||||
);
|
||||
}
|
||||
|
||||
function resolveAssetExportEndpoint(config) {
|
||||
return (
|
||||
String(config.erpAssetExportEndpoint ?? '').trim() ||
|
||||
String(config.erpSyncEndpoint ?? '').trim()
|
||||
);
|
||||
}
|
||||
|
||||
async function parseResponseBody(response) {
|
||||
const contentType = response.headers.get('content-type') || '';
|
||||
if (contentType.includes('application/json')) {
|
||||
@@ -236,6 +243,55 @@ async function exportJournalToErp(config, payload) {
|
||||
};
|
||||
}
|
||||
|
||||
async function exportAssetToErp(config, payload) {
|
||||
if (!config.erpSyncEnabled) {
|
||||
return {
|
||||
ok: false,
|
||||
code: 'erp_sync_disabled',
|
||||
message: 'ERP sync disabled',
|
||||
retryable: false,
|
||||
};
|
||||
}
|
||||
|
||||
const provider = normalizeProvider(config);
|
||||
if (provider === 'mock') {
|
||||
const identity = payload?.assetNo ?? payload?.entityId ?? 'UNKNOWN';
|
||||
return {
|
||||
ok: true,
|
||||
code: 'mock_synced',
|
||||
message: 'mock ERP asset synced',
|
||||
response: {
|
||||
externalAssetId: `ERP-ASSET-${identity}`,
|
||||
externalAssetNo: `ERP-ASSET-${identity}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (provider === 'http') {
|
||||
return postJsonToErp(config, {
|
||||
endpoint: resolveAssetExportEndpoint(config),
|
||||
timeoutMs: coerceTimeout(config.erpAssetTimeoutMs, config.erpSyncTimeoutMs),
|
||||
payload,
|
||||
successCode: 'http_synced',
|
||||
successMessage: 'ERP asset synced',
|
||||
missingEndpointCode: 'erp_asset_endpoint_missing',
|
||||
missingEndpointMessage: 'ERP asset endpoint missing',
|
||||
http4xxCode: 'erp_asset_http_4xx',
|
||||
http5xxCode: 'erp_asset_http_5xx',
|
||||
timeoutCode: 'erp_asset_timeout',
|
||||
networkCode: 'erp_asset_network_error',
|
||||
messagePrefix: 'ERP asset sync',
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
ok: false,
|
||||
code: 'erp_sync_provider_invalid',
|
||||
message: `Unsupported ERP sync provider: ${provider}`,
|
||||
retryable: false,
|
||||
};
|
||||
}
|
||||
|
||||
async function exportProcurementToErp(config, payload) {
|
||||
if (!config.erpSyncEnabled) {
|
||||
return {
|
||||
@@ -299,6 +355,7 @@ async function pushPaidReimbursementToErp(config, payload) {
|
||||
|
||||
module.exports = {
|
||||
buildErpPayload,
|
||||
exportAssetToErp,
|
||||
exportJournalToErp,
|
||||
exportProcurementToErp,
|
||||
normalizeProvider,
|
||||
|
||||
在新工单中引用
屏蔽一个用户