|
|
@@ -101,9 +101,17 @@ public class CfLegacyLedgerMigrationService {
|
|
|
if (row.memberId == null) {
|
|
|
if (hasMigratableValue(row.totalEarned, row.available, row.frozen,
|
|
|
row.withdrawn, row.exchanged)) {
|
|
|
- unresolved++;
|
|
|
- log.error("迁移417: 家庭池 familyId={} 找不到创建者对应的 family_member",
|
|
|
- row.familyId);
|
|
|
+ if (isOrphanFamilyPool(row.familyId, row.userId)) {
|
|
|
+ // 孤儿家庭池:家庭不存在或该家庭已无任何家庭成员(创建者亦不在列)。
|
|
|
+ // 余额保留旧表 family_platform_balance 供人工处置,跳过迁移,不阻塞整批。
|
|
|
+ log.warn("迁移417: 家庭池 familyId={} 已无任何家庭成员(含创建者),"
|
|
|
+ + "存量 CF {} 保留在 family_platform_balance 待人工处理,本次跳过不迁移",
|
|
|
+ row.familyId, row.available + row.frozen);
|
|
|
+ } else {
|
|
|
+ unresolved++;
|
|
|
+ log.error("迁移417: 家庭池 familyId={} 找不到创建者对应的 family_member",
|
|
|
+ row.familyId);
|
|
|
+ }
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
@@ -270,6 +278,26 @@ public class CfLegacyLedgerMigrationService {
|
|
|
|| withdrawn != 0 || exchanged != 0;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 判断家庭池是否已无可归属成员(孤儿):家庭记录不存在,或该家庭已无任何 family_members。
|
|
|
+ * 孤儿池余额保留旧表不迁移(不静默丢弃),也不计入 unresolved 阻塞其余正常账本迁入。
|
|
|
+ * 成员数查询失败时保守返回 false(仍走 unresolved 阻断,保持原有安全语义)。
|
|
|
+ */
|
|
|
+ private boolean isOrphanFamilyPool(Long familyId, Long userId) {
|
|
|
+ if (userId == null) {
|
|
|
+ return true; // families 无此家庭记录(LEFT JOIN 未命中)
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Integer count = jdbcTemplate.queryForObject(
|
|
|
+ "SELECT COUNT(*) FROM family_members WHERE family_id = ?",
|
|
|
+ Integer.class, familyId);
|
|
|
+ return count != null && count == 0;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("迁移417: 查询家庭 {} 成员数失败: {}", familyId, e.getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/** 有价值但找不到目标成员的旧账本必须让整批回滚,禁止静默丢失 CF 值。 */
|
|
|
private static void assertNoUnresolvedSource(String refType, int unresolved) {
|
|
|
if (unresolved > 0) {
|