From 2dd87e0414e05054e0cd350f8fc217e1308e11dc Mon Sep 17 00:00:00 2001 From: niudehua <657563945@qq.com> Date: Sat, 13 Mar 2021 22:16:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20=E4=BA=8B=E5=8A=A1=20rollb?= =?UTF-8?q?ack=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/job/impl/InfJobServiceImpl.java | 8 +++---- .../user/SysUserProfileController.java | 2 +- .../permission/impl/SysMenuServiceImpl.java | 2 +- .../impl/SysPermissionServiceImpl.java | 2 +- .../permission/impl/SysRoleServiceImpl.java | 2 +- .../service/user/SysUserServiceImpl.java | 22 ++++--------------- .../codegen/impl/ToolCodegenServiceImpl.java | 10 ++++----- 7 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/main/java/cn/iocoder/dashboard/modules/infra/service/job/impl/InfJobServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/infra/service/job/impl/InfJobServiceImpl.java index d82207de1..156c423c6 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/infra/service/job/impl/InfJobServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/infra/service/job/impl/InfJobServiceImpl.java @@ -41,7 +41,7 @@ public class InfJobServiceImpl implements InfJobService { private SchedulerManager schedulerManager; @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public Long createJob(InfJobCreateReqVO createReqVO) throws SchedulerException { validateCronExpression(createReqVO.getCronExpression()); // 校验唯一性 @@ -66,7 +66,7 @@ public class InfJobServiceImpl implements InfJobService { } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public void updateJob(InfJobUpdateReqVO updateReqVO) throws SchedulerException { validateCronExpression(updateReqVO.getCronExpression()); // 校验存在 @@ -86,7 +86,7 @@ public class InfJobServiceImpl implements InfJobService { } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public void updateJobStatus(Long id, Integer status) throws SchedulerException { // 校验 status if (!containsAny(status, InfJobStatusEnum.NORMAL.getStatus(), InfJobStatusEnum.STOP.getStatus())) { @@ -120,7 +120,7 @@ public class InfJobServiceImpl implements InfJobService { } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public void deleteJob(Long id) throws SchedulerException { // 校验存在 InfJobDO job = this.validateJobExists(id); diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserProfileController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserProfileController.java index 710617e1f..1b2503c77 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserProfileController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserProfileController.java @@ -88,7 +88,7 @@ public class SysUserProfileController { * @param file 头像文件 * @return 上传结果 */ - @PostMapping("/uploadAvatar") + @PostMapping("/upload-avatar") @ApiOperation("上传用户个人头像") public CommonResult uploadAvatar(@RequestParam("avatarFile") MultipartFile file) { if (!file.isEmpty()) { diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysMenuServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysMenuServiceImpl.java index 070677d8e..b4773c248 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysMenuServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysMenuServiceImpl.java @@ -206,7 +206,7 @@ public class SysMenuServiceImpl implements SysMenuService { * * @param menuId 菜单编号 */ - @Transactional + @Transactional(rollbackFor = Exception.class) public void deleteMenu(Long menuId) { // 校验更新的菜单是否存在 if (menuMapper.selectById(menuId) == null) { diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java index 9f48af9f5..ceb1d6d83 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java @@ -176,7 +176,7 @@ public class SysPermissionServiceImpl implements SysPermissionService { } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public void assignRoleMenu(Long roleId, Set menuIds) { // 获得角色拥有菜单编号 Set dbMenuIds = CollectionUtils.convertSet(roleMenuMapper.selectListByRoleId(roleId), diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java index d760b734b..93f67ea71 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java @@ -174,7 +174,7 @@ public class SysRoleServiceImpl implements SysRoleService { } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public void deleteRole(Long id) { // 校验是否可以更新 this.checkUpdateRole(id); diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserServiceImpl.java index 735121216..5411d27e8 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserServiceImpl.java @@ -2,7 +2,7 @@ package cn.iocoder.dashboard.modules.system.service.user; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.IoUtil; -import cn.hutool.core.lang.UUID; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.dashboard.common.enums.CommonStatusEnum; import cn.iocoder.dashboard.common.exception.ServiceException; @@ -68,19 +68,6 @@ public class SysUserServiceImpl implements SysUserService { @Resource private InfFileService fileService; -// /** -// * 根据条件分页查询用户列表 -// * -// * @param user 用户信息 -// * @return 用户信息集合信息 -// */ -// @Override -// @DataScope(deptAlias = "d", userAlias = "u") -// public List selectUserList(SysUser user) -// { -// return userMapper.selectUserList(user); -// } - @Override public SysUserDO getUserByUserName(String username) { return userMapper.selectByUsername(username); @@ -322,7 +309,7 @@ public class SysUserServiceImpl implements SysUserService { * @param id 用户 id * @param oldPassword 旧密码 * @param newPassword 新密码 - * @return + * @return 校验结果 */ private boolean checkOldPassword(Long id, String oldPassword, String newPassword) { if (id == null || StrUtil.isBlank(oldPassword) || StrUtil.isBlank(newPassword)) { @@ -340,7 +327,7 @@ public class SysUserServiceImpl implements SysUserService { } @Override - @Transactional // 添加事务,异常则回滚所有导入 + @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入 public SysUserImportRespVO importUsers(List importUsers, boolean isUpdateSupport) { if (CollUtil.isEmpty(importUsers)) { throw ServiceExceptionUtil.exception(USER_IMPORT_LIST_IS_EMPTY); @@ -381,8 +368,7 @@ public class SysUserServiceImpl implements SysUserService { public int updateAvatar(Long id, InputStream avatarFile) { this.checkUserExists(id); // 存储文件 - String avatar; - avatar = fileService.createFile(UUID.fastUUID().toString(), IoUtil.readBytes(avatarFile)); + String avatar = fileService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile)); // 更新路径 SysUserDO sysUserDO = new SysUserDO(); sysUserDO.setId(id); diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java index 6b2b5f9f7..5b746f6fd 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java @@ -109,7 +109,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public List createCodegenListFromDB(List tableNames) { List ids = new ArrayList<>(tableNames.size()); // 遍历添加。虽然效率会低一点,但是没必要做成完全批量,因为不会这么大量 @@ -118,7 +118,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public void updateCodegen(ToolCodegenUpdateReqVO updateReqVO) { // 校验是否已经存在 if (codegenTableMapper.selectById(updateReqVO.getTable().getId()) == null) { @@ -134,7 +134,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public void syncCodegenFromDB(Long tableId) { // 校验是否已经存在 ToolCodegenTableDO table = codegenTableMapper.selectById(tableId); @@ -149,7 +149,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public void syncCodegenFromSQL(Long tableId, String sql) { // 校验是否已经存在 ToolCodegenTableDO table = codegenTableMapper.selectById(tableId); @@ -201,7 +201,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public void deleteCodegen(Long tableId) { // 校验是否已经存在 if (codegenTableMapper.selectById(tableId) == null) {