| | |
| | | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | // 间隔 |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |