using Microsoft.AspNetCore.Mvc;using WMS.BZWeb;
using System.Threading.Tasks;
using WMS.Info;
using WMS.Util;
using WMS.BZWeb.Extensions;
using WMS.Core;
using WMS.BZServices;
namespace WMS.BZWeb
{
///
/// 描 述:基础控制器
///
// [HandlerLogin(EFilterMode.Enforce)]
[TypeFilter(typeof(ExceptionFilter))]
//[XSSFilter]
public abstract class MvcControllerBase : Controller
{
#region 获取基础信息
///
/// 获取登录信息(视图中无法获取)
///
///
public LoginUserInfo GetLoginUser()
{
LoginUserInfo LoginUser = BZLoginBLLCore.GetLoginUser();
return LoginUser;
}
///
/// 获取登录者用户名称(视图中无法获取)
///
///
public string GetUserName()
{
return WebUtil.GetItem("userName") as string;
}
///
/// 获取登录者用户Id(视图中无法获取)
///
///
public string GetUserId()
{
return WebUtil.GetItem("userId") as string;
}
///
/// 获取登录者用户账号(视图中无法获取)
///
///
public string GetUserAccount()
{
return WebUtil.GetItem("account") as string;
}
#endregion
///
/// 返回成功消息
///
/// 消息
/// 数据
///
protected virtual ActionResult Success(string info="", object data = null)
{
return Content(new ResInfo { code = EResponseCode.Success, info = string.IsNullOrWhiteSpace(info) ? "响应成功" : info, data = data == null ? new object { } : data }.ToJson());
}
protected virtual ActionResult Success(object data)
{
return Content(new ResInfo { code = EResponseCode.Success, info = "响应成功", data = data }.ToJson());
}
///
/// 返回成功消息
///
/// 消息
/// 数据
///
protected virtual ActionResult Fail(string info )
{
return Content(new ResInfo { code = EResponseCode.Fail, info = info, data = new object { } }.ToJson());
}
///
/// 返回成功消息
///
/// 消息
/// 数据
///
protected virtual ActionResult FailEx(string info)
{
return Content(new ResInfo { code = EResponseCode.Exception, info = info, data = new object { } }.ToJson());
}
///
/// 转换结果
///
/// 数据
///
protected virtual ActionResult ToJsonResult(ResInfo resdata)
{
if (resdata == null)
{
resdata = new ResInfo() { code = EResponseCode.Exception, data = new object { }, info = "响应失败。" };
}
else
{
if (resdata.data == null)
{
resdata.data = new object { };
}
}
return Content(resdata.ToJson());
}
///
/// 转换分页数据结果
///
/// 分页参数
/// 分页数据
protected virtual ActionResult ToPageDataResult(Pagination paginationobj, object PageData)
{
var resdata = new ResInfo()
{
code = EResponseCode.Success,
data = new
{
rows = PageData,
total = paginationobj.total,
page = paginationobj.page,
records = paginationobj.records,
},
info = "响应成功。"
};
return Content(resdata.ToJson());
}
///
/// 转换分页数据结果
///
/// 分页参数
/// 分页数据
protected virtual Pagination InitPagination(string pagination)
{
Pagination paginationobj = pagination.ToObject();
if (paginationobj == null)
{
paginationobj = new Pagination()
{
page = 1,
records = 0,
rows = 100,
sidx = "",
sord = "asc"
};
}
if (paginationobj.page < 1)
{
paginationobj.page = 1;
}
if (paginationobj.rows < 1)
{
paginationobj.rows = 100;
}
return paginationobj;
}
/////
///// 返回成功数据
/////
///// 数据
/////
//protected virtual ActionResult Success(object data)
//{
// return Content(new ResParameter { code = ResponseCode.success, info = "响应成功", data = data }.ToJson());
//}
/////
///// 返回成功消息
/////
///// 消息
///// 数据
/////
//protected virtual ActionResult Success(string info, object data)
//{
// return Content(new ResParameter { code = ResponseCode.success, info = info, data = data }.ToJson());
//}
/////
///// 带操作日志
/////
/////
/////
//protected virtual ActionResult 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 Content(new ResParameter { code = ResponseCode.success, info = info, data = new object { } }.ToJson());
//}
/////
///// 返回失败消息
/////
///// 消息
/////
//protected virtual ActionResult Fail(string info)
//{
// return Content(new ResParameter { code = ResponseCode.fail, info = info }.ToJson());
//}
/////
///// 返回失败消息
/////
///// 消息
///// 消息
/////
//protected virtual ActionResult Fail(string info, object data)
//{
// return Content(new ResParameter { code = ResponseCode.fail, info = info, data = data }.ToJson());
//}
//#endregion
}
}