/// <summary> /// 获取岗位树 /// </summary> /// <returns></returns> public JsonResult GetPostTree(int deptId = -1, int showCheckBox = 0, string ids = "") { var postIds = ids.GetArray(); var allDept = _deptManager.GetAllDept(CurrentTenant.TenantId); var allPost = _postManager.GetAllPost(CurrentTenant.TenantId); var rootNode = new EasyuiTreeNode(); if (deptId == -1) { rootNode = GetChildPostTree(new SysDepartment { DeptId = 0, DeptName = CurrentTenant.TenantName }, allDept, allPost, showCheckBox, postIds); } else { //rootNode = GetDeptPostTreeNode(deptId, allDept, allPost); SysDepartment dept = new SysDepartment { DeptId = 0, DeptName = CurrentTenant.TenantName }; if (deptId > 0) { dept = allDept.FirstOrDefault(p => p.DeptId == deptId); } if (dept != null) { rootNode = new EasyuiTreeNode() { id = dept.DeptId + "_0", text = dept.DeptName + "[" + RetechWing.LanguageResources.Dept.Department + "]" }; foreach (var item in allPost.Where(p => p.ParentId == 0 && p.DeptId == deptId)) { rootNode.children.Add(GetChildPosts(item, allPost, showCheckBox, postIds)); } } } return(Json(new[] { rootNode }, JsonRequestBehavior.AllowGet)); }
public JsonResult SelectDepts(string pname, int pageIndex, int pageSize, string ids = "") { int total; var list = _deptManager.GetAllDept(out total, (pageIndex - 1) * pageSize + 1, pageSize, CurrentTenant.TenantId, pname); var deptIds = ids.GetArray(); var dataList = list.Select(p => new { p.DeptId, p.DeptName, p.DeptCode, p.ParentName, IsSelected = deptIds.Contains(p.DeptId) ? "1" : "0" }); return(Json(new { dataList, totalRecord = total }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 设置审批流程时用 /// </summary> /// <param name="wayType"></param> /// <param name="ids"></param> /// <param name="parentDeptId"></param> /// <returns></returns> public JsonResult GetDeptTreeByApprove(int wayType, string ids = "", int parentDeptId = 0) { var deptIds = ids.GetArray(); var allDept = _deptManager.GetAllDept(CurrentTenant.TenantId); var rootNode = GetChildDeptsByApprove( parentDeptId == 0 ? new SysDepartment { DeptId = 0, DeptName = CurrentTenant.TenantName } : allDept.First(p => p.DeptId == parentDeptId), allDept, deptIds, parentDeptId, wayType); return(Json(new[] { rootNode }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 读取文件内容,并添加 /// </summary> /// <param name="excelPath"></param> /// <param name="errorStr"></param> /// <returns></returns> private bool InsertUserList(string excelPath, ref string errorStr) { string RowIds = ""; int total; var listUserSql = _teacherManager.GetTeachers(out total, "", "", 1, int.MaxValue, "UserId DESC").ToList(); var paraUsers = SystemUsers.AsParallel(); foreach (var teacher in listUserSql) { teacher.UserInfo = paraUsers.First(p => p.UserId == teacher.UserId); } string userCodeRepeat = ""; //工号重复 string userEmailRepeat = ""; //邮箱重复 var excelUser = new List <Models.ResTeacher>(); var type = GetExcelContent(excelPath, ref errorStr, ref excelUser); var allDept = _deptManager.GetAllDept(CurrentTenant.TenantId).ToList(); var allPost = _postManager.GetAllPost(CurrentTenant.TenantId).ToList(); var f = true; if (type) { foreach (Models.ResTeacher item in excelUser) { try { f = true; var model = listUserSql.Find(p => p.UserInfo.Username == item.UserInfo.Username); #region 找出部门Id、岗位Id var deptId = 0; var postId = 0; if (!string.IsNullOrWhiteSpace(item.UserInfo.DeptName)) { var de = allDept.Find(p => p.DeptName == item.UserInfo.DeptName); if (de != null) { deptId = de.DeptId; } } if (!string.IsNullOrWhiteSpace(item.UserInfo.PostName)) { var po = allPost.Find(p => p.PostName == item.UserInfo.PostName); if (po != null) { postId = po.PostId; } } #endregion if (model != null) { #region 验证邮箱与工号是否已经存在 var m1 = listUserSql.Find(p => p.UserInfo.Email == item.UserInfo.Email && p.UserInfo.Username != item.UserInfo.Username); var m2 = listUserSql.Find(p => p.UserInfo.UserCode == item.UserInfo.UserCode && p.UserInfo.Username != item.UserInfo.Username); if (m1 != null) { userEmailRepeat += item.UserInfo.RowId + ","; f = false; } if (m2 != null) { userCodeRepeat += item.UserInfo.RowId + ","; f = false; } #endregion if (f) { model.UserInfo.UserCode = item.UserInfo.UserCode; model.UserInfo.Email = item.UserInfo.Email; model.UserInfo.Sex = item.UserInfo.Sex; model.UserInfo.Realname = item.UserInfo.Realname; model.UserInfo.DeptId = deptId == 0 ? model.UserInfo.DeptId : deptId; model.UserInfo.PostId = postId == 0 ? model.UserInfo.PostId : postId; model.UserInfo.Status = 0; model.UserInfo.DeptId = deptId; model.UserInfo.PostId = postId; model.UserInfo.Photo = "~/images/userheader/default.jpg"; model.UserInfo.Phone = ""; model.UserInfo.TenantId = CurrentTenant.TenantId; model.UserInfo.Password = "******".GetMd5(2); model.UserInfo.Level = 1; _teacherManager.SaveTeacher(model); } } else { #region 验证邮箱与工号是否已经存在 var m1 = listUserSql.Find(p => p.UserInfo.Email == item.UserInfo.Email); var m2 = listUserSql.Find(p => p.UserInfo.UserCode == item.UserInfo.UserCode); if (m1 != null) { userEmailRepeat += item.UserInfo.RowId + ","; f = false; } if (m2 != null) { userCodeRepeat += item.UserInfo.RowId + ","; f = false; } #endregion if (f) { item.UserInfo.Status = 0; item.UserInfo.DeptId = deptId; item.UserInfo.PostId = postId; item.UserInfo.Photo = "~/images/userheader/default.jpg"; item.UserInfo.Phone = ""; item.UserInfo.TenantId = CurrentTenant.TenantId; item.UserInfo.Password = "******".GetMd5(2); item.UserInfo.Level = 1; item.UserInfo.NamePin = item.UserInfo.Realname.GetPy(); _teacherManager.SaveTeacher(item); } } } catch { RowIds += item.UserInfo.RowId + ","; } } } BusinessCache.SystemCache.RemoveCacheUser(); if (RowIds != "") { errorStr = errorStr + string.Format("<br /> " + "第{0}行,数据有误!", RowIds.TrimEnd(',')); } if (userCodeRepeat != "") { errorStr = errorStr + string.Format("<br /> " + "第{0}行,工号在系统已经存在!", userCodeRepeat.TrimEnd(',')); } if (userEmailRepeat != "") { errorStr = errorStr + string.Format("<br /> " + "第{0}行,邮箱在系统已经存在!", userEmailRepeat.TrimEnd(',')); } return(type); }
/// <summary> /// 读取文件内容,并添加 /// </summary> /// <param name="excelPath"></param> /// <param name="errorStr"></param> /// <returns></returns> private bool InsertUserList(string excelPath, ref string errorStr) { string RowIds = ""; int total; var listUserSql = _userManager.GetAllUsers(out total, CurrentTenant.TenantId, "", "", "", "", 0, 0, int.MaxValue).ToList(); string userCodeRepeat = ""; //工号重复 string userEmailRepeat = ""; //邮箱重复 var excelUser = new List <SysUser>(); var type = GetExcelContent(excelPath, ref errorStr, ref excelUser); var allDept = _deptManager.GetAllDept(CurrentTenant.TenantId).ToList(); var allPost = _postManager.GetAllPost(CurrentTenant.TenantId).ToList(); var f = true; if (type) { foreach (SysUser item in excelUser) { try { f = true; SysUser model = listUserSql.Find(p => p.Username == item.Username); #region 找出部门Id、岗位Id var deptId = 0; var postId = 0; if (!string.IsNullOrWhiteSpace(item.DeptName)) { //现在匹配部门编码 var de = allDept.Find(p => p.DeptCode == item.DeptName); if (de != null) { deptId = de.DeptId; } } if (deptId > 0) { if (!string.IsNullOrWhiteSpace(item.PostName)) { var po = allPost.Find(p => p.PostName == item.PostName && p.DeptId == deptId); if (po != null) { postId = po.PostId; } } } #endregion if (model != null) { #region 验证邮箱与工号是否已经存在 var m1 = listUserSql.Find(p => p.Email == item.Email && p.Username != item.Username); var m2 = listUserSql.Find(p => p.UserCode == item.UserCode && p.Username != item.Username); if (m1 != null) { userEmailRepeat += item.RowId + ","; f = false; } if (m2 != null) { userCodeRepeat += item.RowId + ","; f = false; } #endregion if (f) { model.UserCode = item.UserCode; model.Email = item.Email; model.Sex = item.Sex; if (item.Photo.Contains("woman.png") || item.Photo.Contains("man.png")) { if (model.Sex == 2) { model.Photo = "~/UploadFiles/UserPhoto/woman.png"; } else { model.Photo = "~/UploadFiles/UserPhoto/man.png"; } } model.Realname = item.Realname; model.Lookup = item.Realname.GetPy(); model.DeptId = deptId == 0 ? model.DeptId : deptId; model.PostId = postId == 0 ? model.PostId : postId; _userManager.UpdateUser(model); } } else { #region 验证邮箱与工号是否已经存在 var m1 = listUserSql.Find(p => p.Email == item.Email); var m2 = listUserSql.Find(p => p.UserCode == item.UserCode); if (m1 != null) { userEmailRepeat += item.RowId + ","; f = false; } if (m2 != null) { userCodeRepeat += item.RowId + ","; f = false; } #endregion if (f) { item.Status = 0; item.DeptId = deptId; item.PostId = postId; if (item.Sex == 2) { item.Photo = "~/UploadFiles/UserPhoto/woman.png"; } else { item.Photo = "~/UploadFiles/UserPhoto/man.png"; } item.Phone = ""; item.TenantId = CurrentTenant.TenantId; item.Password = "******".GetMd5(2); item.Level = 1; _userManager.AddUser(item); } } } catch { RowIds += item.RowId + ","; } } } if (RowIds != "") { errorStr = errorStr + string.Format("<br /> " + "第{0}行,数据有误!", RowIds.TrimEnd(',')); } if (userCodeRepeat != "") { errorStr = errorStr + string.Format("<br /> " + "第{0}行,工号在系统已经存在!", userCodeRepeat.TrimEnd(',')); } if (userEmailRepeat != "") { errorStr = errorStr + string.Format("<br /> " + "第{0}行,邮箱在系统已经存在!", userEmailRepeat.TrimEnd(',')); } return(type); }