Example #1
0
        public int GetUserStageLearnPercent(int userId, int applyId)
        {
            var apply         = _dataAccess.Get <PromotionApply>(applyId);
            var stage         = _dataAccess.Get <PromotionStage>(apply.CurrentStageId);
            int completeCount = (int)_dataAccess.ExecuteScalar(string.Format(@"select count(0) from Len_LearningRecord
where LearnProcess = 2 and LearnPath = 3 
and SourceId in (select RecordId from Ab_LearningRecord where StageId = {0} and ApplyId = {2})
and UserId = {1}", apply.CurrentStageId, userId, applyId));
            int allCount      = (int)_dataAccess.ExecuteScalar(string.Format(@"select count(0) from Ab_AbilityResource
where Ab_AbilityResource.IsDelete = 0 and Ab_AbilityResource.ResourceType = 0 
and Ab_AbilityResource.AbilityId in (
	select AbilityId from Ab_PostAbility where IsDelete = 0 and PostId = {0}
)", stage.PostId));

            if (stage.ExamId > 0)
            {
                allCount++;
                var record = _dataAccess.GetListBySql <AbPromotionStageLenRecord>(string.Format(@"select * from Ab_PromotionStageLenRecord where PromotionId = {0} and ApplyId = {1} and StageId = {2} and UserId = {3}", apply.PromotionId, applyId, apply.CurrentStageId, userId)).FirstOrDefault();
                if (record != null)
                {
                    var examuserlist = new RetechWing.BusinessCommon.Examination.ExaminationCommonMethod().GetExamSendStudentWithByRelationIdAndUserId(record.RecordId, 2, userId);
                    if (examuserlist.Any(p => p.IsPass == 1))
                    {
                        completeCount++;
                    }
                }
            }
            return(allCount == 0 ? 0 : completeCount * 100 / allCount);
        }
Example #2
0
        public void StageStudyed(int userId, int promotionId, int stageId)
        {
            var apply = _dataAccess.GetListBySql <PromotionApply>(string.Format("select * from Ab_PromotionApply where IsDelete = 0 and ApproveStatus = 2 and PromotionStatus = 0 and UserId = {0} and PromotionId = {1}", userId, promotionId)).FirstOrDefault();

            if (apply == null || apply.PromotionStatus == 1 || apply.CurrentStageId != stageId)
            {
                return;
            }
            var stageList = _dataAccess.GetList <RetechWing.Models.Ab.PromotionStage>(" IsDelete = 0 and PromotionId = " + promotionId).OrderBy(p => p.OrderNum);
            var stage     = stageList.FirstOrDefault(p => p.StageId == apply.CurrentStageId);

            if (stage.Period > 0 && apply.StageStartTime.HasValue &&
                apply.StageStartTime.Value.AddDays(stage.Period) < DateTime.Now)
            {
                return;
            }
            var recordIdList = _dataAccess.FetchListBySql <int>(string.Format("select RecordId from Ab_LearningRecord where StageId = {0} and ApplyId = {1}", stageId, apply.ApplyId));

            //if (recordIdList.Count() == 0)
            //    return;
            if (recordIdList.Count() == 0)
            {
                if (stage.ObligatoryLessScore > 0)
                {
                    return;
                }
                if (stage.ElectiveLessScore > 0)
                {
                    return;
                }
            }
            else
            {
                var courseElective   = _dataAccess.FetchListBySql <dynamic>(string.Format(@"select ResourceId as CourseId 
,(	
	SELECT COUNT(0) FROM Ab_PostElectiveCourse 
	WHERE PostId = {0} AND AbilityId = Ab_AbilityResource.AbilityId 
	AND COURSEID = Ab_AbilityResource.ResourceId
) AS Elective
from Ab_AbilityResource
where Ab_AbilityResource.IsDelete = 0 and Ab_AbilityResource.ResourceType = 0 
and Ab_AbilityResource.AbilityId in (
	select AbilityId from Ab_PostAbility where IsDelete = 0 and PostId = {0}
)", stage.PostId));
                var courseLearnScore = _dataAccess.GetListBySql <RetechWing.Models.ResCourse>(string.Format(@"select CourseId,LearnScore 
from Res_Course
where Res_Course.CourseId in (
	select CourseId from Len_LearningRecord
	where LearnProcess = 2 and LearnPath = 3 and SourceId in ({0}) and UserID = {1}
)", recordIdList.GetString(), userId));
                if (stage.ObligatoryLessScore > courseLearnScore.Where(p => courseElective.Any(ce => ce.Elective == 0 && ce.CourseId == p.CourseId)).Sum(p => p.LearnScore))
                {
                    return;
                }
                if (stage.ElectiveLessScore > courseLearnScore.Where(p => courseElective.Any(ce => ce.Elective == 1 && ce.CourseId == p.CourseId)).Sum(p => p.LearnScore))
                {
                    return;
                }
            }

            var psRecordList = _dataAccess.GetListBySql <RetechWing.Models.Ab.AbPromotionStageLenRecord>(string.Format(@"select * from Ab_PromotionStageLenRecord where ApplyId = {0} and UserId = {1}", apply.ApplyId, userId));
            var psRecord     = psRecordList.FirstOrDefault(p => p.StageId == stageId);

            if (psRecord == null)
            {
                return;
            }

            if (stage.ExamId > 0)
            {
                var examuserlist = new RetechWing.BusinessCommon.Examination.ExaminationCommonMethod().GetExamSendStudentWithByRelationIdAndUserId(psRecord.RecordId, 2, userId);
                if (examuserlist.Count == 0)
                {
                    return;
                }
                if (!examuserlist.Any(p => p.IsPass == 1))
                {
                    return;
                }
            }

            psRecord.EndTime = DateTime.Now;
            _dataAccess.UpdateEntity(psRecord);

            var nextStage = stageList.FirstOrDefault(p => p.OrderNum == stage.OrderNum + 1);

            while (true)
            {
                if (nextStage == null)
                {
                    break;
                }
                var tmpPsRecord = psRecordList.FirstOrDefault(p => p.StageId == nextStage.StageId);
                if (tmpPsRecord != null && tmpPsRecord.EndTime.HasValue)
                {
                    nextStage = stageList.FirstOrDefault(p => p.OrderNum == nextStage.OrderNum + 1);
                }
                else
                {
                    break;
                }
            }

            apply.StageStartTime = null;
            if (nextStage == null)
            {
                apply.PromotionStatus      = 1;
                apply.PromotionSucceedTime = DateTime.Now;
            }
            else
            {
                apply.CurrentStageId = nextStage.StageId;
            }
            _dataAccess.UpdateEntity(apply);
        }