点赞数负数的情况

This commit is contained in:
2025-01-14 14:10:54 +08:00
parent 93bbb2d782
commit d376c3ad22

View File

@@ -127,11 +127,14 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
.eq(CourseDetails::getCourseId, collect.getCourseId())
.eq(CourseDetails::getCourseDetailsId, collect.getCourseDetailsId());
CourseDetails courseDetails = courseDetailsService.getOne(queryWrapper);
int goods = courseDetails.getGoodNum() == null || courseDetails.getGoodNum() < 0 ? 0 : courseDetails.getGoodNum() - (isGood.equals(1) ? 1 : -1);
if (goods < 0) {
return;
}
LambdaUpdateWrapper<CourseDetails> updateWrapper = new LambdaUpdateWrapper<CourseDetails>()
.eq(CourseDetails::getCourseId, collect.getCourseId())
.eq(CourseDetails::getCourseDetailsId, collect.getCourseDetailsId())
.set(CourseDetails::getGoodNum, courseDetails.getGoodNum() == null ? 0 : courseDetails.getGoodNum() - (isGood.equals(1) ? 1 : -1));
.set(CourseDetails::getGoodNum, goods);
courseDetailsService.update(updateWrapper);
}
@@ -143,7 +146,7 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
if (classify.equals(1)) {
//收藏记录
courses = baseMapper.selectClassify1In3(userId);
}else if (classify.equals(2)){
} else if (classify.equals(2)) {
//点赞
courses = baseMapper.selectClassify2(userId);
} else {
@@ -156,14 +159,14 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
//详情id
Set<Long> courseDetailIds = new HashSet<>();
//剧集-观看记录时间
Map<Long,String> upTime = new HashMap<>();
Map<Long, String> upTime = new HashMap<>();
courses.forEach(s -> {
if (s == null) {
return;
}
courseIdList.add(s.getCourseId());
courseDetailIds.add(s.getCourseDetailsId());
upTime.put(s.getCourseId(),s.getUpdateTime());
upTime.put(s.getCourseId(), s.getUpdateTime());
});
List<Course> courseList = courseIdList.isEmpty() ? new ArrayList<>() :
courseDao.selectList(new LambdaQueryWrapper<Course>().in(Course::getCourseId, courseIdList));