예제 #1
0
 /// <summary>
 /// 撤回评审
 /// </summary>
 /// <param name="reviewRound"></param>
 /// <returns></returns>
 public virtual async Task WithDraw(ReviewRound reviewRound)
 {
     reviewRound.ReviewStatus        = ReviewStatus.BeforePublish;
     reviewRound.ExpertReviewDetails = new List <ExpertReviewDetail>();//清空打分明细
     reviewRound.Review.ReviewStatus = ReviewStatus.BeforePublish;
     reviewRound.Review.StartTime    = null;
 }
        private async Task BuildTableData(DataTable dt, ReviewRound reviewdetail, List <ProjectReviewSummary> projectreviewsummarys)
        {
            var reviewExpertIds = reviewdetail.Review.ReviewExperts.Select(o => o.Id);
            var reviewProjects  = reviewdetail.Review.ReviewProjects;
            var experts         = await UserManager.Repository.GetAll().Where(o => reviewExpertIds.Contains(o.Id)).ToListAsync();

            //显示的最大轮数
            var maxshowturn      = reviewdetail.Turn == 1 ? reviewdetail.Review.ReviewRounds.Where(o => o.ReviewStatus == ReviewStatus.Reviewed && o.Round == reviewdetail.Round).Max(o => o.Turn) : reviewdetail.Turn;
            var allreviewdetails = reviewdetail.Review.ReviewRounds.Where(o => o.Round == reviewdetail.Round).ToList();

            foreach (var p in projectreviewsummarys)
            {
                var reviewProject = reviewProjects.Where(a => a.Id == p.Id).SingleOrDefault();
                var row           = dt.NewRow();
                row["排名"]   = p.Rank;
                row["序号"]   = p.Sort;
                row["项目名称"] = p.ProjectName;
                row["申报单位"] = p.DesignOrganizationName;
                if (reviewdetail.ReviewMethod == ReviewMethod.Weighting)
                {
                    row["加权得分"] = p.Score;
                }
                row["本轮得分"] = p.OriScore;
                if (reviewdetail.Round == 1 && reviewdetail.Turn == 1 && reviewdetail.ReviewMethod != ReviewMethod.Vote)
                {
                    row["基础分"] = reviewProject?.BaseScore;
                }
                //补投列

                for (var i = 2; i <= maxshowturn; i++)
                {
                    row["补投" + (i - 1)] = p.SubScores[i - 2];
                }
                //专家打分列
                for (var i = 1; i <= maxshowturn; i++)
                {
                    var expertprojectreviewdetail = allreviewdetails[i - 1].ExpertReviewDetails;
                    experts.ForEach(o =>
                    {
                        var projectdetail = expertprojectreviewdetail.Single(e => e.ExpertID == o.Id).ProjectReviewDetails.FirstOrDefault(e => e.ProjectId == p.Id);
                        if (projectdetail != null)
                        {
                            row[o.Name + i] = projectdetail.IsAvoid ? "" : (allreviewdetails[i - 1].ReviewMethod == ReviewMethod.Vote ? (projectdetail.VoteFlag ? "Y" : "") : projectdetail.Score.ToString());
                        }
                    });
                }
                dt.Rows.Add(row);
            }
        }
        /// <summary>
        /// 构建表格结构
        /// </summary>
        /// <param name="review"></param>
        /// <param name="reviewdetail"></param>
        /// <param name="award"></param>
        /// <returns></returns>
        private async Task <DataTable> BuildProjectTable(ReviewRound reviewdetail)
        {
            var reviewExpertIds = reviewdetail.Review.ReviewExperts.Select(o => o.Id);
            var experts         = await UserManager.Repository.GetAll().Where(o => reviewExpertIds.Contains(o.Id)).ToListAsync();

            var dt = new DataTable();
            var c  = 53;//起始颜色

            dt.Columns.AddRange(new DataColumn[] {
                new DataColumn("排名"),
                new DataColumn("序号"),
                new DataColumn("项目名称"),
                new DataColumn("申报单位")
            });
            if (reviewdetail.ReviewMethod == ReviewMethod.Weighting)
            {
                //如果是与上轮加权的,需要增加一列
                dt.Columns.Add("加权得分").Prefix = "c" + c--.ToString();
            }
            dt.Columns.Add("本轮得分").Prefix = "c" + c--.ToString();
            if (reviewdetail.Round == 1 && reviewdetail.Turn == 1 && reviewdetail.ReviewMethod != ReviewMethod.Vote)
            {
                dt.Columns.Add("基础分").Prefix = "c" + c.ToString();
            }
            //补投列
            //显示的最大轮数
            var maxshowturn = reviewdetail.Turn == 1 ? reviewdetail.Review.ReviewRounds.Where(o => o.ReviewStatus == ReviewStatus.Reviewed && o.Round == reviewdetail.Round).Max(o => o.Turn) : reviewdetail.Turn;

            for (var i = 2; i <= maxshowturn; i++)
            {
                dt.Columns.Add("补投" + (i - 1)).Prefix = "c" + c--.ToString();
            }
            //专家打分列
            for (var i = 1; i <= maxshowturn; i++)
            {
                experts.ForEach(o => {
                    dt.Columns.Add(o.Name + i).Prefix = "c" + (c + i - 1).ToString();
                });
            }
            return(dt);
        }
        /// <summary>
        /// 提交评审活动
        /// </summary>
        /// <returns></returns>
        public virtual async Task SubmitReviewRound(ReviewRoundDto reviewRoundDto)
        {
            var manager = Manager as ReviewManager;
            var review  = await Manager.GetByIdAsync(reviewRoundDto.ReviewId);

            ReviewRound reviewRound = null;
            await Repository.EnsureCollectionLoadedAsync(review, o => o.ReviewRounds);

            if (reviewRoundDto.Id == 0)
            {
                //新的评审
                if (review.ReviewRounds.Count(o => o.Round == reviewRoundDto.Round && o.Turn == reviewRoundDto.Turn) > 0)
                {
                    throw new UserFriendlyException("相同轮次的评审已存在");
                }
                else
                {
                    reviewRound = reviewRoundDto.MapTo <ReviewRound>();
                    //设置源项目id
                    if (review.ReviewRounds.Count == 0)
                    {
                        //如果是第一次评审,则取评选活动的参选项目做为本次评选的来源项目
                        reviewRound.SourceProjectIDs = string.Join(',', review.ReviewProjects.Select(o => o.Id));
                    }
                    else
                    {
                        //非第一次评审,则取选择的项目作为来源项目
                        //reviewRound.SourceProjectIDs = review.ReviewRounds.Last().ResultProjectIDs;
                    }
                    review.ReviewRounds.Add(reviewRound);
                    //如果有专家回避了所有项目,则直接设置此专家为已提交状态
                    var reviewProjects      = review.ReviewProjects.Where(o => reviewRound.SourceProjectIDs.Split(',').Contains(o.Id.ToString()));
                    var excludeExpertIdsAll = reviewProjects.SelectMany(o => {
                        var excludeExpertIdsStr = string.IsNullOrEmpty(o.ExcludeExpertIDs) ? "" : o.ExcludeExpertIDs;
                        return(excludeExpertIdsStr.Split(','));
                    }).ToList();
                    foreach (var expert in review.ReviewExperts)
                    {
                        if (excludeExpertIdsAll.Count(o => o == expert.Id.ToString()) == reviewProjects.Count())
                        {
                            reviewRound.ExpertReviewDetails = new List <ExpertReviewDetail>()
                            {
                                new ExpertReviewDetail()
                                {
                                    ExpertID             = expert.Id,
                                    FinishTime           = DateTime.Now,
                                    ProjectReviewDetails = new List <ProjectReviewDetail>()
                                }
                            };
                        }
                    }
                }
            }
            else
            {
                //修改
                reviewRound = await ReviewRoundRepository.GetAsync(reviewRoundDto.Id);

                reviewRoundDto.MapTo(reviewRound);
            }
            //如果使用评分表,则将评分表的总分作为评审活动的分制上限
            if (reviewRound.ReviewMethodSetting.RateType == RateType.RateTable)
            {
                var rateTables = await manager.GetRateTable(review);

                var reviewMethodSetting = reviewRound.ReviewMethodSetting;
                reviewMethodSetting.MaxScore    = rateTables[0].TotalScore;
                reviewRound.ReviewMethodSetting = reviewMethodSetting;
            }
            //根据评审轮次的状态更新评选活动的状态
            review.ReviewStatus = reviewRoundDto.ReviewStatus;
            if (review.ReviewStatus == ReviewStatus.Reviewing)
            {
                review.StartTime = DateTime.Now;
            }
        }
예제 #5
0
        /// <summary>
        /// 获取项目得分详情列表
        /// </summary>
        /// <returns></returns>
        public virtual async Task <List <ProjectReviewSummary> > GetProjectRanks(ReviewRound reviewRound, int r = 0)
        {
            //本轮首次得分
            //var mainreviewdetail = Config.Helper.Single<ReviewDetail>("where reviewid=@0 and round=@1 and turn=1", ReviewID, r == 0 ? Round : r);
            var mainReviewDetail = reviewRound.Review.ReviewRounds.Single(o => o.Turn == 1 && o.Round == (r == 0 ? reviewRound.Round : r));
            //var otherreviewdetails = Config.Helper.CreateWhere<ReviewDetail>()
            //    .Where(p => p.ReviewID == ReviewID && p.Round == mainreviewdetail.Round && p.Turn > 1 && p.ReviewStatus == ReviewStatus.Reviewed).Select();
            //modi20181104未完成的评审活动的数据也需要
            var otherReviewDetails = reviewRound.Review.ReviewRounds.Where(o => o.Round == mainReviewDetail.Round && o.Turn > 1 /*&& o.ReviewStatus == ReviewStatus.Reviewed*/).OrderBy(o => o.Turn).ToList();
            //上轮得分
            List <ProjectReviewSummary> lastProjectRanks = null;
            //参数
            var methodsetting = mainReviewDetail.ReviewMethodSetting;

            if (mainReviewDetail.ReviewMethod == ReviewMethod.Weighting)
            {
                lastProjectRanks = await GetProjectRanks(reviewRound, mainReviewDetail.Round - 1);
            }
            //var sourceProjects = Config.Helper.CreateWhere<Project>()
            //    .AddWhereSql("id in(" + mainreviewdetail.SourceProjectIDs + ")")
            //    .Select();
            var sourceProjectIds = mainReviewDetail.SourceProjectIDs.Split(',').Select(s => int.Parse(s));
            var sourceProjects   = await ProjectRepository.GetAll().Where(o => sourceProjectIds.Contains(o.Id)).ToListAsync();

            //var projectdetails = mainreviewdetail.VoteDetails.SelectMany(o => o.VoteProjectDetail);
            var projectDetails = mainReviewDetail.ExpertReviewDetails.Where(o => o.FinishTime != null).SelectMany(o => o.ProjectReviewDetails);
            var result         = sourceProjects.Select(o =>
            {
                //var awardproject = Config.Helper.CreateWhere<AwardProject>()
                //.Where(a => a.AwardID == review.AwardID && a.ProjectID == o.ID)
                //.SingleOrDefault();
                var reviewProject = reviewRound.Review.ReviewProjects.Single(p => p.Id == o.Id);

                var obj                    = new ProjectReviewSummary();
                obj.Id                     = o.Id;
                obj.Round                  = reviewRound.Round;
                obj.MaxScore               = reviewRound.ReviewMethodSetting.MaxScore;
                obj.ProjectName            = o.ProjectName;
                obj.PrizeName              = o.Prize.PrizeName;
                obj.SubMajorName           = o.PrizeSubMajor?.Major.BriefName;
                obj.DesignOrganizationName = o.DesignOrganization.BriefName;
                obj.Sort                   = reviewProject.Sort; //排序
                obj.NeedConfirm            = false;              //同分标记
                //得分
                if (mainReviewDetail.ReviewMethod == ReviewMethod.Vote)
                {
                    obj.Score = projectDetails.Where(p => p.ProjectId == o.Id).Sum(p =>
                    {
                        if (p.IsAvoid)
                        {
                            return(0);
                        }
                        return(p.VoteFlag ? 1 : 0);
                    });
                }
                else
                {
                    var scores = projectDetails.Where(p => p.ProjectId == o.Id && !p.IsAvoid).Select(p => p.Score.Value).ToList();
                    //如果是第一轮第一次的平均分计算,且存在基础分,则将基础分加入
                    if (mainReviewDetail.Round == 1 && reviewProject.BaseScore != null)
                    {
                        scores.Add(Convert.ToDecimal(reviewProject.BaseScore));
                    }
                    obj.Score = Math.Round(CalculateScore(scores, mainReviewDetail.ReviewMethodSetting), 4);
                    //obj.Score =Math.Round( projectdetails.Where(p => p.ProjectID == o.ID && !p.IsAvoid).Average(p =>
                    //{
                    //    return p.Score;
                    //}),4);
                    obj.OriScore = obj.Score;
                    //与上轮加权的还需要再计算
                    if (mainReviewDetail.ReviewMethod == ReviewMethod.Weighting && mainReviewDetail.Round > 1)
                    {
                        var lastroundscore = lastProjectRanks.Single(p => p.Id == o.Id).Score;
                        obj.Score          = Math.Round(lastroundscore * methodsetting.WeightLast / 100 + obj.Score * methodsetting.WeightNow / 100, 4);
                    }
                }
                obj.TotalScore = obj.Score * 1000; //TotalScore用来存本轮的总分用来排序
                                                   //需要将同轮下面几次的分数也列出

                for (var i = 0; i < otherReviewDetails.Count; i++)
                {
                    var p        = otherReviewDetails[i];
                    var subscore = p.ExpertReviewDetails.Where(e => e.FinishTime != null).SelectMany(v => v.ProjectReviewDetails).Where(v => v.ProjectId == o.Id).Sum(d =>
                    {
                        if (d.IsAvoid)
                        {
                            return(0);
                        }
                        return(d.VoteFlag ? 1 : 0);
                    });
                    obj.SubScores.Add(subscore);
                    obj.TotalScore += Convert.ToDecimal(subscore * Math.Pow(10, -i));
                }

                #region old
                //otherReviewDetails.ForEach(p =>
                //{
                //    var subscore = p.ExpertReviewDetails.Where(e => e.FinishTime != null).SelectMany(v => v.ProjectReviewDetails).Where(v => v.ProjectId == o.Id).Sum(d =>
                //        {
                //            if (d.IsAvoid) { return 0; }
                //            return d.VoteFlag ? 1 : 0;
                //        });
                //    obj.SubScores.Add(subscore);
                //    obj.TotalScore += subscore;
                //});
                #endregion

                return(obj);
            }).OrderByDescending(o => o.TotalScore).ToList();

            return(result);
        }