Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
a0300d134f
|
|
@ -67,6 +67,7 @@ public class SqxExceptionHandler {
|
|||
public Result handleException(Exception e, WebRequest webRequest) {
|
||||
logErrorInfo(webRequest);
|
||||
logger.error(e.getMessage(), e);
|
||||
e.printStackTrace();
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.sqx.modules.app.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -17,12 +19,14 @@ public class UserInfo implements Serializable {
|
|||
*
|
||||
*/
|
||||
@TableId(type = IdType.ID_WORKER)
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@TableField(updateStrategy = FieldStrategy.NEVER)
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -165,15 +165,15 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
|
|||
List<CourseDetails> courseDetails1 = courseIdList.isEmpty() ? new ArrayList<>() :
|
||||
courseDetailsService.list(new LambdaQueryWrapper<CourseDetails>().in(CourseDetails::getCourseDetailsId, courseDetailIds));
|
||||
Map<Long, CourseDetails> courseDetailsMap = courseDetails1.stream().collect(Collectors.toMap(CourseDetails::getCourseId, item -> item));
|
||||
List<CourseDetails> courseDetails2 = courseIdList.isEmpty() ? new ArrayList<>() : courseDetailsDao.countByCourseId(courseIdList);
|
||||
Map<Long, Integer> countMap = courseDetails2.stream()
|
||||
.collect(Collectors.toMap(CourseDetails::getCourseId, CourseDetails::getCourseDetailsCount));
|
||||
// List<CourseDetails> courseDetails2 = courseIdList.isEmpty() ? new ArrayList<>() : courseDetailsDao.countByCourseId(courseIdList);
|
||||
// Map<Long, Integer> countMap = courseDetails2.stream()
|
||||
// .collect(Collectors.toMap(CourseDetails::getCourseId, CourseDetails::getCourseDetailsCount));
|
||||
|
||||
if (CollectionUtil.isNotEmpty(courseList)) {
|
||||
for (Course course : courseList) {
|
||||
// course.setCourseClassification(courseClassificationDao.selectById(course.getClassifyId()));
|
||||
CourseDetails courseDetails = courseDetailsMap.getOrDefault(course.getCourseId(), null);
|
||||
course.setCourseDetailsCount(countMap.getOrDefault(course.getCourseId(), 0));
|
||||
course.setCourseDetailsCount(courseDetailsDao.countCourseByCourseId(course.getCourseId()));
|
||||
if (courseDetails != null) {
|
||||
course.setCourseDetailsName(courseDetails.getCourseDetailsName());
|
||||
course.setCourseDetailsId(courseDetails.getCourseDetailsId());
|
||||
|
|
|
|||
|
|
@ -154,85 +154,91 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
|||
|
||||
@Override
|
||||
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);
|
||||
if(bean==null){
|
||||
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();
|
||||
try{
|
||||
//观看记录
|
||||
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);
|
||||
if(bean==null){
|
||||
log.error("未找到该剧集 用户id:{} 剧集:{}",userId,courseId);
|
||||
return Result.error("未找到该剧集");
|
||||
}
|
||||
}
|
||||
List<CourseDetailsSetVo> courseDetailsSetVos;
|
||||
if (freeWatch || courseUser != null) {
|
||||
courseDetailsSetVos = baseMapper.courseSets(courseId, 2, null);
|
||||
} else {
|
||||
courseDetailsSetVos = baseMapper.courseSets(courseId, 1, bean.getWholesalePrice());
|
||||
}
|
||||
if (sort != null && sort > 2) {
|
||||
startSort = sort - 3;
|
||||
endSort = sort + 3;
|
||||
if (courseDetailsSetVos.size() < endSort) {
|
||||
startSort = courseDetailsSetVos.size() - 5;
|
||||
endSort = courseDetailsSetVos.size() + 1;
|
||||
//查询用户是否购买了整集
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
//已购买剧集
|
||||
Set<Long> detailsId = new HashSet<>();
|
||||
if ((!freeWatch)) {
|
||||
detailsId = courseUserDao.selectUserCourseDetailsId(courseId, userId);
|
||||
}
|
||||
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);
|
||||
List<CourseDetailsSetVo> courseDetailsSetVos;
|
||||
if (freeWatch || courseUser != null) {
|
||||
courseDetailsSetVos = baseMapper.courseSets(courseId, 2, null);
|
||||
} else {
|
||||
courseDetailsSetVos = baseMapper.courseSets(courseId, 1, bean.getWholesalePrice());
|
||||
}
|
||||
// 不免费 3集以后 (已买的不为空 并不在已买的包含)
|
||||
if (!freeWatch && s.getSort() > 3 && (CollectionUtil.isEmpty(finalDetailsId) || !finalDetailsId.contains(s.getCourseDetailsId()))) {
|
||||
s.setVideoUrl(null);
|
||||
if (sort != null && sort > 2) {
|
||||
startSort = sort - 3;
|
||||
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>()
|
||||
.eq("user_id", userId).eq("course_details_id", s.getCourseDetailsId()).eq("classify", 2).last("limit 1"));
|
||||
s.setIsGood(isGood == null ? 0 : 1);
|
||||
//已购买剧集
|
||||
Set<Long> detailsId = new HashSet<>();
|
||||
if ((!freeWatch)) {
|
||||
detailsId = courseUserDao.selectUserCourseDetailsId(courseId, userId);
|
||||
}
|
||||
});
|
||||
if (courseCollect == null) {
|
||||
courseDetailsSetVos.get(0).setCurrent(1);
|
||||
current.set(courseDetailsSetVos.get(0));
|
||||
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 (!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
|
||||
|
|
|
|||
|
|
@ -203,6 +203,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements
|
|||
m.put("courseDetailsName", "");
|
||||
m.put("dyEpisodeId", "");
|
||||
m.put("wxCourseDetailsId", "");
|
||||
m.put("courseId", m.get("courseId").toString());
|
||||
}
|
||||
PageUtils pageUtils = PageUtils.page(pageInfo);
|
||||
setCache(cacheKey, JSONUtil.toJsonStr(pageUtils));
|
||||
|
|
@ -226,7 +227,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements
|
|||
map.put("dyEpisodeId", "");
|
||||
map.put("wxCourseDetailsId", "");
|
||||
map.putAll(countMap);
|
||||
map.put("courseId", courseId + "");
|
||||
map.put("courseId", map.get("courseId").toString());
|
||||
}
|
||||
PageUtils pageUtils = PageUtils.page(pageInfo);
|
||||
// setCache(cacheKey, JSONUtil.toJsonStr(pageUtils));
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@
|
|||
FROM `course_collect` c1
|
||||
WHERE c1.classify = 3
|
||||
AND c1.user_id = #{userId}
|
||||
group by c1.course_id
|
||||
order by c1.create_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue