rentease-backend/scripts/add-rooms-q千妗.js

73 lines
2.0 KiB
JavaScript
Raw Normal View History

2026-03-02 12:36:41 +00:00
const { Region, Apartment, Room } = require('../models');
// 房间列表
const roomNumbers = [
'201', '202', '203', '204',
'301', '302', '303', '304', '305', '306', '307',
'401', '402', '403', '404',
'501', '502'
];
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();