查询 集数 重写

This commit is contained in:
2025-01-06 09:52:55 +08:00
parent 5828199ba0
commit ec789a8df1
6 changed files with 71 additions and 101 deletions

View File

@@ -48,18 +48,10 @@ public class AppCourseController extends AbstractController {
@Login
@GetMapping("/courseSets")
@ApiOperation("根据id查询短剧集数列表")
public Result courseSets(@RequestAttribute("userId") Long userId, Long courseId) {
return courseDetailsService.courseSets(userId, courseId);
public Result courseSets(@RequestAttribute("userId") Long userId, Long courseId, Integer sort) {
return courseDetailsService.courseSets(userId, courseId,sort);
}
@Login
@GetMapping("/courseDetails")
@ApiOperation("查询短剧 内容")
public Result courseDetails(@RequestAttribute("userId") Long userId, Long courseId, Integer sort) {
return courseDetailsService.courseDetails(userId, courseId, sort);
}
@Login
@GetMapping("/selectCourseDetailsById")
@ApiOperation("根据id查询短剧详情")

View File

@@ -23,10 +23,7 @@ public interface CourseDetailsDao extends BaseMapper<CourseDetails> {
* @param wholesalePrice 10集价格
*/
@Cacheable(cacheNames = "courseSets" ,key = "#courseId")
List<CourseDetailsSetVo> courseSets(@Param("courseId") Long courseId, Integer isPrice, BigDecimal price, BigDecimal wholesalePrice);
List<CourseDetailsVo> courseDetails(@Param("courseId") Long courseId, @Param("collect") Long collect,
@Param("starSort") Integer starSort, @Param("endSort") Integer endSort);
List<CourseDetailsSetVo> courseSets(@Param("courseId") Long courseId, @Param("collect") Long collect, Integer isPrice, BigDecimal price, BigDecimal wholesalePrice);
List<CourseDetails> findByCourseId(@Param("id") Long id, @Param("userId") Long userId);

View File

@@ -20,9 +20,8 @@ public interface CourseDetailsService extends IService<CourseDetails> {
* @param courseId
* @return
*/
Result courseSets(Long userId, Long courseId);
Result courseSets(Long userId, Long courseId, Integer sort);
Result courseDetails(Long userId, Long courseId, Integer sort);
Result selectCourseDetailsById(Long id,String token,String courseDetailsId);

View File

@@ -154,104 +154,76 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
}
@Override
public Result courseSets(Long userId, Long courseId) {
CourseCollect courseCollect = courseCollectDao.selectOne(new QueryWrapper<CourseCollect>().eq("course_id", courseId)
.eq("user_id", userId).eq("classify", 3).last("limit 1"));
public Result courseSets(Long userId, Long courseId, Integer sort) {
//观看记录
CourseCollect courseCollect = courseCollectDao.selectOne(new QueryWrapper<CourseCollect>()
.eq("course_id", courseId).eq("user_id", userId)
.eq("classify", 3).last("limit 1"));
//是否追剧
Integer collect = courseCollectDao.selectCount(new QueryWrapper<CourseCollect>()
.eq("user_id", userId).eq("course_id", courseId)
.eq("classify", 1).last("limit 1"));
Course bean = courseDao.selectById(courseId);
//查询用户是否购买了整集
CourseUser courseUser = courseUserDao.selectCourseUser(courseId, userId);
// 每天购买超过上限,获得免费时间段资格
boolean freeWatch = checkFreeWatchPayCount(userId);
List<CourseDetailsSetVo> courseDetailsSetVos;
if (freeWatch || courseUser != null) {
courseDetailsSetVos = baseMapper.courseSets(courseId, 2, null, null);
} else {
// courseDetailsSetVos = baseMapper.courseSets(courseId, 1, bean.getPrice(), bean.getWholesalePrice());
courseDetailsSetVos = baseMapper.courseSets(courseId, 2, bean.getPrice(), bean.getWholesalePrice());
//查询用户是否单独购买了集
Set<Long> detailsId = courseUserDao.selectUserCourseDetailsId(courseId, userId);
if (courseCollect != null) {
for (CourseDetailsSetVo s : courseDetailsSetVos) {
if (s.getCourseDetailsId().equals(courseCollect.getCourseDetailsId())) {
s.setCurrent(1);
break;
}
}
} else {
courseDetailsSetVos.get(0).setCurrent(1);
}
if (CollectionUtil.isNotEmpty(detailsId)) {
courseDetailsSetVos = courseDetailsSetVos.stream()
.peek(s -> {
if (detailsId.contains(s.getCourseDetailsId())) {
s.setIsPrice(2);
}
})
.collect(Collectors.toList());
}
}
Map<String, Object> map = new HashMap<>();
map.put("title", bean.getTitle());
map.put("list", courseDetailsSetVos);
return new Result().put("data", map);
}
@Override
public Result courseDetails(Long userId, Long courseId, Integer sort) {
Course bean = courseDao.selectById(courseId);
Integer detailCount = baseMapper.countCourseByCourseId(courseId);
if (detailCount == null || detailCount.equals(0)) {
return Result.error("暂无可看剧集,请观看其它影片。");
}
int startSort = 0;
int endSort = 5;
if (sort == null) {
CourseCollect courseCollect = courseCollectDao.selectOne(new QueryWrapper<CourseCollect>().eq("course_id", courseId)
.eq("user_id", userId).eq("classify", 3).last("limit 1"));
if (courseCollect != null) {
CourseDetails courseDetails = baseMapper.selectOne(new QueryWrapper<CourseDetails>()
.eq("course_details_id", courseCollect.getCourseDetailsId()).eq("course_id", courseCollect.getCourseId()).last("limit 1"));
sort = courseDetails.getSort();
}
}
List<CourseDetailsSetVo> courseDetailsSetVos;
if (freeWatch || courseUser != null) {
courseDetailsSetVos = baseMapper.courseSets(courseId, collect == null ? 0L : 1L, 2, null, null);
} else {
courseDetailsSetVos = baseMapper.courseSets(courseId, collect == null ? 0L : 1L, 1, bean.getPrice(), bean.getWholesalePrice());
}
if (sort != null && sort > 2) {
startSort = sort - 3;
endSort = sort + 3;
if (detailCount < endSort) {
startSort = detailCount - 5;
endSort = detailCount + 1;
if (courseDetailsSetVos.size() < endSort) {
startSort = courseDetailsSetVos.size() - 5;
endSort = courseDetailsSetVos.size() + 1;
}
}
//查询用户是否购买了整
CourseUser courseUser = courseUserDao.selectCourseUser(courseId, userId);
boolean freeWatch = true;
if (courseUser == null) {
// 每天购买超过上限,获得免费时间段资格
freeWatch = checkFreeWatchPayCount(userId);
}
Integer collect = courseCollectDao.selectCount(new QueryWrapper<CourseCollect>()
.eq("user_id", userId).eq("course_id", courseId)
.eq("classify", 1).last("limit 1"));
//已购买剧
Set<Long> detailsId = new HashSet<>();
//全剧免费
if ((!freeWatch)) {
detailsId = courseUserDao.selectUserCourseDetailsId(courseId, userId);
}
List<CourseDetailsVo> courseDetailsVos = baseMapper.courseDetails(courseId, collect == null ? 0L : 1L, startSort, endSort);
Set<Long> finalDetailsId = detailsId;
courseDetailsVos.stream().forEach(s -> {
int finalStartSort = startSort;
int finalEndSort = endSort;
courseDetailsSetVos.parallelStream().forEach(s -> {
//当前
if (courseCollect != null && s.getCourseDetailsId().equals(courseCollect.getCourseDetailsId())) {
s.setCurrent(1);
}
// 不免费 3集以后 (已买的不为空 并不在已买的包含)
// if (!freeWatch && s.getSort() > 3 && (CollectionUtil.isEmpty(finalDetailsId) || !finalDetailsId.contains(s.getCourseDetailsId()))) {
// s.setVideoUrl(null);
// }
CourseCollect isGood = courseCollectDao.selectOne(new QueryWrapper<CourseCollect>()
.eq("user_id", userId).eq("course_details_id", s.getCourseDetailsId()).eq("classify", 2).last("limit 1"));
s.setIsGood(isGood == null ? 0 : 1);
if (!freeWatch && s.getSort() > 3 && (CollectionUtil.isEmpty(finalDetailsId) || !finalDetailsId.contains(s.getCourseDetailsId()))) {
s.setVideoUrl(null);
}
if (s.getSort() > finalStartSort && s.getSort() < finalEndSort) {
CourseCollect isGood = courseCollectDao.selectOne(new QueryWrapper<CourseCollect>()
.eq("user_id", userId).eq("course_details_id", s.getCourseDetailsId()).eq("classify", 2).last("limit 1"));
s.setIsGood(isGood == null ? 0 : 1);
}
});
if (courseCollect == null) {
courseDetailsSetVos.get(0).setCurrent(1);
}
ThreadUtil.execAsync(() -> {
setCourseView(bean);
});
return new Result().put("data", courseDetailsVos);
Map<String, Object> map = new HashMap<>();
map.put("title", bean.getTitle());
map.put("list", courseDetailsSetVos);
return new Result().put("data", map);
}
@Override

View File

@@ -15,4 +15,25 @@ public class CourseDetailsSetVo {
private BigDecimal wholesalePrice;
private BigDecimal countPrice;
private Integer sort;
/**
* 封面图
*/
private String titleImg;
/**
* 视频地址
*/
private String videoUrl;
/**
* 点赞数
*/
private Integer goodNum;
/**
* 是否已追
*/
private Long isCollect;
/**
* 是否点赞
*/
private Integer isGood;
}

View File

@@ -6,32 +6,21 @@
select c.course_id as courseId
, c.course_details_id as courseDetailsId
, c.course_details_name as courseDetailsName
, c.video_url as videoUrl
, c.price as countPrice
, c.sort as sort
, ifnull(#{price}, 0) as price
, ifnull(#{wholesalePrice}, 0) as wholesalePrice
, IF(#{isPrice} = 1, c.is_price, 2) AS isPrice
, c.title_img as titleImg
, c.good_num as goodNum
, c.sort as sort
, IF(#{collect} = 1, 1, 0) AS isCollect
from course_details c
where c.course_id = #{courseId}
order by c.sort asc
</select>
<select id="courseDetails" resultType="com.sqx.modules.course.vo.CourseDetailsVo">
select c.course_id as courseId
, c.course_details_id as courseDetailsId
, c.course_details_name as courseDetailsName
, c.title_img as titleImg
, c.video_url as videoUrl
, c.good_num as goodNum
, c.sort as sort
, IF(#{collect} = 1, 1, 0) AS isCollect
from course_details c
where c.course_id = #{courseId}
and sort &gt; #{starSort}
and sort &lt; #{endSort}
order by c.sort asc
</select>
<!--查找指定短剧的目录 按照顺序数字升序-->
<select id="findByCourseId" resultType="com.sqx.modules.course.entity.CourseDetails">
select