package org.springblade.risk.log.listener;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.ldt.consts.QueueConst;
import com.ldt.entity.ApiLogData;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.event.ApiLogEvent;
import org.springblade.core.log.model.LogApi;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: lianghanqiang
 * @description: api 日志收集
 * @since: 10/27/21 -- 2:31 PM
 */

@Slf4j
@Component
@AllArgsConstructor
public class LdtApiLogListener {

//	private RabbitTemplate rabbitTemplate;

	@Async
	@EventListener({ApiLogEvent.class})
	public void saveApiLog(ApiLogEvent event) {

		Map<String, Object> source = (Map<String, Object>) event.getSource();
		LogApi logApi = (LogApi) source.get("log");
		ApiLogData apiLogData = BeanUtil.toBean(logApi, ApiLogData.class);
//		rabbitTemplate.send(QueueConst.apiLog,new Message(JSON.toJSONString(apiLogData).getBytes()));

	}
}
