From 1f5bb628057315607ebf27dfcd3f20ea9572de8b Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 4 Mar 2026 08:25:15 -0800 Subject: [PATCH] =?UTF-8?q?fix(contribution-service):=20=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=90=8E=E5=86=99=E5=85=A5=20synced=5Fadopti?= =?UTF-8?q?ons=20=E8=AE=B0=E5=BD=95=E4=BB=A5=E8=A7=A3=E9=99=A4=E5=8D=96?= =?UTF-8?q?=E5=87=BA=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit swapContributionForMerge 在事务内新增步骤 9f: - 写入 synced_adoptions(original_adoption_id = 20B + mergeId) - 供 SellRestrictionService.isRestricted 的 has_real_tree 判断使用 - upsert 保证幂等,contributionDistributed 由调用方置 true Bug: 合并已完成(contribution_records 正确),但 isRestricted 始终 返回 true,因为 synced_adoptions 中没有 20B+ 记录(virtualAdoption 仅用于计算,未持久化)。 Co-Authored-By: Claude Sonnet 4.6 --- .../pre-planting-contribution.service.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/backend/services/contribution-service/src/pre-planting/application/services/pre-planting-contribution.service.ts b/backend/services/contribution-service/src/pre-planting/application/services/pre-planting-contribution.service.ts index c9b5f83e..cdfac55f 100644 --- a/backend/services/contribution-service/src/pre-planting/application/services/pre-planting-contribution.service.ts +++ b/backend/services/contribution-service/src/pre-planting/application/services/pre-planting-contribution.service.ts @@ -861,6 +861,26 @@ export class PrePlantingContributionService { where: { sourceAdoptionId: mergeSourceAdoptionId }, data: { remark: mergeRemark }, }); + + // 9f: 在 synced_adoptions 中写入合并树记录,供 sell-restriction 检查(has_real_tree 判断) + // originalAdoptionId 使用 20B 偏移,与 SellRestrictionService.MERGE_OFFSET 一致 + const totalPortionCount = sourceOrders.reduce((sum, o) => sum + o.portionCount, 0); + await tx.syncedAdoption.upsert({ + where: { originalAdoptionId: mergeSourceAdoptionId }, + create: { + originalAdoptionId: mergeSourceAdoptionId, + accountSequence, + treeCount: 1, + adoptionDate: miningEnabledAt, + status: 'MINING_ENABLED', + selectedProvince: firstOrder.provinceCode ?? '', + selectedCity: firstOrder.cityCode ?? '', + contributionPerTree: contributionPerTree, + sourceSequenceNum: BigInt(0), + distributionSummary: `PRE_PLANTING_MERGE:${mergeNo}:portions=${totalPortionCount}`, + }, + update: {}, // 幂等:已存在则不修改 + }); }); // Step 10: 插入幂等标记(最终一致性,事务提交后 best-effort 写入)