2019-12-23 16:32:06 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text.Json.Serialization;
|
2024-12-23 20:26:21 +08:00
|
|
|
using SimApi.Helpers;
|
2019-12-23 16:32:06 +08:00
|
|
|
|
2024-03-23 07:29:43 +08:00
|
|
|
namespace SimApi.Communications;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 基础相应
|
|
|
|
|
/// </summary>
|
2024-04-16 06:29:21 +08:00
|
|
|
public class SimApiBaseResponse(int code = 200, string message = "成功")
|
2019-12-23 16:32:06 +08:00
|
|
|
{
|
2024-04-16 06:29:21 +08:00
|
|
|
public int Code { get; set; } = code;
|
|
|
|
|
public string Message { get; set; } = message;
|
|
|
|
|
|
2025-11-01 15:40:55 +08:00
|
|
|
public SimApiBaseResponse() : this(200, "成功")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 12:48:43 +08:00
|
|
|
/// <summary>
|
2024-03-23 07:29:43 +08:00
|
|
|
/// 默认错误代码对应提示信息
|
2020-01-06 12:48:43 +08:00
|
|
|
/// </summary>
|
2024-03-23 07:29:43 +08:00
|
|
|
private static readonly Dictionary<int, string> MsgBox = new()
|
2019-12-23 16:32:06 +08:00
|
|
|
{
|
2024-03-23 07:29:43 +08:00
|
|
|
{ 200, "成功" },
|
|
|
|
|
{ 204, "没有数据" },
|
|
|
|
|
{ 400, "参数错误" },
|
|
|
|
|
{ 401, "需要登录" },
|
|
|
|
|
{ 403, "无权访问" },
|
|
|
|
|
{ 404, "接口不存在" },
|
|
|
|
|
{ 500, "服务器错误" }
|
|
|
|
|
};
|
2019-12-23 16:32:06 +08:00
|
|
|
|
2024-04-16 06:29:21 +08:00
|
|
|
public SimApiBaseResponse(int code) : this(code, MsgBox.GetValueOrDefault(code, "未知错误"))
|
2024-03-23 07:29:43 +08:00
|
|
|
{
|
2019-12-23 16:32:06 +08:00
|
|
|
}
|
2020-01-06 12:48:43 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
2024-03-23 07:29:43 +08:00
|
|
|
/// 序列化为JSON字符串
|
2020-01-17 12:40:22 +08:00
|
|
|
/// </summary>
|
2024-03-23 07:29:43 +08:00
|
|
|
/// <returns></returns>
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2024-12-23 20:26:21 +08:00
|
|
|
return SimApiUtil.Json(this);
|
2024-03-23 07:29:43 +08:00
|
|
|
}
|
|
|
|
|
}
|
2020-01-17 12:40:22 +08:00
|
|
|
|
2024-03-23 07:29:43 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 动态内容分页
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
2024-04-16 06:57:56 +08:00
|
|
|
public class SimApiBasePageResponse<T>() : SimApiBaseResponse
|
2024-04-16 06:29:21 +08:00
|
|
|
{
|
2024-08-03 19:19:42 +08:00
|
|
|
public T? List { get; set; }
|
2024-04-16 06:29:21 +08:00
|
|
|
public int Page { get; set; } = 1;
|
|
|
|
|
public int Count { get; set; } = 20;
|
|
|
|
|
public int Total { get; set; }
|
2024-04-16 06:57:56 +08:00
|
|
|
|
|
|
|
|
public SimApiBasePageResponse(T list, int page, int count, int total) : this()
|
|
|
|
|
{
|
|
|
|
|
List = list;
|
|
|
|
|
Page = page;
|
|
|
|
|
Count = count;
|
|
|
|
|
Total = total;
|
|
|
|
|
}
|
2024-04-16 06:29:21 +08:00
|
|
|
}
|
2024-03-23 07:29:43 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 动态Data返回
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
2024-04-16 06:57:56 +08:00
|
|
|
public class SimApiBaseResponse<T>() : SimApiBaseResponse
|
2024-04-16 06:29:21 +08:00
|
|
|
{
|
2024-08-03 19:19:42 +08:00
|
|
|
public T? Data { get; set; }
|
2024-04-16 06:57:56 +08:00
|
|
|
|
|
|
|
|
public SimApiBaseResponse(T data) : this()
|
|
|
|
|
{
|
|
|
|
|
Data = data;
|
|
|
|
|
}
|
2024-04-16 06:29:21 +08:00
|
|
|
}
|