Ejemplo n.º 1
0
        public IHttpActionResult DepartAlarmTypeStatistics(DepartAlarmStatisticsModel query)
        {
            if (query == null || string.IsNullOrEmpty(query.From) || string.IsNullOrEmpty(query.To))
            {
                return(BadRequest());
            }
            try
            {
                if (!UserController.LoginDictionary.ContainsKey(GetCookie("token")))
                {
                    return(Logout());
                }
                UserInfo userCookie = UserController.LoginDictionary[GetCookie("token")];
                if (userCookie == null)
                {
                    return(Logout());
                }
                if (query.DepartmentID == 0)
                {
                    query.DepartmentID = userCookie.DepartmentID;
                }

                query.From = Convert.ToDateTime(query.From).ToString("yyyy-MM-dd 00:00:00");
                query.To   = Convert.ToDateTime(query.To).ToString("yyyy-MM-dd  23:59:59");
                var result = CabinetLog.DepartAlarmTypeStatistics(query.DepartmentID, query.From, query.To);
                return(Success(result));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(Failure("提交失败"));
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult DepartMonthAlarmStatistics(DepartAlarmStatisticsModel query)
        {
            if (query == null || string.IsNullOrEmpty(query.From) || string.IsNullOrEmpty(query.To))
            {
                return(BadRequest());
            }
            try
            {
                if (!UserController.LoginDictionary.ContainsKey(GetCookie("token")))
                {
                    return(Logout());
                }
                UserInfo userCookie = UserController.LoginDictionary[GetCookie("token")];
                if (userCookie == null)
                {
                    return(Logout());
                }
                if (query.DepartmentID == 0)
                {
                    query.DepartmentID = userCookie.DepartmentID;
                }
                MonthAlarmStatisticsModel model = new Models.MonthAlarmStatisticsModel();
                model.Year = DateTime.Parse(query.From).Year.ToString();
                model.Data = new List <int>();

                query.From = Convert.ToDateTime(query.From).ToString("yyyy-MM-dd 00:00:00");
                query.To   = Convert.ToDateTime(query.To).ToString("yyyy-MM-dd  23:59:59");

                var result = CabinetLog.DepartMonthAlarmStatistics(query.DepartmentID, query.From, query.To);
                if (result.Count > 0)
                {
                    for (int i = 1; i <= 12; i++)
                    {
                        var item = result.Find(m => m.Month == i);
                        model.Data.Add(item == null ? 0 : item.Count);
                    }
                }
                return(Success(model));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(Failure("查询失败"));
            }
        }