Exemple #1
0
 private void CheckInsurancePolicy(InsurancePolicy insurancePolicy)
 {
     if (insurancePolicy.InsurancePolicyStatus == InsurancePolicyStatus.Approving)
     {
         throw new UserFriendlyException($"保单编号为{insurancePolicy.InsuranceNum}的保单为签核中保单,无法送签");
     }
 }
Exemple #2
0
        private void InsertInsuranceApprovalDetail(CreateInsuranceApprovalDto input, InsuranceApproval entity, InsurancePolicy insurancePolicy, IEnumerable <InsuranceDetail> insurancePolicyDetails, IQueryable <InsuranceApprovalDetail> insuranceApprovalDetails)
        {
            decimal originalAmount = 0, transactionAmount = 0, noDeductibleOriginalAmount = 0, noDeductibleTransactionAmount = 0, rebateAmount = 0, extraRebateAmount = 0;

            switch (input.InsuranceApprovalType)
            {
            case InsuranceApprovalType.TemporaryLoan:
            case InsuranceApprovalType.Change:
            case InsuranceApprovalType.PaymentRequest:
                insuranceApprovalDetails      = insuranceApprovalDetails.Where(a => a.InsuranceApproval.InsuranceApprovalType != InsuranceApprovalType.WriteOff && a.InsuranceApproval.InsuranceApprovalType != InsuranceApprovalType.RebateInvoice);
                originalAmount                = insurancePolicyDetails.Sum(d => d.OriginalAmount) - insuranceApprovalDetails.Sum(d => d.OriginalAmount);
                transactionAmount             = insurancePolicyDetails.Sum(d => d.TransactionAmount) - insuranceApprovalDetails.Sum(d => d.TransactionAmount);
                noDeductibleOriginalAmount    = insurancePolicyDetails.Sum(d => d.NoDeductibleOriginalAmount) - insuranceApprovalDetails.Sum(d => d.NoDeductibleOriginalAmount);
                noDeductibleTransactionAmount = insurancePolicyDetails.Sum(d => d.NoDeductibleTransactionAmount) - insuranceApprovalDetails.Sum(d => d.NoDeductibleTransactionAmount);
                rebateAmount      = insurancePolicyDetails.Sum(d => d.RebateAmount) - insuranceApprovalDetails.Sum(d => d.RebateAmount);
                extraRebateAmount = insurancePolicyDetails.Sum(d => d.ExtraRebateAmount) - insuranceApprovalDetails.Sum(d => d.ExtraRebateAmount);
                break;

            case InsuranceApprovalType.WriteOff:
                var temporaryLoanDetails = insuranceApprovalDetails.Where(a => a.InsuranceApproval.InsuranceApprovalType == InsuranceApprovalType.TemporaryLoan);
                var writeOffDetails      = insuranceApprovalDetails.Where(a => a.InsuranceApproval.InsuranceApprovalType == InsuranceApprovalType.WriteOff);
                originalAmount                = temporaryLoanDetails.Sum(d => d.OriginalAmount) - writeOffDetails.Sum(d => d.OriginalAmount);
                transactionAmount             = temporaryLoanDetails.Sum(d => d.TransactionAmount) - writeOffDetails.Sum(d => d.TransactionAmount);
                noDeductibleOriginalAmount    = temporaryLoanDetails.Sum(d => d.NoDeductibleOriginalAmount) - writeOffDetails.Sum(d => d.NoDeductibleOriginalAmount);
                noDeductibleTransactionAmount = temporaryLoanDetails.Sum(d => d.NoDeductibleTransactionAmount) - writeOffDetails.Sum(d => d.NoDeductibleTransactionAmount);
                rebateAmount      = temporaryLoanDetails.Sum(d => d.RebateAmount) - writeOffDetails.Sum(d => d.RebateAmount);
                extraRebateAmount = temporaryLoanDetails.Sum(d => d.ExtraRebateAmount) - writeOffDetails.Sum(d => d.ExtraRebateAmount);
                break;

            case InsuranceApprovalType.RebateInvoice:
                insuranceApprovalDetails      = insuranceApprovalDetails.Where(a => a.InsuranceApproval.InsuranceApprovalType == InsuranceApprovalType.RebateInvoice);
                originalAmount                = insurancePolicyDetails.Sum(d => d.OriginalAmount) - insuranceApprovalDetails.Sum(d => d.OriginalAmount);
                transactionAmount             = insurancePolicyDetails.Sum(d => d.TransactionAmount) - insuranceApprovalDetails.Sum(d => d.TransactionAmount);
                noDeductibleOriginalAmount    = insurancePolicyDetails.Sum(d => d.NoDeductibleOriginalAmount) - insuranceApprovalDetails.Sum(d => d.NoDeductibleOriginalAmount);
                noDeductibleTransactionAmount = insurancePolicyDetails.Sum(d => d.NoDeductibleTransactionAmount) - insuranceApprovalDetails.Sum(d => d.NoDeductibleTransactionAmount);
                rebateAmount      = insurancePolicyDetails.Sum(d => d.RebateAmount) - insuranceApprovalDetails.Sum(d => d.RebateAmount);
                extraRebateAmount = insurancePolicyDetails.Sum(d => d.ExtraRebateAmount) - insuranceApprovalDetails.Sum(d => d.ExtraRebateAmount);
                break;

            default:
                break;
            }

            _insuranceApprovalDetailRepository.Insert(new InsuranceApprovalDetail
            {
                CreatorUserId       = input.CreatorUserId,
                InsuranceApprovalId = entity.Id,
                InsurancePolicyId   = insurancePolicy.Id,
                InsuranceNum        = insurancePolicy.InsuranceNum,
                MakNo = insurancePolicy.CarBase.MakNo,
                InsurancePolicyType           = insurancePolicy.InsurancePolicyType,
                OriginalAmount                = originalAmount,
                TransactionAmount             = transactionAmount,
                NoDeductibleOriginalAmount    = noDeductibleOriginalAmount,
                NoDeductibleTransactionAmount = noDeductibleTransactionAmount,
                RebateAmount      = rebateAmount,
                ExtraRebateAmount = extraRebateAmount,
                CusName           = insurancePolicy.CarBase.Inc.Sname
            });
        }
        public async Task <int> ImportAll(ImportInsuranceDetailDto[] inputs)
        {
            CheckCreatePermission();

            int insertNum = 0;

            inputs.ToList().ForEach(x =>
            {
                var insuranceLog = new InsuranceLog();
                InsurancePolicy insurancePolicy;
                InsuranceDetail entity;
                switch (x.InsuranceOperationType)
                {
                case InsuranceOperationType.BatchAdd:
                    insurancePolicy     = _insurancePolicyRepository.FirstOrDefault(i => i.InsuranceNum == x.InsuranceNum && i.CarBaseId == x.CarBaseId);
                    x.InsurancePolicyId = insurancePolicy.Id;
                    entity = Repository.FirstOrDefault(o => o.InsurancePolicyId == insurancePolicy.Id && o.InsuranceType.Id == x.InsuranceTypeId);
                    if (entity == null)
                    {
                        entity    = MapToEntity(x);
                        entity.Id = Repository.InsertAndGetId(entity);
                    }
                    else
                    {
                        insuranceLog.OldInsuranceJson = JsonConvert.SerializeObject(entity);
                        x.Id = entity.Id;
                        MapToEntity(x, entity);
                    }
                    insuranceLog.NewInsuranceJson  = JsonConvert.SerializeObject(entity);
                    insuranceLog.SerialNumber      = x.SerialNumber;
                    insuranceLog.InsuranceDetailId = entity.Id;
                    break;

                case InsuranceOperationType.BatchReduce:
                    insurancePolicy     = _insurancePolicyRepository.FirstOrDefault(i => i.InsuranceNum == x.InsuranceNum && i.CarBaseId == x.CarBaseId);
                    x.InsurancePolicyId = insurancePolicy.Id;
                    entity = Repository.FirstOrDefault(o => o.InsurancePolicyId == insurancePolicy.Id && o.InsuranceType.Id == x.InsuranceTypeId);
                    insuranceLog.OldInsuranceJson = JsonConvert.SerializeObject(entity);
                    x.Id = entity.Id;
                    MapToEntity(x, entity);
                    insuranceLog.NewInsuranceJson  = JsonConvert.SerializeObject(entity);
                    insuranceLog.SerialNumber      = x.SerialNumber;
                    insuranceLog.InsuranceDetailId = entity.Id;
                    break;

                case InsuranceOperationType.Insure:
                    insurancePolicy = _insurancePolicyRepository.FirstOrDefault(i => i.InsuranceNum == x.InsuranceNum && i.CarBaseId == x.CarBaseId);
                    if (insurancePolicy == null)
                    {
                        var carBase         = _carBaseRepository.FirstOrDefault(c => c.Id == x.CarBaseId);
                        var insurancePreset = _insurancePresetRepository.FirstOrDefault(i => i.Id == x.InsurancePresetId);
                        var supplier        = _supplierRepository.FirstOrDefault(s => s.Id == x.SupplierId);
                        insurancePolicy     = new InsurancePolicy
                        {
                            CarBaseId             = carBase.Id,
                            SupplierId            = supplier.Id,
                            InsuranceContractType = x.InsuranceContractType,
                            InsurancePolicyType   = x.InsurancePolicyType,
                            InsuranceNum          = x.InsuranceNum,
                            StartTime             = x.StartTime,
                            EndTime = x.EndTime,
                            CompulsoryInsuranceRebateRate = insurancePreset.CompulsoryInsuranceRebateRate,
                            CommercialInsuranceRebateRate = insurancePreset.CommercialInsuranceRebateRate,
                            ExtraRebateRate = insurancePreset.ExtraRebateRate,
                            CarrierLiabilityInsuranceRebateRate = insurancePreset.CarrierLiabilityInsuranceRebateRate,
                        };
                        insurancePolicy.Id = _insurancePolicyRepository.InsertAndGetId(insurancePolicy);
                    }

                    x.InsurancePolicyId = insurancePolicy.Id;

                    entity = MapToEntity(x);

                    if (Repository.FirstOrDefault(d => d.InsuranceTypeId == entity.InsuranceTypeId && d.InsurancePolicyId == entity.InsurancePolicyId) != null)
                    {
                        throw new UserFriendlyException($"保单编号为{insurancePolicy.InsuranceNum}的保单存在与导入数据相同险种明细,请确认后重新导入");
                    }
                    entity.Id = Repository.InsertAndGetId(entity);

                    insuranceLog.NewInsuranceJson  = JsonConvert.SerializeObject(entity);
                    insuranceLog.InsuranceDetailId = entity.Id;

                    break;
                }
                insuranceLog.InsuranceOperationType = x.InsuranceOperationType;
                _insuranceLogRepository.Insert(insuranceLog);
                insertNum++;
            });
            await CurrentUnitOfWork.SaveChangesAsync();

            return(insertNum);
        }