1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package com.example.unusualsounds.project.vox.task;
- import com.example.unusualsounds.project.vox.config.VideoTaskManager;
- import com.example.unusualsounds.project.vox.entity.VoiceTicketLogs;
- import com.example.unusualsounds.project.vox.service.impl.VoiceTicketLogsServiceImpl;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.cache.annotation.CacheEvict;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 工单定时任务
- * ---
- * 用于应对边缘测网络问题,主要针对定时关闭问题
- * 1. 算法启接口调用后,将工单存入表中
- * 2. 定时查询本地存入的工单,主要侦测当前停止的工单任务是否再运行
- * 3. 只添加算法停接口因网络问题未收到停止的请求
- * 4. 忽略因网络问题未收到启动的请求,所以定时查询是自己表内已经插入的数据
- *
- */
- @Component
- @Slf4j
- public class TicketsTask {
- @Autowired
- private VideoTaskManager videoTaskManager;
- @Autowired
- private VoiceTicketLogsServiceImpl voiceTicketLogsServiceImpl;
- @Value("${vox.video-dir}")
- private String videoDir;
- @Scheduled(cron = "0 */10 * * * ?")
- public void checkStopTickets() {
- List<String> strings = this.stopTickets();
- if (strings != null && strings.size() > 0) {
- strings.forEach(s -> {
- try {
- videoTaskManager.stopTask(s);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- });
- }else {
- log.info("定时停止工单:无");
- }
- }
- /**
- * 停止到时间未停止的工单
- * @return
- */
- public List<String> stopTickets() {
- List<VideoTaskManager.TaskStatus> taskStatuses = videoTaskManager.listTasks();
- if(taskStatuses == null || taskStatuses.size() == 0) return null;
- //openUuid,streamId
- Map<String, String> taskStatusesList = new HashMap<>();
- taskStatuses.forEach(
- task ->{
- taskStatusesList.put(task.getOpenUuid(),task.getStreamId());
- }
- );
- List<VoiceTicketLogs> delTasks = voiceTicketLogsServiceImpl.contrastTasks(taskStatusesList);
- delTasks.forEach(str -> {
- log.info("需要停止的工单:{}",str);
- });
- List<String> collect = delTasks.stream().map(
- task -> {
- return task.getDeviceUuid() + "_" + task.getSkillName();
- })
- .distinct().collect(Collectors.toList());
- return collect;
- }
- }
|