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

视频功能

上级 a13a09d1
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.cache;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.pojo.vo.UserCountsCacheVO;
import java.util.List;
public interface IUserCountsCacheRepository {
void save(List<UserCountsCacheVO> userCounts);
void deleteAll();
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.cache.impl;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.cache.IUserCountsCacheRepository;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.pojo.vo.UserCountsCacheVO;
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;
import static cn.tedu.youbiliprojectbackend.common.consts.CountConsts.USER_COUNT;
@Slf4j
@Repository
public class UserCountsCacheRepositoryImpl implements IUserCountsCacheRepository {
@Autowired
RedisTemplate<String, Serializable> template;
@Override
public void save(List<UserCountsCacheVO> userCounts) {
ValueOperations<String, Serializable> operations = template.opsForValue();
for (UserCountsCacheVO userCount : userCounts) {
operations.set(USER_COUNT+userCount.getUserID(),userCount);
}
}
@Override
public void deleteAll() {
log.debug("清空缓存");
Set<String> keys = template.keys(USER_COUNT + "*");
if (keys != null && !keys.isEmpty()) {
template.delete(keys);
}
}
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.persist.mapper;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.pojo.vo.UserCountsCacheVO;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface UserCountMapper {
List<UserCountsCacheVO> selectAll();
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.persist.repository;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.pojo.vo.UserCountsCacheVO;
import java.util.List;
public interface IUserCountsRepository {
List<UserCountsCacheVO> selectAll();
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.persist.repository.impl;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.persist.mapper.UserCountMapper;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.persist.repository.IUserCountsRepository;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.pojo.vo.UserCountsCacheVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class UserCountsRepository implements IUserCountsRepository {
@Autowired
private UserCountMapper mapper;
@Override
public List<UserCountsCacheVO> selectAll() {
return mapper.selectAll();
}
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.pojo.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class UserCountsCacheVO implements Serializable {
private Long userID;
private Integer fans;
private Integer follows;
private Integer videoCount;
private Integer totalLikes;
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.schedule;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.service.IUserCountsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class UserCountsCacheSchedule implements ApplicationRunner {
@Autowired
private IUserCountsService service;
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("项目启动,正在处理缓存用户计数字段业务");
service.saveCacheUserCounts();
}
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.service;
import org.springframework.stereotype.Service;
@Service
public interface IUserCountsService {
void saveCacheUserCounts();
}
package cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.service.impl;
import cn.tedu.youbiliprojectbackend.common.cacheUtils.count.user.dao.cache.IUserCountsCacheRepository;
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;
public class UserCountsService implements IUserCountsService {
@Autowired
private IUserCountsRepository repository;
@Autowired
IUserCountsCacheRepository cacheRepository;
@Override
public void saveCacheUserCounts() {
cacheRepository.deleteAll();
cacheRepository.save(repository.selectAll());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册