import { Client } from 'ssh2'; const conn = new Client(); const cleanStations = [ { "id": "mrk7uhka", "cityId": "1", "districtId": "d1", "name": "金融街融汇景苑" }, { "id": "mrmyqn5z", "cityId": "1", "districtId": "d1", "name": "景瑞誉景天地" }, { "id": "mrn2hu0d", "cityId": "1", "districtId": "d1", "name": "富御园" }, { "id": "mrltf4b3j65gh", "cityId": "1", "districtId": "d2", "name": "金融街融汇景苑" }, { "id": "s3", "cityId": "1", "districtId": "d2", "name": "华兴里" }, { "id": "s4", "cityId": "1", "districtId": "d2", "name": "华兴南里" }, { "id": "s5", "cityId": "1", "districtId": "mqugyhc6", "name": "意境兰庭" } ]; const uniqueStations = []; const seen = new Set(); cleanStations.forEach(s => { const key = `${s.cityId}-${s.districtId}-${s.name}`; if (!seen.has(key)) { seen.add(key); uniqueStations.push(s); } }); console.log('清理后站点:', JSON.stringify(uniqueStations, null, 2)); conn.on('ready', () => { console.log('\n=== 清理重复站点 ===\n'); const jsonStr = JSON.stringify(uniqueStations, null, 2); conn.exec(`echo "${jsonStr.replace(/"/g, '\\"')}" > /www/huishou/server/data/stations.json`, (err, stream) => { if (err) { console.log('ERR:', err); conn.end(); return; } stream.on('close', () => { console.log('站点数据已写入'); conn.exec('docker restart huishou-backend', (err, stream2) => { if (err) { console.log('ERR:', err); conn.end(); return; } stream2.on('close', () => { console.log('容器重启完成'); conn.end(); }); }); }); }); }); conn.on('error', (err) => { console.log('连接错误:', err.message); }); conn.connect({ host: 'hs.yifenbao.cn', port: 22, username: 'root', password: 'Torch1112' });