diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/BaseEntity.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/BaseEntity.java index 70e75888..1a93917b 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/BaseEntity.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/BaseEntity.java @@ -31,11 +31,17 @@ public class BaseEntity implements Serializable { @TableField(exist = false) private String searchValue; + /** + * 创建部门 + */ + @TableField(fill = FieldFill.INSERT) + private Long createDept; + /** * 创建者 */ @TableField(fill = FieldFill.INSERT) - private String createBy; + private Long createBy; /** * 创建时间 @@ -47,7 +53,7 @@ public class BaseEntity implements Serializable { * 更新者 */ @TableField(fill = FieldFill.INSERT_UPDATE) - private String updateBy; + private Long updateBy; /** * 更新时间 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 5388ae58..dada87f5 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 @@ -30,12 +30,17 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { ? baseEntity.getCreateTime() : new Date(); baseEntity.setCreateTime(current); baseEntity.setUpdateTime(current); - String username = StringUtils.isNotBlank(baseEntity.getCreateBy()) - ? baseEntity.getCreateBy() : getLoginUsername(); + LoginUser loginUser = LoginHelper.getLoginUser(); + Long userId = ObjectUtil.isNotNull(baseEntity.getCreateBy()) + ? baseEntity.getCreateBy() : loginUser.getUserId(); // 当前已登录 且 创建人为空 则填充 - baseEntity.setCreateBy(username); + baseEntity.setCreateBy(userId); // 当前已登录 且 更新人为空 则填充 - baseEntity.setUpdateBy(username); + baseEntity.setUpdateBy(userId); + // 创建部门 + Long deptId = ObjectUtil.isNotNull(baseEntity.getCreateDept()) + ? baseEntity.getCreateDept() : loginUser.getDeptId(); + baseEntity.setCreateDept(deptId); } } catch (Exception e) { throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED); @@ -49,11 +54,8 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { Date current = new Date(); // 更新时间填充(不管为不为空) baseEntity.setUpdateTime(current); - String username = getLoginUsername(); // 当前已登录 更新人填充(不管为不为空) - if (StringUtils.isNotBlank(username)) { - baseEntity.setUpdateBy(username); - } + baseEntity.setUpdateBy(LoginHelper.getUserId()); } } catch (Exception e) { throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED); diff --git a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/demo/domain/vo/TestDemoVo.java b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/demo/domain/vo/TestDemoVo.java index 41faec36..365927e2 100644 --- a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/demo/domain/vo/TestDemoVo.java +++ b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/demo/domain/vo/TestDemoVo.java @@ -68,7 +68,7 @@ public class TestDemoVo implements Serializable { * 创建人 */ @ExcelProperty(value = "创建人") - private String createBy; + private Long createBy; /** * 更新时间 @@ -80,7 +80,7 @@ public class TestDemoVo implements Serializable { * 更新人 */ @ExcelProperty(value = "更新人") - private String updateBy; + private Long updateBy; } diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java index cb0a065b..b02bc583 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java @@ -2,6 +2,7 @@ package com.ruoyi.generator.util; import com.ruoyi.common.core.constant.GenConstants; import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.satoken.utils.LoginHelper; import com.ruoyi.generator.config.GenConfig; import com.ruoyi.generator.domain.GenTable; import com.ruoyi.generator.domain.GenTableColumn; @@ -29,7 +30,7 @@ public class GenUtils { genTable.setBusinessName(getBusinessName(genTable.getTableName())); genTable.setFunctionName(replaceText(genTable.getTableComment())); genTable.setFunctionAuthor(GenConfig.getAuthor()); - genTable.setCreateBy(operName); + genTable.setCreateBy(LoginHelper.getUserId()); } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysOssVo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysOssVo.java index 26c11e0c..6aab7736 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysOssVo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysOssVo.java @@ -50,7 +50,7 @@ public class SysOssVo implements Serializable { /** * 上传人 */ - private String createBy; + private Long createBy; /** * 服务商 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/listener/SysUserImportListener.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/listener/SysUserImportListener.java index 9840f75d..7919aac5 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/listener/SysUserImportListener.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/listener/SysUserImportListener.java @@ -57,7 +57,7 @@ public class SysUserImportListener extends AnalysisEventListener").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功"); @@ -68,7 +68,7 @@ public class SysUserImportListener extends AnalysisEventListener").append(successNum).append("、账号 ").append(user.getUserName()).append(" 更新成功"); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java index b5b072bb..46cef4df 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java @@ -81,7 +81,7 @@ public class SysLoginService { LoginHelper.loginByDevice(loginUser, DeviceType.PC); recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); - recordLoginInfo(user.getUserId(), username); + recordLoginInfo(user.getUserId()); return StpUtil.getTokenValue(); } @@ -96,7 +96,7 @@ public class SysLoginService { LoginHelper.loginByDevice(loginUser, DeviceType.APP); recordLogininfor(user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); - recordLoginInfo(user.getUserId(), user.getUserName()); + recordLoginInfo(user.getUserId()); return StpUtil.getTokenValue(); } @@ -118,7 +118,7 @@ public class SysLoginService { LoginHelper.loginByDevice(loginUser, DeviceType.XCX); recordLogininfor(user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); - recordLoginInfo(user.getUserId(), user.getUserName()); + recordLoginInfo(user.getUserId()); return StpUtil.getTokenValue(); } @@ -232,7 +232,7 @@ public class SysLoginService { private LoginUser buildLoginUser(SysUser user) { LoginUser loginUser = new LoginUser(); loginUser.setUserId(user.getUserId()); - loginUser.setDeptId(user.getDeptId()); + loginUser.setDeptId(ObjectUtil.isNull(user.getDept()) ? null : user.getDept().getDeptId()); loginUser.setUsername(user.getUserName()); loginUser.setUserType(user.getUserType()); loginUser.setMenuPermission(permissionService.getMenuPermission(user)); @@ -248,12 +248,12 @@ public class SysLoginService { * * @param userId 用户ID */ - public void recordLoginInfo(Long userId, String username) { + public void recordLoginInfo(Long userId) { SysUser sysUser = new SysUser(); sysUser.setUserId(userId); sysUser.setLoginIp(ServletUtils.getClientIP()); sysUser.setLoginDate(DateUtils.getNowDate()); - sysUser.setUpdateBy(username); + sysUser.setUpdateBy(userId); userMapper.updateById(sysUser); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java index 2cdacb7c..b7b81d16 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java @@ -1,5 +1,6 @@ package com.ruoyi.system.service.impl; +import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.mybatis.core.page.PageQuery; @@ -30,7 +31,7 @@ public class SysNoticeServiceImpl implements ISysNoticeService { LambdaQueryWrapper lqw = new LambdaQueryWrapper() .like(StringUtils.isNotBlank(notice.getNoticeTitle()), SysNotice::getNoticeTitle, notice.getNoticeTitle()) .eq(StringUtils.isNotBlank(notice.getNoticeType()), SysNotice::getNoticeType, notice.getNoticeType()) - .like(StringUtils.isNotBlank(notice.getCreateBy()), SysNotice::getCreateBy, notice.getCreateBy()); + .like(ObjectUtil.isNotNull(notice.getCreateBy()), SysNotice::getCreateBy, notice.getCreateBy()); Page page = baseMapper.selectPage(pageQuery.build(), lqw); return TableDataInfo.build(page); } @@ -57,7 +58,7 @@ public class SysNoticeServiceImpl implements ISysNoticeService { return baseMapper.selectList(new LambdaQueryWrapper() .like(StringUtils.isNotBlank(notice.getNoticeTitle()), SysNotice::getNoticeTitle, notice.getNoticeTitle()) .eq(StringUtils.isNotBlank(notice.getNoticeType()), SysNotice::getNoticeType, notice.getNoticeType()) - .like(StringUtils.isNotBlank(notice.getCreateBy()), SysNotice::getCreateBy, notice.getCreateBy())); + .like(ObjectUtil.isNotNull(notice.getCreateBy()), SysNotice::getCreateBy, notice.getCreateBy())); } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java index cc303221..937ee16d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java @@ -78,7 +78,7 @@ public class SysOssServiceImpl implements ISysOssService { lqw.eq(StringUtils.isNotBlank(bo.getUrl()), SysOss::getUrl, bo.getUrl()); lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null, SysOss::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime")); - lqw.eq(StringUtils.isNotBlank(bo.getCreateBy()), SysOss::getCreateBy, bo.getCreateBy()); + lqw.eq(ObjectUtil.isNotNull(bo.getCreateBy()), SysOss::getCreateBy, bo.getCreateBy()); lqw.eq(StringUtils.isNotBlank(bo.getService()), SysOss::getService, bo.getService()); return lqw; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index 4e1d63ab..26618907 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -287,8 +287,8 @@ public class SysUserServiceImpl implements ISysUserService { */ @Override public boolean registerUser(SysUser user) { - user.setCreateBy(user.getUserName()); - user.setUpdateBy(user.getUserName()); + user.setCreateBy(user.getUserId()); + user.setUpdateBy(user.getUserId()); return baseMapper.insert(user) > 0; }