#
vincentlu
2026-03-25 c2ee312636815ef842e8ec6e173ef1fc28d0cb96
#
3个文件已修改
107 ■■■■■ 已修改文件
zy-acs-common/src/main/java/com/zy/acs/common/utils/RedisSupport.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-hk/zy-acs-hk-latent/src/main/java/com/zy/acs/hk/latent/listen/MessageListener.java 57 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/hik/HikOrderPublishService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-common/src/main/java/com/zy/acs/common/utils/RedisSupport.java
@@ -263,6 +263,54 @@
        }
        return value;
    }
    public Object pushStrict(String name, Object value) {
        if(!this.initialize){
            throw new IllegalStateException("redis is not initialized");
        }
        console("push list value",name,value);
        if(value==null){
            throw new IllegalArgumentException("push value can not be null");
        }
        byte[] payload = Serialize.serialize(value);
        if(payload == null){
            throw new IllegalStateException("serialize redis list value failed");
        }
        Jedis jedis = this.getJedis();
        try{
            jedis.rpush(("LIST."+name).getBytes(), payload);
        }catch(Exception ex){
            throw new IllegalStateException("push redis list value failed: " + name, ex);
        }finally{
            if(jedis!=null)
                this.pool.returnResource(jedis);
        }
        return value;
    }
    public Object pushHeadStrict(String name, Object value) {
        if(!this.initialize){
            throw new IllegalStateException("redis is not initialized");
        }
        console("push list head value",name,value);
        if(value==null){
            throw new IllegalArgumentException("push value can not be null");
        }
        byte[] payload = Serialize.serialize(value);
        if(payload == null){
            throw new IllegalStateException("serialize redis list value failed");
        }
        Jedis jedis = this.getJedis();
        try{
            jedis.lpush(("LIST."+name).getBytes(), payload);
        }catch(Exception ex){
            throw new IllegalStateException("push redis list head value failed: " + name, ex);
        }finally{
            if(jedis!=null)
                this.pool.returnResource(jedis);
        }
        return value;
    }
    /**
     * 获取列表头部元素
     * @param <T>
zy-acs-hk/zy-acs-hk-latent/src/main/java/com/zy/acs/hk/latent/listen/MessageListener.java
@@ -2,12 +2,15 @@
import com.alibaba.fastjson.JSON;
import com.zy.acs.common.constant.RedisConstant;
import com.zy.acs.common.domain.AgvProtocol;
import com.zy.acs.common.hk.order.HkOrderDown;
import com.zy.acs.common.hk.order.HkOrderMessage;
import com.zy.acs.common.utils.RedisSupport;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.hk.latent.mqtt.publisher.HkOrderPublisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
@@ -24,16 +27,32 @@
    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
    private final static Logger log = LoggerFactory.getLogger(MessageListener.class);
    @Autowired
    private HkOrderPublisher hkOrderPublisher;
    @PostConstruct
    private void start(){
        thread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                AgvProtocol protocol = redis.pop(RedisConstant.AGV_PATH_DOWN_FLAG);
                if (null != protocol) {
                    log.info("监听器 >>> {}", JSON.toJSONString(protocol));
                    if (!Cools.isEmpty(protocol.getAgvNo())) {
//                        publisher.publish(ProtocolUtils.installDownProtocol(protocol));
                HkOrderDown orderDown = redis.pop(RedisConstant.HK_AGV_PATH_DOWN_FLAG);
                if (orderDown != null) {
                    try {
                        log.info("监听器 >>> {}", JSON.toJSONString(orderDown));
                        HkOrderMessage orderMessage = normalize(orderDown);
                        if (orderMessage == null) {
                            log.error("drop invalid hk order message, payload={}", JSON.toJSONString(orderDown));
                        } else {
                            hkOrderPublisher.publish(orderMessage);
                        }
                    } catch (IllegalArgumentException e) {
                        log.error("drop illegal hk order message, payload={}", JSON.toJSONString(orderDown), e);
                    } catch (Exception e) {
                        log.error("publish hk order failed, requeue to head payload={}", JSON.toJSONString(orderDown), e);
                        try {
                            redis.pushHeadStrict(RedisConstant.HK_AGV_PATH_DOWN_FLAG, orderDown);
                        } catch (Exception pushEx) {
                            log.error("requeue hk order failed, payload={}", JSON.toJSONString(orderDown), pushEx);
                        }
                    }
                }
                // 间隔
@@ -50,4 +69,28 @@
        if (thread != null) thread.interrupt();
    }
    private HkOrderMessage normalize(HkOrderDown orderDown) {
        if (orderDown == null || orderDown.getOrderMessage() == null) {
            return null;
        }
        HkOrderMessage orderMessage = orderDown.getOrderMessage();
        if (!StringUtils.hasText(orderMessage.getSerialNumber()) && StringUtils.hasText(orderDown.getAgvNo())) {
            orderMessage.setSerialNumber(orderDown.getAgvNo());
        }
        if (!StringUtils.hasText(orderMessage.getOrderId()) && StringUtils.hasText(orderDown.getActionGroupId())) {
            orderMessage.setOrderId(orderDown.getActionGroupId());
        }
        if (!StringUtils.hasText(orderMessage.getSerialNumber())) {
            return null;
        }
        if (!StringUtils.hasText(orderMessage.getOrderId())) {
            return null;
        }
        if (orderMessage.getOrderUpdateId() == null) {
            orderMessage.setOrderUpdateId(0L);
        }
        return orderMessage;
    }
}
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/hik/HikOrderPublishService.java
@@ -58,7 +58,7 @@
        orderDown.setAgvNo(agvNo);
        orderDown.setActionGroupId(actionGroupId);
        orderDown.setOrderMessage(orderMessage);
        redis.push(RedisConstant.HK_AGV_PATH_DOWN_FLAG, orderDown);
        redis.pushStrict(RedisConstant.HK_AGV_PATH_DOWN_FLAG, orderDown);
        log.info("push hik order to redis, agvNo={}, actionGroupId={}, nodeCount={}, edgeCount={}, redisKey={}",
                agvNo,
                actionGroupId,