package cn.meowrain.backend.common.mybaits;

import cn.meowrain.backend.common.mybaits.config.MybatisPlusMetaObjectHandler;
import cn.meowrain.backend.common.mybaits.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
public class MybatisPlusAutoConfiguration {

	@Bean
	public MybatisPlusInterceptor mybatisPlusInterceptor() {
		MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
		interceptor.addInnerInterceptor(new PaginationInterceptor());
		return interceptor;
	}

	/**
	 * 创建并返回MybatisPlusMetaObjectHandler实例，用于审计字段自动填充
	 */
	@Bean
	public MybatisPlusMetaObjectHandler mybatisPlusMetaObjectHandler() {
		return new MybatisPlusMetaObjectHandler();
	}

}
