Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -67,6 +67,7 @@ public class SqxExceptionHandler {
|
|||||||
public Result handleException(Exception e, WebRequest webRequest) {
|
public Result handleException(Exception e, WebRequest webRequest) {
|
||||||
logErrorInfo(webRequest);
|
logErrorInfo(webRequest);
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
|
e.printStackTrace();
|
||||||
return Result.error();
|
return Result.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.sqx.modules.app.entity;
|
package com.sqx.modules.app.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -17,12 +19,14 @@ public class UserInfo implements Serializable {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@TableId(type = IdType.ID_WORKER)
|
@TableId(type = IdType.ID_WORKER)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户id
|
* 用户id
|
||||||
*/
|
*/
|
||||||
@TableField(updateStrategy = FieldStrategy.NEVER)
|
@TableField(updateStrategy = FieldStrategy.NEVER)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -165,15 +165,15 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
|
|||||||
List<CourseDetails> courseDetails1 = courseIdList.isEmpty() ? new ArrayList<>() :
|
List<CourseDetails> courseDetails1 = courseIdList.isEmpty() ? new ArrayList<>() :
|
||||||
courseDetailsService.list(new LambdaQueryWrapper<CourseDetails>().in(CourseDetails::getCourseDetailsId, courseDetailIds));
|
courseDetailsService.list(new LambdaQueryWrapper<CourseDetails>().in(CourseDetails::getCourseDetailsId, courseDetailIds));
|
||||||
Map<Long, CourseDetails> courseDetailsMap = courseDetails1.stream().collect(Collectors.toMap(CourseDetails::getCourseId, item -> item));
|
Map<Long, CourseDetails> courseDetailsMap = courseDetails1.stream().collect(Collectors.toMap(CourseDetails::getCourseId, item -> item));
|
||||||
List<CourseDetails> courseDetails2 = courseIdList.isEmpty() ? new ArrayList<>() : courseDetailsDao.countByCourseId(courseIdList);
|
// List<CourseDetails> courseDetails2 = courseIdList.isEmpty() ? new ArrayList<>() : courseDetailsDao.countByCourseId(courseIdList);
|
||||||
Map<Long, Integer> countMap = courseDetails2.stream()
|
// Map<Long, Integer> countMap = courseDetails2.stream()
|
||||||
.collect(Collectors.toMap(CourseDetails::getCourseId, CourseDetails::getCourseDetailsCount));
|
// .collect(Collectors.toMap(CourseDetails::getCourseId, CourseDetails::getCourseDetailsCount));
|
||||||
|
|
||||||
if (CollectionUtil.isNotEmpty(courseList)) {
|
if (CollectionUtil.isNotEmpty(courseList)) {
|
||||||
for (Course course : courseList) {
|
for (Course course : courseList) {
|
||||||
// course.setCourseClassification(courseClassificationDao.selectById(course.getClassifyId()));
|
// course.setCourseClassification(courseClassificationDao.selectById(course.getClassifyId()));
|
||||||
CourseDetails courseDetails = courseDetailsMap.getOrDefault(course.getCourseId(), null);
|
CourseDetails courseDetails = courseDetailsMap.getOrDefault(course.getCourseId(), null);
|
||||||
course.setCourseDetailsCount(countMap.getOrDefault(course.getCourseId(), 0));
|
course.setCourseDetailsCount(courseDetailsDao.countCourseByCourseId(course.getCourseId()));
|
||||||
if (courseDetails != null) {
|
if (courseDetails != null) {
|
||||||
course.setCourseDetailsName(courseDetails.getCourseDetailsName());
|
course.setCourseDetailsName(courseDetails.getCourseDetailsName());
|
||||||
course.setCourseDetailsId(courseDetails.getCourseDetailsId());
|
course.setCourseDetailsId(courseDetails.getCourseDetailsId());
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements
|
|||||||
m.put("courseDetailsName", "");
|
m.put("courseDetailsName", "");
|
||||||
m.put("dyEpisodeId", "");
|
m.put("dyEpisodeId", "");
|
||||||
m.put("wxCourseDetailsId", "");
|
m.put("wxCourseDetailsId", "");
|
||||||
|
m.put("courseId", m.get("courseId").toString());
|
||||||
}
|
}
|
||||||
PageUtils pageUtils = PageUtils.page(pageInfo);
|
PageUtils pageUtils = PageUtils.page(pageInfo);
|
||||||
setCache(cacheKey, JSONUtil.toJsonStr(pageUtils));
|
setCache(cacheKey, JSONUtil.toJsonStr(pageUtils));
|
||||||
@@ -226,7 +227,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements
|
|||||||
map.put("dyEpisodeId", "");
|
map.put("dyEpisodeId", "");
|
||||||
map.put("wxCourseDetailsId", "");
|
map.put("wxCourseDetailsId", "");
|
||||||
map.putAll(countMap);
|
map.putAll(countMap);
|
||||||
map.put("courseId", courseId + "");
|
map.put("courseId", map.get("courseId").toString());
|
||||||
}
|
}
|
||||||
PageUtils pageUtils = PageUtils.page(pageInfo);
|
PageUtils pageUtils = PageUtils.page(pageInfo);
|
||||||
// setCache(cacheKey, JSONUtil.toJsonStr(pageUtils));
|
// setCache(cacheKey, JSONUtil.toJsonStr(pageUtils));
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
FROM `course_collect` c1
|
FROM `course_collect` c1
|
||||||
WHERE c1.classify = 3
|
WHERE c1.classify = 3
|
||||||
AND c1.user_id = #{userId}
|
AND c1.user_id = #{userId}
|
||||||
group by c1.course_id
|
|
||||||
order by c1.create_time desc
|
order by c1.create_time desc
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user