You've already forked FrameTour-BE
获取人脸对应视频流程,自动删除源视频流程,自动创建任务渲染流程,自动删除人脸数据逻辑
This commit is contained in:
142
src/main/java/com/ycwl/basic/task/DynamicTaskGenerator.java
Normal file
142
src/main/java/com/ycwl/basic/task/DynamicTaskGenerator.java
Normal file
@ -0,0 +1,142 @@
|
||||
package com.ycwl.basic.task;
|
||||
|
||||
import com.ycwl.basic.mapper.pc.DeviceMapper;
|
||||
import com.ycwl.basic.mapper.pc.FaceMapper;
|
||||
import com.ycwl.basic.mapper.pc.FaceSampleMapper;
|
||||
import com.ycwl.basic.mapper.pc.ScenicMapper;
|
||||
import com.ycwl.basic.mapper.pc.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.scenic.entity.ScenicConfigEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.req.ScenicReqQuery;
|
||||
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
|
||||
import com.ycwl.basic.model.pc.template.entity.TemplateConfigEntity;
|
||||
import com.ycwl.basic.model.pc.template.req.TemplateReqQuery;
|
||||
import com.ycwl.basic.model.pc.template.resp.TemplateRespVO;
|
||||
import com.ycwl.basic.model.task.resp.SearchFaceRespVo;
|
||||
import com.ycwl.basic.service.task.TaskFaceService;
|
||||
import com.ycwl.basic.service.task.TaskService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@EnableScheduling
|
||||
@Slf4j
|
||||
public class DynamicTaskGenerator {
|
||||
@Autowired
|
||||
private ScenicMapper scenicMapper;
|
||||
@Autowired
|
||||
private TemplateMapper templateMapper;
|
||||
@Autowired
|
||||
private FaceMapper faceMapper;
|
||||
@Autowired
|
||||
private TaskFaceService faceService;
|
||||
@Autowired
|
||||
private FaceSampleMapper faceSampleMapper;
|
||||
@Autowired
|
||||
private TaskService taskService;
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
|
||||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void dynamicTask() {
|
||||
List<ScenicRespVO> scenicList = scenicMapper.list(new ScenicReqQuery());
|
||||
for (ScenicRespVO scenic : scenicList) {
|
||||
log.info("定时任务执行,当前景区:{}", scenic.getName());
|
||||
ScenicConfigEntity scenicConfig = scenicMapper.getConfig(scenic.getId());
|
||||
if (scenicConfig == null || scenicConfig.getBookRoutine() == 2) {
|
||||
log.info("当前景区{},未启用提前预约流程", scenic.getName());
|
||||
continue;
|
||||
}
|
||||
log.info("当前景区{},启用了提前预约流程", scenic.getName());
|
||||
TemplateReqQuery templateQuery = new TemplateReqQuery();
|
||||
templateQuery.setScenicId(scenic.getId());
|
||||
List<TemplateRespVO> templateList = templateMapper.list(templateQuery);
|
||||
for (TemplateRespVO template : templateList) {
|
||||
log.info("当前景区{},启用了提前预约流程,模板:{}", scenic.getName(), template.getName());
|
||||
if (template.getStatus() == 0) {
|
||||
log.info("当前模板{}未启用,跳过", template.getName());
|
||||
continue;
|
||||
}
|
||||
TemplateConfigEntity templateConfig = templateMapper.getConfig(template.getId());
|
||||
if (templateConfig == null) {
|
||||
log.info("当前模板{}未配置,跳过", template.getName());
|
||||
continue;
|
||||
}
|
||||
if (templateConfig.getIsDefault() == 0) {
|
||||
if (scenicConfig.getBookRoutine() == 1) {
|
||||
log.info("当前模板{}未启用默认,且景区启用预约流程,跳过", template.getName());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Integer minimalPlaceholderFill = templateConfig.getMinimalPlaceholderFill();
|
||||
List<String> placeholderList = new ArrayList<>();
|
||||
if (minimalPlaceholderFill == null) {
|
||||
minimalPlaceholderFill = 0;
|
||||
}
|
||||
List<TemplateRespVO> subTemplateList = templateMapper.getByPid(template.getId());
|
||||
for (TemplateRespVO subTemplate : subTemplateList) {
|
||||
if (subTemplate.getIsPlaceholder() == 1) {
|
||||
placeholderList.add(subTemplate.getSourceUrl());
|
||||
}
|
||||
}
|
||||
if (minimalPlaceholderFill == 0) {
|
||||
for (TemplateRespVO subTemplate : subTemplateList) {
|
||||
if (subTemplate.getIsPlaceholder() == 1) {
|
||||
minimalPlaceholderFill += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("当前模板{}启用默认,最小占位素材:{}", template.getName(), minimalPlaceholderFill);
|
||||
// 查找人脸样本
|
||||
List<FaceRespVO> list = faceMapper.listByScenicIdAndNotFinished(scenic.getId());
|
||||
for (FaceRespVO face : list) {
|
||||
log.info("当前模板{}启用默认,人脸样本:{}", template.getName(), face.getFaceUrl());
|
||||
if (((new Date()).getTime() - face.getCreateAt().getTime()) > scenicConfig.getMaxJourneyHour() * 3600 * 1000) {
|
||||
log.info("当前人脸样本{}已超过最大游玩{}小时,自动检测人脸", face.getFaceUrl(), scenicConfig.getMaxJourneyHour());
|
||||
List<String> oldMatchedSampleListIds = new ArrayList<>();
|
||||
if (face.getMatchSampleIds() != null) {
|
||||
oldMatchedSampleListIds = Arrays.asList(face.getMatchSampleIds().split(","));
|
||||
}
|
||||
SearchFaceRespVo searchFace = faceService.searchFace(scenic.getId(), face.getId());
|
||||
if (oldMatchedSampleListIds.size() == searchFace.getSampleListIds().size()) {
|
||||
boolean isEqual = true;
|
||||
for (Long sampleId : searchFace.getSampleListIds()) {
|
||||
if (!oldMatchedSampleListIds.contains(sampleId.toString())) {
|
||||
isEqual = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isEqual) {
|
||||
log.info("当前人脸样本{}已超过最大游玩{}小时,但人脸检测结果与上次相同,跳过", face.getFaceUrl(), scenicConfig.getMaxJourneyHour());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
List<FaceSampleRespVO> faceSampleList = faceSampleMapper.listByIds(searchFace.getSampleListIds());
|
||||
int matchedPlaceholder = 0;
|
||||
for (FaceSampleRespVO faceSample : faceSampleList) {
|
||||
if (placeholderList.contains(faceSample.getDeviceId().toString())) {
|
||||
matchedPlaceholder += 1;
|
||||
}
|
||||
}
|
||||
if (matchedPlaceholder >= minimalPlaceholderFill) {
|
||||
log.info("当前人脸样本{}已超过最小占位素材{},自动创建任务", face.getFaceUrl(), minimalPlaceholderFill);
|
||||
taskService.createRenderTask(scenic.getId(), template.getId(), face.getId());
|
||||
faceMapper.finishedJourney(face.getId());
|
||||
} else {
|
||||
log.info("当前人脸样本{}未超过最小占位素材{},未达到自动生成条件", face.getFaceUrl(), minimalPlaceholderFill);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user