|
@@ -39,15 +39,16 @@ import com.boman.domain.SysRole;
|
|
|
import com.boman.domain.SysUser;
|
|
|
import com.boman.system.api.model.LoginUser;
|
|
|
|
|
|
+import static com.boman.common.core.utils.SecurityUtils.checkStrongPwd;
|
|
|
+
|
|
|
/**
|
|
|
* 用户信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/user")
|
|
|
-public class SysUserController extends BaseController
|
|
|
-{
|
|
|
+public class SysUserController extends BaseController {
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(SysUserController.class);
|
|
|
@Autowired
|
|
@@ -70,8 +71,7 @@ public class SysUserController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize(hasPermi = "system:user:list")
|
|
|
@GetMapping("/list")
|
|
|
- public TableDataInfo list(SysUser user)
|
|
|
- {
|
|
|
+ public TableDataInfo list(SysUser user) {
|
|
|
startPage();
|
|
|
List<SysUser> list = userService.selectUserList(user);
|
|
|
return getDataTable(list);
|
|
@@ -86,8 +86,7 @@ public class SysUserController extends BaseController
|
|
|
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
|
|
@PreAuthorize(hasPermi = "system:user:export")
|
|
|
@PostMapping("/export")
|
|
|
- public void export(HttpServletResponse response, SysUser user) throws IOException
|
|
|
- {
|
|
|
+ public void export(HttpServletResponse response, SysUser user) throws IOException {
|
|
|
List<SysUser> list = userService.selectUserList(user);
|
|
|
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
|
|
util.exportExcel(response, list, "用户数据");
|
|
@@ -96,8 +95,7 @@ public class SysUserController extends BaseController
|
|
|
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
|
|
@PreAuthorize(hasPermi = "system:user:import")
|
|
|
@PostMapping("/importData")
|
|
|
- public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
|
|
|
- {
|
|
|
+ public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
|
|
|
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
|
|
List<SysUser> userList = util.importExcel(file.getInputStream());
|
|
|
String operName = SecurityUtils.getUsername();
|
|
@@ -106,8 +104,7 @@ public class SysUserController extends BaseController
|
|
|
}
|
|
|
|
|
|
@PostMapping("/importTemplate")
|
|
|
- public void importTemplate(HttpServletResponse response) throws IOException
|
|
|
- {
|
|
|
+ public void importTemplate(HttpServletResponse response) throws IOException {
|
|
|
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
|
|
util.importTemplateExcel(response, "用户数据");
|
|
|
}
|
|
@@ -176,12 +173,11 @@ public class SysUserController extends BaseController
|
|
|
|
|
|
/**
|
|
|
* 获取用户信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @return 用户信息
|
|
|
*/
|
|
|
@GetMapping("getInfo")
|
|
|
- public AjaxResult getInfo()
|
|
|
- {
|
|
|
+ public AjaxResult getInfo() {
|
|
|
Long id = SecurityUtils.getUserId();
|
|
|
// 角色集合
|
|
|
Set<String> roles = permissionService.getRolePermission(id);
|
|
@@ -198,15 +194,13 @@ public class SysUserController extends BaseController
|
|
|
* 根据用户编号获取详细信息
|
|
|
*/
|
|
|
@PreAuthorize(hasPermi = "system:user:query")
|
|
|
- @GetMapping(value = { "/", "/{id}" })
|
|
|
- public AjaxResult getInfo(@PathVariable(value = "id", required = false) Long id)
|
|
|
- {
|
|
|
+ @GetMapping(value = {"/", "/{id}"})
|
|
|
+ public AjaxResult getInfo(@PathVariable(value = "id", required = false) Long id) {
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
List<SysRole> roles = roleService.selectRoleAll();
|
|
|
ajax.put("roles", SysUser.isAdmin(id) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
|
|
ajax.put("posts", postService.selectPostAll());
|
|
|
- if (StringUtils.isNotNull(id))
|
|
|
- {
|
|
|
+ if (StringUtils.isNotNull(id)) {
|
|
|
ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(id));
|
|
|
ajax.put("postIds", postService.selectPostListById(id));
|
|
|
ajax.put("roleIds", roleService.selectRoleListById(id));
|
|
@@ -220,21 +214,17 @@ public class SysUserController extends BaseController
|
|
|
@PreAuthorize(hasPermi = "system:user:add")
|
|
|
@Log(title = "用户管理", businessType = BusinessType.INSERT)
|
|
|
@PostMapping
|
|
|
- public AjaxResult add(@Validated @RequestBody SysUser user)
|
|
|
- {
|
|
|
- if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName())))
|
|
|
- {
|
|
|
+ public AjaxResult add(@Validated @RequestBody SysUser user) {
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName()))) {
|
|
|
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
|
|
- }
|
|
|
- else if (StringUtils.isNotEmpty(user.getPhonenumber())
|
|
|
- && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
|
|
- {
|
|
|
+ } else if (StringUtils.isNotEmpty(user.getPhonenumber())
|
|
|
+ && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
|
|
|
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
|
|
- }
|
|
|
- else if (StringUtils.isNotEmpty(user.getEmail())
|
|
|
- && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
|
|
- {
|
|
|
+ } else if (StringUtils.isNotEmpty(user.getEmail())
|
|
|
+ && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
|
|
|
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
|
|
+ } else if ("1".equals(checkStrongPwd(user.getPassword()))) {
|
|
|
+ return AjaxResult.error("密码必须包含数字、大小写字母、特殊符号且大于8位");
|
|
|
}
|
|
|
user.setCreateBy(SecurityUtils.getUsername());
|
|
|
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
|
@@ -247,17 +237,13 @@ public class SysUserController extends BaseController
|
|
|
@PreAuthorize(hasPermi = "system:user:edit")
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping
|
|
|
- public AjaxResult edit(@Validated @RequestBody SysUser user)
|
|
|
- {
|
|
|
+ public AjaxResult edit(@Validated @RequestBody SysUser user) {
|
|
|
//userService.checkUserAllowed(user);
|
|
|
if (StringUtils.isNotEmpty(user.getPhonenumber())
|
|
|
- && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
|
|
- {
|
|
|
+ && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
|
|
|
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
|
|
- }
|
|
|
- else if (StringUtils.isNotEmpty(user.getEmail())
|
|
|
- && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
|
|
- {
|
|
|
+ } else if (StringUtils.isNotEmpty(user.getEmail())
|
|
|
+ && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
|
|
|
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
|
|
}
|
|
|
user.setUpdateBy(SecurityUtils.getUsername());
|
|
@@ -270,8 +256,7 @@ public class SysUserController extends BaseController
|
|
|
@PreAuthorize(hasPermi = "system:user:remove")
|
|
|
@Log(title = "用户管理", businessType = BusinessType.DELETE)
|
|
|
@DeleteMapping("/{ids}")
|
|
|
- public AjaxResult remove(@PathVariable Long[] ids)
|
|
|
- {
|
|
|
+ public AjaxResult remove(@PathVariable Long[] ids) {
|
|
|
return toAjax(userService.deleteUserByIds(ids));
|
|
|
}
|
|
|
|
|
@@ -281,9 +266,11 @@ public class SysUserController extends BaseController
|
|
|
@PreAuthorize(hasPermi = "system:user:edit")
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping("/resetPwd")
|
|
|
- public AjaxResult resetPwd(@RequestBody SysUser user)
|
|
|
- {
|
|
|
+ public AjaxResult resetPwd(@RequestBody SysUser user) {
|
|
|
//userService.checkUserAllowed(user);
|
|
|
+ if ("1".equals(checkStrongPwd(user.getPassword()))) {
|
|
|
+ return AjaxResult.error("密码必须包含数字、大小写字母、特殊符号且大于8位");
|
|
|
+ }
|
|
|
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
|
|
user.setUpdateBy(SecurityUtils.getUsername());
|
|
|
return toAjax(userService.resetPwd(user));
|
|
@@ -295,8 +282,7 @@ public class SysUserController extends BaseController
|
|
|
@PreAuthorize(hasPermi = "system:user:edit")
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping("/changeStatus")
|
|
|
- public AjaxResult changeStatus(@RequestBody SysUser user)
|
|
|
- {
|
|
|
+ public AjaxResult changeStatus(@RequestBody SysUser user) {
|
|
|
userService.checkUserAllowed(user);
|
|
|
user.setUpdateBy(SecurityUtils.getUsername());
|
|
|
return toAjax(userService.updateUserStatus(user));
|
|
@@ -309,17 +295,18 @@ public class SysUserController extends BaseController
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
@PostMapping("/listByDeptId")
|
|
|
public List<SysUser> listByDeptId(@RequestBody List<Long> deptIdList) {
|
|
|
- return userService.listByDeptId(deptIdList);
|
|
|
+ return userService.listByDeptId(deptIdList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 为用户档案定制新增接口
|
|
|
+ *
|
|
|
* @param result 结果
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/addUser")
|
|
|
public void addUser(@Validated @RequestBody List<JSONObject> result) {
|
|
|
- userService.addUser(result);
|
|
|
+ userService.addUser(result);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -327,8 +314,7 @@ public class SysUserController extends BaseController
|
|
|
* 获取全部用户列表
|
|
|
*/
|
|
|
@GetMapping("/userListAll")
|
|
|
- public List<SysUser> selectUserListAll()
|
|
|
- {
|
|
|
+ public List<SysUser> selectUserListAll() {
|
|
|
return userService.selectUserListAll();
|
|
|
}
|
|
|
|
|
@@ -339,7 +325,7 @@ public class SysUserController extends BaseController
|
|
|
* @return com.boman.domain.SysUser
|
|
|
*/
|
|
|
@GetMapping("/queryByOpenId/{openId}")
|
|
|
- public SysUser queryByOpenId(@PathVariable("openId") String openId){
|
|
|
+ public SysUser queryByOpenId(@PathVariable("openId") String openId) {
|
|
|
return userService.queryByOpenId(openId);
|
|
|
}
|
|
|
|
|
@@ -352,9 +338,7 @@ public class SysUserController extends BaseController
|
|
|
@GetMapping("/getByPhone/{phone}")
|
|
|
public SysUser getByPhone(@PathVariable("phone") String phone) {
|
|
|
SysUser sysUser = userService.getByPhone(phone);
|
|
|
- LOGGER.info("getByPhone: 请求结果:{}",JSON.toJSONString(sysUser));
|
|
|
+ LOGGER.info("getByPhone: 请求结果:{}", JSON.toJSONString(sysUser));
|
|
|
return ObjectUtils.requireNonNull(sysUser, String.format("手机号 [%s] 对应的用户不存在", phone));
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|