Beispiel #1
0
        public JsonResult QuotaRecordUpload(List <InstructorQuotaRecord> list)
        {
            var bll       = new InstructorQuotaRecordBll();
            var delegates = new List <Func <bool> >();

            list.ForEach(item =>
            {
                delegates.Add(() =>
                {
                    var condition =
                        $"InstructorId={item.InstructorId} AND QuotaId={item.QuotaId} AND Year={item.Year} AND Month={item.Month}";
                    if (bll.Exists(condition))
                    {
                        return(bll.Delete(condition));
                    }

                    return(true);
                });
            });

            delegates.Add(() =>
            {
                bll.BulkInsert(list);
                return(true);
            });

            if (bll.ExecuteTransation(delegates.ToArray()))
            {
                return(Json(ErrorModel.OperateSuccess));
            }

            return(Json(ErrorModel.OperateFailed));
        }
        private void ComputeScore()
        {
            var quotaBll  = new InstructorQuotaBll();
            var quotaList = quotaBll.QueryList("IsDelete=0").ToList();

            var standardBll  = new InstructorReviewStandardBll();
            var standardList = standardBll.QueryList("IsDelete=0").ToList();

            var currentYear  = DateTime.Now.Year;
            var currentMonth = DateTime.Now.Month;

            var instructorQuotaRecordBll = new InstructorQuotaRecordBll();
            var condition  = $"Year={currentYear} AND Month={currentMonth} AND IsDelete=0";
            var recordList = instructorQuotaRecordBll.QueryList(condition).ToList();

            // 将指标完成记录以指标Id分组
            var groupList = recordList.GroupBy(item => item.QuotaId);

            // 分别计算每项指标得分
            var counterList = new List <ScoreCounter>();

            foreach (var item in groupList)
            {
                var quotaId   = item.Key;
                var quota     = quotaList.Single(q => q.Id == quotaId);
                var standards = standardList.Where(s => s.InstructorQuotaId == quotaId).ToList();

                if (quota.NeedReview)
                {
                    counterList.AddRange(
                        from record in item
                        let score = ScoreCalculater(quota.QuataAmmount, quota.BaseScore, record.FinishedAmmount, standards)
                                    select new ScoreCounter
                    {
                        InstructorId = record.InstructorId,
                        QuotaId      = quotaId,
                        Score        = score
                    });
                }
            }

            // 统计指导司机本月总得分
            var instructorScoreList =
                counterList.GroupBy(item => item.InstructorId)
                .Select(group => new InstructorReviewScore
            {
                InstructorId = group.Key,
                Year         = currentYear,
                Month        = currentMonth,
                Score        = group.Sum(s => s.Score)
            });

            // 删除本月当前得分记录,插入新的得分记录
            var scoreBll        = new InstructorReviewScoreBll();
            var deleteCondition = $"Year={currentYear} AND Month={currentMonth}";

            scoreBll.ExecuteTransation(
                () => !scoreBll.Exists(deleteCondition) || scoreBll.Delete(deleteCondition),
                () =>
            {
                scoreBll.BulkInsert(instructorScoreList);
                return(true);
            });
        }