All Downloads are FREE. Search and download functionalities are using the official Maven repository.

im.shs.tick.mybatis.config.MybatisMetaObjectHandler Maven / Gradle / Ivy

The newest version!
package im.shs.tick.mybatis.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import im.shs.tick.core.utils.DateUtil;
import im.shs.tick.security.service.TickUser;
import im.shs.tick.security.util.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;

import java.util.Date;

public class MybatisMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        TickUser user = SecurityUtils.getUser();
        this.setInsertFieldValByName("createTime", DateUtil.toDateTime(new Date()), metaObject);
        this.setInsertFieldValByName("createBy", null != user ? user.getId() : null, metaObject);
        this.setInsertFieldValByName("deleted", false, metaObject);
        this.setInsertFieldValByName("version", 0, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        TickUser user = SecurityUtils.getUser();
        this.setUpdateFieldValByName("updateTime", DateUtil.toDateTime(new Date()), metaObject);
        this.setUpdateFieldValByName("updateBy", null != user ? user.getId() : null, metaObject);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy