| | |
| | | package com.tcm.training.admin.app.course.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.tcm.training.admin.app.course.vo.AppHealthCourseCategoryOptionVO; |
| | | import com.tcm.training.admin.app.course.vo.AppHealthCourseDetailVO; |
| | | import com.tcm.training.admin.app.course.vo.AppHealthCourseExpertVO; |
| | | import com.tcm.training.admin.app.course.vo.AppHealthCourseListItemVO; |
| | | import com.tcm.training.admin.app.course.vo.AppHealthCourseVideoVO; |
| | | import com.tcm.training.admin.live.entity.Expert; |
| | | import com.tcm.training.admin.live.entity.HealthCourseVideo; |
| | | import com.tcm.training.admin.live.entity.LiveCourseCategory; |
| | | import com.tcm.training.admin.live.mapper.ExpertMapper; |
| | | import com.tcm.training.admin.live.mapper.HealthCourseMapper; |
| | | import com.tcm.training.admin.live.mapper.HealthCourseVideoMapper; |
| | | import com.tcm.training.admin.live.mapper.LiveCourseCategoryMapper; |
| | | import com.tcm.training.admin.live.service.HealthCourseAppService; |
| | | import com.tcm.training.admin.live.service.LiveCourseCategoryAppService; |
| | | import com.tcm.training.admin.live.vo.HealthCourseDetailVO; |
| | | import com.tcm.training.admin.live.vo.HealthCourseListRow; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | |
| | | private static final int VIDEO_STATUS_ENABLED = 1; |
| | | |
| | | private final HealthCourseAppService healthCourseAppService; |
| | | private final HealthCourseMapper healthCourseMapper; |
| | | private final HealthCourseVideoMapper healthCourseVideoMapper; |
| | | private final LiveCourseCategoryMapper liveCourseCategoryMapper; |
| | | private final ExpertMapper expertMapper; |
| | | |
| | | /** |
| | | * 注入 APP 养生课程详情所需依赖。 |
| | | */ |
| | | public AppHealthCourseService(HealthCourseAppService healthCourseAppService, |
| | | HealthCourseMapper healthCourseMapper, |
| | | HealthCourseVideoMapper healthCourseVideoMapper, |
| | | LiveCourseCategoryMapper liveCourseCategoryMapper, |
| | | ExpertMapper expertMapper) { |
| | | this.healthCourseAppService = healthCourseAppService; |
| | | this.healthCourseMapper = healthCourseMapper; |
| | | this.healthCourseVideoMapper = healthCourseVideoMapper; |
| | | this.liveCourseCategoryMapper = liveCourseCategoryMapper; |
| | | this.expertMapper = expertMapper; |
| | | } |
| | | |
| | | /** |
| | | * 获取 APP 养生课程列表页数据。 |
| | | */ |
| | | public List<AppHealthCourseListItemVO> list(Long levelCategoryId, Long difficultyCategoryId) { |
| | | List<HealthCourseListRow> rows = healthCourseMapper.selectCourseList( |
| | | null, |
| | | levelCategoryId, |
| | | difficultyCategoryId, |
| | | COURSE_STATUS_ENABLED |
| | | ); |
| | | if (rows == null || rows.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | List<AppHealthCourseListItemVO> result = new ArrayList<AppHealthCourseListItemVO>(rows.size()); |
| | | for (HealthCourseListRow row : rows) { |
| | | AppHealthCourseListItemVO itemVO = new AppHealthCourseListItemVO(); |
| | | itemVO.setId(row.getId()); |
| | | itemVO.setTitle(trimToEmpty(row.getTitle())); |
| | | itemVO.setCoverImage(trimToEmpty(row.getCoverImg())); |
| | | itemVO.setLevelName(trimToEmpty(row.getLevelName())); |
| | | itemVO.setDifficultyName(trimToEmpty(row.getDifficultyName())); |
| | | itemVO.setSalePrice(defaultPrice(row.getSalePrice())); |
| | | itemVO.setLearnUserCount(defaultNumber(row.getLearnUserCount())); |
| | | result.add(itemVO); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取 APP 养生课程主题筛选项。 |
| | | */ |
| | | public List<AppHealthCourseCategoryOptionVO> listThemes() { |
| | | return listCategoriesByType(LiveCourseCategoryAppService.TYPE_LEVEL); |
| | | } |
| | | |
| | | /** |
| | | * 获取 APP 养生课程难度筛选项。 |
| | | */ |
| | | public List<AppHealthCourseCategoryOptionVO> listDifficulties() { |
| | | return listCategoriesByType(LiveCourseCategoryAppService.TYPE_DIFFICULTY); |
| | | } |
| | | |
| | | /** |
| | | * 按分类类型读取 APP 养生课程筛选项。 |
| | | */ |
| | | private List<AppHealthCourseCategoryOptionVO> listCategoriesByType(String categoryType) { |
| | | List<LiveCourseCategory> categories = liveCourseCategoryMapper.selectList(new LambdaQueryWrapper<LiveCourseCategory>() |
| | | .eq(LiveCourseCategory::getType, categoryType) |
| | | .eq(LiveCourseCategory::getDeleted, 0) |
| | | .orderByAsc(LiveCourseCategory::getSort) |
| | | .orderByAsc(LiveCourseCategory::getId)); |
| | | if (categories == null || categories.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | List<AppHealthCourseCategoryOptionVO> result = |
| | | new ArrayList<AppHealthCourseCategoryOptionVO>(categories.size()); |
| | | for (LiveCourseCategory category : categories) { |
| | | AppHealthCourseCategoryOptionVO optionVO = new AppHealthCourseCategoryOptionVO(); |
| | | optionVO.setId(category.getId()); |
| | | optionVO.setName(trimToEmpty(category.getName())); |
| | | result.add(optionVO); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 查询课程下启用的视频章节。 |
| | | */ |
| | | private List<HealthCourseVideo> listEnabledVideos(Long courseId) { |