Exemplo n.º 1
0
 /// <summary>
 /// 子表:分类统计时长
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public ActionResult SubList(TXQuery data)
 {
     if (Request.HttpMethod == "POST")
     {
         Response <List <TXStatistics> > response = new Response <List <TXStatistics> >();
         List <object> list = new List <object>();
         if (data != null)
         {
             Request <TXQuery> request = new Request <TXQuery>();
             request.Data        = data;
             request.RequsetTime = DateTime.Now;
             request.RequestKey  = Guid.NewGuid().ToString();
             response            = logic.GetSubHours(request);
             //行号
             #region
             if (response.Result != null && response.Result.Count > 0)
             {
                 int index = 1;
                 foreach (TXStatistics item in response.Result)
                 {
                     list.Add(new
                     {
                         RowNum = index,
                         UserID = item.UserID,
                         Year   = item.Year,
                         Month  = item.Month,
                         Hours  = item.Hours,
                         OAType = item.OAType
                     });
                     index++;
                 }
             }
             #endregion
         }
         //return Json(new { data = response.Result });
         //return Json(new { rows = response.Result, total = response.TotalCount });
         return(Json(new { rows = list, total = response.TotalCount }));
     }
     return(View());
 }
Exemplo n.º 2
0
        /// <summary>
        /// 加班请假时间分类统计
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <returns>调休列表</returns>
        public Response <List <TXStatistics> > GetSubHours(Request <TXQuery> request)
        {
            Response <List <TXStatistics> > response = new Response <List <TXStatistics> >();

            try
            {
                if (request != null && request.Data != null)
                {
                    TXQuery data = request.Data;
                    #region 加班请假分类统计
                    int userId = data.UserID != 0 ? data.UserID : utility.GetUserID(cookieKey);
                    if (data.Month != 0)
                    {
                        //按月统计
                        var result = from h in dbContext.TXHours
                                     where h.Year == data.Year && h.Month == data.Month && h.UserID == userId
                                     group h by new { h.UserID, h.Year, h.Month, h.OAType } into n
                            select new TXStatistics()
                        {
                            Year   = n.Key.Year,
                            Month  = n.Key.Month,
                            UserID = n.Key.UserID,
                            OAType = (int)n.Key.OAType,
                            Hours  = n.Sum(o => o.Hours)
                        };
                        response.Result = result.ToList();
                    }
                    else
                    {
                        //按年统计
                        var result2 = from h in dbContext.TXHours
                                      where h.Year == data.Year && h.UserID == userId
                                      group h by new { h.UserID, h.Year, h.OAType } into n
                            select new TXStatistics()
                        {
                            Year   = n.Key.Year,
                            UserID = n.Key.UserID,
                            OAType = (int)n.Key.OAType,
                            Hours  = n.Sum(o => o.Hours)
                        };
                        response.Result = result2.ToList();
                    }
                    #endregion
                    if (response.Result != null && response.Result.Count > 0)
                    {
                        response.IsSuccess = true;
                    }
                    else
                    {
                        response.ErrorMsg = "没有数据!";
                    }
                    log.AddLog(LogType.Info, "GetSubHours,查询结果:" + JsonConvert.SerializeObject(response), request.RequestKey);
                }
            }
            catch (Exception ex)
            {
                response.ErrorMsg = "统计出错,系统异常!";
                log.AddLog(LogType.Error, "GetSubHours,加班请假分类统计异常:" + ex.Message, request.RequestKey);
            }
            return(response);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 调休剩余时间统计
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <returns>调休列表</returns>
        public Response <List <TXStatistics> > GetHours(Request <TXQuery> request)
        {
            Response <List <TXStatistics> > response = new Response <List <TXStatistics> >();

            try
            {
                if (request != null && request.Data != null)
                {
                    TXQuery  data = request.Data;
                    RoleType role = utility.GetRoleType(cookieKey);
                    if (role == RoleType.Admin && data.UserID == 0)
                    {
                        #region 管理员全部统计
                        if (data.Month != 0)
                        {
                            //按月统计
                            var result = from h in dbContext.TXHours
                                         where h.Year == data.Year && h.Month == data.Month
                                         group h by new { h.UserID, h.Year, h.Month } into n
                                select new TXStatistics()
                            {
                                Year   = n.Key.Year,
                                Month  = n.Key.Month,
                                UserID = n.Key.UserID,
                                Hours  = n.Sum(o => o.Hours)
                            };
                            response.Result = result.ToList();
                        }
                        else
                        {
                            //按年统计
                            var result2 = from h in dbContext.TXHours
                                          where h.Year == data.Year
                                          group h by new { h.UserID, h.Year } into n
                                select new TXStatistics()
                            {
                                Year   = n.Key.Year,
                                UserID = n.Key.UserID,
                                Hours  = n.Sum(o => o.Hours)
                            };
                            response.Result = result2.ToList();
                        }
                        #endregion
                    }
                    else
                    {
                        #region 单个用户统计
                        int userId = data.UserID != 0 ? data.UserID : utility.GetUserID(cookieKey);
                        if (data.Month != 0)
                        {
                            //按月统计
                            var result = from h in dbContext.TXHours
                                         where h.Year == data.Year && h.Month == data.Month && h.UserID == userId
                                         group h by new { h.UserID, h.Year, h.Month } into n
                                select new TXStatistics()
                            {
                                Year   = n.Key.Year,
                                Month  = n.Key.Month,
                                UserID = n.Key.UserID,
                                Hours  = n.Sum(o => o.Hours)
                            };
                            response.Result = result.ToList();
                        }
                        else
                        {
                            //按年统计
                            var result2 = from h in dbContext.TXHours
                                          where h.Year == data.Year && h.UserID == userId
                                          group h by new { h.UserID, h.Year } into n
                                select new TXStatistics()
                            {
                                Year   = n.Key.Year,
                                UserID = n.Key.UserID,
                                Hours  = n.Sum(o => o.Hours)
                            };
                            response.Result = result2.ToList();
                        }
                        #endregion
                    }
                    if (response.Result != null && response.Result.Count > 0)
                    {
                        response.IsSuccess  = true;
                        response.TotalCount = response.Result.Count();
                        int pageIndex = data.PageIndex <= 0 ? 1 : data.PageIndex;
                        int pageSize  = data.PageSize <= 0 ? 10 : data.PageSize;
                        response.Result = response.Result.OrderBy(o => o.UserID).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
                    }
                    else
                    {
                        response.ErrorMsg = "没有数据!";
                    }
                    log.AddLog(LogType.Info, "GetHours,查询结果:" + JsonConvert.SerializeObject(response), request.RequestKey);
                }
            }
            catch (Exception ex)
            {
                response.ErrorMsg = "统计出错,系统异常!";
                log.AddLog(LogType.Error, "GetHours,调休剩余时间统计异常:" + ex.Message, request.RequestKey);
            }
            return(response);
        }