This commit is contained in:
parent
2950f34959
commit
2e8bddab4e
|
|
@ -80,7 +80,18 @@ const getAllRentals = async (req, res) => {
|
|||
// 先检查并更新租房状态
|
||||
await checkAndUpdateRentalStatus();
|
||||
|
||||
const { roomId, tenantName, status, page = 1, pageSize = 10 } = req.query;
|
||||
const {
|
||||
apartmentId,
|
||||
roomId,
|
||||
tenantName,
|
||||
status,
|
||||
startDateFrom,
|
||||
startDateTo,
|
||||
endDateFrom,
|
||||
endDateTo,
|
||||
page = 1,
|
||||
pageSize = 10
|
||||
} = req.query;
|
||||
|
||||
// 构建查询条件
|
||||
const where = { isDeleted: 0 };
|
||||
|
|
@ -93,12 +104,21 @@ const getAllRentals = async (req, res) => {
|
|||
if (tenantName) {
|
||||
where.tenantName = { [Op.like]: `%${tenantName}%` };
|
||||
}
|
||||
if (startDateFrom && startDateTo) {
|
||||
where.startDate = { [Op.between]: [new Date(startDateFrom), new Date(startDateTo)] };
|
||||
}
|
||||
if (endDateFrom && endDateTo) {
|
||||
where.endDate = { [Op.between]: [new Date(endDateFrom), new Date(endDateTo)] };
|
||||
}
|
||||
|
||||
// 构建包含关系
|
||||
const include = [
|
||||
{
|
||||
model: Room,
|
||||
where: { isDeleted: 0 },
|
||||
where: {
|
||||
isDeleted: 0,
|
||||
...(apartmentId ? { apartmentId } : {})
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Apartment,
|
||||
|
|
@ -291,7 +311,16 @@ const listRentals = async (req, res) => {
|
|||
// 先检查并更新租房状态
|
||||
await checkAndUpdateRentalStatus();
|
||||
|
||||
const { roomId, tenantName, status } = req.query;
|
||||
const {
|
||||
apartmentId,
|
||||
roomId,
|
||||
tenantName,
|
||||
status,
|
||||
startDateFrom,
|
||||
startDateTo,
|
||||
endDateFrom,
|
||||
endDateTo
|
||||
} = req.query;
|
||||
|
||||
// 构建查询条件
|
||||
const where = { isDeleted: 0 };
|
||||
|
|
@ -304,12 +333,21 @@ const listRentals = async (req, res) => {
|
|||
if (tenantName) {
|
||||
where.tenantName = { [Op.like]: `%${tenantName}%` };
|
||||
}
|
||||
if (startDateFrom && startDateTo) {
|
||||
where.startDate = { [Op.between]: [new Date(startDateFrom), new Date(startDateTo)] };
|
||||
}
|
||||
if (endDateFrom && endDateTo) {
|
||||
where.endDate = { [Op.between]: [new Date(endDateFrom), new Date(endDateTo)] };
|
||||
}
|
||||
|
||||
// 构建包含关系
|
||||
const include = [
|
||||
{
|
||||
model: Room,
|
||||
where: { isDeleted: 0 },
|
||||
where: {
|
||||
isDeleted: 0,
|
||||
...(apartmentId ? { apartmentId } : {})
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Apartment,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,15 @@ const formatWaterBillData = (bill) => {
|
|||
// 获取所有水费记录(支持搜索和分页)
|
||||
const getAllWaterBills = async (req, res) => {
|
||||
try {
|
||||
const { roomId, status, startDate, endDate, page = 1, pageSize = 10 } = req.query;
|
||||
const {
|
||||
apartmentId,
|
||||
roomId,
|
||||
status,
|
||||
startDateFrom,
|
||||
endDateTo,
|
||||
page = 1,
|
||||
pageSize = 10
|
||||
} = req.query;
|
||||
|
||||
// 构建查询条件
|
||||
const where = { isDeleted: 0 };
|
||||
|
|
@ -44,12 +52,21 @@ const getAllWaterBills = async (req, res) => {
|
|||
if (status) {
|
||||
where.status = status;
|
||||
}
|
||||
if (startDate) {
|
||||
where.startDate = { [Op.gte]: new Date(startDate) };
|
||||
if (startDateFrom && endDateTo) {
|
||||
where.startDate = { [Op.gte]: new Date(startDateFrom) };
|
||||
where.endDate = { [Op.lte]: new Date(endDateTo) };
|
||||
}
|
||||
if (endDate) {
|
||||
where.endDate = { [Op.lte]: new Date(endDate) };
|
||||
|
||||
// 构建包含关系
|
||||
const include = [
|
||||
{
|
||||
model: Room,
|
||||
where: {
|
||||
isDeleted: 0,
|
||||
...(apartmentId ? { apartmentId } : {})
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
// 计算偏移量
|
||||
const offset = (page - 1) * pageSize;
|
||||
|
|
@ -57,12 +74,7 @@ const getAllWaterBills = async (req, res) => {
|
|||
// 查询水费数据
|
||||
const { count, rows } = await WaterBill.findAndCountAll({
|
||||
where,
|
||||
include: [
|
||||
{
|
||||
model: Room,
|
||||
where: { isDeleted: 0 }
|
||||
}
|
||||
],
|
||||
include,
|
||||
limit: parseInt(pageSize),
|
||||
offset: parseInt(offset),
|
||||
order: [['createTime', 'DESC']] // 按创建时间倒序排序
|
||||
|
|
@ -192,7 +204,13 @@ const deleteWaterBill = async (req, res) => {
|
|||
// 获取所有水费记录(不分页)
|
||||
const listWaterBills = async (req, res) => {
|
||||
try {
|
||||
const { roomId, status, startDate, endDate } = req.query;
|
||||
const {
|
||||
apartmentId,
|
||||
roomId,
|
||||
status,
|
||||
startDateFrom,
|
||||
endDateTo
|
||||
} = req.query;
|
||||
|
||||
// 构建查询条件
|
||||
const where = { isDeleted: 0 };
|
||||
|
|
@ -202,22 +220,26 @@ const listWaterBills = async (req, res) => {
|
|||
if (status) {
|
||||
where.status = status;
|
||||
}
|
||||
if (startDate) {
|
||||
where.startDate = { [Op.gte]: new Date(startDate) };
|
||||
if (startDateFrom && endDateTo) {
|
||||
where.startDate = { [Op.gte]: new Date(startDateFrom) };
|
||||
where.endDate = { [Op.lte]: new Date(endDateTo) };
|
||||
}
|
||||
if (endDate) {
|
||||
where.endDate = { [Op.lte]: new Date(endDate) };
|
||||
|
||||
// 构建包含关系
|
||||
const include = [
|
||||
{
|
||||
model: Room,
|
||||
where: {
|
||||
isDeleted: 0,
|
||||
...(apartmentId ? { apartmentId } : {})
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
// 查询水费数据
|
||||
const bills = await WaterBill.findAll({
|
||||
where,
|
||||
include: [
|
||||
{
|
||||
model: Room,
|
||||
where: { isDeleted: 0 }
|
||||
}
|
||||
],
|
||||
include,
|
||||
order: [['createTime', 'DESC']] // 按创建时间倒序排序
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue