From aaf9f574596e997f1428db3c678319c5eb68f030 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: Mon, 11 Oct 2021 16:49:21 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=8E=BB=E9=99=A4=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisplus/CreateAndUpdateMetaObjectHandler.java | 8 ++++++-- .../java/com/ruoyi/system/service/SysLoginService.java | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/mybatisplus/CreateAndUpdateMetaObjectHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/mybatisplus/CreateAndUpdateMetaObjectHandler.java index feb73a45..9b5ce710 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/mybatisplus/CreateAndUpdateMetaObjectHandler.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/mybatisplus/CreateAndUpdateMetaObjectHandler.java @@ -27,7 +27,9 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { this.setFieldValByName("createTime", new Date(), metaObject); } if (metaObject.hasGetter("createBy")) { - this.setFieldValByName("createBy", getLoginUsername(), metaObject); + if (metaObject.getValue("createBy") == null) { + this.setFieldValByName("createBy", getLoginUsername(), metaObject); + } } } catch (Exception e) { throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED); @@ -39,7 +41,9 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { public void updateFill(MetaObject metaObject) { try { if (metaObject.hasGetter("updateBy")) { - this.setFieldValByName("updateBy", getLoginUsername(), metaObject); + if (metaObject.getValue("updateBy") == null) { + this.setFieldValByName("updateBy", getLoginUsername(), metaObject); + } } if (metaObject.hasGetter("updateTime")) { this.setFieldValByName("updateTime", new Date(), metaObject); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java index 0d2218ec..59cba7fb 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java @@ -78,7 +78,7 @@ public class SysLoginService { } asyncService.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"), request); LoginUser loginUser = (LoginUser) authentication.getPrincipal(); - recordLoginInfo(loginUser.getUserId()); + recordLoginInfo(loginUser.getUserId(), username); // 生成token return tokenService.createToken(loginUser); } @@ -110,11 +110,12 @@ public class SysLoginService { * * @param userId 用户ID */ - public void recordLoginInfo(Long userId) { + public void recordLoginInfo(Long userId, String username) { SysUser sysUser = new SysUser(); sysUser.setUserId(userId); sysUser.setLoginIp(ServletUtils.getClientIP()); sysUser.setLoginDate(DateUtils.getNowDate()); + sysUser.setUpdateBy(username); userService.updateUserProfile(sysUser); } }