| 
														
															@@ -11,6 +11,7 @@ import com.ym.mec.im.message.TicketExpiredMessage; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import com.ym.pojo.ScheduledTaskInfo; 
														 | 
														
														 | 
														
															 import com.ym.pojo.ScheduledTaskInfo; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import com.ym.service.RoomService; 
														 | 
														
														 | 
														
															 import com.ym.service.RoomService; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import lombok.extern.slf4j.Slf4j; 
														 | 
														
														 | 
														
															 import lombok.extern.slf4j.Slf4j; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+import org.redisson.api.RedissonClient; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import org.springframework.beans.factory.annotation.Autowired; 
														 | 
														
														 | 
														
															 import org.springframework.beans.factory.annotation.Autowired; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import org.springframework.scheduling.annotation.SchedulingConfigurer; 
														 | 
														
														 | 
														
															 import org.springframework.scheduling.annotation.SchedulingConfigurer; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import org.springframework.scheduling.config.ScheduledTask; 
														 | 
														
														 | 
														
															 import org.springframework.scheduling.config.ScheduledTask; 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -28,26 +29,22 @@ import java.util.concurrent.ConcurrentHashMap; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 @Service 
														 | 
														
														 | 
														
															 @Service 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 public class ScheduleManager implements SchedulingConfigurer { 
														 | 
														
														 | 
														
															 public class ScheduleManager implements SchedulingConfigurer { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     private ScheduledTaskRegistrar taskRegistrar; 
														 | 
														
														 | 
														
															     private ScheduledTaskRegistrar taskRegistrar; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     @Autowired 
														 | 
														
														 | 
														
															     @Autowired 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     RoomProperties roomProperties; 
														 | 
														
														 | 
														
															     RoomProperties roomProperties; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     @Autowired 
														 | 
														
														 | 
														
															     @Autowired 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     WhiteBoardProperties whiteBoardProperties; 
														 | 
														
														 | 
														
															     WhiteBoardProperties whiteBoardProperties; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     @Autowired 
														 | 
														
														 | 
														
															     @Autowired 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     IMHelper imHelper; 
														 | 
														
														 | 
														
															     IMHelper imHelper; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     @Autowired 
														 | 
														
														 | 
														
															     @Autowired 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     RoomMemberDao roomMemberDao; 
														 | 
														
														 | 
														
															     RoomMemberDao roomMemberDao; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     @Autowired 
														 | 
														
														 | 
														
															     @Autowired 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     RoomDao roomDao; 
														 | 
														
														 | 
														
															     RoomDao roomDao; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     @Autowired 
														 | 
														
														 | 
														
															     @Autowired 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     RoomService roomService; 
														 | 
														
														 | 
														
															     RoomService roomService; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    @Autowired 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    RedissonClient redissonClient; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    private ConcurrentHashMap<String, ScheduledTask> schedulingTasks = new ConcurrentHashMap<>(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//    private ConcurrentHashMap<String, ScheduledTask> schedulingTasks = new ConcurrentHashMap<>(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     private ConcurrentHashMap<String, ScheduledTask> roomCacheTasks = new ConcurrentHashMap<>(); 
														 | 
														
														 | 
														
															     private ConcurrentHashMap<String, ScheduledTask> roomCacheTasks = new ConcurrentHashMap<>(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     private ConcurrentHashMap<String, Date> userIMOfflineMap = new ConcurrentHashMap<>(); 
														 | 
														
														 | 
														
															     private ConcurrentHashMap<String, Date> userIMOfflineMap = new ConcurrentHashMap<>(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     private ScheduledDelayTask userIMOfflineKickTask = new ScheduledDelayTask(new Runnable() { 
														 | 
														
														 | 
														
															     private ScheduledDelayTask userIMOfflineKickTask = new ScheduledDelayTask(new Runnable() { 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -95,35 +92,38 @@ public class ScheduleManager implements SchedulingConfigurer { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															     public void addTask(ScheduledTaskInfo task) { 
														 | 
														
														 | 
														
															     public void addTask(ScheduledTaskInfo task) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         log.info("add speech task: {}", task); 
														 | 
														
														 | 
														
															         log.info("add speech task: {}", task); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        schedulingTasks.put(task.getTicket(), taskRegistrar.scheduleFixedDelayTask(new ScheduledDelayTask(new Runnable() { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            @Override 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            public void run() { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                log.info("speech task expired, execute task: {}", task); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                TicketExpiredMessage msg = new TicketExpiredMessage(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                msg.setFromUserId(task.getApplyUserId()); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                msg.setToUserId(task.getTargetUserId()); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                msg.setTicket(task.getTicket()); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                try { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    imHelper.publishMessage(task.getTargetUserId(), task.getRoomId(), msg); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                } catch (Exception e) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    log.error("msg send error: {}", e.getMessage()); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                } 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                ScheduledTask scheduledTask = schedulingTasks.remove(task.getTicket()); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                scheduledTask.cancel(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        redissonClient.getBucket(task.getTicket()).set(task); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        /*ScheduledTask scheduledTask = taskRegistrar.scheduleFixedDelayTask(new ScheduledDelayTask(() -> { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            log.info("speech task expired, execute task: {}", task); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            TicketExpiredMessage msg = new TicketExpiredMessage(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            msg.setFromUserId(task.getApplyUserId()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            msg.setToUserId(task.getTargetUserId()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            msg.setTicket(task.getTicket()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            try { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                imHelper.publishMessage(task.getTargetUserId(), task.getRoomId(), msg); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            } catch (Exception e) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                log.error("msg send error: {}", e.getMessage()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             } 
														 | 
														
														 | 
														
															             } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        }, roomProperties.getTaskTtl() * 60, roomProperties.getTaskTtl(), task))); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            ScheduledTask scheduledTask1 = schedulingTasks.remove(task.getTicket()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            scheduledTask1.cancel(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        }, roomProperties.getTaskTtl() * 60, roomProperties.getTaskTtl(), task));*/ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															     public ScheduledTaskInfo executeTask(String key) { 
														 | 
														
														 | 
														
															     public ScheduledTaskInfo executeTask(String key) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        ScheduledTask scheduledTask = schedulingTasks.remove(key); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        if (scheduledTask == null) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        if (!redissonClient.getBucket(key).isExists()) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             log.error("task not exist: key={}", key); 
														 | 
														
														 | 
														
															             log.error("task not exist: key={}", key); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             throw new ApiException(ErrorEnum.ERR_APPLY_TICKET_INVALID); 
														 | 
														
														 | 
														
															             throw new ApiException(ErrorEnum.ERR_APPLY_TICKET_INVALID); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         } 
														 | 
														
														 | 
														
															         } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        ScheduledDelayTask task = (ScheduledDelayTask)scheduledTask.getTask(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        ScheduledTaskInfo taskInfo = task.getScheduledTaskInfo(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        scheduledTask.cancel(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        log.info("execute speech task: {}", taskInfo); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        return taskInfo; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        return (ScheduledTaskInfo)redissonClient.getBucket(key).get(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//        ScheduledTask scheduledTask = schedulingTasks.remove(key); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//        if (scheduledTask == null) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//            log.error("task not exist: key={}", key); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//            throw new ApiException(ErrorEnum.ERR_APPLY_TICKET_INVALID); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//        } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//        ScheduledDelayTask task = (ScheduledDelayTask)scheduledTask.getTask(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//        ScheduledTaskInfo taskInfo = task.getScheduledTaskInfo(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//        scheduledTask.cancel(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//        log.info("execute speech task: {}", taskInfo); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+//        return taskInfo; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 } 
														 | 
														
														 | 
														
															 } 
														 |