
package com.tmerclub.cloud.multishop.listener;

import com.tmerclub.cloud.api.multishop.bo.OrderChangeShopWalletAmountBO;
import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import com.tmerclub.cloud.multishop.service.ShopWalletService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author tmerclub
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.ORDER_SETTLED_SHOP_TOPIC, consumerGroup = RocketMqConstant.ORDER_SETTLED_SHOP_TOPIC)
public class OrderReceiptShopConsumer implements RocketMQListener<List<OrderChangeShopWalletAmountBO>> {

    @Autowired
    private ShopWalletService shopWalletService;

    /**
     * 结束周期完成，结算给商家
     */
    @Override
    public void onMessage(List<OrderChangeShopWalletAmountBO> changeShopWalletAmountList) {
        for (OrderChangeShopWalletAmountBO orderChangeShopWalletAmountBO : changeShopWalletAmountList) {
            shopWalletService.addAmountBySettledOrder(orderChangeShopWalletAmountBO);
        }
    }
}
