public ActionResult SurveyReport(int userSurveyId) { Cde_Report report = _reportManager.GetReport(userSurveyId); UserSurvey userSurvey = _surveyManager.GetSurveyInfoByUserSurveyId(userSurveyId); report.Survey = userSurvey.Survey; report.User = _userManager.GetUserById(userSurvey.UserId); report.Survey.Exampaper = _exampaperManager.GetFullExampaper(userSurvey.Survey.ExampaperId); report.SendUsers.AddRange(_userSendSurveyManager.GetSurveySendUsers(userSurveyId)); _surveyManager.LoadSendUsers(report.Survey); Cde_Configuration config = _configManager.GetConfig(CurrentTenant.TenantId); ViewBag.surveyConfig = config; List <Cde_SurveyReplyAnswer> userAnswers = _userSendSurveyManager.GetUsersReplyAnswers(userSurveyId); foreach (Cde_SurveyReplyAnswer answer in userAnswers) { Cde_SurveySendUsers anuser = report.SendUsers.Find(p => p.UserId == answer.UserID); if (anuser != null) { answer.Relationship = anuser.Relationship; } } foreach (Cde_IndexQuestion question in report.Survey.Exampaper.Questions) { IEnumerable <Cde_SurveyReplyAnswer> qans = userAnswers.Where(p => p.QuestionId == question.QuestionId); question.ReplyAnswers.AddRange(qans); IEnumerable <Cde_SurveyReplyAnswer> lans = qans.Where(p => p.Relationship == 0); IEnumerable <Cde_SurveyReplyAnswer> colans = qans.Where(p => p.Relationship == 1); IEnumerable <Cde_SurveyReplyAnswer> subans = qans.Where(p => p.Relationship == 2); IEnumerable <Cde_SurveyReplyAnswer> selfans = qans.Where(p => p.Relationship == 3); double ls = lans.Any() ? lans.Average(p => p.Score) : 0d; double cs = colans.Any() ? colans.Average(p => p.Score) : 0d; double sus = subans.Any() ? subans.Average(p => p.Score) : 0d; double ss = selfans.Any() ? selfans.Average(p => p.Score) : 0d; question.AverageScore = (ls * config.LeaderWeight / 100d + cs * config.ColleagueWeight / 100d + sus * config.SubordinateWeight / 100d + ss * config.SelfWeight / 100d); question.OtherScore = (ls * config.LeaderWeight / 100d + cs * config.ColleagueWeight / 100d + sus * config.SubordinateWeight / 100d) * (1 - config.SelfWeight / 100d); question.SelfScore = ss; } foreach (Cde_ReportIndex index in report.IndexList) { index.OtherScore = (index.LeaderScore * config.LeaderWeight / 100m + index.ColleagueScore * config.ColleagueWeight / 100m + index.SubordinateScore * config.SubordinateWeight / 100m) / (1M - config.SelfWeight / 100m); } return(View(report)); }
public JsonResult SaveSurveyAnswer(string data, int userSurveyId, int sendId, int issubmit, int exampaperId) { try { dynamic replyAnswer = JsonConvert.DeserializeObject(data); List <Cde_IndexQuestion> questions = _questionManager.GetExampaperQuestions(exampaperId); var list = new List <Cde_SurveyReplyAnswer>(); foreach (dynamic reply in replyAnswer) { int id = reply.id; if (reply.content == null) { continue; } string content = reply.content; Cde_IndexQuestion q = questions.FirstOrDefault(p => p.QuestionId == id); if (q == null) { q = new Cde_IndexQuestion(); } int score = 0; if (reply.type == 0) { Cde_IndexQuestionAnswer a = q.Answers.FirstOrDefault(p => p.AnswerId == int.Parse(content)); if (a == null) { a = new Cde_IndexQuestionAnswer(); } score = a.Score; } list.Add(new Cde_SurveyReplyAnswer { SendUserId = sendId, QuestionId = reply.id, ExampaperID = exampaperId, UserSurveyID = userSurveyId, Status = issubmit == 0 ? 0 : 1, UserID = CurrentUser.UserId, ObjectiveAnswer = reply.content, SubjectiveAnswer = reply.content, AnswerTime = DateTime.Now, Score = score }); } if (list.Count > 0) { _userSurveyManager.AddSurveyAnswers(userSurveyId, sendId, list); } Cde_SurveySendUsers sendInfo = _userSendSurveyManager.GetSendUserById(sendId); sendInfo.Status = issubmit + 2; sendInfo.SubmitTime = DateTime.Now; _userSendSurveyManager.UpdateSurveySendUser(sendInfo); return(Json(1, JsonRequestBehavior.DenyGet)); } catch (Exception ex) { LogHelper.WriteLog("填写360评估提交答案时出现问题", ex); return(Json(0, JsonRequestBehavior.DenyGet)); } }