package com.fzm.mall.server.front.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.toolkit.SystemClock;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    
    private static final Logger log = LoggerFactory.getLogger(MyMetaObjectHandler.class);
    
    @Override
    public void insertFill(MetaObject metaObject) {
        log.debug("start insert fill ....");
        Long currentTime = SystemClock.now();
        this.setFieldValByName("createTime", currentTime, metaObject);
        this.setFieldValByName("updateTime", currentTime, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.debug("start update fill ....");
        Long currentTime = SystemClock.now();
        this.setFieldValByName("updateTime", currentTime, metaObject);
    }

}
