package com.ruoyi.framework.impl;

import com.mybatisflex.annotation.InsertListener;
import com.ruoyi.common.utils.SecurityUtil;
import com.ruoyi.common.web.domain.BaseEntity;

import java.util.Date;

/**
 * 实体类插入 监听
 * @author ruoyi
 */
public class DomainInsertListenerImpl<T extends BaseEntity> implements InsertListener {

    /**
     * 实体类执行插入时，自动赋值创建者和创建时间
     * @param entity
     */
    @SuppressWarnings("unchecked")
    @Override
    public void onInsert(Object entity) {
        if(entity instanceof BaseEntity) {
            T t = (T) entity;
            t.setCreateBy(SecurityUtil.getUserName());
            t.setCreateTime(new Date());
        }
    }

}
