package com.tmzn.devicelinkykc.taskQueue; import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg; import com.tmzn.devicelinkykc.socket.SocketHandle; import com.tmzn.devicelinkykc.taskQueue.queue.MsgCharngingQueue; import com.tmzn.devicelinkykc.taskQueue.queue.MsgFreeQueue; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Map; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; /** * @author xp * @date 2024/3/15 * @explain " 设备状态推送任务 " */ @Component public class DeviceStatusPushTask { @Autowired private MsgCharngingQueue msgCharngingQueue; @Autowired private MsgFreeQueue msgFreeQueue; @Autowired private SocketHandle socketHandle; /** * 充电中任务状态 */ public void chargingStatus(){ ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(1); Runnable task = new Runnable() { @Override public void run() { Map deviceConnectionMsgMap = socketHandle.getDeviceConnectionMsgMap(); msgCharngingQueue.add(deviceConnectionMsgMap); } }; scheduler.scheduleAtFixedRate(task,0,15*1000, TimeUnit.MILLISECONDS); } /** * 空闲状态上送 */ public void freeStatus(){ ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(1); Runnable task = new Runnable() { @Override public void run() { Map deviceConnectionMsgMap = socketHandle.getDeviceConnectionMsgMap(); msgFreeQueue.add(deviceConnectionMsgMap); } }; scheduler.scheduleAtFixedRate(task,100,3*60*1000, TimeUnit.MILLISECONDS); } }