73 lines
2.0 KiB
JavaScript
73 lines
2.0 KiB
JavaScript
|
|
const { Region, Apartment, Room } = require('../models');
|
|||
|
|
|
|||
|
|
// 房间列表
|
|||
|
|
const roomNumbers = [
|
|||
|
|
'301', '302', '303', '304', '305', '306', '307',
|
|||
|
|
'401', '402', '403', '404', '405', '406', '407',
|
|||
|
|
'501', '502', '503', '504', '505', '506', '507',
|
|||
|
|
'601', '602', '603', '604', '605', '606', '607'
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
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();
|