diff --git a/ruoyi-ui/src/api/system/user.js b/ruoyi-ui/src/api/system/user.js index 28c8d03b04..5d63dd4adf 100644 --- a/ruoyi-ui/src/api/system/user.js +++ b/ruoyi-ui/src/api/system/user.js @@ -54,27 +54,27 @@ export function exportUser(query) { } // 用户密码重置 -export function resetUserPwd(userId, password) { +export function resetUserPwd(id, password) { const data = { - userId, + id, password } return request({ - url: '/system/user/resetPwd', - method: 'put', + url: '/system/user/update-password', + method: 'post', data: data }) } // 用户状态修改 -export function changeUserStatus(userId, status) { +export function changeUserStatus(id, status) { const data = { - userId, + id, status } return request({ - url: '/system/user/updateStatus', - method: 'put', + url: '/system/user/update-status', + method: 'post', data: data }) } diff --git a/ruoyi-ui/src/views/system/user/index.vue b/ruoyi-ui/src/views/system/user/index.vue index 3257a4ac04..749fd2dbd8 100644 --- a/ruoyi-ui/src/views/system/user/index.vue +++ b/ruoyi-ui/src/views/system/user/index.vue @@ -480,7 +480,7 @@ export default { }, // 用户状态修改 handleStatusChange(row) { - let text = row.status === "0" ? "启用" : "停用"; + let text = row.status === SysCommonStatusEnum.ENABLE ? "启用" : "停用"; this.$confirm('确认要"' + text + '""' + row.username + '"用户吗?', "警告", { confirmButtonText: "确定", cancelButtonText: "取消", @@ -490,7 +490,8 @@ export default { }).then(() => { this.msgSuccess(text + "成功"); }).catch(function() { - row.status = row.status === "0" ? "1" : "0"; + row.status = row.status === SysCommonStatusEnum.ENABLE ? SysCommonStatusEnum.DISABLE + : SysCommonStatusEnum.ENABLE; }); }, // 取消按钮 @@ -518,7 +519,7 @@ export default { }, /** 搜索按钮操作 */ handleQuery() { - this.queryParams.page = 1; + this.queryParams.pageNo = 1; this.getList(); }, /** 重置按钮操作 */ diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java index d330758024..1a62885173 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java @@ -88,6 +88,34 @@ public class SysUserController { return success(true); } + @ApiOperation("删除用户") + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") + @PostMapping("/delete") +// @PreAuthorize("@ss.hasPermi('system:user:remove')") +// @Log(title = "用户管理", businessType = BusinessType.DELETE) + public CommonResult deleteUser(@RequestParam("id") Long id) { + userService.deleteUser(id); + return success(true); + } + + @ApiOperation("重置用户密码") + @PostMapping("/update-password") +// @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") +// @Log(title = "用户管理", businessType = BusinessType.UPDATE) + public CommonResult updateUserPassword(@Validated @RequestBody SysUserUpdatePasswordReqVO reqVO) { + userService.updateUserPassword(reqVO.getId(), reqVO.getPassword()); + return success(true); + } + + @ApiOperation("修改用户状态") + @PostMapping("/update-status") +// @PreAuthorize("@ss.hasPermi('system:user:edit')") +// @Log(title = "用户管理", businessType = BusinessType.UPDATE) + public CommonResult updateUserStatus(@Validated @RequestBody SysUserUpdateStatusReqVO reqVO) { + userService.updateUserStatus(reqVO.getId(), reqVO.getStatus()); + return success(true); + } + // @Log(title = "用户管理", businessType = BusinessType.EXPORT) // @PreAuthorize("@ss.hasPermi('system:user:export')") // @GetMapping("/export") @@ -119,43 +147,4 @@ public class SysUserController { // } // - -// /** -// * 删除用户 -// */ -// @PreAuthorize("@ss.hasPermi('system:user:remove')") -// @Log(title = "用户管理", businessType = BusinessType.DELETE) -// @DeleteMapping("/{userIds}") -// public AjaxResult remove(@PathVariable Long[] userIds) -// { -// return toAjax(userService.deleteUserByIds(userIds)); -// } -// -// /** -// * 重置密码 -// */ -// @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") -// @Log(title = "用户管理", businessType = BusinessType.UPDATE) -// @PutMapping("/resetPwd") -// public AjaxResult resetPwd(@RequestBody SysUser user) -// { -// userService.checkUserAllowed(user); -// user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); -// user.setUpdateBy(SecurityUtils.getUsername()); -// return toAjax(userService.resetPwd(user)); -// } -// -// /** -// * 状态修改 -// */ -// @PreAuthorize("@ss.hasPermi('system:user:edit')") -// @Log(title = "用户管理", businessType = BusinessType.UPDATE) -// @PutMapping("/changeStatus") -// public AjaxResult changeStatus(@RequestBody SysUser user) -// { -// userService.checkUserAllowed(user); -// user.setUpdateBy(SecurityUtils.getUsername()); -// return toAjax(userService.updateUserStatus(user)); -// } - } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserUpdatePasswordReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserUpdatePasswordReqVO.java new file mode 100644 index 0000000000..10fa4a033c --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserUpdatePasswordReqVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.dashboard.modules.system.controller.user.vo.user; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@ApiModel("用户更新密码 Request VO") +@Data +public class SysUserUpdatePasswordReqVO { + + @ApiModelProperty(value = "用户编号", required = true, example = "1024") + @NotNull(message = "用户编号不能为空") + private Long id; + + @ApiModelProperty(value = "密码", required = true, example = "123456") + @NotEmpty(message = "密码不能为空") + @Length(min = 4, max = 16, message = "密码长度为 4-16 位") + private String password; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysPermissionService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysPermissionService.java index 34de1ac111..aef198f897 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysPermissionService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysPermissionService.java @@ -69,7 +69,7 @@ public interface SysPermissionService { void assignRoleDataScope(Long roleId, Integer dataScope, Set dataScopeDeptIds); /** - * 处理角色删除时,删除关联授权角色 + * 处理角色删除时,删除关联授权数据 * * @param roleId 角色编号 */ @@ -82,4 +82,11 @@ public interface SysPermissionService { */ void processMenuDeleted(Long menuId); + /** + * 处理用户删除是,删除关联授权数据 + * + * @param userId 用户编号 + */ + void processUserDeleted(Long userId); + } 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 40bbd82aff..9a90a46fd5 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 @@ -161,4 +161,9 @@ public class SysPermissionServiceImpl implements SysPermissionService { // TODO 实现我 } + @Override + public void processUserDeleted(Long userId) { + // TODO 实现我 + } + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserService.java index 64ef0527a3..e0d8faee63 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserService.java @@ -59,6 +59,29 @@ public interface SysUserService { */ void updateUser(SysUserUpdateReqVO reqVO); + /** + * 删除用户 + * + * @param id 用户编号 + */ + void deleteUser(Long id); + + /** + * 修改密码 + * + * @param id 用户编号 + * @param password 密码 + */ + void updateUserPassword(Long id, String password); + + /** + * 修改密码 + * + * @param id 用户编号 + * @param status 状态 + */ + void updateUserStatus(Long id, Integer status); + // // /** // * 根据用户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 4001ea6850..66125945b2 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 @@ -15,6 +15,7 @@ import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO; import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; import cn.iocoder.dashboard.modules.system.service.dept.SysPostService; +import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService; import cn.iocoder.dashboard.util.collection.CollectionUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.security.crypto.password.PasswordEncoder; @@ -45,19 +46,12 @@ public class SysUserServiceImpl implements SysUserService { private SysDeptService deptService; @Resource private SysPostService postService; + @Resource + private SysPermissionService permissionService; @Resource private PasswordEncoder passwordEncoder; -// @Autowired -// private SysUserRoleMapper userRoleMapper; -// -// @Autowired -// private SysUserPostMapper userPostMapper; -// -// @Autowired -// private ISysConfigService configService; - // /** // * 根据条件分页查询用户列表 // * @@ -117,6 +111,38 @@ public class SysUserServiceImpl implements SysUserService { userMapper.updateById(updateObj); } + @Override + public void deleteUser(Long id) { + // 校验用户存在 + this.checkUserExists(id); + // 删除用户 + userMapper.deleteById(id); + } + + @Override + public void updateUserPassword(Long id, String password) { + // 校验用户存在 + this.checkUserExists(id); + // 更新密码 + SysUserDO updateObj = new SysUserDO(); + updateObj.setId(id); + updateObj.setPassword(passwordEncoder.encode(password)); // 加密密码 + userMapper.updateById(updateObj); + } + + @Override + public void updateUserStatus(Long id, Integer status) { + // 校验用户存在 + this.checkUserExists(id); + // 更新状态 + SysUserDO updateObj = new SysUserDO(); + updateObj.setId(id); + updateObj.setStatus(status); + userMapper.updateById(updateObj); + // 删除用户关联数据 + permissionService.processUserDeleted(id); + } + private void checkCreateOrUpdate(Long id, String username, String mobile, String email, Long deptId, Set postIds) { // 校验用户存在 @@ -253,50 +279,6 @@ public class SysUserServiceImpl implements SysUserService { // } // } // } -// -// /** -// * 新增用户岗位信息 -// * -// * @param user 用户对象 -// */ -// public void insertUserPost(SysUser user) -// { -// Long[] posts = user.getPostIds(); -// if (StringUtils.isNotNull(posts)) -// { -// // 新增用户与岗位管理 -// List list = new ArrayList(); -// for (Long postId : posts) -// { -// SysUserPost up = new SysUserPost(); -// up.setUserId(user.getUserId()); -// up.setPostId(postId); -// list.add(up); -// } -// if (list.size() > 0) -// { -// userPostMapper.batchUserPost(list); -// } -// } -// } -// -// /** -// * 通过用户ID删除用户 -// * -// * @param userId 用户ID -// * @return 结果 -// */ -// @Override -// @Transactional -// public int deleteUserById(Long userId) -// { -// // 删除用户与角色关联 -// userRoleMapper.deleteUserRoleByUserId(userId); -// // 删除用户与岗位表 -// userPostMapper.deleteUserPostByUserId(userId); -// return userMapper.deleteUserById(userId); -// } - // /** // * 导入用户数据