Commit 61c24c0aa7fd1b4640b8f1feeaa1d81d0214fc3a
1 parent
e4bda22b
设置 事务 rollback 属性
增加 个人信息设置 功能 增加 个人信息设置 功能
Showing
14 changed files
with
97 additions
and
110 deletions
src/main/java/cn/iocoder/dashboard/modules/infra/service/job/impl/InfJobServiceImpl.java
| @@ -41,7 +41,7 @@ public class InfJobServiceImpl implements InfJobService { | @@ -41,7 +41,7 @@ public class InfJobServiceImpl implements InfJobService { | ||
| 41 | private SchedulerManager schedulerManager; | 41 | private SchedulerManager schedulerManager; |
| 42 | 42 | ||
| 43 | @Override | 43 | @Override |
| 44 | - @Transactional | 44 | + @Transactional(rollbackFor = Exception.class) |
| 45 | public Long createJob(InfJobCreateReqVO createReqVO) throws SchedulerException { | 45 | public Long createJob(InfJobCreateReqVO createReqVO) throws SchedulerException { |
| 46 | validateCronExpression(createReqVO.getCronExpression()); | 46 | validateCronExpression(createReqVO.getCronExpression()); |
| 47 | // 校验唯一性 | 47 | // 校验唯一性 |
| @@ -66,7 +66,7 @@ public class InfJobServiceImpl implements InfJobService { | @@ -66,7 +66,7 @@ public class InfJobServiceImpl implements InfJobService { | ||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | @Override | 68 | @Override |
| 69 | - @Transactional | 69 | + @Transactional(rollbackFor = Exception.class) |
| 70 | public void updateJob(InfJobUpdateReqVO updateReqVO) throws SchedulerException { | 70 | public void updateJob(InfJobUpdateReqVO updateReqVO) throws SchedulerException { |
| 71 | validateCronExpression(updateReqVO.getCronExpression()); | 71 | validateCronExpression(updateReqVO.getCronExpression()); |
| 72 | // 校验存在 | 72 | // 校验存在 |
| @@ -86,7 +86,7 @@ public class InfJobServiceImpl implements InfJobService { | @@ -86,7 +86,7 @@ public class InfJobServiceImpl implements InfJobService { | ||
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | @Override | 88 | @Override |
| 89 | - @Transactional | 89 | + @Transactional(rollbackFor = Exception.class) |
| 90 | public void updateJobStatus(Long id, Integer status) throws SchedulerException { | 90 | public void updateJobStatus(Long id, Integer status) throws SchedulerException { |
| 91 | // 校验 status | 91 | // 校验 status |
| 92 | if (!containsAny(status, InfJobStatusEnum.NORMAL.getStatus(), InfJobStatusEnum.STOP.getStatus())) { | 92 | if (!containsAny(status, InfJobStatusEnum.NORMAL.getStatus(), InfJobStatusEnum.STOP.getStatus())) { |
| @@ -120,7 +120,7 @@ public class InfJobServiceImpl implements InfJobService { | @@ -120,7 +120,7 @@ public class InfJobServiceImpl implements InfJobService { | ||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | @Override | 122 | @Override |
| 123 | - @Transactional | 123 | + @Transactional(rollbackFor = Exception.class) |
| 124 | public void deleteJob(Long id) throws SchedulerException { | 124 | public void deleteJob(Long id) throws SchedulerException { |
| 125 | // 校验存在 | 125 | // 校验存在 |
| 126 | InfJobDO job = this.validateJobExists(id); | 126 | InfJobDO job = this.validateJobExists(id); |
src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java
| @@ -40,8 +40,8 @@ public class SysUserController { | @@ -40,8 +40,8 @@ public class SysUserController { | ||
| 40 | @Resource | 40 | @Resource |
| 41 | private SysDeptService deptService; | 41 | private SysDeptService deptService; |
| 42 | 42 | ||
| 43 | - @ApiOperation("获得用户分页列表") | ||
| 44 | @GetMapping("/page") | 43 | @GetMapping("/page") |
| 44 | + @ApiOperation("获得用户分页列表") | ||
| 45 | @PreAuthorize("@ss.hasPermission('system:user:list')") | 45 | @PreAuthorize("@ss.hasPermission('system:user:list')") |
| 46 | public CommonResult<PageResult<SysUserPageItemRespVO>> pageUsers(@Validated SysUserPageReqVO reqVO) { | 46 | public CommonResult<PageResult<SysUserPageItemRespVO>> pageUsers(@Validated SysUserPageReqVO reqVO) { |
| 47 | // 获得用户分页列表 | 47 | // 获得用户分页列表 |
| @@ -66,9 +66,9 @@ public class SysUserController { | @@ -66,9 +66,9 @@ public class SysUserController { | ||
| 66 | /** | 66 | /** |
| 67 | * 根据用户编号获取详细信息 | 67 | * 根据用户编号获取详细信息 |
| 68 | */ | 68 | */ |
| 69 | + @GetMapping("/get") | ||
| 69 | @ApiOperation("获得用户详情") | 70 | @ApiOperation("获得用户详情") |
| 70 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | 71 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) |
| 71 | - @GetMapping("/get") | ||
| 72 | // @PreAuthorize("@ss.hasPermi('system:user:query')") | 72 | // @PreAuthorize("@ss.hasPermi('system:user:query')") |
| 73 | public CommonResult<SysUserRespVO> getInfo(@RequestParam("id") Long id) { | 73 | public CommonResult<SysUserRespVO> getInfo(@RequestParam("id") Long id) { |
| 74 | return success(SysUserConvert.INSTANCE.convert(userService.getUser(id))); | 74 | return success(SysUserConvert.INSTANCE.convert(userService.getUser(id))); |
src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserProfileController.java
| 1 | package cn.iocoder.dashboard.modules.system.controller.user; | 1 | package cn.iocoder.dashboard.modules.system.controller.user; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; | ||
| 3 | import cn.iocoder.dashboard.common.pojo.CommonResult; | 4 | import cn.iocoder.dashboard.common.pojo.CommonResult; |
| 4 | -import cn.iocoder.dashboard.framework.security.core.LoginUser; | ||
| 5 | import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils; | 5 | import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils; |
| 6 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserProfileRespVO; | 6 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserProfileRespVO; |
| 7 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserProfileUpdateReqVO; | 7 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserProfileUpdateReqVO; |
| @@ -12,8 +12,10 @@ import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO; | @@ -12,8 +12,10 @@ import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO; | ||
| 12 | import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService; | 12 | import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService; |
| 13 | import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService; | 13 | import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService; |
| 14 | import cn.iocoder.dashboard.modules.system.service.user.SysUserService; | 14 | import cn.iocoder.dashboard.modules.system.service.user.SysUserService; |
| 15 | +import cn.iocoder.dashboard.util.collection.CollectionUtils; | ||
| 15 | import io.swagger.annotations.Api; | 16 | import io.swagger.annotations.Api; |
| 16 | import io.swagger.annotations.ApiOperation; | 17 | import io.swagger.annotations.ApiOperation; |
| 18 | +import lombok.extern.slf4j.Slf4j; | ||
| 17 | import org.springframework.web.bind.annotation.GetMapping; | 19 | import org.springframework.web.bind.annotation.GetMapping; |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | 20 | import org.springframework.web.bind.annotation.PostMapping; |
| 19 | import org.springframework.web.bind.annotation.RequestBody; | 21 | import org.springframework.web.bind.annotation.RequestBody; |
| @@ -24,15 +26,19 @@ import org.springframework.web.multipart.MultipartFile; | @@ -24,15 +26,19 @@ import org.springframework.web.multipart.MultipartFile; | ||
| 24 | 26 | ||
| 25 | import javax.annotation.Resource; | 27 | import javax.annotation.Resource; |
| 26 | import javax.servlet.http.HttpServletRequest; | 28 | import javax.servlet.http.HttpServletRequest; |
| 29 | +import java.io.IOException; | ||
| 27 | import java.util.List; | 30 | import java.util.List; |
| 28 | -import java.util.stream.Collectors; | 31 | + |
| 32 | +import static cn.iocoder.dashboard.common.pojo.CommonResult.success; | ||
| 33 | +import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.FILE_IS_EMPTY; | ||
| 29 | 34 | ||
| 30 | /** | 35 | /** |
| 31 | * @author niudehua | 36 | * @author niudehua |
| 32 | */ | 37 | */ |
| 33 | -@Api(tags = "用户个人中心") | ||
| 34 | @RestController | 38 | @RestController |
| 35 | @RequestMapping("/system/user/profile") | 39 | @RequestMapping("/system/user/profile") |
| 40 | +@Api(tags = "用户个人中心") | ||
| 41 | +@Slf4j | ||
| 36 | public class SysUserProfileController { | 42 | public class SysUserProfileController { |
| 37 | 43 | ||
| 38 | @Resource | 44 | @Resource |
| @@ -42,58 +48,33 @@ public class SysUserProfileController { | @@ -42,58 +48,33 @@ public class SysUserProfileController { | ||
| 42 | @Resource | 48 | @Resource |
| 43 | private SysRoleService roleService; | 49 | private SysRoleService roleService; |
| 44 | 50 | ||
| 45 | - /** | ||
| 46 | - * 个人信息 | ||
| 47 | - * | ||
| 48 | - * @return 个人信息详情 | ||
| 49 | - */ | ||
| 50 | - @ApiOperation("获得登录用户信息") | ||
| 51 | @GetMapping("/get") | 51 | @GetMapping("/get") |
| 52 | + @ApiOperation("获得登录用户信息") | ||
| 52 | public CommonResult<SysUserProfileRespVO> profile() { | 53 | public CommonResult<SysUserProfileRespVO> profile() { |
| 53 | - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); | ||
| 54 | // 获取用户信息 | 54 | // 获取用户信息 |
| 55 | - assert loginUser != null; | ||
| 56 | - Long userId = loginUser.getId(); | 55 | + Long userId = SecurityFrameworkUtils.getLoginUserId(); |
| 57 | SysUserDO user = userService.getUser(userId); | 56 | SysUserDO user = userService.getUser(userId); |
| 58 | SysUserProfileRespVO userProfileRespVO = SysUserConvert.INSTANCE.convert03(user); | 57 | SysUserProfileRespVO userProfileRespVO = SysUserConvert.INSTANCE.convert03(user); |
| 59 | List<SysRoleDO> userRoles = roleService.listRolesFromCache(permissionService.listUserRoleIs(userId)); | 58 | List<SysRoleDO> userRoles = roleService.listRolesFromCache(permissionService.listUserRoleIs(userId)); |
| 60 | - userProfileRespVO.setRoles(userRoles.stream().map(SysUserConvert.INSTANCE::convert).collect(Collectors.toSet())); | ||
| 61 | - return CommonResult.success(userProfileRespVO); | 59 | + userProfileRespVO.setRoles(CollectionUtils.convertSet(userRoles, SysUserConvert.INSTANCE::convert)); |
| 60 | + return success(userProfileRespVO); | ||
| 62 | } | 61 | } |
| 63 | 62 | ||
| 64 | - /** | ||
| 65 | - * 修改个人信息 | ||
| 66 | - * | ||
| 67 | - * @param reqVO 个人信息更新 reqVO | ||
| 68 | - * @param request HttpServletRequest | ||
| 69 | - * @return 修改结果 | ||
| 70 | - */ | ||
| 71 | - @ApiOperation("修改用户个人信息") | ||
| 72 | @PostMapping("/update") | 63 | @PostMapping("/update") |
| 64 | + @ApiOperation("修改用户个人信息") | ||
| 73 | public CommonResult<Boolean> updateProfile(@RequestBody SysUserProfileUpdateReqVO reqVO, HttpServletRequest request) { | 65 | public CommonResult<Boolean> updateProfile(@RequestBody SysUserProfileUpdateReqVO reqVO, HttpServletRequest request) { |
| 74 | - if (userService.updateUserProfile(reqVO) > 0) { | ||
| 75 | - SecurityFrameworkUtils.setLoginUser(SysAuthConvert.INSTANCE.convert(reqVO), request); | ||
| 76 | - return CommonResult.success(true); | ||
| 77 | - } | ||
| 78 | - return CommonResult.success(false); | 66 | + userService.updateUserProfile(reqVO); |
| 67 | + SecurityFrameworkUtils.setLoginUser(SysAuthConvert.INSTANCE.convert(reqVO), request); | ||
| 68 | + return success(true); | ||
| 79 | } | 69 | } |
| 80 | 70 | ||
| 81 | - /** | ||
| 82 | - * 上传用户个人头像 | ||
| 83 | - * | ||
| 84 | - * @param file 头像文件 | ||
| 85 | - * @return 上传结果 | ||
| 86 | - */ | 71 | + @PostMapping("/upload-avatar") |
| 87 | @ApiOperation("上传用户个人头像") | 72 | @ApiOperation("上传用户个人头像") |
| 88 | - @PostMapping("/uploadAvatar") | ||
| 89 | - public CommonResult<Boolean> uploadAvatar(@RequestParam("avatarFile") MultipartFile file) { | ||
| 90 | - if (!file.isEmpty()) { | ||
| 91 | - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); | ||
| 92 | - assert loginUser != null; | ||
| 93 | - if (userService.updateAvatar(loginUser.getId(), file) > 0) { | ||
| 94 | - return CommonResult.success(true); | ||
| 95 | - } | 73 | + public CommonResult<Boolean> uploadAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { |
| 74 | + if (file.isEmpty()) { | ||
| 75 | + throw ServiceExceptionUtil.exception(FILE_IS_EMPTY); | ||
| 96 | } | 76 | } |
| 97 | - return CommonResult.success(false); | 77 | + userService.updateAvatar(SecurityFrameworkUtils.getLoginUserId(), file.getInputStream()); |
| 78 | + return success(true); | ||
| 98 | } | 79 | } |
| 99 | } | 80 | } |
src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserProfileRespVO.java
| @@ -17,11 +17,6 @@ import java.util.Set; | @@ -17,11 +17,6 @@ import java.util.Set; | ||
| 17 | @EqualsAndHashCode(callSuper = true) | 17 | @EqualsAndHashCode(callSuper = true) |
| 18 | public class SysUserProfileRespVO extends SysUserRespVO { | 18 | public class SysUserProfileRespVO extends SysUserRespVO { |
| 19 | 19 | ||
| 20 | - @ApiModelProperty(value = "旧密码", required = true, example = "123456") | ||
| 21 | - private String oldPassword; | ||
| 22 | - | ||
| 23 | - @ApiModelProperty(value = "新密码", required = true, example = "123456") | ||
| 24 | - private String newPassword; | ||
| 25 | /** | 20 | /** |
| 26 | * 所属角色 | 21 | * 所属角色 |
| 27 | */ | 22 | */ |
src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserProfileUpdateReqVO.java
| @@ -3,19 +3,38 @@ package cn.iocoder.dashboard.modules.system.controller.user.vo.user; | @@ -3,19 +3,38 @@ package cn.iocoder.dashboard.modules.system.controller.user.vo.user; | ||
| 3 | import io.swagger.annotations.ApiModel; | 3 | import io.swagger.annotations.ApiModel; |
| 4 | import io.swagger.annotations.ApiModelProperty; | 4 | import io.swagger.annotations.ApiModelProperty; |
| 5 | import lombok.Data; | 5 | import lombok.Data; |
| 6 | -import lombok.EqualsAndHashCode; | ||
| 7 | 6 | ||
| 7 | +import javax.validation.constraints.Email; | ||
| 8 | import javax.validation.constraints.NotNull; | 8 | import javax.validation.constraints.NotNull; |
| 9 | +import javax.validation.constraints.Size; | ||
| 9 | 10 | ||
| 10 | -@ApiModel("用户更新 Request VO") | 11 | +@ApiModel("用户个人信息更新 Request VO") |
| 11 | @Data | 12 | @Data |
| 12 | -@EqualsAndHashCode(callSuper = true) | ||
| 13 | -public class SysUserProfileUpdateReqVO extends SysUserBaseVO { | 13 | +public class SysUserProfileUpdateReqVO { |
| 14 | 14 | ||
| 15 | @ApiModelProperty(value = "用户编号", required = true, example = "1024") | 15 | @ApiModelProperty(value = "用户编号", required = true, example = "1024") |
| 16 | @NotNull(message = "用户编号不能为空") | 16 | @NotNull(message = "用户编号不能为空") |
| 17 | private Long id; | 17 | private Long id; |
| 18 | 18 | ||
| 19 | + @ApiModelProperty(value = "用户昵称", required = true, example = "芋艿") | ||
| 20 | + @Size(max = 30, message = "用户昵称长度不能超过30个字符") | ||
| 21 | + private String nickname; | ||
| 22 | + | ||
| 23 | + @ApiModelProperty(value = "用户邮箱", example = "yudao@iocoder.cn") | ||
| 24 | + @Email(message = "邮箱格式不正确") | ||
| 25 | + @Size(max = 50, message = "邮箱长度不能超过50个字符") | ||
| 26 | + private String email; | ||
| 27 | + | ||
| 28 | + @ApiModelProperty(value = "手机号码", example = "15601691300") | ||
| 29 | + @Size(max = 11, message = "手机号码长度不能超过11个字符") | ||
| 30 | + private String mobile; | ||
| 31 | + | ||
| 32 | + @ApiModelProperty(value = "用户性别", example = "1", notes = "参见 SysSexEnum 枚举类") | ||
| 33 | + private Integer sex; | ||
| 34 | + | ||
| 35 | + @ApiModelProperty(value = "用户头像", example = "http://www.iocoder.cn/xxx.png") | ||
| 36 | + private String avatar; | ||
| 37 | + | ||
| 19 | @ApiModelProperty(value = "旧密码", required = true, example = "123456") | 38 | @ApiModelProperty(value = "旧密码", required = true, example = "123456") |
| 20 | private String oldPassword; | 39 | private String oldPassword; |
| 21 | 40 |
src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java
| @@ -76,5 +76,6 @@ public interface SysErrorCodeConstants { | @@ -76,5 +76,6 @@ public interface SysErrorCodeConstants { | ||
| 76 | // ========== 文件 1002009000 ========== | 76 | // ========== 文件 1002009000 ========== |
| 77 | ErrorCode FILE_PATH_EXISTS = new ErrorCode(1002009001, "文件路径已经存在"); | 77 | ErrorCode FILE_PATH_EXISTS = new ErrorCode(1002009001, "文件路径已经存在"); |
| 78 | ErrorCode FILE_UPLOAD_FAILED = new ErrorCode(1002009002, "文件上传失败"); | 78 | ErrorCode FILE_UPLOAD_FAILED = new ErrorCode(1002009002, "文件上传失败"); |
| 79 | + ErrorCode FILE_IS_EMPTY= new ErrorCode(1002009003, "文件为空"); | ||
| 79 | 80 | ||
| 80 | } | 81 | } |
src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysMenuServiceImpl.java
| @@ -206,7 +206,7 @@ public class SysMenuServiceImpl implements SysMenuService { | @@ -206,7 +206,7 @@ public class SysMenuServiceImpl implements SysMenuService { | ||
| 206 | * | 206 | * |
| 207 | * @param menuId 菜单编号 | 207 | * @param menuId 菜单编号 |
| 208 | */ | 208 | */ |
| 209 | - @Transactional | 209 | + @Transactional(rollbackFor = Exception.class) |
| 210 | public void deleteMenu(Long menuId) { | 210 | public void deleteMenu(Long menuId) { |
| 211 | // 校验更新的菜单是否存在 | 211 | // 校验更新的菜单是否存在 |
| 212 | if (menuMapper.selectById(menuId) == null) { | 212 | if (menuMapper.selectById(menuId) == null) { |
src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java
| @@ -176,7 +176,7 @@ public class SysPermissionServiceImpl implements SysPermissionService { | @@ -176,7 +176,7 @@ public class SysPermissionServiceImpl implements SysPermissionService { | ||
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | @Override | 178 | @Override |
| 179 | - @Transactional | 179 | + @Transactional(rollbackFor = Exception.class) |
| 180 | public void assignRoleMenu(Long roleId, Set<Long> menuIds) { | 180 | public void assignRoleMenu(Long roleId, Set<Long> menuIds) { |
| 181 | // 获得角色拥有菜单编号 | 181 | // 获得角色拥有菜单编号 |
| 182 | Set<Long> dbMenuIds = CollectionUtils.convertSet(roleMenuMapper.selectListByRoleId(roleId), | 182 | Set<Long> dbMenuIds = CollectionUtils.convertSet(roleMenuMapper.selectListByRoleId(roleId), |
src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java
| @@ -174,7 +174,7 @@ public class SysRoleServiceImpl implements SysRoleService { | @@ -174,7 +174,7 @@ public class SysRoleServiceImpl implements SysRoleService { | ||
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | @Override | 176 | @Override |
| 177 | - @Transactional | 177 | + @Transactional(rollbackFor = Exception.class) |
| 178 | public void deleteRole(Long id) { | 178 | public void deleteRole(Long id) { |
| 179 | // 校验是否可以更新 | 179 | // 校验是否可以更新 |
| 180 | this.checkUpdateRole(id); | 180 | this.checkUpdateRole(id); |
src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserService.java
| @@ -11,8 +11,8 @@ import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserProfil | @@ -11,8 +11,8 @@ import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserProfil | ||
| 11 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO; | 11 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO; |
| 12 | import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO; | 12 | import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO; |
| 13 | import cn.iocoder.dashboard.util.collection.CollectionUtils; | 13 | import cn.iocoder.dashboard.util.collection.CollectionUtils; |
| 14 | -import org.springframework.web.multipart.MultipartFile; | ||
| 15 | 14 | ||
| 15 | +import java.io.InputStream; | ||
| 16 | import java.util.Collection; | 16 | import java.util.Collection; |
| 17 | import java.util.HashMap; | 17 | import java.util.HashMap; |
| 18 | import java.util.List; | 18 | import java.util.List; |
| @@ -115,7 +115,7 @@ public interface SysUserService { | @@ -115,7 +115,7 @@ public interface SysUserService { | ||
| 115 | * @param reqVO 用户个人信息 | 115 | * @param reqVO 用户个人信息 |
| 116 | * @return 修改结果 | 116 | * @return 修改结果 |
| 117 | */ | 117 | */ |
| 118 | - int updateUserProfile(SysUserProfileUpdateReqVO reqVO); | 118 | + void updateUserProfile(SysUserProfileUpdateReqVO reqVO); |
| 119 | 119 | ||
| 120 | /** | 120 | /** |
| 121 | * 删除用户 | 121 | * 删除用户 |
| @@ -154,9 +154,8 @@ public interface SysUserService { | @@ -154,9 +154,8 @@ public interface SysUserService { | ||
| 154 | * | 154 | * |
| 155 | * @param id 用户 id | 155 | * @param id 用户 id |
| 156 | * @param avatarFile 头像文件 | 156 | * @param avatarFile 头像文件 |
| 157 | - * @return 更新结果 | ||
| 158 | */ | 157 | */ |
| 159 | - int updateAvatar(Long id, MultipartFile avatarFile); | 158 | + void updateAvatar(Long id, InputStream avatarFile); |
| 160 | 159 | ||
| 161 | // | 160 | // |
| 162 | // /** | 161 | // /** |
src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserServiceImpl.java
| @@ -2,11 +2,13 @@ package cn.iocoder.dashboard.modules.system.service.user; | @@ -2,11 +2,13 @@ package cn.iocoder.dashboard.modules.system.service.user; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.io.IoUtil; | 4 | import cn.hutool.core.io.IoUtil; |
| 5 | +import cn.hutool.core.util.IdUtil; | ||
| 5 | import cn.hutool.core.util.StrUtil; | 6 | import cn.hutool.core.util.StrUtil; |
| 6 | import cn.iocoder.dashboard.common.enums.CommonStatusEnum; | 7 | import cn.iocoder.dashboard.common.enums.CommonStatusEnum; |
| 7 | import cn.iocoder.dashboard.common.exception.ServiceException; | 8 | import cn.iocoder.dashboard.common.exception.ServiceException; |
| 8 | import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; | 9 | import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; |
| 9 | import cn.iocoder.dashboard.common.pojo.PageResult; | 10 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 11 | +import cn.iocoder.dashboard.modules.infra.service.file.InfFileService; | ||
| 10 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserCreateReqVO; | 12 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserCreateReqVO; |
| 11 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserExportReqVO; | 13 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserExportReqVO; |
| 12 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserImportExcelVO; | 14 | import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserImportExcelVO; |
| @@ -19,7 +21,6 @@ import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysDeptDO; | @@ -19,7 +21,6 @@ import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysDeptDO; | ||
| 19 | import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysPostDO; | 21 | import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysPostDO; |
| 20 | import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO; | 22 | import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO; |
| 21 | import cn.iocoder.dashboard.modules.system.dal.mysql.user.SysUserMapper; | 23 | import cn.iocoder.dashboard.modules.system.dal.mysql.user.SysUserMapper; |
| 22 | -import cn.iocoder.dashboard.modules.system.service.common.SysFileService; | ||
| 23 | import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; | 24 | import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; |
| 24 | import cn.iocoder.dashboard.modules.system.service.dept.SysPostService; | 25 | import cn.iocoder.dashboard.modules.system.service.dept.SysPostService; |
| 25 | import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService; | 26 | import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService; |
| @@ -28,10 +29,9 @@ import lombok.extern.slf4j.Slf4j; | @@ -28,10 +29,9 @@ import lombok.extern.slf4j.Slf4j; | ||
| 28 | import org.springframework.security.crypto.password.PasswordEncoder; | 29 | import org.springframework.security.crypto.password.PasswordEncoder; |
| 29 | import org.springframework.stereotype.Service; | 30 | import org.springframework.stereotype.Service; |
| 30 | import org.springframework.transaction.annotation.Transactional; | 31 | import org.springframework.transaction.annotation.Transactional; |
| 31 | -import org.springframework.web.multipart.MultipartFile; | ||
| 32 | 32 | ||
| 33 | import javax.annotation.Resource; | 33 | import javax.annotation.Resource; |
| 34 | -import java.io.IOException; | 34 | +import java.io.InputStream; |
| 35 | import java.util.ArrayList; | 35 | import java.util.ArrayList; |
| 36 | import java.util.Collection; | 36 | import java.util.Collection; |
| 37 | import java.util.Collections; | 37 | import java.util.Collections; |
| @@ -66,20 +66,7 @@ public class SysUserServiceImpl implements SysUserService { | @@ -66,20 +66,7 @@ public class SysUserServiceImpl implements SysUserService { | ||
| 66 | private PasswordEncoder passwordEncoder; | 66 | private PasswordEncoder passwordEncoder; |
| 67 | 67 | ||
| 68 | @Resource | 68 | @Resource |
| 69 | - private SysFileService fileService; | ||
| 70 | - | ||
| 71 | -// /** | ||
| 72 | -// * 根据条件分页查询用户列表 | ||
| 73 | -// * | ||
| 74 | -// * @param user 用户信息 | ||
| 75 | -// * @return 用户信息集合信息 | ||
| 76 | -// */ | ||
| 77 | -// @Override | ||
| 78 | -// @DataScope(deptAlias = "d", userAlias = "u") | ||
| 79 | -// public List<SysUser> selectUserList(SysUser user) | ||
| 80 | -// { | ||
| 81 | -// return userMapper.selectUserList(user); | ||
| 82 | -// } | 69 | + private InfFileService fileService; |
| 83 | 70 | ||
| 84 | @Override | 71 | @Override |
| 85 | public SysUserDO getUserByUserName(String username) { | 72 | public SysUserDO getUserByUserName(String username) { |
| @@ -156,20 +143,22 @@ public class SysUserServiceImpl implements SysUserService { | @@ -156,20 +143,22 @@ public class SysUserServiceImpl implements SysUserService { | ||
| 156 | } | 143 | } |
| 157 | 144 | ||
| 158 | @Override | 145 | @Override |
| 159 | - public int updateUserProfile(SysUserProfileUpdateReqVO reqVO) { | 146 | + public void updateUserProfile(SysUserProfileUpdateReqVO reqVO) { |
| 160 | // 校验正确性 | 147 | // 校验正确性 |
| 161 | - this.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | ||
| 162 | - reqVO.getDeptId(), reqVO.getPostIds()); | ||
| 163 | - | 148 | + this.checkUserExists(reqVO.getId()); |
| 149 | + this.checkEmailUnique(reqVO.getId(), reqVO.getEmail()); | ||
| 150 | + this.checkMobileUnique(reqVO.getId(), reqVO.getMobile()); | ||
| 151 | + // 校验填写密码 | ||
| 152 | + String encode = null; | ||
| 153 | + if (this.checkOldPassword(reqVO.getId(), reqVO.getOldPassword(), reqVO.getNewPassword())) { | ||
| 154 | + // 更新密码 | ||
| 155 | + encode = passwordEncoder.encode(reqVO.getNewPassword()); | ||
| 156 | + } | ||
| 164 | SysUserDO updateObj = SysUserConvert.INSTANCE.convert(reqVO); | 157 | SysUserDO updateObj = SysUserConvert.INSTANCE.convert(reqVO); |
| 165 | - // 校验旧密码 | ||
| 166 | - if (checkOldPassword(reqVO.getId(), reqVO.getOldPassword(), reqVO.getNewPassword())) { | ||
| 167 | - return userMapper.updateById(updateObj); | 158 | + if (StrUtil.isNotBlank(encode)) { |
| 159 | + updateObj.setPassword(encode); | ||
| 168 | } | 160 | } |
| 169 | - | ||
| 170 | - String encode = passwordEncoder.encode(reqVO.getNewPassword()); | ||
| 171 | - updateObj.setPassword(encode); | ||
| 172 | - return userMapper.updateById(updateObj); | 161 | + userMapper.updateById(updateObj); |
| 173 | } | 162 | } |
| 174 | 163 | ||
| 175 | @Override | 164 | @Override |
| @@ -314,9 +303,17 @@ public class SysUserServiceImpl implements SysUserService { | @@ -314,9 +303,17 @@ public class SysUserServiceImpl implements SysUserService { | ||
| 314 | }); | 303 | }); |
| 315 | } | 304 | } |
| 316 | 305 | ||
| 306 | + /** | ||
| 307 | + * 校验旧密码、新密码 | ||
| 308 | + * | ||
| 309 | + * @param id 用户 id | ||
| 310 | + * @param oldPassword 旧密码 | ||
| 311 | + * @param newPassword 新密码 | ||
| 312 | + * @return 校验结果 | ||
| 313 | + */ | ||
| 317 | private boolean checkOldPassword(Long id, String oldPassword, String newPassword) { | 314 | private boolean checkOldPassword(Long id, String oldPassword, String newPassword) { |
| 318 | if (id == null || StrUtil.isBlank(oldPassword) || StrUtil.isBlank(newPassword)) { | 315 | if (id == null || StrUtil.isBlank(oldPassword) || StrUtil.isBlank(newPassword)) { |
| 319 | - return true; | 316 | + return false; |
| 320 | } | 317 | } |
| 321 | SysUserDO user = userMapper.selectById(id); | 318 | SysUserDO user = userMapper.selectById(id); |
| 322 | if (user == null) { | 319 | if (user == null) { |
| @@ -326,11 +323,11 @@ public class SysUserServiceImpl implements SysUserService { | @@ -326,11 +323,11 @@ public class SysUserServiceImpl implements SysUserService { | ||
| 326 | if (!passwordEncoder.matches(oldPassword, user.getPassword())) { | 323 | if (!passwordEncoder.matches(oldPassword, user.getPassword())) { |
| 327 | throw ServiceExceptionUtil.exception(USER_PASSWORD_FAILED); | 324 | throw ServiceExceptionUtil.exception(USER_PASSWORD_FAILED); |
| 328 | } | 325 | } |
| 329 | - return false; | 326 | + return true; |
| 330 | } | 327 | } |
| 331 | 328 | ||
| 332 | @Override | 329 | @Override |
| 333 | - @Transactional // 添加事务,异常则回滚所有导入 | 330 | + @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入 |
| 334 | public SysUserImportRespVO importUsers(List<SysUserImportExcelVO> importUsers, boolean isUpdateSupport) { | 331 | public SysUserImportRespVO importUsers(List<SysUserImportExcelVO> importUsers, boolean isUpdateSupport) { |
| 335 | if (CollUtil.isEmpty(importUsers)) { | 332 | if (CollUtil.isEmpty(importUsers)) { |
| 336 | throw ServiceExceptionUtil.exception(USER_IMPORT_LIST_IS_EMPTY); | 333 | throw ServiceExceptionUtil.exception(USER_IMPORT_LIST_IS_EMPTY); |
| @@ -368,20 +365,15 @@ public class SysUserServiceImpl implements SysUserService { | @@ -368,20 +365,15 @@ public class SysUserServiceImpl implements SysUserService { | ||
| 368 | } | 365 | } |
| 369 | 366 | ||
| 370 | @Override | 367 | @Override |
| 371 | - public int updateAvatar(Long id, MultipartFile avatarFile) { | 368 | + public void updateAvatar(Long id, InputStream avatarFile) { |
| 372 | this.checkUserExists(id); | 369 | this.checkUserExists(id); |
| 373 | // 存储文件 | 370 | // 存储文件 |
| 374 | - String avatar = null; | ||
| 375 | - try { | ||
| 376 | - avatar = fileService.createFile(avatarFile.getOriginalFilename(), IoUtil.readBytes(avatarFile.getInputStream())); | ||
| 377 | - } catch (IOException e) { | ||
| 378 | - throw ServiceExceptionUtil.exception(FILE_UPLOAD_FAILED); | ||
| 379 | - } | 371 | + String avatar = fileService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile)); |
| 380 | // 更新路径 | 372 | // 更新路径 |
| 381 | SysUserDO sysUserDO = new SysUserDO(); | 373 | SysUserDO sysUserDO = new SysUserDO(); |
| 382 | sysUserDO.setId(id); | 374 | sysUserDO.setId(id); |
| 383 | sysUserDO.setAvatar(avatar); | 375 | sysUserDO.setAvatar(avatar); |
| 384 | - return userMapper.updateById(sysUserDO); | 376 | + userMapper.updateById(sysUserDO); |
| 385 | } | 377 | } |
| 386 | 378 | ||
| 387 | } | 379 | } |
src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java
| @@ -109,7 +109,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | @@ -109,7 +109,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | ||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | @Override | 111 | @Override |
| 112 | - @Transactional | 112 | + @Transactional(rollbackFor = Exception.class) |
| 113 | public List<Long> createCodegenListFromDB(List<String> tableNames) { | 113 | public List<Long> createCodegenListFromDB(List<String> tableNames) { |
| 114 | List<Long> ids = new ArrayList<>(tableNames.size()); | 114 | List<Long> ids = new ArrayList<>(tableNames.size()); |
| 115 | // 遍历添加。虽然效率会低一点,但是没必要做成完全批量,因为不会这么大量 | 115 | // 遍历添加。虽然效率会低一点,但是没必要做成完全批量,因为不会这么大量 |
| @@ -118,7 +118,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | @@ -118,7 +118,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | ||
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | @Override | 120 | @Override |
| 121 | - @Transactional | 121 | + @Transactional(rollbackFor = Exception.class) |
| 122 | public void updateCodegen(ToolCodegenUpdateReqVO updateReqVO) { | 122 | public void updateCodegen(ToolCodegenUpdateReqVO updateReqVO) { |
| 123 | // 校验是否已经存在 | 123 | // 校验是否已经存在 |
| 124 | if (codegenTableMapper.selectById(updateReqVO.getTable().getId()) == null) { | 124 | if (codegenTableMapper.selectById(updateReqVO.getTable().getId()) == null) { |
| @@ -134,7 +134,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | @@ -134,7 +134,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | ||
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | @Override | 136 | @Override |
| 137 | - @Transactional | 137 | + @Transactional(rollbackFor = Exception.class) |
| 138 | public void syncCodegenFromDB(Long tableId) { | 138 | public void syncCodegenFromDB(Long tableId) { |
| 139 | // 校验是否已经存在 | 139 | // 校验是否已经存在 |
| 140 | ToolCodegenTableDO table = codegenTableMapper.selectById(tableId); | 140 | ToolCodegenTableDO table = codegenTableMapper.selectById(tableId); |
| @@ -149,7 +149,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | @@ -149,7 +149,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | ||
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | @Override | 151 | @Override |
| 152 | - @Transactional | 152 | + @Transactional(rollbackFor = Exception.class) |
| 153 | public void syncCodegenFromSQL(Long tableId, String sql) { | 153 | public void syncCodegenFromSQL(Long tableId, String sql) { |
| 154 | // 校验是否已经存在 | 154 | // 校验是否已经存在 |
| 155 | ToolCodegenTableDO table = codegenTableMapper.selectById(tableId); | 155 | ToolCodegenTableDO table = codegenTableMapper.selectById(tableId); |
| @@ -201,7 +201,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | @@ -201,7 +201,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | ||
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | @Override | 203 | @Override |
| 204 | - @Transactional | 204 | + @Transactional(rollbackFor = Exception.class) |
| 205 | public void deleteCodegen(Long tableId) { | 205 | public void deleteCodegen(Long tableId) { |
| 206 | // 校验是否已经存在 | 206 | // 校验是否已经存在 |
| 207 | if (codegenTableMapper.selectById(tableId) == null) { | 207 | if (codegenTableMapper.selectById(tableId) == null) { |
src/main/resources/application-dev.yaml
| @@ -145,7 +145,7 @@ yudao: | @@ -145,7 +145,7 @@ yudao: | ||
| 145 | swagger: | 145 | swagger: |
| 146 | title: 管理后台 | 146 | title: 管理后台 |
| 147 | description: 提供管理员管理的所有功能 | 147 | description: 提供管理员管理的所有功能 |
| 148 | - version: ${yudao.info.base-package} | 148 | + version: ${yudao.info.version} |
| 149 | base-package: ${yudao.info.base-package}.modules | 149 | base-package: ${yudao.info.base-package}.modules |
| 150 | captcha: | 150 | captcha: |
| 151 | timeout: 5m | 151 | timeout: 5m |
src/main/resources/application-local.yaml
| @@ -145,7 +145,7 @@ yudao: | @@ -145,7 +145,7 @@ yudao: | ||
| 145 | swagger: | 145 | swagger: |
| 146 | title: 管理后台 | 146 | title: 管理后台 |
| 147 | description: 提供管理员管理的所有功能 | 147 | description: 提供管理员管理的所有功能 |
| 148 | - version: ${yudao.info.base-package} | 148 | + version: ${yudao.info.version} |
| 149 | base-package: ${yudao.info.base-package}.modules | 149 | base-package: ${yudao.info.base-package}.modules |
| 150 | captcha: | 150 | captcha: |
| 151 | timeout: 5m | 151 | timeout: 5m |