package com.yuchen.saas.park.api.config;

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

import java.time.LocalDateTime;

@Component
public class CustomMetaObjectHandler implements MetaObjectHandler {
    private static final String UPDATE_TIME_COLUMN = "updateTime";

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class);

        this.strictInsertFill(metaObject, UPDATE_TIME_COLUMN, LocalDateTime::now, LocalDateTime.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue(UPDATE_TIME_COLUMN, LocalDateTime.now());
        this.strictUpdateFill(metaObject, UPDATE_TIME_COLUMN, LocalDateTime::now, LocalDateTime.class);
    }
}