提交 2668320f 编写于 作者: 喷火的神灵's avatar 喷火的神灵 🎱

计数字段功能修正

上级 5aefbcd1
/YouBili_front/node_modules/
/youbili-project-backend/src/main/resources/videos/2023-04-14 10-44-46.mp4
......@@ -143,17 +143,17 @@
import {
uploadVideo, // 上传视频
} from "@/utils/option"
import { createFFmpeg, fetchFile } from '@ffmpeg/ffmpeg';
export default {
name: "contribute",
data() {
return {
fileList: [],
video: {
userID: "", // 当前用户id
title: "", // 标题
description: "", // 描述
videoImgUrl: "", // 视频封面
videoUrl: "",
videoSrcUrl: "",
type: "", // 分类
tag: "" // 标签
},
......@@ -215,12 +215,13 @@ export default {
// 上传视频
uploadVideoFile(param) {
const file = param.file;
this.video.videoUrl = file.name;
let form = new FormData();
form.append("file", file);
uploadVideo(form).then(res => {
if (res.success) {
alert("上传成功")
alert("上传成功");
this.video.userID = res.data.userID;
this.video.videoSrcUrl = res.data.videoSrcUrl;
}
})
},
......
......@@ -4,7 +4,9 @@ import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.cache.IUse
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.persist.repository.IUserCountsRepository;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.service.IUserCountsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserCountsService implements IUserCountsService {
@Autowired
private IUserCountsRepository repository;
......
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.cache;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.pojo.VideoCount;
import cn.tedu.youbiliprojectbackend.common.consts.CountConsts;
import java.util.List;
public interface VideoCountCache extends CountConsts {
/**
* 将视频计数信息保存在缓存之中
*/
void save(List<VideoCount> videoCounts);
/**
* 清空所有保存的视频计数信息
*/
void deleteAll();
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.cache.impl;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.cache.VideoCountCache;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.persist.repository.VideoCountRepositroy;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.pojo.VideoCount;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;
import java.io.Serializable;
import java.util.List;
import java.util.Set;
@Slf4j
@Repository
public class VideoCountCacheImpl implements VideoCountCache {
@Autowired
RedisTemplate<String, Serializable> redisTemplate;
/**
* 将视频计数信息保存在缓存之中
*/
@Override
public void save(List<VideoCount> videoCounts) {
log.debug("开始将视频计数信息保存在缓存之中!");
ValueOperations<String, Serializable> operations = redisTemplate.opsForValue();
for(VideoCount count : videoCounts){
String key = VIDEO_COUNT + count.getVideoID();
operations.set(key,count);
}
}
/**
* 清空所有保存的视频计数信息
*/
@Override
public void deleteAll() {
Set<String> keys = redisTemplate.keys(VIDEO_COUNT+"*");
ValueOperations<String, Serializable> operations = redisTemplate.opsForValue();
if (keys != null && !keys.isEmpty()) {
redisTemplate.delete(keys);
}
}
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.persist.mapper;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.pojo.VideoCount;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 视频计数字段Mapper
*/
@Repository
public interface VideoCountMapper {
List<VideoCount> selectCount();
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.persist.repository;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.pojo.VideoCount;
import java.util.List;
public interface VideoCountRepositroy {
/**
* 查询视频所有的计数字段;
* @return
*/
List<VideoCount> videoCacheCount();
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.persist.repository.impl;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.persist.mapper.VideoCountMapper;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.persist.repository.VideoCountRepositroy;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.pojo.VideoCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class VideoCountRepositroyImpl implements VideoCountRepositroy {
@Autowired
VideoCountMapper videoCountMapper;
@Override
public List<VideoCount> videoCacheCount() {
return videoCountMapper.selectCount();
}
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.pojo;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class VideoCount implements Serializable {
private Long videoID;
private Integer viewCount;
private Integer likeCount;
private Integer favoriteCount;
private Integer dislikeCount;
private Integer barrageCount;
private Integer commentCount;
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.service;
public interface VideoCountService {
void SaveCacheVideoCount();
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.service.impl;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.cache.VideoCountCache;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.persist.repository.VideoCountRepositroy;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.service.VideoCountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class VideoCountServiceImpl implements VideoCountService {
@Autowired
VideoCountRepositroy videoCountRepositroy;
@Autowired
VideoCountCache videoCountCache;
/**
* 当项目启动时 先清除videoCount字段 再保存
*/
@Override
public void SaveCacheVideoCount() {
log.debug("开始向缓存之中写入数据!");
videoCountCache.deleteAll();
videoCountCache.save(videoCountRepositroy.videoCacheCount());
}
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.videoList.schedule;
package cn.tedu.youbiliprojectbackend.common.cacheUtils.schedule;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.service.IUserCountsService;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.cache.VideoCountCache;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.service.VideoCountService;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.videoList.service.VideoListService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -10,10 +13,16 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
public class VideoListCacheSchedule implements ApplicationRunner {
public class CacheSchedule implements ApplicationRunner {
@Autowired
VideoListService videoListService;
@Autowired
VideoCountService videoCountService;
@Autowired
IUserCountsService userCountsService;
/**
* 当项目启动时
* 运行下面的方法
......@@ -27,5 +36,13 @@ public class VideoListCacheSchedule implements ApplicationRunner {
public void run(ApplicationArguments args) throws Exception {
log.debug("开始向缓存中写入数据 ----- 视频列表!");
videoListService.saveCacheVideo();
log.debug("开始向缓存中写入数据 ----- 视频计数字段");
videoCountService.SaveCacheVideoCount();
log.debug("开始向缓存中写入数据 ----- 用户计数字段");
userCountsService.saveCacheUserCounts();
}
}
......@@ -11,5 +11,5 @@ public interface RegisterConsts {
/**
* 发送邮件请求插入缓存
*/
String REGISTER_EMAIL_SEND = "user:Register:sendEmail";
String REGISTER_EMAIL_SEND = "Account:Register:SendEmail";
}
......@@ -11,10 +11,10 @@ public interface UserCacheConsts {
/**
* 缓存的JWT前缀
*/
String USER_JWT_PREFIX = "user:Login:jwt:";
String USER_JWT_PREFIX = "Account:Login:jwt:";
/**
* 用户启用状态的KEY的前缀
*/
String USER_ENABLE_PREFIX = "user:Login:enable:";
String USER_ENABLE_PREFIX = "Account:Login:enable:";
}
......@@ -15,7 +15,9 @@ import org.springframework.context.annotation.Configuration;
"cn.tedu.youbiliprojectbackend.modules.user.fan.dao.persist.mapper",
"cn.tedu.youbiliprojectbackend.modules.user.personal.dao.persist.mapper",
"cn.tedu.youbiliprojectbackend.modules.orders.dao.mapper",
"cn.tedu.youbiliprojectbackend.common.cacheUtils.videoList.dao.persist.mapper"
"cn.tedu.youbiliprojectbackend.common.cacheUtils.videoList.dao.persist.mapper",
"cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.persist.mapper",
"cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.persist.mapper"
})
public class MybatisConfig {
}
package cn.tedu.youbiliprojectbackend.modules.tag.classification.controller;
import cn.tedu.youbiliprojectbackend.common.web.response.RestBean;
import cn.tedu.youbiliprojectbackend.common.web.response.ServiceCode;
import cn.tedu.youbiliprojectbackend.modules.tag.pojo.vo.CategoryListVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......
package cn.tedu.youbiliprojectbackend.modules.tag.classification.dao.mapper;
import cn.tedu.youbiliprojectbackend.modules.tag.pojo.entity.Category;
import cn.tedu.youbiliprojectbackend.modules.tag.classification.pojo.entity.Category;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
......
......@@ -40,7 +40,7 @@ public class FavoriteController {
@GetMapping("delete")
public RestBean<String> delete(@AuthenticationPrincipal CurrentPrincipal currentPrincipal,
Long favoriteID){
log.debug("开始处理请求: delete");
log.debug("开始处理请求: deleteAll");
favoriteService.deleteById(favoriteID, currentPrincipal.getUserID());
return RestBean.success("删除成功!");
}
......
......@@ -66,7 +66,7 @@ public class FollowController {
log.debug("followID: {}",followID);
followService.delete(principal.getUserID(),followID);
// followService.delete(1L,3L);
// followService.deleteAll(1L,3L);
return RestBean.success("取消关注成功!");
}
......
......@@ -13,6 +13,8 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@RestController
......@@ -52,6 +54,10 @@ public class VideoUploadController {
return RestBean.failure(ServiceCode.ERROR_UNKNOWN);
}
return RestBean.success();
Map<String, Object> map = new HashMap<>();
map.put("videoSrcUrl", path);
map.put("userID", principal.getUserID());
// map.put("username", principal.getUsername());
return RestBean.success(map);
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.persist.mapper.UserCountMapper">
<select id="selectAll" resultType="cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.pojo.vo.UserCountsCacheVO">
SELECT userID, fans,follows,videoCount,totalLikes
FROM user
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.dao.persist.mapper.VideoCountMapper">
<select id="selectCount"
resultType="cn.tedu.youbiliprojectbackend.common.cacheUtils.count.video.pojo.VideoCount">
SELECT
videoID,viewCount,
likeCount,
favoriteCount,
dislikeCount,
barrageCount,
commentCount
FROM video
WHERE reviewStatus = 'Approved'
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册