package com.web.rocketmq.consumer;

import com.hai.entity.HighOrder;
import com.hai.order.service.OrderService;
import com.hai.order.type.OrderStatus;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "order-cancel-group", topic = "order-topic",selectorExpression = "cancel")
public class OrderCancelConsumer implements RocketMQListener<HighOrder> {

    @Resource
    private OrderService orderService;

    @Override
    public void onMessage(HighOrder order) {
        HighOrder highOrder = orderService.getOrderDetailByNo(order.getOrderNo());
        if (highOrder != null && highOrder.getOrderStatus().equals(OrderStatus.STATUS1.getNumber())) {
            // 取消订单
            orderService.cancelOrder(order.getOrderNo(), null);
        }
    }
}
