コード例 #1
0
        /// <summary>
        /// 根据条件分页获取列表
        /// </summary>
        /// <param name="page">查询实体</param>
        /// <param name="type"></param>
        /// <returns></returns>
        public async Task <PagedResultDto <UserCourseRecordListOutputDto> > GetList(GetUserCourseRecordListInput input)
        {
            var userId    = (await base.GetCurrentUserAsync()).Id;
            var query     = GetQueryFromList(userId, input);
            var toalCount = await query.CountAsync();

            var ret = await query.OrderByDescending(r => r.CreationTime).PageBy(input).ToListAsync();

            var courseSet = await _courseSettingAppService.Get();

            ret.ForEach(x =>
            {
                x.FaceUrl = _abpFileRelationAppService.GetList(new GetAbpFilesInput()
                {
                    BusinessId   = x.CourseId.ToString(),
                    BusinessType = (int)AbpFileBusinessType.培训课程封面
                }).FirstOrDefault()?.Id.ToString();
                if (x.CourseFileType == CourseFileType.Doc || x.CourseFileType == CourseFileType.Pdf)
                {
                    x.CourseLink = _abpFileRelationAppService.GetList(new GetAbpFilesInput()
                    {
                        BusinessId   = x.CourseId.ToString(),
                        BusinessType = (int)AbpFileBusinessType.培训课程文件
                    }).FirstOrDefault()?.Id.ToString();
                }
                x.LearnScore   = courseSet.GetSetVal(x.LearnType, x.IsSpecial).ClassHourScore;
                x.ViewingRatio = Math.Round(Convert.ToDecimal(x.MyLearnTime) / Convert.ToDecimal(x.LearnTime) * 100, 2);
            });
            return(new PagedResultDto <UserCourseRecordListOutputDto>(toalCount, ret));
        }
コード例 #2
0
        /// <summary>
        /// 组装我的课程查询语句
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        IQueryable <UserCourseRecordListOutputDto> GetQueryFromList(long userId, GetUserCourseRecordListInput input)
        {
            var userIdStr = "u_" + userId.ToString();

            switch (input.type)
            {
            case MyCourseListType.RequiredCourse:    //我的必修课程
                return
                    ((from a in _courseRepository.GetAll().Where(x =>
                                                                 !x.IsDeleted && (x.LearnType == CourseLearnType.MustAll ||
                                                                                  (x.LearnType == CourseLearnType.Must &&
                                                                                   x.LearnUser.GetStrContainsArray(userIdStr))) && x.Status == -1 && !x.IsDelCourse)
                      join b1 in _repository.GetAll()
                      .Where(x => !x.IsDeleted && x.UserId == userId)
                      .DefaultIfEmpty() on a.Id equals b1.CourseId into tmp1
                      from b in tmp1.DefaultIfEmpty()
                      let myLearnTime = _courseRecordDetailRepository.GetAll()
                                        .Where(x => !x.IsDeleted && x.UserId == userId && x.CourseId == a.Id)
                                        .OrderByDescending(x => (x.LastModificationTime ?? x.CreationTime))
                                        .Select(x => x.LearningTime).FirstOrDefault()
                                        select new UserCourseRecordListOutputDto()
                {
                    CourseId = a.Id,
                    CourseName = a.CourseName,
                    CourseIntroduction = a.CourseIntroduction,
                    LearnTime = a.LearnTime,
                    MyLearnTime = myLearnTime,
                    IsComplate = b != null && (b.IsComplete != null && b.IsComplete != false),
                    LearnType = a.LearnType,
                    IsSpecial = a.IsSpecial,
                    CourseFileType = a.CourseFileType,
                    CourseLink = a.CourseLink,
                    CreationTime = a.CreationTime,
                    ComplateTime = a.ComplateTime
                }).Where(x => x.IsComplate == false));

            case MyCourseListType.ElectiveCourse:    //我的选修课程
                return((from a in _courseRepository.GetAll().Where(x =>
                                                                   !x.IsDeleted && x.LearnType == CourseLearnType.Selected && x.Status == -1 && !x.IsDelCourse &&
                                                                   (input.CourseType == null || x.CourseType == input.CourseType) &&
                                                                   (input.CourseName == null || x.CourseName.Contains(input.CourseName))
                                                                   )
                        join b1 in _repository.GetAll()
                        .Where(x => !x.IsDeleted && x.UserId == userId)
                        .DefaultIfEmpty() on a.Id equals b1.CourseId into tmp1
                        from b in tmp1.DefaultIfEmpty()
                        let myLearnTime = _courseRecordDetailRepository.GetAll()
                                          .Where(x => !x.IsDeleted && x.UserId == userId && x.CourseId == a.Id)
                                          .OrderByDescending(x => (x.LastModificationTime ?? x.CreationTime))
                                          .Select(x => x.LearningTime).FirstOrDefault()
                                          select new UserCourseRecordListOutputDto()
                {
                    CourseId = a.Id,
                    CourseName = a.CourseName,
                    CourseIntroduction = a.CourseIntroduction,
                    LearnTime = a.LearnTime,
                    MyLearnTime = myLearnTime,
                    IsComplate = b != null && (b.IsComplete != null && b.IsComplete != false),
                    LearnType = a.LearnType,
                    IsSpecial = a.IsSpecial,
                    CourseFileType = a.CourseFileType,
                    CourseLink = a.CourseLink,
                    CreationTime = a.CreationTime
                }).Where(x => x.IsComplate == false));

            case MyCourseListType.ComplateCourse:    //我的已完成课程
                return(from a in _courseRepository.GetAll().Where(x =>
                                                                  !x.IsDeleted && (x.LearnType != CourseLearnType.Must ||
                                                                                   (x.LearnType == CourseLearnType.Must &&
                                                                                    x.LearnUser.GetStrContainsArray(userIdStr))) && x.Status == -1 && !x.IsDelCourse)
                       join b in _repository.GetAll()
                       .Where(x => !x.IsDeleted && x.UserId == userId && x.IsComplete == true) on a.Id equals b
                       .CourseId
                       let myLearnTime = _courseRecordDetailRepository.GetAll()
                                         .Where(x => !x.IsDeleted && x.UserId == userId && x.CourseId == a.Id)
                                         .OrderByDescending(x => (x.LastModificationTime ?? x.CreationTime))
                                         .Select(x => x.LearningTime).FirstOrDefault()
                                         select new UserCourseRecordListOutputDto()
                {
                    CourseId = a.Id,
                    CourseName = a.CourseName,
                    CourseIntroduction = a.CourseIntroduction,
                    LearnTime = a.LearnTime,
                    MyLearnTime = myLearnTime,
                    IsComplate = true,
                    LearnType = a.LearnType,
                    IsSpecial = a.IsSpecial,
                    CourseFileType = a.CourseFileType,
                    CourseLink = a.CourseLink,
                    CreationTime = b.CreationTime
                });
            }
            return(null);
        }