diff --git a/server/CoreCms.Net.Web.Admin/Controllers/SQ/SQRoomPricingController.cs b/server/CoreCms.Net.Web.Admin/Controllers/SQ/SQRoomPricingController.cs
index d12c824..4aa71a0 100644
--- a/server/CoreCms.Net.Web.Admin/Controllers/SQ/SQRoomPricingController.cs
+++ b/server/CoreCms.Net.Web.Admin/Controllers/SQ/SQRoomPricingController.cs
@@ -17,6 +17,7 @@ using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.Entities.Expression;
using CoreCms.Net.Model.FromBody;
using CoreCms.Net.Model.ViewModels.UI;
+using CoreCms.Net.Model.ViewModels.SQ;
using CoreCms.Net.Utility.Extensions;
using CoreCms.Net.Utility.Helper;
using CoreCms.Net.Web.Admin.Infrastructure;
@@ -30,11 +31,14 @@ using NPOI.HSSF.UserModel;
using SqlSugar;
using System;
+using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
+using NLog;
+using AutoMapper;
namespace CoreCms.Net.Web.Admin.Controllers
{
@@ -50,16 +54,31 @@ namespace CoreCms.Net.Web.Admin.Controllers
{
private readonly IWebHostEnvironment _webHostEnvironment;
private readonly ISQRoomPricingServices _SQRoomPricingServices;
+ private readonly ISQRoomsServices _SQRoomsServices;
+ private readonly ISQReservationsServices _SQReservationsServices;
+ private readonly ISQReservationParticipantsServices _SQReservationParticipantsServices;
+ private readonly ICoreCmsUserServices _userServices;
+ private readonly IMapper _mapper;
///
/// 构造函数
///
public SQRoomPricingController(IWebHostEnvironment webHostEnvironment
, ISQRoomPricingServices SQRoomPricingServices
+ , ISQRoomsServices SQRoomsServices
+ , ISQReservationsServices SQReservationsServices
+ , ISQReservationParticipantsServices SQReservationParticipantsServices
+ , ICoreCmsUserServices userServices
+ , IMapper mapper
)
{
_webHostEnvironment = webHostEnvironment;
_SQRoomPricingServices = SQRoomPricingServices;
+ _SQRoomsServices = SQRoomsServices;
+ _SQReservationsServices = SQReservationsServices;
+ _SQReservationParticipantsServices = SQReservationParticipantsServices;
+ _userServices = userServices;
+ _mapper = mapper;
}
#region 获取列表============================================================
@@ -820,6 +839,265 @@ namespace CoreCms.Net.Web.Admin.Controllers
}
#endregion
+ #region 获取房间时段状态============================================================
+ // GET: Api/SQRoomPricing/GetRoomListWithSlots
+ ///
+ /// 获取房间列表及时段状态(用于日历视图)
+ ///
+ /// 日期
+ /// 是否只显示可用房间
+ /// 当前时段
+ ///
+ [HttpGet]
+ [AllowAnonymous]
+ [Description("获取房间列表及时段状态")]
+ public async Task GetRoomListWithSlots([FromQuery] string date, [FromQuery] bool showOnlyAvailable = false, [FromQuery] int? currentTimeSlot = null)
+ {
+ var jm = new AdminUiCallBack();
+
+ // 验证日期参数
+ if (string.IsNullOrEmpty(date))
+ {
+ jm.msg = "请提供日期参数";
+ return jm;
+ }
+
+ if (!DateTime.TryParse(date, out DateTime dateValue))
+ {
+ jm.msg = "日期格式不正确";
+ return jm;
+ }
+
+ // 调用服务获取数据
+ var result = await _SQRoomsServices.GetRoomListWithSlotsAsync(dateValue, showOnlyAvailable, currentTimeSlot);
+
+ jm.code = 0;
+ jm.msg = "获取成功";
+ jm.data = result;
+
+ return jm;
+ }
+ #endregion
+
+ #region 获取日期详情============================================================
+ // GET: Api/SQRoomPricing/GetDateDetails
+ ///
+ /// 获取指定日期和房间的详细信息(用于日历视图点击日期)
+ ///
+ /// 日期
+ /// 房间ID
+ ///
+ [HttpGet]
+ [AllowAnonymous]
+ [Description("获取日期详情")]
+ public async Task GetDateDetails([FromQuery] string date, [FromQuery] int roomId)
+ {
+ var jm = new AdminUiCallBack();
+
+ try
+ {
+ // 验证参数
+ if (string.IsNullOrEmpty(date))
+ {
+ jm.msg = "请提供日期参数";
+ return jm;
+ }
+
+ if (roomId <= 0)
+ {
+ jm.msg = "请提供房间ID";
+ return jm;
+ }
+
+ if (!DateTime.TryParse(date, out DateTime dateValue))
+ {
+ jm.msg = "日期格式不正确";
+ return jm;
+ }
+
+ // 获取房间信息
+ var room = await _SQRoomsServices.QueryByIdAsync(roomId);
+ if (room == null)
+ {
+ jm.msg = "房间不存在";
+ return jm;
+ }
+
+ // 获取该日期该房间的时段状态
+ var roomListWithSlots = await _SQRoomsServices.GetRoomListWithSlotsAsync(dateValue, false, null);
+ var roomData = roomListWithSlots?.FirstOrDefault(r => r.id == roomId);
+
+ // 获取该日期该房间的预约列表
+ var startTime = dateValue.Date;
+ var endTime = dateValue.Date.AddDays(1);
+ var reservations = await _SQReservationsServices.QueryListByClauseAsync(
+ p => p.room_id == roomId &&
+ p.start_time >= startTime &&
+ p.start_time < endTime &&
+ p.status != 4, // 排除已取消的预约
+ p => p.start_time,
+ OrderByType.Asc
+ );
+
+ // 查询所有预约的参与者
+ var reservationIds = reservations.Select(r => r.id).ToList();
+ List allParticipants = new List();
+ List userList = new List();
+
+ if (reservationIds.Any())
+ {
+ allParticipants = await _SQReservationParticipantsServices.QueryListByClauseAsync(
+ p => reservationIds.Contains(p.reservation_id),
+ p => p.role,
+ OrderByType.Desc,
+ true
+ );
+
+ // 查询所有参与者的用户信息
+ var userIds = allParticipants.Select(p => p.user_id).Distinct().ToList();
+ if (userIds.Any())
+ {
+ userList = await _userServices.QueryListByClauseAsync(
+ u => userIds.Contains(u.id),
+ u => u.id,
+ OrderByType.Asc,
+ true
+ );
+ }
+ }
+
+ // 处理时段数据,添加参与者头像和数量
+ var enhancedTimeSlots = new List