123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- 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
- {
- /// <summary>
- /// 描 述:基础控制器
- /// </summary>
- // [HandlerLogin(EFilterMode.Enforce)]
- [TypeFilter(typeof(ExceptionFilter))]
- //[XSSFilter]
- public abstract class MvcControllerBase : Controller
- {
- #region 获取基础信息
- /// <summary>
- /// 获取登录信息(视图中无法获取)
- /// </summary>
- /// <returns></returns>
- public LoginUserInfo GetLoginUser()
- {
- LoginUserInfo LoginUser = BZLoginBLLCore.GetLoginUser();
- return LoginUser;
- }
- /// <summary>
- /// 获取登录者用户名称(视图中无法获取)
- /// </summary>
- /// <returns></returns>
- public string GetUserName()
- {
- return WebUtil.GetItem("userName") as string;
- }
- /// <summary>
- /// 获取登录者用户Id(视图中无法获取)
- /// </summary>
- /// <returns></returns>
- public string GetUserId()
- {
- return WebUtil.GetItem("userId") as string;
- }
- /// <summary>
- /// 获取登录者用户账号(视图中无法获取)
- /// </summary>
- /// <returns></returns>
- public string GetUserAccount()
- {
- return WebUtil.GetItem("account") as string;
- }
- #endregion
- /// <summary>
- /// 返回成功消息
- /// </summary>
- /// <param name="info">消息</param>
- /// <param name="data">数据</param>
- /// <returns></returns>
- 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());
- }
- /// <summary>
- /// 返回成功消息
- /// </summary>
- /// <param name="info">消息</param>
- /// <param name="data">数据</param>
- /// <returns></returns>
- protected virtual ActionResult Fail(string info )
- {
- return Content(new ResInfo { code = EResponseCode.Fail, info = info, data = new object { } }.ToJson());
- }
- /// <summary>
- /// 返回成功消息
- /// </summary>
- /// <param name="info">消息</param>
- /// <param name="data">数据</param>
- /// <returns></returns>
- protected virtual ActionResult FailEx(string info)
- {
- return Content(new ResInfo { code = EResponseCode.Exception, info = info, data = new object { } }.ToJson());
- }
- /// <summary>
- /// 转换结果
- /// </summary>
- /// <param name="data">数据</param>
- /// <returns></returns>
- 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());
- }
- /// <summary>
- /// 转换分页数据结果
- /// </summary>
- /// <param name="paginationobj">分页参数</param>
- /// <param name="PageData">分页数据</param>
- 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());
- }
- /// <summary>
- /// 转换分页数据结果
- /// </summary>
- /// <param name="paginationobj">分页参数</param>
- /// <param name="PageData">分页数据</param>
- protected virtual Pagination InitPagination(string pagination)
- {
- Pagination paginationobj = pagination.ToObject<Pagination>();
- 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;
- }
- ///// <summary>
- ///// 返回成功数据
- ///// </summary>
- ///// <param name="data">数据</param>
- ///// <returns></returns>
- //protected virtual ActionResult Success(object data)
- //{
- // return Content(new ResParameter { code = ResponseCode.success, info = "响应成功", data = data }.ToJson());
- //}
- ///// <summary>
- ///// 返回成功消息
- ///// </summary>
- ///// <param name="info">消息</param>
- ///// <param name="data">数据</param>
- ///// <returns></returns>
- //protected virtual ActionResult Success(string info, object data)
- //{
- // return Content(new ResParameter { code = ResponseCode.success, info = info, data = data }.ToJson());
- //}
- ///// <summary>
- ///// 带操作日志
- ///// </summary>
- ///// <param name="info"></param>
- ///// <returns></returns>
- //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());
- //}
- ///// <summary>
- ///// 返回失败消息
- ///// </summary>
- ///// <param name="info">消息</param>
- ///// <returns></returns>
- //protected virtual ActionResult Fail(string info)
- //{
- // return Content(new ResParameter { code = ResponseCode.fail, info = info }.ToJson());
- //}
- ///// <summary>
- ///// 返回失败消息
- ///// </summary>
- ///// <param name="info">消息</param>
- ///// <param name="data">消息</param>
- ///// <returns></returns>
- //protected virtual ActionResult Fail(string info, object data)
- //{
- // return Content(new ResParameter { code = ResponseCode.fail, info = info, data = data }.ToJson());
- //}
- //#endregion
- }
- }
|