|
@ -6,14 +6,11 @@ import com.qyft.gd.system.common.base.BasePageQuery; |
|
|
import com.qyft.gd.system.common.result.PageResult; |
|
|
import com.qyft.gd.system.common.result.PageResult; |
|
|
import com.qyft.gd.system.common.result.Result; |
|
|
import com.qyft.gd.system.common.result.Result; |
|
|
import com.qyft.gd.system.common.result.ResultCode; |
|
|
import com.qyft.gd.system.common.result.ResultCode; |
|
|
import com.qyft.gd.system.common.utils.JwtUtil; |
|
|
|
|
|
import com.qyft.gd.system.model.entity.User; |
|
|
import com.qyft.gd.system.model.entity.User; |
|
|
import com.qyft.gd.system.service.UserService; |
|
|
import com.qyft.gd.system.service.UserService; |
|
|
import io.jsonwebtoken.Claims; |
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
import io.swagger.v3.oas.annotations.Parameter; |
|
|
import io.swagger.v3.oas.annotations.Parameter; |
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
import jakarta.servlet.http.HttpServletRequest; |
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
@ -37,12 +34,12 @@ public class UserController { |
|
|
@PostMapping("/") |
|
|
@PostMapping("/") |
|
|
public Result<String> addUser(@RequestBody User user) { |
|
|
public Result<String> addUser(@RequestBody User user) { |
|
|
User existingUser = userService.findByUsername(user.getUsername()); |
|
|
User existingUser = userService.findByUsername(user.getUsername()); |
|
|
if(existingUser == null) { |
|
|
|
|
|
|
|
|
if (existingUser == null) { |
|
|
boolean isSuccess = userService.addUser(user); |
|
|
boolean isSuccess = userService.addUser(user); |
|
|
if (isSuccess) { |
|
|
if (isSuccess) { |
|
|
return Result.success(); |
|
|
return Result.success(); |
|
|
} |
|
|
} |
|
|
}else{ |
|
|
|
|
|
|
|
|
} else { |
|
|
return Result.failed(ResultCode.USERNAME_ALREADY_EXISTS); |
|
|
return Result.failed(ResultCode.USERNAME_ALREADY_EXISTS); |
|
|
} |
|
|
} |
|
|
return Result.failed(); |
|
|
return Result.failed(); |
|
@ -50,22 +47,12 @@ public class UserController { |
|
|
|
|
|
|
|
|
@Operation(summary = "当前用户信息") |
|
|
@Operation(summary = "当前用户信息") |
|
|
@GetMapping("/current") |
|
|
@GetMapping("/current") |
|
|
public Result<User> currentUser(HttpServletRequest request) { |
|
|
|
|
|
String token = (String) request.getAttribute("token"); |
|
|
|
|
|
if (token == null || token.isEmpty()) { |
|
|
|
|
|
return Result.failed(ResultCode.ACCESS_TOKEN_INVALID); |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
Claims claims = JwtUtil.parseJWE(token); |
|
|
|
|
|
String username = claims.getSubject(); |
|
|
|
|
|
User user = userService.findByUsername(username); |
|
|
|
|
|
if (user == null) { |
|
|
|
|
|
return Result.failed(ResultCode.ACCESS_TOKEN_INVALID); |
|
|
|
|
|
} |
|
|
|
|
|
return Result.success(user); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
|
public Result<User> currentUser() { |
|
|
|
|
|
User user = userService.currentUser(); |
|
|
|
|
|
if (user == null) { |
|
|
return Result.failed(ResultCode.ACCESS_TOKEN_INVALID); |
|
|
return Result.failed(ResultCode.ACCESS_TOKEN_INVALID); |
|
|
} |
|
|
} |
|
|
|
|
|
return Result.success(user); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Operation(summary = "更新用户信息") |
|
|
@Operation(summary = "更新用户信息") |
|
@ -81,7 +68,7 @@ public class UserController { |
|
|
|
|
|
|
|
|
@Operation(summary = "删除用户") |
|
|
@Operation(summary = "删除用户") |
|
|
@DeleteMapping("/{ids}") |
|
|
@DeleteMapping("/{ids}") |
|
|
public Result<String> deleteUser( @Parameter(description = "用户ID,多个以英文逗号(,)分割") @PathVariable String ids) { |
|
|
|
|
|
|
|
|
public Result<String> deleteUser(@Parameter(description = "用户ID,多个以英文逗号(,)分割") @PathVariable String ids) { |
|
|
boolean isSuccess = userService.deleteUser(ids); |
|
|
boolean isSuccess = userService.deleteUser(ids); |
|
|
if (isSuccess) { |
|
|
if (isSuccess) { |
|
|
return Result.success(); |
|
|
return Result.success(); |
|
|