liding
4 天以前 99b8950ca72fc71144d12844eccae8d69c331a92
自动插入修复
已修改2个文件
41 ■■■■■ 文件已修改
basic-server/src/main/resources/db/migration/postgresql/V20250603102701__create_table_coal_info.sql 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-common/src/main/java/com/ruoyi/common/handler/MyMetaObjectHandler.java 37 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
basic-server/src/main/resources/db/migration/postgresql/V20250603102701__create_table_coal_info.sql
@@ -9,9 +9,9 @@
    -- 新增字段
    deleted          int4         NOT NULL DEFAULT 0,                 -- 是否删除(软删除标志)
    create_by        VARCHAR(255),                                    -- 创建人
    create_time      TIMESTAMP             DEFAULT CURRENT_TIMESTAMP, -- 创建时间,默认当前时间
    create_time      TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, -- 创建时间,默认当前时间
    update_by        VARCHAR(255),                                    -- 最后更新人
    update_time      TIMESTAMP             DEFAULT CURRENT_TIMESTAMP  -- 最后更新时间,默认当前时间
    update_time      TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP  -- 最后更新时间,默认当前时间
);
-- 为表添加注释
ruoyi-common/src/main/java/com/ruoyi/common/handler/MyMetaObjectHandler.java
@@ -7,23 +7,38 @@
import java.time.LocalDateTime;
/**
 * @Author: zhangxy
 * @Date: 2020-08-05 14:40
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        this.strictInsertFill(metaObject, "createBy", Long.class, userId);
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        // 判断字段是否存在,存在才填充
        if (metaObject.hasSetter("createBy")) {
            Long userId = 0L;
            try {
                if (SecurityUtils.getLoginUser() != null) {
                    userId = SecurityUtils.getLoginUser().getUserId();
                    this.strictInsertFill(metaObject, "createBy", Long.class, userId);
                }
            } catch (Exception ignored) {
            }
        }
        if (metaObject.hasSetter("createTime")) {
            this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        }
    }
    @Override
    public void updateFill(MetaObject metaObject) {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        this.strictInsertFill(metaObject, "updateBy", Long.class, userId);
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        // 判断字段是否存在,存在才填充
        if (metaObject.hasSetter("updateBy")) {
            Long userId = SecurityUtils.getLoginUser().getUserId();
            this.strictUpdateFill(metaObject, "updateBy", Long.class, userId);
        }
        if (metaObject.hasSetter("updateTime")) {
            this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        }
    }
}
}