Exemple #1
0
        /// <summary>
        /// 添加一个岗位信息
        /// </summary>
        /// <param name="input">实体</param>
        /// <returns></returns>
        public async Task Create(CreateOrganizationUnitPostsInput input)
        {
            var postid = _postInforepository.InsertAndGetId(new PostInfo()
            {
                Name = input.Name,
            });
            var newmodel = new OrganizationUnitPosts()
            {
                Id = Guid.NewGuid(),
                OrganizationUnitId = input.OrganizationUnitId,
                PostId             = postid,
                PrepareNumber      = input.PrepareNumber,
                Level = (Level)input.Level
            };

            if (input.RoleNames != null && input.RoleNames.Count > 0)
            {
                foreach (var r in input.RoleNames)
                {
                    var role2 = _roleRepository.GetAll().FirstOrDefault(ite => ite.Name == r);
                    if (role2 != null)
                    {
                        var tmp = new OrganizationUnitPostsRole()
                        {
                            OrgPostId = newmodel.Id,
                            RoleName  = r
                        };
                        _organizationUnitPostsRoleRepository.Insert(tmp);
                    }
                }
            }

            var role = _roleRepository.GetAll().FirstOrDefault(ite => ite.Id == input.RoleId);

            if (role != null)
            {
                var tmp = new OrganizationUnitPostsRole()
                {
                    OrgPostId = newmodel.Id,
                    RoleName  = role.Name
                };
                _organizationUnitPostsRoleRepository.Insert(tmp);
            }
            else
            {
                throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "请先设置岗位权限。");
            }

            await _repository.InsertAsync(newmodel);
        }
Exemple #2
0
        /// <summary>
        /// 修复数据(对每个部门默认添加“分管领导”和“部门领导”岗位)
        /// </summary>
        /// <returns></returns>
        public async Task CreateDefaultPost(long?orgid)
        {
            var query = _organizationUnitRepository.GetAll();

            if (orgid.HasValue)
            {
                query = query.Where(ite => ite.Id == orgid.Value);
            }
            var orgs = query.ToList();
            var role = Abp.AbpBootstrapper.Create <Abp.Modules.AbpModule>().IocManager.IocContainer.Resolve <IRoleAppService>();

            foreach (var org in orgs)
            {
                var orgpost = _repository.GetAll().Where(ite => ite.OrganizationUnitId == org.Id).ToList();
                if (orgpost.Exists(ite => ite.Level == Level.分管领导) == false)
                {
                    var roleid = await role.Create(new Roles.Dto.CreateRoleDto()
                    {
                        DisplayName = org.DisplayName + "分管领导角色",
                        Permissions = new List <string>()
                    });

                    CurrentUnitOfWork.SaveChanges();
                    await Create(new CreateOrganizationUnitPostsInput()
                    {
                        Level = (int)Level.分管领导,
                        Name  = org.DisplayName + "分管领导",
                        OrganizationUnitId = org.Id,
                        PrepareNumber      = 2,
                        RoleNames          = new List <string>()
                        {
                            "OrgFGLD"
                        },
                        RoleId = roleid.Id
                    });
                }
                else
                {
                    var chargeOrgPost = orgpost.FirstOrDefault(ite => ite.Level == Level.分管领导);
                    if (!_organizationUnitPostsRoleRepository.GetAll().Any(r => r.OrgPostId == chargeOrgPost.Id && r.RoleName == "OrgFGLD"))
                    {
                        var tmp = new OrganizationUnitPostsRole()
                        {
                            OrgPostId = chargeOrgPost.Id,
                            RoleName  = "OrgFGLD"
                        };
                        _organizationUnitPostsRoleRepository.Insert(tmp);
                    }
                }
                if (orgpost.Exists(ite => ite.Level == Level.部门领导) == false)
                {
                    var roleid = await role.Create(new Roles.Dto.CreateRoleDto()
                    {
                        DisplayName = org.DisplayName + "部门领导角色",
                        Permissions = new List <string>()
                    });

                    CurrentUnitOfWork.SaveChanges();
                    await Create(new CreateOrganizationUnitPostsInput()
                    {
                        Level = (int)Level.部门领导,
                        Name  = org.DisplayName + "部门领导",
                        OrganizationUnitId = org.Id,
                        PrepareNumber      = 2,
                        RoleNames          = new List <string>()
                        {
                            "DLEADER"
                        },
                        RoleId = roleid.Id
                    });
                }
            }
        }