指定设备提前预约

This commit is contained in:
2025-02-05 14:31:31 +08:00
parent 1eb636d402
commit a016622cc9
27 changed files with 471 additions and 103 deletions

View File

@ -90,7 +90,7 @@ public class DynamicTaskGenerator {
queue.add(new Task(faceSampleId, createTime));
}
@Scheduled(fixedDelay = 500L)
@Scheduled(fixedDelay = 1000L)
public void doTask() {
Task task = queue.poll();
if (task == null) {
@ -111,7 +111,7 @@ public class DynamicTaskGenerator {
log.debug("当前景区{},无配置", faceSample.getScenicId());
return;
}
if (!Integer.valueOf(1).equals(scenicConfig.getBookRoutine()) && !Integer.valueOf(3).equals(scenicConfig.getBookRoutine())) {
if (!Integer.valueOf(5).equals(scenicConfig.getBookRoutine())) {
log.debug("当前景区{}未启用预约流程,跳过", faceSample.getScenicId());
return;
}

View File

@ -3,10 +3,15 @@ package com.ycwl.basic.task;
import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.mapper.ScenicMapper;
import com.ycwl.basic.mapper.SourceMapper;
import com.ycwl.basic.mapper.VideoMapper;
import com.ycwl.basic.model.pc.faceSample.req.FaceSampleReqQuery;
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.video.req.VideoReqQuery;
import com.ycwl.basic.model.pc.video.resp.VideoRespVO;
import com.ycwl.basic.repository.ScenicRepository;
import com.ycwl.basic.service.task.TaskFaceService;
import com.ycwl.basic.storage.StorageFactory;
import com.ycwl.basic.storage.adapters.IStorageAdapter;
@ -31,6 +36,10 @@ public class FaceCleaner {
private FaceSampleMapper faceSampleMapper;
@Autowired
private SourceMapper sourceMapper;
@Autowired
private VideoMapper videoMapper;
@Autowired
private ScenicRepository scenicRepository;
@Scheduled(cron = "0 0 4 * * ?")
public void clean(){
@ -44,11 +53,43 @@ public class FaceCleaner {
@Scheduled(cron = "0 0 3 * * ?")
public void deleteExpiredSource(){
ScenicReqQuery scenicQuery = new ScenicReqQuery();
List<ScenicRespVO> scenicList = scenicMapper.list(scenicQuery);
scenicList.parallelStream().forEach(scenic -> {
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenic.getId());
if (scenicConfig == null) {
log.info("当前景区{},无配置信息", scenic.getName());
return;
}
int imageSourceExpireDay = 7;
int videoSourceExpireDay = 7;
if (scenicConfig.getImageSourceStoreDay() != null) {
imageSourceExpireDay = scenicConfig.getImageSourceStoreDay();
} else {
log.info("当前景区{}原始素材保存天数未设置默认7天", scenic.getName());
}
if (scenicConfig.getVideoSourceStoreDay() != null) {
videoSourceExpireDay = scenicConfig.getVideoSourceStoreDay();
} else {
log.info("当前景区{}原始素材保存天数未设置默认7天", scenic.getName());
}
if (Integer.valueOf(1).equals(scenicConfig.getDisableSourceVideo())) {
return;
}
if (Integer.valueOf(1).equals(scenicConfig.getDisableSourceImage())) {
return;
}
log.info("当前景区{},开始删除原始素材", scenic.getName());
});
}
@Scheduled(cron = "0 0 5 * * ?")
public void clear(){
public void clearOss(){
cleanFaceSampleOss();
cleanSourceOss();
cleanVideoOss();
}
private void cleanFaceSampleOss() {
log.info("开始清理人脸文件");
List<FaceSampleRespVO> faceSampleRespVOS = faceSampleMapper.list(new FaceSampleReqQuery());
IStorageAdapter adapter = StorageFactory.use("faces");
@ -60,4 +101,20 @@ public class FaceCleaner {
}
});
}
private void cleanSourceOss() {
}
private void cleanVideoOss() {
log.info("开始清理视频文件");
List<VideoRespVO> videoRespVOS = videoMapper.list(new VideoReqQuery());
IStorageAdapter adapter = StorageFactory.use("video");
List<StorageFileObject> fileObjectList = adapter.listDir("");
fileObjectList.parallelStream().forEach(fileObject -> {
if (videoRespVOS.parallelStream().noneMatch(videoRespVO -> videoRespVO.getVideoUrl().contains(fileObject.getFullPath()))){
log.info("删除视频文件:{}", fileObject);
adapter.deleteFile(fileObject.getFullPath());
} else {
log.info("视频文件存在关系:{},未删除", fileObject);
}
});
}
}

View File

@ -1,18 +1,17 @@
package com.ycwl.basic.task;
import com.ycwl.basic.biz.OrderBiz;
import com.ycwl.basic.biz.TaskStatusBiz;
import com.ycwl.basic.device.DeviceFactory;
import com.ycwl.basic.device.entity.common.FileObject;
import com.ycwl.basic.device.operator.IDeviceStorageOperator;
import com.ycwl.basic.model.pc.faceSample.entity.FaceSampleEntity;
import com.ycwl.basic.repository.DeviceRepository;
import com.ycwl.basic.mapper.DeviceMapper;
import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.mapper.SourceMapper;
import com.ycwl.basic.model.mobile.order.IsBuyRespVO;
import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity;
import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
import com.ycwl.basic.model.pc.faceSample.resp.FaceSampleRespVO;
import com.ycwl.basic.model.pc.source.entity.MemberSourceEntity;
import com.ycwl.basic.model.pc.source.entity.SourceEntity;
import com.ycwl.basic.repository.TemplateRepository;
@ -34,7 +33,6 @@ import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
@ -57,6 +55,8 @@ public class VideoPieceGetter {
private OrderBiz orderBiz;
@Autowired
private TemplateRepository templateRepository;
@Autowired
private TaskStatusBiz taskStatusBiz;
@Data
public static class Task {
@ -97,6 +97,9 @@ public class VideoPieceGetter {
} else {
templatePlaceholder = null;
}
if (task.faceId != null) {
taskStatusBiz.setFaceCutStatus(task.faceId, 0);
}
AtomicBoolean invoke = new AtomicBoolean(false);
List<String> currentPlaceholder = new ArrayList<>();
List<FaceSampleEntity> list = faceSampleMapper.listByIds(task.getFaceSampleIds());
@ -113,7 +116,7 @@ public class VideoPieceGetter {
.stream()
.parallel()
.forEach(faceSampleList -> {
faceSampleList.forEach(faceSample -> {
faceSampleList.parallelStream().forEach(faceSample -> {
DeviceEntity device = deviceRepository.getDevice(faceSample.getDeviceId());
DeviceConfigEntity config = deviceRepository.getDeviceConfig(faceSample.getDeviceId());
@ -245,6 +248,9 @@ public class VideoPieceGetter {
}
});
});
if (task.faceId != null) {
taskStatusBiz.setFaceCutStatus(task.faceId, 1);
}
if (null != task.getCallback()) {
if (!invoke.get()) {
invoke.set(true);

View File

@ -4,10 +4,14 @@ import cn.hutool.core.date.DateUtil;
import com.ycwl.basic.biz.TemplateBiz;
import com.ycwl.basic.mapper.FaceMapper;
import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.mapper.ScenicMapper;
import com.ycwl.basic.mapper.TemplateMapper;
import com.ycwl.basic.model.mobile.scenic.content.ContentPageVO;
import com.ycwl.basic.model.pc.face.req.FaceReqQuery;
import com.ycwl.basic.model.pc.face.resp.FaceRespVO;
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.task.resp.SearchFaceRespVo;
import com.ycwl.basic.repository.ScenicRepository;
import com.ycwl.basic.repository.TemplateRepository;
@ -20,6 +24,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@ -38,31 +43,71 @@ public class VideoTaskGenerator {
private TaskTaskServiceImpl taskTaskService;
@Autowired
private TemplateMapper templateMapper;
@Autowired
private ScenicMapper scenicMapper;
@Autowired
private ScenicRepository scenicRepository;
// TODO: 可配置,现在赶时间暂时写死
@Scheduled(cron = "0 0 18 * * *")
@Scheduled(cron = "0 0 * * * *")
public void generateVideoTask() {
// 指定,获取指定日期的未完成人脸样本,并生成任务
Long scenicId = 3946669713328836608L;
List<ContentPageVO> contentList = templateMapper.listFor(scenicId);
if (contentList.isEmpty()) {
List<ScenicRespVO> scenicList = scenicMapper.list(new ScenicReqQuery());
if (scenicList.isEmpty()) {
return;
}
Long templateId = contentList.get(0).getTemplateId();
FaceReqQuery query = new FaceReqQuery();
query.setScenicId(scenicId);
query.setStartTime(DateUtil.beginOfDay(new Date()));
query.setEndTime(DateUtil.endOfDay(new Date()));
List<FaceRespVO> list = faceMapper.list(query);
list.stream().parallel().forEach(face -> {
taskFaceService.searchFace(face.getId());
boolean canAutoGenerate = templateBiz.determineTemplateCanAutoGenerate(templateId, face.getId(), false);
if (canAutoGenerate) {
log.info("task callback: 自动生成");
taskTaskService.forceCreateTaskByFaceIdAndTempalteId(face.getId(), templateId);
} else {
log.info("task callback: 不自动生成");
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
calendar.clear();
scenicList.parallelStream().forEach(scenic -> {
Long scenicId = scenic.getId();
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
if (scenicConfig == null) {
log.info("当前景区{},无配置信息", scenic.getName());
return;
}
if (Integer.valueOf(1).equals(scenicConfig.getBookRoutine()) || Integer.valueOf(3).equals(scenicConfig.getBookRoutine())) {
Integer hour = scenicConfig.getForceFinishTime();
if (hour != currentHour) {
return;
}
// 定时逻辑
List<ContentPageVO> contentList = templateMapper.listFor(scenicId);
if (contentList.isEmpty()) {
return;
}
FaceReqQuery query = new FaceReqQuery();
query.setScenicId(scenicId);
query.setStartTime(DateUtil.beginOfDay(new Date()));
query.setEndTime(DateUtil.endOfDay(new Date()));
List<FaceRespVO> list = faceMapper.list(query);
list.stream().parallel().forEach(face -> {
taskFaceService.searchFace(face.getId());
if (Integer.valueOf(3).equals(scenicConfig.getBookRoutine())) {
// 全部生成
contentList.forEach(content -> {
Long templateId = content.getTemplateId();
boolean canAutoGenerate = templateBiz.determineTemplateCanAutoGenerate(templateId, face.getId(), false);
if (canAutoGenerate) {
log.info("task callback: 自动生成");
taskTaskService.forceCreateTaskByFaceIdAndTempalteId(face.getId(), templateId);
} else {
log.info("task callback: 不自动生成");
}
});
} else {
Long templateId = contentList.get(0).getTemplateId();
boolean canAutoGenerate = templateBiz.determineTemplateCanAutoGenerate(templateId, face.getId(), false);
if (canAutoGenerate) {
log.info("task callback: 自动生成");
taskTaskService.forceCreateTaskByFaceIdAndTempalteId(face.getId(), templateId);
} else {
log.info("task callback: 不自动生成");
}
}
});
}
});
}