You've already forked FrameTour-BE
task缓存
This commit is contained in:
41
src/main/java/com/ycwl/basic/repository/OrderRepository.java
Normal file
41
src/main/java/com/ycwl/basic/repository/OrderRepository.java
Normal file
@ -0,0 +1,41 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
import com.ycwl.basic.mapper.OrderMapper;
|
||||
import com.ycwl.basic.model.pc.order.entity.OrderEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class OrderRepository {
|
||||
@Autowired
|
||||
private OrderMapper orderMapper;
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
public static final String ORDER_ITEM_CACHE_KEY = "order:user:%s:type:%s:id:%s";
|
||||
|
||||
public boolean checkUserBuyItem(Long userId, int goodsType, Long goodsId) {
|
||||
if (redisTemplate.hasKey(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId))) {
|
||||
return true;
|
||||
}
|
||||
OrderEntity orderEntity = orderMapper.getUserBuyItem(userId, goodsType, goodsId);
|
||||
if (orderEntity == null) {
|
||||
return false;
|
||||
}
|
||||
redisTemplate.opsForValue().set(String.format(ORDER_ITEM_CACHE_KEY, userId, goodsType, goodsId), "1");
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkUserBuyFaceSourceImage(Long userId, Long faceId) {
|
||||
return checkUserBuyItem(userId, 2, faceId);
|
||||
}
|
||||
|
||||
public boolean checkUserBuyFaceSourceVideo(Long userId, Long faceId) {
|
||||
return checkUserBuyItem(userId, 1, faceId);
|
||||
}
|
||||
|
||||
public boolean checkUserBuyVideo(Long userId, Long videoId) {
|
||||
return checkUserBuyItem(userId, 0, videoId);
|
||||
}
|
||||
}
|
@ -17,7 +17,6 @@ public class VideoTaskRepository {
|
||||
@Autowired
|
||||
private VideoMapper videoMapper;
|
||||
|
||||
public static final String USER_TASK_CACHE_KEY = "task:user:%s";
|
||||
public static final String TASK_CACHE_KEY = "task:byId:%s";
|
||||
|
||||
public TaskEntity getTaskById(Long taskId) {
|
||||
@ -25,10 +24,14 @@ public class VideoTaskRepository {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(TASK_CACHE_KEY, taskId)), TaskEntity.class);
|
||||
} else {
|
||||
TaskEntity task = taskMapper.get(taskId);
|
||||
if (task != null) {
|
||||
if (task != null && 1 == task.getStatus()) {
|
||||
redisTemplate.opsForValue().set(String.format(TASK_CACHE_KEY, taskId), JSONObject.toJSONString(task));
|
||||
}
|
||||
return task;
|
||||
}
|
||||
}
|
||||
|
||||
public void clearTaskCache(Long taskId) {
|
||||
redisTemplate.delete(String.format(TASK_CACHE_KEY, taskId));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user