using AutoMapper;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.ViewModels.SQ;
using Kdbndp.KingbaseTypes;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinUserInfoBatchGetRequest.Types;
namespace CoreCms.Net.Services.SQ
{
public static class SQServices
{
///
///
///
///
///
public static async Task> LoadSQReservationParticipantsApiDtoId(List rIds, int userId, SqlSugarScope _dbBase, ICoreCmsUserBlacklistServices _coreCmsUserBlacklistServices)
{
if (rIds != null && rIds.Count > 0)
{
string sqlWhere = string.Join(",", rIds);
var participants = await _dbBase.Ado.SqlQueryAsync($"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();
//如果用户登录了
userBlacklist = await _coreCmsUserBlacklistServices.GetUserBlacklists(userId);
//并且用户有黑名单数据
if (userBlacklist.Count > 0)
{
//查找并修改黑名单用户
foreach (var participant in participants.Where(it => userBlacklist.Contains(it.user_id)))
{
participant.UserBlackStatus = 1;
}
}
}
return participants;
}
return new List();
}
///
/// 加载组局参与者信息
///
/// 预约信息
/// 当前用户
///
///
///
///
public static async Task LoadSQReservationParticipantsApiDto(this List list, int userId, SqlSugarScope _dbBase, ICoreCmsUserBlacklistServices _coreCmsUserBlacklistServices, IMapper _mapper)
{
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($"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)
{
if (userId > 0)
{
var userBlacklist = new List();
//如果用户登录了
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 list)
{
var temp = participants.Where(it => it.reservation_id == item.id).OrderBy(it => it.role).ThenBy(it => it.status).ToList();
var dto = _mapper.Map>(temp);
item.Participants = dto;
}
}
}
return true;
}
}
}