增加后台管理模块
This commit is contained in:
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
/**
|
||||
* 成就控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.emotion.controller;
|
||||
|
||||
import com.emotion.common.Result;
|
||||
import com.emotion.dto.request.AdminLoginRequest;
|
||||
import com.emotion.dto.request.RefreshTokenRequest;
|
||||
import com.emotion.dto.response.AdminAuthResponse;
|
||||
import com.emotion.dto.response.AdminInfoResponse;
|
||||
import com.emotion.service.AdminAuthService;
|
||||
import com.emotion.util.JwtUtil;
|
||||
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.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 管理员认证控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @date 2025-10-27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/auth")
|
||||
@Tag(name = "管理员认证管理", description = "管理员登录、登出等认证相关接口")
|
||||
public class AdminAuthController {
|
||||
|
||||
@Autowired
|
||||
private AdminAuthService adminAuthService;
|
||||
|
||||
@Autowired
|
||||
private JwtUtil jwtUtil;
|
||||
|
||||
/**
|
||||
* 管理员登录
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
@Operation(summary = "管理员登录", description = "使用账号和密码登录")
|
||||
public Result<AdminAuthResponse> login(@Validated @RequestBody AdminLoginRequest request) {
|
||||
AdminAuthResponse response = adminAuthService.login(request);
|
||||
return Result.success("登录成功", response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前管理员信息
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
@Operation(summary = "获取当前管理员信息", description = "根据Token获取当前登录的管理员信息")
|
||||
public Result<AdminInfoResponse> getCurrentAdminInfo(HttpServletRequest request) {
|
||||
String authHeader = request.getHeader("Authorization");
|
||||
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
|
||||
return Result.unauthorized("未登录");
|
||||
}
|
||||
|
||||
String token = authHeader.substring(7);
|
||||
String adminId = jwtUtil.getUserIdFromToken(token);
|
||||
|
||||
AdminInfoResponse adminInfo = adminAuthService.getCurrentAdminInfo(adminId);
|
||||
return Result.success(adminInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员登出
|
||||
*/
|
||||
@PostMapping("/logout")
|
||||
@Operation(summary = "管理员登出", description = "退出登录")
|
||||
public Result<Void> logout(HttpServletRequest request) {
|
||||
adminAuthService.logout(request);
|
||||
return Result.success("登出成功", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新访问令牌
|
||||
*/
|
||||
@PostMapping("/refreshToken")
|
||||
@Operation(summary = "刷新访问令牌", description = "使用刷新令牌获取新的访问令牌")
|
||||
public Result<AdminAuthResponse> refreshToken(@Validated @RequestBody RefreshTokenRequest request) {
|
||||
AdminAuthResponse response = adminAuthService.refreshToken(request.getRefreshToken());
|
||||
return Result.success("令牌刷新成功", response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证访问令牌
|
||||
*/
|
||||
@GetMapping("/validateToken")
|
||||
@Operation(summary = "验证访问令牌", description = "验证当前Token是否有效")
|
||||
public Result<Boolean> validateToken(HttpServletRequest request) {
|
||||
boolean isValid = adminAuthService.validateToken(request);
|
||||
return Result.success(isValid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.emotion.controller;
|
||||
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.common.Result;
|
||||
import com.emotion.dto.request.AdminCreateRequest;
|
||||
import com.emotion.dto.request.AdminPageRequest;
|
||||
import com.emotion.dto.request.AdminUpdateRequest;
|
||||
import com.emotion.dto.response.AdminResponse;
|
||||
import com.emotion.service.AdminService;
|
||||
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.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 管理员控制器
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-10-27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin")
|
||||
@Tag(name = "管理员管理", description = "管理员的增删改查功能")
|
||||
public class AdminController {
|
||||
|
||||
@Autowired
|
||||
private AdminService adminService;
|
||||
|
||||
/**
|
||||
* 分页查询管理员
|
||||
*/
|
||||
@Operation(summary = "分页查询管理员", description = "分页查询管理员列表")
|
||||
@GetMapping("/page")
|
||||
public Result<PageResult<AdminResponse>> getPage(@Validated AdminPageRequest request) {
|
||||
PageResult<AdminResponse> pageResult = adminService.getPageWithResponse(request);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取管理员
|
||||
*/
|
||||
@Operation(summary = "根据ID获取管理员", description = "根据ID获取管理员详情")
|
||||
@GetMapping("/detail")
|
||||
public Result<AdminResponse> getById(@RequestParam String id) {
|
||||
AdminResponse response = adminService.getAdminResponseById(id);
|
||||
if (response == null) {
|
||||
return Result.notFound("管理员不存在");
|
||||
}
|
||||
return Result.success(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建管理员
|
||||
*/
|
||||
@Operation(summary = "创建管理员", description = "创建新的管理员")
|
||||
@PostMapping("/create")
|
||||
public Result<AdminResponse> create(@RequestBody @Validated AdminCreateRequest request) {
|
||||
AdminResponse response = adminService.createAdminWithResponse(request);
|
||||
if (response == null) {
|
||||
return Result.error("创建失败");
|
||||
}
|
||||
return Result.success("创建成功", response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新管理员
|
||||
*/
|
||||
@Operation(summary = "更新管理员", description = "更新指定管理员")
|
||||
@PutMapping("/update")
|
||||
public Result<AdminResponse> update(@RequestBody @Validated AdminUpdateRequest request) {
|
||||
AdminResponse response = adminService.updateAdminWithResponse(request);
|
||||
if (response == null) {
|
||||
return Result.error("更新失败");
|
||||
}
|
||||
return Result.success("更新成功", response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除管理员
|
||||
*/
|
||||
@Operation(summary = "删除管理员", description = "删除指定管理员")
|
||||
@DeleteMapping("/delete")
|
||||
public Result<Void> delete(@RequestParam String id) {
|
||||
boolean deleted = adminService.removeById(id);
|
||||
if (!deleted) {
|
||||
return Result.error("删除失败");
|
||||
}
|
||||
return Result.success("删除成功", null);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import javax.validation.Valid;
|
||||
/**
|
||||
* AI聊天控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@Slf4j
|
||||
|
||||
@@ -26,7 +26,7 @@ import javax.validation.Valid;
|
||||
/**
|
||||
* 认证控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.security.Principal;
|
||||
* WebSocket聊天控制器
|
||||
* 使用规范的请求对象封装参数,符合项目开发规则
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
@Slf4j
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
/**
|
||||
* 评论控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
/**
|
||||
* 社区帖子控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
/**
|
||||
* 对话控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.math.BigDecimal;
|
||||
/**
|
||||
* Coze API调用记录控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
/**
|
||||
* 日记评论控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -17,7 +17,7 @@ import javax.validation.Valid;
|
||||
/**
|
||||
* 用户日记控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
/**
|
||||
* 情绪分析控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
/**
|
||||
* 情绪记录控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-22
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -19,7 +19,7 @@ import javax.validation.Valid;
|
||||
/**
|
||||
* 情绪总结控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-25
|
||||
*/
|
||||
@Slf4j
|
||||
|
||||
@@ -16,7 +16,7 @@ import javax.validation.Valid;
|
||||
/**
|
||||
* 成长话题控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -16,7 +16,7 @@ import javax.validation.Valid;
|
||||
/**
|
||||
* 访客用户控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
/**
|
||||
* 健康检查控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -18,7 +18,7 @@ import javax.validation.Valid;
|
||||
/**
|
||||
* 消息控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -16,7 +16,7 @@ import javax.validation.Valid;
|
||||
/**
|
||||
* 奖励控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -14,7 +14,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
* Token控制器
|
||||
* 提供基于请求头Authorization的token验证和用户信息获取功能
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -16,7 +16,7 @@ import javax.validation.Valid;
|
||||
/**
|
||||
* 话题互动控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -17,7 +17,7 @@ import javax.validation.Valid;
|
||||
/**
|
||||
* 用户控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-22
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
/**
|
||||
* 用户统计控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
|
||||
Reference in New Issue
Block a user