package com.cpop.core.listen;

import com.cpop.core.base.table.SysOperationLog;
import com.cpop.core.event.OperationLogEvent;
import com.cpop.core.utils.uuid.IdUtils;
import com.cpop.core.service.CoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author: DB
 * @date: 2022-08-12 10:25
 * @Description:  操作日志监听
 */
@Slf4j
@Component
public class SysOperationLogListen {

    @Autowired
    private CoreService coreService;

    @Async
    @Order
    @EventListener(OperationLogEvent.class)
    public void saveSysOperationLog(OperationLogEvent event) {
        SysOperationLog operationLog = (SysOperationLog) event.getSource();
        // 保存日志
        operationLog.setId(IdUtils.fastSimpleUUID());
        if (coreService.saveOperationLog(operationLog)) {
        }
    }
}
