1/21 灯组逻辑优化 1.0
parent
1a3bd7085e
commit
d6b9404eed
@ -0,0 +1,17 @@
|
|||||||
|
package com.glxp.api.dao.collect;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.glxp.api.entity.collect.SysOrderLed;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : zhuzhu
|
||||||
|
* @date : 2025/1/20 14:25
|
||||||
|
* @modyified By :
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysOrderLedMapper extends BaseMapper<SysOrderLed> {
|
||||||
|
|
||||||
|
|
||||||
|
void updateSetOrderId(Integer id);
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.glxp.api.service.collect;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.glxp.api.dao.collect.IoCollectLedGroupMapper;
|
||||||
|
import com.glxp.api.dao.collect.SysOrderLedMapper;
|
||||||
|
import com.glxp.api.entity.basic.SysWorkplaceQueue;
|
||||||
|
import com.glxp.api.entity.collect.IoCollectOrderBiz;
|
||||||
|
import com.glxp.api.entity.collect.SysOrderLed;
|
||||||
|
import com.glxp.api.service.basic.SysWorkplaceQueueService;
|
||||||
|
import com.glxp.api.service.inout.IoSplitCodeService;
|
||||||
|
import com.glxp.api.util.redis.RedisDelayedQueue;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : zhuzhu
|
||||||
|
* @date : 2025/1/20 14:23
|
||||||
|
* @modyified By :
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SysOrderLedService extends ServiceImpl<SysOrderLedMapper, SysOrderLed> {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
SysOrderLedMapper sysOrderLedMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
IoCollectOrderBizService ioCollectOrderBizService;
|
||||||
|
@Resource
|
||||||
|
SysWorkplaceQueueService sysWorkplaceQueueService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
IoSplitCodeService splitCodeService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisDelayedQueue redisDelayedQueue;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void updateSetOrderId(Integer id) {
|
||||||
|
sysOrderLedMapper.updateSetOrderId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeLed(String orderId) {
|
||||||
|
String task = redisDelayedQueue.getTaskByOrderId("led_queue", orderId);
|
||||||
|
String[] valueList = task.split(";");
|
||||||
|
String mac = valueList[1];
|
||||||
|
String bizId = valueList[2];
|
||||||
|
SysOrderLed orderLed = getOne(new LambdaQueryWrapper<SysOrderLed>().eq(SysOrderLed::getOrderId, orderId));
|
||||||
|
updateSetOrderId(orderLed.getId());
|
||||||
|
SysWorkplaceQueue sysWorkplaceQueue = sysWorkplaceQueueService.getOne(new LambdaQueryWrapper<SysWorkplaceQueue>().eq(SysWorkplaceQueue::getMac, mac));
|
||||||
|
IoCollectOrderBiz collectOrderBiz = ioCollectOrderBizService.getById(bizId);
|
||||||
|
splitCodeService.confirmBizAutiTagCode(collectOrderBiz, sysWorkplaceQueue.getCode(), null, true);
|
||||||
|
// 从队列中删除已执行的任务genjv
|
||||||
|
redisDelayedQueue.getJedis().zrem("led_queue", orderId + ";" + mac + ";" + bizId);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.glxp.api.dao.collect.SysOrderLedMapper">
|
||||||
|
|
||||||
|
<update id="updateSetOrderId">
|
||||||
|
UPDATE sys_order_led
|
||||||
|
SET orderId = null
|
||||||
|
WHERE id = #{id}
|
||||||
|
</update>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue