You've already forked FrameTour-BE
改bug
This commit is contained in:
@ -0,0 +1,7 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FaceRepository {
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
public class ScenicRepository {
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ycwl.basic.mapper.FaceMapper;
|
||||
import com.ycwl.basic.mapper.FaceSampleMapper;
|
||||
import com.ycwl.basic.mapper.TemplateMapper;
|
||||
import com.ycwl.basic.model.pc.face.resp.FaceRespVO;
|
||||
import com.ycwl.basic.model.pc.faceSample.resp.FaceSampleRespVO;
|
||||
import com.ycwl.basic.model.pc.template.entity.TemplateConfigEntity;
|
||||
import com.ycwl.basic.model.pc.template.resp.TemplateRespVO;
|
||||
import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service // 临时这么用
|
||||
public class TemplateRepository {
|
||||
@Autowired
|
||||
private FaceMapper faceMapper;
|
||||
@Autowired
|
||||
private FaceSampleMapper faceSampleMapper;
|
||||
@Autowired
|
||||
private TemplateMapper templateMapper;
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
public static final String TEMPLATE_CACHE_KEY = "template:%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));
|
||||
Map<String, Boolean> map = new HashMap<>();
|
||||
for (TemplateRespVO child : template.getChildren()) {
|
||||
if (child.getIsPlaceholder() == 1) {
|
||||
map.put(child.getSourceUrl(), false);
|
||||
}
|
||||
}
|
||||
TemplateConfigEntity templateConfig = templateMapper.getConfig(templateId);
|
||||
if (0 == templateConfig.getMinimalPlaceholderFill()) {
|
||||
return true;
|
||||
}
|
||||
FaceRespVO face = faceMapper.getById(faceId);
|
||||
if (face.getMatchSampleIds() == null) {
|
||||
return false;
|
||||
}
|
||||
List<FaceSampleRespVO> faceSample = faceSampleMapper.listByIds(Arrays.stream(face.getMatchSampleIds().split(",")).map(Long::valueOf).collect(Collectors.toList()));
|
||||
faceSample.stream().collect(Collectors.groupingBy(FaceSampleRespVO::getDeviceId)).forEach((deviceId, value) -> {
|
||||
if (map.containsKey(deviceId.toString())) {
|
||||
map.put(deviceId.toString(), true);
|
||||
}
|
||||
});
|
||||
return map.values().stream().filter(item -> item).count() >= templateConfig.getMinimalPlaceholderFill();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
TemplateRespVO template = templateMapper.getById(templateId);
|
||||
if (null == template.getPid() || template.getPid() == 0) {
|
||||
template.setChildren(templateMapper.getByPid(templateId));
|
||||
redisTemplate.opsForValue().set(String.format(TEMPLATE_CACHE_KEY, templateId), JSONObject.toJSONString(template));
|
||||
return template;
|
||||
} else {
|
||||
clearTemplateCache(templateId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public TemplateConfigEntity getTemplateConfig(Long templateId) {
|
||||
if (redisTemplate.hasKey(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId)), TemplateConfigEntity.class);
|
||||
}
|
||||
TemplateConfigEntity templateConfig = templateMapper.getConfig(templateId);
|
||||
if (templateConfig == null) {
|
||||
templateConfig = new TemplateConfigEntity();
|
||||
templateConfig.setId(SnowFlakeUtil.getLongId());
|
||||
templateConfig.setTemplateId(templateId);
|
||||
templateMapper.addConfig(templateConfig);
|
||||
}
|
||||
redisTemplate.opsForValue().set(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId), JSONObject.toJSONString(templateConfig));
|
||||
return templateConfig;
|
||||
}
|
||||
|
||||
public boolean clearTemplateCache(Long templateId) {
|
||||
redisTemplate.delete(String.format(TEMPLATE_CACHE_KEY, templateId));
|
||||
redisTemplate.delete(String.format(TEMPLATE_CONFIG_CACHE_KEY, templateId));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
public class VideoTaskRepository {
|
||||
}
|
Reference in New Issue
Block a user