feat:完成furion改造
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yi.Framework.Infrastructure.Data.Entities;
|
||||
using Yi.Framework.Infrastructure.Data.Filters;
|
||||
|
||||
namespace Yi.Framework.Infrastructure.Data
|
||||
{
|
||||
public static class DataFilterExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseDataFiterServer(this IApplicationBuilder builder)
|
||||
{
|
||||
return builder.UseMiddleware<DataFilterMiddleware>();
|
||||
}
|
||||
}
|
||||
|
||||
public class DataFilterMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly ILogger<DataFilterMiddleware> _logger;
|
||||
public DataFilterMiddleware(RequestDelegate next, ILoggerFactory loggerFactory)
|
||||
{
|
||||
_next = next;
|
||||
_logger = loggerFactory.CreateLogger<DataFilterMiddleware>();
|
||||
}
|
||||
public async Task InvokeAsync(HttpContext context, IDataFilter dataFilter)
|
||||
{
|
||||
//添加默认的过滤器
|
||||
dataFilter.AddFilter<ISoftDelete>(u => u.IsDeleted == false);
|
||||
//dataFilter.AddFilter<IMultiTenant>(u => u.TenantId == Guid.Empty);
|
||||
await _next(context);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Infrastructure.Data.Json
|
||||
{
|
||||
public class DateTimeJsonConverter : JsonConverter<DateTime>
|
||||
{
|
||||
private readonly string Format;
|
||||
public DateTimeJsonConverter(string format)
|
||||
{
|
||||
Format = format;
|
||||
}
|
||||
public override void Write(Utf8JsonWriter writer, DateTime date, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(date.ToString(Format));
|
||||
}
|
||||
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
return DateTime.ParseExact(reader.GetString(), Format, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Buffers.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Yi.Framework.Infrastructure.Data.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// 长整形转字符串
|
||||
/// </summary>
|
||||
public class LongToStringConverter : JsonConverter<long>
|
||||
{
|
||||
public override long Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
ReadOnlySpan<byte> span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
|
||||
if (Utf8Parser.TryParse(span, out long number, out int bytesConsumed) && span.Length == bytesConsumed)
|
||||
{
|
||||
return number;
|
||||
}
|
||||
|
||||
if (long.TryParse(reader.GetString(), out number))
|
||||
{
|
||||
return number;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return reader.GetInt64();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, long value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user