private DataTable GetCashFlowTable(string projectGuid, DateTime paymentDate) { var projectLogicModel = Platform.GetProject(projectGuid); var project = projectLogicModel.Instance; var datasetSchedule = projectLogicModel.DealSchedule.GetByPaymentDay(paymentDate); CommUtils.AssertNotNull(datasetSchedule.Dataset.Instance, "第{0}期模型未生成", Toolkit.DateToString(paymentDate)); //获取预测的资产池当期本金与利息 var acfTable = datasetSchedule.Dataset.DealModel.AssetCashflowDt; for (int i = acfTable.Columns.Count - 1; i >= 0; i--) { var c = acfTable.Columns[i]; DateTime date; if (DateTime.TryParse(c.ColumnName, out date)) { if (date < paymentDate) { acfTable.Columns.Remove(c); } } } var assetViewModel = Toolkit.GetAssetCashflow(acfTable, paymentDate); //判断本金与利息是否被覆盖 var assetCashflowVariable = m_dbAdapter.AssetCashflowVariable.GetByProjectIdPaymentDay(project.ProjectId, paymentDate); var predictInterestCollection = double.Parse(assetViewModel.TotalCurrentInterestCollection.ToString("n2")); var predictPricipalCollection = double.Parse(assetViewModel.TotalCurrentPrinCollection.ToString("n2")); var cashflowDt = ABSDealUtils.GetCashflowDt(datasetSchedule, assetCashflowVariable, predictInterestCollection, predictPricipalCollection, out double currInterest, out double currPrincipal); cashflowDt = ABSDealUtils.CleanAndTranslateCashflowTable(cashflowDt); return(cashflowDt); }
private object GetCFTableByProject(CashflowViewModel viewModel, string projectGuid, DateTime paymentDate) { var project = m_dbAdapter.Project.GetProjectByGuid(projectGuid); var projectLogicModel = Platform.GetProject(projectGuid); var datasetSchedule = projectLogicModel.DealSchedule.GetByPaymentDay(paymentDate); CommUtils.AssertNotNull(datasetSchedule.Dataset.Instance, "第{0}期模型未生成", Toolkit.DateToString(datasetSchedule.PaymentDate)); //同步数据库中参数到模型文件 var variableDateset = m_dbAdapter.CashflowVariable.GetByPaymentDay(project.ProjectId, paymentDate); UpdateVariablesFromCurrPeriodDBToModel(datasetSchedule.Dataset, variableDateset, project.ProjectId, paymentDate); var cashflowTableViewModel = new CashflowDetailTableViewModel(); cashflowTableViewModel.CurrentPaymentDate = Toolkit.DateToString(datasetSchedule.PaymentDate); //获取预测的资产池当期本金与利息 var acfTable = datasetSchedule.Dataset.DealModel.AssetCashflowDt; for (int i = acfTable.Columns.Count - 1; i >= 0; i--) { var c = acfTable.Columns[i]; DateTime date; if (DateTime.TryParse(c.ColumnName, out date)) { if (date < paymentDate) { acfTable.Columns.Remove(c); } } } var assetViewModel = Toolkit.GetAssetCashflow(acfTable, paymentDate); //判断本金与利息是否被覆盖 var assetCashflowVariable = m_dbAdapter.AssetCashflowVariable.GetByProjectIdPaymentDay(project.ProjectId, paymentDate); var cashflowViewModel = new CashflowViewModel(); cashflowViewModel.PredictInterestCollection = double.Parse(assetViewModel.TotalCurrentInterestCollection.ToString("n2")); cashflowViewModel.PredictPricipalCollection = double.Parse(assetViewModel.TotalCurrentPrinCollection.ToString("n2")); cashflowViewModel.OverridableVariables = SelectOverridableVariables(datasetSchedule.Dataset); var cashflowDt = ABSDealUtils.GetCashflowDt(datasetSchedule, assetCashflowVariable, cashflowViewModel.PredictInterestCollection, cashflowViewModel.PredictPricipalCollection, out double currInterest, out double currPrincipal); cashflowViewModel.CurrentInterestCollection = currInterest; cashflowViewModel.CurrentPricipalCollection = currPrincipal; cashflowDt = ABSDealUtils.CleanAndTranslateCashflowTable(cashflowDt); var columnNames = new List <string>(); for (int i = 0; i < cashflowDt.Columns.Count; ++i) { var columnName = cashflowDt.Columns[i].ColumnName.ToString(); columnNames.Add(columnName); } viewModel.ColHeader = columnNames; string testFailRemind = null; var rowsNum = cashflowDt.Rows.Count; if (cashflowDt != null && rowsNum > 0) { var equalRowsNumber = 0; var prevAsset = cashflowDt.Rows[0][0].ToString(); for (int i = 0; i < rowsNum; i++) { DataRow dr = cashflowDt.Rows[i]; var row = dr.ItemArray.ToList().ConvertAll(x => x.ToString()); viewModel.CashflowDataResult.Add(row); if (testFailRemind == null) { if (row.Any(x => x.ToString() == "FAIL")) { testFailRemind = "预测将发生违约,启动差额支付"; } } var element = dr["类型"] != null ? dr["类型"].ToString() : ""; var description = dr["项目描述"] != null ? dr["项目描述"].ToString() : ""; if (prevAsset == element) { equalRowsNumber++; if (i == rowsNum - 1) { var info = new Tuple <int, int, int, int>(rowsNum - equalRowsNumber, 0, equalRowsNumber, 1); viewModel.MergeCellsInfo.Add(info); } } else { var info = new Tuple <int, int, int, int>(i - equalRowsNumber, 0, equalRowsNumber, 1); viewModel.MergeCellsInfo.Add(info); equalRowsNumber = 1; prevAsset = cashflowDt.Rows[i][0].ToString(); } } } var result = new { colHeader = viewModel.ColHeader, paymentDate = Toolkit.DateToString(paymentDate), dataResult = viewModel.CashflowDataResult, mergeCellsInfo = viewModel.MergeCellsInfo.ConvertAll(x => new { row = x.Item1, col = x.Item2, rowspan = x.Item3, colspan = x.Item4 }), isError = false, PredictInterestCollection = cashflowViewModel.PredictInterestCollection, PredictPricipalCollection = cashflowViewModel.PredictPricipalCollection, CurrentInterestCollection = cashflowViewModel.CurrentInterestCollection, CurrentPricipalCollection = cashflowViewModel.CurrentPricipalCollection, OverridableVariables = cashflowViewModel.OverridableVariables, TestFailRemind = testFailRemind }; return(result); }