Exemplo n.º 1
0
        public int AddReport(Cde_Report report)
        {
            int reportId = _dataAccess.AddEntity(report);

            foreach (var index in report.IndexList)
            {
                index.ReportId = reportId;
            }
            _dataAccess.AddEntities(report.IndexList);
            return(reportId);
        }
Exemplo n.º 2
0
 public bool UpdateReport(Cde_Report report)
 {
     var where = "Cde_ReportIndex.ReportId=" + report.ReportId;
     _dataAccess.DeleteEntities <Cde_ReportIndex>(where);
     _dataAccess.UpdateEntity(report);
     foreach (var index in report.IndexList)
     {
         index.ReportId = report.ReportId;
     }
     _dataAccess.AddEntities(report.IndexList);
     return(true);
 }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        public int GenerateReport(int surveyId, out string errorMsg)
        {
            //获取评估信息
            var surveyInfo = _dataAccess.Get <Models.Cde.SurveyInfo>(surveyId);

            //判断评估是否已经到期
            //如果没有到期,不能生成结果
            if (surveyInfo.EndTime > DateTime.Now)
            {
                errorMsg = @RetechWing.LanguageResources.TalnetUI.CdeSurvey.CannotGenerate;
                return(0);
            }
            //找到被评人员
            surveyInfo.EvalUsers.AddRange(_dataAccess.GetList <UserSurvey>("Cde_UserSurvey.ApproveFlag=2 AND Cde_UserSurvey.SurveyId=" + surveyId));
            if (surveyInfo.EvalUsers.Count == 0)
            {
                errorMsg = @RetechWing.LanguageResources.TalnetUI.CdeSurvey.NoSubmitSurvey;
                return(0);
            }

            var reports = new List <Cde_Report>();
            //本次评测用到的问卷
            var exampaper = new CdeExampaperManager().GetFullExampaper(surveyInfo.ExampaperId);
            //所有参评者
            var allparts = _dataAccess.GetList <Cde_SurveySendUsers>("Cde_SurveySendUsers.UserSurveyId IN(" + surveyInfo.EvalUsers.Select(p => p.UserSurveyId).GetString() + ")");
            //配置信息
            var cdeConfig = _dataAccess.Get <Cde_Configuration>(surveyInfo.TenantId, "TenantId");

            foreach (var usy in surveyInfo.EvalUsers)
            {
                //判断是否全部未提交
                var sendusers = allparts.Where(p => p.UserSurveyId == usy.UserSurveyId);

                ////如果有未提交的,则不生成报告
                //if (sendusers.Any(p => p.Status != 3))
                //{
                //    continue;
                //}

                //如果有已提交的,则生成报告
                if (!sendusers.Any(p => p.Status == 3))
                {
                    continue;
                }

                var report = new Cde_Report();

                //判断权重
                //参评者
                var partics = allparts.Where(p => p.UserSurveyId == usy.UserSurveyId).ToList();
                int lew = 0, colw = 0, subw = 0, selfw = 0;
                if (partics.Any(p => p.Relationship == 0 && p.Status == 3))
                {
                    lew = cdeConfig.LeaderWeight;
                }
                if (partics.Any(p => p.Relationship == 1 && p.Status == 3))
                {
                    colw = cdeConfig.ColleagueWeight;
                }
                if (partics.Any(p => p.Relationship == 2 && p.Status == 3))
                {
                    subw = cdeConfig.SubordinateWeight;
                }
                if (partics.Any(p => p.Relationship == 3 && p.Status == 3))
                {
                    selfw = cdeConfig.SelfWeight;
                }
                int     total = lew + colw + subw + selfw;//按理说,应该是100,但是找谁说理呢
                decimal ev    = 100m / total;
                //计算最终的真实权重
                report.LeaderWeight      = lew * ev;
                report.ColleagueWeight   = colw * ev;
                report.SubordinateWeight = subw * ev;
                report.SelfWeight        = selfw * ev;

                report.UserSurveyId = usy.UserSurveyId;
                report.UserId       = usy.UserId;
                report.SurveyId     = usy.SurveyId;
                report.IsDelete     = 0;
                var userAns = new CdeSurveySendUserManager().GetUsersReplyAnswers(usy.UserSurveyId);
                //var firstSorts = exampaper.Questions.Select(p => p.SortId).Distinct();
                var secondSorts = exampaper.Questions.Select(p => p.SecondSortId).Distinct();
                //var allsorts = new IndexSortManager().GetSorts(usy.Survey.TenantId);
                //找出所有参评者跟被评估者的关系
                foreach (var answer in userAns)
                {
                    var su = sendusers.FirstOrDefault(p => p.UserId == answer.UserID);
                    if (su != null)
                    {
                        answer.Relationship = su.Relationship;
                    }
                }
                var questions = exampaper.Questions;
                foreach (var secondSort in secondSorts)
                {
                    var detail = new Cde_ReportIndex();
                    detail.SortId       = questions.First(p => p.SecondSortId == secondSort).SortId;
                    detail.SecondSortId = secondSort;
                    var indexQs = questions.Where(p => p.SecondSortId == secondSort);

                    var leaderAns = userAns.Where(p => indexQs.Any(q => q.QuestionId == p.QuestionId))
                                    .Where(p => p.Relationship == 0).ToArray();
                    detail.LeaderScore = leaderAns.Any() ? (decimal)leaderAns.Average(p => p.Score) : 0m;

                    var collAns = userAns.Where(p => indexQs.Any(q => q.QuestionId == p.QuestionId))
                                  .Where(p => p.Relationship == 1).ToArray();
                    detail.ColleagueScore = collAns.Any() ? (decimal)collAns.Average(p => p.Score) : 0m;

                    var subAns = userAns.Where(p => indexQs.Any(q => q.QuestionId == p.QuestionId))
                                 .Where(p => p.Relationship == 2).ToArray();
                    detail.SubordinateScore = subAns.Any() ? (decimal)subAns.Average(p => p.Score) : 0m;

                    var selfAns = userAns.Where(p => indexQs.Any(q => q.QuestionId == p.QuestionId))
                                  .Where(p => p.Relationship == 3).ToArray();
                    detail.SelfScore = selfAns.Any() ? (decimal)selfAns.Average(p => p.Score) : 0m;

                    detail.AvgScore = (
                        detail.LeaderScore * report.LeaderWeight +
                        detail.ColleagueScore * report.ColleagueWeight +
                        detail.SubordinateScore * report.SubordinateWeight +
                        detail.SelfScore * report.SelfWeight
                        ) / 100M;

                    report.IndexList.Add(detail);
                    report.TotalScore = report.IndexList.Average(p => p.AvgScore);
                }
                report.GeneratedTime = DateTime.Now;
                reports.Add(report);
                usy.Report = report;
            }
            if (reports.Count == 0)
            {
                errorMsg = @RetechWing.LanguageResources.TalnetUI.CdeSurvey.NoSubmitSurvey;
                return(0);
            }
            //计算排名
            var orderRpts = reports.OrderByDescending(p => p.TotalScore).ToArray();

            for (int i = 0; i < orderRpts.Length; i++)
            {
                orderRpts[i].OrderNum = i + 1;
            }
            //_dataAccess.AddEntities(reports);
            var reportManager = new CdeReportManager();

            foreach (var report in reports)
            {
                reportManager.AddReport(report);
            }
            foreach (var user in surveyInfo.EvalUsers)
            {
                if (user.Report == null)
                {
                    continue;
                }
                user.ReportGenerated = user.Report.ReportId;
                _dataAccess.UpdateEntity(user);
            }
            surveyInfo.IsGeneratedReport = 1;
            _dataAccess.UpdateEntity(surveyInfo);

            errorMsg = string.Empty;
            return(1);
        }