package com.cpop.core.base.entity;

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

import java.time.LocalDateTime;

/**
 * @author: DB
 * @Date: 2023/08/04/15:13
 * @Description:
 */
public class BaseUpdateListener implements UpdateListener {

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