请求剧集 Io异常问题
This commit is contained in:
parent
0eaa579b98
commit
36157f1085
|
|
@ -154,85 +154,91 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result courseSets(Long userId, Long courseId, Integer sort) {
|
public Result courseSets(Long userId, Long courseId, Integer sort) {
|
||||||
//观看记录
|
try{
|
||||||
CourseCollect courseCollect = courseCollectDao.selectOne(new QueryWrapper<CourseCollect>()
|
//观看记录
|
||||||
.eq("course_id", courseId).eq("user_id", userId)
|
CourseCollect courseCollect = courseCollectDao.selectOne(new QueryWrapper<CourseCollect>()
|
||||||
.eq("classify", 3).last("limit 1"));
|
.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)
|
Integer collect = courseCollectDao.selectCount(new QueryWrapper<CourseCollect>()
|
||||||
.eq("classify", 1).last("limit 1"));
|
.eq("user_id", userId).eq("course_id", courseId)
|
||||||
Course bean = courseDao.selectById(courseId);
|
.eq("classify", 1).last("limit 1"));
|
||||||
if(bean==null){
|
Course bean = courseDao.selectById(courseId);
|
||||||
log.error("未找到该剧集 用户id:{} 剧集:{}",userId,courseId);
|
if(bean==null){
|
||||||
return Result.error("未找到该剧集");
|
log.error("未找到该剧集 用户id:{} 剧集:{}",userId,courseId);
|
||||||
}
|
return Result.error("未找到该剧集");
|
||||||
//查询用户是否购买了整集
|
|
||||||
CourseUser courseUser = courseUserDao.selectCourseUser(courseId, userId);
|
|
||||||
// 每天购买超过上限,获得免费时间段资格
|
|
||||||
boolean freeWatch = checkFreeWatchPayCount(userId);
|
|
||||||
int startSort = 0;
|
|
||||||
int endSort = 5;
|
|
||||||
if (sort == null) {
|
|
||||||
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;
|
CourseUser courseUser = courseUserDao.selectCourseUser(courseId, userId);
|
||||||
if (freeWatch || courseUser != null) {
|
// 每天购买超过上限,获得免费时间段资格
|
||||||
courseDetailsSetVos = baseMapper.courseSets(courseId, 2, null);
|
boolean freeWatch = checkFreeWatchPayCount(userId);
|
||||||
} else {
|
int startSort = 0;
|
||||||
courseDetailsSetVos = baseMapper.courseSets(courseId, 1, bean.getWholesalePrice());
|
int endSort = 5;
|
||||||
}
|
if (sort == null) {
|
||||||
if (sort != null && sort > 2) {
|
if (courseCollect != null) {
|
||||||
startSort = sort - 3;
|
CourseDetails courseDetails = baseMapper.selectOne(new QueryWrapper<CourseDetails>()
|
||||||
endSort = sort + 3;
|
.eq("course_details_id", courseCollect.getCourseDetailsId()).eq("course_id", courseCollect.getCourseId()).last("limit 1"));
|
||||||
if (courseDetailsSetVos.size() < endSort) {
|
sort = courseDetails.getSort();
|
||||||
startSort = courseDetailsSetVos.size() - 5;
|
}
|
||||||
endSort = courseDetailsSetVos.size() + 1;
|
|
||||||
}
|
}
|
||||||
}
|
List<CourseDetailsSetVo> courseDetailsSetVos;
|
||||||
//已购买剧集
|
if (freeWatch || courseUser != null) {
|
||||||
Set<Long> detailsId = new HashSet<>();
|
courseDetailsSetVos = baseMapper.courseSets(courseId, 2, null);
|
||||||
if ((!freeWatch)) {
|
} else {
|
||||||
detailsId = courseUserDao.selectUserCourseDetailsId(courseId, userId);
|
courseDetailsSetVos = baseMapper.courseSets(courseId, 1, bean.getWholesalePrice());
|
||||||
}
|
|
||||||
AtomicReference<CourseDetailsSetVo> current = new AtomicReference<>(new CourseDetailsSetVo());
|
|
||||||
Set<Long> finalDetailsId = detailsId;
|
|
||||||
int finalStartSort = startSort;
|
|
||||||
int finalEndSort = endSort;
|
|
||||||
courseDetailsSetVos.parallelStream().forEach(s -> {
|
|
||||||
//当前
|
|
||||||
if (courseCollect != null && s.getCourseDetailsId().equals(courseCollect.getCourseDetailsId())) {
|
|
||||||
s.setCurrent(1);
|
|
||||||
current.set(s);
|
|
||||||
}
|
}
|
||||||
// 不免费 3集以后 (已买的不为空 并不在已买的包含)
|
if (sort != null && sort > 2) {
|
||||||
if (!freeWatch && s.getSort() > 3 && (CollectionUtil.isEmpty(finalDetailsId) || !finalDetailsId.contains(s.getCourseDetailsId()))) {
|
startSort = sort - 3;
|
||||||
s.setVideoUrl(null);
|
endSort = sort + 3;
|
||||||
|
if (courseDetailsSetVos.size() < endSort) {
|
||||||
|
startSort = courseDetailsSetVos.size() - 5;
|
||||||
|
endSort = courseDetailsSetVos.size() + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (s.getSort() > finalStartSort && s.getSort() < finalEndSort) {
|
//已购买剧集
|
||||||
CourseCollect isGood = courseCollectDao.selectOne(new QueryWrapper<CourseCollect>()
|
Set<Long> detailsId = new HashSet<>();
|
||||||
.eq("user_id", userId).eq("course_details_id", s.getCourseDetailsId()).eq("classify", 2).last("limit 1"));
|
if ((!freeWatch)) {
|
||||||
s.setIsGood(isGood == null ? 0 : 1);
|
detailsId = courseUserDao.selectUserCourseDetailsId(courseId, userId);
|
||||||
}
|
}
|
||||||
});
|
AtomicReference<CourseDetailsSetVo> current = new AtomicReference<>(new CourseDetailsSetVo());
|
||||||
if (courseCollect == null) {
|
Set<Long> finalDetailsId = detailsId;
|
||||||
courseDetailsSetVos.get(0).setCurrent(1);
|
int finalStartSort = startSort;
|
||||||
current.set(courseDetailsSetVos.get(0));
|
int finalEndSort = endSort;
|
||||||
|
courseDetailsSetVos.parallelStream().forEach(s -> {
|
||||||
|
//当前
|
||||||
|
if (courseCollect != null && s.getCourseDetailsId().equals(courseCollect.getCourseDetailsId())) {
|
||||||
|
s.setCurrent(1);
|
||||||
|
current.set(s);
|
||||||
|
}
|
||||||
|
// 不免费 3集以后 (已买的不为空 并不在已买的包含)
|
||||||
|
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);
|
||||||
|
current.set(courseDetailsSetVos.get(0));
|
||||||
|
}
|
||||||
|
ThreadUtil.execAsync(() -> {
|
||||||
|
setCourseView(bean);
|
||||||
|
});
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("current", current.get());
|
||||||
|
map.put("price", freeWatch ? 0 : bean.getPrice());
|
||||||
|
map.put("title", bean.getTitle());
|
||||||
|
map.put("collect", collect == null || collect.equals(0) ? 0L : 1L);
|
||||||
|
map.put("list", courseDetailsSetVos);
|
||||||
|
return new Result().put("data", map);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("请求剧集异常打印:");
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.error("请求剧集失败");
|
||||||
}
|
}
|
||||||
ThreadUtil.execAsync(() -> {
|
|
||||||
setCourseView(bean);
|
|
||||||
});
|
|
||||||
Map<String, Object> map = new HashMap<>();
|
|
||||||
map.put("current", current.get());
|
|
||||||
map.put("price", freeWatch ? 0 : bean.getPrice());
|
|
||||||
map.put("title", bean.getTitle());
|
|
||||||
map.put("collect", collect == null || collect.equals(0) ? 0L : 1L);
|
|
||||||
map.put("list", courseDetailsSetVos);
|
|
||||||
return new Result().put("data", map);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue