You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.7 KiB
Java
106 lines
3.7 KiB
Java
package com.glxp.api.task;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
import com.glxp.api.dao.schedule.ScheduledDao;
|
|
import com.glxp.api.entity.basic.SysWorkplaceQueue;
|
|
import com.glxp.api.entity.collect.*;
|
|
import com.glxp.api.entity.system.ScheduledEntity;
|
|
import com.glxp.api.exception.JsonException;
|
|
import com.glxp.api.req.system.ScheduledRequest;
|
|
import com.glxp.api.service.basic.SysWorkplaceQueueService;
|
|
import com.glxp.api.service.collect.*;
|
|
import com.glxp.api.service.inout.IoSplitCodeService;
|
|
import com.glxp.api.util.IntUtil;
|
|
import com.glxp.api.util.RedisUtil;
|
|
import com.glxp.api.util.redis.RedisDelayedQueue;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
import org.jfree.ui.Spinner;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
|
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
|
import org.springframework.scheduling.support.CronTrigger;
|
|
import org.springframework.stereotype.Component;
|
|
import redis.clients.jedis.resps.Tuple;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.*;
|
|
|
|
@Component
|
|
@EnableScheduling
|
|
@Slf4j
|
|
public class LedClearTask implements SchedulingConfigurer {
|
|
|
|
|
|
@Resource
|
|
RedisUtil redisUtil;
|
|
|
|
@Resource
|
|
private ScheduledDao scheduledDao;
|
|
@Resource
|
|
private RedisDelayedQueue redisDelayedQueue;
|
|
|
|
@Resource
|
|
SysOrderLedService sysOrderLedService;
|
|
|
|
|
|
@Resource
|
|
IoSplitCodeService splitCodeService;
|
|
@Resource
|
|
IoCollectOrderBizService ioCollectOrderBizService;
|
|
@Resource
|
|
SysWorkplaceQueueService sysWorkplaceQueueService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
|
|
scheduledTaskRegistrar.addTriggerTask(() -> process(),
|
|
triggerContext -> {
|
|
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
|
scheduledRequest.setCronName("LedClearTask");
|
|
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
|
|
if (scheduledEntity == null) {
|
|
return null;
|
|
}
|
|
String cron = scheduledEntity.getCron();
|
|
return new CronTrigger(cron).nextExecutionTime(triggerContext);
|
|
});
|
|
}
|
|
|
|
private void process() {
|
|
|
|
long currentTimestamp = System.currentTimeMillis() / 1000; // 当前时间戳(秒)
|
|
|
|
// 获取所有超时的任务 (score <= 当前时间戳)
|
|
List<Tuple> tasksToProcess = redisDelayedQueue.getJedis().zrangeByScoreWithScores("led_queue", "-inf", String.valueOf(currentTimestamp));
|
|
|
|
Iterator<Tuple> iterator = tasksToProcess.iterator();
|
|
while (iterator.hasNext()) {
|
|
Tuple task = iterator.next();
|
|
String values = task.getElement();
|
|
String[] valueList = values.split(";");
|
|
String orderId = valueList[0];
|
|
String mac = valueList[1];
|
|
String bizId = valueList[2];
|
|
SysOrderLed orderLed = sysOrderLedService.getOne(new LambdaQueryWrapper<SysOrderLed>().eq(SysOrderLed::getOrderId, orderId));
|
|
if (orderLed == null){
|
|
redisDelayedQueue.getJedis().zrem("led_queue", orderId + ";" + mac + ";" + bizId);
|
|
return;
|
|
}
|
|
try {
|
|
sysOrderLedService.closeLed(orderId);
|
|
} catch (Exception e) {
|
|
throw new JsonException(e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|