KKSU
2024-12-17 288e2a2ca2e7c2f7158507174a42f8a417380d23
src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java
@@ -1,19 +1,12 @@
package cc.mrbird.febs.rabbit.consumer;
import cc.mrbird.febs.mall.dto.ApiMemberChargeFailDto;
import cc.mrbird.febs.mall.service.IAgentService;
import cc.mrbird.febs.mall.service.IApiMallOrderInfoService;
import cc.mrbird.febs.mall.service.IMemberProfitService;
import cc.mrbird.febs.rabbit.constants.QueueConstants;
import cc.mrbird.febs.rabbit.enumerates.RabbitQueueEnum;
import cc.mrbird.febs.vip.service.IVipCommonService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
 * @author wzy
@@ -22,88 +15,34 @@
@Slf4j
@Component
public class AgentConsumer {
    @Autowired
    private IApiMallOrderInfoService orderInfoService;
    @Autowired
    private IAgentService agentService;
    @Autowired
    private IMemberProfitService memberProfitService;
    @RabbitListener(queues = QueueConstants.QUEUE_DEFAULT)
    public void agentReturn(Message message, Channel channel) {
        log.info("消费者:{}", new String(message.getBody()));
    }
    @RabbitListener(queues = "queue_order_delay_qay")
    public void orderCancelDelay(String id) {
    /**
     * 充值自动过期
     * @param apiMemberChargeFailDto
     */
    @RabbitListener(queues = QueueConstants.RUN_VIP_OPERATION_CHARGE_FAIL)
    public void memberChargeFailMsg(ApiMemberChargeFailDto apiMemberChargeFailDto) {
        try {
            orderInfoService.autoCancelOrder(Long.parseLong(id));
            agentService.sendMemberChargeFailMsg(apiMemberChargeFailDto);
        } catch (Exception e) {
            log.error("订单超时支付异常", e);
            log.error("消费充值自动过期异常", e);
        }
    }
    @RabbitListener(queues = QueueConstants.AGENT_AUTO_LEVEL_UP)
    public void agentAutoLevelUp(String id) {
        log.info("收到代理自动升级消息:{}", id);
    /**
     * 购买成功
     */
    @RabbitListener(queues = QueueConstants.RUN_VIP_OPERATION_CHARGE)
    public void buyVipSuccessMsg(Long chargeId) {
        try {
            agentService.autoUpAgentLevel(Long.parseLong(id));
            agentService.buyVipSuccessMsg(chargeId);
        } catch (Exception e) {
            log.error("代理自动升级异常", e);
            log.error("消费购买成功异常", e);
        }
    }
    @RabbitListener(queues = QueueConstants.AGENT_RETURN_MONEY)
    public void agentReturnMoney(String orderId) {
        log.info("收到返利消息:{}", orderId);
        try {
            agentService.returnMoneyToAgent(Long.parseLong(orderId));
        } catch (Exception e) {
            log.error("返利异常", e);
        }
    }
    @RabbitListener(queues = QueueConstants.ORDER_RETURN_MONEY)
    public void orderReturnMoney(String orderId) {
        log.info("收到订单返利消息:{}", orderId);
        try {
            memberProfitService.dynamicProfit(Long.parseLong(orderId));
        } catch (Exception e) {
            log.error("订单返利异常:", e);
        }
    }
    @RabbitListener(queues = QueueConstants.ORDER_COUPON)
    public void getOrderCoupon(Long orderId) {
        log.info("收到使用优惠卷消息:{}", orderId);
        try {
            memberProfitService.getOrderCoupon(orderId);
        } catch (Exception e) {
            log.error("使用优惠卷异常:", e);
        }
    }
    @Autowired
    private IVipCommonService vipCommonService;
    @RabbitListener(queues = QueueConstants.GET_SCORE_MSG)
    public void getScoreMsg(Long orderId) {
        log.info("收到积分消息:{}", orderId);
        try {
            vipCommonService.getScore(orderId);
        } catch (Exception e) {
            log.error("获取积分消息异常", e);
        }
    }
    @RabbitListener(queues = QueueConstants.VIP_LEVEL_UP)
    public void vipLevelUp(Long orderId) {
        log.info("收到会员升级消息:{}", orderId);
        try {
            vipCommonService.levelUp(orderId);
        } catch (Exception e) {
            log.error("会员升级消息异常", e);
        }
    }
}