Esempio n. 1
0
        public JsonResult GetStandardList(int quotaId)
        {
            var standardBll  = new InstructorReviewStandardBll();
            var standardList = standardBll.QueryList($"InstructorQuotaId={quotaId} AND IsDelete=0");

            return(Json(ErrorModel.GetDataSuccess(standardList)));
        }
Esempio n. 2
0
        public JsonResult DeleteStandard(int id)
        {
            var standardBll = new InstructorReviewStandardBll();

            if (standardBll.DeleteSoftly(id))
            {
                return(Json(ErrorModel.OperateSuccess));
            }

            return(Json(ErrorModel.OperateFailed));
        }
Esempio n. 3
0
        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);
            });
        }
Esempio n. 4
0
        public JsonResult SaveQuota()
        {
            var quotaJson = Request["quota"];

            if (string.IsNullOrEmpty(quotaJson))
            {
                return(Json(ErrorModel.InputError));
            }

            var quota = JsonHelper.Deserialize <InstructorQuota>(quotaJson);

            if (quota == null)
            {
                return(Json(ErrorModel.InputError));
            }

            var standardJson = Request["standard"];

            if (quota.NeedReview && string.IsNullOrEmpty(standardJson))
            {
                return(Json(ErrorModel.InputError));
            }

            var standardList = JsonHelper.Deserialize <List <InstructorReviewStandard> >(standardJson);

            if (quota.NeedReview && (standardList == null || standardList.Count == 0))
            {
                return(Json(ErrorModel.InputError));
            }

            var updateType = quota.Id == 0 ? DataUpdateType.Insert : DataUpdateType.Update;

            bool success;
            var  quotaBll = new InstructorQuotaBll();

            if (quota.Id > 0)
            {
                success = quotaBll.Update(quota);
            }
            else
            {
                quotaBll.Insert(quota);
                success = quota.Id > 0;
            }

            if (success)
            {
                DataUpdateLog.SingleUpdate(typeof(InstructorQuota).Name, quota.Id, updateType);

                if (standardList != null && standardList.Count > 0)
                {
                    var standardToInsert = standardList.Where(s => s.Id == 0).ToList();
                    if (standardToInsert.Any())
                    {
                        standardToInsert.ForEach(s => s.InstructorQuotaId = quota.Id);

                        var standardBll = new InstructorReviewStandardBll();
                        standardBll.BulkInsert(standardToInsert);
                    }
                }

                return(Json(ErrorModel.OperateSuccess));
            }

            return(Json(ErrorModel.OperateFailed));
        }