|
|
@ -555,6 +555,7 @@ public class MysqlServiceImpl implements MysqlService { |
|
|
stmt.setString(1, uid); |
|
|
stmt.setString(1, uid); |
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
try (ResultSet rs = stmt.executeQuery()) { |
|
|
return rs.next(); |
|
|
return rs.next(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -779,13 +780,22 @@ public class MysqlServiceImpl implements MysqlService { |
|
|
String[] parts = entry.getKey().split("_"); |
|
|
String[] parts = entry.getKey().split("_"); |
|
|
int jwcode = Integer.parseInt(parts[0]); |
|
|
int jwcode = Integer.parseInt(parts[0]); |
|
|
int walletId = Integer.parseInt(parts[1]); |
|
|
int walletId = Integer.parseInt(parts[1]); |
|
|
|
|
|
int amount = entry.getValue(); |
|
|
|
|
|
|
|
|
|
|
|
// 生成钱包流水单号(独立于业务单号,便于追溯) |
|
|
|
|
|
String recordOrderCode = "WALLET_CZ_" + System.currentTimeMillis() + "_" + UUID.randomUUID().toString().substring(0, 6); |
|
|
|
|
|
|
|
|
|
|
|
// ① 加入余额更新批次 |
|
|
stmt.setInt(1, jwcode); |
|
|
stmt.setInt(1, jwcode); |
|
|
stmt.setString(2, String.valueOf(walletId)); |
|
|
stmt.setString(2, String.valueOf(walletId)); |
|
|
stmt.setInt(3, entry.getValue()); |
|
|
|
|
|
|
|
|
stmt.setInt(3, amount); |
|
|
stmt.addBatch(); |
|
|
stmt.addBatch(); |
|
|
|
|
|
|
|
|
|
|
|
// ② 写入明细记录(安全隔离,失败仅打日志) |
|
|
|
|
|
insertWalletRecordSafe(mysqlConn, jwcode, walletId, 0, amount, recordOrderCode, "地区钱包充值"); |
|
|
} |
|
|
} |
|
|
int[] results = stmt.executeBatch(); |
|
|
int[] results = stmt.executeBatch(); |
|
|
logger.info("✅ [充值完成] 地区钱包充值更新成功 {} 条", results.length); |
|
|
|
|
|
|
|
|
logger.info("✅ [充值完成] 地区钱包余额更新成功 {} 条,同步写入明细 {} 条", results.length, userWalletGoldMap.size()); |
|
|
} catch (SQLException e) { |
|
|
} catch (SQLException e) { |
|
|
logger.error("❌ [充值失败] 更新 user_region_wallet 异常", e); |
|
|
logger.error("❌ [充值失败] 更新 user_region_wallet 异常", e); |
|
|
} |
|
|
} |
|
|
@ -889,10 +899,15 @@ public class MysqlServiceImpl implements MysqlService { |
|
|
stmt.setString(3, String.valueOf(deduct.walletId)); |
|
|
stmt.setString(3, String.valueOf(deduct.walletId)); |
|
|
stmt.setInt(4, deduct.amount); |
|
|
stmt.setInt(4, deduct.amount); |
|
|
stmt.addBatch(); |
|
|
stmt.addBatch(); |
|
|
logger.debug(" ➖ [扣减] walletId={}, amount={}", deduct.walletId, deduct.amount); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 写入消费明细(安全隔离,失败仅打日志) |
|
|
|
|
|
String recordOrderCode = "WALLET_XF_" + System.currentTimeMillis() + "_" + UUID.randomUUID().toString().substring(0, 6); |
|
|
|
|
|
insertWalletRecordSafe(conn, jwcode, deduct.walletId, 1, deduct.amount, recordOrderCode, "地区钱包消费扣减"); |
|
|
} |
|
|
} |
|
|
int[] results = stmt.executeBatch(); |
|
|
int[] results = stmt.executeBatch(); |
|
|
logger.debug("✅ [扣减执行] 成功 {} 条", results.length); |
|
|
|
|
|
|
|
|
logger.debug("✅ [扣减执行] 余额更新成功 {} 条,同步写入明细 {} 条", results.length, deducts.size()); |
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
logger.error("❌ [扣减失败] 执行钱包扣减异常", e); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -927,4 +942,23 @@ public class MysqlServiceImpl implements MysqlService { |
|
|
default -> 1; |
|
|
default -> 1; |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
|
|
|
* 安全写入钱包明细(异常隔离,确保不影响主流程) |
|
|
|
|
|
*/ |
|
|
|
|
|
private void insertWalletRecordSafe(Connection conn, int jwcode, int walletId, int type, int amount, String orderCode, String description) { |
|
|
|
|
|
String sql = "INSERT INTO user_wallet_record (jwcode, wallet_id, type, amount, order_code, description, status, create_time, update_time) " + |
|
|
|
|
|
"VALUES (?, ?, ?, ?, ?, ?, 0, NOW(), NOW())"; |
|
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) { |
|
|
|
|
|
stmt.setInt(1, jwcode); |
|
|
|
|
|
stmt.setInt(2, walletId); |
|
|
|
|
|
stmt.setInt(3, type); |
|
|
|
|
|
stmt.setInt(4, amount); |
|
|
|
|
|
stmt.setString(5, orderCode); |
|
|
|
|
|
stmt.setString(6, description); |
|
|
|
|
|
stmt.executeUpdate(); |
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
// ⚠️ 核心:仅记录 ERROR 日志,绝对不 throw,确保金币同步/余额更新流程 100% 不受影响 |
|
|
|
|
|
logger.error("📝 钱包明细记录写入失败(已安全隔离) jwcode={}, walletId={}, amount={}", jwcode, walletId, amount, e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |