|
@@ -1,6 +1,9 @@
|
|
package com.backendsys.modules.system.controller;
|
|
package com.backendsys.modules.system.controller;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import cn.hutool.core.util.ClassUtil;
|
|
|
|
+import com.backendsys.aspect.QueryNullCheck;
|
|
import com.backendsys.exception.CustException;
|
|
import com.backendsys.exception.CustException;
|
|
import com.backendsys.modules.common.config.security.enums.SecurityEnum;
|
|
import com.backendsys.modules.common.config.security.enums.SecurityEnum;
|
|
import com.backendsys.modules.common.config.security.utils.SecurityUtil;
|
|
import com.backendsys.modules.common.config.security.utils.SecurityUtil;
|
|
@@ -17,13 +20,18 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
@Validated
|
|
@Validated
|
|
@RestController
|
|
@RestController
|
|
@Tag(name = "系统用户")
|
|
@Tag(name = "系统用户")
|
|
public class SysUserV2Controller {
|
|
public class SysUserV2Controller {
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private SysUserService sysUserService;
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * TODO 1.手机号码字段,需要经过验证码校验,不能用 updateUserInfo 改 (待修改)
|
|
|
|
+ * TODO 2.审核用户,需要单独的表做审核记录,不能直接改字段
|
|
|
|
+ */
|
|
@Autowired
|
|
@Autowired
|
|
private SysUserV2Service sysUserV2Service;
|
|
private SysUserV2Service sysUserV2Service;
|
|
|
|
|
|
@@ -33,7 +41,6 @@ public class SysUserV2Controller {
|
|
public Result getUserList(SysUserDTO sysUserDTO) {
|
|
public Result getUserList(SysUserDTO sysUserDTO) {
|
|
return Result.success().put("data", sysUserV2Service.selectUserList(sysUserDTO));
|
|
return Result.success().put("data", sysUserV2Service.selectUserList(sysUserDTO));
|
|
}
|
|
}
|
|
-
|
|
|
|
@Operation(summary = "获得系统用户列表 (在线的)")
|
|
@Operation(summary = "获得系统用户列表 (在线的)")
|
|
@PreAuthorize("@ss.hasPermi('3.1')")
|
|
@PreAuthorize("@ss.hasPermi('3.1')")
|
|
@GetMapping("/api/v2/system/user/getUserOnlineList")
|
|
@GetMapping("/api/v2/system/user/getUserOnlineList")
|
|
@@ -60,9 +67,7 @@ public class SysUserV2Controller {
|
|
if (user_id != SecurityUtil.getUserId() && !SecurityUtil.hasPermission("3.2.1.2") && !SecurityUtil.isSuper()) {
|
|
if (user_id != SecurityUtil.getUserId() && !SecurityUtil.hasPermission("3.2.1.2") && !SecurityUtil.isSuper()) {
|
|
throw new CustException(SecurityEnum.NOAUTH);
|
|
throw new CustException(SecurityEnum.NOAUTH);
|
|
}
|
|
}
|
|
-
|
|
|
|
return Result.success().put("data", sysUserV2Service.selectUserInfo(user_id));
|
|
return Result.success().put("data", sysUserV2Service.selectUserInfo(user_id));
|
|
-// return Result.success().put("data", sysUserV2Service.selectUserDetail(user_id));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -94,11 +99,6 @@ public class SysUserV2Controller {
|
|
return Result.success().put("data", sysUserV2Service.insertUser(sysUserDTO));
|
|
return Result.success().put("data", sysUserV2Service.insertUser(sysUserDTO));
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * TODO 1.手机号码字段,需要经过验证码校验,不能用 updateUserInfo 改 (待修改)
|
|
|
|
- * TODO 2.审核用户,需要单独的表做审核记录,不能直接改字段
|
|
|
|
- */
|
|
|
|
/**
|
|
/**
|
|
* 权限:
|
|
* 权限:
|
|
* - 编辑用户信息权限 (3.2.3)
|
|
* - 编辑用户信息权限 (3.2.3)
|
|
@@ -110,12 +110,17 @@ public class SysUserV2Controller {
|
|
public Result updateUserInfo(@Validated(SysUserDTO.Update.class) @RequestBody SysUserDTO sysUserDTO) {
|
|
public Result updateUserInfo(@Validated(SysUserDTO.Update.class) @RequestBody SysUserDTO sysUserDTO) {
|
|
|
|
|
|
// - 不传 user_id 时,修改目标为 当前用户
|
|
// - 不传 user_id 时,修改目标为 当前用户
|
|
- if (ObjectUtil.isEmpty(sysUserDTO.getUser_id())) sysUserDTO.setUser_id(SecurityUtil.getUserId());
|
|
|
|
|
|
+ Long user_id = sysUserDTO.getUser_id();
|
|
|
|
+ if (ObjectUtil.isEmpty(user_id)) {
|
|
|
|
+ user_id = SecurityUtil.getUserId();
|
|
|
|
+ sysUserDTO.setUser_id(user_id);
|
|
|
|
+ } else if (!SecurityUtil.getUserId().equals(1L) && user_id.equals(1L)) {
|
|
|
|
+ throw new CustException("不能编辑超管账号");
|
|
|
|
+ }
|
|
|
|
|
|
// 编辑他人的用户信息
|
|
// 编辑他人的用户信息
|
|
// - 编辑自己 (无需权限)
|
|
// - 编辑自己 (无需权限)
|
|
// - 编辑他人 (需要子权限或超级管理员)
|
|
// - 编辑他人 (需要子权限或超级管理员)
|
|
- Long user_id = sysUserDTO.getUser_id();
|
|
|
|
if (user_id != SecurityUtil.getUserId() && !SecurityUtil.hasPermission("3.2.3.2") && !SecurityUtil.isSuper()) {
|
|
if (user_id != SecurityUtil.getUserId() && !SecurityUtil.hasPermission("3.2.3.2") && !SecurityUtil.isSuper()) {
|
|
throw new CustException(SecurityEnum.NOAUTH);
|
|
throw new CustException(SecurityEnum.NOAUTH);
|
|
}
|
|
}
|
|
@@ -127,18 +132,26 @@ public class SysUserV2Controller {
|
|
return Result.success().put("data", sysUserV2Service.updateUserInfo(sysUserDTO));
|
|
return Result.success().put("data", sysUserV2Service.updateUserInfo(sysUserDTO));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 权限:(同上)
|
|
|
|
+ */
|
|
@Operation(summary = "编辑系统用户密码")
|
|
@Operation(summary = "编辑系统用户密码")
|
|
@PreAuthorize("@ss.hasPermi('3.2.3')")
|
|
@PreAuthorize("@ss.hasPermi('3.2.3')")
|
|
@PutMapping("/api/v2/system/user/updateUserPassword")
|
|
@PutMapping("/api/v2/system/user/updateUserPassword")
|
|
public Result updateUserPassword(@Validated(SysUserDTO.UpdatePassword.class) @RequestBody SysUserDTO sysUserDTO) {
|
|
public Result updateUserPassword(@Validated(SysUserDTO.UpdatePassword.class) @RequestBody SysUserDTO sysUserDTO) {
|
|
|
|
|
|
// - 不传 user_id 时,修改目标为 当前用户
|
|
// - 不传 user_id 时,修改目标为 当前用户
|
|
- if (ObjectUtil.isEmpty(sysUserDTO.getUser_id())) sysUserDTO.setUser_id(SecurityUtil.getUserId());
|
|
|
|
|
|
+ Long user_id = sysUserDTO.getUser_id();
|
|
|
|
+ if (ObjectUtil.isEmpty(user_id)) {
|
|
|
|
+ user_id = SecurityUtil.getUserId();
|
|
|
|
+ sysUserDTO.setUser_id(user_id);
|
|
|
|
+ } else if (!SecurityUtil.getUserId().equals(1L) && user_id.equals(1L)) {
|
|
|
|
+ throw new CustException("不能编辑超管账号");
|
|
|
|
+ }
|
|
|
|
|
|
// 编辑他人的用户信息
|
|
// 编辑他人的用户信息
|
|
// - 编辑自己 (无需权限)
|
|
// - 编辑自己 (无需权限)
|
|
// - 编辑他人 (需要子权限或超级管理员)
|
|
// - 编辑他人 (需要子权限或超级管理员)
|
|
- Long user_id = sysUserDTO.getUser_id();
|
|
|
|
if (user_id != SecurityUtil.getUserId() && !SecurityUtil.hasPermission("3.2.3.2") && !SecurityUtil.isSuper()) {
|
|
if (user_id != SecurityUtil.getUserId() && !SecurityUtil.hasPermission("3.2.3.2") && !SecurityUtil.isSuper()) {
|
|
throw new CustException(SecurityEnum.NOAUTH);
|
|
throw new CustException(SecurityEnum.NOAUTH);
|
|
}
|
|
}
|
|
@@ -146,6 +159,17 @@ public class SysUserV2Controller {
|
|
return Result.success().put("data", sysUserV2Service.updateUserPassword(sysUserDTO));
|
|
return Result.success().put("data", sysUserV2Service.updateUserPassword(sysUserDTO));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Operation(summary = "删除系统用户")
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('3.2.4')")
|
|
|
|
+ @DeleteMapping("/api/v2/system/user/deleteUser")
|
|
|
|
+ public Result deleteUser(@Validated(SysUserDTO.Delete.class) @RequestBody SysUserDTO sysUserDTO) {
|
|
|
|
+
|
|
|
|
+ List<Long> user_ids = sysUserDTO.getUser_ids();
|
|
|
|
+ Long my_user_id = SecurityUtil.getUserId();
|
|
|
|
+ if (user_ids.contains(my_user_id)) throw new CustException("不能删除自己的账号");
|
|
|
|
+ if (user_ids.contains(1L)) throw new CustException("不能删除超管账号");
|
|
|
|
|
|
|
|
+ return Result.success().put("data", sysUserV2Service.deleteUser(user_ids));
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|