/// <summary> /// 添加成员 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="userIds">成员Id</param> public void SaveMember(AuthorizeTypeEnum authorizeType, string objectId, string[] userIds) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { db.Delete <UserRelationEntity>(t => t.ObjectId == objectId && t.IsDefault == 0); int SortCode = 1; foreach (string item in userIds) { UserRelationEntity userRelationEntity = new UserRelationEntity(); userRelationEntity.Create(); userRelationEntity.Category = (int)authorizeType; userRelationEntity.ObjectId = objectId; userRelationEntity.UserId = item; userRelationEntity.SortCode = SortCode++; db.Insert(userRelationEntity); } db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 添加成员 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="userIds">成员Id</param> public void SaveMember(AuthorizeTypeEnum authorizeType, string objectId, string[] userIds) { //先清除历史用户关系数据 int isSucc = o.BllSession.UserRelationBll.Delete(u => u.ObjectId.Equals(objectId) && u.IsDefault == false); if (isSucc > 0) { //组装数据 List <UserRelationEntity> list = new List <UserRelationEntity>(); for (int i = 1; i <= userIds.Length; i++) { UserRelationEntity userRelationEntity = new UserRelationEntity { Category = (int)authorizeType, ObjectId = objectId, UserId = userIds[i - 1], SortCode = i }; userRelationEntity.Create(); list.Add(userRelationEntity); } //批量保存 o.BllSession.UserRelationBll.Insert(list); } }
/// <summary> /// 添加成员 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="userIds">成员Id</param> public void SaveMember(AuthorizeTypeEnum authorizeType, string objectId, string[] userIds) { //先清除历史用户关系数据 int isSucc = this.BaseRepository().Delete <UserRelationEntity>(u => u.ObjectId == objectId && u.IsDefault == false); if (isSucc > 0) { //组装数据 List <UserRelationEntity> list = new List <UserRelationEntity>(); for (int i = 1; i <= userIds.Length; i++) { UserRelationEntity userRelationEntity = new UserRelationEntity { Category = (int)authorizeType, ObjectId = objectId, UserId = userIds[i - 1], SortCode = i }; userRelationEntity.Create(); list.Add(userRelationEntity); } //批量保存 int res = this.BaseRepository().Insert(list); } }
/// <summary> /// 添加成员 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="userIds">成员Id</param> public void SaveMember(AuthorizeTypeEnum authorizeType, string objectId, string[] userIds) { try { using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction()) { Base_UserRelation.Delete("where ObjectId=@0 and IsDefault=0", objectId); int SortCode = 1; foreach (string item in userIds) { UserRelationEntity userRelationEntity = new UserRelationEntity(); userRelationEntity.Create(); userRelationEntity.Category = (int)authorizeType; userRelationEntity.ObjectId = objectId; userRelationEntity.UserId = item; userRelationEntity.SortCode = SortCode++; Base_UserRelation userrelation = EntityConvertTools.CopyToModel <UserRelationEntity, Base_UserRelation>(userRelationEntity, null); userrelation.Insert(); } tran.Complete(); } } catch (Exception) { throw; } }
/// <summary> /// 添加成员 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="userIds">成员Id</param> public void SaveMember(AuthorizeTypeEnum authorizeType, string objectId, string[] userIds, string[] deleteUserIds) { List <UserRelationEntity> plist = new List <UserRelationEntity>(); IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { foreach (var item in deleteUserIds) { var expression = LinqExtensions.True <UserRelationEntity>(); expression = expression.And(t => t.ObjectId == objectId && t.UserId == item); db.Delete <UserRelationEntity>(expression); } int SortCode = 1; UserRelationEntity userRelationEntity = null; foreach (string item in userIds) { userRelationEntity = new UserRelationEntity(); userRelationEntity.Create(); userRelationEntity.Category = (int)authorizeType; userRelationEntity.ObjectId = objectId; userRelationEntity.UserId = item; userRelationEntity.SortCode = SortCode++; bool isAdded = IsAdded(item, objectId, (int)authorizeType); if (!isAdded) { plist.Add(userRelationEntity); } userRelationEntity = null; } if (plist.Count > 0) { db.Insert(plist); } db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <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="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; } }