package com.hfkj.consumer;

import com.hfkj.entity.BsOrder;
import com.hfkj.model.order.OrderModel;
import com.hfkj.service.order.BsOrderService;
import com.hfkj.sysenum.order.OrderStatusEnum;
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<OrderModel> {

    @Resource
    private BsOrderService orderService;

    @Override
    public void onMessage(OrderModel order) {
        // 查询订单
        BsOrder bsOrder = orderService.getOrder(order.getOrderNo());
        if (bsOrder != null && bsOrder.getOrderStatus().equals(OrderStatusEnum.status1.getCode())) {
            // 取消订单
            orderService.cancel(order.getOrderNo());
        }
    }
}
