视频 查看集 和 集数列表 拆分2

配置日志
This commit is contained in:
2025-01-04 17:49:13 +08:00
parent a2fdd2c4fd
commit 464f4ba7c8
9 changed files with 118 additions and 69 deletions

View File

@@ -153,24 +153,6 @@ public class ShardingConfig {
for (String regionTable : regionTables) {
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration(regionTable, String.format(regionTablesDataNode, regionTable));
tableRuleConfig.setDatabaseShardingStrategyConfig(databaseShardingStrategyConfig);
// // 设置区域表使用雪花算法生成主键
// switch (regionTable){
// case "orders":
// tableRuleConfig.setKeyGeneratorConfig(new KeyGeneratorConfiguration("SNOWFLAKE", "orders_id"));
// break;
//// case "course_collect":
//// tableRuleConfig.setKeyGeneratorConfig(new KeyGeneratorConfiguration("SNOWFLAKE", "course_collect_id"));
//// break;
// case "course_user":
// tableRuleConfig.setKeyGeneratorConfig(new KeyGeneratorConfiguration("SNOWFLAKE", "course_user_id"));
// break;
// case "tb_user":
// tableRuleConfig.setKeyGeneratorConfig(new KeyGeneratorConfiguration("SNOWFLAKE", "user_id"));
// break;
// default:
// tableRuleConfig.setKeyGeneratorConfig(new KeyGeneratorConfiguration("SNOWFLAKE", "id"));
// break;
// }
sets.add(tableRuleConfig);
}
@@ -178,8 +160,6 @@ public class ShardingConfig {
// 定义区域表的分库规则
StandardShardingStrategyConfiguration courseDetailsShardingStrategyConfig = new StandardShardingStrategyConfiguration(
courseDetailsShardingDatabaseColumn, new StandardShardingStrategyConf());
// InlineShardingStrategyConfiguration courseDetailsShardingStrategyConfig = new InlineShardingStrategyConfiguration(
// courseDetailsShardingDatabaseColumn, courseDetailsShardingDatabaseAlgorithm);
for (String regionTable : courseDetails) {
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration(regionTable, String.format(regionTablesDataNode, regionTable));
tableRuleConfig.setDatabaseShardingStrategyConfig(courseDetailsShardingStrategyConfig);

View File

@@ -6,14 +6,15 @@ import com.sqx.modules.course.vo.CourseDetailsSetVo;
import com.sqx.modules.course.vo.CourseDetailsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Mapper
@CacheConfig
public interface CourseDetailsDao extends BaseMapper<CourseDetails> {
/**
* @param courseId 剧的id
@@ -21,9 +22,10 @@ public interface CourseDetailsDao extends BaseMapper<CourseDetails> {
* @param price 全剧价格
* @param wholesalePrice 10集价格
*/
List<CourseDetailsSetVo> courseSets(@Param("courseId") Long courseId, boolean isPrice, BigDecimal price, BigDecimal wholesalePrice);
@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") Integer collect,
List<CourseDetailsVo> courseDetails(@Param("courseId") Long courseId, @Param("collect") Long collect,
@Param("starSort") Integer starSort, @Param("endSort") Integer endSort);
List<CourseDetails> findByCourseId(@Param("id") Long id, @Param("userId") Long userId);
@@ -42,6 +44,7 @@ public interface CourseDetailsDao extends BaseMapper<CourseDetails> {
*/
Map<String, Object> countCourse(Long courseId);
@Cacheable(cacheNames = "courseCount" ,key = "#courseId")
Integer countCourseByCourseId(Long courseId);
List<CourseDetails> countByCourseId();

View File

@@ -46,15 +46,13 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
@Service
@@ -84,6 +82,7 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
@Override
@CacheEvict(cacheNames = {"courseSets", "courseCount"}, key = "#courseDetails.courseId")
public Result insert(CourseDetails courseDetails) {
if (courseDetails.getGoodNum() == null) {
courseDetails.setGoodNum(0);
@@ -93,6 +92,7 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
}
@Override
@CacheEvict(cacheNames = {"courseSets", "courseCount"}, key = "#courseDetails.courseId")
public Result updateCourseDetails(CourseDetails courseDetails) {
baseMapper.updateById(courseDetails);
return Result.success();
@@ -164,26 +164,36 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
boolean freeWatch = checkFreeWatchPayCount(userId);
List<CourseDetailsSetVo> courseDetailsSetVos;
if (freeWatch || courseUser != null) {
courseDetailsSetVos = baseMapper.courseSets(courseId, false, null, null);
courseDetailsSetVos = baseMapper.courseSets(courseId, 2, null, null);
} else {
courseDetailsSetVos = baseMapper.courseSets(courseId, true, bean.getPrice(), bean.getWholesalePrice());
// 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 (s.getCourseDetailsId().equals(courseCollect.getCourseDetailsId())) {
s.setCurrent(1);
}
if (detailsId.contains(s.getCourseDetailsId())) {
s.setIsPrice(2);
}
})
.filter(s -> s.getCurrent() == 1 || s.getIsPrice() == 2)
.collect(Collectors.toList());
}
}
return new Result().put("data", courseDetailsSetVos);
Map<String, Object> map = new HashMap<>();
map.put("title", bean.getTitle());
map.put("list", courseDetailsSetVos);
return new Result().put("data", map);
}
@Override
@@ -198,9 +208,11 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
if (sort == null) {
CourseCollect courseCollect = courseCollectDao.selectOne(new QueryWrapper<CourseCollect>().eq("course_id", courseId)
.eq("user_id", userId).eq("classify", 3).last("limit 1"));
CourseDetails courseDetails = baseMapper.selectOne(new QueryWrapper<CourseDetails>()
.eq("course_details_id", courseCollect.getCourseDetailsId()).eq("course_id", courseCollect.getCourseId()).last("limit 1"));
sort = courseDetails.getSort();
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();
}
}
if (sort != null && sort > 2) {
startSort = sort - 3;
@@ -210,11 +222,28 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
endSort = detailCount + 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"));
List<CourseDetailsVo> courseDetailsVos = baseMapper.courseDetails(courseId, collect, startSort, endSort);
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 -> {
// 不免费 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);

View File

@@ -49,6 +49,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@@ -149,6 +150,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements
}
@Override
@CacheEvict(cacheNames = {"courseSets", "courseCount"}, key = "#course.courseId")
public Result updateCourse(Course course) {
baseMapper.updateById(course);
return Result.success("操作成功!");

View File

@@ -13,4 +13,6 @@ public class CourseDetailsSetVo {
private Integer isPrice;
private BigDecimal price;
private BigDecimal wholesalePrice;
private BigDecimal countPrice;
private Integer sort;
}

View File

@@ -22,9 +22,10 @@ public class CourseDetailsVo {
/**
* 是否已追
*/
private Integer isCollect;
private Long isCollect;
/**
* 是否点赞
*/
private Integer isGood;
private Integer sort;
}