73 lines
2.0 KiB
JavaScript
73 lines
2.0 KiB
JavaScript
const { Region, Apartment, Room } = require('../models');
|
||
|
||
// 房间列表
|
||
const roomNumbers = [
|
||
'201', '202', '203', '205', '206', '208', '209',
|
||
'301', '302', '303', '305', '306', '308', '309',
|
||
'401', '402', '403', '405', '406', '408', '409',
|
||
'501', '502', '503', '505', '506', '508', '509'
|
||
];
|
||
|
||
async function addRooms() {
|
||
try {
|
||
console.log('开始添加房间...');
|
||
|
||
// 查找或创建碧云公寓
|
||
let apartment = await Apartment.findOne({ where: { name: '碧云公寓' } });
|
||
|
||
if (!apartment) {
|
||
console.log('碧云公寓不存在,创建中...');
|
||
// 查找或创建大商汇区域
|
||
let region = await Region.findOne({ where: { name: '大商汇' } });
|
||
if (!region) {
|
||
region = await Region.create({ name: '大商汇', description: '大商汇区域' });
|
||
console.log('创建了大商汇区域');
|
||
}
|
||
|
||
// 创建碧云公寓
|
||
apartment = await Apartment.create({
|
||
regionId: region.id,
|
||
name: '碧云公寓',
|
||
address: '大商汇区域'
|
||
});
|
||
console.log('创建了碧云公寓');
|
||
} else {
|
||
console.log('找到碧云公寓,ID:', apartment.id);
|
||
}
|
||
|
||
// 添加房间
|
||
console.log('开始添加房间...');
|
||
for (const roomNumber of roomNumbers) {
|
||
// 检查房间是否已存在
|
||
const existingRoom = await Room.findOne({
|
||
where: {
|
||
apartmentId: apartment.id,
|
||
roomNumber: roomNumber
|
||
}
|
||
});
|
||
|
||
if (!existingRoom) {
|
||
await Room.create({
|
||
apartmentId: apartment.id,
|
||
roomNumber: roomNumber,
|
||
area: 25, // 默认面积
|
||
price: 2000, // 默认价格
|
||
status: 'empty' // 空房状态
|
||
});
|
||
console.log(`添加了房间: ${roomNumber}`);
|
||
} else {
|
||
console.log(`房间 ${roomNumber} 已存在,跳过`);
|
||
}
|
||
}
|
||
|
||
console.log('房间添加完成!');
|
||
process.exit(0);
|
||
} catch (error) {
|
||
console.error('添加房间时出错:', error);
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
// 执行脚本
|
||
addRooms();
|