⚡优化数据传输
This commit is contained in:
parent
ab98cf30c1
commit
c65952202a
48
Infrastructure/StringConverter.cs
Normal file
48
Infrastructure/StringConverter.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// Json任何类型读取到字符串属性
|
||||
/// 因为 System.Text.Json 必须严格遵守类型一致,当非字符串读取到字符属性时报错:
|
||||
/// The JSON value could not be converted to System.String.
|
||||
/// </summary>
|
||||
public class StringConverter : System.Text.Json.Serialization.JsonConverter<string>
|
||||
{
|
||||
public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
return reader.GetString();
|
||||
}
|
||||
else
|
||||
{
|
||||
//非字符类型,返回原生内容
|
||||
return GetRawPropertyValue(reader);
|
||||
}
|
||||
|
||||
throw new JsonException();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 非字符类型,返回原生内容
|
||||
/// </summary>
|
||||
/// <param name="jsonReader"></param>
|
||||
/// <returns></returns>
|
||||
private static string GetRawPropertyValue(Utf8JsonReader jsonReader)
|
||||
{
|
||||
ReadOnlySpan<byte> utf8Bytes = jsonReader.HasValueSequence ?
|
||||
jsonReader.ValueSequence.ToArray() :
|
||||
jsonReader.ValueSpan;
|
||||
return Encoding.UTF8.GetString(utf8Bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MiniExcelLibs;
|
||||
using SqlSugar;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
@ -146,7 +145,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
public IActionResult Remove(int userid = 0)
|
||||
{
|
||||
if (userid <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
|
||||
if (userid == 1) return ToResponse(Infrastructure.ResultCode.FAIL, "不能删除管理员账号");
|
||||
if (userid == 1) return ToResponse(ResultCode.FAIL, "不能删除管理员账号");
|
||||
int result = UserService.DeleteUser(userid);
|
||||
|
||||
return ToResponse(result);
|
||||
@ -159,7 +158,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
[HttpPut("resetPwd")]
|
||||
[Log(Title = "重置密码", BusinessType = BusinessType.UPDATE)]
|
||||
[ActionPermissionFilter(Permission = "system:user:resetPwd")]
|
||||
public IActionResult ResetPwd([FromBody] SysUser sysUser)
|
||||
public IActionResult ResetPwd([FromBody] SysUserDto sysUser)
|
||||
{
|
||||
//密码md5
|
||||
sysUser.Password = NETCore.Encrypt.EncryptProvider.Md5(sysUser.Password);
|
||||
|
||||
@ -83,6 +83,7 @@ builder.Services.AddMvc(options =>
|
||||
options.JsonSerializerOptions.WriteIndented = true;
|
||||
options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeNullConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new Infrastructure.StringConverter());
|
||||
});
|
||||
|
||||
builder.Services.AddSwaggerConfig();
|
||||
|
||||
@ -14,6 +14,7 @@ namespace ZR.Model.System.Dto
|
||||
/// 用户性别(0男 1女 2未知)
|
||||
/// </summary>
|
||||
public int Sex { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
|
||||
public class SysUserQueryDto
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user