/// <summary> /// 取得風險評估問卷資料 /// </summary> /// <param name="questId">問卷編號</param> /// <param name="userId">用戶ID</param> /// <returns>風險評估問卷資料</returns> public RiskEvaQuestionnaireEntity GetRiskQuestionnaire(string questId, string userId) { RiskEvaQuestionnaireEntity result = null; if (String.IsNullOrEmpty(questId)) { throw new ArgumentNullException("questId"); } else if (String.IsNullOrEmpty(userId)) { throw new ArgumentNullException("userId"); } RiskEvaluationDO riskEvaluationDO = new RiskEvaluationDAO().GetLatestRiskEvaluation(userId); bool canEvaluteRisk = CheckCanEvaluteRisk(riskEvaluationDO); if (!canEvaluteRisk) { var ex = new InvalidOperationException("Not can used risk evaluation"); ex.Data["canEvaluteRisk"] = canEvaluteRisk; throw ex; } QuestionnaireEntity activeQuestionnaire = QuestService.GetActiveQuestionnaire(questId); if (activeQuestionnaire == null) { var ex = new InvalidOperationException("activeQuestionnaire not found"); ex.Data["questId"] = questId; throw ex; } result = new RiskEvaQuestionnaireEntity() { QuestionnaireEntity = activeQuestionnaire, }; return(result); }
/// <summary> /// 儲存評估投資風險評估結果資料 /// </summary> /// <param name="riskResultId">風險評估結果識別代號</param> public void SaveRiskRank(string riskResultId) { if (String.IsNullOrEmpty(riskResultId)) { throw new ArgumentNullException("riskResultId"); } RiskEvaResultDTO riskEvaResultDTO = GetRiskResult(riskResultId); if (riskEvaResultDTO == null) { var ex = new InvalidOperationException("riskEvaResultDTO not found"); ex.Data["riskResultId"] = riskResultId; throw ex; } else if (riskEvaResultDTO.QuestionnaireResultEntity == null) { var ex = new InvalidOperationException("QuestionnaireResultEntity not found"); ex.Data["riskResultId"] = riskResultId; throw ex; } QuestionnaireResultEntity questResultEntity = riskEvaResultDTO.QuestionnaireResultEntity; RiskEvaluationDO riskEvaluationDO = new RiskEvaluationDAO().GetLatestRiskEvaluation( questResultEntity.TesteeId); bool canEvaluteRisk = CheckCanEvaluteRisk(riskEvaluationDO); if (!canEvaluteRisk) { var ex = new InvalidOperationException("Not can used risk evaluation"); ex.Data["canEvaluteRisk"] = canEvaluteRisk; throw ex; } DateTime currenTime = DateTime.Now; if (riskEvaluationDO == null) { riskEvaluationDO = new RiskEvaluationDO() { Uid = Guid.NewGuid(), RiskEvaId = _riskEvaIdFundInvestment, QuestAnswerId = questResultEntity.QuestAnswerId, CliId = questResultEntity.TesteeId, RiskResult = string.Join(";", questResultEntity.RiskResult.Select(x => $"[{x.Key}:{x.Value}]")), RiskScore = questResultEntity.ActualScore, RiskAttribute = questResultEntity.RiskRankKind, EvaluationDate = currenTime, BusinessDate = ConvertBusinessDate(currenTime), IsUsed = "N", CreateUserId = questResultEntity.TesteeId, CreateTime = currenTime, ModifyUserId = null, ModifyTime = null, }; new RiskEvaluationDAO().Insert(riskEvaluationDO); } else { bool inCuttimeRange = CheckInCuttimeRange(riskEvaluationDO); if (inCuttimeRange) { riskEvaluationDO.QuestAnswerId = questResultEntity.QuestAnswerId; riskEvaluationDO.RiskResult = String.Join(";", questResultEntity.RiskResult.Select(x => $"[{x.Key}:{x.Value}]")); riskEvaluationDO.RiskScore = questResultEntity.ActualScore; riskEvaluationDO.RiskAttribute = questResultEntity.RiskRankKind; riskEvaluationDO.EvaluationDate = currenTime; riskEvaluationDO.BusinessDate = ConvertBusinessDate(currenTime); riskEvaluationDO.IsUsed = "N"; riskEvaluationDO.ModifyUserId = questResultEntity.TesteeId; riskEvaluationDO.ModifyTime = currenTime; new RiskEvaluationDAO().Update(riskEvaluationDO); } else { riskEvaluationDO = new RiskEvaluationDO() { Uid = Guid.NewGuid(), RiskEvaId = _riskEvaIdFundInvestment, QuestAnswerId = questResultEntity.QuestAnswerId, CliId = questResultEntity.TesteeId, RiskResult = String.Join(";", questResultEntity.RiskResult.Select(x => $"[{x.Key}:{x.Value}]")), RiskScore = questResultEntity.ActualScore, RiskAttribute = questResultEntity.RiskRankKind, EvaluationDate = currenTime, BusinessDate = ConvertBusinessDate(currenTime), IsUsed = "N", CreateUserId = questResultEntity.TesteeId, CreateTime = currenTime, ModifyUserId = null, ModifyTime = null, }; new RiskEvaluationDAO().Insert(riskEvaluationDO); } } }
/// <summary> /// 評估投資風險等級 /// </summary> /// <param name="answer">風險評估填答資料</param> /// <returns></returns> public RiskEvaResultDTO EvaluateRiskRank(RiskEvaAnswerEntity answer) { RiskEvaResultDTO riskEvaResultDTO = null; QuestionnaireResultEntity questionResultEntity = null; if (answer == null) { throw new ArgumentNullException("answer"); } else if (answer.QuestionnaireAnswerEntity == null) { throw new ArgumentNullException("QuestionnaireAnswerEntity"); } RiskEvaluationDO riskEvaluationDO = new RiskEvaluationDAO().GetLatestRiskEvaluation( answer.QuestionnaireAnswerEntity.UserId); bool canEvaluteRisk = CheckCanEvaluteRisk(riskEvaluationDO); if (!canEvaluteRisk) { var ex = new InvalidOperationException("Not can used risk evaluation"); ex.Data["canEvaluteRisk"] = canEvaluteRisk; throw ex; } questionResultEntity = QuestService.Calculate(answer.QuestionnaireAnswerEntity); if (questionResultEntity == null) { throw new InvalidOperationException("questResultEntity not found"); } if (questionResultEntity.QuestionnaireEntity.NeedScore == "Y") { RiskRankDO riskRankDO = new RiskRankDAO().GetRiskRank(questionResultEntity.ActualScore, _riskEvaIdFundInvestment); if (riskRankDO == null) { var ex = new InvalidOperationException("riskRankDO not found"); ex.Data["QuestId"] = questionResultEntity.QuestionnaireEntity.QuestId; ex.Data["UserId"] = answer.QuestionnaireAnswerEntity.UserId; ex.Data["ActualScore"] = questionResultEntity.ActualScore; ex.Data["riskEvaId"] = _riskEvaIdFundInvestment; throw ex; } questionResultEntity.RiskRankKind = riskRankDO.RiskRankKind; } riskEvaResultDTO = new RiskEvaResultDTO() { QuestionnaireResultEntity = questionResultEntity, RiskRankEntities = GetRiskRankEntities(_riskEvaIdFundInvestment), }; CacheProvider.SetCache($"{_cacheKeyQuestionResultEntity}-{questionResultEntity.QuestAnswerId}", questionResultEntity); return(riskEvaResultDTO); }