KKSU
2025-02-12 1bb96bab1185f2e1aa2f468266512ee0beb83286
src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java
@@ -1,17 +1,13 @@
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.rabbit.constants.QueueConstants;
import cc.mrbird.febs.rabbit.enumerates.RabbitQueueEnum;
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.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
 * @author wzy
@@ -19,44 +15,62 @@
 **/
@Slf4j
@Component
@ConditionalOnProperty(prefix = "consumer", name = "open", havingValue = "true")
public class AgentConsumer {
    @Autowired
    private IApiMallOrderInfoService orderInfoService;
    @Autowired
    private IAgentService agentService;
    @RabbitListener(queues = QueueConstants.QUEUE_DEFAULT)
    public void agentReturn(Message message, Channel channel) {
        log.info("消费者:{}", new String(message.getBody()));
    }
    @RabbitListener(queues = "queue_order_delay")
    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));
    /**
     * 充值成功
     */
    @RabbitListener(queues = QueueConstants.RUN_VIP_OPERATION_CHARGE_BALANCE)
    public void chargeSuccessMsg(Long chargeId) {
        try {
            agentService.chargeSuccessMsg(chargeId);
        } catch (Exception e) {
            log.error("返利异常", e);
            log.error("消费充值异常", e);
        }
    }
    /**
     * 节点升级
     */
    @RabbitListener(queues = QueueConstants.RUN_VIP_NODE_UP)
    public void nodeUpMsg(Long memberId) {
        try {
            agentService.nodeUpMsg(memberId);
        } catch (Exception e) {
            log.error("消费节点升级异常", e);
        }
    }
}