mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-04 22:41:24 +08:00
Optimized source code structure. Added api document to LoginController
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.Element;
|
||||
import com.cfive.pinnacle.service.permission.IElementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 页面元素 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/element")
|
||||
public class ElementController {
|
||||
private IElementService elementService;
|
||||
|
||||
@Autowired
|
||||
public void setElementService(IElementService elementService) {
|
||||
this.elementService = elementService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllElement() {
|
||||
List<Element> elements = elementService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(elements);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getElement(@PathVariable long id) {
|
||||
LambdaQueryWrapper<Element> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Element::getId, id);
|
||||
Element element = elementService.getOne(wrapper);
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(element);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.File;
|
||||
import com.cfive.pinnacle.service.permission.IFileService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 文件 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/file")
|
||||
public class FileController {
|
||||
private IFileService fileService;
|
||||
|
||||
@Autowired
|
||||
public void setFileService(IFileService fileService) {
|
||||
this.fileService = fileService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllFile() {
|
||||
List<File> files = fileService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(files);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getFile(@PathVariable int id) {
|
||||
LambdaQueryWrapper<File> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(File::getId, id);
|
||||
File file = fileService.getOne(wrapper);
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(file);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.permission.Group;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.permission.IGroupService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户组 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/group")
|
||||
@Tag(name = "用户组", description = "用户组相关接口")
|
||||
public class GroupController {
|
||||
private IGroupService groupService;
|
||||
|
||||
@Autowired
|
||||
public void setGroupService(IGroupService groupService) {
|
||||
this.groupService = groupService;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有用户组")
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:group:all', 'system:group:add', 'system:group:delete', 'system:group:modify', 'system:user:add', 'system:user:modify')")
|
||||
public ResponseResult<List<Group>> getAllGroup() {
|
||||
List<Group> groups = groupService.getAllGroup();
|
||||
return ResponseResult.databaseSelectSuccess(groups);
|
||||
}
|
||||
|
||||
@Operation(summary = "添加用户组")
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('system:group:add')")
|
||||
public ResponseResult<Group> addGroup(@RequestBody Group group) {
|
||||
if (!StringUtils.hasText(group.getName())) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "Name cannot be empty", null);
|
||||
}
|
||||
if (groupService.addGroup(group)) {
|
||||
return ResponseResult.databaseSaveSuccess(group);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "删除用户组")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "用户组ID", in = ParameterIn.PATH)
|
||||
})
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasAuthority('system:group:delete')")
|
||||
public ResponseResult<?> deleteGroup(@PathVariable Long id) {
|
||||
LambdaQueryWrapper<Group> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Group::getId, id);
|
||||
if (groupService.remove(wrapper)) {
|
||||
return ResponseResult.databaseDeleteSuccess();
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "修改用户组")
|
||||
@PutMapping
|
||||
@PreAuthorize("hasAuthority('system:group:modify')")
|
||||
public ResponseResult<Group> modifyGroup(@RequestBody Group group) {
|
||||
if (!StringUtils.hasText(group.getName())) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "Name cannot be empty", null);
|
||||
}
|
||||
if (groupService.modifyGroup(group)) {
|
||||
return ResponseResult.databaseUpdateSuccess(group);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.cfive.pinnacle.entity.User;
|
||||
import com.cfive.pinnacle.entity.permission.User;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.permission.ILoginService;
|
||||
import com.cfive.pinnacle.utils.WebUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -13,6 +14,7 @@ import java.util.HashMap;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@Tag(name = "登录", description = "登录相关接口")
|
||||
public class LoginController {
|
||||
|
||||
private ILoginService loginService;
|
||||
@@ -22,14 +24,16 @@ public class LoginController {
|
||||
this.loginService = loginService;
|
||||
}
|
||||
|
||||
@Operation(summary = "登录")
|
||||
@PostMapping("/login")
|
||||
public ResponseResult login(@RequestBody User user) {
|
||||
public ResponseResult<HashMap<String, String>> login(@RequestBody User user) {
|
||||
HashMap<String, String> hashMap = loginService.login(user);
|
||||
return ResponseResult.build(ResponseCode.LOGIN_SUCCESS, "Login Success", hashMap);
|
||||
}
|
||||
|
||||
@Operation(summary = "登出")
|
||||
@RequestMapping("/logout")
|
||||
public ResponseResult logout(HttpServletRequest request) {
|
||||
public ResponseResult<?> logout(HttpServletRequest request) {
|
||||
boolean result = loginService.logout(request.getHeader("token"));
|
||||
if (result) {
|
||||
return ResponseResult.build(ResponseCode.LOGOUT_SUCCESS, "Logout Success", null);
|
||||
@@ -37,9 +41,4 @@ public class LoginController {
|
||||
return ResponseResult.build(ResponseCode.LOGOUT_FAILED, "Logout Failed", null);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/userInfo")
|
||||
public ResponseResult getUserInfo() {
|
||||
return ResponseResult.success(WebUtil.getLoginUser());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.Menu;
|
||||
import com.cfive.pinnacle.service.permission.IMenuService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/menu")
|
||||
public class MenuController {
|
||||
private IMenuService menuService;
|
||||
|
||||
@Autowired
|
||||
public void setMenuService(IMenuService menuService) {
|
||||
this.menuService = menuService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllMenu() {
|
||||
List<Menu> menus = menuService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(menus);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getMenu(@PathVariable int id) {
|
||||
LambdaQueryWrapper<Menu> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Menu::getId, id);
|
||||
Menu menu = menuService.getOne(wrapper);
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(menu);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.Operation;
|
||||
import com.cfive.pinnacle.service.permission.IOperationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 功能 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/operation")
|
||||
public class OperationController {
|
||||
private IOperationService operationService;
|
||||
|
||||
@Autowired
|
||||
public void setOperationService(IOperationService operationService) {
|
||||
this.operationService = operationService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllOperation() {
|
||||
List<Operation> operations = operationService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(operations);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getOperation(@PathVariable int id) {
|
||||
LambdaQueryWrapper<Operation> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Operation::getId, id);
|
||||
Operation operation = operationService.getOne(wrapper);
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(operation);
|
||||
}
|
||||
}
|
||||
@@ -31,14 +31,14 @@ public class OperationLogController {
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllOperationLog() {
|
||||
public ResponseResult<List<OperationLog>> getAllOperationLog() {
|
||||
List<OperationLog> operationLogs = operationLogService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(operationLogs);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getOperationLog(@PathVariable int id) {
|
||||
public ResponseResult<OperationLog> getOperationLog(@PathVariable int id) {
|
||||
LambdaQueryWrapper<OperationLog> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OperationLog::getId, id);
|
||||
OperationLog operationLog = operationLogService.getOne(wrapper);
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.*;
|
||||
import com.cfive.pinnacle.service.permission.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 权限类型 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/powerType")
|
||||
public class PowerTypeController {
|
||||
IPowerTypeService powerTypeService;
|
||||
|
||||
public void setPowerTypeService(IPowerTypeService powerTypeService) {
|
||||
this.powerTypeService = powerTypeService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllPowerType() {
|
||||
List<PowerType> powerTypes = powerTypeService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(powerTypes);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getPowerType(@PathVariable int id) {
|
||||
LambdaQueryWrapper<PowerType> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PowerType::getId, id);
|
||||
PowerType powerType = powerTypeService.getOne(wrapper);
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(powerType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.permission.Role;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.permission.IRoleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/role")
|
||||
@Tag(name = "角色", description = "角色相关接口")
|
||||
public class RoleController {
|
||||
|
||||
private IRoleService roleService;
|
||||
|
||||
@Autowired
|
||||
public void setRoleService(IRoleService roleService) {
|
||||
this.roleService = roleService;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有角色")
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:role:all', 'system:role:add', 'system:role:delete', 'system:role:modeify', 'system:group:add', 'system:group:modify', 'system:user:add', 'system:user:modify')")
|
||||
public ResponseResult<List<Role>> getAllRole() {
|
||||
List<Role> roles = roleService.getAllRole();
|
||||
return ResponseResult.databaseSelectSuccess(roles);
|
||||
}
|
||||
|
||||
@Operation(summary = "添加角色")
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('system:role:add')")
|
||||
public ResponseResult<Role> addRole(@RequestBody Role role) {
|
||||
if (!StringUtils.hasText(role.getName())) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "Name cannot be empty", null);
|
||||
}
|
||||
if (roleService.addRole(role)) {
|
||||
return ResponseResult.databaseSaveSuccess(role);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "删除角色")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "角色ID", in = ParameterIn.PATH)
|
||||
})
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasAuthority('system:role:delete')")
|
||||
public ResponseResult<?> deleteRole(@PathVariable Long id) {
|
||||
LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Role::getId, id);
|
||||
if (roleService.remove(wrapper)) {
|
||||
return ResponseResult.databaseDeleteSuccess();
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "修改角色")
|
||||
@PutMapping()
|
||||
@PreAuthorize("hasAuthority('system:role:modify')")
|
||||
public ResponseResult<Role> modifyRole(@RequestBody Role role) {
|
||||
if (!StringUtils.hasText(role.getName())) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "Name cannot be empty", null);
|
||||
}
|
||||
if (roleService.modifyRole(role)) {
|
||||
return ResponseResult.databaseUpdateSuccess(role);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.permission.User;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.permission.IUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
@Tag(name = "用户", description = "用户相关接口")
|
||||
public class UserController {
|
||||
private IUserService userService;
|
||||
|
||||
@Autowired
|
||||
public void setUserService(IUserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
@Operation(summary = "获取当前用户信息")
|
||||
public ResponseResult<User> getInfo() {
|
||||
return ResponseResult.databaseSelectSuccess(userService.getInfo());
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:user:all', 'system:user:add', 'system:user:modify')")
|
||||
@Operation(summary = "获取所有用户(权限管理相关)")
|
||||
public ResponseResult<List<User>> getAllUser() {
|
||||
List<User> users = userService.getAllUser();
|
||||
return ResponseResult.databaseSelectSuccess(users);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasAuthority('system:user:one')")
|
||||
@Operation(summary = "获取单个用户(权限管理相关)")
|
||||
public ResponseResult<User> getUser(@PathVariable Long id) {
|
||||
User user = userService.getUser(id);
|
||||
return ResponseResult.databaseSelectSuccess(user);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('system:user:add')")
|
||||
@Operation(summary = "添加用户(权限管理相关)")
|
||||
public ResponseResult<User> addUser(@RequestBody User user) {
|
||||
if (!StringUtils.hasText(user.getUsername())) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "Username cannot be empty", null);
|
||||
}
|
||||
if (!StringUtils.hasText(user.getPasswd())) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "Password cannot be empty", null);
|
||||
}
|
||||
if (userService.addUser(user)) {
|
||||
return ResponseResult.databaseSaveSuccess(user);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasAuthority('system:user:delete')")
|
||||
@Operation(summary = "删除用户(权限管理相关)")
|
||||
public ResponseResult<?> deleteUser(@PathVariable Long id) {
|
||||
if (id == 1L) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "Unable to remove super admin", null);
|
||||
}
|
||||
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(User::getId, id);
|
||||
if (userService.remove(wrapper)) {
|
||||
return ResponseResult.databaseDeleteSuccess();
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping()
|
||||
@PreAuthorize("hasAuthority('system:user:modify')")
|
||||
@Operation(summary = "修改用户(权限管理相关)")
|
||||
public ResponseResult<User> modifyUser(@RequestBody User user) {
|
||||
if (!StringUtils.hasText(user.getUsername())) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "Username cannot be empty", null);
|
||||
}
|
||||
if (!StringUtils.hasText(user.getPasswd())) {
|
||||
user.setPasswd(null);
|
||||
}
|
||||
if (userService.modifyUser(user)) {
|
||||
return ResponseResult.databaseUpdateSuccess(user);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user