Beispiel #1
0
        private async Task CreateTopCorporation(CreateCorporationInput input)
        {
            if (input.Mold != Shared.CorporationMold.Group && input.Mold != Shared.CorporationMold.Monomer)
            {
                throw new BusinessException("公司类型不正确,顶层公司只能指定为:集团公司或单体公司");
            }
            var orgCode   = string.Empty;
            var maxTopOrg = (await _organizationRepository.GetAllAsync(p => p.Level == 1 && p.OrgType == Shared.Organizations.OrganizationType.Corporation)).OrderByDescending(p => p.Id).FirstOrDefault();

            if (maxTopOrg == null)
            {
                orgCode = "1".PadLeft(HeroConstants.CodeRuleRestrain.CodeCoverBit, HeroConstants.CodeRuleRestrain.CodeCoverSymbol);
            }
            else
            {
                orgCode = (Convert.ToInt32(maxTopOrg.Code.TrimStart('0')) + 1).ToString().PadLeft(HeroConstants.CodeRuleRestrain.CodeCoverBit, HeroConstants.CodeRuleRestrain.CodeCoverSymbol);
            }
            var topCorporation = input.MapTo <Corporation>();
            var topOrgInfo     = input.MapTo <Organization>();

            topOrgInfo.Code  = orgCode;
            topOrgInfo.Level = 1;
            await UnitOfWorkAsync(async (conn, trans) =>
            {
                var orgId            = await _organizationRepository.InsertAndGetIdAsync(topOrgInfo, conn, trans);
                topCorporation.OrgId = orgId;
                await _corporationRepository.InsertAsync(topCorporation, conn, trans);
            }, Connection);
        }
Beispiel #2
0
        private async Task CreateSubCorporation(CreateCorporationInput input)
        {
            var parentCorporation = await _corporationRepository.SingleAsync(p => p.OrgId == input.ParentId.Value);

            if (parentCorporation.Mold == Shared.CorporationMold.Monomer)
            {
                throw new BusinessException("单体公司不允许增加子公司");
            }
            var parentOrg = await _organizationRepository.GetAsync(input.ParentId.Value);

            var corporation = input.MapTo <Corporation>();
            var orgInfo     = input.MapTo <Organization>();
            var orgCode     = string.Empty;
            var maxLevelOrg = (await _organizationRepository.GetAllAsync(p => p.ParentId == parentOrg.Id)).OrderByDescending(p => p.Id).FirstOrDefault();

            if (maxLevelOrg == null)
            {
                orgCode = "1".PadLeft(HeroConstants.CodeRuleRestrain.CodeCoverBit, HeroConstants.CodeRuleRestrain.CodeCoverSymbol);
            }
            else
            {
                orgCode = (Convert.ToInt32(maxLevelOrg.Code.Split(HeroConstants.CodeRuleRestrain.CodeSeparator).Last().TrimStart('0')) + 1).ToString().PadLeft(HeroConstants.CodeRuleRestrain.CodeCoverBit, HeroConstants.CodeRuleRestrain.CodeCoverSymbol);
            }
            orgInfo.Code  = parentOrg.Code + HeroConstants.CodeRuleRestrain.CodeSeparator + orgCode;
            orgInfo.Level = parentOrg.Level + 1;
            await UnitOfWorkAsync(async (conn, trans) =>
            {
                var orgId         = await _organizationRepository.InsertAndGetIdAsync(orgInfo, conn, trans);
                corporation.OrgId = orgId;
                await _corporationRepository.InsertAsync(corporation, conn, trans);
            }, Connection);
        }
Beispiel #3
0
        public async Task <string> Create(CreateCorporationInput input)
        {
            input.CheckDataAnnotations().CheckValidResult();
            await _corporationDomainService.CreateCorporation(input);

            return("新增公司信息成功");
        }
 public async Task <CreateCorporationOutput> CreateCorporation(CreateCorporationInput input)
 {
     if (!input.ParentId.HasValue || input.ParentId == 0)
     {
         return(await CreateTopCorporation(input));
     }
     else
     {
         return(await CreateSubCorporation(input));
     }
 }
Beispiel #5
0
 public async Task CreateCorporation(CreateCorporationInput input)
 {
     if (!input.ParentId.HasValue || input.ParentId == 0)
     {
         await CreateTopCorporation(input);
     }
     else
     {
         await CreateSubCorporation(input);
     }
 }
Beispiel #6
0
        public async Task <CreateCorporationOutput> CreateCorporation(CreateCorporationInput input)
        {
            var exsitOrg =
                await _organizationRepository.SingleOrDefaultAsync(p => p.Identification == input.Identification);

            if (exsitOrg != null)
            {
                throw new BusinessException($"系统中已经存在标识为{input.Identification}的组织机构");
            }

            if (!input.ParentId.HasValue || input.ParentId == 0)
            {
                return(await CreateTopCorporation(input));
            }
            return(await CreateSubCorporation(input));
        }
Beispiel #7
0
 public async Task <CreateCorporationOutput> Create(CreateCorporationInput input)
 {
     input.CheckDataAnnotations().CheckValidResult();
     return(await _corporationDomainService.CreateCorporation(input));
 }