Exemple #1
0
        private void UpdateVariablesFromCurrPeriodDBToModel(DatasetLogicModel dataset,
                                                            List <CashflowVariable> variableDateset, int projectId, DateTime paymentDate)
        {
            if (dataset == null)
            {
                return;
            }

            if (variableDateset.Count == 0)
            {
                var tasks = m_dbAdapter.Task.GetTasksByProjectId(projectId, true);
                tasks = tasks.Where(x =>
                                    x.TaskExtensionId.HasValue && x.TaskExtension.TaskExtensionType == TaskExtensionType.Cashflow.ToString()
                                    ).ToList();

                if (tasks.Count > 0)
                {
                    var projectLogicModel = dataset.ProjectLogicModel;
                    var allPaymentDays    = projectLogicModel.GetAllPaymentDates(projectLogicModel.DealSchedule.Instanse.PaymentDates);

                    var currPaymentDateIndex = allPaymentDays.IndexOf(paymentDate);
                    if (currPaymentDateIndex != -1)
                    {
                        if (currPaymentDateIndex == 0)
                        {
                            tasks = tasks.Where(x => x.EndTime <= paymentDate).ToList();
                        }
                        else
                        {
                            tasks = tasks.Where(x => x.EndTime > allPaymentDays[currPaymentDateIndex + 1] && x.EndTime <= paymentDate).ToList();
                        }

                        if (tasks.Count > 0)
                        {
                            var task        = tasks.First();
                            var dbViewModel = Toolkit.ConvertTaskExtension(task.TaskExtension).Info as CashflowViewModel;
                            if (dbViewModel != null)
                            {
                                var cashflowVariable = SaveOverridableVariable(dbViewModel.OverridableVariables, projectId, paymentDate);

                                UpdateVariablesFromCurrPeriodDBToModel(dataset, cashflowVariable, projectId, paymentDate);
                            }
                        }
                    }
                }
            }

            //更新FutureVariables.csv
            foreach (var keyVal in variableDateset)
            {
                dataset.Variables.UpdateVariableValue(keyVal.EnglishName, dataset.DatasetSchedule.PaymentDate, keyVal.Value.ToString());
            }

            //更新CurrentVariables.csv
            //设置 OtherIncome = 当期的OtherIncomeMax + 前一期模型的OtherIncome
            var otherIncomeMaxKeyVal = variableDateset.SingleOrDefault(x => x.EnglishName.Equals("OtherIncomeMax", StringComparison.CurrentCultureIgnoreCase));

            if (otherIncomeMaxKeyVal != null)
            {
                var key = "OtherIncome";
                var otherIncomeValue = otherIncomeMaxKeyVal.Value;

                if (dataset.Previous != null && dataset.Previous.Instance != null)
                {
                    //当前一期Dataset存在时,如果前一期的CurrentVariablesCsv不存在,不处理前一期表中的OtherIncome
                    if (dataset.Previous.Variables.CurrentVariables.Count > 0)
                    {
                        //var prevColumnDate = dataset.Previous.Variables..DateColumns.First();
                        foreach (var record in dataset.Previous.Variables.CurrentVariables)
                        {
                            if (record.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                            {
                                double prevOtherIncome = 0;
                                if (double.TryParse(record.Value, out prevOtherIncome))
                                {
                                    otherIncomeValue += prevOtherIncome;
                                    break;
                                }
                            }
                        }
                    }
                }

                var currentCsv = dataset.Variables.CurrentVariables;

                CommUtils.Assert(currentCsv.Count > 0,
                                 $"第{DateUtils.DateToString(paymentDate)}期模型中,currentCSV不包含任何偿付期列");
                var date = dataset.Variables.Asofdate;

                dataset.Variables.UpdateVariableValue(key, date, otherIncomeValue.ToString(), "其它收益");
                dataset.Variables.Save();
            }
        }
        public ActionResult Index(string shortCode)
        {
            if (string.IsNullOrEmpty(shortCode))
            {
                return(RedirectToAction("Index", "Schedule"));
            }

            var task    = m_dbAdapter.Task.GetTask(shortCode);
            var project = m_dbAdapter.Project.GetProjectById(task.ProjectId);

            task.ProjectName = project.Name;

            var taskViewModel = Toolkit.ConvertTask(task);

            GetPrevAndNextTaskShortCode(taskViewModel, task);
            taskViewModel.ProjectGuid = project.ProjectGuid;
            taskViewModel.TaskHandler = Platform.UserProfile.GetDisplayRealNameAndUserName(taskViewModel.TaskHandler);

            taskViewModel.PrevTaskNameArray      = new List <string>();
            taskViewModel.PrevTaskShortCodeArray = new List <string>();
            foreach (var prevTaskId in task.PrevTaskIdArray)
            {
                var prevTask = m_dbAdapter.Task.GetTask(prevTaskId);
                taskViewModel.PrevTaskShortCodeArray.Add(prevTask.ShortCode);
                taskViewModel.PrevTaskNameArray.Add(prevTask.Description);
            }

            //Get task extension info.
            if (task.TaskExtensionId.HasValue)
            {
                var taskExtension = m_dbAdapter.Task.GetTaskExtension(task.TaskExtensionId.Value);
                taskExtension.TaskExtensionHandler = Platform.UserProfile.GetDisplayRealNameAndUserName(taskExtension.TaskExtensionHandler);
                taskViewModel.TaskExtension        = Toolkit.ConvertTaskExtension(taskExtension);

                var instance = TaskExFactory.CreateInstance(taskViewModel.TaskExtension.Type, shortCode, CurrentUserName);
                if (instance != null)
                {
                    //扩展工作页面初始化时的异常返回错误信息
                    object entity;
                    try
                    {
                        entity = instance.GetEntity();
                    }
                    catch (ApplicationException e)
                    {
                        entity = e.Message;
                    }
                    taskViewModel.TaskExtension.Info = entity;
                }
            }

            //Get task status history info.
            var taskStatusHitory = m_dbAdapter.Task.GetTaskStatusHistory(task.TaskId);

            if (taskStatusHitory != null)
            {
                var usernameCache = new Dictionary <string, string>();

                taskViewModel.TaskStatusHistory = new List <TaskStatusHistoryViewModel>();
                foreach (var item in taskStatusHitory)
                {
                    var viewModel = Toolkit.ConvertTaskStatusHistory(item);

                    string name = string.Empty;
                    if (usernameCache.ContainsKey(viewModel.TimeStampUserName))
                    {
                        name = usernameCache[viewModel.TimeStampUserName];
                    }
                    else
                    {
                        name = m_dbAdapter.Authority.GetNameByUserName(viewModel.TimeStampUserName);
                        usernameCache[viewModel.TimeStampUserName] = name;
                    }

                    name = string.IsNullOrEmpty(name) ? viewModel.TimeStampUserName
                        : (name + "(" + viewModel.TimeStampUserName + ")");
                    viewModel.TimeStampUserName = name;

                    taskViewModel.TaskStatusHistory.Add(viewModel);
                }
            }

            taskViewModel.ProjectSeriesStage = ProjectSeriesStage.存续期;
            if (project.ProjectSeriesId.HasValue && project.TypeId.HasValue && project.TypeId.Value == 1)
            {
                taskViewModel.ProjectSeriesStage = ProjectSeriesStage.发行;

                var projectSeries = m_dbAdapter.ProjectSeries.GetById(project.ProjectSeriesId.Value);
                taskViewModel.ProjectSeriesGuid = projectSeries.Guid;
            }

            return(View(taskViewModel));
        }