193 lines
7.3 KiB
C#
193 lines
7.3 KiB
C#
using AutoMapper;
|
||
|
||
using CoreCms.Net.Auth.HttpContextUser;
|
||
using CoreCms.Net.IRepository.UnitOfWork;
|
||
using CoreCms.Net.IServices;
|
||
using CoreCms.Net.Model.Entities;
|
||
using CoreCms.Net.Model.Entities.Expression;
|
||
using CoreCms.Net.Model.ViewModels.SQ;
|
||
using CoreCms.Net.Model.ViewModels.UI;
|
||
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Hosting;
|
||
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
|
||
using SqlSugar;
|
||
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace CoreCms.Net.Web.WebApi.Controllers;
|
||
|
||
/// <summary>
|
||
/// 预约接口
|
||
/// </summary>
|
||
[Route("api/[controller]/[action]")]
|
||
[ApiController]
|
||
public class SQController : ControllerBase
|
||
{
|
||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||
private readonly ISQReservationsServices _SQReservationsServices;
|
||
private readonly ISQRoomsServices _SQRoomsServices;
|
||
private readonly ISysDictionaryDataServices _sysDictionaryDataServices;
|
||
private readonly ISysDictionaryServices _sysDictionaryServices;
|
||
private readonly ISQReservationParticipantsServices _SQReservationParticipantsServices;
|
||
private readonly IMapper _mapper;
|
||
private readonly ICoreCmsUserServices _userServices;
|
||
private readonly IHttpContextUser _user;
|
||
private readonly SqlSugarScope _dbBase;
|
||
private readonly ICoreCmsUserBlacklistServices _coreCmsUserBlacklistServices;
|
||
|
||
/// <summary>
|
||
/// 构造函数
|
||
///</summary>
|
||
public SQController(IWebHostEnvironment webHostEnvironment
|
||
, ISQReservationsServices SQReservationsServices
|
||
, ISQRoomsServices SQRoomsServices
|
||
, ISysDictionaryServices sysDictionaryServices
|
||
, ISysDictionaryDataServices sysDictionaryDataServices
|
||
, ISQReservationParticipantsServices sQReservationParticipantsServices
|
||
, IMapper mapper
|
||
, ICoreCmsUserServices userServices
|
||
, IHttpContextUser user
|
||
, IUnitOfWork unitOfWork
|
||
, ICoreCmsUserBlacklistServices coreCmsUserBlacklistServices
|
||
)
|
||
{
|
||
_webHostEnvironment = webHostEnvironment;
|
||
_SQReservationsServices = SQReservationsServices;
|
||
_SQRoomsServices = SQRoomsServices;
|
||
_sysDictionaryServices = sysDictionaryServices;
|
||
_sysDictionaryDataServices = sysDictionaryDataServices;
|
||
_SQReservationParticipantsServices = sQReservationParticipantsServices;
|
||
_mapper = mapper;
|
||
_userServices = userServices;
|
||
_user = user;
|
||
_dbBase = unitOfWork.GetDbClient();
|
||
_coreCmsUserBlacklistServices = coreCmsUserBlacklistServices;
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="type">1发起者,0参与者</param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
[Authorize]
|
||
public async Task<WebApiDto> GetMyReservation([FromQuery] int type = 0)
|
||
{
|
||
var userId = _user.ID;
|
||
|
||
//var list = await _SQReservationsServices.GetMyReservation(userId);
|
||
var list = await _dbBase.Ado.SqlQueryAsync<SQReservationsMyDto>($"select r.*, p.status pstatus,p.join_time, p.quit_time ,p.is_refund from SQReservationParticipants p inner join SQReservations r on p.reservation_id=r.id where p.user_id={userId} and p.role={type}");
|
||
//SQReservationsMyDto
|
||
return new WebApiDto()
|
||
{
|
||
Data = list,
|
||
Code = 0,
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="pageIndex"></param>
|
||
/// <param name="pageSize"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public async Task<WebApiDto> GetReservationList([FromQuery] int pageIndex = 1, [FromQuery] int pageSize = 20)
|
||
{
|
||
var userId = _user.ID;
|
||
var now = DateTime.Now;
|
||
|
||
var where = PredicateBuilder.True<SQReservations>();
|
||
where = where.And(it => it.end_time > now);
|
||
where = where.And(it => it.status < 2);
|
||
var list = await _SQReservationsServices.QueryPageAsync(where, it => it.start_time, OrderByType.Asc, pageIndex, pageSize, true);
|
||
var pageList = _mapper.Map<List<SQReservationsApiDto>>(list);
|
||
var rIds = list.Select(it => it.id).ToList();
|
||
if (rIds != null && rIds.Count > 0)
|
||
{
|
||
string sqlWhere = string.Join(",", rIds);
|
||
var participants = await _dbBase.Ado.SqlQueryAsync<SQReservationParticipantsApiDto>($"select p.id,p.reservation_id,p.status,p.join_time,p.user_id, p.role,u.nickName UserName,u.avatarImage AvatarImage from SQReservationParticipants p inner join CoreCmsUser u on p.user_id=u.id where p.status=0 and p.reservation_id in ({sqlWhere})");
|
||
if (participants != null && participants.Count > 0)
|
||
{
|
||
var userBlacklist = new List<int>();
|
||
//如果用户登录了
|
||
if (userId > 0)
|
||
{
|
||
|
||
userBlacklist = await _coreCmsUserBlacklistServices.GetUserBlacklists(userId);
|
||
//并且用户有黑名单数据
|
||
if (userBlacklist.Count > 0)
|
||
{
|
||
//查找并修改黑名单用户
|
||
foreach (var participant in participants.Where(it => userBlacklist.Contains(it.user_id)))
|
||
{
|
||
participant.UserBlackStatus = 1;
|
||
}
|
||
}
|
||
}
|
||
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 dto = _mapper.Map<List<SQReservationParticipantsApiDto>>(temp);
|
||
item.Participants = dto;
|
||
}
|
||
}
|
||
//var participants = await _SQReservationParticipantsServices.QueryListByClauseAsync(it => rIds.Contains(it.reservation_id), "", true);
|
||
//List<CoreCmsUser> userList = new List<CoreCmsUser>();
|
||
//if (participants != null && participants.Count > 0)
|
||
//{
|
||
// var userIds = participants.Select(it => it.user_id).ToList();
|
||
// userList = await _userServices.QueryListByClauseAsync(it => userIds.Contains(it.id), "", true);
|
||
//}
|
||
//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 dto = _mapper.Map<List<SQReservationParticipantsDto>>(temp);
|
||
// if (userList != null && userList.Count > 0)
|
||
// {
|
||
// foreach (var p in dto)
|
||
// {
|
||
// var u = userList.FirstOrDefault(it => it.id == p.user_id);
|
||
// if (u != null)
|
||
// {
|
||
// p.UserName = u.nickName;
|
||
// p.AvatarImage = u.avatarImage;
|
||
// }
|
||
// }
|
||
|
||
// }
|
||
// item.Participants = dto;
|
||
//}
|
||
}
|
||
return new WebApiDto()
|
||
{
|
||
Data = pageList,
|
||
Code = 0,
|
||
Msg = "ok",
|
||
};
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public async Task<WebApiDto> GetReservationDetail([FromQuery] int id)
|
||
{
|
||
return new WebApiDto()
|
||
{
|
||
|
||
};
|
||
}
|
||
}
|