2019-12-23 16:32:06 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
|
2020-08-05 15:29:56 +08:00
|
|
|
namespace SimApi.Communications
|
2019-12-23 16:32:06 +08:00
|
|
|
{
|
2020-01-06 12:48:43 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 基础相应
|
|
|
|
|
/// </summary>
|
2023-03-28 06:33:48 +08:00
|
|
|
public record SimApiBaseResponse(int Code = 200, string Message = "成功")
|
2019-12-23 16:32:06 +08:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 默认错误代码对应提示信息
|
|
|
|
|
/// </summary>
|
2023-03-28 06:33:48 +08:00
|
|
|
private static readonly Dictionary<int, string> MsgBox = new()
|
2019-12-23 16:32:06 +08:00
|
|
|
{
|
2023-03-28 06:33:48 +08:00
|
|
|
{
|
|
|
|
|
200, "成功"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
204, "没有数据"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
400, "参数错误"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
401, "需要登录"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
403, "无权访问"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
404, "接口不存在"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
500, "服务器错误"
|
|
|
|
|
}
|
2019-12-23 16:32:06 +08:00
|
|
|
};
|
|
|
|
|
|
2023-03-28 06:33:48 +08:00
|
|
|
public SimApiBaseResponse(int code) : this(code, MsgBox.ContainsKey(code) ? MsgBox[code] : "未知错误")
|
2019-12-23 16:32:06 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 序列化为JSON字符串
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return JsonSerializer.Serialize(this, new JsonSerializerOptions
|
|
|
|
|
{
|
|
|
|
|
IgnoreReadOnlyProperties = true,
|
|
|
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
2023-03-28 06:33:48 +08:00
|
|
|
Converters =
|
|
|
|
|
{
|
|
|
|
|
new JsonStringEnumConverter()
|
|
|
|
|
}
|
2019-12-23 16:32:06 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-06 12:48:43 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
2020-01-17 12:40:22 +08:00
|
|
|
/// 动态内容分页
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
2023-03-28 06:33:48 +08:00
|
|
|
public record SimApiBasePageResponse<T>
|
|
|
|
|
(T List, int Page = 1, int Count = 1, int Total = 1, int Code = 200,
|
|
|
|
|
string Message = "成功") : SimApiBaseResponse(Code, Message);
|
2020-01-17 12:40:22 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 动态Data返回
|
2020-01-06 12:48:43 +08:00
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
2023-03-28 06:33:48 +08:00
|
|
|
public record SimApiBaseResponse<T>(T Data, int Code = 200, string Message = "成功") : SimApiBaseResponse(Code,
|
|
|
|
|
Message);
|
2019-12-23 16:32:06 +08:00
|
|
|
}
|