コード例 #1
0
        public void Load(int projectId, DateTime asOfDate)
        {
            var project      = m_dbAdapter.Project.GetProjectById(projectId);
            var dealSchedule = NancyUtils.GetDealSchedule(projectId, asOfDate.ToString("yyyyMMdd"));

            m_dealSchedule = dealSchedule;

            var errorMsg = "Search payment date/as of date failed, projectGuid=[" + project.ProjectGuid + "] asOfDate=[" + asOfDate.ToString() + "]";

            CommUtils.Assert(dealSchedule.DeterminationDates != null && dealSchedule.DeterminationDates.Length > 0, errorMsg);
            CommUtils.Assert(dealSchedule.PaymentDates != null && dealSchedule.PaymentDates.Length > 0, errorMsg);
            CommUtils.Assert(dealSchedule.DeterminationDates.Length == dealSchedule.PaymentDates.Length, errorMsg);
            CommUtils.Assert(asOfDate < dealSchedule.LegalMaturity, errorMsg);

            var asOfDateList = dealSchedule.DeterminationDates.ToList();

            asOfDateList.Insert(0, dealSchedule.FirstCollectionPeriodStartDate);
            asOfDateList.RemoveAt(asOfDateList.Count - 1);

            var paymentDateList   = dealSchedule.PaymentDates.ToList();
            var projectLogicModel = new ProjectLogicModel(m_userName, project);

            var findPaymentDates = projectLogicModel.DealSchedule.DurationPeriods
                                   .Where(x => x.Dataset != null && x.Dataset.Instance != null &&
                                          DateUtils.ParseDigitDate(x.Dataset.Instance.AsOfDate) == asOfDate)
                                   .Select(x => x.Dataset.Instance.PaymentDate);

            CommUtils.AssertEquals(findPaymentDates.Count(), 1, "查找PaymentDay失败,AsOfDate={0}", asOfDate);

            m_paymentDay = findPaymentDates.Single().Value;
            var index = paymentDateList.IndexOf(m_paymentDay);

            CommUtils.Assert(index >= 0, errorMsg);

            m_asOfDay = asOfDate;
            if (index == 0)
            {
                m_previousPaymentDay = paymentDateList[0];
            }
            else
            {
                m_previousPaymentDay = paymentDateList[index - 1];
            }

            if (index == paymentDateList.Count - 1)
            {
                m_nextAsOfDay    = null;
                m_nextPaymentDay = null;
            }
            else
            {
                m_nextAsOfDay    = asOfDateList[index + 1];
                m_nextPaymentDay = paymentDateList[index + 1];
            }

            m_isInitialized = true;
        }
コード例 #2
0
ファイル: NancyUtils.cs プロジェクト: weedkiller/absmanager
        public static DealSchedule GetDealSchedule(int projectId, string asOfDate = null, bool ignoreException = true)
        {
            try
            {
                var dbAdapter   = new DBAdapter();
                var rootFolder  = WebConfigUtils.RootFolder;
                var project     = dbAdapter.Project.GetProjectById(projectId);
                var modelFolder = Path.Combine(rootFolder, project.Model.ModelFolder);
                var ymlFilePath = modelFolder + @"\Script.yml";
                if (File.Exists(ymlFilePath))
                {
                    using (StreamReader sr = new StreamReader(ymlFilePath))
                    {
                        var dateFromYml = ReadYmlExInfo(sr);

                        var nancyDealData = NancyUtils.GetNancyDealDataByFile(sr.BaseStream);
                        if (nancyDealData != null)
                        {
                            var scheduleData = nancyDealData.ScheduleData;
                            var dealSchedule = new DealSchedule();
                            //第一个偿付期的计息区间起始日期就是起息日
                            dealSchedule.FirstAccrualDate   = scheduleData.ClosingDate;
                            dealSchedule.ClosingDate        = scheduleData.ClosingDate;
                            dealSchedule.LegalMaturity      = scheduleData.LegalMaturity;
                            dealSchedule.PaymentDates       = scheduleData.PaymentSchedule.Periods.Select(x => x.PaymentDate).ToArray();
                            dealSchedule.DeterminationDates = scheduleData.PaymentSchedule.Periods.Select(x => x.DeterminationDate).ToArray();

                            dealSchedule.FirstCollectionPeriodStartDate = dateFromYml.Item1.HasValue
                                ? dateFromYml.Item1.Value : scheduleData.PaymentSchedule.Periods.First().CollectionBegin;
                            dealSchedule.FirstCollectionPeriodEndDate = scheduleData.PaymentSchedule.Periods.First().CollectionEnd;

                            var scheduledPaymentDateArray = nancyDealData.ScheduleData.PaymentSchedule.Periods.Select(x => x.ScheduledPaymentDate).ToArray();
                            dealSchedule.NoteAccrualDates = new Dictionary <string, DateTime[]>();
                            nancyDealData.Notes.ForEach(x => dealSchedule.NoteAccrualDates[x.Name] = scheduledPaymentDateArray);

                            return(dealSchedule);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (ignoreException)
                {
                    return(null);
                }
                else
                {
                    throw e;
                }
            }

            return(null);
        }
コード例 #3
0
        private void Initialize(ProjectLogicModel project)
        {
            var objStr = "产品 [" + project.Instance.Name + "] ";

            var projectId = project.Instance.ProjectId;

            if (project.Instance.Model == null && project.Instance.ModelId > 0)
            {
                project.Instance.Model = m_dbAdapter.Project.GetModel(project.Instance.ModelId);
            }

            var modelFolder = WebConfigUtils.RootFolder + project.Instance.Model.ModelFolder + "\\";

            CommUtils.Assert(Directory.Exists(modelFolder), "找不到模型路径[{0}]", modelFolder);

            DealSchedule dealSchedule = null;

            try
            {
                dealSchedule = NancyUtils.GetDealSchedule(projectId, ignoreException: false);
            }
            catch (Exception e)
            {
                CommUtils.Assert(false, "加载模型失败:[{0}],模型路径:{1}"
                                 + Environment.NewLine + e.Message, modelFolder);
            }
            CommUtils.AssertNotNull(dealSchedule, "加载模型失败:{0}", modelFolder);
            m_instanse = dealSchedule;

            CommUtils.Assert(DateUtils.IsNormalDate(dealSchedule.FirstCollectionPeriodStartDate),
                             "模型中,FirstCollectionPeriodStartDate({0})不是有效的日期", dealSchedule.FirstCollectionPeriodStartDate.ToString());
            CommUtils.Assert(DateUtils.IsNormalDate(dealSchedule.FirstCollectionPeriodEndDate),
                             "模型中,FirstCollectionPeriodEndDate({0})不是有效的日期", dealSchedule.FirstCollectionPeriodEndDate.ToString());

            CommUtils.AssertNotNull(dealSchedule.PaymentDates, objStr + "中没有PaymentDatas数据");
            CommUtils.AssertNotNull(dealSchedule.DeterminationDates, objStr + "中没有DeterminationDates数据");
            CommUtils.AssertEquals(dealSchedule.PaymentDates.Length, dealSchedule.DeterminationDates.Length, objStr + "中DealSchedule数据加载失败");

            _durationPeriods = new List <DatasetScheduleLogicModel>();
            for (int i = 0; i < dealSchedule.PaymentDates.Length; i++)
            {
                var paymentDate    = dealSchedule.PaymentDates[i];
                var durationPeriod = new DatasetScheduleLogicModel(project);
                durationPeriod.Sequence    = m_project.GetAllPaymentDates(dealSchedule.PaymentDates).IndexOf(paymentDate) + 1;
                durationPeriod.PaymentDate = paymentDate;
                if (i == 0)
                {
                    durationPeriod.AsOfDateBegin = dealSchedule.FirstCollectionPeriodStartDate;
                }
                else
                {
                    durationPeriod.AsOfDateBegin = dealSchedule.DeterminationDates[i - 1];
                }

                durationPeriod.AsOfDateEnd = dealSchedule.DeterminationDates[i];

                if (i != 0)
                {
                    durationPeriod.Previous      = _durationPeriods[i - 1];
                    durationPeriod.Previous.Next = durationPeriod;
                }

                _durationPeriods.Add(durationPeriod);
            }

            ClosingDate   = dealSchedule.ClosingDate;
            LegalMaturity = dealSchedule.LegalMaturity;
        }