using CommonUtil; using Microsoft.AspNetCore.Mvc; using System; namespace Link.Api.Controllers { /// /// 基类控制器 /// [Produces(TopConstants.CONTENT_TYPE_APPLICATION_JSON)] [Route(TopConstants.API_ROUTE)] public class BaseController : ControllerBase { private const string JSON_RPC = "2.0"; private const string ERROR_CODE = "-32006"; /// /// 无参构造函数 /// public BaseController() { } #region 统一返回方法 /// /// 成功返回 /// /// /// [NonAction] public IActionResult Success(T rtData) { return Ok(new { jsonrpc = JSON_RPC, id = Guid.NewGuid().ToString(), result = rtData }); } /// /// 成功返回分页 /// /// /// /// /// /// /// [NonAction] public IActionResult Success(T rtData, int currentPage, int pageSize, int totalCount) { return Ok(new { jsonrpc = JSON_RPC, id = Guid.NewGuid().ToString(), result = new TopPageResultDTO { PageNo = currentPage, TotalCount = totalCount, PageSize = pageSize, Data = rtData } }); } /// /// 返回错误 /// /// /// [NonAction] public IActionResult Error(string errMsg) { return Ok(new { jsonrpc = JSON_RPC, id = Guid.NewGuid().ToString(), error = new { code = ERROR_CODE, message = errMsg } }); } #endregion } }