fix-config-issue.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // 修复配置表不一致问题
  2. const { exec } = require('child_process');
  3. const util = require('util');
  4. const execPromise = util.promisify(exec);
  5. async function fixConfigIssue() {
  6. console.log('=== 修复飞鹅配置表不一致问题 ===\n');
  7. try {
  8. // 1. 检查当前配置状态
  9. console.log('1. 当前配置状态:');
  10. // system_config_mt 表中的飞鹅配置
  11. const { stdout: systemConfig } = await execPromise(
  12. 'psql -h 127.0.0.1 -U postgres -d postgres -c "SELECT config_key, config_value FROM system_config_mt WHERE tenant_id = 1 AND config_key LIKE \'feie.%\' ORDER BY config_key"'
  13. );
  14. console.log('system_config_mt 表:');
  15. console.log(systemConfig);
  16. // feie_config_mt 表中的配置
  17. const { stdout: feieConfig } = await execPromise(
  18. 'psql -h 127.0.0.1 -U postgres -d postgres -c "SELECT config_key, config_value FROM feie_config_mt WHERE tenant_id = 1 ORDER BY config_key"'
  19. );
  20. console.log('feie_config_mt 表:');
  21. console.log(feieConfig);
  22. // 2. 将 system_config_mt 中的配置复制到 feie_config_mt
  23. console.log('\n2. 同步配置到 feie_config_mt 表...');
  24. const configsToSync = [
  25. { key: 'feie.api.user', value: '2638601246@qq.com' },
  26. { key: 'feie.api.ukey', value: 'tAwVmIEv48zcIu2Y' },
  27. { key: 'feie.api.base_url', value: 'https://api.feieyun.cn/Api/Open/' },
  28. { key: 'feie.api.timeout', value: '10000' },
  29. { key: 'feie.api.max_retries', value: '3' },
  30. { key: 'feie.anti_refund_delay', value: '120' }
  31. ];
  32. for (const config of configsToSync) {
  33. console.log(` 同步 ${config.key} = ${config.value}`);
  34. // 使用 UPSERT (INSERT ... ON CONFLICT ... DO UPDATE)
  35. const upsertSql = `
  36. INSERT INTO feie_config_mt (tenant_id, config_key, config_value, created_at, updated_at)
  37. VALUES (1, '${config.key}', '${config.value}', NOW(), NOW())
  38. ON CONFLICT (tenant_id, config_key)
  39. DO UPDATE SET config_value = EXCLUDED.config_value, updated_at = NOW()
  40. `;
  41. await execPromise(`psql -h 127.0.0.1 -U postgres -d postgres -c "${upsertSql}"`);
  42. }
  43. // 3. 验证修复结果
  44. console.log('\n3. 验证修复结果...');
  45. const { stdout: finalConfig } = await execPromise(
  46. 'psql -h 127.0.0.1 -U postgres -d postgres -c "SELECT config_key, config_value FROM feie_config_mt WHERE tenant_id = 1 ORDER BY config_key"'
  47. );
  48. console.log('修复后的 feie_config_mt 表:');
  49. console.log(finalConfig);
  50. // 4. 检查必要的配置是否完整
  51. console.log('\n4. 检查配置完整性...');
  52. const requiredConfigs = [
  53. 'feie.api.user',
  54. 'feie.api.ukey',
  55. 'feie.api.base_url',
  56. 'feie.anti_refund_delay'
  57. ];
  58. const { stdout: checkResult } = await execPromise(
  59. `psql -h 127.0.0.1 -U postgres -d postgres -c "SELECT config_key FROM feie_config_mt WHERE tenant_id = 1 AND config_key IN ('${requiredConfigs.join("','")}')"`
  60. );
  61. const lines = checkResult.trim().split('\n');
  62. const foundConfigs = lines.slice(2, -1).map(line => line.trim()); // 跳过标题行和空行
  63. console.log(` 找到 ${foundConfigs.length}/${requiredConfigs.length} 个必要配置:`);
  64. requiredConfigs.forEach(key => {
  65. const found = foundConfigs.includes(key);
  66. console.log(` ${key}: ${found ? '✅' : '❌'}`);
  67. });
  68. if (foundConfigs.length === requiredConfigs.length) {
  69. console.log('\n✅ 配置修复完成!');
  70. console.log('\n现在可以测试支付成功触发API:');
  71. console.log('curl -X POST http://localhost:8080/api/v1/payments/payment/trigger-success \\');
  72. console.log(' -H "Content-Type: application/json" \\');
  73. console.log(' -H "Authorization: Bearer YOUR_TOKEN" \\');
  74. console.log(' -d \'{"orderId": 25}\'');
  75. } else {
  76. console.log('\n❌ 配置仍然不完整,请手动添加缺失的配置。');
  77. }
  78. } catch (error) {
  79. console.error('修复失败:', error.message);
  80. }
  81. }
  82. fixConfigIssue().catch(console.error);