package com.ruoyi.framework.impl;

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

import java.util.Date;

/**
 * 实体类更新 监听
 * @author ruoyi
 */
public class DomainUpdateListenerImpl<T extends BaseEntity> implements UpdateListener {

    /**
     * 实体类执行更新时，自动赋值更新者和更新时间
     * @param entity
     */
    @SuppressWarnings("unchecked")
    @Override
    public void onUpdate(Object entity) {
        if(entity instanceof BaseEntity) {
            T t = (T) entity;
            t.setUpdateBy(SecurityUtil.getUserName());
            t.setUpdateTime(new Date());
        }
    }

}
