const Department = require('../models/Department'); const Position = require('../models/Position'); const sequelize = require('../config/database'); // 查看数据库中的部门和岗位 async function checkData() { try { console.log('连接数据库...'); // 获取所有部门 console.log('\n查询所有部门...'); const departments = await Department.findAll(); console.log(`找到 ${departments.length} 个部门:`); departments.forEach(dept => { console.log(`- ID: ${dept.id}, 名称: ${dept.name}, 描述: ${dept.description}`); }); // 获取所有岗位 console.log('\n查询所有岗位...'); const positions = await Position.findAll({ include: [ { model: Department, as: 'department', attributes: ['name'] } ] }); console.log(`找到 ${positions.length} 个岗位:`); positions.forEach(pos => { console.log(`- ID: ${pos.id}, 名称: ${pos.name}, 部门ID: ${pos.department_id}, 部门名称: ${pos.department?.name || '未知'}`); }); console.log('\n查询完成!'); process.exit(0); } catch (error) { console.error('查询数据失败:', error); process.exit(1); } } // 执行查询 checkData();