import * as dotenv from 'dotenv'; dotenv.config(); import pool from './src/config/database'; async function run() { // 查找 wyy 用户 const [users] = await pool.query("SELECT * FROM user WHERE username LIKE '%wyy%' OR name LIKE '%wyy%'"); console.log('找到用户:', users); if (users.length === 0) { console.log('未找到 wyy 用户,查看所有员工账号:'); const [all] = await pool.query("SELECT user_id, username, name, role FROM user WHERE role = 'employee'"); console.table(all); await pool.end(); return; } for (const user of users) { const userId = user.user_id; // 找到该用户的绩效记录 const [perfs] = await pool.query('SELECT perf_id FROM performance_month WHERE user_id = ?', [userId]); for (const perf of perfs) { await pool.query('DELETE FROM ai_result WHERE perf_id = ?', [perf.perf_id]); await pool.query('DELETE FROM attendance WHERE perf_id = ?', [perf.perf_id]); await pool.query('DELETE FROM perf_item WHERE perf_id = ?', [perf.perf_id]); } await pool.query('DELETE FROM performance_month WHERE user_id = ?', [userId]); await pool.query('DELETE FROM operation_log WHERE user_id = ?', [userId]); await pool.query('DELETE FROM user WHERE user_id = ?', [userId]); console.log(`已删除用户 ${user.username}(${user.name}) 及其所有数据`); } await pool.end(); console.log('完成'); } run().catch(console.error);