Commit 8921556d75c631fc52e51f2e0b6dfb28eb430cb4

Authored by YunaiV
1 parent e3884ee5

完成用户的重置密码、删除、修改状态的对接

ruoyi-ui/src/api/system/user.js
... ... @@ -54,27 +54,27 @@ export function exportUser(query) {
54 54 }
55 55  
56 56 // 用户密码重置
57   -export function resetUserPwd(userId, password) {
  57 +export function resetUserPwd(id, password) {
58 58 const data = {
59   - userId,
  59 + id,
60 60 password
61 61 }
62 62 return request({
63   - url: '/system/user/resetPwd',
64   - method: 'put',
  63 + url: '/system/user/update-password',
  64 + method: 'post',
65 65 data: data
66 66 })
67 67 }
68 68  
69 69 // 用户状态修改
70   -export function changeUserStatus(userId, status) {
  70 +export function changeUserStatus(id, status) {
71 71 const data = {
72   - userId,
  72 + id,
73 73 status
74 74 }
75 75 return request({
76   - url: '/system/user/updateStatus',
77   - method: 'put',
  76 + url: '/system/user/update-status',
  77 + method: 'post',
78 78 data: data
79 79 })
80 80 }
... ...
ruoyi-ui/src/views/system/user/index.vue
... ... @@ -480,7 +480,7 @@ export default {
480 480 },
481 481 // 用户状态修改
482 482 handleStatusChange(row) {
483   - let text = row.status === "0" ? "启用" : "停用";
  483 + let text = row.status === SysCommonStatusEnum.ENABLE ? "启用" : "停用";
484 484 this.$confirm('确认要"' + text + '""' + row.username + '"用户吗?', "警告", {
485 485 confirmButtonText: "确定",
486 486 cancelButtonText: "取消",
... ... @@ -490,7 +490,8 @@ export default {
490 490 }).then(() => {
491 491 this.msgSuccess(text + "成功");
492 492 }).catch(function() {
493   - row.status = row.status === "0" ? "1" : "0";
  493 + row.status = row.status === SysCommonStatusEnum.ENABLE ? SysCommonStatusEnum.DISABLE
  494 + : SysCommonStatusEnum.ENABLE;
494 495 });
495 496 },
496 497 // 取消按钮
... ... @@ -518,7 +519,7 @@ export default {
518 519 },
519 520 /** 搜索按钮操作 */
520 521 handleQuery() {
521   - this.queryParams.page = 1;
  522 + this.queryParams.pageNo = 1;
522 523 this.getList();
523 524 },
524 525 /** 重置按钮操作 */
... ...
src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java
... ... @@ -88,6 +88,34 @@ public class SysUserController {
88 88 return success(true);
89 89 }
90 90  
  91 + @ApiOperation("删除用户")
  92 + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024")
  93 + @PostMapping("/delete")
  94 +// @PreAuthorize("@ss.hasPermi('system:user:remove')")
  95 +// @Log(title = "用户管理", businessType = BusinessType.DELETE)
  96 + public CommonResult<Boolean> deleteUser(@RequestParam("id") Long id) {
  97 + userService.deleteUser(id);
  98 + return success(true);
  99 + }
  100 +
  101 + @ApiOperation("重置用户密码")
  102 + @PostMapping("/update-password")
  103 +// @PreAuthorize("@ss.hasPermi('system:user:resetPwd')")
  104 +// @Log(title = "用户管理", businessType = BusinessType.UPDATE)
  105 + public CommonResult<Boolean> updateUserPassword(@Validated @RequestBody SysUserUpdatePasswordReqVO reqVO) {
  106 + userService.updateUserPassword(reqVO.getId(), reqVO.getPassword());
  107 + return success(true);
  108 + }
  109 +
  110 + @ApiOperation("修改用户状态")
  111 + @PostMapping("/update-status")
  112 +// @PreAuthorize("@ss.hasPermi('system:user:edit')")
  113 +// @Log(title = "用户管理", businessType = BusinessType.UPDATE)
  114 + public CommonResult<Boolean> updateUserStatus(@Validated @RequestBody SysUserUpdateStatusReqVO reqVO) {
  115 + userService.updateUserStatus(reqVO.getId(), reqVO.getStatus());
  116 + return success(true);
  117 + }
  118 +
91 119 // @Log(title = "用户管理", businessType = BusinessType.EXPORT)
92 120 // @PreAuthorize("@ss.hasPermi('system:user:export')")
93 121 // @GetMapping("/export")
... ... @@ -119,43 +147,4 @@ public class SysUserController {
119 147 // }
120 148 //
121 149  
122   -
123   -// /**
124   -// * 删除用户
125   -// */
126   -// @PreAuthorize("@ss.hasPermi('system:user:remove')")
127   -// @Log(title = "用户管理", businessType = BusinessType.DELETE)
128   -// @DeleteMapping("/{userIds}")
129   -// public AjaxResult remove(@PathVariable Long[] userIds)
130   -// {
131   -// return toAjax(userService.deleteUserByIds(userIds));
132   -// }
133   -//
134   -// /**
135   -// * 重置密码
136   -// */
137   -// @PreAuthorize("@ss.hasPermi('system:user:resetPwd')")
138   -// @Log(title = "用户管理", businessType = BusinessType.UPDATE)
139   -// @PutMapping("/resetPwd")
140   -// public AjaxResult resetPwd(@RequestBody SysUser user)
141   -// {
142   -// userService.checkUserAllowed(user);
143   -// user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
144   -// user.setUpdateBy(SecurityUtils.getUsername());
145   -// return toAjax(userService.resetPwd(user));
146   -// }
147   -//
148   -// /**
149   -// * 状态修改
150   -// */
151   -// @PreAuthorize("@ss.hasPermi('system:user:edit')")
152   -// @Log(title = "用户管理", businessType = BusinessType.UPDATE)
153   -// @PutMapping("/changeStatus")
154   -// public AjaxResult changeStatus(@RequestBody SysUser user)
155   -// {
156   -// userService.checkUserAllowed(user);
157   -// user.setUpdateBy(SecurityUtils.getUsername());
158   -// return toAjax(userService.updateUserStatus(user));
159   -// }
160   -
161 150 }
... ...
src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserUpdatePasswordReqVO.java 0 → 100644
  1 +package cn.iocoder.dashboard.modules.system.controller.user.vo.user;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import org.hibernate.validator.constraints.Length;
  8 +
  9 +import javax.validation.constraints.NotEmpty;
  10 +import javax.validation.constraints.NotNull;
  11 +
  12 +@ApiModel("用户更新密码 Request VO")
  13 +@Data
  14 +public class SysUserUpdatePasswordReqVO {
  15 +
  16 + @ApiModelProperty(value = "用户编号", required = true, example = "1024")
  17 + @NotNull(message = "用户编号不能为空")
  18 + private Long id;
  19 +
  20 + @ApiModelProperty(value = "密码", required = true, example = "123456")
  21 + @NotEmpty(message = "密码不能为空")
  22 + @Length(min = 4, max = 16, message = "密码长度为 4-16 位")
  23 + private String password;
  24 +
  25 +}
... ...
src/main/java/cn/iocoder/dashboard/modules/system/service/permission/SysPermissionService.java
... ... @@ -69,7 +69,7 @@ public interface SysPermissionService {
69 69 void assignRoleDataScope(Long roleId, Integer dataScope, Set<Long> dataScopeDeptIds);
70 70  
71 71 /**
72   - * 处理角色删除时,删除关联授权角色
  72 + * 处理角色删除时,删除关联授权数据
73 73 *
74 74 * @param roleId 角色编号
75 75 */
... ... @@ -82,4 +82,11 @@ public interface SysPermissionService {
82 82 */
83 83 void processMenuDeleted(Long menuId);
84 84  
  85 + /**
  86 + * 处理用户删除是,删除关联授权数据
  87 + *
  88 + * @param userId 用户编号
  89 + */
  90 + void processUserDeleted(Long userId);
  91 +
85 92 }
... ...
src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java
... ... @@ -161,4 +161,9 @@ public class SysPermissionServiceImpl implements SysPermissionService {
161 161 // TODO 实现我
162 162 }
163 163  
  164 + @Override
  165 + public void processUserDeleted(Long userId) {
  166 + // TODO 实现我
  167 + }
  168 +
164 169 }
... ...
src/main/java/cn/iocoder/dashboard/modules/system/service/user/SysUserService.java
... ... @@ -59,6 +59,29 @@ public interface SysUserService {
59 59 */
60 60 void updateUser(SysUserUpdateReqVO reqVO);
61 61  
  62 + /**
  63 + * 删除用户
  64 + *
  65 + * @param id 用户编号
  66 + */
  67 + void deleteUser(Long id);
  68 +
  69 + /**
  70 + * 修改密码
  71 + *
  72 + * @param id 用户编号
  73 + * @param password 密码
  74 + */
  75 + void updateUserPassword(Long id, String password);
  76 +
  77 + /**
  78 + * 修改密码
  79 + *
  80 + * @param id 用户编号
  81 + * @param status 状态
  82 + */
  83 + void updateUserStatus(Long id, Integer status);
  84 +
62 85 //
63 86 // /**
64 87 // * 根据用户ID查询用户所属角色组
... ...
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;
15 15 import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO;
16 16 import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService;
17 17 import cn.iocoder.dashboard.modules.system.service.dept.SysPostService;
  18 +import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService;
18 19 import cn.iocoder.dashboard.util.collection.CollectionUtils;
19 20 import lombok.extern.slf4j.Slf4j;
20 21 import org.springframework.security.crypto.password.PasswordEncoder;
... ... @@ -45,19 +46,12 @@ public class SysUserServiceImpl implements SysUserService {
45 46 private SysDeptService deptService;
46 47 @Resource
47 48 private SysPostService postService;
  49 + @Resource
  50 + private SysPermissionService permissionService;
48 51  
49 52 @Resource
50 53 private PasswordEncoder passwordEncoder;
51 54  
52   -// @Autowired
53   -// private SysUserRoleMapper userRoleMapper;
54   -//
55   -// @Autowired
56   -// private SysUserPostMapper userPostMapper;
57   -//
58   -// @Autowired
59   -// private ISysConfigService configService;
60   -
61 55 // /**
62 56 // * 根据条件分页查询用户列表
63 57 // *
... ... @@ -117,6 +111,38 @@ public class SysUserServiceImpl implements SysUserService {
117 111 userMapper.updateById(updateObj);
118 112 }
119 113  
  114 + @Override
  115 + public void deleteUser(Long id) {
  116 + // 校验用户存在
  117 + this.checkUserExists(id);
  118 + // 删除用户
  119 + userMapper.deleteById(id);
  120 + }
  121 +
  122 + @Override
  123 + public void updateUserPassword(Long id, String password) {
  124 + // 校验用户存在
  125 + this.checkUserExists(id);
  126 + // 更新密码
  127 + SysUserDO updateObj = new SysUserDO();
  128 + updateObj.setId(id);
  129 + updateObj.setPassword(passwordEncoder.encode(password)); // 加密密码
  130 + userMapper.updateById(updateObj);
  131 + }
  132 +
  133 + @Override
  134 + public void updateUserStatus(Long id, Integer status) {
  135 + // 校验用户存在
  136 + this.checkUserExists(id);
  137 + // 更新状态
  138 + SysUserDO updateObj = new SysUserDO();
  139 + updateObj.setId(id);
  140 + updateObj.setStatus(status);
  141 + userMapper.updateById(updateObj);
  142 + // 删除用户关联数据
  143 + permissionService.processUserDeleted(id);
  144 + }
  145 +
120 146 private void checkCreateOrUpdate(Long id, String username, String mobile, String email,
121 147 Long deptId, Set<Long> postIds) {
122 148 // 校验用户存在
... ... @@ -253,50 +279,6 @@ public class SysUserServiceImpl implements SysUserService {
253 279 // }
254 280 // }
255 281 // }
256   -//
257   -// /**
258   -// * 新增用户岗位信息
259   -// *
260   -// * @param user 用户对象
261   -// */
262   -// public void insertUserPost(SysUser user)
263   -// {
264   -// Long[] posts = user.getPostIds();
265   -// if (StringUtils.isNotNull(posts))
266   -// {
267   -// // 新增用户与岗位管理
268   -// List<SysUserPost> list = new ArrayList<SysUserPost>();
269   -// for (Long postId : posts)
270   -// {
271   -// SysUserPost up = new SysUserPost();
272   -// up.setUserId(user.getUserId());
273   -// up.setPostId(postId);
274   -// list.add(up);
275   -// }
276   -// if (list.size() > 0)
277   -// {
278   -// userPostMapper.batchUserPost(list);
279   -// }
280   -// }
281   -// }
282   -//
283   -// /**
284   -// * 通过用户ID删除用户
285   -// *
286   -// * @param userId 用户ID
287   -// * @return 结果
288   -// */
289   -// @Override
290   -// @Transactional
291   -// public int deleteUserById(Long userId)
292   -// {
293   -// // 删除用户与角色关联
294   -// userRoleMapper.deleteUserRoleByUserId(userId);
295   -// // 删除用户与岗位表
296   -// userPostMapper.deleteUserPostByUserId(userId);
297   -// return userMapper.deleteUserById(userId);
298   -// }
299   -
300 282  
301 283 // /**
302 284 // * 导入用户数据
... ...