/// <summary> /// 启用管理员账号 /// </summary> /// <param name="keyValue">主键值</param> public void AddAdmin(string keyValue) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); //先找到当前机构的角色id var roleEnity = db.FindEntity <RoleEntity>(t => t.OrganizeId == keyValue); if (roleEnity != null) { //再给当前角色添加菜单权限 var authorize = db.FindEntity <AuthorizeEntity>(t => t.ObjectId == roleEnity.RoleId && t.ItemId == "26cba400-c984-4f6b-b025-76d4dbf54184"); if (authorize == null) { AuthorizeEntity authorizeEntity2 = new AuthorizeEntity(); authorizeEntity2.Create(); authorizeEntity2.Category = 2; //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeEntity2.ObjectId = roleEnity.RoleId; //角色id,角色限定了机构和部门 authorizeEntity2.ItemType = 1; //项目类型: 1 - 菜单2 - 按钮3 - 视图4表单 authorizeEntity2.ItemId = "26cba400-c984-4f6b-b025-76d4dbf54184"; //项目主键 authorizeEntity2.SortCode = 8; db.Insert(authorizeEntity2); db.Commit(); } } //修改平台管理员标识 OrganizeEntity organizeEntity = GetEntity(keyValue); organizeEntity.PTAdminMark = 1; this.BaseRepository().Update(organizeEntity); }
/// <summary> /// 添加授权 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="moduleIds">功能Id</param> /// <param name="moduleButtonIds">按钮Id</param> /// <param name="moduleColumnIds">视图Id</param> /// <param name="authorizeDataList">数据权限</param> public void SaveAuthorize(AuthorizeTypeEnum authorizeType, string objectId, string[] moduleIds, string[] moduleButtonIds, string[] moduleColumnIds, IEnumerable <AuthorizeDataEntity> authorizeDataList) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { #region 功能 int SortCode = 1; db.Delete <AuthorizeEntity>(t => t.ObjectId == objectId); if (moduleIds.Length > 0) { foreach (string item in moduleIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = 1; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; db.Insert(authorizeEntity); } } else { db.Delete <AuthorizeDataEntity>(objectId, "ObjectId"); } #endregion if (moduleColumnIds.Length > 0) { foreach (string mId in moduleColumnIds) { #region 数据权限 SortCode = 1; int index = 0; db.ExecuteBySql(string.Format("delete from BASE_AUTHORIZEDATA where ObjectId='{0}' and resourceid='{1}'", objectId, mId)); foreach (AuthorizeDataEntity authorizeDataEntity in authorizeDataList) { authorizeDataEntity.Create(); authorizeDataEntity.Category = (int)authorizeType; authorizeDataEntity.ObjectId = objectId; authorizeDataEntity.ResourceId = mId; // authorizeDataEntity.Module = "Department"; authorizeDataEntity.SortCode = SortCode++; db.Insert(authorizeDataEntity); index++; } #endregion } } db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, TelphoneLiangVipEntity entity) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); if (!string.IsNullOrEmpty(keyValue)) { entity.Modify(keyValue); this.BaseRepository().Update(entity); } else { entity.Create(); this.BaseRepository().Insert(entity); //修改机构表中的vip标识位 var orgEntity = db.FindEntity <OrganizeEntity>(t => t.OrganizeId == entity.OrganizeId); orgEntity.VipMark = 1; db.Update(orgEntity); //根据机构id获取角色id var roleEntity = db.FindEntity <RoleEntity>(t => t.OrganizeId == entity.OrganizeId); //如果上传号码上限>0,添加'靓号库'菜单 if (entity.UploadMax > 0) { var authorize = db.FindEntity <AuthorizeEntity>(t => t.ObjectId == roleEntity.RoleId && t.ItemId == "16cea332-0204-4f7d-a510-0426329205ff"); if (authorize != null) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = 2; //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeEntity.ObjectId = roleEntity.RoleId; //角色id,角色限定了机构和部门 authorizeEntity.ItemType = 1; //项目类型: 1 - 菜单2 - 按钮3 - 视图4表单 authorizeEntity.ItemId = "16cea332-0204-4f7d-a510-0426329205ff"; //项目主键 authorizeEntity.SortCode = 100; db.Insert(authorizeEntity); } } //如果代售号码上限>0,添加'代售靓号库'菜单 if (entity.OtherMax > 0) { var authorize = db.FindEntity <AuthorizeEntity>(t => t.ObjectId == roleEntity.RoleId && t.ItemId == "effbaf18-e4d1-4250-9aa0-370422634a21"); if (authorize != null) { AuthorizeEntity authorizeEntity2 = new AuthorizeEntity(); authorizeEntity2.Create(); authorizeEntity2.Category = 2; //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeEntity2.ObjectId = roleEntity.RoleId; //角色id,角色限定了机构和部门 authorizeEntity2.ItemType = 1; //项目类型: 1 - 菜单2 - 按钮3 - 视图4表单 authorizeEntity2.ItemId = "effbaf18-e4d1-4250-9aa0-370422634a21"; //项目主键 authorizeEntity2.SortCode = 100; db.Insert(authorizeEntity2); } } db.Commit(); } }
/// <summary> /// 添加授权 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="moduleIds">功能Id</param> /// <param name="moduleButtonIds">按钮Id</param> /// <param name="moduleColumnIds">视图Id</param> /// <param name="authorizeDataList">数据权限</param> public void SaveAuthorize(AuthorizeTypeEnum authorizeType, string objectId, string[] moduleIds, string[] moduleButtonIds, string[] moduleColumnIds, IEnumerable <AuthorizeDataEntity> authorizeDataList) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { db.Delete <AuthorizeEntity>(t => t.ObjectId == objectId); #region 功能 int SortCode = 1; foreach (string item in moduleIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = 1; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; db.Insert(authorizeEntity); } #endregion #region 钮 SortCode = 1; foreach (string item in moduleButtonIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = 2; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; db.Insert(authorizeEntity); } #endregion #region 视图 SortCode = 1; foreach (string item in moduleColumnIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = 3; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; db.Insert(authorizeEntity); } #endregion #region 数据权限 SortCode = 1; db.Delete <AuthorizeDataEntity>(objectId, "ObjectId"); int index = 0; foreach (AuthorizeDataEntity authorizeDataEntity in authorizeDataList) { authorizeDataEntity.Create(); authorizeDataEntity.Category = (int)authorizeType; authorizeDataEntity.ObjectId = objectId; // authorizeDataEntity.Module = "Department"; authorizeDataEntity.SortCode = SortCode++; db.Insert(authorizeDataEntity); index++; } #endregion db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 添加授权 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="moduleIds">功能Id</param> /// <param name="moduleButtonIds">按钮Id</param> /// <param name="moduleColumnIds">视图Id</param> /// <param name="authorizeDataList">数据权限</param> public void SaveAuthorize(AuthorizeTypeEnum authorizeType, string objectId, string[] moduleIds, string[] moduleButtonIds, string[] moduleColumnIds, IEnumerable <AuthorizeDataEntity> authorizeDataList) { //先清除历史授权数据 int isSucc = this.BaseRepository().Delete <AuthorizeDataEntity>(u => u.ObjectId == objectId); if (isSucc >= 0) { #region 功能 List <AuthorizeEntity> authorizeMenuList = new List <AuthorizeEntity>(); for (int i = 1; i <= moduleIds.Length; i++) { AuthorizeEntity authorize = new AuthorizeEntity { Category = (int)authorizeType, ObjectId = objectId, ItemType = 1, ItemId = moduleIds[i - 1], SortCode = i }; authorize.Create(); authorizeMenuList.Add(authorize); } //保存 int res = this.BaseRepository().Insert(authorizeMenuList); #endregion 功能 #region 钮 List <AuthorizeEntity> authorizeButtonList = new List <AuthorizeEntity>(); for (int i = 1; i <= moduleButtonIds.Length; i++) { AuthorizeEntity authorize = new AuthorizeEntity { Category = (int)authorizeType, ObjectId = objectId, ItemType = 2, ItemId = moduleButtonIds[i - 1], SortCode = i }; authorize.Create(); authorizeButtonList.Add(authorize); } //保存 res = this.BaseRepository().Insert(authorizeButtonList); #endregion 钮 #region 视图 List <AuthorizeEntity> authorizeViewList = new List <AuthorizeEntity>(); for (int i = 1; i <= moduleColumnIds.Length; i++) { AuthorizeEntity authorize = new AuthorizeEntity { Category = (int)authorizeType, ObjectId = objectId, ItemType = 3, ItemId = moduleColumnIds[i - 1], SortCode = i }; authorize.Create(); authorizeViewList.Add(authorize); } //保存 res = this.BaseRepository().Insert(authorizeViewList); #endregion 视图 #region 数据权限 //清除数据权限 isSucc = this .BaseRepository().Delete <AuthorizeDataEntity>(u => u.ObjectId == objectId); int sortCode = 1; List <AuthorizeDataEntity> authorizeDataTempList = new List <AuthorizeDataEntity>(); foreach (AuthorizeDataEntity authorizeData in authorizeDataList) { authorizeData.Category = (int)authorizeType; authorizeData.ObjectId = objectId; authorizeData.SortCode = sortCode++; authorizeData.Create(); authorizeDataTempList.Add(authorizeData); } //保存 this.BaseRepository().Insert(authorizeDataTempList); #endregion 数据权限 } }
/// <summary> /// 新增下级代理 /// </summary> /// <param name="organizeEntity"></param> public void SaveNewAgent(OrganizeEntity organizeEntity) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { #region 新增机构 //父机构 if (organizeEntity.ParentId == null) { throw new Exception("上级机构不能为空!"); } if (organizeEntity.ParentId != "0") { var parentEntity = this.BaseRepository().FindEntity(organizeEntity.ParentId); organizeEntity.Category = parentEntity.Category + 1; //顶级机构 IEnumerable <OrganizeEntity> topList = GetParentIdByOrgId(organizeEntity.ParentId); if (topList.Count() > 0 && string.IsNullOrEmpty(organizeEntity.Img1)) { OrganizeEntity topEntity = topList.First(); organizeEntity.TopOrganizeId = topEntity.OrganizeId;//顶级机构 } } else { organizeEntity.Category = 0; } //如果图片为空 if (string.IsNullOrEmpty(organizeEntity.Img1)) { organizeEntity.Img1 = Config.GetValue("Img1"); organizeEntity.Img2 = Config.GetValue("Img2"); organizeEntity.Img3 = Config.GetValue("Img3"); organizeEntity.Img4 = Config.GetValue("Img4"); } organizeEntity.Create(); db.Insert(organizeEntity); #endregion #region 新增默认管理部门 DepartmentEntity department = new DepartmentEntity(); department.OrganizeId = organizeEntity.OrganizeId; department.ParentId = "0"; department.EnCode = organizeEntity.OuterPhone;//账号 department.FullName = organizeEntity.FullName; department.Create(); db.Insert(department); #endregion #region 新增默认靓号角色 RoleEntity role = new RoleEntity(); role.OrganizeId = organizeEntity.OrganizeId; role.Category = 1; //分类1 - 角色2 - 岗位3 - 职位4 - 工作组 role.EnCode = organizeEntity.OuterPhone; //账号 role.FullName = organizeEntity.FullName; role.Create(); db.Insert(role); #endregion #region 授权功能 //string copyObject = "f7e8ce33-ce79-460f-a24c-d0ed53001477";//复制二级唐山和讯老李17040258888管理 ////临沂大华单独处理 //if (organizeEntity.TopOrganizeId== "a5a962da-57e1-4ad4-87b2-bbdcd1b7cc92" && organizeEntity.Category != 0) //{ // copyObject = "1062959a-bd81-4547-ac9a-c51f750ea237";//珊哥在线管理(只显示机构,其它什么都没有) //} //else //{ // if (organizeEntity.Category < 1) // { // copyObject = "209b63c7-3638-45e7-b24a-cf88f6d5c9dd";//复制唐山和讯老李17040258888管理(零,一级) // } //} string copyObject = "c1139630-d98f-4412-be8e-2c13cfd11380";//默认三级:不显示靓号库,看不到底价 //临沂大华单独处理 if (organizeEntity.TopOrganizeId == "a5a962da-57e1-4ad4-87b2-bbdcd1b7cc92" && organizeEntity.Category != 0) { copyObject = "fbf669b2-e7fc-450d-a3e5-20e005cab567";//测试4级机构 18777777777(只显示机构,其它什么都没有) } else { if (organizeEntity.Category <= 1) { copyObject = "094115aa-4635-4ad0-b798-76d34c6d4e72";//零级:含基础设置 18660999999 } else if (organizeEntity.Category == 2) { copyObject = "12de4dd4-156b-4495-8f43-e235d6de85d2";//二级:可看低价,无基础设置18666666666 } } var AuthorizeList = db.FindList <AuthorizeEntity>(t => t.ObjectId == copyObject); foreach (AuthorizeEntity item in AuthorizeList) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = 2; //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeEntity.ObjectId = role.RoleId; //角色id,角色限定了机构和部门 authorizeEntity.ItemType = item.ItemType; //项目类型: 1 - 菜单2 - 按钮3 - 视图4表单 authorizeEntity.ItemId = item.ItemId; //项目主键 authorizeEntity.SortCode = item.SortCode; db.Insert(authorizeEntity); } #endregion #region 数据权限 就一个 AuthorizeDataEntity authorizeDataEntity = new AuthorizeDataEntity(); authorizeDataEntity.Create(); authorizeDataEntity.AuthorizeType = 4; //授权类型: 1 - 仅限本人2 - 仅限本人及下属3 - 所在部门4 - 所在公司5 - 按明细设置 authorizeDataEntity.Category = 2; //对象分类: 1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeDataEntity.ObjectId = role.RoleId; //角色id,角色限定了机构和部门 authorizeDataEntity.IsRead = 0; authorizeDataEntity.SortCode = 1; db.Insert(authorizeDataEntity); #endregion #region 新增默认用户 UserEntity userEntity = new UserEntity(); userEntity.Create(); userEntity.Account = organizeEntity.OuterPhone; //登录名为机构名拼音首字母organizeEntity.EnCode userEntity.RealName = organizeEntity.Manager; //organizeEntity.FullName userEntity.WeChat = organizeEntity.ShortName; //微信昵称 userEntity.OrganizeId = organizeEntity.OrganizeId; userEntity.DepartmentId = department.DepartmentId; userEntity.RoleId = role.RoleId; userEntity.Gender = 1; userEntity.Secretkey = Md5Helper.MD5(CommonHelper.CreateNo(), 16).ToLower(); userEntity.Password = Md5Helper.MD5(DESEncrypt.Encrypt(Md5Helper.MD5("0000", 32).ToLower(), userEntity.Secretkey).ToLower(), 32).ToLower(); db.Insert(userEntity); #endregion #region 新增默认用户关系 UserRelationEntity userRelationEntity = new UserRelationEntity(); userRelationEntity.Create(); userRelationEntity.Category = 2;//登录名为机构名拼音首字母 userRelationEntity.UserId = userEntity.UserId; userRelationEntity.ObjectId = userEntity.RoleId; db.Insert(userRelationEntity); #endregion db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 保存机构表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="organizeEntity">机构实体</param> /// <returns></returns> public void SaveForm(string keyValue, OrganizeEntity organizeEntity) { if (!string.IsNullOrEmpty(keyValue)) { organizeEntity.Modify(keyValue); this.BaseRepository().Update(organizeEntity); } else { organizeEntity.Create(); organizeEntity.EnCode = Str.PinYin(organizeEntity.FullName);//登录名为机构名拼音首字母 this.BaseRepository().Insert(organizeEntity); IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { //新增默认管理部门 DepartmentEntity department = new DepartmentEntity(); department.OrganizeId = organizeEntity.OrganizeId; department.ParentId = "0"; department.EnCode = organizeEntity.EnCode + "01"; department.FullName = organizeEntity.FullName + "管理部"; department.Create(); db.Insert(department); //新增默认靓号角色 RoleEntity role = new RoleEntity(); role.OrganizeId = organizeEntity.OrganizeId; role.Category = 1;//分类1 - 角色2 - 岗位3 - 职位4 - 工作组 role.EnCode = organizeEntity.EnCode + "01"; role.FullName = organizeEntity.FullName + "管理"; role.Create(); db.Insert(role); #region 授权功能 var AuthorizeList = db.FindList <AuthorizeEntity>(t => t.ObjectId == "48c566d6-3dfb-4b08-8f62-a662642db300"); foreach (AuthorizeEntity item in AuthorizeList) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = 2; //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeEntity.ObjectId = role.RoleId; authorizeEntity.ItemType = item.ItemType; authorizeEntity.ItemId = item.ItemId; authorizeEntity.SortCode = item.SortCode; db.Insert(authorizeEntity); } #endregion #region 数据权限 var authorizeDataList = db.FindList <AuthorizeDataEntity>(t => t.ObjectId == "48c566d6-3dfb-4b08-8f62-a662642db300"); foreach (AuthorizeDataEntity item in authorizeDataList) { AuthorizeDataEntity authorizeDataEntity = new AuthorizeDataEntity(); authorizeDataEntity.Create(); authorizeDataEntity.AuthorizeType = item.AuthorizeType; //授权类型: 1 - 仅限本人2 - 仅限本人及下属3 - 所在部门4 - 所在公司5 - 按明细设置 authorizeDataEntity.Category = 2; //对象分类: 1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeDataEntity.ObjectId = role.RoleId; authorizeDataEntity.IsRead = item.IsRead; authorizeDataEntity.SortCode = item.SortCode; db.Insert(authorizeDataEntity); } #endregion //新增默认用户 UserEntity userEntity = new UserEntity(); userEntity.Create(); userEntity.Account = organizeEntity.EnCode;//登录名为机构名拼音首字母 userEntity.RealName = organizeEntity.FullName; userEntity.OrganizeId = organizeEntity.OrganizeId; userEntity.DepartmentId = department.DepartmentId; userEntity.RoleId = role.RoleId; userEntity.Secretkey = Md5Helper.MD5(CommonHelper.CreateNo(), 16).ToLower(); userEntity.Password = Md5Helper.MD5(DESEncrypt.Encrypt(Md5Helper.MD5("0000", 32).ToLower(), userEntity.Secretkey).ToLower(), 32).ToLower(); db.Insert(userEntity); //新增默认用户关系 UserRelationEntity userRelationEntity = new UserRelationEntity(); userRelationEntity.Create(); userRelationEntity.Category = 2;//登录名为机构名拼音首字母 userRelationEntity.UserId = userEntity.UserId; userRelationEntity.ObjectId = userEntity.RoleId; db.Insert(userRelationEntity); db.Commit(); } catch (Exception) { db.Rollback(); throw; } } }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, TelphoneLiangVipEntity entity) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); if (!string.IsNullOrEmpty(keyValue)) { var oldEntity = db.FindEntity <TelphoneLiangVipEntity>(t => t.Id == keyValue); //加入共享平台 if (entity.ShareMark == 1 && oldEntity.ShareMark != 1) { string shareOrg = RedisCache.Get <string>("ShareOrg"); if (!string.IsNullOrEmpty(shareOrg)) { if (!shareOrg.Contains(entity.OrganizeId)) { RedisCache.Set <string>("ShareOrg", shareOrg + ",'" + entity.OrganizeId + "'"); } } } //取消共享 if (entity.ShareMark != 1 && oldEntity.ShareMark == 1) { string shareOrg = RedisCache.Get <string>("ShareOrg"); if (!string.IsNullOrEmpty(shareOrg)) { RedisCache.Set <string>("ShareOrg", shareOrg.Replace(",'" + entity.OrganizeId + "'", "")); } } entity.Modify(keyValue); this.BaseRepository().Update(entity); } else { entity.Create(); this.BaseRepository().Insert(entity); //修改机构表中的vip标识位 var orgEntity = db.FindEntity <OrganizeEntity>(t => t.OrganizeId == entity.OrganizeId); orgEntity.VipMark = 1; db.Update(orgEntity); //根据机构id获取角色id var roleEntity = db.FindEntity <RoleEntity>(t => t.OrganizeId == entity.OrganizeId); //如果上传号码上限>0,添加'靓号库'菜单,Base_Module菜单id if (entity.UploadMax > 0) { var authorize = db.FindEntity <AuthorizeEntity>(t => t.ObjectId == roleEntity.RoleId && t.ItemId == "16cea332-0204-4f7d-a510-0426329205ff"); if (authorize == null) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = 2; //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeEntity.ObjectId = roleEntity.RoleId; //角色id,角色限定了机构和部门 authorizeEntity.ItemType = 1; //项目类型: 1 - 菜单2 - 按钮3 - 视图4表单 authorizeEntity.ItemId = "16cea332-0204-4f7d-a510-0426329205ff"; //项目主键 authorizeEntity.SortCode = 100; db.Insert(authorizeEntity); } } //如果代售号码上限>0,添加'代售靓号库'菜单,Base_Module菜单id if (entity.OtherMax > 0) { var authorize = db.FindEntity <AuthorizeEntity>(t => t.ObjectId == roleEntity.RoleId && t.ItemId == "effbaf18-e4d1-4250-9aa0-370422634a21"); if (authorize == null) { AuthorizeEntity authorizeEntity2 = new AuthorizeEntity(); authorizeEntity2.Create(); authorizeEntity2.Category = 2; //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeEntity2.ObjectId = roleEntity.RoleId; //角色id,角色限定了机构和部门 authorizeEntity2.ItemType = 1; //项目类型: 1 - 菜单2 - 按钮3 - 视图4表单 authorizeEntity2.ItemId = "effbaf18-e4d1-4250-9aa0-370422634a21"; //项目主键 authorizeEntity2.SortCode = 100; db.Insert(authorizeEntity2); } } //报表 var authorize6 = db.FindEntity <AuthorizeEntity>(t => t.ObjectId == roleEntity.RoleId && t.ItemId == "6"); if (authorize6 == null) { AuthorizeEntity authorizeEntity2 = new AuthorizeEntity(); authorizeEntity2.Create(); authorizeEntity2.Category = 2; //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeEntity2.ObjectId = roleEntity.RoleId; //角色id,角色限定了机构和部门 authorizeEntity2.ItemType = 1; //项目类型: 1 - 菜单2 - 按钮3 - 视图4表单 authorizeEntity2.ItemId = "6"; //项目主键 authorizeEntity2.SortCode = 12; db.Insert(authorizeEntity2); } //靓号销售报表 var authorize61 = db.FindEntity <AuthorizeEntity>(t => t.ObjectId == roleEntity.RoleId && t.ItemId == "44498bc7-33ac-418f-a0f8-c88241afa118"); if (authorize61 == null) { AuthorizeEntity authorizeEntity2 = new AuthorizeEntity(); authorizeEntity2.Create(); authorizeEntity2.Category = 2; //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeEntity2.ObjectId = roleEntity.RoleId; //角色id,角色限定了机构和部门 authorizeEntity2.ItemType = 1; //项目类型: 1 - 菜单2 - 按钮3 - 视图4表单 authorizeEntity2.ItemId = "44498bc7-33ac-418f-a0f8-c88241afa118"; //项目主键 authorizeEntity2.SortCode = 13; db.Insert(authorizeEntity2); } db.Commit(); //添加缓存分享平台 if (entity.ShareMark == 1) { string shareOrg = RedisCache.Get <string>("ShareOrg"); if (!string.IsNullOrEmpty(shareOrg)) { RedisCache.Set <string>("ShareOrg", shareOrg + ",'" + entity.OrganizeId + "'"); } } } }
/// <summary> /// 新增下级代理 /// </summary> /// <param name="organizeEntity"></param> public void SaveNewAgent(OrganizeEntity organizeEntity) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { #region 新增机构 //父机构 if (organizeEntity.ParentId == null) { organizeEntity.ParentId = "0"; //throw new Exception("上级机构不能为空!"); } if (organizeEntity.ParentId != "0") { var parentEntity = this.BaseRepository().FindEntity(organizeEntity.ParentId); organizeEntity.Category = parentEntity.Category + 1; //顶级机构 IEnumerable <OrganizeEntity> topList = GetParentIdByOrgId(organizeEntity.ParentId); if (topList.Count() > 0 && string.IsNullOrEmpty(organizeEntity.Img1)) { OrganizeEntity topEntity = topList.First(); organizeEntity.TopOrganizeId = topEntity.OrganizeId;//顶级机构 } } else { organizeEntity.Category = 0; } organizeEntity.Create(); #endregion #region 新增默认管理部门 DepartmentEntity department = new DepartmentEntity(); department.OrganizeId = organizeEntity.OrganizeId; department.ParentId = "0"; department.EnCode = organizeEntity.OuterPhone;//账号 department.FullName = organizeEntity.FullName; department.Create(); db.Insert(department); #endregion #region 新增默认靓号角色 RoleEntity role = new RoleEntity(); role.OrganizeId = organizeEntity.OrganizeId; role.Category = 1; //分类1 - 角色2 - 岗位3 - 职位4 - 工作组 role.EnCode = organizeEntity.OuterPhone; //账号 role.FullName = organizeEntity.FullName; role.Create(); db.Insert(role); #endregion #region 授权功能 var AuthorizeList = db.FindList <AuthorizeEntity>(t => t.ObjectId == "6581e298-d4b4-4347-96da-030d82cd247b"); foreach (AuthorizeEntity item in AuthorizeList) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = 2; //1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeEntity.ObjectId = role.RoleId; //角色id,角色限定了机构和部门 authorizeEntity.ItemType = item.ItemType; //项目类型: 1 - 菜单2 - 按钮3 - 视图4表单 authorizeEntity.ItemId = item.ItemId; //项目主键 authorizeEntity.SortCode = item.SortCode; db.Insert(authorizeEntity); } #endregion #region 数据权限 就一个 AuthorizeDataEntity authorizeDataEntity = new AuthorizeDataEntity(); authorizeDataEntity.Create(); authorizeDataEntity.AuthorizeType = 4; //授权类型: 1 - 仅限本人2 - 仅限本人及下属3 - 所在部门4 - 所在公司5 - 按明细设置 authorizeDataEntity.Category = 2; //对象分类: 1 - 部门2 - 角色3 - 岗位4 - 职位5 - 工作组 authorizeDataEntity.ObjectId = role.RoleId; //角色id,角色限定了机构和部门 authorizeDataEntity.IsRead = 0; authorizeDataEntity.SortCode = 1; db.Insert(authorizeDataEntity); #endregion #region 新增默认用户 UserEntity userEntity = new UserEntity(); userEntity.Create(); role.EnCode = organizeEntity.OuterPhone; //账号 userEntity.Account = organizeEntity.OuterPhone; //登录名为机构名拼音首字母organizeEntity.EnCode userEntity.RealName = organizeEntity.Manager; //organizeEntity.FullName userEntity.WeChat = organizeEntity.ShortName; //微信昵称 userEntity.OrganizeId = organizeEntity.OrganizeId; userEntity.DepartmentId = department.DepartmentId; userEntity.RoleId = role.RoleId; userEntity.Gender = 1; userEntity.Secretkey = Md5Helper.MD5(CommonHelper.CreateNo(), 16).ToLower(); userEntity.Password = Md5Helper.MD5(DESEncrypt.Encrypt(Md5Helper.MD5("0000", 32).ToLower(), userEntity.Secretkey).ToLower(), 32).ToLower(); db.Insert(userEntity); #endregion #region 新增默认用户关系 UserRelationEntity userRelationEntity = new UserRelationEntity(); userRelationEntity.Create(); userRelationEntity.Category = 2;//登录名为机构名拼音首字母 userRelationEntity.UserId = userEntity.UserId; userRelationEntity.ObjectId = userEntity.RoleId; db.Insert(userRelationEntity); #endregion #region 新增代理表 var agentEntity = agentService.GetEntityByOpenId(organizeEntity.ManagerId); if (agentEntity == null) { var weChat_Users = db.FindEntity <WeChat_UsersEntity>(t => t.OpenId == organizeEntity.ManagerId); if (weChat_Users != null) { agentEntity = new Wechat_AgentEntity() { OpenId = weChat_Users.OpenId, nickname = weChat_Users.NickName, Sex = weChat_Users.Sex, HeadimgUrl = weChat_Users.HeadimgUrl, Province = weChat_Users.Province, City = weChat_Users.City, Country = weChat_Users.Country, LV = "普通代理", Category = 0, OrganizeId = organizeEntity.OrganizeId, //绑定机构id }; agentEntity.Create(); //create得不到id,自增 agentService.SaveForm(null, agentEntity); //提交数据库之后才能拿到id,复制给机构表中的agentid //更新id,0级机构上级和顶级都是本机构 agentEntity.Pid = agentEntity.Id; agentEntity.Tid = agentEntity.Id; agentEntity.Category = 0;//改为0级代理 agentService.SaveForm(agentEntity.Id, agentEntity); } } else { if (!string.IsNullOrEmpty(agentEntity.OrganizeId)) { agentEntity.OrganizeId = organizeEntity.OrganizeId;//如果不存在代理机构id, //更新id,0级机构上级和顶级都是本机构 agentEntity.Pid = agentEntity.Id; agentEntity.Tid = agentEntity.Id; agentEntity.Category = 0;//改为0级代理 db.Update(agentEntity); } } organizeEntity.AgentId = agentEntity.Id;//绑定代理id #endregion db.Insert(organizeEntity); db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// Default constructor. /// </summary> /// <param name="entity">AuthorizeEntity enumeration which represents allowed entities.</param> public AuthorizeAttribute(AuthorizeEntity entity) { Entity = entity; }
/// <summary> /// 添加授权 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="moduleIds">功能Id</param> /// <param name="moduleButtonIds">按钮Id</param> /// <param name="moduleColumnIds">视图Id</param> /// <param name="authorizeDataList">数据权限</param> public void SaveAuthorize(AuthorizeTypeEnum authorizeType, string objectId, string[] moduleIds, string[] moduleButtonIds, string[] moduleColumnIds, IEnumerable <AuthorizeDataEntity> authorizeDataList) { try { using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction()) { //删除授权 Base_Authorize.Delete("where ObjectId=@0", objectId); #region 功能 int SortCode = 1; foreach (string item in moduleIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = (int)Enums.FormElementTypeEnum.菜单; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; Base_Authorize authorize = EntityConvertTools.CopyToModel <AuthorizeEntity, Base_Authorize>(authorizeEntity, null); authorize.Insert(); } #endregion #region 钮 SortCode = 1; foreach (string item in moduleButtonIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = (int)Enums.FormElementTypeEnum.钮; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; Base_Authorize authorize = EntityConvertTools.CopyToModel <AuthorizeEntity, Base_Authorize>(authorizeEntity, null); authorize.Insert(); } #endregion #region 视图 SortCode = 1; foreach (string item in moduleColumnIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = (int)Enums.FormElementTypeEnum.视图; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; Base_Authorize authorize = EntityConvertTools.CopyToModel <AuthorizeEntity, Base_Authorize>(authorizeEntity, null); authorize.Insert(); } #endregion #region 数据权限 SortCode = 1; Base_AuthorizeDatum.Delete("where objectId=@0", objectId); int index = 0; foreach (AuthorizeDataEntity authorizeDataEntity in authorizeDataList) { authorizeDataEntity.Create(); authorizeDataEntity.Category = (int)authorizeType; authorizeDataEntity.ObjectId = objectId; authorizeDataEntity.SortCode = SortCode++; Base_AuthorizeDatum authorizedata = EntityConvertTools.CopyToModel <AuthorizeDataEntity, Base_AuthorizeDatum>(authorizeDataEntity, null); authorizedata.Insert(); index++; } #endregion tran.Complete(); } } catch (Exception) { throw; } }
/// <summary> /// Default constructor. /// </summary> /// <param name="entity">AuthorizeEntity enumeration which represents allowed entities.</param> public AuthorizeAttribute(AuthorizeEntity entity) { Entity = entity; }
/// <summary> /// 添加授权 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="moduleIds">功能Id</param> /// <param name="moduleButtonIds">按钮Id</param> /// <param name="moduleColumnIds">视图Id</param> /// <param name="authorizeDataList">数据权限</param> public void SaveAuthorize(AuthorizeTypeEnum authorizeType, string objectId, string[] moduleIds, string[] moduleButtonIds, string[] moduleColumnIds, IEnumerable <AuthorizeDataEntity> authorizeDataList) { //IModuleService bll = new ModuleService(); //IEnumerable<ModuleEntity> IEModule = bll.GetListByParent(); IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { db.Delete <AuthorizeEntity>(t => t.ObjectId == objectId); int SortCode = 1; if (moduleIds != null) { #region 功能 foreach (string item in moduleIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = 1; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; db.Insert(authorizeEntity); } #endregion #region 钮 if (moduleButtonIds != null) { SortCode = 1; foreach (string item in moduleButtonIds) { //if (IEModule.Count(t => t.ModuleId == item) == 0) //{ AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = 2; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; db.Insert(authorizeEntity); //} } } #endregion #region 视图 if (moduleColumnIds != null) { SortCode = 1; foreach (string item in moduleColumnIds) { //if (IEModule.Count(t => t.ModuleId == item) == 0) //{ AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = 3; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; db.Insert(authorizeEntity); //} } } #endregion } #region 数据权限 SortCode = 1; db.Delete <AuthorizeDataEntity>(objectId, "ObjectId"); int index = 0; foreach (AuthorizeDataEntity authorizeDataEntity in authorizeDataList) { authorizeDataEntity.Create(); authorizeDataEntity.Category = (int)authorizeType; authorizeDataEntity.ObjectId = objectId; // authorizeDataEntity.Module = "Department"; authorizeDataEntity.SortCode = SortCode++; db.Insert(authorizeDataEntity); index++; } #endregion db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 添加授权 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="moduleIds">功能Id</param> /// <param name="moduleButtonIds">按钮Id</param> /// <param name="moduleColumnIds">视图Id</param> /// <param name="authorizeDataList">数据权限</param> public void SaveAuthorize(AuthorizeTypeEnum authorizeType, string objectId, string[] moduleIds, string[] moduleButtonIds, string[] moduleColumnIds, IEnumerable <AuthorizeDataEntity> authorizeDataList) { IDbTransaction tran = null; Logger(this.GetType(), "SaveAuthorize-添加授权", () => { using (var conn = this.BaseRepository().GetBaseConnection()) { tran = conn.BeginTransaction(); //先清除历史授权数据 int isSucc = this.BaseRepository().Delete <AuthorizeEntity>(conn, u => u.ObjectId == objectId, tran); if (isSucc >= 0) { #region 功能 List <AuthorizeEntity> authorizeMenuList = new List <AuthorizeEntity>(); for (int i = 1; i <= moduleIds.Length; i++) { AuthorizeEntity authorize = new AuthorizeEntity { Category = (int)authorizeType, ObjectId = objectId, ItemType = 1, ItemId = moduleIds[i - 1], SortCode = i }; authorize.Create(); authorizeMenuList.Add(authorize); } //保存 int res = this.BaseRepository().Insert(conn, authorizeMenuList, tran); #endregion 功能 #region 钮 List <AuthorizeEntity> authorizeButtonList = new List <AuthorizeEntity>(); for (int i = 1; i <= moduleButtonIds.Length; i++) { AuthorizeEntity authorize = new AuthorizeEntity { Category = (int)authorizeType, ObjectId = objectId, ItemType = 2, ItemId = moduleButtonIds[i - 1], SortCode = i }; authorize.Create(); authorizeButtonList.Add(authorize); } //保存 res = this.BaseRepository().Insert(conn, authorizeButtonList, tran); #endregion 钮 #region 视图 List <AuthorizeEntity> authorizeViewList = new List <AuthorizeEntity>(); for (int i = 1; i <= moduleColumnIds.Length; i++) { AuthorizeEntity authorize = new AuthorizeEntity { Category = (int)authorizeType, ObjectId = objectId, ItemType = 3, ItemId = moduleColumnIds[i - 1], SortCode = i }; authorize.Create(); authorizeViewList.Add(authorize); } //保存 res = this.BaseRepository().Insert(conn, authorizeViewList, tran); #endregion 视图 #region 数据权限 //清除数据权限 isSucc = this.BaseRepository().Delete <AuthorizeDataEntity>(conn, u => u.ObjectId == objectId, tran); int sortCode = 1; List <AuthorizeDataEntity> authorizeDataTempList = new List <AuthorizeDataEntity>(); foreach (AuthorizeDataEntity authorizeData in authorizeDataList) { authorizeData.Category = (int)authorizeType; authorizeData.ObjectId = objectId; authorizeData.SortCode = sortCode++; authorizeData.Create(); authorizeDataTempList.Add(authorizeData); } //保存 res = this.BaseRepository().Insert(conn, authorizeDataTempList, tran); #endregion 数据权限 } tran.Commit(); } }, e => { Trace.WriteLine(e.Message); }); }
/// <summary> /// 作者:姚栋 /// 日期:2018-05-30 /// 描述:给某个岗位进行项目授权 /// </summary> /// <param name="authorizeType">授权类型</param> /// <param name="postId">岗位Id</param> /// <param name="moduleIds">项目Id集合</param>· /// <returns></returns> public void SaveAuthorizeAndPost(AuthorizeTypeEnum authorizeType, string postId, string[] projectColumnIds, string[] arryprojectNames) { var projectList = this.BaseRepository().IQueryable <Base_ProjectInfoEntity>().ToList(); IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { if (projectColumnIds.Length != arryprojectNames.Length) { throw new Exception("授权数据异常!"); } #region 数据权限 int SortCode = 1; Base_ProjectInfoEntity currentProject = null; for (int i = 0; i < projectColumnIds.Length; i++) { currentProject = projectList.FirstOrDefault(p => p.ProjectID == projectColumnIds[i]); AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = postId; authorizeEntity.ItemType = (int)AuthorizeItmeTypeEnum.ProjectInfo; authorizeEntity.ItemId = projectColumnIds[i]; authorizeEntity.ItemName = arryprojectNames[i]; authorizeEntity.SortCode = SortCode++; if (currentProject != null) { authorizeEntity.Remark1 = currentProject.CompanyName; authorizeEntity.Remark2 = currentProject.CityName; } db.Insert(authorizeEntity); } //foreach (string item in projectColumnIds) //{ // AuthorizeEntity authorizeEntity = new AuthorizeEntity(); // authorizeEntity.Create(); // authorizeEntity.Category = (int)authorizeType; // authorizeEntity.ObjectId = postId; // authorizeEntity.ItemType = (int)AuthorizeItmeTypeEnum.ProjectInfo; // authorizeEntity.ItemId = item; // authorizeEntity.SortCode = SortCode++; // db.Insert(authorizeEntity); //} #endregion StringBuilder strSql = new StringBuilder(); strSql.Append(@"update Base_Role set AuthorizationMethod=@AuthorizationMethod where RoleId=@PostID"); var parameter = new List <DbParameter>(); parameter.Add(DbParameters.CreateDbParameter("@PostID", postId)); parameter.Add(DbParameters.CreateDbParameter("@AuthorizationMethod", (int)AuthorizationMethodEnum.CustomizeProject)); db.ExecuteBySql(strSql.ToString(), parameter.ToArray()); db.Commit(); } catch (Exception ex) { db.Rollback(); throw new Exception(ex.Message); } }