using Learun.Application.TwoDevelopment.ZZDT_EC;
using Learun.Loger;
using Learun.Util;
using Learun.Util.Operat;
using Newtonsoft.Json;
using System.Web.Http;
using System.Web.Http.Results;
using System.Web.Mvc;
namespace Learun.Application.Web
{
///
/// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
/// Copyright (c) 2013-2018 Hexagon PPM
/// 创建人:-框架开发组
/// 日 期:2017.03.08
/// 描 述:基础控制器。写了一些自己封装的返回结果
///
[HandlerApiLogin(FilterMode.Enforce)]
//API接口接收参数日志,用的时候取消注释
[LogActionFilter]
//[TimingActionFilter]
public abstract class WebApiControllerBase : ApiController
{
///
/// 重写
///
///
///
///
protected new JsonResult Json(T content)
{
var SET = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings;
SET.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;//25 09 03,getbreaker,避免循环引用 remoteCB
return Json(content, SET, System.Text.Encoding.UTF8);
}
#region 日志操作
///
/// 日志对象实体
///
private Log _logger;
///
/// 日志操作
///
public Log Logger
{
get { return _logger ?? (_logger = LogFactory.GetLogger(this.GetType().ToString())); }
}
#endregion
#region 请求响应
///
/// 返回成功消息
///
/// 数据
///
protected virtual IHttpActionResult ToJsonResult(object data)
{
return Json(data);
}
///
/// 返回成功消息
///
/// 消息
///
protected virtual IHttpActionResult Success(string info)
{
return Json(new ResParameter { code = ResponseCode.success, info = info, data = new object { } });
}
///
/// 返回成功消息
///
/// 数据
///
protected virtual IHttpActionResult SuccessString(string data)
{
return Json(new ResParameter { code = ResponseCode.success, info = "响应成功", data = data });
}
///
/// 返回成功数据
///
/// 数据
///
protected virtual IHttpActionResult Success(object data)
{
return Json(new ResParameter { code = ResponseCode.success, info = "响应成功", data = data });
}
///
/// 返回成功消息
///
/// 消息
/// 数据
///
protected virtual IHttpActionResult Success(string info, object data)
{
return Json(new ResParameter { code = ResponseCode.success, info = info, data = data });
}
///
/// 带操作日志
///
///
///
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 { } });
}
///
/// 返回失败消息
///
/// 消息
///
protected virtual IHttpActionResult Fail(string info)
{
return Json(new ResParameter { code = ResponseCode.fail, info = info });
}
///
/// 返回失败消息
///
/// 消息
/// 消息
///
protected virtual IHttpActionResult Fail(string info, object data)
{
return Json(new ResParameter { code = ResponseCode.fail, info = info, data = data });
}
#endregion
}
}