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

配置日志
This commit is contained in:
wangw 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;
}

View File

@ -1,6 +1,9 @@
#logging:
# file:
# name: logs/duanju.log
# 日志配置
logging:
file:
name: logs/duanju.log
config: classpath:logback.xml
# Tomcat
server:
@ -27,25 +30,6 @@ pagehelper:
supportMethodsArguments: true
params:
count: countSql
#mybatis-plus:
# mapper-locations: classpath*:/mapper/**/*.xml
# #实体扫描多个package用逗号或者分号分隔
# typeAliasesPackage: com.sqx.modules.*.entity
# global-config:
# #数据库相关配置
# db-config:
# #主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
# id-type: AUTO
# logic-delete-value: -1
# logic-not-delete-value: 0
# banner: false
# #原生配置
# configuration:
# map-underscore-to-camel-case: true
# cache-enabled: false
# call-setters-on-nulls: true
# jdbc-type-for-null: 'null'
## log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
sqx:
redis:

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<contextName>logback</contextName>
<!-- 打印控制台格式 -->
<!--%d表示日期%thread表示线程名%-5level级别从左显示5个字符宽度%msg日志消息%n是换行符-->
<property name="p_console"
value="%green(%d) | %highlight(%-5level) [%thread] %yellow(%c) %cyan([%L]) -| %X{messageId} %msg %n"/>
<!--写入文件格式-->
<property name="p_file" value="%d | %-5level [%thread] %c [%L] -| %X{messageId} %msg %n"/>
<!--输出到控制台-->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${p_console}</pattern>
</encoder>
</appender>
<!--按天生成日志-->
<appender name="logFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/duanju.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--生成日志文件名称-->
<fileNamePattern>logs/duanju.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>30</MaxHistory>
<maxFileSize>100MB</maxFileSize>
</rollingPolicy>
<!-- 日志输出格式 -->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${p_file}</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 配置一些第三方包的日志过滤级别,用于避免刷屏 -->
<!-- 日志级别排序为: TRACE < DEBUG < INFO < WARN < ERROR-->
<!-- WARN [main] org.mybatis.spring.mapper.ClassPathMapperScanner-->
<!-- INFO [main] org.apache.shardingsphere.core.log.ConfigurationLogger-->
<logger name="org.springframework.context.support" level="WARN"/>
<logger name="org.apache.shardingsphere" level="WARN"/>
<logger name="org.mybatis.spring.mapper.ClassPathMapperScanner" level="ERROR"/>
<logger name="com.zaxxer.hikari" level="WARN"/>
<!-- 输出日志 -->
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="logFile"/>
</root>
</configuration>

View File

@ -3,13 +3,14 @@
<mapper namespace="com.sqx.modules.course.dao.CourseDetailsDao">
<select id="courseSets" resultType="com.sqx.modules.course.vo.CourseDetailsSetVo">
select c.course_id as courseId
, c.course_details_id as courseDetailsId
, c.course_details_name as courseDetailsName
, c.price as countPrice
, ifnull(#{price}, 0, #{price}) as price
, ifnull(#{wholesalePrice}, 0, #{wholesalePrice}) as wholesalePrice
, IF(#{isPrice}, c.is_price, 2) AS isPrice
select c.course_id as courseId
, c.course_details_id as courseDetailsId
, c.course_details_name as courseDetailsName
, c.price as countPrice
, c.sort as sort
, ifnull(#{price}, 0) as price
, ifnull(#{wholesalePrice}, 0) as wholesalePrice
, IF(#{isPrice} = 1, c.is_price, 2) AS isPrice
from course_details c
where c.course_id = #{courseId}
order by c.sort asc
@ -22,7 +23,8 @@
, c.title_img as titleImg
, c.video_url as videoUrl
, c.good_num as goodNum
, ifnull(#{collect}, 0, 1) as isCollect
, c.sort as sort
, IF(#{collect} = 1, 1, 0) AS isCollect
from course_details c
where c.course_id = #{courseId}
and sort &gt; #{starSort}