优化数据返回

This commit is contained in:
不做码农
2022-01-11 10:49:38 +08:00
parent 617b34c884
commit b1bd8f12bb
5 changed files with 21 additions and 18 deletions

View File

@@ -18,18 +18,18 @@ namespace ZR.Admin.WebApi.Controllers
public static string TIME_FORMAT_FULL = "yyyy-MM-dd HH:mm:ss";
public static string TIME_FORMAT_FULL_2 = "MM-dd HH:mm:ss";
/// <summary>
/// 返回成功封装
/// </summary>
/// <param name="data"></param>
/// <param name="timeFormatStr"></param>
/// <returns></returns>
protected IActionResult SUCCESS(object data, string timeFormatStr = "yyyy-MM-dd HH:mm:ss")
{
string jsonStr = GetJsonStr(GetApiResult(data != null ? ResultCode.SUCCESS : ResultCode.FAIL, data), timeFormatStr);
return Content(jsonStr, "application/json");
}
protected IActionResult ToResponse(ResultCode resultCode, object data = null)
{
string jsonStr = GetJsonStr(GetApiResult(resultCode, data), "");
return Content(jsonStr, "application/json");
}
/// <summary>
/// json输出带时间格式的
/// </summary>
@@ -42,6 +42,7 @@ namespace ZR.Admin.WebApi.Controllers
return Content(jsonStr, "application/json");
}
protected IActionResult ToResponse(long rows, string timeFormatStr = "yyyy-MM-dd HH:mm:ss")
{
string jsonStr = GetJsonStr(ToJson(rows), timeFormatStr);
@@ -49,6 +50,13 @@ namespace ZR.Admin.WebApi.Controllers
return Content(jsonStr, "application/json");
}
protected IActionResult ToResponse(ResultCode resultCode, string msg = "")
{
return ToResponse(GetApiResult(resultCode, msg));
}
#region
/// <summary>
/// 响应返回结果
/// </summary>
@@ -96,11 +104,7 @@ namespace ZR.Admin.WebApi.Controllers
return JsonConvert.SerializeObject(apiResult, Formatting.Indented, serializerSettings);
}
protected IActionResult CustomError(ResultCode resultCode, string msg = "")
{
return ToResponse(GetApiResult(resultCode, msg));
}
#endregion
/// <summary>
/// 导出Excel