package com.tofly.common.log.event;

import com.tofly.base.api.entity.Log;
import com.tofly.base.api.feign.BaseLogService;
import com.tofly.common.core.constant.SecurityConstants;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Async;


/**
 * 异步监听日志事件
 */
@Slf4j
@AllArgsConstructor
public class SysLogListener {


	private  BaseLogService baseLogService;
	private Environment environment;

	@Async
	@Order
	@EventListener(SysLogEvent.class)
	public void saveSysLog(SysLogEvent event) {
		Log sysLog = (Log) event.getSource();
		sysLog.setServiceId(environment.getProperty("spring.application.name"));
		log.info("baselogservice:{}",baseLogService);
		baseLogService.saveLog(sysLog, SecurityConstants.FROM_IN);
	}
}
