Beispiel #1
0
 public object GetSelfEvaluateMonthList([FromBody] JObject json)
 {
     try
     {
         var     bll = new SelfEvaluateBLL();
         string  res = json.Value <string>("json");
         dynamic dy = JsonConvert.DeserializeObject <ExpandoObject>(res);
         int     page = Convert.ToInt32(dy.data.pageNum), rows = Convert.ToInt32(dy.data.pageSize);
         string  keyword = dy.data.keyword;
         string  userid  = dy.userid;
         OperatorProvider.AppUserId = userid;  //设置当前用户
         Operator curUser = OperatorProvider.Provider.Current();
         if (null == curUser)
         {
             return(new { code = -1, count = 0, info = "请求失败,请登录!", data = new object() });
         }
         var list      = bll.GetList("", curUser.DeptCode, keyword).ToList();
         var nlist     = new List <MonthEvaluate>();
         var ylist     = list.GroupBy(x => x.Year).Select(x => x.FirstOrDefault().Year).OrderByDescending(x => x); //根据年分分组
         var userCount = new UserBLL().GetList().Count(p => p.DepartmentCode.StartsWith(curUser.DeptCode) && p.IsPresence == "1");
         foreach (string year in ylist)
         {
             var mlist = list.Where(x => x.Year == year).GroupBy(x => x.Month).Select(x => x.FirstOrDefault().Month).OrderByDescending(x => x);//查询当年数据根据月份分组
             foreach (string month in mlist)
             {
                 var obj = new MonthEvaluate();
                 obj.name   = year + "年" + month + "月员工HSE自我评估";
                 obj.count1 = list.Where(x => x.Year == year && x.Month == month && x.IsFill == "1").GroupBy(x => x.CreateUserId).Count();
                 obj.count2 = ((userCount - obj.count1) < 0 ? 0 : (userCount - obj.count1));
                 obj.year   = year;
                 obj.month  = month;
                 var summary = bll.GetSummary(year, month, curUser.DeptId);
                 obj.content = summary == null ? "" : summary.Content;
                 nlist.Add(obj);
             }
         }
         return(new { code = 0, count = 0, info = "获取成功", data = nlist });
     }
     catch (Exception ex)
     {
         return(new { code = -1, count = 0, info = "获取数据失败:" + ex.Message, data = new object() });
     }
 }
        /// <summary>
        /// 获取台账数据
        /// </summary>
        /// <returns></returns>
        public ActionResult GetDataList(Pagination pagination, string queryJson)
        {
            var userNow = OperatorProvider.Provider.Current();

            var    bll         = new SelfEvaluateBLL();
            var    queryJsonTo = queryJson.ToJObject();
            var    watch       = CommonHelper.TimerStart();
            string deptcode    = string.Empty;
            string keyword     = string.Empty;
            string year        = string.Empty;
            string month       = string.Empty;

            if (queryJsonTo["mydata"].IsEmpty())
            {
                if (!queryJsonTo["DeptCode"].IsEmpty())
                {
                    deptcode = queryJsonTo["DeptCode"].ToString();
                }
                if (!queryJsonTo["keyword"].IsEmpty())
                {
                    keyword = queryJsonTo["keyword"].ToString();
                }
                if (!queryJsonTo["year"].IsEmpty())
                {
                    year = queryJsonTo["year"].ToString();
                }
                if (!queryJsonTo["month"].IsEmpty())
                {
                    month = queryJsonTo["month"].ToString();
                }
            }
            var list = bll.GetList("", deptcode, keyword, year, month);

            if (!queryJsonTo["mydata"].IsEmpty())
            {
                list = list.Where(x => x.CreateUserId == userNow.UserId).OrderByDescending(x => x.CreateDate);
            }
            else
            {
                list = list.Where(x => x.IsSubmit == "1").OrderByDescending(x => x.CreateDate);
            }
            pagination.records = list.Count();
            var           datalist = (list.Skip(pagination.rows * (pagination.page - 1)).Take(pagination.rows)).ToList();
            List <object> userData = new List <object>();
            var           userbll  = new UserBLL();
            var           deptbll  = new DepartmentBLL();

            datalist.ForEach(x =>
            {
                var getuser   = userbll.GetEntity(x.CreateUserId);
                var dept      = string.Empty;
                var go        = true;
                var getDept   = deptbll.GetEntity(getuser.DepartmentId);
                var parDeptId = getDept.ParentId;
                if (getDept.Nature == "班组" || getDept.Nature == "专业")
                {
                    dept = getDept.FullName;
                    while (go)
                    {
                        var parDept = deptbll.GetEntity(parDeptId);
                        if (parDept == null)
                        {
                            go = false;
                            break;
                        }
                        if (parDept.Nature == "部门")
                        {
                            if (string.IsNullOrEmpty(dept))
                            {
                                dept = parDept.FullName;
                            }
                            else
                            {
                                dept = parDept.FullName + "/" + dept;
                            }
                            go = false;
                            break;
                        }
                        else
                        {
                            parDeptId = parDept.ParentId;
                        }
                    }
                }
                else
                {
                    dept = getDept.FullName;
                }

                var user = new
                {
                    id       = x.Id,
                    name     = getuser.RealName,
                    dept     = dept,
                    rolename = getuser.DutyName,
                    time     = x.CreateDate,
                    issubmit = x.IsSubmit == "0" ? "1" : string.Empty
                };
                userData.Add(user);
            });
            var JsonData = new
            {
                rows     = userData,
                total    = pagination.total,
                page     = pagination.page,
                records  = pagination.records,
                costtime = CommonHelper.TimerEnd(watch)
            };

            return(Content(JsonData.ToJson()));
        }
Beispiel #3
0
        public object GetSelfEvaluateList([FromBody] JObject json)
        {
            try
            {
                var     bll = new SelfEvaluateBLL();
                string  res = json.Value <string>("json");
                dynamic dy = JsonConvert.DeserializeObject <ExpandoObject>(res);
                int     page = Convert.ToInt32(dy.data.pageNum), rows = Convert.ToInt32(dy.data.pageSize);
                string  type     = dy.data.type;
                string  name     = dy.data.name;
                string  userid   = dy.userid;
                string  keyword  = dy.data.keyword;
                string  year     = dy.data.year;
                string  deptcode = dy.data.deptcode;
                string  state    = dy.data.state;
                string  month    = dy.data.month;
                OperatorProvider.AppUserId = userid;  //设置当前用户
                Operator curUser = OperatorProvider.Provider.Current();
                if (null == curUser)
                {
                    return(new { code = -1, count = 0, info = "请求失败,请登录!", data = new object() });
                }
                var list = new List <SelfEvaluateEntity>();
                if (string.IsNullOrEmpty(deptcode))
                {
                    list     = bll.GetList("", curUser.DeptCode, keyword, year, month).ToList();
                    deptcode = curUser.DeptCode;
                }
                else
                {
                    list = bll.GetList("", deptcode, keyword, year, month).ToList();
                }
                if (type == "my")
                {
                    list = list.Where(x => x.CreateUserId == curUser.UserId).ToList();
                }
                else
                {
                    if (state != "已填报")
                    {
                        var           allUser         = new UserBLL().GetList().Where(x => x.IsPresence == "1");
                        List <string> submituserids   = list.Where(x => x.IsSubmit == "1").Select(x => x.CreateUserId).ToList();                                                                                      //该部门下已提交人的人的Id
                        List <string> submitUserNames = allUser.Where(p => submituserids.Contains(p.UserId) && p.IsPresence == "1").Select(p => p.RealName).ToList();                                                 //已提交的人
                        List <Entity.BaseManage.UserEntity> notSubmitUserNames = allUser.Where(p => p.DepartmentCode != null && p.DepartmentCode.StartsWith(deptcode) && !submituserids.Contains(p.UserId)).ToList(); //未提交的人
                        if (state == "未填报")
                        {
                            list.Clear();
                        }
                        var yearNum  = Convert.ToInt32(year);
                        var monthNum = Convert.ToInt32(month);
                        var dayTime  = new DateTime(yearNum, monthNum, 1);
                        notSubmitUserNames.ForEach(x =>
                        {
                            var model        = new SelfEvaluateEntity();
                            model.CreateUser = x.RealName;
                            model.CreateDate = dayTime;
                            model.DeptId     = x.DepartmentId;
                            model.DeptCode   = x.DepartmentCode;
                            model.IsSubmit   = "1";
                            list.Add(model);
                        });
                    }
                    list = list.Where(x => x.IsSubmit == "1").ToList();
                }

                if (!string.IsNullOrEmpty(name))
                {
                    list = list.Where(x => x.CreateUser.Contains(name)).ToList();
                }
                int count = list.Count();
                list = list.Skip((page - 1) * rows).Take(rows).OrderBy(p => p.IsFill).OrderByDescending(x => x.IsSubmit).ThenByDescending(p => p.CreateDate).ToList();
                var deptbll = new DepartmentBLL();
                var allDept = deptbll.GetList();
                list.ForEach(x =>
                {
                    var dept      = string.Empty;
                    var go        = true;
                    var getDept   = allDept.FirstOrDefault(p => p.DepartmentId == x.DeptId);
                    var parDeptId = getDept.ParentId;
                    if (getDept.Nature == "班组" || getDept.Nature == "专业")
                    {
                        dept = getDept.FullName;
                        while (go)
                        {
                            var parDept = deptbll.GetEntity(parDeptId);
                            if (parDept == null)
                            {
                                go = false;
                                break;
                            }
                            if (parDept.Nature == "部门")
                            {
                                if (string.IsNullOrEmpty(dept))
                                {
                                    dept = parDept.FullName;
                                }
                                else
                                {
                                    dept = parDept.FullName + "/" + dept;
                                }
                                go = false;
                            }
                            else
                            {
                                parDeptId = parDept.ParentId;
                            }
                        }
                    }
                    else
                    {
                        dept = getDept.FullName;
                    }
                    x.DeptName = dept;
                });
                return(new { code = 0, count = count, info = "获取成功", data = list });
            }
            catch (Exception ex)
            {
                return(new { code = -1, count = 0, info = "获取数据失败:" + ex.Message, data = new object() });
            }
        }