/// <summary> /// 获取用户组人员 /// </summary> /// <param name="code">用户组编码</param> /// <param name="departments">部门范围权限</param> /// <param name="departmentScope">部门业务权限</param> /// <param name="branchID">登录人机构ID</param> /// <param name="departmentID">登录人部门ID</param> /// <param name="userID">登录人ID</param> /// <returns></returns> public IQueryable <ORG_User> GetGroupUsers(SysEntities db, string code, int departmentScope, string departments, int branchID, int departmentID, int userID) { // 获取特定用户组所有人员 var query = from a in db.ORG_User join b in db.ORG_GroupUser on a.ID equals b.ORG_User_ID join c in db.ORG_Group on b.ORG_Group_ID equals c.ID where c.Code == code && a.XYBZ == "Y" && c.XYBZ == "Y" select a; if (departmentScope == (int)DepartmentScopeAuthority.无限制)//无限制 { if (!string.IsNullOrEmpty(departments)) { query = from a in query join b in db.ORG_Department on a.ORG_Department_ID equals b.ID where a.XYBZ == "Y" && b.XYBZ == "Y" && departments.Split(',').Contains(b.ID.ToString()) select a; } } else if (departmentScope == (int)DepartmentScopeAuthority.本机构及下属机构)//本机构及下属机构 { //查询本机构及下属机构所有部门数据 var branch = db.ORG_Department.FirstOrDefault(o => o.ID == branchID); query = from a in query join b in db.ORG_Department on a.ORG_Department_ID equals b.ID where a.XYBZ == "Y" && b.XYBZ == "Y" && b.LeftValue >= branch.LeftValue && b.RightValue <= branch.RightValue select a; } else if (departmentScope == (int)DepartmentScopeAuthority.本机构) //本机构 { query = from a in query join b in db.ORG_Department on a.ORG_Department_ID equals b.ID where a.XYBZ == "Y" && b.XYBZ == "Y" && b.BranchID == branchID select a; } else if (departmentScope == (int)DepartmentScopeAuthority.本部门及其下属部门)//本部门及其下属部门 { //当前用户所属部门 ORG_Department department = db.ORG_Department.FirstOrDefault(o => o.ID == departmentID); //查询本部门及下属部门所有部门数据 query = from a in query join b in db.ORG_Department on a.ORG_Department_ID equals b.ID where a.XYBZ == "Y" && b.XYBZ == "Y" && b.LeftValue >= department.LeftValue && b.RightValue <= department.RightValue select a; } else if (departmentScope == (int)DepartmentScopeAuthority.本部门) //本部门 { query = query.Where(c => c.XYBZ == "Y" && c.ORG_Department_ID == departmentID); } else if (departmentScope == (int)DepartmentScopeAuthority.本人) //本人 { query = query.Where(c => c.XYBZ == "Y" && c.ID == userID); } return(query); }
/// <summary> /// 根据用户组权限获取公司列表(需进行权限判断) /// </summary> /// 责任客服可查询:自己负责的企业 /// 社保客服可查询:所有企业 /// <param name="departmentScope">部门业务权限</param> /// <param name="departments">部门范围权限</param> /// <param name="branchID">登录人机构ID</param> /// <param name="departmentID">登录人部门ID</param> /// <param name="userID">登录人ID</param> public List <CRM_Company> GetCompanyListByGroup(int departmentScope, string departments, int branchID, int departmentID, int userID) { using (SysEntities db = new SysEntities()) { string groupUser_SBKF = "SBKF"; // 用户组中“社保客服”的编码 string groupUser_ZRKF = "ZRKF"; // 用户组中“责任客服”的编码 bool isUser_ZRKF = IsUserGroup(groupUser_ZRKF, userID); bool isUser_SBKF = IsUserGroup(groupUser_SBKF, userID); var query = db.CRM_Company.Where(o => true); if (isUser_SBKF) // 社保客服可以看所有的企业 { // 企业不需要做任何过滤 return(query.ToList()); } #region 权限获取 var people = db.ORG_User.Where(o => true); // 所有员工 switch (departmentScope) { case (int)Common.DepartmentScopeAuthority.无限制: // 无限制 //不做任何逻辑判断,查询所有部门数据 if (!string.IsNullOrEmpty(departments)) { // 获取特定用户组所有人员 if (departments != "") { int[] departmentList = Array.ConvertAll <string, int>(departments.Split(','), delegate(string s) { return(int.Parse(s)); }); people = from a in db.ORG_User join b in db.ORG_Department on a.ORG_Department_ID equals b.ID where a.XYBZ == "Y" && b.XYBZ == "Y" && departmentList.Contains(b.ID) select a; } } break; case (int)Common.DepartmentScopeAuthority.本机构及下属机构: //当前用户直属机构 //查询本机构及下属机构所有部门数据 var branch = db.ORG_Department.FirstOrDefault(o => o.ID == userID); people = from a in db.ORG_User join b in db.ORG_Department on a.ORG_Department_ID equals b.ID where a.XYBZ == "Y" && b.XYBZ == "Y" && b.LeftValue >= branch.LeftValue && b.RightValue <= branch.RightValue select a; break; case (int)Common.DepartmentScopeAuthority.本机构: //查询本机构所有部门数据 people = from a in db.ORG_User join b in db.ORG_Department on a.ORG_Department_ID equals b.ID where a.XYBZ == "Y" && b.XYBZ == "Y" && b.BranchID == branchID select a; break; case (int)Common.DepartmentScopeAuthority.本部门及其下属部门: //当前用户所属部门 ORG_Department department = db.ORG_Department.FirstOrDefault(o => o.ID == departmentID); //查询本部门及下属部门所有部门数据 people = from a in db.ORG_User join b in db.ORG_Department on a.ORG_Department_ID equals b.ID where a.XYBZ == "Y" && b.XYBZ == "Y" && b.LeftValue >= department.LeftValue && b.RightValue <= department.RightValue select a; break; case (int)Common.DepartmentScopeAuthority.本部门: //查询本部门所有用户数据 people = from a in db.ORG_User.Where(o => o.XYBZ == "Y") join b in db.ORG_Department.Where(o => o.XYBZ == "Y" && o.BranchID == departmentID) on a.ORG_Department_ID equals b.ID select a; break; case (int)Common.DepartmentScopeAuthority.本人: people = from a in db.ORG_User.Where(o => o.ID == userID) select a; break; } #endregion #region 获取符合条件的企业信息 if (isUser_ZRKF) { // 获取责任客服负责的企业 query = (from cc in query join cctb in db.CRM_CompanyToBranch on cc.ID equals cctb.CRM_Company_ID join f in people on cctb.UserID_ZR equals f.ID select cc); } #endregion return(query.ToList()); } }
/// <summary> /// 根据企业名称查询企业(销售用)【带权限】 /// </summary> /// <param name="companyName">企业名称</param> /// <param name="branchID">所属分支机构</param> /// <returns></returns> public IQueryable <CRM_CompanyView> GetCompanyListForSales(SysEntities db, string companyName, int?userID_XS, int branchID, string menuID, int departmentScope, int userID, int userDepartmentID, string departments) { List <CRM_CompanyView> list = new List <CRM_CompanyView>(); var query = from a in db.CRM_Company join b in db.CRM_CompanyToBranch on a.ID equals b.CRM_Company_ID join d in db.ORG_User on b.UserID_ZR equals d.ID into tmpzr from zr in tmpzr.DefaultIfEmpty() join c in db.ORG_User on b.UserID_XS equals c.ID into tmpxs from xs in tmpxs.DefaultIfEmpty() where a.CompanyName.Contains(companyName) && (userID_XS == null || b.UserID_XS == userID_XS) select new CRM_CompanyView() { ID = b.ID, CRM_Company_ID = a.ID, CompanyCode = a.CompanyCode, CompanyName = a.CompanyName, UserID_XS = b.UserID_XS, OperateStatus = a.OperateStatus, CreateTime = a.CreateTime, UserID_ZR = b.UserID_ZR, UserID_XS_Name = xs.RName, UserID_ZR_Name = zr.RName }; if (departmentScope == (int)DepartmentScopeAuthority.无限制)//无限制 { if (!string.IsNullOrEmpty(departments)) { var people = from a in db.ORG_User where departments.Split(',').Contains(a.ORG_Department_ID.ToString()) select a; query = from a in query join c in people on a.UserID_XS equals c.ID select a; } } else if (departmentScope == (int)DepartmentScopeAuthority.本机构及下属机构)//本机构及下属机构 { //当前用户直属机构 //查询本机构及下属机构所有部门数据 var branch = db.ORG_Department.FirstOrDefault(o => o.ID == branchID); var people = from a in db.ORG_User join b in db.ORG_Department on a.ORG_Department_ID equals b.ID where a.XYBZ == "Y" && b.XYBZ == "Y" && b.LeftValue >= branch.LeftValue && b.RightValue <= branch.RightValue select a; query = from cc in query join f in people on cc.UserID_XS equals f.ID select cc; } else if (departmentScope == (int)DepartmentScopeAuthority.本机构) //本机构 { //查询本机构所有部门数据 var people = from a in db.ORG_User join b in db.ORG_Department on a.ORG_Department_ID equals b.ID where a.XYBZ == "Y" && b.XYBZ == "Y" && b.BranchID == branchID select a; query = (from cc in query join f in people on cc.UserID_XS equals f.ID select cc); } else if (departmentScope == (int)DepartmentScopeAuthority.本部门及其下属部门)//本部门及其下属部门 { //当前用户所属部门 ORG_Department department = db.ORG_Department.FirstOrDefault(o => o.ID == userDepartmentID); //查询本部门及下属部门所有部门数据 var people = from a in db.ORG_User join b in db.ORG_Department on a.ORG_Department_ID equals b.ID where a.XYBZ == "Y" && b.XYBZ == "Y" && b.LeftValue >= department.LeftValue && b.RightValue <= department.RightValue select a; query = (from cc in query join f in people on cc.UserID_XS equals f.ID select cc); } else if (departmentScope == (int)DepartmentScopeAuthority.本部门) //本部门 { //查询本部门所有用户数据 var people = from a in db.ORG_User.Where(o => o.XYBZ == "Y") join b in db.ORG_Department.Where(o => o.XYBZ == "Y" && o.BranchID == userDepartmentID) on a.ORG_Department_ID equals b.ID select a; query = (from cc in query join f in people on cc.UserID_XS equals f.ID select cc); } else if (departmentScope == (int)DepartmentScopeAuthority.本人) //本人 { query = (from cc in query where cc.UserID_XS == userID select cc); } query = query.OrderByDescending(o => o.CreateTime); return(query); }