diff --git a/src/main/java/com/guaiguailang/harmony/controller/AuthController.java b/src/main/java/com/guaiguailang/harmony/controller/AuthController.java index b6d8c29..e7a3d74 100644 --- a/src/main/java/com/guaiguailang/harmony/controller/AuthController.java +++ b/src/main/java/com/guaiguailang/harmony/controller/AuthController.java @@ -97,8 +97,22 @@ public class AuthController { public ResponseEntity getRoleAll() { return ResponseEntity.ok(authService.getRoleAll()); } + @Operation( + summary = "角色更新", + description = "更新角色信息", + tags = {"权限相关接口"} + ) @PostMapping("/role-update") public ResponseEntity updateRole(@RequestBody SystemRole role) { return ResponseEntity.ok(authService.updateRole(role)); } + @Operation( + summary = "角色新增", + description = "新增角色", + tags = {"权限相关接口"} + ) + @PostMapping("/role-add") + public ResponseEntity addRole(@RequestBody SystemRole role) { + return ResponseEntity.ok(authService.addRole(role)); + } } diff --git a/src/main/java/com/guaiguailang/harmony/controller/UserController.java b/src/main/java/com/guaiguailang/harmony/controller/UserController.java index c244206..67f3b5d 100644 --- a/src/main/java/com/guaiguailang/harmony/controller/UserController.java +++ b/src/main/java/com/guaiguailang/harmony/controller/UserController.java @@ -109,4 +109,17 @@ public class UserController { public ResponseEntity updateUser(@RequestBody ParamUserAdd userAddParam){ return ResponseEntity.ok(userService.updateUser(userAddParam)); } + @Operation( + summary = "用户 删除", + description = "用户逻辑删除", + tags = {"用户相关接口"} + ) + @PostMapping("/delete") + public ResponseEntity deleteUser(@RequestBody ParamUserAdd userAddParam){ + return ResponseEntity.ok(userService.deleteUser(userAddParam)); + } + @PostMapping("/delete-realy") + public ResponseEntity deleteUserRealy(@RequestBody ParamUserAdd userAddParam){ + return ResponseEntity.ok(userService.deleteUserReay(userAddParam)); + } } diff --git a/src/main/java/com/guaiguailang/harmony/domain/vo/ResponseResult.java b/src/main/java/com/guaiguailang/harmony/domain/vo/ResponseResult.java index d60a05c..ebc694d 100644 --- a/src/main/java/com/guaiguailang/harmony/domain/vo/ResponseResult.java +++ b/src/main/java/com/guaiguailang/harmony/domain/vo/ResponseResult.java @@ -13,6 +13,9 @@ public class ResponseResult { private Integer code; // 消息代码,不填写默认1 private String msg; // 消息内容,不填写默认"success" private T data; // 数据内容,可以为空 + public static ResponseResult success() { + return success(null, "ok"); + } public static ResponseResult success(T data) { return success(data, "success"); } diff --git a/src/main/java/com/guaiguailang/harmony/mapper/UserMapper.java b/src/main/java/com/guaiguailang/harmony/mapper/UserMapper.java index 447fc2e..a7d6883 100644 --- a/src/main/java/com/guaiguailang/harmony/mapper/UserMapper.java +++ b/src/main/java/com/guaiguailang/harmony/mapper/UserMapper.java @@ -8,6 +8,7 @@ import com.guaiguailang.harmony.domain.vo.UserListNum; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; import java.util.List; import java.util.Map; @@ -39,4 +40,6 @@ public interface UserMapper extends BaseMapper { */ @Select("select * from system_role where role_id = (select role_id from user_info where user_info.id=#{id})") SystemRole getRoleLevelByUserId(Long id); + @Update("update user_info set deleted=1 where id=#{id}") + Integer changeDelete(Long id); } diff --git a/src/main/java/com/guaiguailang/harmony/service/AuthService.java b/src/main/java/com/guaiguailang/harmony/service/AuthService.java index 286a366..4d9933d 100644 --- a/src/main/java/com/guaiguailang/harmony/service/AuthService.java +++ b/src/main/java/com/guaiguailang/harmony/service/AuthService.java @@ -13,4 +13,6 @@ public interface AuthService { ResponseResult getRoleAll(); ResponseResult updateRole(SystemRole systemRole); + + ResponseResult addRole(SystemRole role); } diff --git a/src/main/java/com/guaiguailang/harmony/service/UserService.java b/src/main/java/com/guaiguailang/harmony/service/UserService.java index 8202d53..e8185e3 100644 --- a/src/main/java/com/guaiguailang/harmony/service/UserService.java +++ b/src/main/java/com/guaiguailang/harmony/service/UserService.java @@ -19,4 +19,8 @@ public interface UserService { ResponseResult registerUser(ParamUserAdd userAddParam); ResponseResult updateUser(ParamUserAdd userAddParam); + + ResponseResult deleteUser(ParamUserAdd userAddParam); + + ResponseResult deleteUserReay(ParamUserAdd userAddParam); } diff --git a/src/main/java/com/guaiguailang/harmony/service/impl/AuthServiceImpl.java b/src/main/java/com/guaiguailang/harmony/service/impl/AuthServiceImpl.java index b123425..6acbe15 100644 --- a/src/main/java/com/guaiguailang/harmony/service/impl/AuthServiceImpl.java +++ b/src/main/java/com/guaiguailang/harmony/service/impl/AuthServiceImpl.java @@ -2,6 +2,7 @@ package com.guaiguailang.harmony.service.impl; import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.util.SaResult; +import com.github.yitter.idgen.YitIdHelper; import com.guaiguailang.harmony.domain.dto.ParamLogin; import com.guaiguailang.harmony.domain.entity.SystemRole; import com.guaiguailang.harmony.domain.entity.UserInfo; @@ -108,4 +109,19 @@ public class AuthServiceImpl implements AuthService { return ResponseResult.error("更新失败"); } } + + @Override + public ResponseResult addRole(SystemRole role) { + // todo 此处可以进行性能优化,获取level从redis中获取 + // 做一个校验,更新的level不能小于操作人的level + Long id = Long.parseLong(StpUtil.getLoginId().toString());// 获取用户id + // 获取level + SystemRole systemRoleCreator = userMapper.getRoleLevelByUserId(id); + if(role.getLevel()<=systemRoleCreator.getLevel()){ + return ResponseResult.error("权限不足"); + } + role.setId(YitIdHelper.nextId()); + // 角色等级校验 + return ResponseResult.success(roleMapper.insert(role)); + } } diff --git a/src/main/java/com/guaiguailang/harmony/service/impl/UserServiceImpl.java b/src/main/java/com/guaiguailang/harmony/service/impl/UserServiceImpl.java index 6c260ce..c489e07 100644 --- a/src/main/java/com/guaiguailang/harmony/service/impl/UserServiceImpl.java +++ b/src/main/java/com/guaiguailang/harmony/service/impl/UserServiceImpl.java @@ -265,6 +265,26 @@ public class UserServiceImpl implements UserService { } } + @Override + public ResponseResult deleteUser(ParamUserAdd userAddParam) { + Integer result = userMapper.changeDelete(userAddParam.getId()); + if (result==1){ + return ResponseResult.success(); + }else { +return ResponseResult.error("删除失败"); + } + } + + @Override + public ResponseResult deleteUserReay(ParamUserAdd userAddParam) { + Integer result = userMapper.deleteById(userAddParam.getId()); + if (result==1){ + return ResponseResult.success(); + }else { + return ResponseResult.error("删除失败"); + } + } + // 方法 public UserInfo getUserByAccount(String username){ return userMapper.getUserByAccount(username);