import { Client } from 'ssh2'; const conn = new Client(); conn.on('ready', () => { console.log('=== 重置订单ID ===\n'); console.log('1. 获取完整订单数据:'); conn.exec('curl -s http://localhost:4000/api/orders', (err, stream) => { if (err) { console.log('ERR:', err); conn.end(); return; } let output = ''; stream.on('data', (d) => output += d.toString()); stream.on('close', () => { try { const result = JSON.parse(output); const orders = result.data || []; console.log(`当前订单数: ${orders.length}`); console.log('当前订单ID:', orders.map(o => o.id).join(', ')); console.log('\n2. 重新编号订单ID...'); orders.forEach((order, idx) => { order.id = (idx + 1).toString(); }); console.log('新订单ID:', orders.map(o => o.id).join(', ')); const updatedData = JSON.stringify(orders, null, 2); console.log('\n3. 更新数据文件...'); conn.exec(`cat > /www/huishou/server/data/orders.json << 'EOF' ${updatedData} EOF`, (err, stream2) => { if (err) { console.log('ERR:', err); conn.end(); return; } stream2.on('close', () => { console.log('\n4. 重启容器...'); conn.exec('docker restart huishou-backend', (err, stream3) => { if (err) { console.log('ERR:', err); conn.end(); return; } stream3.on('close', () => { console.log('容器已重启!'); conn.end(); }); }); }); }); } catch (e) { console.log('解析错误:', e.message); console.log('输出:', output); conn.end(); } }); }); }); conn.on('error', (err) => { console.log('连接错误:', err.message); }); conn.connect({ host: 'hs.yifenbao.cn', port: 22, username: 'root', password: 'Torch1112' });