using CommonUtil;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading.Tasks;
|
|
namespace Api.Operater.Controllers
|
{
|
public class BaseController : ControllerBase
|
{
|
|
#region 统一返回方法
|
|
/// <summary>
|
/// 成功返回
|
/// </summary>
|
/// <param name="rtData"></param>
|
/// <returns></returns>
|
[NonAction]
|
public IActionResult Success<T>(T rtData)
|
{
|
return Ok(new
|
{
|
success = true,
|
result = rtData
|
});
|
}
|
|
|
/// <summary>
|
/// 成功返回分页
|
/// </summary>
|
/// <typeparam name="T"></typeparam>
|
/// <param name="rtData"></param>
|
/// <param name="currentPage"></param>
|
/// <param name="pageSize"></param>
|
/// <param name="totalCount"></param>
|
/// <returns></returns>
|
[NonAction]
|
public IActionResult Success<T>(T rtData, int currentPage, int pageSize, int totalCount)
|
{
|
return Ok(new
|
{
|
success = true,
|
result = new TopPageResultDTO<T>
|
{
|
PageNo = currentPage,
|
TotalCount = totalCount,
|
PageSize = pageSize,
|
Data = rtData
|
}
|
});
|
}
|
|
|
/// <summary>
|
/// 返回错误
|
/// </summary>
|
/// <param name="errMsg"></param>
|
/// <returns></returns>
|
[NonAction]
|
public IActionResult Error(string errMsg)
|
{
|
|
return Ok(new
|
{
|
success = false,
|
error = new
|
{
|
code = "-32006",
|
message = errMsg
|
}
|
});
|
}
|
|
#endregion
|
}
|
}
|