You've already forked FrameTour-BE
taskStatus
This commit is contained in:
@ -1,7 +1,17 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
import com.ycwl.basic.mapper.FaceMapper;
|
||||
import com.ycwl.basic.mapper.FaceSampleMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FaceRepository {
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
@Autowired
|
||||
private FaceMapper faceMapper;
|
||||
@Autowired
|
||||
private FaceSampleMapper faceSampleMapper;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -30,12 +31,12 @@ public class TemplateRepository {
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
public static final String TEMPLATE_CACHE_KEY = "template:%s";
|
||||
public static final String TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY = "template:id:byScenic:%s";
|
||||
public static final String TEMPLATE_CONFIG_CACHE_KEY = "template:%s:config";
|
||||
|
||||
|
||||
public boolean determineTemplateCanGenerate(Long templateId, Long faceId) {
|
||||
TemplateRespVO template = templateMapper.getById(templateId);
|
||||
template.setChildren(templateMapper.getByPid(templateId));
|
||||
TemplateRespVO template = getTemplate(templateId);
|
||||
Map<String, Boolean> map = new HashMap<>();
|
||||
for (TemplateRespVO child : template.getChildren()) {
|
||||
if (child.getIsPlaceholder() == 1) {
|
||||
@ -59,6 +60,20 @@ public class TemplateRepository {
|
||||
return map.values().stream().filter(item -> item).count() >= templateConfig.getMinimalPlaceholderFill();
|
||||
}
|
||||
|
||||
public List<TemplateRespVO> getTemplateListByScenicId(Long scenicId) {
|
||||
List<Long> idList;
|
||||
if (redisTemplate.hasKey(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId))) {
|
||||
idList = JSONObject.parseArray(redisTemplate.opsForValue().get(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId)), Long.class);
|
||||
} else {
|
||||
idList = templateMapper.listEnabledTemplateIdByScenicId(scenicId);
|
||||
redisTemplate.opsForValue().set(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, scenicId), JSONObject.toJSONString(idList));
|
||||
}
|
||||
if (idList == null || idList.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return idList.stream().map(this::getTemplate).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public TemplateRespVO getTemplate(Long templateId) {
|
||||
if (redisTemplate.hasKey(String.format(TEMPLATE_CACHE_KEY, templateId))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_CACHE_KEY, templateId)), TemplateRespVO.class);
|
||||
@ -90,6 +105,10 @@ public class TemplateRepository {
|
||||
}
|
||||
|
||||
public boolean clearTemplateCache(Long templateId) {
|
||||
if (redisTemplate.hasKey(String.format(TEMPLATE_CACHE_KEY, templateId))) {
|
||||
TemplateRespVO template = getTemplate(templateId);
|
||||
redisTemplate.delete(String.format(TEMPLATE_ID_BY_SCENIC_ID_CACHE_KEY, template.getScenicId()));
|
||||
}
|
||||
redisTemplate.delete(String.format(TEMPLATE_CACHE_KEY, templateId));
|
||||
redisTemplate.delete(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId));
|
||||
return true;
|
||||
|
@ -1,4 +1,34 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class VideoTaskRepository {
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
@Autowired
|
||||
private TaskMapper taskMapper;
|
||||
@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) {
|
||||
if (redisTemplate.hasKey(String.format(TASK_CACHE_KEY, taskId))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(TASK_CACHE_KEY, taskId)), TaskEntity.class);
|
||||
} else {
|
||||
TaskEntity task = taskMapper.get(taskId);
|
||||
if (task != null) {
|
||||
redisTemplate.opsForValue().set(String.format(TASK_CACHE_KEY, taskId), JSONObject.toJSONString(task));
|
||||
}
|
||||
return task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user