Ejemplo n.º 1
0
        /// <summary>
        /// 我的统计积分-查询db
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        private async Task <UserCourseStatisticsOutputDto> GetMyStatisticsScoreFromDb(long userId)
        {
            var result = new UserCourseStatisticsOutputDto();
            //我的统计积分来自于必修课程与选修课程,必修课程的积分来自于全员必修和部分必修
            //先查询所有已修完毕的记录
            var complateSourceList = await(from b in _repository.GetAll().Where(x => !x.IsDeleted && x.UserId == userId && x.IsComplete == true)
                                           join c in _courseRepository.GetAll().Where(x => !x.IsDeleted && x.Status == -1 && !x.IsDelCourse) on b.CourseId equals c.Id
                                           select new
            {
                c.LearnType
            }).ToListAsync();

            //我的已修必修课数
            result.RequiredComplateSourceScore = complateSourceList
                                                 .Count(x => x.LearnType == CourseLearnType.Must || x.LearnType == CourseLearnType.MustAll);
            //所有必修数
            var userIdStr = "u_" + userId;

            result.RequiredAllSourceScore = await(from a in _courseRepository.GetAll().Where(x =>
                                                                                             !x.IsDeleted && !x.IsDelCourse &&
                                                                                             ((x.LearnType == CourseLearnType.Must && x.LearnUser.GetStrContainsArray(userIdStr)) ||
                                                                                              x.LearnType == CourseLearnType.MustAll) && x.Status == -1)
                                                  select a
                                                  ).CountAsync();
            //我的已修选修课数
            result.ElectiveComplateSourceScore = complateSourceList
                                                 .Count(x => x.LearnType == CourseLearnType.Selected);
            //所有我观看过的选修数
            var setElectiveIsSpecial = (await _courseSettingAppService.GetSetVal(CourseLearnType.Selected, true))
                                       .ClassHourScore;
            var setElectiveNotSpecial = (await _courseSettingAppService.GetSetVal(CourseLearnType.Selected, false))
                                        .ClassHourScore;

            result.ElectiveAllSourceScore =
                await(from a in _repository.GetAll().Where(x => !x.IsDeleted && x.UserId == userId)
                      join c in _courseRepository.GetAll()
                      .Where(x => !x.IsDeleted && !x.IsDelCourse && x.LearnType == CourseLearnType.Selected && x.Status == -1) on a.CourseId equals c.Id
                      select c.IsSpecial ? setElectiveIsSpecial : setElectiveNotSpecial
                      ).CountAsync();
            //我的课数
            result.MyAllSourceScore      = result.RequiredAllSourceScore + result.ElectiveAllSourceScore;
            result.MyComplateSourceScore = result.RequiredComplateSourceScore + result.ElectiveComplateSourceScore;
            //学习时长
            result.LearnTime = await _courseRecordDetailRepository.GetAll()
                               .Where(x => !x.IsDeleted && x.UserId == userId)
                               .Select(x => new
            {
                x.LearningTime,
                x.CourseId,
            }).GroupBy(x => x.CourseId)
                               .Select(x => x.OrderByDescending(y => y.LearningTime).FirstOrDefault().LearningTime).SumAsync();

            //本周排名
            var myRank = await _courseAppService.GetCourseWeekRankById(userId);

            result.ThisWeekRank = myRank?.Rank ?? -1;
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加一个UserCourseComment
        /// </summary>
        /// <param name="input">实体</param>
        /// <returns></returns>

        public async Task Create(CreateUserCourseCommentInput input)
        {
            var model = await _courseRepository.FirstOrDefaultAsync(x => x.Id == input.CourseId && x.Status == -1);

            if (model == null)
            {
                throw new UserFriendlyException((int)ErrorCode.CodeValErr, "课程不存在!");
            }
            var userId   = (await base.GetCurrentUserAsync()).Id;
            var newmodel = new UserCourseComment()
            {
                UserId   = userId,
                CourseId = input.CourseId,
                Comment  = input.Comment
            };
            await _repository.InsertAsync(newmodel);

            //送积分
            var set = await _courseSettingAppService.GetSetVal(model.LearnType, model.IsSpecial);

            if (set.CommentScore > 0)
            {
                await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                {
                    FromId     = input.CourseId,
                    FromType   = TrainScoreFromType.CourseComment,
                    BusinessId = newmodel.Id,
                    Score      = set.CommentScore,
                    UserId     = userId
                });
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加一个UserCourseRecordDetail
        /// </summary>
        /// <param name="input">实体</param>
        /// <returns></returns>

        public async Task Create(CreateUserCourseRecordDetailInput input)
        {
            var user = await base.GetCurrentUserAsync();

            var chkCreate = false;
            //查询出课程
            var couser = await _couserRepository.FirstOrDefaultAsync(x => x.Id == input.CourseId && x.Status == -1);

            if (couser == null)
            {
                throw new UserFriendlyException((int)ErrorCode.CodeValErr, "课程不存在!");
            }
            //判断修习时长是否超过课程时长
            if (input.LearningTime > couser.LearnTime)
            {
                throw new UserFriendlyException((int)ErrorCode.CodeValErr, "修习时长不能超过课程总时长!");
            }
            //查询出上一条观看记录
            var model = await _repository.GetAll().Where(x => x.UserId == user.Id && x.CourseId == input.CourseId)
                        .OrderByDescending(x => x.LastModificationTime ?? x.CreationTime).FirstOrDefaultAsync();

            if (model == null)
            {
                //判断第一次修习时长是否大于1分钟
                if (input.LearningTime > 1)
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "初次记录修习时长不得高于1分钟!");
                }
                chkCreate = true;
            }
            else
            {
                //判断当前时间-上一条观看时间是否小于1分钟
                if (DateTime.Now - (model.LastModificationTime ?? model.CreationTime) < TimeSpan.FromSeconds(50))
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "请勿短时间内多次上传课时!");
                }
                //判断本次上传修习时长-上一条观看记录修习时长是否大于1分钟
                if (input.LearningTime - model.LearningTime > 1)
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "单次记录修习时长不得高于1分钟!");
                }
                //判断当前时间与上一条观看时间是否在同一天
                if (!DateTime.Now.Date.Equals(model.CreationTime.Date))
                {
                    chkCreate = true;
                }
            }
            if (chkCreate)
            {
                //创建新的修习记录
                model = new UserCourseRecordDetail()
                {
                    CourseId     = input.CourseId,
                    LearningTime = input.LearningTime,
                    UserId       = user.Id
                };
                await _repository.InsertAsync(model);
            }
            else
            {
                //更新修习时长
                model.LearningTime = input.LearningTime;
                await _repository.UpdateAsync(model);
            }
            var record = await _courseRecordRepository.GetAll()
                         .Where(x => !x.IsDeleted && x.CourseId == model.CourseId && x.UserId == model.UserId)
                         .FirstOrDefaultAsync();

            if (record != null)
            {
                //更新总时长
                record.LearnTime = model.LearningTime;
                //判断课程的修习状态进行完成操作
                if (record.IsComplete == null)
                {
                    var set = await _courseSettingAppService.Get();

                    //判断当前观看比率是否大于set的观看比率
                    if (Convert.ToDecimal(model.LearningTime) / Convert.ToDecimal(couser.LearnTime) * 100 >=
                        set.ViewingRatio)
                    {
                        //无计时或尚未超出规定学习时间
                        if (couser.ComplateTime == null || couser.ComplateTime > DateTime.Now)
                        {
                            //查询set并送出积分
                            var setScore = await _courseSettingAppService.GetSetVal(couser.LearnType, couser.IsSpecial);

                            if (setScore.ClassHourScore > 0)
                            {
                                await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                                {
                                    FromType = TrainScoreFromType.CourseLearn,
                                    FromId   = record.CourseId,
                                    Score    = setScore.ClassHourScore,
                                    UserId   = user.Id
                                });
                            }
                            //更新课程观看状态
                            record.IsComplete = true;
                        }
                        else
                        {
                            //有计时并且超时当时完成的需要恢复之前扣除的积分
                            //恢复积分
                            var oldscore =
                                await _trainScoreRecordRepository.FirstOrDefaultAsync(x => x.BusinessId == record.Id);

                            if (oldscore != null)
                            {
                                await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                                {
                                    FromId   = model.Id,
                                    FromType = TrainScoreFromType.CourseLearn,
                                    Score    = oldscore.Score,
                                    UserId   = user.Id
                                });
                            }
                        }
                    }
                }
                await _courseRecordRepository.UpdateAsync(record);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 修改一个UserCourseExperience
        /// </summary>
        /// <param name="input">实体</param>
        /// <returns></returns>
        public async Task Update(UpdateUserCourseExperienceInput input)
        {
            if (input.InStanceId != Guid.Empty)
            {
                var dbmodel = await _repository.FirstOrDefaultAsync(x => x.Id == input.InStanceId);

                if (dbmodel == null)
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "该数据不存在!");
                }
                var logModel = new UserCourseExperience();
                if (input.IsUpdateForChange)
                {
                    logModel = dbmodel.DeepClone <UserCourseExperience>();
                }
                var dbexp = string.IsNullOrEmpty(dbmodel.ExperienceId)
                    ? new List <string>()
                    : dbmodel.ExperienceId.Split(',').ToList();
                if (string.IsNullOrEmpty(input.ExperienceId))
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "请至少选择一条心得体会汇总!");
                }
                var inputexp = input.ExperienceId.Split(',').ToList();
                var newexp   = inputexp.Except(dbexp).ToList();
                dbexp.AddRange(newexp);
                dbmodel.ExperienceId = string.Join(",", dbexp);
                await _repository.UpdateAsync(dbmodel);

                if (input.IsUpdateForChange)
                {
                    var flowModel = _workFlowCacheManager.GetWorkFlowModelFromCache(input.FlowId);
                    if (flowModel == null)
                    {
                        throw new UserFriendlyException((int)ErrorCode.CodeValErr, "流程不存在");
                    }
                    var logs = GetChangeModel(logModel).GetColumnAllLogs(GetChangeModel(dbmodel));
                    await _projectAuditManager.InsertAsync(logs, input.InStanceId.ToString(),
                                                           flowModel.TitleField.Table);
                }
                //采纳心得体会加积分
                var course = _courseRepository.Get(dbmodel.CourseId);
                var set    = await _courseSettingAppService.GetSetVal(course.LearnType, course.IsSpecial);

                newexp.ForEach(async x =>
                {
                    var exp   = _experienceRepository.Get(Guid.Parse(x));
                    exp.IsUse = true;
                    _experienceRepository.Update(exp);
                    if (set.ExperienceScore > 0)
                    {
                        await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                        {
                            FromId   = dbmodel.CourseId,
                            FromType = TrainScoreFromType.CourseExperience,
                            Score    = set.ExperienceScore,
                            UserId   = exp.CreatorUserId ?? 0
                        });
                    }
                });
            }
            else
            {
                throw new UserFriendlyException((int)ErrorCode.CodeValErr, "该数据不存在!");
            }
        }