public ActionResult GetScoreSecond(string time, string deptid) { var ckTime = DateTime.Now.ToString("yyyy-MM-01") == time; var list = default(List <string>); string category = "厂级,部门,班组"; list = category.Split(',').ToList(); var depts = bllSecond.getDepartmentList("", category); string deptName = ""; if (deptid == "0") { foreach (var item in depts) { if (item.Nature == "部门") { var dept = depts.Where(x => x.ParentId == item.DepartmentId).ToList(); if (dept.Count() > 0) { deptid = dept[0].DepartmentId; deptName = dept[0].FullName; break; } } } } else { var Nature = deptbll.GetEntity(deptid); if (Nature.Nature == "部门") { var one = depts.FirstOrDefault(x => x.ParentId == deptid); deptid = one.DepartmentId; deptName = one.FullName; } if (Nature.Nature == "厂级") { foreach (var item in depts) { if (item.Nature == "部门") { var dept = depts.Where(x => x.ParentId == item.DepartmentId).ToList(); if (dept.Count() > 0) { deptid = dept[0].DepartmentId; deptName = dept[0].FullName; break; } } } } if (Nature.Nature == "班组") { deptName = Nature.FullName; } } if (ckTime) { var jsonStr = new { rows = "", records = 0, isup = "未提交", total = 0, deptname = deptName }; return(Content(jsonStr.ToJson())); } var worktime = Convert.ToDateTime(time); var data = bllSecond.getScore(worktime, deptid).OrderBy(x => x.planer).ThenBy(x => x.username).ToList(); double total = 0; foreach (var item in data) { var score = Convert.ToDouble(item.score.Split(',')[0]); total = total + score; } var month = upbllSecond.getListByMonth(time).Where(x => x.departmentid == deptid).ToList(); var ck = month.FirstOrDefault(x => x.departmentid == deptid); bool isup = ck == null ? false : ck.isup; List <SortModel> result = new List <SortModel>(); foreach (var item in data) { var resultinfo = new SortModel(); string itemJson = new object().ToJson(); string myTitleStr = string.Empty; myTitleStr = item.score; var strSp = myTitleStr.Split(','); var sort = item.sort.Split(',').ToList(); int num = 0; for (int i = 0; i < strSp.Count(); i++) { if (i == 0) { itemJson = itemJson.Insert(1, "\"title" + num + "\":" + strSp[i]); } else { itemJson = itemJson.Insert(1, "\"title" + num + "\":" + strSp[i] + ","); } num++; } itemJson = itemJson.Insert(1, "\"username\":\"" + item.username + "\","); itemJson = itemJson.Insert(1, "\"quarters\":\"" + item.quarters + "\","); resultinfo.Info = itemJson; result.Add(resultinfo); } var JsonData = new { rows = result.Select(p => p.Info.ToJObject()), records = data.Count, isup = isup ? "已提交" : ck == null ? "未生成绩效表" : "未提交", total = total, deptname = deptName }; return(Content(JsonData.ToJson())); } /// <summary>
public ActionResult GetScore(string time, string deptid) { var ckTime = DateTime.Now.ToString("yyyy-MM-01") == time; var list = default(List <string>); string category = "厂级,部门,班组"; list = category.Split(',').ToList(); var depts = bll.getDepartmentList("", category); string deptName = ""; if (deptid == "0") { foreach (var item in depts) { if (item.Nature == "部门") { var dept = depts.Where(x => x.ParentId == item.DepartmentId).ToList(); if (dept.Count() > 0) { deptid = dept[0].DepartmentId; deptName = dept[0].FullName; break; } } } } else { var Nature = deptbll.GetEntity(deptid); if (Nature.Nature == "部门") { var one = depts.FirstOrDefault(x => x.ParentId == deptid); deptid = one.DepartmentId; deptName = one.FullName; } if (Nature.Nature == "厂级") { foreach (var item in depts) { if (item.Nature == "部门") { var dept = depts.Where(x => x.ParentId == item.DepartmentId).ToList(); if (dept.Count() > 0) { deptid = dept[0].DepartmentId; deptName = dept[0].FullName; break; } } } } if (Nature.Nature == "班组") { deptName = Nature.FullName; } } if (ckTime) { var jsonStr = new { rows = "", records = 0, isup = "未提交", total = 0, deptname = deptName }; return(Content(jsonStr.ToJson())); } var data = bll.getScore(time, deptid).OrderBy(x => x.planer).ThenBy(x => x.username).ToList(); double total = 0; foreach (var item in data) { var score = Convert.ToDouble(item.score.Split(',')[0]); total = total + score; } var month = upbll.getListByMonth(time).Where(x => x.departmentid == deptid).ToList(); var ck = month.FirstOrDefault(x => x.departmentid == deptid); bool isup = ck == null ? false : ck.isup; List <SortModel> result = new List <SortModel>(); foreach (var item in data) { var resultinfo = new SortModel(); string itemJson = new object().ToJson(); string myTitleStr = string.Empty; myTitleStr = item.score; var strSp = myTitleStr.Split(','); var sort = item.sort.Split(',').ToList(); int num = 0; decimal jxScore = 0;//绩效得分 for (int i = 0; i < strSp.Count() - 1; i++) { if (sort.Contains(i.ToString())) { if (i == strSp.Count() - 2) { itemJson = itemJson.Insert(1, "\"title" + num + "\":" + strSp[i]); } else { itemJson = itemJson.Insert(1, "\"title" + num + "\":" + strSp[i] + ","); } num++; } if (i == 1)//第二个是绩效 { decimal.TryParse(strSp[i], out jxScore); } } itemJson = itemJson.Insert(1, "\"username\":\"" + item.username + "\","); itemJson = itemJson.Insert(1, "\"quarters\":\"" + item.quarters + "\","); resultinfo.Info = itemJson; resultinfo.Value = jxScore; resultinfo.Index = num; // resultinfo = itemJson.ToJObject(); result.Add(resultinfo); } result = result.OrderByDescending(p => p.Value).ToList(); var ki = new List <KeyIndex>(); var valueList = result.Select(p => p.Value).Distinct().ToList(); for (int i = 0; i < valueList.Count; i++) { ki.Add(new KeyIndex() { Value = valueList[i], Index = i + 1 }); } for (int i = 1; i <= result.Count; i++) { result[i - 1].Info = result[i - 1].Info.Insert(1, "\"title" + result[i - 1].Index + "\":" + ki.FirstOrDefault(p => p.Value == result[i - 1].Value).Index.ToString() + ","); } var JsonData = new { rows = result.Select(p => p.Info.ToJObject()), records = data.Count, isup = isup ? "已提交" : ck == null ? "未生成绩效表" : "未提交", total = total, deptname = deptName }; return(Content(JsonData.ToJson())); }