package com.ruoyi.common.orm.listener;

import com.mybatisflex.annotation.InsertListener;
import com.ruoyi.common.orm.core.domain.BaseEntity;
import com.ruoyi.common.security.utils.LoginHelper;

import java.util.Date;

/**
 * Entity实体类新增数据监听器
 *
 * @author dataprince数据小王子
 */
public class EntityInsertListener implements InsertListener {

    @Override
    public void onInsert(Object entity) {
        BaseEntity baseEntity = (BaseEntity) entity;
        Long loginUserId = LoginHelper.getUserId();
        Date createTime = new Date();
        baseEntity.setCreateBy(loginUserId);
        baseEntity.setCreateTime(createTime);
        baseEntity.setUpdateBy(loginUserId);
        baseEntity.setUpdateTime(createTime);
    }
}
