From f50f351794a6e5f302e7e135997cc806120e10c1 Mon Sep 17 00:00:00 2001 From: Yjoioooo <693337446@qq.com> Date: Sat, 6 May 2023 13:46:02 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=99=A8=E5=8A=A0=E5=85=A5=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E4=BA=BA=E9=83=A8=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreateAndUpdateMetaObjectHandler.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java index 5ed320df..c53fe6b5 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java @@ -16,7 +16,6 @@ import java.util.Date; * MP注入处理器 * * @author Lion Li - * @date 2021/4/25 */ @Slf4j public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { @@ -30,12 +29,15 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { ? baseEntity.getCreateTime() : new Date(); baseEntity.setCreateTime(current); baseEntity.setUpdateTime(current); + LoginUser loginUser = getLoginUser(); Long userId = ObjectUtil.isNotNull(baseEntity.getCreateBy()) - ? baseEntity.getCreateBy() : getLoginId(); + ? baseEntity.getCreateBy() : loginUser.getUserId(); // 当前已登录 且 创建人为空 则填充 baseEntity.setCreateBy(userId); // 当前已登录 且 更新人为空 则填充 baseEntity.setUpdateBy(userId); + baseEntity.setCreateDept(ObjectUtil.isNotNull(baseEntity.getCreateDept()) + ? baseEntity.getCreateDept() : loginUser.getDeptId()); } } catch (Exception e) { throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED); @@ -50,10 +52,10 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { Date current = new Date(); // 更新时间填充(不管为不为空) baseEntity.setUpdateTime(current); - Long userId = getLoginId(); + LoginUser loginUser = getLoginUser(); // 当前已登录 更新人填充(不管为不为空) - if (ObjectUtil.isNotNull(userId)) { - baseEntity.setUpdateBy(userId); + if (ObjectUtil.isNotNull(loginUser)) { + baseEntity.setUpdateBy(loginUser.getUserId()); } } } catch (Exception e) { @@ -62,9 +64,9 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { } /** - * 获取登录用户名 + * 获取登录用户 */ - private Long getLoginId() { + private LoginUser getLoginUser() { LoginUser loginUser; try { loginUser = LoginHelper.getLoginUser(); @@ -72,7 +74,7 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { log.warn("自动注入警告 => 用户未登录"); return null; } - return ObjectUtil.isNotNull(loginUser) ? loginUser.getUserId() : null; + return loginUser; } }