package com.jy.log.listener;

import com.jy.framework.model.constants.ProfileConstant;
import com.jy.framework.model.event.AccessEvent;
import com.jy.framework.model.event.ExceptionEvent;
import com.jy.framework.model.event.OperateEvent;
import com.jy.log.service.LogAccessService;
import com.jy.log.service.LogExceptionService;
import com.jy.log.service.LogOperateService;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Profile;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Profile({ProfileConstant.TEST, ProfileConstant.PROD})
@Component
public class LogEventListeners {

    @Resource
    private LogAccessService logAccessService;

    @Resource
    private LogOperateService logOperateService;

    @Resource
    private LogExceptionService logExceptionService;

    /**
     * 记录用户访问信息
     */
    @EventListener
    public void recordAccess(AccessEvent event) {
        logAccessService.save(event);
    }

    /**
     * 记录用户操作信息
     */
    @EventListener
    public void recordOperate(OperateEvent event) {
        logOperateService.save(event);
    }

    /**
     * 记录异常信息
     */
    @EventListener
    public void recordException(ExceptionEvent event) {
        logExceptionService.save(event);
    }

}
