初始化
This commit is contained in:
commit
cbcd2f2ee2
|
|
@ -0,0 +1,3 @@
|
||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
.idea/
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
const express = require('express');
|
||||||
|
const cors = require('cors');
|
||||||
|
const sequelize = require('./config/db');
|
||||||
|
|
||||||
|
// 导入路由
|
||||||
|
const regionRoutes = require('./routes/region');
|
||||||
|
const apartmentRoutes = require('./routes/apartment');
|
||||||
|
const roomRoutes = require('./routes/room');
|
||||||
|
const tenantRoutes = require('./routes/tenant');
|
||||||
|
const contractRoutes = require('./routes/contract');
|
||||||
|
const rentalRoutes = require('./routes/rental');
|
||||||
|
const statisticsRoutes = require('./routes/statistics');
|
||||||
|
const waterBillRoutes = require('./routes/waterBill');
|
||||||
|
const electricityBillRoutes = require('./routes/electricityBill');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
||||||
|
// 中间件
|
||||||
|
app.use(cors());
|
||||||
|
app.use(express.json());
|
||||||
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
|
||||||
|
// 路由
|
||||||
|
app.use('/api/regions', regionRoutes);
|
||||||
|
app.use('/api/apartments', apartmentRoutes);
|
||||||
|
app.use('/api/rooms', roomRoutes);
|
||||||
|
app.use('/api/tenants', tenantRoutes);
|
||||||
|
app.use('/api/contracts', contractRoutes);
|
||||||
|
app.use('/api/rentals', rentalRoutes);
|
||||||
|
app.use('/api/statistics', statisticsRoutes);
|
||||||
|
app.use('/api/water-bills', waterBillRoutes);
|
||||||
|
app.use('/api/electricity-bills', electricityBillRoutes);
|
||||||
|
|
||||||
|
// 测试接口
|
||||||
|
app.get('/', (req, res) => {
|
||||||
|
res.json({ message: 'Rentease API 服务运行正常' });
|
||||||
|
});
|
||||||
|
|
||||||
|
// 启动服务器
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log(`服务器运行在 http://localhost:${PORT}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = app;
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
const sequelize = require('./config/db');
|
||||||
|
const { Region, Apartment, Room, Tenant, Contract, Rental } = require('./models');
|
||||||
|
|
||||||
|
// 检查数据库数据的函数
|
||||||
|
async function checkData() {
|
||||||
|
try {
|
||||||
|
console.log('开始检查数据库数据...');
|
||||||
|
|
||||||
|
// 检查区域数据
|
||||||
|
const regions = await Region.findAll();
|
||||||
|
console.log(`区域数据数量: ${regions.length}`);
|
||||||
|
regions.forEach(region => {
|
||||||
|
console.log(`区域: ${region.name}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 检查公寓数据
|
||||||
|
const apartments = await Apartment.findAll();
|
||||||
|
console.log(`\n公寓数据数量: ${apartments.length}`);
|
||||||
|
apartments.forEach(apartment => {
|
||||||
|
console.log(`公寓: ${apartment.name}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 检查房间数据
|
||||||
|
const rooms = await Room.findAll();
|
||||||
|
console.log(`\n房间数据数量: ${rooms.length}`);
|
||||||
|
rooms.forEach(room => {
|
||||||
|
console.log(`房间: ${room.roomNumber}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 检查租客数据
|
||||||
|
const tenants = await Tenant.findAll();
|
||||||
|
console.log(`\n租客数据数量: ${tenants.length}`);
|
||||||
|
tenants.forEach(tenant => {
|
||||||
|
console.log(`租客: ${tenant.name}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 检查合同数据
|
||||||
|
const contracts = await Contract.findAll();
|
||||||
|
console.log(`\n合同数据数量: ${contracts.length}`);
|
||||||
|
contracts.forEach(contract => {
|
||||||
|
console.log(`合同 ID: ${contract.id}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 检查租房数据
|
||||||
|
const rentals = await Rental.findAll();
|
||||||
|
console.log(`\n租房数据数量: ${rentals.length}`);
|
||||||
|
rentals.forEach(rental => {
|
||||||
|
console.log(`租房 ID: ${rental.id}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('\n数据检查完成!');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('检查数据时出错:', error);
|
||||||
|
} finally {
|
||||||
|
// 关闭数据库连接
|
||||||
|
await sequelize.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行检查操作
|
||||||
|
checkData();
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
const sequelize = require('./config/db');
|
||||||
|
const { Room, Rental, Tenant, Contract } = require('./models');
|
||||||
|
|
||||||
|
// 清空数据的函数
|
||||||
|
async function clearData() {
|
||||||
|
try {
|
||||||
|
console.log('开始清空数据...');
|
||||||
|
|
||||||
|
// 按照依赖关系的顺序删除数据
|
||||||
|
// 先删除租房记录(依赖于房间、租客和合同)
|
||||||
|
await Rental.destroy({ where: {} });
|
||||||
|
console.log('租房数据已删除');
|
||||||
|
|
||||||
|
// 删除合同记录(依赖于房间和租客)
|
||||||
|
await Contract.destroy({ where: {} });
|
||||||
|
console.log('合同数据已删除');
|
||||||
|
|
||||||
|
// 删除房间记录(依赖于公寓)
|
||||||
|
await Room.destroy({ where: {} });
|
||||||
|
console.log('房间数据已删除');
|
||||||
|
|
||||||
|
// 删除租客记录(无依赖)
|
||||||
|
await Tenant.destroy({ where: {} });
|
||||||
|
console.log('租客数据已删除');
|
||||||
|
|
||||||
|
console.log('数据清空完成!');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('清空数据时出错:', error);
|
||||||
|
} finally {
|
||||||
|
// 关闭数据库连接
|
||||||
|
await sequelize.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行清空操作
|
||||||
|
clearData();
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
const { Sequelize } = require('sequelize');
|
||||||
|
const mysql = require('mysql2/promise');
|
||||||
|
|
||||||
|
// 先创建数据库
|
||||||
|
const createDatabase = async () => {
|
||||||
|
try {
|
||||||
|
// 连接到MySQL服务器
|
||||||
|
const connection = await mysql.createConnection({
|
||||||
|
host: 'localhost',
|
||||||
|
user: 'root',
|
||||||
|
password: '123456'
|
||||||
|
});
|
||||||
|
|
||||||
|
// 创建数据库
|
||||||
|
await connection.query('CREATE DATABASE IF NOT EXISTS rentease');
|
||||||
|
console.log('数据库创建成功');
|
||||||
|
await connection.end();
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('创建数据库失败:', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 创建数据库连接 - 使用MySQL
|
||||||
|
const sequelize = new Sequelize(
|
||||||
|
'rentease', // 数据库名称
|
||||||
|
'root', // 用户名
|
||||||
|
'123456', // 密码
|
||||||
|
{
|
||||||
|
host: 'localhost',
|
||||||
|
dialect: 'mysql',
|
||||||
|
logging: false,
|
||||||
|
timezone: '+08:00'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 测试数据库连接
|
||||||
|
const testConnection = async () => {
|
||||||
|
try {
|
||||||
|
await createDatabase();
|
||||||
|
// 重新创建sequelize实例,确保连接管理器是活跃的
|
||||||
|
const newSequelize = new Sequelize(
|
||||||
|
'rentease', // 数据库名称
|
||||||
|
'root', // 用户名
|
||||||
|
'123456', // 密码
|
||||||
|
{
|
||||||
|
host: 'localhost',
|
||||||
|
dialect: 'mysql',
|
||||||
|
logging: false,
|
||||||
|
timezone: '+08:00'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
await newSequelize.authenticate();
|
||||||
|
console.log('数据库连接成功');
|
||||||
|
return newSequelize;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('数据库连接失败:', error);
|
||||||
|
return sequelize;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 导出sequelize实例
|
||||||
|
module.exports = sequelize;
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
const sequelize = require('./db');
|
||||||
|
const { Region, Apartment, Room, Tenant, Contract, Rental } = require('../models');
|
||||||
|
|
||||||
|
// 同步数据库表结构
|
||||||
|
const syncDatabase = async () => {
|
||||||
|
try {
|
||||||
|
console.log('正在同步数据库表结构...');
|
||||||
|
await sequelize.sync({ force: true });
|
||||||
|
console.log('数据库表结构同步成功');
|
||||||
|
|
||||||
|
// 插入初始数据
|
||||||
|
await insertInitialData();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('数据库表结构同步失败:', error);
|
||||||
|
} finally {
|
||||||
|
await sequelize.close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 插入初始数据
|
||||||
|
const insertInitialData = async () => {
|
||||||
|
try {
|
||||||
|
// 插入区域数据
|
||||||
|
const regions = await Region.bulkCreate([
|
||||||
|
{ id: 1, name: '大商汇', description: '大商汇区域', createTime: '2023-01-06' },
|
||||||
|
{ id: 2, name: '丰源市场', description: '丰源市场区域', createTime: '2023-01-07' }
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 插入公寓数据
|
||||||
|
const apartments = await Apartment.bulkCreate([
|
||||||
|
{ id: 1, regionId: 1, name: '爱奇艺公寓', address: '大商汇区域', createTime: '2023-01-18' },
|
||||||
|
{ id: 2, regionId: 2, name: '碧云公寓', address: '丰源市场区域', createTime: '2023-01-19' }
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 插入房间数据
|
||||||
|
const rooms = await Room.bulkCreate([
|
||||||
|
// 大商汇 - 爱奇艺公寓
|
||||||
|
{ id: 1, apartmentId: 1, roomNumber: '401', area: 40, price: 2500, status: 'empty', createTime: '2023-01-18' },
|
||||||
|
{ id: 2, apartmentId: 1, roomNumber: '402', area: 40, price: 2500, status: 'empty', createTime: '2023-01-18' },
|
||||||
|
{ id: 3, apartmentId: 1, roomNumber: '403', area: 45, price: 2800, status: 'rented', createTime: '2023-01-18' },
|
||||||
|
{ id: 4, apartmentId: 1, roomNumber: '404', area: 45, price: 2800, status: 'soon_expire', createTime: '2023-01-18' },
|
||||||
|
{ id: 5, apartmentId: 1, roomNumber: '405', area: 50, price: 3000, status: 'empty', createTime: '2023-01-18' },
|
||||||
|
{ id: 6, apartmentId: 1, roomNumber: '406', area: 50, price: 3000, status: 'expired', createTime: '2023-01-18' },
|
||||||
|
{ id: 7, apartmentId: 1, roomNumber: '407', area: 55, price: 3200, status: 'cleaning', createTime: '2023-01-18' },
|
||||||
|
// 丰源市场 - 碧云公寓
|
||||||
|
{ id: 8, apartmentId: 2, roomNumber: '201', area: 35, price: 2200, status: 'empty', createTime: '2023-01-19' },
|
||||||
|
{ id: 9, apartmentId: 2, roomNumber: '202', area: 35, price: 2200, status: 'rented', createTime: '2023-01-19' },
|
||||||
|
{ id: 10, apartmentId: 2, roomNumber: '203', area: 40, price: 2400, status: 'empty', createTime: '2023-01-19' },
|
||||||
|
{ id: 11, apartmentId: 2, roomNumber: '205', area: 40, price: 2400, status: 'maintenance', createTime: '2023-01-19' },
|
||||||
|
{ id: 12, apartmentId: 2, roomNumber: '206', area: 45, price: 2600, status: 'rented', createTime: '2023-01-19' },
|
||||||
|
{ id: 13, apartmentId: 2, roomNumber: '208', area: 45, price: 2600, status: 'empty', createTime: '2023-01-19' },
|
||||||
|
{ id: 14, apartmentId: 2, roomNumber: '209', area: 50, price: 2800, status: 'soon_expire', createTime: '2023-01-19' }
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 插入租客数据
|
||||||
|
const tenants = await Tenant.bulkCreate([
|
||||||
|
{ id: 1, name: '张三', phone: '13800138001', idCard: '110101199001011234', createTime: '2023-02-01' },
|
||||||
|
{ id: 2, name: '李四', phone: '13800138002', idCard: '110101199001011235', createTime: '2023-02-02' },
|
||||||
|
{ id: 3, name: '王五', phone: '13800138003', idCard: '110101199001011236', createTime: '2023-02-03' },
|
||||||
|
{ id: 4, name: '赵六', phone: '13800138004', idCard: '110101199001011237', createTime: '2023-02-04' },
|
||||||
|
{ id: 5, name: '钱七', phone: '13800138005', idCard: '110101199001011238', createTime: '2023-02-05' }
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 插入合同数据
|
||||||
|
const contracts = await Contract.bulkCreate([
|
||||||
|
{ id: 1, roomId: 3, tenantId: 1, startDate: '2023-03-01', endDate: '2024-03-01', rent: 2800, deposit: 5600, status: 'active', createTime: '2023-02-28' },
|
||||||
|
{ id: 2, roomId: 9, tenantId: 2, startDate: '2023-04-01', endDate: '2024-04-01', rent: 2200, deposit: 4400, status: 'active', createTime: '2023-03-31' },
|
||||||
|
{ id: 3, roomId: 12, tenantId: 3, startDate: '2023-05-01', endDate: '2024-05-01', rent: 2600, deposit: 5200, status: 'active', createTime: '2023-04-30' },
|
||||||
|
{ id: 4, roomId: 4, tenantId: 4, startDate: '2022-03-01', endDate: '2023-03-01', rent: 2800, deposit: 5600, status: 'expired', createTime: '2022-02-28' },
|
||||||
|
{ id: 5, roomId: 6, tenantId: 5, startDate: '2022-04-01', endDate: '2023-04-01', rent: 3000, deposit: 6000, status: 'expired', createTime: '2022-03-31' }
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 插入租房数据
|
||||||
|
const rentals = await Rental.bulkCreate([
|
||||||
|
{ id: 1, roomId: 3, tenantId: 1, contractId: 1, startDate: '2023-03-01', endDate: '2024-03-01', rent: 2800, deposit: 5600, status: 'active', createTime: '2023-02-28' },
|
||||||
|
{ id: 2, roomId: 9, tenantId: 2, contractId: 2, startDate: '2023-04-01', endDate: '2024-04-01', rent: 2200, deposit: 4400, status: 'active', createTime: '2023-03-31' },
|
||||||
|
{ id: 3, roomId: 12, tenantId: 3, contractId: 3, startDate: '2023-05-01', endDate: '2024-05-01', rent: 2600, deposit: 5200, status: 'active', createTime: '2023-04-30' },
|
||||||
|
{ id: 4, roomId: 4, tenantId: 4, contractId: 4, startDate: '2022-03-01', endDate: '2023-03-01', rent: 2800, deposit: 5600, status: 'expired', createTime: '2022-02-28' },
|
||||||
|
{ id: 5, roomId: 6, tenantId: 5, contractId: 5, startDate: '2022-04-01', endDate: '2023-04-01', rent: 3000, deposit: 6000, status: 'expired', createTime: '2022-03-31' }
|
||||||
|
]);
|
||||||
|
|
||||||
|
console.log('初始数据插入成功');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('初始数据插入失败:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
syncDatabase();
|
||||||
|
|
@ -0,0 +1,137 @@
|
||||||
|
const { Apartment, Region } = require('../models');
|
||||||
|
const { Op } = require('sequelize');
|
||||||
|
|
||||||
|
// 格式化时间(考虑时区,转换为北京时间)
|
||||||
|
const formatDate = (date) => {
|
||||||
|
if (!date) return null;
|
||||||
|
// 创建一个新的Date对象,加上8小时的时区偏移
|
||||||
|
const beijingDate = new Date(date.getTime() + 8 * 60 * 60 * 1000);
|
||||||
|
return beijingDate.toISOString().split('T')[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化公寓数据
|
||||||
|
const formatApartmentData = (apartment) => {
|
||||||
|
const formattedApartment = {
|
||||||
|
...apartment.toJSON(),
|
||||||
|
createTime: formatDate(apartment.createTime)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化关联数据
|
||||||
|
if (formattedApartment.Region) {
|
||||||
|
formattedApartment.Region = {
|
||||||
|
...formattedApartment.Region,
|
||||||
|
createTime: formatDate(formattedApartment.Region.createTime)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedApartment;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取所有公寓(支持搜索和分页)
|
||||||
|
const getAllApartments = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { regionId, name, page = 1, pageSize = 10 } = req.query;
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
const where = {};
|
||||||
|
if (regionId) {
|
||||||
|
where.regionId = regionId;
|
||||||
|
}
|
||||||
|
if (name) {
|
||||||
|
where.name = {
|
||||||
|
[Op.like]: `%${name}%`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算偏移量
|
||||||
|
const offset = (page - 1) * pageSize;
|
||||||
|
|
||||||
|
// 查询公寓数据
|
||||||
|
const { count, rows } = await Apartment.findAndCountAll({
|
||||||
|
where,
|
||||||
|
include: [Region],
|
||||||
|
limit: parseInt(pageSize),
|
||||||
|
offset: parseInt(offset)
|
||||||
|
});
|
||||||
|
|
||||||
|
// 格式化数据
|
||||||
|
const formattedApartments = rows.map(formatApartmentData);
|
||||||
|
|
||||||
|
// 返回结果
|
||||||
|
res.status(200).json({
|
||||||
|
data: formattedApartments,
|
||||||
|
total: count,
|
||||||
|
page: parseInt(page),
|
||||||
|
pageSize: parseInt(pageSize)
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取单个公寓
|
||||||
|
const getApartmentById = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const apartment = await Apartment.findByPk(id, {
|
||||||
|
include: [Region]
|
||||||
|
});
|
||||||
|
if (!apartment) {
|
||||||
|
return res.status(404).json({ error: '公寓不存在' });
|
||||||
|
}
|
||||||
|
const formattedApartment = formatApartmentData(apartment);
|
||||||
|
res.status(200).json(formattedApartment);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 创建公寓
|
||||||
|
const createApartment = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { regionId, name, address } = req.body;
|
||||||
|
const apartment = await Apartment.create({ regionId, name, address });
|
||||||
|
res.status(201).json(apartment);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 更新公寓
|
||||||
|
const updateApartment = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const { regionId, name, address } = req.body;
|
||||||
|
const apartment = await Apartment.findByPk(id);
|
||||||
|
if (!apartment) {
|
||||||
|
return res.status(404).json({ error: '公寓不存在' });
|
||||||
|
}
|
||||||
|
await apartment.update({ regionId, name, address });
|
||||||
|
res.status(200).json(apartment);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除公寓
|
||||||
|
const deleteApartment = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const apartment = await Apartment.findByPk(id);
|
||||||
|
if (!apartment) {
|
||||||
|
return res.status(404).json({ error: '公寓不存在' });
|
||||||
|
}
|
||||||
|
await apartment.destroy();
|
||||||
|
res.status(200).json({ message: '公寓删除成功' });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getAllApartments,
|
||||||
|
getApartmentById,
|
||||||
|
createApartment,
|
||||||
|
updateApartment,
|
||||||
|
deleteApartment
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,152 @@
|
||||||
|
const { Contract, Room, Tenant, Apartment, Region } = require('../models');
|
||||||
|
|
||||||
|
// 格式化时间(考虑时区,转换为北京时间)
|
||||||
|
const formatDate = (date) => {
|
||||||
|
if (!date) return null;
|
||||||
|
// 创建一个新的Date对象,加上8小时的时区偏移
|
||||||
|
const beijingDate = new Date(date.getTime() + 8 * 60 * 60 * 1000);
|
||||||
|
return beijingDate.toISOString().split('T')[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化合同数据
|
||||||
|
const formatContractData = (contract) => {
|
||||||
|
const formattedContract = {
|
||||||
|
...contract.toJSON(),
|
||||||
|
startDate: formatDate(contract.startDate),
|
||||||
|
endDate: formatDate(contract.endDate),
|
||||||
|
createTime: formatDate(contract.createTime)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化关联数据
|
||||||
|
if (formattedContract.Room) {
|
||||||
|
formattedContract.Room = {
|
||||||
|
...formattedContract.Room,
|
||||||
|
createTime: formatDate(formattedContract.Room.createTime)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (formattedContract.Room.Apartment) {
|
||||||
|
formattedContract.Room.Apartment = {
|
||||||
|
...formattedContract.Room.Apartment,
|
||||||
|
createTime: formatDate(formattedContract.Room.Apartment.createTime)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (formattedContract.Room.Apartment.Region) {
|
||||||
|
formattedContract.Room.Apartment.Region = {
|
||||||
|
...formattedContract.Room.Apartment.Region,
|
||||||
|
createTime: formatDate(formattedContract.Room.Apartment.Region.createTime)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (formattedContract.Tenant) {
|
||||||
|
formattedContract.Tenant = {
|
||||||
|
...formattedContract.Tenant,
|
||||||
|
createTime: formatDate(formattedContract.Tenant.createTime)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedContract;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取所有合同
|
||||||
|
const getAllContracts = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const contracts = await Contract.findAll({
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Room,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Apartment,
|
||||||
|
include: [Region]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
Tenant
|
||||||
|
]
|
||||||
|
});
|
||||||
|
const formattedContracts = contracts.map(formatContractData);
|
||||||
|
res.status(200).json(formattedContracts);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取单个合同
|
||||||
|
const getContractById = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const contract = await Contract.findByPk(id, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Room,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Apartment,
|
||||||
|
include: [Region]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
Tenant
|
||||||
|
]
|
||||||
|
});
|
||||||
|
if (!contract) {
|
||||||
|
return res.status(404).json({ error: '合同不存在' });
|
||||||
|
}
|
||||||
|
const formattedContract = formatContractData(contract);
|
||||||
|
res.status(200).json(formattedContract);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 创建合同
|
||||||
|
const createContract = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { roomId, tenantId, startDate, endDate, rent, deposit, status } = req.body;
|
||||||
|
const contract = await Contract.create({ roomId, tenantId, startDate, endDate, rent, deposit, status });
|
||||||
|
res.status(201).json(contract);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 更新合同
|
||||||
|
const updateContract = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const { roomId, tenantId, startDate, endDate, rent, deposit, status } = req.body;
|
||||||
|
const contract = await Contract.findByPk(id);
|
||||||
|
if (!contract) {
|
||||||
|
return res.status(404).json({ error: '合同不存在' });
|
||||||
|
}
|
||||||
|
await contract.update({ roomId, tenantId, startDate, endDate, rent, deposit, status });
|
||||||
|
res.status(200).json(contract);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除合同
|
||||||
|
const deleteContract = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const contract = await Contract.findByPk(id);
|
||||||
|
if (!contract) {
|
||||||
|
return res.status(404).json({ error: '合同不存在' });
|
||||||
|
}
|
||||||
|
await contract.destroy();
|
||||||
|
res.status(200).json({ message: '合同删除成功' });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getAllContracts,
|
||||||
|
getContractById,
|
||||||
|
createContract,
|
||||||
|
updateContract,
|
||||||
|
deleteContract
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,180 @@
|
||||||
|
const { ElectricityBill, Room } = require('../models');
|
||||||
|
const { Op } = require('sequelize');
|
||||||
|
|
||||||
|
// 格式化时间(考虑时区,转换为北京时间)
|
||||||
|
const formatDate = (date) => {
|
||||||
|
if (!date) return null;
|
||||||
|
// 创建一个新的Date对象,加上8小时的时区偏移
|
||||||
|
const beijingDate = new Date(date.getTime() + 8 * 60 * 60 * 1000);
|
||||||
|
return beijingDate.toISOString().split('T')[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化电费数据
|
||||||
|
const formatElectricityBillData = (bill) => {
|
||||||
|
const formattedBill = {
|
||||||
|
...bill.toJSON(),
|
||||||
|
startDate: formatDate(bill.startDate),
|
||||||
|
endDate: formatDate(bill.endDate),
|
||||||
|
createTime: formatDate(bill.createTime)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化关联数据
|
||||||
|
if (formattedBill.Room) {
|
||||||
|
formattedBill.Room = {
|
||||||
|
...formattedBill.Room,
|
||||||
|
createTime: formatDate(formattedBill.Room.createTime)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedBill;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取所有电费记录(支持搜索和分页)
|
||||||
|
const getAllElectricityBills = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { roomId, status, startDate, endDate, page = 1, pageSize = 10 } = req.query;
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
const where = {};
|
||||||
|
if (roomId) {
|
||||||
|
where.roomId = roomId;
|
||||||
|
}
|
||||||
|
if (status) {
|
||||||
|
where.status = status;
|
||||||
|
}
|
||||||
|
if (startDate) {
|
||||||
|
where.startDate = { [Op.gte]: new Date(startDate) };
|
||||||
|
}
|
||||||
|
if (endDate) {
|
||||||
|
where.endDate = { [Op.lte]: new Date(endDate) };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算偏移量
|
||||||
|
const offset = (page - 1) * pageSize;
|
||||||
|
|
||||||
|
// 查询电费数据
|
||||||
|
const { count, rows } = await ElectricityBill.findAndCountAll({
|
||||||
|
where,
|
||||||
|
include: [Room],
|
||||||
|
limit: parseInt(pageSize),
|
||||||
|
offset: parseInt(offset)
|
||||||
|
});
|
||||||
|
|
||||||
|
// 格式化数据
|
||||||
|
const formattedBills = rows.map(formatElectricityBillData);
|
||||||
|
|
||||||
|
// 返回结果
|
||||||
|
res.status(200).json({
|
||||||
|
data: formattedBills,
|
||||||
|
total: count,
|
||||||
|
page: parseInt(page),
|
||||||
|
pageSize: parseInt(pageSize)
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取单个电费记录
|
||||||
|
const getElectricityBillById = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const bill = await ElectricityBill.findByPk(id, {
|
||||||
|
include: [Room]
|
||||||
|
});
|
||||||
|
if (!bill) {
|
||||||
|
return res.status(404).json({ error: '电费记录不存在' });
|
||||||
|
}
|
||||||
|
const formattedBill = formatElectricityBillData(bill);
|
||||||
|
res.status(200).json(formattedBill);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 创建电费记录
|
||||||
|
const createElectricityBill = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { roomId, startDate, endDate, startReading, endReading, unitPrice } = req.body;
|
||||||
|
|
||||||
|
// 计算用电量和费用
|
||||||
|
const usage = parseFloat(endReading) - parseFloat(startReading);
|
||||||
|
const amount = usage * parseFloat(unitPrice);
|
||||||
|
|
||||||
|
const bill = await ElectricityBill.create({
|
||||||
|
roomId,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
startReading,
|
||||||
|
endReading,
|
||||||
|
usage,
|
||||||
|
unitPrice,
|
||||||
|
amount
|
||||||
|
});
|
||||||
|
|
||||||
|
const formattedBill = formatElectricityBillData(bill);
|
||||||
|
res.status(201).json(formattedBill);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 更新电费记录
|
||||||
|
const updateElectricityBill = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const { startDate, endDate, startReading, endReading, unitPrice, status } = req.body;
|
||||||
|
|
||||||
|
const bill = await ElectricityBill.findByPk(id);
|
||||||
|
if (!bill) {
|
||||||
|
return res.status(404).json({ error: '电费记录不存在' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算用电量和费用
|
||||||
|
let usage = bill.usage;
|
||||||
|
let amount = bill.amount;
|
||||||
|
if (startReading && endReading && unitPrice) {
|
||||||
|
usage = parseFloat(endReading) - parseFloat(startReading);
|
||||||
|
amount = usage * parseFloat(unitPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
await bill.update({
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
startReading,
|
||||||
|
endReading,
|
||||||
|
usage,
|
||||||
|
unitPrice,
|
||||||
|
amount,
|
||||||
|
status
|
||||||
|
});
|
||||||
|
|
||||||
|
const formattedBill = formatElectricityBillData(bill);
|
||||||
|
res.status(200).json(formattedBill);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除电费记录
|
||||||
|
const deleteElectricityBill = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const bill = await ElectricityBill.findByPk(id);
|
||||||
|
if (!bill) {
|
||||||
|
return res.status(404).json({ error: '电费记录不存在' });
|
||||||
|
}
|
||||||
|
await bill.destroy();
|
||||||
|
res.status(200).json({ message: '电费记录删除成功' });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getAllElectricityBills,
|
||||||
|
getElectricityBillById,
|
||||||
|
createElectricityBill,
|
||||||
|
updateElectricityBill,
|
||||||
|
deleteElectricityBill
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
const { Region } = require('../models');
|
||||||
|
|
||||||
|
// 格式化时间(考虑时区,转换为北京时间)
|
||||||
|
const formatDate = (date) => {
|
||||||
|
if (!date) return null;
|
||||||
|
// 创建一个新的Date对象,加上8小时的时区偏移
|
||||||
|
const beijingDate = new Date(date.getTime() + 8 * 60 * 60 * 1000);
|
||||||
|
return beijingDate.toISOString().split('T')[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化区域数据
|
||||||
|
const formatRegionData = (region) => {
|
||||||
|
return {
|
||||||
|
...region.toJSON(),
|
||||||
|
createTime: formatDate(region.createTime)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取所有区域
|
||||||
|
const getAllRegions = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const regions = await Region.findAll();
|
||||||
|
const formattedRegions = regions.map(formatRegionData);
|
||||||
|
res.status(200).json(formattedRegions);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取单个区域
|
||||||
|
const getRegionById = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const region = await Region.findByPk(id);
|
||||||
|
if (!region) {
|
||||||
|
return res.status(404).json({ error: '区域不存在' });
|
||||||
|
}
|
||||||
|
const formattedRegion = formatRegionData(region);
|
||||||
|
res.status(200).json(formattedRegion);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 创建区域
|
||||||
|
const createRegion = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { name, description } = req.body;
|
||||||
|
const region = await Region.create({ name, description });
|
||||||
|
res.status(201).json(region);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 更新区域
|
||||||
|
const updateRegion = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const { name, description } = req.body;
|
||||||
|
const region = await Region.findByPk(id);
|
||||||
|
if (!region) {
|
||||||
|
return res.status(404).json({ error: '区域不存在' });
|
||||||
|
}
|
||||||
|
await region.update({ name, description });
|
||||||
|
res.status(200).json(region);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除区域
|
||||||
|
const deleteRegion = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const region = await Region.findByPk(id);
|
||||||
|
if (!region) {
|
||||||
|
return res.status(404).json({ error: '区域不存在' });
|
||||||
|
}
|
||||||
|
await region.destroy();
|
||||||
|
res.status(200).json({ message: '区域删除成功' });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getAllRegions,
|
||||||
|
getRegionById,
|
||||||
|
createRegion,
|
||||||
|
updateRegion,
|
||||||
|
deleteRegion
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,324 @@
|
||||||
|
const { Rental, Room, Tenant, Contract, Apartment, Region } = require('../models');
|
||||||
|
const { Op } = require('sequelize');
|
||||||
|
|
||||||
|
// 格式化时间(考虑时区,转换为北京时间)
|
||||||
|
const formatDate = (date) => {
|
||||||
|
if (!date) return null;
|
||||||
|
// 创建一个新的Date对象,加上8小时的时区偏移
|
||||||
|
const beijingDate = new Date(date.getTime() + 8 * 60 * 60 * 1000);
|
||||||
|
return beijingDate.toISOString().split('T')[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化租房数据
|
||||||
|
const formatRentalData = (rental) => {
|
||||||
|
const formattedRental = {
|
||||||
|
...rental.toJSON(),
|
||||||
|
startDate: formatDate(rental.startDate),
|
||||||
|
endDate: formatDate(rental.endDate),
|
||||||
|
createTime: formatDate(rental.createTime)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化关联数据
|
||||||
|
if (formattedRental.Contract) {
|
||||||
|
formattedRental.Contract = {
|
||||||
|
...formattedRental.Contract,
|
||||||
|
startDate: formatDate(formattedRental.Contract.startDate),
|
||||||
|
endDate: formatDate(formattedRental.Contract.endDate),
|
||||||
|
createTime: formatDate(formattedRental.Contract.createTime)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedRental;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 检查并更新租房状态
|
||||||
|
const checkAndUpdateRentalStatus = async () => {
|
||||||
|
try {
|
||||||
|
// 获取当前日期
|
||||||
|
const currentDate = new Date();
|
||||||
|
// 计算10天后的日期
|
||||||
|
const tenDaysLater = new Date();
|
||||||
|
tenDaysLater.setDate(currentDate.getDate() + 10);
|
||||||
|
|
||||||
|
// 查找所有活跃的租房记录
|
||||||
|
const rentals = await Rental.findAll({
|
||||||
|
where: { status: 'active' },
|
||||||
|
include: [Room]
|
||||||
|
});
|
||||||
|
|
||||||
|
// 检查每个租房记录的状态
|
||||||
|
for (const rental of rentals) {
|
||||||
|
const endDate = new Date(rental.endDate);
|
||||||
|
|
||||||
|
// 检查是否已到期
|
||||||
|
if (endDate < currentDate) {
|
||||||
|
// 更新租房状态为已到期
|
||||||
|
await rental.update({ status: 'expired' });
|
||||||
|
// 更新房间状态为空房
|
||||||
|
if (rental.Room) {
|
||||||
|
await rental.Room.update({ status: 'empty' });
|
||||||
|
}
|
||||||
|
} else if (endDate <= tenDaysLater) {
|
||||||
|
// 更新房间状态为即将到期
|
||||||
|
if (rental.Room && rental.Room.status === 'rented') {
|
||||||
|
await rental.Room.update({ status: 'soon_expire' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('租房状态检查和更新完成');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('检查和更新租房状态时出错:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取所有租房(支持搜索和分页)
|
||||||
|
const getAllRentals = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// 先检查并更新租房状态
|
||||||
|
await checkAndUpdateRentalStatus();
|
||||||
|
|
||||||
|
const { roomNumber, tenantName, status, page = 1, pageSize = 10 } = req.query;
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
const where = {};
|
||||||
|
if (status) {
|
||||||
|
where.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建包含关系
|
||||||
|
const include = [
|
||||||
|
{
|
||||||
|
model: Room,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Apartment,
|
||||||
|
include: [Region]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
where: roomNumber ? { roomNumber: { [Op.like]: `%${roomNumber}%` } } : {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: Tenant,
|
||||||
|
where: tenantName ? { name: { [Op.like]: `%${tenantName}%` } } : {}
|
||||||
|
},
|
||||||
|
Contract
|
||||||
|
];
|
||||||
|
|
||||||
|
// 计算偏移量
|
||||||
|
const offset = (page - 1) * pageSize;
|
||||||
|
|
||||||
|
// 查询租房数据
|
||||||
|
const { count, rows } = await Rental.findAndCountAll({
|
||||||
|
where,
|
||||||
|
include,
|
||||||
|
limit: parseInt(pageSize),
|
||||||
|
offset: parseInt(offset)
|
||||||
|
});
|
||||||
|
|
||||||
|
// 格式化数据
|
||||||
|
const formattedRentals = rows.map(formatRentalData);
|
||||||
|
|
||||||
|
// 返回结果
|
||||||
|
res.status(200).json({
|
||||||
|
data: formattedRentals,
|
||||||
|
total: count,
|
||||||
|
page: parseInt(page),
|
||||||
|
pageSize: parseInt(pageSize)
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取单个租房
|
||||||
|
const getRentalById = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const rental = await Rental.findByPk(id, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Room,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Apartment,
|
||||||
|
include: [Region]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
Tenant,
|
||||||
|
Contract
|
||||||
|
]
|
||||||
|
});
|
||||||
|
if (!rental) {
|
||||||
|
return res.status(404).json({ error: '租房记录不存在' });
|
||||||
|
}
|
||||||
|
const formattedRental = formatRentalData(rental);
|
||||||
|
res.status(200).json(formattedRental);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 创建租房
|
||||||
|
const createRental = async (req, res) => {
|
||||||
|
try {
|
||||||
|
console.log('接收到的请求数据:', req.body);
|
||||||
|
|
||||||
|
// 直接使用req.body中的数据
|
||||||
|
const body = req.body;
|
||||||
|
|
||||||
|
// 检查请求体是否存在
|
||||||
|
if (!body) {
|
||||||
|
return res.status(400).json({ error: '请求体不能为空' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查所有必要参数
|
||||||
|
if (!body.roomId) {
|
||||||
|
return res.status(400).json({ error: '缺少房间ID' });
|
||||||
|
}
|
||||||
|
if (!body.tenantName) {
|
||||||
|
return res.status(400).json({ error: '缺少租客姓名' });
|
||||||
|
}
|
||||||
|
if (!body.tenantPhone) {
|
||||||
|
return res.status(400).json({ error: '缺少租客电话' });
|
||||||
|
}
|
||||||
|
if (!body.tenantIdCard) {
|
||||||
|
return res.status(400).json({ error: '缺少身份证号' });
|
||||||
|
}
|
||||||
|
if (!body.startDate) {
|
||||||
|
return res.status(400).json({ error: '缺少开始日期' });
|
||||||
|
}
|
||||||
|
if (!body.endDate) {
|
||||||
|
return res.status(400).json({ error: '缺少结束日期' });
|
||||||
|
}
|
||||||
|
if (!body.rent) {
|
||||||
|
return res.status(400).json({ error: '缺少租金' });
|
||||||
|
}
|
||||||
|
if (!body.deposit) {
|
||||||
|
return res.status(400).json({ error: '缺少押金' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换roomId为整数类型
|
||||||
|
const parsedRoomId = parseInt(body.roomId);
|
||||||
|
if (isNaN(parsedRoomId)) {
|
||||||
|
return res.status(400).json({ error: '无效的房间ID' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 先查找或创建租客
|
||||||
|
let tenant = await Tenant.findOne({ where: { idCard: body.tenantIdCard } });
|
||||||
|
if (!tenant) {
|
||||||
|
console.log('创建新租客:', { name: body.tenantName, phone: body.tenantPhone, idCard: body.tenantIdCard });
|
||||||
|
tenant = await Tenant.create({
|
||||||
|
name: body.tenantName,
|
||||||
|
phone: body.tenantPhone,
|
||||||
|
idCard: body.tenantIdCard
|
||||||
|
});
|
||||||
|
}
|
||||||
|
console.log('租客信息:', tenant);
|
||||||
|
|
||||||
|
// 确保租客创建成功
|
||||||
|
if (!tenant || !tenant.id) {
|
||||||
|
return res.status(500).json({ error: '创建租客失败' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建合同
|
||||||
|
console.log('创建合同:', {
|
||||||
|
roomId: parsedRoomId,
|
||||||
|
tenantId: tenant.id,
|
||||||
|
startDate: body.startDate,
|
||||||
|
endDate: body.endDate,
|
||||||
|
rent: body.rent,
|
||||||
|
deposit: body.deposit,
|
||||||
|
status: body.status || 'active'
|
||||||
|
});
|
||||||
|
const contract = await Contract.create({
|
||||||
|
roomId: parsedRoomId,
|
||||||
|
tenantId: tenant.id,
|
||||||
|
startDate: body.startDate,
|
||||||
|
endDate: body.endDate,
|
||||||
|
rent: body.rent,
|
||||||
|
deposit: body.deposit,
|
||||||
|
status: body.status || 'active'
|
||||||
|
});
|
||||||
|
console.log('合同信息:', contract);
|
||||||
|
|
||||||
|
// 确保合同创建成功
|
||||||
|
if (!contract || !contract.id) {
|
||||||
|
return res.status(500).json({ error: '创建合同失败' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建租房记录
|
||||||
|
console.log('创建租房记录:', {
|
||||||
|
roomId: parsedRoomId,
|
||||||
|
tenantId: tenant.id,
|
||||||
|
contractId: contract.id,
|
||||||
|
startDate: body.startDate,
|
||||||
|
endDate: body.endDate,
|
||||||
|
rent: body.rent,
|
||||||
|
deposit: body.deposit,
|
||||||
|
status: body.status || 'active'
|
||||||
|
});
|
||||||
|
|
||||||
|
// 直接使用具体的数值创建租房记录
|
||||||
|
const rental = await Rental.create({
|
||||||
|
roomId: parsedRoomId,
|
||||||
|
tenantId: tenant.id,
|
||||||
|
contractId: contract.id,
|
||||||
|
startDate: body.startDate,
|
||||||
|
endDate: body.endDate,
|
||||||
|
rent: body.rent,
|
||||||
|
deposit: body.deposit,
|
||||||
|
status: body.status || 'active'
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('租房记录:', rental);
|
||||||
|
|
||||||
|
// 更新房间状态为已租
|
||||||
|
await Room.update({ status: 'rented' }, { where: { id: parsedRoomId } });
|
||||||
|
|
||||||
|
res.status(201).json(rental);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('创建租房记录时出错:', error);
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 更新租房
|
||||||
|
const updateRental = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const { roomId, tenantId, contractId, startDate, endDate, rent, deposit, status } = req.body;
|
||||||
|
const rental = await Rental.findByPk(id);
|
||||||
|
if (!rental) {
|
||||||
|
return res.status(404).json({ error: '租房记录不存在' });
|
||||||
|
}
|
||||||
|
await rental.update({ roomId, tenantId, contractId, startDate, endDate, rent, deposit, status });
|
||||||
|
res.status(200).json(rental);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除租房
|
||||||
|
const deleteRental = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const rental = await Rental.findByPk(id);
|
||||||
|
if (!rental) {
|
||||||
|
return res.status(404).json({ error: '租房记录不存在' });
|
||||||
|
}
|
||||||
|
await rental.destroy();
|
||||||
|
res.status(200).json({ message: '租房记录删除成功' });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getAllRentals,
|
||||||
|
getRentalById,
|
||||||
|
createRental,
|
||||||
|
updateRental,
|
||||||
|
deleteRental
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,286 @@
|
||||||
|
const { Room, Apartment, Rental } = require('../models');
|
||||||
|
const { Op } = require('sequelize');
|
||||||
|
|
||||||
|
// 格式化时间(考虑时区,转换为北京时间)
|
||||||
|
const formatDate = (date) => {
|
||||||
|
if (!date) return null;
|
||||||
|
// 创建一个新的Date对象,加上8小时的时区偏移
|
||||||
|
const beijingDate = new Date(date.getTime() + 8 * 60 * 60 * 1000);
|
||||||
|
return beijingDate.toISOString().split('T')[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化房间数据
|
||||||
|
const formatRoomData = (room) => {
|
||||||
|
const formattedRoom = {
|
||||||
|
...room.toJSON(),
|
||||||
|
createTime: formatDate(room.createTime)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化关联数据
|
||||||
|
if (formattedRoom.Apartment) {
|
||||||
|
formattedRoom.Apartment = {
|
||||||
|
...formattedRoom.Apartment,
|
||||||
|
createTime: formatDate(formattedRoom.Apartment.createTime)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化租房信息
|
||||||
|
if (formattedRoom.Rentals && formattedRoom.Rentals.length > 0) {
|
||||||
|
formattedRoom.Rentals = formattedRoom.Rentals.map(rental => {
|
||||||
|
const formattedRental = {
|
||||||
|
...rental,
|
||||||
|
startDate: formatDate(rental.startDate),
|
||||||
|
endDate: formatDate(rental.endDate),
|
||||||
|
createTime: formatDate(rental.createTime)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化租客信息
|
||||||
|
if (formattedRental.Tenant) {
|
||||||
|
formattedRental.Tenant = {
|
||||||
|
...formattedRental.Tenant,
|
||||||
|
createTime: formatDate(formattedRental.Tenant.createTime)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedRental;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedRoom;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 检查并更新租房状态
|
||||||
|
const checkAndUpdateRentalStatus = async () => {
|
||||||
|
try {
|
||||||
|
// 获取当前日期
|
||||||
|
const currentDate = new Date();
|
||||||
|
// 计算10天后的日期
|
||||||
|
const tenDaysLater = new Date();
|
||||||
|
tenDaysLater.setDate(currentDate.getDate() + 10);
|
||||||
|
|
||||||
|
// 查找所有活跃的租房记录
|
||||||
|
const rentals = await Rental.findAll({
|
||||||
|
where: { status: 'active' }
|
||||||
|
});
|
||||||
|
|
||||||
|
// 检查每个租房记录的状态
|
||||||
|
for (const rental of rentals) {
|
||||||
|
const endDate = new Date(rental.endDate);
|
||||||
|
|
||||||
|
// 检查是否已到期
|
||||||
|
if (endDate < currentDate) {
|
||||||
|
// 更新租房状态为已到期
|
||||||
|
await rental.update({ status: 'expired' });
|
||||||
|
// 更新房间状态为空房
|
||||||
|
const room = await Room.findByPk(rental.roomId);
|
||||||
|
if (room) {
|
||||||
|
await room.update({ status: 'empty' });
|
||||||
|
}
|
||||||
|
} else if (endDate <= tenDaysLater) {
|
||||||
|
// 更新房间状态为即将到期
|
||||||
|
const room = await Room.findByPk(rental.roomId);
|
||||||
|
if (room && room.status === 'rented') {
|
||||||
|
await room.update({ status: 'soon_expire' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('租房状态检查和更新完成');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('检查和更新租房状态时出错:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取所有房间(支持搜索和分页)
|
||||||
|
const getAllRooms = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// 先检查并更新租房状态
|
||||||
|
await checkAndUpdateRentalStatus();
|
||||||
|
|
||||||
|
const { apartmentId, roomNumber, status, page = 1, pageSize = 10 } = req.query;
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
const where = {};
|
||||||
|
if (apartmentId) {
|
||||||
|
where.apartmentId = apartmentId;
|
||||||
|
}
|
||||||
|
if (roomNumber) {
|
||||||
|
where.roomNumber = {
|
||||||
|
[Op.like]: `%${roomNumber}%`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (status) {
|
||||||
|
where.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算偏移量
|
||||||
|
const offset = (page - 1) * pageSize;
|
||||||
|
|
||||||
|
// 查询房间数据
|
||||||
|
const { count, rows } = await Room.findAndCountAll({
|
||||||
|
where,
|
||||||
|
include: [
|
||||||
|
Apartment
|
||||||
|
],
|
||||||
|
limit: parseInt(pageSize),
|
||||||
|
offset: parseInt(offset)
|
||||||
|
});
|
||||||
|
|
||||||
|
// 为每个房间获取非过期的租房信息
|
||||||
|
const formattedRooms = await Promise.all(rows.map(async (room) => {
|
||||||
|
const formattedRoom = formatRoomData(room);
|
||||||
|
|
||||||
|
// 查询非过期的租房信息
|
||||||
|
const rentals = await Rental.findAll({
|
||||||
|
where: {
|
||||||
|
roomId: room.id,
|
||||||
|
status: { [Op.ne]: 'expired' }
|
||||||
|
},
|
||||||
|
include: ['Tenant']
|
||||||
|
});
|
||||||
|
|
||||||
|
// 格式化租房信息
|
||||||
|
if (rentals.length > 0) {
|
||||||
|
formattedRoom.Rentals = rentals.map(rental => {
|
||||||
|
const formattedRental = {
|
||||||
|
...rental.toJSON(),
|
||||||
|
startDate: formatDate(rental.startDate),
|
||||||
|
endDate: formatDate(rental.endDate),
|
||||||
|
createTime: formatDate(rental.createTime)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化租客信息
|
||||||
|
if (formattedRental.Tenant) {
|
||||||
|
formattedRental.Tenant = {
|
||||||
|
...formattedRental.Tenant,
|
||||||
|
createTime: formatDate(formattedRental.Tenant.createTime)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedRental;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
formattedRoom.Rentals = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedRoom;
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 返回结果
|
||||||
|
res.status(200).json({
|
||||||
|
data: formattedRooms,
|
||||||
|
total: count,
|
||||||
|
page: parseInt(page),
|
||||||
|
pageSize: parseInt(pageSize)
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取单个房间
|
||||||
|
const getRoomById = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// 先检查并更新租房状态
|
||||||
|
await checkAndUpdateRentalStatus();
|
||||||
|
|
||||||
|
const { id } = req.params;
|
||||||
|
const room = await Room.findByPk(id, {
|
||||||
|
include: [Apartment]
|
||||||
|
});
|
||||||
|
if (!room) {
|
||||||
|
return res.status(404).json({ error: '房间不存在' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化房间数据
|
||||||
|
const formattedRoom = formatRoomData(room);
|
||||||
|
|
||||||
|
// 查询非过期的租房信息
|
||||||
|
const rentals = await Rental.findAll({
|
||||||
|
where: {
|
||||||
|
roomId: room.id,
|
||||||
|
status: { [Op.ne]: 'expired' }
|
||||||
|
},
|
||||||
|
include: ['Tenant']
|
||||||
|
});
|
||||||
|
|
||||||
|
// 格式化租房信息
|
||||||
|
if (rentals.length > 0) {
|
||||||
|
formattedRoom.Rentals = rentals.map(rental => {
|
||||||
|
const formattedRental = {
|
||||||
|
...rental.toJSON(),
|
||||||
|
startDate: formatDate(rental.startDate),
|
||||||
|
endDate: formatDate(rental.endDate),
|
||||||
|
createTime: formatDate(rental.createTime)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化租客信息
|
||||||
|
if (formattedRental.Tenant) {
|
||||||
|
formattedRental.Tenant = {
|
||||||
|
...formattedRental.Tenant,
|
||||||
|
createTime: formatDate(formattedRental.Tenant.createTime)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedRental;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
formattedRoom.Rentals = [];
|
||||||
|
}
|
||||||
|
res.status(200).json(formattedRoom);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 创建房间
|
||||||
|
const createRoom = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { apartmentId, roomNumber, area, price, status } = req.body;
|
||||||
|
const room = await Room.create({ apartmentId, roomNumber, area, price, status });
|
||||||
|
res.status(201).json(room);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 更新房间
|
||||||
|
const updateRoom = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const { apartmentId, roomNumber, area, price, status } = req.body;
|
||||||
|
const room = await Room.findByPk(id);
|
||||||
|
if (!room) {
|
||||||
|
return res.status(404).json({ error: '房间不存在' });
|
||||||
|
}
|
||||||
|
await room.update({ apartmentId, roomNumber, area, price, status });
|
||||||
|
res.status(200).json(room);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除房间
|
||||||
|
const deleteRoom = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const room = await Room.findByPk(id);
|
||||||
|
if (!room) {
|
||||||
|
return res.status(404).json({ error: '房间不存在' });
|
||||||
|
}
|
||||||
|
await room.destroy();
|
||||||
|
res.status(200).json({ message: '房间删除成功' });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getAllRooms,
|
||||||
|
getRoomById,
|
||||||
|
createRoom,
|
||||||
|
updateRoom,
|
||||||
|
deleteRoom
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,225 @@
|
||||||
|
const { Room, Rental, Apartment, Region } = require('../models');
|
||||||
|
const { Op } = require('sequelize');
|
||||||
|
|
||||||
|
// 租金统计
|
||||||
|
const getRentStatistics = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// 获取当前年份
|
||||||
|
const currentYear = new Date().getFullYear();
|
||||||
|
|
||||||
|
// 从数据库查询所有租房记录(包括活跃和已到期的)
|
||||||
|
const rentals = await Rental.findAll({
|
||||||
|
include: [Room]
|
||||||
|
});
|
||||||
|
|
||||||
|
// 按月份统计租金
|
||||||
|
const monthlyRent = {};
|
||||||
|
|
||||||
|
// 初始化12个月的数据
|
||||||
|
for (let i = 1; i <= 12; i++) {
|
||||||
|
const monthKey = `${currentYear}-${i.toString().padStart(2, '0')}`;
|
||||||
|
monthlyRent[monthKey] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算每个月的租金收入
|
||||||
|
rentals.forEach(rental => {
|
||||||
|
if (rental.Room) {
|
||||||
|
// 检查租金是否有效
|
||||||
|
const rentAmount = parseFloat(rental.rent) || 0;
|
||||||
|
if (rentAmount > 0 && rental.startDate && rental.endDate) {
|
||||||
|
// 解析开始和结束日期
|
||||||
|
const startDate = new Date(rental.startDate);
|
||||||
|
const endDate = new Date(rental.endDate);
|
||||||
|
|
||||||
|
// 计算当前年份的开始和结束日期
|
||||||
|
const yearStart = new Date(currentYear, 0, 1); // 1月1日
|
||||||
|
const yearEnd = new Date(currentYear, 11, 31); // 12月31日
|
||||||
|
|
||||||
|
// 确定实际的开始和结束日期(考虑年份范围)
|
||||||
|
const actualStart = startDate > yearStart ? startDate : yearStart;
|
||||||
|
const actualEnd = endDate < yearEnd ? endDate : yearEnd;
|
||||||
|
|
||||||
|
// 如果实际开始日期晚于实际结束日期,跳过
|
||||||
|
if (actualStart > actualEnd) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遍历当前年份的每个月
|
||||||
|
for (let i = 1; i <= 12; i++) {
|
||||||
|
const monthKey = `${currentYear}-${i.toString().padStart(2, '0')}`;
|
||||||
|
const monthStart = new Date(currentYear, i - 1, 1); // 当月1日
|
||||||
|
const monthEnd = new Date(currentYear, i, 0); // 当月最后一天
|
||||||
|
|
||||||
|
// 检查租赁期是否与当前月份重叠
|
||||||
|
if (actualStart <= monthEnd && actualEnd >= monthStart) {
|
||||||
|
// 如果重叠,添加当月租金
|
||||||
|
monthlyRent[monthKey] += rentAmount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 转换为数组格式
|
||||||
|
const rentStatistics = Object.entries(monthlyRent).map(([month, amount]) => ({
|
||||||
|
month,
|
||||||
|
amount: Math.round(amount * 100) / 100 // 保留两位小数
|
||||||
|
}));
|
||||||
|
|
||||||
|
res.status(200).json(rentStatistics);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取租金统计数据时出错:', error);
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 房间状态统计
|
||||||
|
const getRoomStatusStatistics = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const statusCounts = await Room.count({
|
||||||
|
group: ['status']
|
||||||
|
});
|
||||||
|
|
||||||
|
const statusMap = {
|
||||||
|
empty: '空房',
|
||||||
|
rented: '在租',
|
||||||
|
soon_expire: '即将到期',
|
||||||
|
expired: '到期',
|
||||||
|
cleaning: '打扫中',
|
||||||
|
maintenance: '维修中'
|
||||||
|
};
|
||||||
|
|
||||||
|
const roomStatusStatistics = Object.entries(statusMap).map(([status, label]) => {
|
||||||
|
const count = statusCounts.find(item => item.status === status)?.count || 0;
|
||||||
|
return { status: label, count };
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).json(roomStatusStatistics);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 区域房屋统计
|
||||||
|
const getRegionHouseStatistics = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const regions = await Region.findAll({
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Apartment,
|
||||||
|
include: [Room]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
const regionHouseStatistics = regions.map(region => {
|
||||||
|
let empty = 0;
|
||||||
|
let rented = 0;
|
||||||
|
let soon_expire = 0;
|
||||||
|
let expired = 0;
|
||||||
|
let cleaning = 0;
|
||||||
|
let maintenance = 0;
|
||||||
|
|
||||||
|
region.Apartments.forEach(apartment => {
|
||||||
|
apartment.Rooms.forEach(room => {
|
||||||
|
switch (room.status) {
|
||||||
|
case 'empty': empty++;
|
||||||
|
break;
|
||||||
|
case 'rented': rented++;
|
||||||
|
break;
|
||||||
|
case 'soon_expire': soon_expire++;
|
||||||
|
break;
|
||||||
|
case 'expired': expired++;
|
||||||
|
break;
|
||||||
|
case 'cleaning': cleaning++;
|
||||||
|
break;
|
||||||
|
case 'maintenance': maintenance++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
region: region.name,
|
||||||
|
empty,
|
||||||
|
rented,
|
||||||
|
soon_expire,
|
||||||
|
expired,
|
||||||
|
cleaning,
|
||||||
|
maintenance,
|
||||||
|
total: empty + rented + soon_expire + expired + cleaning + maintenance
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).json(regionHouseStatistics);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 区域公寓房间状态分布
|
||||||
|
const getRegionApartmentHouseStatistics = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const regions = await Region.findAll({
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Apartment,
|
||||||
|
include: [Room]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
const apartmentHouseStatistics = [];
|
||||||
|
|
||||||
|
regions.forEach(region => {
|
||||||
|
region.Apartments.forEach(apartment => {
|
||||||
|
let empty = 0;
|
||||||
|
let rented = 0;
|
||||||
|
let soon_expire = 0;
|
||||||
|
let expired = 0;
|
||||||
|
let cleaning = 0;
|
||||||
|
let maintenance = 0;
|
||||||
|
|
||||||
|
apartment.Rooms.forEach(room => {
|
||||||
|
switch (room.status) {
|
||||||
|
case 'empty': empty++;
|
||||||
|
break;
|
||||||
|
case 'rented': rented++;
|
||||||
|
break;
|
||||||
|
case 'soon_expire': soon_expire++;
|
||||||
|
break;
|
||||||
|
case 'expired': expired++;
|
||||||
|
break;
|
||||||
|
case 'cleaning': cleaning++;
|
||||||
|
break;
|
||||||
|
case 'maintenance': maintenance++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
apartmentHouseStatistics.push({
|
||||||
|
region: region.name,
|
||||||
|
apartment: apartment.name,
|
||||||
|
empty,
|
||||||
|
rented,
|
||||||
|
soon_expire,
|
||||||
|
expired,
|
||||||
|
cleaning,
|
||||||
|
maintenance,
|
||||||
|
total: empty + rented + soon_expire + expired + cleaning + maintenance
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).json(apartmentHouseStatistics);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getRentStatistics,
|
||||||
|
getRoomStatusStatistics,
|
||||||
|
getRegionHouseStatistics,
|
||||||
|
getRegionApartmentHouseStatistics
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
const { Tenant } = require('../models');
|
||||||
|
|
||||||
|
// 格式化时间(考虑时区,转换为北京时间)
|
||||||
|
const formatDate = (date) => {
|
||||||
|
if (!date) return null;
|
||||||
|
// 创建一个新的Date对象,加上8小时的时区偏移
|
||||||
|
const beijingDate = new Date(date.getTime() + 8 * 60 * 60 * 1000);
|
||||||
|
return beijingDate.toISOString().split('T')[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化租客数据
|
||||||
|
const formatTenantData = (tenant) => {
|
||||||
|
return {
|
||||||
|
...tenant.toJSON(),
|
||||||
|
createTime: formatDate(tenant.createTime)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取所有租客
|
||||||
|
const getAllTenants = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const tenants = await Tenant.findAll();
|
||||||
|
const formattedTenants = tenants.map(formatTenantData);
|
||||||
|
res.status(200).json(formattedTenants);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取单个租客
|
||||||
|
const getTenantById = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const tenant = await Tenant.findByPk(id);
|
||||||
|
if (!tenant) {
|
||||||
|
return res.status(404).json({ error: '租客不存在' });
|
||||||
|
}
|
||||||
|
const formattedTenant = formatTenantData(tenant);
|
||||||
|
res.status(200).json(formattedTenant);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 创建租客
|
||||||
|
const createTenant = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { name, phone, idCard } = req.body;
|
||||||
|
const tenant = await Tenant.create({ name, phone, idCard });
|
||||||
|
res.status(201).json(tenant);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 更新租客
|
||||||
|
const updateTenant = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const { name, phone, idCard } = req.body;
|
||||||
|
const tenant = await Tenant.findByPk(id);
|
||||||
|
if (!tenant) {
|
||||||
|
return res.status(404).json({ error: '租客不存在' });
|
||||||
|
}
|
||||||
|
await tenant.update({ name, phone, idCard });
|
||||||
|
res.status(200).json(tenant);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除租客
|
||||||
|
const deleteTenant = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const tenant = await Tenant.findByPk(id);
|
||||||
|
if (!tenant) {
|
||||||
|
return res.status(404).json({ error: '租客不存在' });
|
||||||
|
}
|
||||||
|
await tenant.destroy();
|
||||||
|
res.status(200).json({ message: '租客删除成功' });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getAllTenants,
|
||||||
|
getTenantById,
|
||||||
|
createTenant,
|
||||||
|
updateTenant,
|
||||||
|
deleteTenant
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,180 @@
|
||||||
|
const { WaterBill, Room } = require('../models');
|
||||||
|
const { Op } = require('sequelize');
|
||||||
|
|
||||||
|
// 格式化时间(考虑时区,转换为北京时间)
|
||||||
|
const formatDate = (date) => {
|
||||||
|
if (!date) return null;
|
||||||
|
// 创建一个新的Date对象,加上8小时的时区偏移
|
||||||
|
const beijingDate = new Date(date.getTime() + 8 * 60 * 60 * 1000);
|
||||||
|
return beijingDate.toISOString().split('T')[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化水费数据
|
||||||
|
const formatWaterBillData = (bill) => {
|
||||||
|
const formattedBill = {
|
||||||
|
...bill.toJSON(),
|
||||||
|
startDate: formatDate(bill.startDate),
|
||||||
|
endDate: formatDate(bill.endDate),
|
||||||
|
createTime: formatDate(bill.createTime)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化关联数据
|
||||||
|
if (formattedBill.Room) {
|
||||||
|
formattedBill.Room = {
|
||||||
|
...formattedBill.Room,
|
||||||
|
createTime: formatDate(formattedBill.Room.createTime)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedBill;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取所有水费记录(支持搜索和分页)
|
||||||
|
const getAllWaterBills = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { roomId, status, startDate, endDate, page = 1, pageSize = 10 } = req.query;
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
const where = {};
|
||||||
|
if (roomId) {
|
||||||
|
where.roomId = roomId;
|
||||||
|
}
|
||||||
|
if (status) {
|
||||||
|
where.status = status;
|
||||||
|
}
|
||||||
|
if (startDate) {
|
||||||
|
where.startDate = { [Op.gte]: new Date(startDate) };
|
||||||
|
}
|
||||||
|
if (endDate) {
|
||||||
|
where.endDate = { [Op.lte]: new Date(endDate) };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算偏移量
|
||||||
|
const offset = (page - 1) * pageSize;
|
||||||
|
|
||||||
|
// 查询水费数据
|
||||||
|
const { count, rows } = await WaterBill.findAndCountAll({
|
||||||
|
where,
|
||||||
|
include: [Room],
|
||||||
|
limit: parseInt(pageSize),
|
||||||
|
offset: parseInt(offset)
|
||||||
|
});
|
||||||
|
|
||||||
|
// 格式化数据
|
||||||
|
const formattedBills = rows.map(formatWaterBillData);
|
||||||
|
|
||||||
|
// 返回结果
|
||||||
|
res.status(200).json({
|
||||||
|
data: formattedBills,
|
||||||
|
total: count,
|
||||||
|
page: parseInt(page),
|
||||||
|
pageSize: parseInt(pageSize)
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取单个水费记录
|
||||||
|
const getWaterBillById = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const bill = await WaterBill.findByPk(id, {
|
||||||
|
include: [Room]
|
||||||
|
});
|
||||||
|
if (!bill) {
|
||||||
|
return res.status(404).json({ error: '水费记录不存在' });
|
||||||
|
}
|
||||||
|
const formattedBill = formatWaterBillData(bill);
|
||||||
|
res.status(200).json(formattedBill);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 创建水费记录
|
||||||
|
const createWaterBill = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { roomId, startDate, endDate, startReading, endReading, unitPrice } = req.body;
|
||||||
|
|
||||||
|
// 计算用水量和费用
|
||||||
|
const usage = parseFloat(endReading) - parseFloat(startReading);
|
||||||
|
const amount = usage * parseFloat(unitPrice);
|
||||||
|
|
||||||
|
const bill = await WaterBill.create({
|
||||||
|
roomId,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
startReading,
|
||||||
|
endReading,
|
||||||
|
usage,
|
||||||
|
unitPrice,
|
||||||
|
amount
|
||||||
|
});
|
||||||
|
|
||||||
|
const formattedBill = formatWaterBillData(bill);
|
||||||
|
res.status(201).json(formattedBill);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 更新水费记录
|
||||||
|
const updateWaterBill = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const { startDate, endDate, startReading, endReading, unitPrice, status } = req.body;
|
||||||
|
|
||||||
|
const bill = await WaterBill.findByPk(id);
|
||||||
|
if (!bill) {
|
||||||
|
return res.status(404).json({ error: '水费记录不存在' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算用水量和费用
|
||||||
|
let usage = bill.usage;
|
||||||
|
let amount = bill.amount;
|
||||||
|
if (startReading && endReading && unitPrice) {
|
||||||
|
usage = parseFloat(endReading) - parseFloat(startReading);
|
||||||
|
amount = usage * parseFloat(unitPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
await bill.update({
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
startReading,
|
||||||
|
endReading,
|
||||||
|
usage,
|
||||||
|
unitPrice,
|
||||||
|
amount,
|
||||||
|
status
|
||||||
|
});
|
||||||
|
|
||||||
|
const formattedBill = formatWaterBillData(bill);
|
||||||
|
res.status(200).json(formattedBill);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除水费记录
|
||||||
|
const deleteWaterBill = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const bill = await WaterBill.findByPk(id);
|
||||||
|
if (!bill) {
|
||||||
|
return res.status(404).json({ error: '水费记录不存在' });
|
||||||
|
}
|
||||||
|
await bill.destroy();
|
||||||
|
res.status(200).json({ message: '水费记录删除成功' });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getAllWaterBills,
|
||||||
|
getWaterBillById,
|
||||||
|
createWaterBill,
|
||||||
|
updateWaterBill,
|
||||||
|
deleteWaterBill
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
const sequelize = require('../config/db');
|
||||||
|
const Region = require('./Region');
|
||||||
|
|
||||||
|
const Apartment = sequelize.define('Apartment', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true
|
||||||
|
},
|
||||||
|
regionId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: Region,
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: DataTypes.STRING(50),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
address: {
|
||||||
|
type: DataTypes.STRING(255),
|
||||||
|
allowNull: true
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tableName: 'apartments',
|
||||||
|
timestamps: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// 建立关联
|
||||||
|
Apartment.belongsTo(Region, { foreignKey: 'regionId' });
|
||||||
|
Region.hasMany(Apartment, { foreignKey: 'regionId' });
|
||||||
|
|
||||||
|
module.exports = Apartment;
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
const sequelize = require('../config/db');
|
||||||
|
const Room = require('./Room');
|
||||||
|
const Tenant = require('./Tenant');
|
||||||
|
|
||||||
|
const Contract = sequelize.define('Contract', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true
|
||||||
|
},
|
||||||
|
roomId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: Room,
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tenantId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: Tenant,
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
rent: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
deposit: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: DataTypes.ENUM('active', 'expired'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'active'
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tableName: 'contracts',
|
||||||
|
timestamps: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// 建立关联
|
||||||
|
Contract.belongsTo(Room, { foreignKey: 'roomId' });
|
||||||
|
Contract.belongsTo(Tenant, { foreignKey: 'tenantId' });
|
||||||
|
|
||||||
|
module.exports = Contract;
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
const sequelize = require('../config/db');
|
||||||
|
const Room = require('./Room');
|
||||||
|
|
||||||
|
const ElectricityBill = sequelize.define('ElectricityBill', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true
|
||||||
|
},
|
||||||
|
roomId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: Room,
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
startReading: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
endReading: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
usage: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
unitPrice: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
amount: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: DataTypes.ENUM('unpaid', 'paid'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'unpaid'
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tableName: 'electricity_bills',
|
||||||
|
timestamps: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// 建立关联
|
||||||
|
ElectricityBill.belongsTo(Room, { foreignKey: 'roomId' });
|
||||||
|
|
||||||
|
module.exports = ElectricityBill;
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
const sequelize = require('../config/db');
|
||||||
|
|
||||||
|
const Region = sequelize.define('Region', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: DataTypes.STRING(50),
|
||||||
|
allowNull: false,
|
||||||
|
unique: true
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: true
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tableName: 'regions',
|
||||||
|
timestamps: false
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = Region;
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
const sequelize = require('../config/db');
|
||||||
|
const Room = require('./Room');
|
||||||
|
const Tenant = require('./Tenant');
|
||||||
|
const Contract = require('./Contract');
|
||||||
|
|
||||||
|
const Rental = sequelize.define('Rental', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true
|
||||||
|
},
|
||||||
|
roomId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: Room,
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tenantId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: Tenant,
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
contractId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: Contract,
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
rent: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
deposit: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: DataTypes.ENUM('active', 'expired'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'active'
|
||||||
|
},
|
||||||
|
remark: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: true
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tableName: 'rentals',
|
||||||
|
timestamps: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// 建立关联
|
||||||
|
Rental.belongsTo(Room, { foreignKey: 'roomId' });
|
||||||
|
Rental.belongsTo(Tenant, { foreignKey: 'tenantId' });
|
||||||
|
Rental.belongsTo(Contract, { foreignKey: 'contractId' });
|
||||||
|
|
||||||
|
module.exports = Rental;
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
const sequelize = require('../config/db');
|
||||||
|
const Apartment = require('./Apartment');
|
||||||
|
|
||||||
|
const Room = sequelize.define('Room', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true
|
||||||
|
},
|
||||||
|
apartmentId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: Apartment,
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
roomNumber: {
|
||||||
|
type: DataTypes.STRING(20),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
area: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
price: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: DataTypes.ENUM('empty', 'rented', 'soon_expire', 'expired', 'cleaning', 'maintenance'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'empty'
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tableName: 'rooms',
|
||||||
|
timestamps: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// 建立关联
|
||||||
|
Room.belongsTo(Apartment, { foreignKey: 'apartmentId' });
|
||||||
|
Apartment.hasMany(Room, { foreignKey: 'apartmentId' });
|
||||||
|
|
||||||
|
module.exports = Room;
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
const sequelize = require('../config/db');
|
||||||
|
|
||||||
|
const Tenant = sequelize.define('Tenant', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: DataTypes.STRING(50),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
phone: {
|
||||||
|
type: DataTypes.STRING(20),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
idCard: {
|
||||||
|
type: DataTypes.STRING(20),
|
||||||
|
allowNull: false,
|
||||||
|
unique: true
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tableName: 'tenants',
|
||||||
|
timestamps: false
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = Tenant;
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
const sequelize = require('../config/db');
|
||||||
|
const Room = require('./Room');
|
||||||
|
|
||||||
|
const WaterBill = sequelize.define('WaterBill', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true
|
||||||
|
},
|
||||||
|
roomId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: Room,
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
startReading: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
endReading: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
usage: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
unitPrice: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
amount: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: DataTypes.ENUM('unpaid', 'paid'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'unpaid'
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tableName: 'water_bills',
|
||||||
|
timestamps: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// 建立关联
|
||||||
|
WaterBill.belongsTo(Room, { foreignKey: 'roomId' });
|
||||||
|
|
||||||
|
module.exports = WaterBill;
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
const Region = require('./Region');
|
||||||
|
const Apartment = require('./Apartment');
|
||||||
|
const Room = require('./Room');
|
||||||
|
const Tenant = require('./Tenant');
|
||||||
|
const Contract = require('./Contract');
|
||||||
|
const Rental = require('./Rental');
|
||||||
|
const WaterBill = require('./WaterBill');
|
||||||
|
const ElectricityBill = require('./ElectricityBill');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Region,
|
||||||
|
Apartment,
|
||||||
|
Room,
|
||||||
|
Tenant,
|
||||||
|
Contract,
|
||||||
|
Rental,
|
||||||
|
WaterBill,
|
||||||
|
ElectricityBill
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,652 @@
|
||||||
|
{
|
||||||
|
"name": "rentease-backend",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"requires": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/debug": {
|
||||||
|
"version": "4.1.12",
|
||||||
|
"resolved": "https://registry.npmmirror.com/@types/debug/-/debug-4.1.12.tgz",
|
||||||
|
"integrity": "sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==",
|
||||||
|
"requires": {
|
||||||
|
"@types/ms": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@types/ms": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/@types/ms/-/ms-2.1.0.tgz",
|
||||||
|
"integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA=="
|
||||||
|
},
|
||||||
|
"@types/node": {
|
||||||
|
"version": "25.3.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/@types/node/-/node-25.3.3.tgz",
|
||||||
|
"integrity": "sha512-DpzbrH7wIcBaJibpKo9nnSQL0MTRdnWttGyE5haGwK86xgMOkFLp7vEyfQPGLOJh5wNYiJ3V9PmUMDhV9u8kkQ==",
|
||||||
|
"requires": {
|
||||||
|
"undici-types": "~7.18.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@types/validator": {
|
||||||
|
"version": "13.15.10",
|
||||||
|
"resolved": "https://registry.npmmirror.com/@types/validator/-/validator-13.15.10.tgz",
|
||||||
|
"integrity": "sha512-T8L6i7wCuyoK8A/ZeLYt1+q0ty3Zb9+qbSSvrIVitzT3YjZqkTZ40IbRsPanlB4h1QB3JVL1SYCdR6ngtFYcuA=="
|
||||||
|
},
|
||||||
|
"accepts": {
|
||||||
|
"version": "1.3.8",
|
||||||
|
"resolved": "https://registry.npmmirror.com/accepts/-/accepts-1.3.8.tgz",
|
||||||
|
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
|
||||||
|
"requires": {
|
||||||
|
"mime-types": "~2.1.34",
|
||||||
|
"negotiator": "0.6.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"array-flatten": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg=="
|
||||||
|
},
|
||||||
|
"aws-ssl-profiles": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g=="
|
||||||
|
},
|
||||||
|
"body-parser": {
|
||||||
|
"version": "1.19.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/body-parser/-/body-parser-1.19.0.tgz",
|
||||||
|
"integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==",
|
||||||
|
"requires": {
|
||||||
|
"bytes": "3.1.0",
|
||||||
|
"content-type": "~1.0.4",
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"depd": "~1.1.2",
|
||||||
|
"http-errors": "1.7.2",
|
||||||
|
"iconv-lite": "0.4.24",
|
||||||
|
"on-finished": "~2.3.0",
|
||||||
|
"qs": "6.7.0",
|
||||||
|
"raw-body": "2.4.0",
|
||||||
|
"type-is": "~1.6.17"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"iconv-lite": {
|
||||||
|
"version": "0.4.24",
|
||||||
|
"resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||||
|
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
||||||
|
"requires": {
|
||||||
|
"safer-buffer": ">= 2.1.2 < 3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bytes": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/bytes/-/bytes-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
|
||||||
|
},
|
||||||
|
"content-disposition": {
|
||||||
|
"version": "0.5.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/content-disposition/-/content-disposition-0.5.3.tgz",
|
||||||
|
"integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==",
|
||||||
|
"requires": {
|
||||||
|
"safe-buffer": "5.1.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"content-type": {
|
||||||
|
"version": "1.0.5",
|
||||||
|
"resolved": "https://registry.npmmirror.com/content-type/-/content-type-1.0.5.tgz",
|
||||||
|
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA=="
|
||||||
|
},
|
||||||
|
"cookie": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/cookie/-/cookie-0.4.0.tgz",
|
||||||
|
"integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg=="
|
||||||
|
},
|
||||||
|
"cookie-signature": {
|
||||||
|
"version": "1.0.6",
|
||||||
|
"resolved": "https://registry.npmmirror.com/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
|
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
|
||||||
|
},
|
||||||
|
"cors": {
|
||||||
|
"version": "2.8.6",
|
||||||
|
"resolved": "https://registry.npmmirror.com/cors/-/cors-2.8.6.tgz",
|
||||||
|
"integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==",
|
||||||
|
"requires": {
|
||||||
|
"object-assign": "^4",
|
||||||
|
"vary": "^1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"debug": {
|
||||||
|
"version": "4.4.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/debug/-/debug-4.4.3.tgz",
|
||||||
|
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "^2.1.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"denque": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/denque/-/denque-2.1.0.tgz",
|
||||||
|
"integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw=="
|
||||||
|
},
|
||||||
|
"depd": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/depd/-/depd-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ=="
|
||||||
|
},
|
||||||
|
"destroy": {
|
||||||
|
"version": "1.0.4",
|
||||||
|
"resolved": "https://registry.npmmirror.com/destroy/-/destroy-1.0.4.tgz",
|
||||||
|
"integrity": "sha512-3NdhDuEXnfun/z7x9GOElY49LoqVHoGScmOKwmxhsS8N5Y+Z8KyPPDnaSzqWgYt/ji4mqwfTS34Htrk0zPIXVg=="
|
||||||
|
},
|
||||||
|
"dottie": {
|
||||||
|
"version": "2.0.7",
|
||||||
|
"resolved": "https://registry.npmmirror.com/dottie/-/dottie-2.0.7.tgz",
|
||||||
|
"integrity": "sha512-7lAK2A0b3zZr3UC5aE69CPdCFR4RHW1o2Dr74TqFykxkUCBXSRJum/yPc7g8zRHJqWKomPLHwFLLoUnn8PXXRg=="
|
||||||
|
},
|
||||||
|
"ee-first": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/ee-first/-/ee-first-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow=="
|
||||||
|
},
|
||||||
|
"encodeurl": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/encodeurl/-/encodeurl-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w=="
|
||||||
|
},
|
||||||
|
"escape-html": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/escape-html/-/escape-html-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow=="
|
||||||
|
},
|
||||||
|
"etag": {
|
||||||
|
"version": "1.8.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/etag/-/etag-1.8.1.tgz",
|
||||||
|
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg=="
|
||||||
|
},
|
||||||
|
"express": {
|
||||||
|
"version": "4.17.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/express/-/express-4.17.1.tgz",
|
||||||
|
"integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==",
|
||||||
|
"requires": {
|
||||||
|
"accepts": "~1.3.7",
|
||||||
|
"array-flatten": "1.1.1",
|
||||||
|
"body-parser": "1.19.0",
|
||||||
|
"content-disposition": "0.5.3",
|
||||||
|
"content-type": "~1.0.4",
|
||||||
|
"cookie": "0.4.0",
|
||||||
|
"cookie-signature": "1.0.6",
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"depd": "~1.1.2",
|
||||||
|
"encodeurl": "~1.0.2",
|
||||||
|
"escape-html": "~1.0.3",
|
||||||
|
"etag": "~1.8.1",
|
||||||
|
"finalhandler": "~1.1.2",
|
||||||
|
"fresh": "0.5.2",
|
||||||
|
"merge-descriptors": "1.0.1",
|
||||||
|
"methods": "~1.1.2",
|
||||||
|
"on-finished": "~2.3.0",
|
||||||
|
"parseurl": "~1.3.3",
|
||||||
|
"path-to-regexp": "0.1.7",
|
||||||
|
"proxy-addr": "~2.0.5",
|
||||||
|
"qs": "6.7.0",
|
||||||
|
"range-parser": "~1.2.1",
|
||||||
|
"safe-buffer": "5.1.2",
|
||||||
|
"send": "0.17.1",
|
||||||
|
"serve-static": "1.14.1",
|
||||||
|
"setprototypeof": "1.1.1",
|
||||||
|
"statuses": "~1.5.0",
|
||||||
|
"type-is": "~1.6.18",
|
||||||
|
"utils-merge": "1.0.1",
|
||||||
|
"vary": "~1.1.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"finalhandler": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/finalhandler/-/finalhandler-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==",
|
||||||
|
"requires": {
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"encodeurl": "~1.0.2",
|
||||||
|
"escape-html": "~1.0.3",
|
||||||
|
"on-finished": "~2.3.0",
|
||||||
|
"parseurl": "~1.3.3",
|
||||||
|
"statuses": "~1.5.0",
|
||||||
|
"unpipe": "~1.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"forwarded": {
|
||||||
|
"version": "0.2.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/forwarded/-/forwarded-0.2.0.tgz",
|
||||||
|
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow=="
|
||||||
|
},
|
||||||
|
"fresh": {
|
||||||
|
"version": "0.5.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/fresh/-/fresh-0.5.2.tgz",
|
||||||
|
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q=="
|
||||||
|
},
|
||||||
|
"generate-function": {
|
||||||
|
"version": "2.3.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/generate-function/-/generate-function-2.3.1.tgz",
|
||||||
|
"integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==",
|
||||||
|
"requires": {
|
||||||
|
"is-property": "^1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"http-errors": {
|
||||||
|
"version": "1.7.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/http-errors/-/http-errors-1.7.2.tgz",
|
||||||
|
"integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==",
|
||||||
|
"requires": {
|
||||||
|
"depd": "~1.1.2",
|
||||||
|
"inherits": "2.0.3",
|
||||||
|
"setprototypeof": "1.1.1",
|
||||||
|
"statuses": ">= 1.5.0 < 2",
|
||||||
|
"toidentifier": "1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"iconv-lite": {
|
||||||
|
"version": "0.7.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.7.2.tgz",
|
||||||
|
"integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==",
|
||||||
|
"requires": {
|
||||||
|
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"inflection": {
|
||||||
|
"version": "1.13.4",
|
||||||
|
"resolved": "https://registry.npmmirror.com/inflection/-/inflection-1.13.4.tgz",
|
||||||
|
"integrity": "sha512-6I/HUDeYFfuNCVS3td055BaXBwKYuzw7K3ExVMStBowKo9oOAMJIXIHvdyR3iboTCp1b+1i5DSkIZTcwIktuDw=="
|
||||||
|
},
|
||||||
|
"inherits": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/inherits/-/inherits-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw=="
|
||||||
|
},
|
||||||
|
"ipaddr.js": {
|
||||||
|
"version": "1.9.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
||||||
|
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g=="
|
||||||
|
},
|
||||||
|
"is-property": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/is-property/-/is-property-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g=="
|
||||||
|
},
|
||||||
|
"lodash": {
|
||||||
|
"version": "4.17.23",
|
||||||
|
"resolved": "https://registry.npmmirror.com/lodash/-/lodash-4.17.23.tgz",
|
||||||
|
"integrity": "sha512-LgVTMpQtIopCi79SJeDiP0TfWi5CNEc/L/aRdTh3yIvmZXTnheWpKjSZhnvMl8iXbC1tFg9gdHHDMLoV7CnG+w=="
|
||||||
|
},
|
||||||
|
"long": {
|
||||||
|
"version": "5.3.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/long/-/long-5.3.2.tgz",
|
||||||
|
"integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA=="
|
||||||
|
},
|
||||||
|
"lru.min": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmmirror.com/lru.min/-/lru.min-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-DqC6n3QQ77zdFpCMASA1a3Jlb64Hv2N2DciFGkO/4L9+q/IpIAuRlKOvCXabtRW6cQf8usbmM6BE/TOPysCdIA=="
|
||||||
|
},
|
||||||
|
"media-typer": {
|
||||||
|
"version": "0.3.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/media-typer/-/media-typer-0.3.0.tgz",
|
||||||
|
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ=="
|
||||||
|
},
|
||||||
|
"merge-descriptors": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w=="
|
||||||
|
},
|
||||||
|
"methods": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/methods/-/methods-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w=="
|
||||||
|
},
|
||||||
|
"mime": {
|
||||||
|
"version": "1.6.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/mime/-/mime-1.6.0.tgz",
|
||||||
|
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg=="
|
||||||
|
},
|
||||||
|
"mime-db": {
|
||||||
|
"version": "1.52.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz",
|
||||||
|
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="
|
||||||
|
},
|
||||||
|
"mime-types": {
|
||||||
|
"version": "2.1.35",
|
||||||
|
"resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz",
|
||||||
|
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||||
|
"requires": {
|
||||||
|
"mime-db": "1.52.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"moment": {
|
||||||
|
"version": "2.30.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/moment/-/moment-2.30.1.tgz",
|
||||||
|
"integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how=="
|
||||||
|
},
|
||||||
|
"moment-timezone": {
|
||||||
|
"version": "0.5.48",
|
||||||
|
"resolved": "https://registry.npmmirror.com/moment-timezone/-/moment-timezone-0.5.48.tgz",
|
||||||
|
"integrity": "sha512-f22b8LV1gbTO2ms2j2z13MuPogNoh5UzxL3nzNAYKGraILnbGc9NEE6dyiiiLv46DGRb8A4kg8UKWLjPthxBHw==",
|
||||||
|
"requires": {
|
||||||
|
"moment": "^2.29.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ms": {
|
||||||
|
"version": "2.1.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz",
|
||||||
|
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
|
||||||
|
},
|
||||||
|
"mysql2": {
|
||||||
|
"version": "3.18.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/mysql2/-/mysql2-3.18.2.tgz",
|
||||||
|
"integrity": "sha512-UfEShBFAZZEAKjySnTUuE7BgqkYT4mx+RjoJ5aqtmwSSvNcJ/QxQPXz/y3jSxNiVRedPfgccmuBtiPCSiEEytw==",
|
||||||
|
"requires": {
|
||||||
|
"aws-ssl-profiles": "^1.1.2",
|
||||||
|
"denque": "^2.1.0",
|
||||||
|
"generate-function": "^2.3.1",
|
||||||
|
"iconv-lite": "^0.7.2",
|
||||||
|
"long": "^5.3.2",
|
||||||
|
"lru.min": "^1.1.4",
|
||||||
|
"named-placeholders": "^1.1.6",
|
||||||
|
"sql-escaper": "^1.3.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"named-placeholders": {
|
||||||
|
"version": "1.1.6",
|
||||||
|
"resolved": "https://registry.npmmirror.com/named-placeholders/-/named-placeholders-1.1.6.tgz",
|
||||||
|
"integrity": "sha512-Tz09sEL2EEuv5fFowm419c1+a/jSMiBjI9gHxVLrVdbUkkNUUfjsVYs9pVZu5oCon/kmRh9TfLEObFtkVxmY0w==",
|
||||||
|
"requires": {
|
||||||
|
"lru.min": "^1.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"negotiator": {
|
||||||
|
"version": "0.6.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/negotiator/-/negotiator-0.6.3.tgz",
|
||||||
|
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg=="
|
||||||
|
},
|
||||||
|
"object-assign": {
|
||||||
|
"version": "4.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/object-assign/-/object-assign-4.1.1.tgz",
|
||||||
|
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg=="
|
||||||
|
},
|
||||||
|
"on-finished": {
|
||||||
|
"version": "2.3.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/on-finished/-/on-finished-2.3.0.tgz",
|
||||||
|
"integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==",
|
||||||
|
"requires": {
|
||||||
|
"ee-first": "1.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parseurl": {
|
||||||
|
"version": "1.3.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/parseurl/-/parseurl-1.3.3.tgz",
|
||||||
|
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="
|
||||||
|
},
|
||||||
|
"path-to-regexp": {
|
||||||
|
"version": "0.1.7",
|
||||||
|
"resolved": "https://registry.npmmirror.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
||||||
|
"integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ=="
|
||||||
|
},
|
||||||
|
"pg-connection-string": {
|
||||||
|
"version": "2.11.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/pg-connection-string/-/pg-connection-string-2.11.0.tgz",
|
||||||
|
"integrity": "sha512-kecgoJwhOpxYU21rZjULrmrBJ698U2RxXofKVzOn5UDj61BPj/qMb7diYUR1nLScCDbrztQFl1TaQZT0t1EtzQ=="
|
||||||
|
},
|
||||||
|
"proxy-addr": {
|
||||||
|
"version": "2.0.7",
|
||||||
|
"resolved": "https://registry.npmmirror.com/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||||
|
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
|
||||||
|
"requires": {
|
||||||
|
"forwarded": "0.2.0",
|
||||||
|
"ipaddr.js": "1.9.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"qs": {
|
||||||
|
"version": "6.7.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/qs/-/qs-6.7.0.tgz",
|
||||||
|
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ=="
|
||||||
|
},
|
||||||
|
"range-parser": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/range-parser/-/range-parser-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg=="
|
||||||
|
},
|
||||||
|
"raw-body": {
|
||||||
|
"version": "2.4.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/raw-body/-/raw-body-2.4.0.tgz",
|
||||||
|
"integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==",
|
||||||
|
"requires": {
|
||||||
|
"bytes": "3.1.0",
|
||||||
|
"http-errors": "1.7.2",
|
||||||
|
"iconv-lite": "0.4.24",
|
||||||
|
"unpipe": "1.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"iconv-lite": {
|
||||||
|
"version": "0.4.24",
|
||||||
|
"resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||||
|
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
||||||
|
"requires": {
|
||||||
|
"safer-buffer": ">= 2.1.2 < 3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"retry-as-promised": {
|
||||||
|
"version": "7.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/retry-as-promised/-/retry-as-promised-7.1.1.tgz",
|
||||||
|
"integrity": "sha512-hMD7odLOt3LkTjcif8aRZqi/hybjpLNgSk5oF5FCowfCjok6LukpN2bDX7R5wDmbgBQFn7YoBxSagmtXHaJYJw=="
|
||||||
|
},
|
||||||
|
"safe-buffer": {
|
||||||
|
"version": "5.1.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
|
},
|
||||||
|
"safer-buffer": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||||
|
},
|
||||||
|
"semver": {
|
||||||
|
"version": "7.7.4",
|
||||||
|
"resolved": "https://registry.npmmirror.com/semver/-/semver-7.7.4.tgz",
|
||||||
|
"integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA=="
|
||||||
|
},
|
||||||
|
"send": {
|
||||||
|
"version": "0.17.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/send/-/send-0.17.1.tgz",
|
||||||
|
"integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==",
|
||||||
|
"requires": {
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"depd": "~1.1.2",
|
||||||
|
"destroy": "~1.0.4",
|
||||||
|
"encodeurl": "~1.0.2",
|
||||||
|
"escape-html": "~1.0.3",
|
||||||
|
"etag": "~1.8.1",
|
||||||
|
"fresh": "0.5.2",
|
||||||
|
"http-errors": "~1.7.2",
|
||||||
|
"mime": "1.6.0",
|
||||||
|
"ms": "2.1.1",
|
||||||
|
"on-finished": "~2.3.0",
|
||||||
|
"range-parser": "~1.2.1",
|
||||||
|
"statuses": "~1.5.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ms": {
|
||||||
|
"version": "2.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.1.tgz",
|
||||||
|
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sequelize": {
|
||||||
|
"version": "6.37.7",
|
||||||
|
"resolved": "https://registry.npmmirror.com/sequelize/-/sequelize-6.37.7.tgz",
|
||||||
|
"integrity": "sha512-mCnh83zuz7kQxxJirtFD7q6Huy6liPanI67BSlbzSYgVNl5eXVdE2CN1FuAeZwG1SNpGsNRCV+bJAVVnykZAFA==",
|
||||||
|
"requires": {
|
||||||
|
"@types/debug": "^4.1.8",
|
||||||
|
"@types/validator": "^13.7.17",
|
||||||
|
"debug": "^4.3.4",
|
||||||
|
"dottie": "^2.0.6",
|
||||||
|
"inflection": "^1.13.4",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
|
"moment": "^2.29.4",
|
||||||
|
"moment-timezone": "^0.5.43",
|
||||||
|
"pg-connection-string": "^2.6.1",
|
||||||
|
"retry-as-promised": "^7.0.4",
|
||||||
|
"semver": "^7.5.4",
|
||||||
|
"sequelize-pool": "^7.1.0",
|
||||||
|
"toposort-class": "^1.0.1",
|
||||||
|
"uuid": "^8.3.2",
|
||||||
|
"validator": "^13.9.0",
|
||||||
|
"wkx": "^0.5.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sequelize-pool": {
|
||||||
|
"version": "7.1.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/sequelize-pool/-/sequelize-pool-7.1.0.tgz",
|
||||||
|
"integrity": "sha512-G9c0qlIWQSK29pR/5U2JF5dDQeqqHRragoyahj/Nx4KOOQ3CPPfzxnfqFPCSB7x5UgjOgnZ61nSxz+fjDpRlJg=="
|
||||||
|
},
|
||||||
|
"serve-static": {
|
||||||
|
"version": "1.14.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/serve-static/-/serve-static-1.14.1.tgz",
|
||||||
|
"integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==",
|
||||||
|
"requires": {
|
||||||
|
"encodeurl": "~1.0.2",
|
||||||
|
"escape-html": "~1.0.3",
|
||||||
|
"parseurl": "~1.3.3",
|
||||||
|
"send": "0.17.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"setprototypeof": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/setprototypeof/-/setprototypeof-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
|
||||||
|
},
|
||||||
|
"sql-escaper": {
|
||||||
|
"version": "1.3.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/sql-escaper/-/sql-escaper-1.3.3.tgz",
|
||||||
|
"integrity": "sha512-BsTCV265VpTp8tm1wyIm1xqQCS+Q9NHx2Sr+WcnUrgLrQ6yiDIvHYJV5gHxsj1lMBy2zm5twLaZao8Jd+S8JJw=="
|
||||||
|
},
|
||||||
|
"statuses": {
|
||||||
|
"version": "1.5.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/statuses/-/statuses-1.5.0.tgz",
|
||||||
|
"integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA=="
|
||||||
|
},
|
||||||
|
"toidentifier": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/toidentifier/-/toidentifier-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
|
||||||
|
},
|
||||||
|
"toposort-class": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/toposort-class/-/toposort-class-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-OsLcGGbYF3rMjPUf8oKktyvCiUxSbqMMS39m33MAjLTC1DVIH6x3WSt63/M77ihI09+Sdfk1AXvfhCEeUmC7mg=="
|
||||||
|
},
|
||||||
|
"type-is": {
|
||||||
|
"version": "1.6.18",
|
||||||
|
"resolved": "https://registry.npmmirror.com/type-is/-/type-is-1.6.18.tgz",
|
||||||
|
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
|
||||||
|
"requires": {
|
||||||
|
"media-typer": "0.3.0",
|
||||||
|
"mime-types": "~2.1.24"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"undici-types": {
|
||||||
|
"version": "7.18.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/undici-types/-/undici-types-7.18.2.tgz",
|
||||||
|
"integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w=="
|
||||||
|
},
|
||||||
|
"unpipe": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/unpipe/-/unpipe-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ=="
|
||||||
|
},
|
||||||
|
"utils-merge": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/utils-merge/-/utils-merge-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA=="
|
||||||
|
},
|
||||||
|
"uuid": {
|
||||||
|
"version": "8.3.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/uuid/-/uuid-8.3.2.tgz",
|
||||||
|
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
||||||
|
},
|
||||||
|
"validator": {
|
||||||
|
"version": "13.15.26",
|
||||||
|
"resolved": "https://registry.npmmirror.com/validator/-/validator-13.15.26.tgz",
|
||||||
|
"integrity": "sha512-spH26xU080ydGggxRyR1Yhcbgx+j3y5jbNXk/8L+iRvdIEQ4uTRH2Sgf2dokud6Q4oAtsbNvJ1Ft+9xmm6IZcA=="
|
||||||
|
},
|
||||||
|
"vary": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/vary/-/vary-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg=="
|
||||||
|
},
|
||||||
|
"wkx": {
|
||||||
|
"version": "0.5.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/wkx/-/wkx-0.5.0.tgz",
|
||||||
|
"integrity": "sha512-Xng/d4Ichh8uN4l0FToV/258EjMGU9MGcA0HV2d9B/ZpZB3lqQm7nkOdZdm5GhKtLLhAE7PiVQwN4eN+2YJJUg==",
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"name": "rentease-backend",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "app.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"description": "",
|
||||||
|
"dependencies": {
|
||||||
|
"cors": "^2.8.6",
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"mysql2": "^3.18.2",
|
||||||
|
"sequelize": "^6.37.7"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const apartmentController = require('../controllers/apartmentController');
|
||||||
|
|
||||||
|
// 路由
|
||||||
|
router.get('/', apartmentController.getAllApartments);
|
||||||
|
router.get('/:id', apartmentController.getApartmentById);
|
||||||
|
router.post('/', apartmentController.createApartment);
|
||||||
|
router.put('/:id', apartmentController.updateApartment);
|
||||||
|
router.delete('/:id', apartmentController.deleteApartment);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const contractController = require('../controllers/contractController');
|
||||||
|
|
||||||
|
// 路由
|
||||||
|
router.get('/', contractController.getAllContracts);
|
||||||
|
router.get('/:id', contractController.getContractById);
|
||||||
|
router.post('/', contractController.createContract);
|
||||||
|
router.put('/:id', contractController.updateContract);
|
||||||
|
router.delete('/:id', contractController.deleteContract);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const electricityBillController = require('../controllers/electricityBillController');
|
||||||
|
|
||||||
|
// 获取所有电费记录
|
||||||
|
router.get('/', electricityBillController.getAllElectricityBills);
|
||||||
|
|
||||||
|
// 获取单个电费记录
|
||||||
|
router.get('/:id', electricityBillController.getElectricityBillById);
|
||||||
|
|
||||||
|
// 创建电费记录
|
||||||
|
router.post('/', electricityBillController.createElectricityBill);
|
||||||
|
|
||||||
|
// 更新电费记录
|
||||||
|
router.put('/:id', electricityBillController.updateElectricityBill);
|
||||||
|
|
||||||
|
// 删除电费记录
|
||||||
|
router.delete('/:id', electricityBillController.deleteElectricityBill);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const regionController = require('../controllers/regionController');
|
||||||
|
|
||||||
|
// 路由
|
||||||
|
router.get('/', regionController.getAllRegions);
|
||||||
|
router.get('/:id', regionController.getRegionById);
|
||||||
|
router.post('/', regionController.createRegion);
|
||||||
|
router.put('/:id', regionController.updateRegion);
|
||||||
|
router.delete('/:id', regionController.deleteRegion);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const rentalController = require('../controllers/rentalController');
|
||||||
|
|
||||||
|
// 路由
|
||||||
|
router.get('/', rentalController.getAllRentals);
|
||||||
|
router.get('/:id', rentalController.getRentalById);
|
||||||
|
router.post('/', rentalController.createRental);
|
||||||
|
router.put('/:id', rentalController.updateRental);
|
||||||
|
router.delete('/:id', rentalController.deleteRental);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const roomController = require('../controllers/roomController');
|
||||||
|
|
||||||
|
// 路由
|
||||||
|
router.get('/', roomController.getAllRooms);
|
||||||
|
router.get('/:id', roomController.getRoomById);
|
||||||
|
router.post('/', roomController.createRoom);
|
||||||
|
router.put('/:id', roomController.updateRoom);
|
||||||
|
router.delete('/:id', roomController.deleteRoom);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const statisticsController = require('../controllers/statisticsController');
|
||||||
|
|
||||||
|
// 路由
|
||||||
|
router.get('/rent', statisticsController.getRentStatistics);
|
||||||
|
router.get('/room-status', statisticsController.getRoomStatusStatistics);
|
||||||
|
router.get('/region-house', statisticsController.getRegionHouseStatistics);
|
||||||
|
router.get('/region-apartment-house', statisticsController.getRegionApartmentHouseStatistics);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const tenantController = require('../controllers/tenantController');
|
||||||
|
|
||||||
|
// 路由
|
||||||
|
router.get('/', tenantController.getAllTenants);
|
||||||
|
router.get('/:id', tenantController.getTenantById);
|
||||||
|
router.post('/', tenantController.createTenant);
|
||||||
|
router.put('/:id', tenantController.updateTenant);
|
||||||
|
router.delete('/:id', tenantController.deleteTenant);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const waterBillController = require('../controllers/waterBillController');
|
||||||
|
|
||||||
|
// 获取所有水费记录
|
||||||
|
router.get('/', waterBillController.getAllWaterBills);
|
||||||
|
|
||||||
|
// 获取单个水费记录
|
||||||
|
router.get('/:id', waterBillController.getWaterBillById);
|
||||||
|
|
||||||
|
// 创建水费记录
|
||||||
|
router.post('/', waterBillController.createWaterBill);
|
||||||
|
|
||||||
|
// 更新水费记录
|
||||||
|
router.put('/:id', waterBillController.updateWaterBill);
|
||||||
|
|
||||||
|
// 删除水费记录
|
||||||
|
router.delete('/:id', waterBillController.deleteWaterBill);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
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();
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
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();
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
const { Region, Apartment, Room } = require('../models');
|
||||||
|
|
||||||
|
// 房间列表
|
||||||
|
const roomNumbers = [
|
||||||
|
'201', '202', '203', '205', '206',
|
||||||
|
'301', '302', '303', '305', '306',
|
||||||
|
'401', '402', '403', '405', '406'
|
||||||
|
];
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
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();
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
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'
|
||||||
|
];
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
const { Region, Apartment, Room } = require('../models');
|
||||||
|
|
||||||
|
// 房间列表
|
||||||
|
const roomNumbers = [
|
||||||
|
'201', '202', '203', '205', '206',
|
||||||
|
'301', '302', '303', '305', '306',
|
||||||
|
'401', '402', '403', '405', '406',
|
||||||
|
'501', '502', '503', '505'
|
||||||
|
];
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
const { Region, Apartment, Room } = require('../models');
|
||||||
|
|
||||||
|
// 房间列表
|
||||||
|
const roomNumbers = [
|
||||||
|
'402', '403', '404', '405', '406', '407', '408', '409', '410', '411', '412', '413',
|
||||||
|
'501', '502', '503', '504', '505', '506', '507', '508', '509', '510', '511', '512', '513'
|
||||||
|
];
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
@ -0,0 +1,205 @@
|
||||||
|
const sequelize = require('./config/db');
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
|
||||||
|
// 定义 WaterBill 模型
|
||||||
|
const WaterBill = sequelize.define('WaterBill', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true
|
||||||
|
},
|
||||||
|
roomId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: 'rooms',
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
startReading: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
endReading: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
usage: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
unitPrice: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
amount: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: DataTypes.ENUM('unpaid', 'paid'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'unpaid'
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tableName: 'water_bills',
|
||||||
|
timestamps: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// 定义 ElectricityBill 模型
|
||||||
|
const ElectricityBill = sequelize.define('ElectricityBill', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true
|
||||||
|
},
|
||||||
|
roomId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: 'rooms',
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
startReading: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
endReading: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
usage: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
unitPrice: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
amount: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: DataTypes.ENUM('unpaid', 'paid'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'unpaid'
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tableName: 'electricity_bills',
|
||||||
|
timestamps: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// 定义 Rental 模型
|
||||||
|
const Rental = sequelize.define('Rental', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true
|
||||||
|
},
|
||||||
|
roomId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: 'rooms',
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tenantId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: 'tenants',
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
contractId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: 'contracts',
|
||||||
|
key: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
rent: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
deposit: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: DataTypes.ENUM('active', 'expired'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'active'
|
||||||
|
},
|
||||||
|
remark: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: true
|
||||||
|
},
|
||||||
|
createTime: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tableName: 'rentals',
|
||||||
|
timestamps: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// 同步数据库模型
|
||||||
|
async function syncDatabase() {
|
||||||
|
try {
|
||||||
|
console.log('开始同步数据库模型...');
|
||||||
|
// 同步 Rental 模型
|
||||||
|
await Rental.sync({ alter: true });
|
||||||
|
console.log('Rental 模型同步成功');
|
||||||
|
// 同步 WaterBill 模型
|
||||||
|
await WaterBill.sync({ alter: true });
|
||||||
|
console.log('WaterBill 模型同步成功');
|
||||||
|
// 同步 ElectricityBill 模型
|
||||||
|
await ElectricityBill.sync({ alter: true });
|
||||||
|
console.log('ElectricityBill 模型同步成功');
|
||||||
|
console.log('数据库模型同步成功');
|
||||||
|
process.exit(0);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('数据库模型同步失败:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行同步
|
||||||
|
syncDatabase();
|
||||||
Loading…
Reference in New Issue