package com.cpop.core.base.entity;

import com.cpop.core.utils.SecurityUtils;
import com.mybatisflex.annotation.InsertListener;

import java.time.LocalDateTime;

/**
 * @author: DB
 * @Date: 2023/08/04/15:12
 * @Description: 添加自动填充
 */
public class BaseInsertListener implements InsertListener {

    @Override
    public void onInsert(Object entity) {
        BaseEntity baseEntity = (BaseEntity) entity;
        LoginUser loginUser = SecurityUtils.getInstance().getLoginUser();
        //设置 account 被新增时的一些默认数据
        baseEntity.setCreateTime(LocalDateTime.now());
        baseEntity.setCreateUserId(null == loginUser ? "1" : loginUser.getUserId());
        baseEntity.setUpdateTime(LocalDateTime.now());
        baseEntity.setUpdateUserId(null == loginUser ? "1" : loginUser.getUserId());
    }
}
