|
@ -0,0 +1,74 @@ |
|
|
|
|
|
package com.iflytop.gd.system.controller; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
import com.iflytop.gd.system.common.base.BasePageQuery; |
|
|
|
|
|
import com.iflytop.gd.system.common.result.PageResult; |
|
|
|
|
|
import com.iflytop.gd.system.common.result.Result; |
|
|
|
|
|
import com.iflytop.gd.system.common.result.ResultCode; |
|
|
|
|
|
import com.iflytop.gd.system.model.entity.User; |
|
|
|
|
|
import com.iflytop.gd.system.service.UserService; |
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter; |
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
@Tag(name = "用户接口") |
|
|
|
|
|
@RestController |
|
|
|
|
|
@RequestMapping("/api/user") |
|
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
|
@Slf4j |
|
|
|
|
|
public class UserController { |
|
|
|
|
|
private final UserService userService; |
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "用户列表") |
|
|
|
|
|
@GetMapping("/list") |
|
|
|
|
|
public PageResult<User> getAllUsers(BasePageQuery pageQuery) { |
|
|
|
|
|
IPage<User> result = userService.page(new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()), null); |
|
|
|
|
|
return PageResult.success(result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "添加新用户") |
|
|
|
|
|
@PostMapping("") |
|
|
|
|
|
public Result<String> addUser(@RequestBody User user) { |
|
|
|
|
|
User existingUser = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getUsername, user.getUsername())); |
|
|
|
|
|
if (existingUser == null) { |
|
|
|
|
|
boolean isSuccess = userService.save(user); |
|
|
|
|
|
if (isSuccess) { |
|
|
|
|
|
return Result.success(); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
return Result.failed(ResultCode.USER_ALREADY_EXISTS); |
|
|
|
|
|
} |
|
|
|
|
|
return Result.failed(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "当前用户信息") |
|
|
|
|
|
@GetMapping("/current") |
|
|
|
|
|
public Result<User> currentUser() { |
|
|
|
|
|
return Result.success(userService.getCurrentUser()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "更新用户信息") |
|
|
|
|
|
@PutMapping("") |
|
|
|
|
|
public Result<String> updateUser(@RequestBody User user) { |
|
|
|
|
|
boolean isSuccess = userService.updateById(user); |
|
|
|
|
|
if (isSuccess) { |
|
|
|
|
|
return Result.success(); |
|
|
|
|
|
} |
|
|
|
|
|
return Result.failed(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "删除用户") |
|
|
|
|
|
@DeleteMapping("/{ids}") |
|
|
|
|
|
public Result<String> deleteUser(@Parameter(description = "用户ID,多个以英文逗号(,)分割") @PathVariable String ids) { |
|
|
|
|
|
boolean isSuccess = userService.deleteUser(ids); |
|
|
|
|
|
if (isSuccess) { |
|
|
|
|
|
return Result.success(); |
|
|
|
|
|
} |
|
|
|
|
|
return Result.failed(); |
|
|
|
|
|
} |
|
|
|
|
|
} |