diff --git a/controllers/statisticsController.js b/controllers/statisticsController.js index 20a755a..d5ad0f8 100644 --- a/controllers/statisticsController.js +++ b/controllers/statisticsController.js @@ -65,6 +65,7 @@ const getRoomStatusStatistics = async (req, res) => { // 初始化统计数据 let empty = 0; + let reserved = 0; let rented = 0; let soon_expire = 0; let expired = 0; @@ -75,6 +76,8 @@ const getRoomStatusStatistics = async (req, res) => { rooms.forEach(room => { if (room.status === 'empty') { empty++; + } else if (room.status === 'reserved') { + reserved++; } else if (room.status === 'rented') { rented++; // 统计附属状态 @@ -94,6 +97,7 @@ const getRoomStatusStatistics = async (req, res) => { const roomStatusStatistics = [ { status: '空房', count: empty }, + { status: '预订', count: reserved }, { status: '在租', count: rented }, { status: '即将到期', count: soon_expire }, { status: '到期', count: expired }, @@ -126,6 +130,7 @@ const getRegionHouseStatistics = async (req, res) => { const regionHouseStatistics = regions.map(region => { let empty = 0; + let reserved = 0; let rented = 0; let soon_expire = 0; let expired = 0; @@ -136,6 +141,8 @@ const getRegionHouseStatistics = async (req, res) => { apartment.Rooms.forEach(room => { if (room.status === 'empty') { empty++; + } else if (room.status === 'reserved') { + reserved++; } else if (room.status === 'rented') { rented++; // 统计附属状态 @@ -157,12 +164,13 @@ const getRegionHouseStatistics = async (req, res) => { return { region: region.name, empty, + reserved, rented, soon_expire, expired, cleaning, maintenance, - total: empty + rented + total: empty + reserved + rented }; }); @@ -194,6 +202,7 @@ const getRegionApartmentHouseStatistics = async (req, res) => { regions.forEach(region => { region.Apartments.forEach(apartment => { let empty = 0; + let reserved = 0; let rented = 0; let soon_expire = 0; let expired = 0; @@ -203,6 +212,8 @@ const getRegionApartmentHouseStatistics = async (req, res) => { apartment.Rooms.forEach(room => { if (room.status === 'empty') { empty++; + } else if (room.status === 'reserved') { + reserved++; } else if (room.status === 'rented') { rented++; // 统计附属状态 @@ -224,12 +235,13 @@ const getRegionApartmentHouseStatistics = async (req, res) => { region: region.name, apartment: apartment.name, empty, + reserved, rented, soon_expire, expired, cleaning, maintenance, - total: empty + rented + total: empty + reserved + rented }); }); }); @@ -247,11 +259,12 @@ const getDashboardStatistics = async (req, res) => { const { Region, Apartment, Room, WaterBill, Rental } = require('../models'); // 并行查询所有统计数据 - const [regionCount, apartmentCount, roomCount, emptyRoomCount, rentedRoomCount, soonExpireRoomCount, expiredRoomCount, collectedRentAmount, collectedWaterAmount] = await Promise.all([ + const [regionCount, apartmentCount, roomCount, emptyRoomCount, reservedRoomCount, rentedRoomCount, soonExpireRoomCount, expiredRoomCount, collectedRentAmount, collectedWaterAmount] = await Promise.all([ Region.count({ where: { isDeleted: 0 } }), Apartment.count({ where: { isDeleted: 0 } }), Room.count({ where: { isDeleted: 0 } }), Room.count({ where: { status: 'empty', isDeleted: 0 } }), + Room.count({ where: { status: 'reserved', isDeleted: 0 } }), Room.count({ where: { status: 'rented', isDeleted: 0 } }), Room.count({ where: { status: 'rented', subStatus: 'soon_expire', isDeleted: 0 } }), Room.count({ where: { status: 'rented', subStatus: 'expired', isDeleted: 0 } }), @@ -267,6 +280,7 @@ const getDashboardStatistics = async (req, res) => { apartmentCount, roomCount, emptyRoomCount, + reservedRoomCount, rentedRoomCount, soonExpireRoomCount, expiredRoomCount, diff --git a/models/Room.js b/models/Room.js index 58c0295..5029ef8 100644 --- a/models/Room.js +++ b/models/Room.js @@ -39,10 +39,10 @@ const Room = sequelize.define('Room', { comment: '年租金' }, status: { - type: DataTypes.ENUM('empty', 'rented'), + type: DataTypes.ENUM('empty', 'reserved', 'rented'), allowNull: false, defaultValue: 'empty', - comment: '房间状态(empty:空房,rented:在租)' + comment: '房间状态(empty:空房,reserved:预订,rented:在租)' }, subStatus: { type: DataTypes.ENUM('normal', 'soon_expire', 'expired'),