Esempio n. 1
0
        /// <summary>
        /// 操作后
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            if (!isCheck)
            {
                return;
            }
            string token;

            token = filterContext.HttpContext.Request.Headers["Access"];
            token = token ?? filterContext.HttpContext.Request["Access"];
            token = token ?? filterContext.HttpContext.Request.Cookies["Access"]?.Value;

            var payload = Cache.GetCache <Payload>(token);
            //操作日志记录
            JsonResult jsonResult = filterContext.Result as JsonResult;
            string     roomId     = filterContext.HttpContext.Request["classroom"];
            string     nodeId     = filterContext.HttpContext.Request["nodeAdd"] ?? "00";

            if (nodeId?.IndexOf("_") != -1)
            {
                nodeId = nodeId.Split('_')[0];
            }
            string onoff = filterContext.HttpContext.Request["onoff"];

            onoff = string.IsNullOrEmpty(onoff) ? "" : onoff;
            EquipmentResult equipmentResult = jsonResult?.Data as EquipmentResult;

            if (equipmentResult != null)
            {
                //开启线程处理后续日志操作
                ThreadPool.QueueUserWorkItem(oo =>
                {
                    Z_EquipmentLog zEquipmentLog = new Z_EquipmentLog();
                    zEquipmentLog.F_Id           = Guid.NewGuid().ToString();
                    zEquipmentLog.F_Account      = payload.Account;
                    zEquipmentLog.F_Date         = DateTime.Now;
                    zEquipmentLog.F_RoomNo       = roomId;
                    string roomName = ZRoomService.GetEntity(z => z.F_RoomNo.ToLower() == roomId.ToLower()).Select(z => z.F_FullName).FirstOrDefault();
                    string nodeName = ZEquipmentService.GetEntity(e => e.F_EquipmentNo.ToLower() == nodeId.ToLower())
                                      .Select(e => e.F_FullName).FirstOrDefault();
                    var user = SysUserService.GetEntity(u => u.F_Account == payload.Account).Select(o => new { o.F_NickName, o.F_RealName })
                               .FirstOrDefault();
                    zEquipmentLog.F_EquipmentNo      = nodeId;
                    zEquipmentLog.F_Description      = equipmentResult.Message;
                    zEquipmentLog.F_EquipmentLogType = onoff == StateType.OPEN ? EQUOPEN : onoff == StateType.CLOSE ? EQUCLOSE : EQUSEARCH;
                    zEquipmentLog.F_RoomName         = roomName;
                    zEquipmentLog.F_EquipmentName    = nodeName;
                    zEquipmentLog.F_NickName         = user?.F_NickName;
                    zEquipmentLog.F_FullName         = user?.F_RealName;

                    ZEquipmentLogService.AddEntity(zEquipmentLog);
                });
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 行为执行后,记录登录记录
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            Action = filterContext.RouteData.Values["action"].ToString();
            JsonResult result = filterContext.Result as JsonResult;
            //TODO 这边需要改成从请求头和Cookie获取
            //string account = filterContext.HttpContext.Request["Account"] == null ? filterContext.HttpContext.Request.Cookies["Account"]?.Value : filterContext.HttpContext.Request["Account"];
            ModelResult mr;
            string      userHostAddress = filterContext.HttpContext.Request.UserHostAddress;//IP地址

            if (result != null)
            {
                mr  = result.Data as LoginResult;
                Log = new Sys_Log {
                    F_Account = "admin"
                };
                #region 开启一个线程,后台处理日志信息
                ThreadPool.QueueUserWorkItem((o =>
                {
                    try
                    {
                        Log.F_Id = Guid.NewGuid().ToString();
                        Log.F_Date = DateTime.Now;
                        Log.F_IPAddress = userHostAddress;
                        Log.F_Type = Action;
                        Log.F_ModuleName = "系统登录";
                        Log.F_IPAddressName = "广东省河源市 电信";
                        Log.F_Result = mr?.Status;
                        Log.F_Description = mr?.Message;
                        Sys_User user = SysUserService.GetEntity(u => u.F_Account == Log.F_Account).FirstOrDefault();
                        Log.F_NickName = user?.F_NickName;
                        //更新日志信息
                        SysLogService.AddEntity(Log);
                    }
                    catch (Exception ex)
                    {
                        ExceptionHelper.AddException(ex);
                    }
                }));
                #endregion
            }
        }