package com.luojia_channel.modules.feedback.mq.consumer;

import com.luojia_channel.modules.feedback.config.FeedbackRabbitMQConfig;
import com.luojia_channel.modules.feedback.entity.FeedbackTicket;
import com.luojia_channel.modules.feedback.service.FeedbackTicketService;
import com.luojia_channel.modules.message.mq.MessageWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


@Slf4j
@Component
@RequiredArgsConstructor
public class FeedbackMessageConsumer {

    private final FeedbackTicketService feedbackTicketService;

    @RabbitListener(queues = FeedbackRabbitMQConfig.FEEDBACK_DLX_QUEUE)
    public void handleFeedbackMessage(MessageWrapper<FeedbackTicket> wrapper) {
        try {
            FeedbackTicket ticket = wrapper.getMessage();
            log.info("收到反馈工单延时消息，工单ID：{}", ticket.getId());

            // 处理延时任务，更新工单状态
            feedbackTicketService.processDelayedFeedback(ticket.getId());

        } catch (Exception e) {
            log.error("处理反馈工单延时消息失败，消息ID：{}", wrapper.getUuid(), e);
            throw e;
        }
    }
}
