task缓存

This commit is contained in:
2025-01-03 17:38:15 +08:00
parent 8e95d1b390
commit 5d9f3aae41
11 changed files with 71 additions and 71 deletions

View 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);
}
}

View File

@ -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));
}
}