
package com.tmerclub.cloud.order.listener;

import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import com.tmerclub.cloud.common.util.Json;
import com.tmerclub.cloud.order.model.Order;
import com.tmerclub.cloud.order.service.OrderService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 商家余额支付成功，订单采购完成
 *
 * @author tmerclub
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.SHOP_BALANCE_PAY_SUCCESS_TOPIC, consumerGroup = RocketMqConstant.SHOP_BALANCE_PAY_SUCCESS_TOPIC)
public class OrderPurchaseFinishConsumer implements RocketMQListener<Long> {

    private static final Logger LOG = LoggerFactory.getLogger(OrderPurchaseFinishConsumer.class);

    @Autowired
    private OrderService orderService;

    /**
     * 修改订单为待采购状态
     */
    @Override
    public void onMessage(Long orderId) {
        if (Objects.isNull(orderId)) {
            return;
        }
        LOG.info("商家余额支付成功，修改订单为采购完成状态... message: {}", Json.toJsonString(orderId));
        Order order = new Order();
        order.setOrderId(orderId);
        // 修改订单的采购状态
        orderService.sourcingOrder(order);
    }
}
