You've already forked FrameTour-BE
修改
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ycwl.basic.mapper.VideoMapper;
|
||||
import com.ycwl.basic.model.pc.video.entity.MemberVideoEntity;
|
||||
import com.ycwl.basic.model.pc.video.entity.VideoEntity;
|
||||
@ -18,6 +19,33 @@ public class VideoRepository {
|
||||
@Autowired
|
||||
private VideoMapper videoMapper;
|
||||
|
||||
public static final String VIDEO_CACHE_KEY = "video:%s";
|
||||
public static final String VIDEO_BY_TASK_ID_CACHE_KEY = "video:task:%s";
|
||||
|
||||
public VideoEntity getVideo(Long videoId) {
|
||||
if (redisTemplate.hasKey(String.format(VIDEO_CACHE_KEY, videoId))) {
|
||||
return JSON.parseObject(redisTemplate.opsForValue().get(String.format(VIDEO_CACHE_KEY, videoId)), VideoEntity.class);
|
||||
}
|
||||
VideoEntity video = videoMapper.getEntity(videoId);
|
||||
if (video != null) {
|
||||
redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, videoId), JSON.toJSONString(video));
|
||||
redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, video.getTaskId()), JSON.toJSONString(video));
|
||||
}
|
||||
return video;
|
||||
}
|
||||
|
||||
public VideoEntity getVideoByTaskId(Long taskId) {
|
||||
if (redisTemplate.hasKey(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId))) {
|
||||
return JSON.parseObject(redisTemplate.opsForValue().get(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId)), VideoEntity.class);
|
||||
}
|
||||
VideoEntity video = videoMapper.findByTaskId(taskId);
|
||||
if (video != null) {
|
||||
redisTemplate.opsForValue().set(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, taskId), JSON.toJSONString(video));
|
||||
redisTemplate.opsForValue().set(String.format(VIDEO_CACHE_KEY, video.getId()), JSON.toJSONString(video));
|
||||
}
|
||||
return video;
|
||||
}
|
||||
|
||||
public void updateMeta(Long videoId, VideoInfoReq req) {
|
||||
VideoRespVO video = videoMapper.getById(videoId);
|
||||
if (video.getDuration() != null) {
|
||||
@ -31,6 +59,7 @@ public class VideoRepository {
|
||||
update.setWidth(req.getWidth());
|
||||
update.setDuration(req.getDuration());
|
||||
videoMapper.updateMeta(update);
|
||||
clearVideoCache(videoId);
|
||||
}
|
||||
|
||||
public void setUserIsBuyItem(Long memberId, Long videoId, Long orderId) {
|
||||
@ -58,4 +87,13 @@ public class VideoRepository {
|
||||
}
|
||||
return Integer.valueOf(1).equals(memberVideo.getIsBuy());
|
||||
}
|
||||
|
||||
public boolean clearVideoCache(Long videoId) {
|
||||
if (redisTemplate.hasKey(String.format(VIDEO_CACHE_KEY, videoId))) {
|
||||
VideoEntity video = getVideo(videoId);
|
||||
redisTemplate.delete(String.format(VIDEO_CACHE_KEY, videoId));
|
||||
redisTemplate.delete(String.format(VIDEO_BY_TASK_ID_CACHE_KEY, video.getTaskId()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,19 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ycwl.basic.mapper.TaskMapper;
|
||||
import com.ycwl.basic.mapper.VideoMapper;
|
||||
import com.ycwl.basic.model.pc.task.entity.TaskEntity;
|
||||
import com.ycwl.basic.model.pc.task.resp.TaskRespVO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@ -34,4 +40,28 @@ public class VideoTaskRepository {
|
||||
public void clearTaskCache(Long taskId) {
|
||||
redisTemplate.delete(String.format(TASK_CACHE_KEY, taskId));
|
||||
}
|
||||
|
||||
|
||||
public Date getTaskShotDate(Long taskId) {
|
||||
TaskRespVO taskRespVO = taskMapper.getById(taskId);
|
||||
if (taskRespVO == null) {
|
||||
return null;
|
||||
}
|
||||
Date shotTime = taskRespVO.getCreateTime();
|
||||
JSONObject paramJson = JSON.parseObject(taskRespVO.getTaskParams());
|
||||
if (paramJson != null) {
|
||||
Optional<String> any = paramJson.keySet().stream().filter(StringUtils::isNumeric).findAny();
|
||||
if (any.isPresent()) {
|
||||
JSONArray jsonArray = paramJson.getJSONArray(any.get());
|
||||
if (!jsonArray.isEmpty()) {
|
||||
JSONObject jsonObject = jsonArray.getJSONObject(0);
|
||||
if (jsonObject.containsKey("createTime")) {
|
||||
shotTime = new Date(jsonObject.getLong("createTime"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return shotTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user