Example #1
0
        private FinancialAccountingCertificateChangeModelDto GetChangeModel(UpdateFinancialAccountingCertificateInput model)
        {
            var ret = new FinancialAccountingCertificateChangeModelDto()
            {
            };

            foreach (var item in model.Details)
            {
                var entity = new FACertificateDetailChangeDto();
                entity.Id = item.Id;
                var acModel = _aCRepository.FirstOrDefault(r => r.Id == item.AccountingCourseId);
                if (acModel != null)
                {
                    entity.AccountingCourseName = acModel.Name;
                }
                entity.BusinessType_Name = item.BusinessType == (int)FACertificateDetailBusinessType.借 ? "借" : "贷";
                entity.Amount            = item.Amount;
                ret.Details.Add(entity);
            }
            return(ret);
        }
Example #2
0
        /// <summary>
        /// 修改一个FinancialAccountingCertificate
        /// </summary>
        /// <param name="input">实体</param>
        /// <returns></returns>
        private void UpdateWithOutNLP(UpdateFinancialAccountingCertificateInput input, bool isUpdateForChange, Guid?flowId)
        {
            if (input.Id != Guid.Empty)
            {
                var dbmodel = _repository.FirstOrDefault(x => x.Id == input.Id);
                if (dbmodel == null)
                {
                    throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "该数据不存在。");
                }
                var old_Model = new FinancialAccountingCertificateChangeModelDto();
                dbmodel.Code              = input.Code;
                dbmodel.BusinessType      = input.BusinessType;
                dbmodel.BusinessId        = input.BusinessId;
                dbmodel.KeepUserId        = input.KeepUserId;
                dbmodel.AuditUserId       = input.AuditUserId;
                dbmodel.CashierUserId     = input.CashierUserId;
                dbmodel.MakeUserId        = input.MakeUserId;
                dbmodel.Summary           = input.Summary;
                dbmodel.Type              = input.Type;
                dbmodel.Name              = input.Name;
                dbmodel.Region            = input.Region;
                dbmodel.TotalDebitAmount  = input.TotalDebitAmount;
                dbmodel.TotalCreditAmount = input.TotalCreditAmount;
                dbmodel.ResultId          = input.ResultId;

                var db_detailsQuery = from a in _detailRepository.GetAll()
                                      join b in _aCRepository.GetAll() on a.AccountingCourseId equals b.Id
                                      where a.MainId == input.Id
                                      select new FACertificateDetailChangeDto {
                    Id = a.Id, AccountingCourseName = b.Name, Amount = a.Amount, BusinessType_Name = a.BusinessType == (int)FACertificateDetailBusinessType.借 ? "借" : "贷"
                };

                var delete_Ids = new List <Guid>();
                if (db_detailsQuery.Count() > 0)
                {
                    old_Model.Details = db_detailsQuery.ToList();
                    delete_Ids        = old_Model.Details.Select(r => r.Id.Value).Except(input.Details.Where(r => r.Id.HasValue).Select(r => r.Id.Value)).ToList();
                }
                foreach (var item in delete_Ids)
                {
                    _detailRepository.Delete(r => r.Id == item);
                }


                foreach (var item in input.Details)
                {
                    if (item.Id.HasValue)
                    {
                        var entity_detail = _detailRepository.Get(item.Id.Value);
                        entity_detail.AccountingCourseId = item.AccountingCourseId;
                        entity_detail.Amount             = item.Amount;
                        entity_detail.BusinessType       = item.BusinessType;
                    }
                    else
                    {
                        var entity = new FACertificateDetail()
                        {
                            Id = Guid.NewGuid(),
                            AccountingCourseId = item.AccountingCourseId,
                            Amount             = item.Amount,
                            BusinessType       = item.BusinessType,
                            MainId             = dbmodel.Id,
                            Summary            = item.Summary
                        };

                        _detailRepository.Insert(entity);
                    }
                }

                _repository.Update(dbmodel);

                if (isUpdateForChange)
                {
                    var new_Model = GetChangeModel(input);
                    var logs      = old_Model.GetColumnAllLogs(new_Model);
                    if (!flowId.HasValue)
                    {
                        throw new UserFriendlyException((int)ErrorCode.CodeValErr, "流程编号为空");
                    }
                    var flowModel = _workFlowCacheManager.GetWorkFlowModelFromCache(flowId.Value);
                    if (flowModel == null)
                    {
                        throw new UserFriendlyException((int)ErrorCode.CodeValErr, "流程不存在");
                    }
                    var groupId = input.GroupId.HasValue ? input.GroupId.Value : Guid.NewGuid();
                    _projectAuditManager.InsertAsync(logs, input.BusinessId.ToString(), flowModel.TitleField.Table, groupId);
                }
            }
            else
            {
                throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "该数据不存在。");
            }
        }