121 lines
4.2 KiB
C#
121 lines
4.2 KiB
C#
using Learun.Loger;
|
||
using Learun.Util;
|
||
using Learun.Util.Operat;
|
||
using System.Web.Http;
|
||
using System.Web.Mvc;
|
||
|
||
namespace Learun.Application.Web
|
||
{
|
||
/// <summary>
|
||
/// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
|
||
/// Copyright (c) 2013-2018 Hexagon PPM
|
||
/// 创建人:-框架开发组
|
||
/// 日 期:2017.03.08
|
||
/// 描 述:基础控制器
|
||
/// </summary>
|
||
[HandlerAppLogin(FilterMode.Enforce, true)]
|
||
public abstract class ApiControllerBase : ApiController
|
||
{
|
||
#region 日志操作
|
||
/// <summary>
|
||
/// 日志对象实体
|
||
/// </summary>
|
||
private Log _logger;
|
||
/// <summary>
|
||
/// 日志操作
|
||
/// </summary>
|
||
public Log Logger
|
||
{
|
||
get { return _logger ?? (_logger = LogFactory.GetLogger(this.GetType().ToString())); }
|
||
}
|
||
#endregion
|
||
|
||
#region 请求响应
|
||
/// <summary>
|
||
/// 返回成功消息
|
||
/// </summary>
|
||
/// <param name="data">数据</param>
|
||
/// <returns></returns>
|
||
protected virtual IHttpActionResult ToJsonResult(object data)
|
||
{
|
||
return Json(data);
|
||
}
|
||
/// <summary>
|
||
/// 返回成功消息
|
||
/// </summary>
|
||
/// <param name="info">消息</param>
|
||
/// <returns></returns>
|
||
protected virtual IHttpActionResult Success(string info)
|
||
{
|
||
return Json(new ResParameter { code = ResponseCode.success, info = info, data = new object { } }.ToJson());
|
||
}
|
||
/// <summary>
|
||
/// 返回成功消息
|
||
/// </summary>
|
||
/// <param name="data">数据</param>
|
||
/// <returns></returns>
|
||
protected virtual IHttpActionResult SuccessString(string data)
|
||
{
|
||
return Json(new ResParameter { code = ResponseCode.success, info = "响应成功", data = data }.ToJson());
|
||
}
|
||
/// <summary>
|
||
/// 返回成功数据
|
||
/// </summary>
|
||
/// <param name="data">数据</param>
|
||
/// <returns></returns>
|
||
protected virtual IHttpActionResult Success(object data)
|
||
{
|
||
return Json(new ResParameter { code = ResponseCode.success, info = "响应成功", data = data }.ToJson());
|
||
}
|
||
/// <summary>
|
||
/// 返回成功消息
|
||
/// </summary>
|
||
/// <param name="info">消息</param>
|
||
/// <param name="data">数据</param>
|
||
/// <returns></returns>
|
||
protected virtual IHttpActionResult Success(string info, object data)
|
||
{
|
||
return Json(new ResParameter { code = ResponseCode.success, info = info, data = data }.ToJson());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 带操作日志
|
||
/// </summary>
|
||
/// <param name="info"></param>
|
||
/// <returns></returns>
|
||
protected virtual IHttpActionResult Success(string info, string title, OperationType type, string keyValue, string content)
|
||
{
|
||
OperateLogModel operateLogModel = new OperateLogModel();
|
||
operateLogModel.title = title;
|
||
operateLogModel.type = type;
|
||
operateLogModel.url = (string)WebHelper.GetHttpItems("currentUrl");
|
||
operateLogModel.sourceObjectId = keyValue;
|
||
operateLogModel.sourceContentJson = content;
|
||
|
||
OperatorHelper.Instance.WriteOperateLog(operateLogModel);
|
||
|
||
return Json(new ResParameter { code = ResponseCode.success, info = info, data = new object { } }.ToJson());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 返回失败消息
|
||
/// </summary>
|
||
/// <param name="info">消息</param>
|
||
/// <returns></returns>
|
||
protected virtual IHttpActionResult Fail(string info)
|
||
{
|
||
return Json(new ResParameter { code = ResponseCode.fail, info = info }.ToJson());
|
||
}
|
||
/// <summary>
|
||
/// 返回失败消息
|
||
/// </summary>
|
||
/// <param name="info">消息</param>
|
||
/// <param name="data">消息</param>
|
||
/// <returns></returns>
|
||
protected virtual IHttpActionResult Fail(string info, object data)
|
||
{
|
||
return Json(new ResParameter { code = ResponseCode.fail, info = info, data = data }.ToJson());
|
||
}
|
||
#endregion
|
||
}
|
||
} |