package com.xunhong.erp.turbo.datasource.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author shenyifei
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
	@Override
	public void insertFill(MetaObject metaObject) {
		setFieldValByName("createdAt", LocalDateTime.now(), metaObject);
		setFieldValByName("updatedAt", LocalDateTime.now(), metaObject);
		setFieldValByName("version", 0, metaObject);
		setFieldValByName("isDelete", 0, metaObject);
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		setFieldValByName("updatedAt", LocalDateTime.now(), metaObject);
	}
}
