diff --git a/CoreCms.Net.IServices/SQ/ISQRoomsServices.cs b/CoreCms.Net.IServices/SQ/ISQRoomsServices.cs index 9dc3d67..cd53118 100644 --- a/CoreCms.Net.IServices/SQ/ISQRoomsServices.cs +++ b/CoreCms.Net.IServices/SQ/ISQRoomsServices.cs @@ -12,14 +12,16 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; + using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.ViewModels.Basics; using CoreCms.Net.Model.ViewModels.UI; + using SqlSugar; namespace CoreCms.Net.IServices { - /// + /// /// 房间表 服务工厂接口 /// public interface ISQRoomsServices : IBaseServices @@ -63,7 +65,7 @@ namespace CoreCms.Net.IServices #endregion - + #region 获取缓存的所有数据========================================================== /// @@ -95,5 +97,13 @@ namespace CoreCms.Net.IServices Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1, int pageSize = 20, bool blUseNoLock = false); #endregion + + #region 获取所有数据 + /// + /// 获取所有数据 + /// + /// + Task> GetRoomList(); + #endregion } } diff --git a/CoreCms.Net.Services/SQ/SQRoomsServices.cs b/CoreCms.Net.Services/SQ/SQRoomsServices.cs index 2cb6886..0320074 100644 --- a/CoreCms.Net.Services/SQ/SQRoomsServices.cs +++ b/CoreCms.Net.Services/SQ/SQRoomsServices.cs @@ -12,6 +12,8 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; + +using CoreCms.Net.Caching.AutoMate.RedisCache; using CoreCms.Net.Configuration; using CoreCms.Net.IRepository; using CoreCms.Net.IRepository.UnitOfWork; @@ -19,6 +21,7 @@ using CoreCms.Net.IServices; using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.ViewModels.Basics; using CoreCms.Net.Model.ViewModels.UI; + using SqlSugar; @@ -31,12 +34,14 @@ namespace CoreCms.Net.Services { private readonly ISQRoomsRepository _dal; private readonly IUnitOfWork _unitOfWork; - - public SQRoomsServices(IUnitOfWork unitOfWork, ISQRoomsRepository dal) + private readonly IRedisOperationRepository _redisOperationRepository; + public SQRoomsServices(IUnitOfWork unitOfWork, ISQRoomsRepository dal, + IRedisOperationRepository redisOperationRepository) { this._dal = dal; base.BaseDal = dal; _unitOfWork = unitOfWork; + _redisOperationRepository = redisOperationRepository; } #region 实现重写增删改查操作========================================================== @@ -114,7 +119,7 @@ namespace CoreCms.Net.Services #endregion - #region 重写根据条件查询分页数据 + #region 重写根据条件查询分页数据 /// /// 重写根据条件查询分页数据 /// @@ -131,6 +136,22 @@ namespace CoreCms.Net.Services { return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock); } + + /// + /// + /// + /// + public async Task> GetRoomList() + { + var key = $"room:GetRoomList"; + var list = await _redisOperationRepository.Get>(key); + if (list == null) + { + list = await _dal.QueryAsync(true); + await _redisOperationRepository.Set(key, list, TimeSpan.FromSeconds(60)); + } + return list; + } #endregion } diff --git a/CoreCms.Net.Web.WebApi/Controllers/SQController.cs b/CoreCms.Net.Web.WebApi/Controllers/SQController.cs index 6a170f4..9ebeb82 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/SQController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/SQController.cs @@ -7,6 +7,7 @@ using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.Entities.Expression; using CoreCms.Net.Model.ViewModels.SQ; using CoreCms.Net.Model.ViewModels.UI; +using CoreCms.Net.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Hosting; @@ -102,7 +103,7 @@ public class SQController : ControllerBase { var userId = _user.ID; var now = DateTime.Now; - + var roomList = await _SQRoomsServices.GetRoomList(); var where = PredicateBuilder.True(); where = where.And(it => it.end_time > now); where = where.And(it => it.status < 2); @@ -134,6 +135,12 @@ public class SQController : ControllerBase foreach (var item in pageList) { var temp = participants.Where(it => it.reservation_id == item.id).OrderBy(it => it.role).ThenBy(it => it.status).ToList(); + var room = roomList.Find(it => it.id == item.room_id); + if (room != null) + { + item.room_name = $"{room.name} {room.price_per_hour}/小时 {room.capacity}/人数"; + + } var dto = _mapper.Map>(temp); item.Participants = dto; }