package com.trs.project.handler;

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

@Component
public class CustomMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        // insert 时的填充策略，可以为空
/*        Object dataTimestamp = getFieldValByName("dataTimestamp", metaObject);
        Object createDate = getFieldValByName("createDate", metaObject);
        if(createDate!=null){
            this.setFieldValByName("createDate", createDate, metaObject);
        } else if (dataTimestamp != null) {
            this.setFieldValByName("createDate", dataTimestamp, metaObject);
        }*/
        Object dataTimestamp = getFieldValByName("dataTimestamp", metaObject);
        if(dataTimestamp!=null){
            this.setFieldValByName("createDate", dataTimestamp, metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        System.out.println("");
        // 判断字段是否有值，如果有值则不更新
/*        Object field = getFieldValByName("createDate", metaObject);
        if (field == null) {
            this.setFieldValByName("createDate", null, metaObject);
        }*/
    }
}
