public ActionResult GetRealListJson(string departmentid) { IList <RoleEntity> list = new List <RoleEntity>(); list = postCache.GetRealList(departmentid).OrderBy(x => x.SortCode).ToList(); return(Content(list.ToJson())); }
public string ImportInfo(string repeatdata) { if (OperatorProvider.Provider.Current().IsSystem) { return("超级管理员无此操作权限"); } var curUser = OperatorProvider.Provider.Current(); string message = "请选择格式正确的文件再导入!"; string falseMessage = ""; int count = HttpContext.Request.Files.Count; try { List <string> listIds = new List <string>(); if (count > 0) { if (HttpContext.Request.Files.Count > 2) { return("请按正确的方式导入文件,一次上传最多支持两份文件(即一份excel数据文件,一份图片压缩文件)."); } HttpPostedFileBase file = HttpContext.Request.Files[0]; string hiddenDirectory = string.Empty; Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(); if (string.IsNullOrEmpty(file.FileName)) { return(message); } if (!(file.FileName.ToLower().Substring(file.FileName.ToLower().IndexOf('.')).Contains("xls") || file.FileName.ToLower().Substring(file.FileName.ToLower().IndexOf('.')).Contains("xlsx"))) { return(message); } string fileName1 = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file.FileName); file.SaveAs(Server.MapPath("~/Resource/temp/" + fileName1)); wb.Open(Server.MapPath("~/Resource/temp/" + fileName1)); Worksheet sheets = wb.Worksheets[0]; Aspose.Cells.Cells cells = sheets.Cells; DataTable dt = cells.ExportDataTable(1, 0, cells.MaxDataRow, cells.MaxColumn + 1, true); //记录错误信息 List <string> resultlist = new List <string>(); List <DepartmentEntity> dlist = departmentBLL.GetList().OrderBy(p => p.SortCode).ToList(); int total = 0; #region 反违章指标部分 #region 对象装载 List <ImportQuantifyIndex> list = new List <ImportQuantifyIndex>(); //先获取到职务列表; for (int i = 0; i < dt.Rows.Count; i++) { string resultmessage = "第" + (i + 1).ToString() + "行数据"; //显示错误 bool isadddobj = true; //年度 string yearvalue = dt.Columns.Contains("年度") ? dt.Rows[i]["年度"].ToString().Trim() : string.Empty; //部门 string deptname = dt.Columns.Contains("部门") ? dt.Rows[i]["部门"].ToString().Trim() : string.Empty; //岗位 string dutyname = dt.Columns.Contains("岗位名称") ? dt.Rows[i]["岗位名称"].ToString().Trim() : string.Empty; //反违章指标 string indexvalue = dt.Columns.Contains("反违章指标") ? dt.Rows[i]["反违章指标"].ToString().Trim() : string.Empty; try { #region 对象集合 ImportQuantifyIndex entity = new ImportQuantifyIndex(); //年度 if (!string.IsNullOrEmpty(yearvalue)) { entity.YearValue = yearvalue; } //反违章指标 if (!string.IsNullOrEmpty(indexvalue)) { entity.IndexValue = indexvalue; } //部门 if (!string.IsNullOrEmpty(deptname)) { if (deptname.Contains("/")) { string[] depts = deptname.Split('/'); var deptlist = dlist.Where(p => p.FullName == depts[0].ToString()).ToList(); if (deptlist.Count() > 0) { var childdeptlist = dlist.Where(p => p.FullName == depts[1].ToString() && p.ParentId == deptlist.FirstOrDefault().DepartmentId).ToList(); if (childdeptlist.Count() > 0) { var dutydeptentity = childdeptlist.FirstOrDefault(); entity.DeptId = dutydeptentity.DepartmentId; entity.DeptName = dutydeptentity.FullName; } } } else { var deptlist = dlist.Where(e => e.FullName == deptname).ToList(); if (deptlist.Count() > 0) { var dutydeptentity = deptlist.FirstOrDefault(); entity.DeptId = dutydeptentity.DepartmentId; entity.DeptName = dutydeptentity.FullName; } } } //岗位 if (!string.IsNullOrEmpty(dutyname) && !string.IsNullOrEmpty(entity.DeptId)) { IList <RoleEntity> rolelist = new List <RoleEntity>(); rolelist = postCache.GetRealList(entity.DeptId).Where(p => p.FullName == dutyname).OrderBy(x => x.SortCode).ToList(); if (rolelist.Count() > 0) { var roleDefault = rolelist.FirstOrDefault(); entity.DutyId = roleDefault.RoleId; entity.DutyName = roleDefault.FullName; } } #endregion #region 必填验证 //部门 if (string.IsNullOrEmpty(deptname)) { resultmessage += "部门为空、"; isadddobj = false; } else { if (string.IsNullOrEmpty(entity.DeptId)) { resultmessage += "部门填写错误或不存在、"; isadddobj = false; } } //岗位 if (string.IsNullOrEmpty(dutyname)) { resultmessage += "岗位为空、"; isadddobj = false; } else { if (!string.IsNullOrEmpty(entity.DeptId)) { if (string.IsNullOrEmpty(entity.DutyId)) { resultmessage += "部门下的岗位不存在、"; isadddobj = false; } } } //年度 if (string.IsNullOrEmpty(yearvalue)) { resultmessage += "年度为空、"; isadddobj = false; } //反违章指标 if (string.IsNullOrEmpty(indexvalue)) { resultmessage += "反违章指标为空、"; isadddobj = false; } if (isadddobj) { list.Add(entity); } else { if (!string.IsNullOrEmpty(resultmessage)) { resultmessage = resultmessage.Substring(0, resultmessage.Length - 1) + ",无法正常导入"; resultlist.Add(resultmessage); } } #endregion } catch { resultmessage += "出现数据异常,无法正常导入"; resultlist.Add(resultmessage); } } if (resultlist.Count > 0) { foreach (string str in resultlist) { falseMessage += str + "</br>"; } } #endregion #region 反违章指标数据集合 foreach (ImportQuantifyIndex entity in list) { string keyValue = string.Empty; int excuteVal = 0; //基本信息 LllegalQuantifyIndexEntity baseentity = new LllegalQuantifyIndexEntity(); //获取数据 var data = lllegalquantifyindexbll.GetList(string.Empty).Where(p => p.DEPTID == entity.DeptId && p.DUTYID == entity.DutyId && p.YEARVALUE == entity.YearValue); if (data.Count() > 0) { //覆盖操作 if (repeatdata == "1") { baseentity = data.FirstOrDefault(); if (null != baseentity) { keyValue = baseentity.ID; } excuteVal = 1; } else //跳过 { excuteVal = 0; } } else { excuteVal = 1; } if (excuteVal > 0) { baseentity.DEPTID = entity.DeptId; //部门id baseentity.DEPTNAME = entity.DeptName; //部门名称 baseentity.DUTYID = entity.DutyId; //岗位id baseentity.DUTYNAME = entity.DutyName; //岗位名称 baseentity.INDEXVALUE = int.Parse(entity.IndexValue); //反违章指标 baseentity.YEARVALUE = entity.YearValue; //年度 baseentity.MONTHVALUE = "01,02,03,04,05,06,07,08,09,10,11,12"; lllegalquantifyindexbll.SaveForm(keyValue, baseentity); total += 1; } } #endregion #endregion count = dt.Rows.Count; message = "共有" + count.ToString() + "条记录,成功导入" + total.ToString() + "条,失败" + (count - total).ToString() + "条"; message += "</br>" + falseMessage; } } catch (Exception ex) { return(ex.Message); } return(message); }