1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.govmade.modules.system.controller;
import java.util.Map;
import java.util.Set;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.govmade.common.utils.Constant;
import com.govmade.common.utils.PageUtils;
import com.govmade.common.utils.R;
import com.govmade.common.utils.ShiroUtils;
import com.govmade.modules.basic.controller.AbstractController;
import com.govmade.modules.system.entity.UserEntity;
import com.govmade.modules.system.service.UserService;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import io.swagger.annotations.ApiOperation;
/**
* 系统管理 - 用户设置
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月3日
*/
@RestController
@RequestMapping("/system/user")
public class UserController extends AbstractController {
@Autowired
private UserService userService;
/**
* 保存或更新用户
*/
@PostMapping("/save")
public R save(UserEntity ue) {
if (null == ue.getId()) {
if (this.userService.checkUser(ue.getUsername()) > 0) {
return R.error(ue.getUsername() + " 已存在!");
}
String password = SecureUtil.md5("123456");
ue.setPassword(password);
}
userService.save(ue);
return R.ok();
}
/**
* 用户列表
*/
@GetMapping("/list")
public R list(@RequestParam Map<String, Object> params) {
// 只有超级管理员,才能查看所有用户列表
if (getUserId() == Constant.SUPER_ADMIN) {
params.put("createBy", getUserId());
} else {
//params.put("deptId", getUser().getDeptId()); // 部门管理员,查看本部门用户列表
}
PageUtils page = userService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 根据ID查询用户
*
* @param id
* @return
*/
@GetMapping("info/{id}")
public R info(@PathVariable("id") Long id) {
return R.ok().put("user", userService.queryById(id));
}
/**
* 删除、批量删除用户
*
* @param ids
* @return
*/
@DeleteMapping("/delete")
public R deleteUser(@RequestParam Set<Long> ids) {
userService.deleteBatchIds(ids);
return R.ok();
}
/**
* 重置密码
* @param id
* @return
*/
@PostMapping("/reset")
public R reset(UserEntity ue) {
if (null != ue.getId()) {
String password = SecureUtil.md5("123456");
ue.setPassword(password);
userService.updateById(ue);
}
return R.ok();
}
/**
* 修改登录用户密码
*/
@PutMapping("updatePassword")
public R password(String password, String newPassword) {
password = new Sha256Hash(password).toHex();
newPassword = new Sha256Hash(newPassword).toHex();
//int count = userService.updatePassword(ShiroUtils.getUserId(), password, newPassword);
// if (count == 0) {
// return R.error("原密码不正确");
// }
ShiroUtils.logout();
return R.ok();
}
}