diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/InjectionMetaObjectHandler.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/InjectionMetaObjectHandler.java index f54d21a..3999597 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/InjectionMetaObjectHandler.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/InjectionMetaObjectHandler.java @@ -5,14 +5,14 @@ import cn.hutool.http.HttpStatus; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; import com.ruoyi.common.core.domain.bo.LoginUser; import com.ruoyi.common.core.exception.ServiceException; -import com.ruoyi.common.mybatis.core.domain.BaseEntity; -import com.ruoyi.common.satoken.utils.LoginHelper; import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.mybatis.core.domain.BaseEntity; +import com.ruoyi.common.mybatis.core.domain.BaseHistoryEntity; +import com.ruoyi.common.satoken.utils.LoginHelper; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.reflection.MetaObject; import java.time.LocalDateTime; -import java.util.Date; /** * MP注入处理器 @@ -40,6 +40,12 @@ public class InjectionMetaObjectHandler implements MetaObjectHandler { baseEntity.setUpdateBy(username); } } + + if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseHistoryEntity baseHistoryEntity) { + LocalDateTime current = ObjectUtil.isNotNull(baseHistoryEntity.getCreateTime()) + ? baseHistoryEntity.getCreateTime() : LocalDateTime.now();; + baseHistoryEntity.setCreateTime(current); + } } catch (Exception e) { throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED); }