package com.zcloud.common.handler;

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

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
//        this.setFieldValByName("isDelete", 0, metaObject);
        this.setFieldValByName("createTime", DateUtil.date2Str(new Date()), metaObject);
        this.setFieldValByName("operatTime", DateUtil.date2Str(new Date()), metaObject);
        this.strictInsertFill(metaObject, "isDelete", Integer.class, 0);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("operatTime", DateUtil.date2Str(new Date()), metaObject);
    }
}
