package com.pannk;

import com.mongodb.MongoClient;
import com.mongodb.event.CommandFailedEvent;
import com.mongodb.event.CommandListener;
import com.mongodb.event.CommandStartedEvent;
import com.mongodb.event.CommandSucceededEvent;
import com.pannk.entity.SysLog;
import org.bson.BsonDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.core.MongoTemplate;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by wolf on 20-11-14.
 */
@SpringBootApplication
public class App implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }

    @Autowired
    private MongoTemplate mongoTemplate;

    @Bean
    public MongoTemplate mongoTemplate(MongoClient mongoClient) {
        return new MongoTemplate(mongoClient, "hello");
    }

    @Override
    public void run(String... args) {
        SysLog sysLog = new SysLog();
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("userName", "zhangsan");
        parameters.put("age", 30);
        sysLog.setOp("query user");
        sysLog.setParameters(parameters);
        sysLog.setTime(new Date());
        sysLog.setUser("admin");
        SysLog save = mongoTemplate.save(sysLog);
        System.out.println(save);


    }
}
