R31-5: 收口门禁稳定化与资产事务超时
这个提交包含在:
+66
-26
@@ -651,6 +651,43 @@ async function handleAssetLedgerSummaryErpSync({
|
||||
};
|
||||
}
|
||||
|
||||
async function runAssetLedgerSummaryErpSyncSafely({
|
||||
prisma,
|
||||
config,
|
||||
request,
|
||||
actorId,
|
||||
asset,
|
||||
sourceEventName,
|
||||
changeType,
|
||||
changedFields,
|
||||
}) {
|
||||
try {
|
||||
return await handleAssetLedgerSummaryErpSync({
|
||||
tx: prisma,
|
||||
config,
|
||||
request,
|
||||
actorId,
|
||||
asset,
|
||||
sourceEventName,
|
||||
changeType,
|
||||
changedFields,
|
||||
});
|
||||
} catch (error) {
|
||||
request.log.error(
|
||||
{
|
||||
err: error,
|
||||
assetId: asset?.id ?? null,
|
||||
assetNo: asset?.asset_no ?? null,
|
||||
sourceEventName,
|
||||
changeType,
|
||||
changedFields: Array.isArray(changedFields) ? changedFields : [],
|
||||
},
|
||||
"Asset ledger summary ERP sync failed after asset commit",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function assetsRoutes(fastify) {
|
||||
fastify.get(
|
||||
"/asset-categories",
|
||||
@@ -975,20 +1012,20 @@ async function assetsRoutes(fastify) {
|
||||
}),
|
||||
});
|
||||
|
||||
await handleAssetLedgerSummaryErpSync({
|
||||
tx,
|
||||
config: fastify.config,
|
||||
request,
|
||||
actorId: request.employee.id,
|
||||
asset: created,
|
||||
sourceEventName: 'asset.card.created',
|
||||
changeType: 'created',
|
||||
changedFields: [],
|
||||
});
|
||||
|
||||
return created;
|
||||
});
|
||||
|
||||
await runAssetLedgerSummaryErpSyncSafely({
|
||||
prisma: fastify.prisma,
|
||||
config: fastify.config,
|
||||
request,
|
||||
actorId: request.employee.id,
|
||||
asset,
|
||||
sourceEventName: 'asset.card.created',
|
||||
changeType: 'created',
|
||||
changedFields: [],
|
||||
});
|
||||
|
||||
return sendData(reply, request, { asset: mapAsset(asset, request, fastify) });
|
||||
},
|
||||
);
|
||||
@@ -1024,7 +1061,7 @@ async function assetsRoutes(fastify) {
|
||||
const assetId = parseUuid("id", request.params?.id);
|
||||
const payload = normalizeAssetPayload(parsePatchBody(ASSET_PATCH_SCHEMA, request.body));
|
||||
|
||||
const asset = await fastify.prisma.$transaction(async (tx) => {
|
||||
const { asset, assetLedgerSummaryChange } = await fastify.prisma.$transaction(async (tx) => {
|
||||
const current = await tx.assetCard.findUnique({
|
||||
where: { id: assetId },
|
||||
select: {
|
||||
@@ -1097,22 +1134,25 @@ async function assetsRoutes(fastify) {
|
||||
});
|
||||
|
||||
const assetLedgerSummaryChange = resolveAssetLedgerSummaryChange(current, updated);
|
||||
if (assetLedgerSummaryChange) {
|
||||
await handleAssetLedgerSummaryErpSync({
|
||||
tx,
|
||||
config: fastify.config,
|
||||
request,
|
||||
actorId: request.employee.id,
|
||||
asset: updated,
|
||||
sourceEventName: assetLedgerSummaryChange.sourceEventName,
|
||||
changeType: assetLedgerSummaryChange.changeType,
|
||||
changedFields: assetLedgerSummaryChange.changedFields,
|
||||
});
|
||||
}
|
||||
|
||||
return updated;
|
||||
return {
|
||||
asset: updated,
|
||||
assetLedgerSummaryChange,
|
||||
};
|
||||
});
|
||||
|
||||
if (assetLedgerSummaryChange) {
|
||||
await runAssetLedgerSummaryErpSyncSafely({
|
||||
prisma: fastify.prisma,
|
||||
config: fastify.config,
|
||||
request,
|
||||
actorId: request.employee.id,
|
||||
asset,
|
||||
sourceEventName: assetLedgerSummaryChange.sourceEventName,
|
||||
changeType: assetLedgerSummaryChange.changeType,
|
||||
changedFields: assetLedgerSummaryChange.changedFields,
|
||||
});
|
||||
}
|
||||
|
||||
return sendData(reply, request, { asset: mapAsset(asset, request, fastify) });
|
||||
},
|
||||
);
|
||||
|
||||
在新工单中引用
屏蔽一个用户