/*
 * Copyright (c) 2023 codvision.com All Rights Reserved.
 */

package com.codvision.monitor.task;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.codvision.logcore.aop.SysLogAspect;
import com.codvision.logcore.bean.SysLogMessage;
import com.codvision.monitor.entity.SysLog;
import com.codvision.monitor.service.ISysLogService;
import com.codvision.mqcore.annotation.MQHandler;
import com.codvision.mqcore.annotation.MQListener;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

/**
 * 关闭订单消费者
 */
@Slf4j
@MQHandler
public class SysLogMQTask {


    @Resource
    private ISysLogService sysLogService;

    @MQListener(queues = SysLogAspect.SYS_LOG_QUEUE_NAME)
    public void sysLogListener(SysLogMessage sysLogMessage) {
        log.info("接收系统操作日志");
        if (ObjectUtil.isNotEmpty(sysLogMessage)) {
            SysLog sysLog = BeanUtil.toBean(sysLogMessage, SysLog.class);
            sysLogService.save(sysLog);
        }
    }
}
