This commit is contained in:
zpc 2025-09-11 01:47:25 +08:00
parent ad6e888bfb
commit 2863559ba0
14 changed files with 270 additions and 35 deletions

View File

@ -12,15 +12,17 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics; using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Model.ViewModels.UI;
using SqlSugar; using SqlSugar;
namespace CoreCms.Net.IRepository namespace CoreCms.Net.IRepository
{ {
/// <summary> /// <summary>
/// 工厂接口 /// 工厂接口
/// </summary> /// </summary>
public interface ICoreCmsUserBlacklistRepository : IBaseRepository<CoreCmsUserBlacklist> public interface ICoreCmsUserBlacklistRepository : IBaseRepository<CoreCmsUserBlacklist>
@ -99,5 +101,7 @@ namespace CoreCms.Net.IRepository
Expression<Func<CoreCmsUserBlacklist, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1, Expression<Func<CoreCmsUserBlacklist, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false); int pageSize = 20, bool blUseNoLock = false);
} }
} }

View File

@ -59,5 +59,7 @@ namespace CoreCms.Net.IRepository
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
Task<List<StatisticsOut>> StatisticsOrder(int day); Task<List<StatisticsOut>> StatisticsOrder(int day);
} }
} }

View File

@ -12,14 +12,16 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics; using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Model.ViewModels.UI;
using SqlSugar; using SqlSugar;
namespace CoreCms.Net.IServices namespace CoreCms.Net.IServices
{ {
/// <summary> /// <summary>
/// 服务工厂接口 /// 服务工厂接口
/// </summary> /// </summary>
public interface ICoreCmsUserBlacklistServices : IBaseServices<CoreCmsUserBlacklist> public interface ICoreCmsUserBlacklistServices : IBaseServices<CoreCmsUserBlacklist>
@ -63,7 +65,7 @@ namespace CoreCms.Net.IServices
#endregion #endregion
#region ========================================================== #region ==========================================================
/// <summary> /// <summary>
@ -95,5 +97,22 @@ namespace CoreCms.Net.IServices
Expression<Func<CoreCmsUserBlacklist, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1, Expression<Func<CoreCmsUserBlacklist, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false); int pageSize = 20, bool blUseNoLock = false);
#endregion #endregion
/// <summary>
/// 获取用户拉黑名单
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
Task<List<int>> GetUserBlacklists(int userId);
/// <summary>
/// 用户拉黑某人
/// </summary>
/// <param name="userId"></param>
/// <param name="toUserId"></param>
/// <param name="type"></param>
/// <returns></returns>
Task<bool> UserBlackUser(int userId, int toUserId, int type);
} }
} }

View File

@ -131,5 +131,7 @@ namespace CoreCms.Net.IServices
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
Task<List<StatisticsOut>> StatisticsOrder(int day); Task<List<StatisticsOut>> StatisticsOrder(int day);
} }
} }

View File

@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoreCms.Net.Middlewares;
/// <summary>
/// 方法执行时间
/// </summary>
public class ExecutionTimeMiddleware(RequestDelegate _next)
{
public async Task Invoke(HttpContext context)
{
// 开始计时
var sw = Stopwatch.StartNew();
//在将响应标头发送到之前添加要调用的委托客户此处注册的回调按相反顺序运行。
context.Response.OnStarting(() =>
{
sw.Stop();
context.Response.Headers.TryAdd("X-Request-Duration", $"{sw.Elapsed.TotalMilliseconds} ms");
return Task.CompletedTask;
});
await _next(context);
}
}

View File

@ -11,6 +11,7 @@
***********************************************************************/ ***********************************************************************/
using CoreCms.Net.Core; using CoreCms.Net.Core;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
namespace CoreCms.Net.Middlewares namespace CoreCms.Net.Middlewares
@ -62,6 +63,15 @@ namespace CoreCms.Net.Middlewares
return app.UseMiddleware<IPLogMildd>(); return app.UseMiddleware<IPLogMildd>();
} }
/// <summary>
/// 接口执行时间中间件
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
public static IApplicationBuilder UseExecutionTimeMiddleware(this IApplicationBuilder app)
{
return app.UseMiddleware<ExecutionTimeMiddleware>();
}
/// <summary> /// <summary>
/// 用户访问接口日志中间件 /// 用户访问接口日志中间件

View File

@ -210,11 +210,6 @@ namespace CoreCms.Net.Model.Entities
/// 最大年龄限制0=不限 /// 最大年龄限制0=不限
/// </summary> /// </summary>
[Display(Name = "最大年龄限制0=不限")] [Display(Name = "最大年龄限制0=不限")]
public System.Int32? max_age { get; set; } public System.Int32? max_age { get; set; }
@ -222,11 +217,6 @@ namespace CoreCms.Net.Model.Entities
/// 鸽子费(保证金) /// 鸽子费(保证金)
/// </summary> /// </summary>
[Display(Name = "鸽子费(保证金)")] [Display(Name = "鸽子费(保证金)")]
public System.Decimal? deposit_fee { get; set; } public System.Decimal? deposit_fee { get; set; }

View File

@ -2,8 +2,11 @@
using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.Entities;
using SqlSugar;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -26,5 +29,67 @@ namespace CoreCms.Net.Model.ViewModels.SQ
/// 用户头像 /// 用户头像
/// </summary> /// </summary>
public string AvatarImage { get; set; } public string AvatarImage { get; set; }
/// <summary>
/// 用户是否拉黑 0否 1是
/// </summary>
public int UserBlackStatus { get; set; }
}
[AutoMap(typeof(SQReservationParticipants))]
public class SQReservationParticipantsApiDto
{
/// <summary>
/// 参与记录ID
/// </summary>
public System.Int32 id { get; set; }
/// <summary>
/// 预约ID
/// </summary>
public System.Int32 reservation_id { get; set; }
/// <summary>
/// 参与者ID关联用户表暂时占位
/// </summary>
public System.Int32 user_id { get; set; }
/// <summary>
/// 角色0=参与者1=发起者
/// </summary>
[Display(Name = "角色0=参与者1=发起者")]
public System.Int32 role { get; set; }
/// <summary>
/// 加入时间
/// </summary>
[Display(Name = "加入时间")]
public System.DateTime join_time { get; set; }
/// <summary>
/// 状态0正常1已退出
/// </summary>
[Display(Name = "状态0正常1已退出")]
public System.Int32 status { get; set; }
/// <summary>
/// 用户昵称
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 用户头像
/// </summary>
public string AvatarImage { get; set; }
/// <summary>
/// 用户是否拉黑 0否 1是
/// </summary>
public int UserBlackStatus { get; set; }
} }
} }

View File

@ -16,6 +16,12 @@ namespace CoreCms.Net.Model.ViewModels.SQ
{ {
public List<SQReservationParticipantsDto> Participants { get; set; } public List<SQReservationParticipantsDto> Participants { get; set; }
} }
[AutoMap(typeof(SQReservations))]
public class SQReservationsApiDto : SQReservations
{
public List<SQReservationParticipantsApiDto> Participants { get; set; }
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>

View File

@ -229,6 +229,7 @@ namespace CoreCms.Net.Repository
var list = new PageList<CoreCmsUserBlacklist>(page, pageIndex, pageSize, totalCount); var list = new PageList<CoreCmsUserBlacklist>(page, pageIndex, pageSize, totalCount);
return list; return list;
} }
#endregion #endregion

View File

@ -10,8 +10,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using CoreCms.Net.Caching.AutoMate.RedisCache;
using CoreCms.Net.Configuration; using CoreCms.Net.Configuration;
using CoreCms.Net.IRepository; using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork; using CoreCms.Net.IRepository.UnitOfWork;
@ -19,6 +22,7 @@ using CoreCms.Net.IServices;
using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics; using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Model.ViewModels.UI;
using SqlSugar; using SqlSugar;
@ -31,12 +35,15 @@ namespace CoreCms.Net.Services
{ {
private readonly ICoreCmsUserBlacklistRepository _dal; private readonly ICoreCmsUserBlacklistRepository _dal;
private readonly IUnitOfWork _unitOfWork; private readonly IUnitOfWork _unitOfWork;
private readonly IRedisOperationRepository _redisOperationRepository;
public CoreCmsUserBlacklistServices(IUnitOfWork unitOfWork, ICoreCmsUserBlacklistRepository dal) public CoreCmsUserBlacklistServices(IUnitOfWork unitOfWork, ICoreCmsUserBlacklistRepository dal,
IRedisOperationRepository redisOperationRepository)
{ {
this._dal = dal; this._dal = dal;
base.BaseDal = dal; base.BaseDal = dal;
_unitOfWork = unitOfWork; _unitOfWork = unitOfWork;
_redisOperationRepository = redisOperationRepository;
} }
#region ========================================================== #region ==========================================================
@ -91,6 +98,9 @@ namespace CoreCms.Net.Services
return await _dal.DeleteByIdsAsync(ids); return await _dal.DeleteByIdsAsync(ids);
} }
#endregion #endregion
#region ========================================================== #region ==========================================================
@ -114,7 +124,7 @@ namespace CoreCms.Net.Services
#endregion #endregion
#region #region
/// <summary> /// <summary>
/// 重写根据条件查询分页数据 /// 重写根据条件查询分页数据
/// </summary> /// </summary>
@ -131,6 +141,62 @@ namespace CoreCms.Net.Services
{ {
return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock); return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock);
} }
public async Task<List<int>> GetUserBlacklists(int userId)
{
if (userId == 0)
{
return new List<int>();
}
string key = $"user:black:{userId}";
var list = await _redisOperationRepository.Get<List<int>>(key);
if (list == null)
{
var userList = await _dal.QueryListByClauseAsync(it => it.UserId == userId);
if (userList.Count == 0)
{
list = new List<int>();
}
else
{
list = userList.Select(it => it.BlockedUserId).ToList();
}
await _redisOperationRepository.Set(key, list, TimeSpan.FromMinutes(60));
}
return list;
}
public async Task<bool> UserBlackUser(int userId, int toUserId, int type)
{
if (userId == 0)
{
return false;
}
if (type == 0)
{
CoreCmsUserBlacklist coreCmsUserBlacklist = new CoreCmsUserBlacklist()
{
UserId = userId,
CreatedTime = DateTime.Now,
BlockedUserId = toUserId,
Reason = "",
};
await _dal.InsertAsync(coreCmsUserBlacklist);
}
else
{
var bluser = await _dal.QueryByClauseAsync(it => it.UserId == userId && it.BlockedUserId == toUserId);
if (bluser != null)
{
await _dal.DeleteByIdAsync(bluser.Id);
}
}
string key = $"user:black:{userId}";
await _redisOperationRepository.Remove(key);
return true;
}
#endregion #endregion
} }

View File

@ -39,6 +39,7 @@ public class SQController : ControllerBase
private readonly ICoreCmsUserServices _userServices; private readonly ICoreCmsUserServices _userServices;
private readonly IHttpContextUser _user; private readonly IHttpContextUser _user;
private readonly SqlSugarScope _dbBase; private readonly SqlSugarScope _dbBase;
private readonly ICoreCmsUserBlacklistServices _coreCmsUserBlacklistServices;
/// <summary> /// <summary>
/// 构造函数 /// 构造函数
@ -53,6 +54,7 @@ public class SQController : ControllerBase
, ICoreCmsUserServices userServices , ICoreCmsUserServices userServices
, IHttpContextUser user , IHttpContextUser user
, IUnitOfWork unitOfWork , IUnitOfWork unitOfWork
, ICoreCmsUserBlacklistServices coreCmsUserBlacklistServices
) )
{ {
_webHostEnvironment = webHostEnvironment; _webHostEnvironment = webHostEnvironment;
@ -65,6 +67,7 @@ public class SQController : ControllerBase
_userServices = userServices; _userServices = userServices;
_user = user; _user = user;
_dbBase = unitOfWork.GetDbClient(); _dbBase = unitOfWork.GetDbClient();
_coreCmsUserBlacklistServices = coreCmsUserBlacklistServices;
} }
/// <summary> /// <summary>
@ -95,7 +98,7 @@ public class SQController : ControllerBase
/// <param name="pageSize"></param> /// <param name="pageSize"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<WebApiDto> GetReservationList([FromQuery] int pageIndex, [FromQuery] int pageSize = 20) public async Task<WebApiDto> GetReservationList([FromQuery] int pageIndex = 1, [FromQuery] int pageSize = 20)
{ {
var userId = _user.ID; var userId = _user.ID;
var now = DateTime.Now; var now = DateTime.Now;
@ -104,36 +107,63 @@ public class SQController : ControllerBase
where = where.And(it => it.end_time > now); where = where.And(it => it.end_time > now);
where = where.And(it => it.status < 2); where = where.And(it => it.status < 2);
var list = await _SQReservationsServices.QueryPageAsync(where, it => it.start_time, OrderByType.Asc, pageIndex, pageSize, true); var list = await _SQReservationsServices.QueryPageAsync(where, it => it.start_time, OrderByType.Asc, pageIndex, pageSize, true);
var pageList = _mapper.Map<List<SQReservationsDto>>(list); var pageList = _mapper.Map<List<SQReservationsApiDto>>(list);
var rIds = list.Select(it => it.id).ToList(); var rIds = list.Select(it => it.id).ToList();
if (rIds != null && rIds.Count > 0) if (rIds != null && rIds.Count > 0)
{ {
var participants = await _SQReservationParticipantsServices.QueryListByClauseAsync(it => rIds.Contains(it.reservation_id), "", true); string sqlWhere = string.Join(",", rIds);
List<CoreCmsUser> userList = new List<CoreCmsUser>(); 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) if (participants != null && participants.Count > 0)
{ {
var userIds = participants.Select(it => it.user_id).ToList(); var userBlacklist = new List<int>();
userList = await _userServices.QueryListByClauseAsync(it => userIds.Contains(it.id), "", true); //如果用户登录了
} if (userId > 0)
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)
userBlacklist = await _coreCmsUserBlacklistServices.GetUserBlacklists(userId);
//并且用户有黑名单数据
if (userBlacklist.Count > 0)
{ {
var u = userList.FirstOrDefault(it => it.id == p.user_id); //查找并修改黑名单用户
if (u != null) foreach (var participant in participants.Where(it => userBlacklist.Contains(it.user_id)))
{ {
p.UserName = u.nickName; participant.UserBlackStatus = 1;
p.AvatarImage = u.avatarImage;
} }
} }
} }
item.Participants = dto; 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() return new WebApiDto()
{ {

View File

@ -762,7 +762,7 @@
预约接口 预约接口
</summary> </summary>
</member> </member>
<member name="M:CoreCms.Net.Web.WebApi.Controllers.SQController.#ctor(Microsoft.AspNetCore.Hosting.IWebHostEnvironment,CoreCms.Net.IServices.ISQReservationsServices,CoreCms.Net.IServices.ISQRoomsServices,CoreCms.Net.IServices.ISysDictionaryServices,CoreCms.Net.IServices.ISysDictionaryDataServices,CoreCms.Net.IServices.ISQReservationParticipantsServices,AutoMapper.IMapper,CoreCms.Net.IServices.ICoreCmsUserServices,CoreCms.Net.Auth.HttpContextUser.IHttpContextUser,CoreCms.Net.IRepository.UnitOfWork.IUnitOfWork)"> <member name="M:CoreCms.Net.Web.WebApi.Controllers.SQController.#ctor(Microsoft.AspNetCore.Hosting.IWebHostEnvironment,CoreCms.Net.IServices.ISQReservationsServices,CoreCms.Net.IServices.ISQRoomsServices,CoreCms.Net.IServices.ISysDictionaryServices,CoreCms.Net.IServices.ISysDictionaryDataServices,CoreCms.Net.IServices.ISQReservationParticipantsServices,AutoMapper.IMapper,CoreCms.Net.IServices.ICoreCmsUserServices,CoreCms.Net.Auth.HttpContextUser.IHttpContextUser,CoreCms.Net.IRepository.UnitOfWork.IUnitOfWork,CoreCms.Net.IServices.ICoreCmsUserBlacklistServices)">
<summary> <summary>
构造函数 构造函数
</summary> </summary>

View File

@ -1,7 +1,9 @@
using System; using System;
using System.Linq; using System.Linq;
using Autofac; using Autofac;
using Autofac.Extensions.DependencyInjection; using Autofac.Extensions.DependencyInjection;
using CoreCms.Net.Auth; using CoreCms.Net.Auth;
using CoreCms.Net.Configuration; using CoreCms.Net.Configuration;
using CoreCms.Net.Core.AutoFac; using CoreCms.Net.Core.AutoFac;
@ -15,11 +17,15 @@ using CoreCms.Net.Swagger;
using CoreCms.Net.Task; using CoreCms.Net.Task;
using CoreCms.Net.Web.WebApi.Infrastructure; using CoreCms.Net.Web.WebApi.Infrastructure;
using CoreCms.Net.WeChat.Service.Mediator; using CoreCms.Net.WeChat.Service.Mediator;
using Essensoft.Paylink.Alipay; using Essensoft.Paylink.Alipay;
using Essensoft.Paylink.WeChatPay; using Essensoft.Paylink.WeChatPay;
using Hangfire; using Hangfire;
using Hangfire.Dashboard.BasicAuthorization; using Hangfire.Dashboard.BasicAuthorization;
using MediatR; using MediatR;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.HttpOverrides;
@ -30,8 +36,10 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
using NLog.Web; using NLog.Web;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -151,6 +159,8 @@ app.UseRequestResponseLog();
app.UseRecordAccessLogsMildd(); app.UseRecordAccessLogsMildd();
// 记录ip请求 (注意开启权限,不然本地无法写入) // 记录ip请求 (注意开启权限,不然本地无法写入)
app.UseIpLogMildd(); app.UseIpLogMildd();
// 记录请求时间
app.UseExecutionTimeMiddleware();
// Swagger授权登录拦截 // Swagger授权登录拦截
app.UseSwaggerAuthorizedMildd(); app.UseSwaggerAuthorizedMildd();
//强制显示中文 //强制显示中文