import { PrismaClient } from '@prisma/client' import bcrypt from 'bcryptjs' import { randomBytes } from 'crypto' const prisma = new PrismaClient() async function main() { // 创建测试企业 let org = await prisma.organization.findFirst({ where: { name: '测试科技有限公司' } }) if (!org) { org = await prisma.organization.create({ data: { name: '测试科技有限公司', plan: 'FREE', maxEmployees: 20, city: '上海', }, }) } // 创建管理员用户 const passwordHash = await bcrypt.hash('12345678', 10) const admin = await prisma.user.upsert({ where: { phone: '13800000001' }, update: {}, create: { orgId: org.id, phone: '13800000001', name: '管理员', passwordHash, role: 'ADMIN', }, }) // 创建测试员工 const salaryHash = randomBytes(32).toString('hex') const employee = await prisma.employee.create({ data: { orgId: org.id, name: '张三', department: '技术部', hireDate: new Date('2026-01-15'), monthlySalary: 'encrypted:' + salaryHash, phone: '13900000001', gender: '男', createdBy: admin.id, }, }) // 创建测试合同 await prisma.laborContract.create({ data: { orgId: org.id, employeeId: employee.id, signDate: new Date('2026-01-20'), startDate: new Date('2026-02-01'), endDate: new Date('2029-01-31'), contractType: 'FIXED', signMethod: 'PAPER', contractYears: 3, probationMonths: 2, probationSalary: 6400, createdBy: admin.id, }, }) console.log('Seed data created:', { org: org.id, admin: admin.id, employee: employee.id }) } main() .catch((e) => { console.error(e) process.exit(1) }) .finally(async () => { await prisma.$disconnect() })