This commit is contained in:
zpc 2025-09-11 03:04:34 +08:00
parent 2863559ba0
commit 6c521672f5
3 changed files with 44 additions and 6 deletions

View File

@ -12,9 +12,11 @@ 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
@ -95,5 +97,13 @@ namespace CoreCms.Net.IServices
Expression<Func<SQRooms, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false);
#endregion
#region
/// <summary>
/// 获取所有数据
/// </summary>
/// <returns></returns>
Task<List<SQRooms>> GetRoomList();
#endregion
}
}

View File

@ -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 ==========================================================
@ -131,6 +136,22 @@ namespace CoreCms.Net.Services
{
return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public async Task<List<SQRooms>> GetRoomList()
{
var key = $"room:GetRoomList";
var list = await _redisOperationRepository.Get<List<SQRooms>>(key);
if (list == null)
{
list = await _dal.QueryAsync(true);
await _redisOperationRepository.Set(key, list, TimeSpan.FromSeconds(60));
}
return list;
}
#endregion
}

View File

@ -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<SQReservations>();
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<List<SQReservationParticipantsApiDto>>(temp);
item.Participants = dto;
}