From 2e310e6da4938db526a255cca708ec6b053460d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Fri, 28 Jan 2022 11:03:40 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=8A=A5=E6=9C=AA=E7=99=BB=E5=BD=95=E8=AD=A6?= =?UTF-8?q?=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreateAndUpdateMetaObjectHandler.java | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java index 19e074ce..3d5a3190 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java @@ -27,26 +27,16 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { try { if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) { BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject(); - Date current = new Date(); - // 创建时间为空 则填充 - if (ObjectUtil.isNull(baseEntity.getCreateTime())) { - baseEntity.setCreateTime(current); - } - // 更新时间为空 则填充 - if (ObjectUtil.isNull(baseEntity.getUpdateTime())) { - baseEntity.setUpdateTime(current); - } - String username = getLoginUsername(); + Date current = ObjectUtil.isNotNull(baseEntity.getCreateTime()) + ? baseEntity.getCreateTime() : new Date(); + baseEntity.setCreateTime(current); + baseEntity.setUpdateTime(current); + String username = StringUtils.isNotBlank(baseEntity.getCreateBy()) + ? baseEntity.getCreateBy() : getLoginUsername(); // 当前已登录 且 创建人为空 则填充 - if (StringUtils.isNotBlank(username) - && StringUtils.isBlank(baseEntity.getCreateBy())) { - baseEntity.setCreateBy(username); - } + baseEntity.setCreateBy(username); // 当前已登录 且 更新人为空 则填充 - if (StringUtils.isNotBlank(username) - && StringUtils.isBlank(baseEntity.getUpdateBy())) { - baseEntity.setUpdateBy(username); - } + baseEntity.setUpdateBy(username); } } catch (Exception e) { throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);