package cn.pluss.platform.controller.component;

import cn.pluss.platform.entity.MerchantOrder;
import cn.pluss.platform.merchantOrder.MerchantOrderService;
import cn.pluss.platform.merchantProfit.MerchantProfitService;
import cn.pluss.platform.realFans.RealFansService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
/**
 * @author SSS
 */
@Slf4j
@Configuration
@ConditionalOnProperty(prefix = "scheduling", name = "enabled", havingValue = "true")
@RabbitListener(queues = "payCallback")
public class PayCallbackConsumer {

    @Resource
    private MerchantProfitService merchantProfitService;

    @Resource
    private MerchantOrderService merchantOrderService;

    @Resource
    private RealFansService realFansService;

    @RabbitHandler
    public void process(String msg) {
        log.info("接受到的消息内容为:{}", msg);
        MerchantOrder order = JSON.parseObject(msg, MerchantOrder.class);
        if(!"1".equals(order.getStatus())){
            return;
        }
        if(!"1".equals(order.getOrderType())){
            //TODO 先将粉丝分润干掉，后面在进行打开
           // realFansService.createFansProfit(order);
        }
        merchantProfitService.createOrderProfitV2(order,"1");
        MerchantOrder update = new MerchantOrder();
        update.setId(order.getId());
        update.setProfitShareMoney(order.getProfitShareMoney());
        update.setFansShareMoney(order.getFansShareMoney());
        merchantOrderService.updateById(update);
    }
}
