/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.seckill.comment.listener;


import com.yami.shop.bean.enums.OrderType;
import com.yami.shop.bean.event.CancelOrderEvent;
import com.yami.shop.bean.order.CancelOrderOrder;
import com.yami.shop.seckill.comment.service.SeckillOrderService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 取消订单事件
 */
@Component("seckillCancelOrderListener")
@AllArgsConstructor
public class CancelOrderListener {


    private final SeckillOrderService seckillOrderService;

    @EventListener(CancelOrderEvent.class)
    @Order(CancelOrderOrder.SECKILL)
    public void seckillCancelOrderEventListener(CancelOrderEvent event) {
        String orderNumber = event.getOrder().getOrderNumber();
        // 不是秒杀订单直接返回
        if (!OrderType.SECKILL.value().equals(event.getOrder().getOrderType())) {
            return;
        }

        seckillOrderService.cancelUnpayOrderByOrderNumber(orderNumber);
    }

}
