deat: 用户删除功能完成

This commit is contained in:
萌狼蓝天 2024-11-06 17:16:36 +08:00
parent 19300abbd4
commit 223bbc904c
8 changed files with 75 additions and 0 deletions

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -13,6 +13,9 @@ public class ResponseResult<T> {
private Integer code; // 消息代码不填写默认1
private String msg; // 消息内容不填写默认"success"
private T data; // 数据内容可以为空
public static <T> ResponseResult<T> success() {
return success(null, "ok");
}
public static <T> ResponseResult<T> success(T data) {
return success(data, "success");
}

View File

@ -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<UserInfo> {
*/
@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);
}

View File

@ -13,4 +13,6 @@ public interface AuthService {
ResponseResult getRoleAll();
ResponseResult updateRole(SystemRole systemRole);
ResponseResult addRole(SystemRole role);
}

View File

@ -19,4 +19,8 @@ public interface UserService {
ResponseResult registerUser(ParamUserAdd userAddParam);
ResponseResult updateUser(ParamUserAdd userAddParam);
ResponseResult deleteUser(ParamUserAdd userAddParam);
ResponseResult deleteUserReay(ParamUserAdd userAddParam);
}

View File

@ -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));
}
}

View File

@ -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);