|
@@ -2,6 +2,7 @@ package com.xuekairui.user.controller;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.xuekairui.common.Result;
|
|
import com.xuekairui.common.Result;
|
|
|
|
|
+import com.xuekairui.user.dto.AdminUpsertRequest;
|
|
|
import com.xuekairui.user.dto.AdminUserResponse;
|
|
import com.xuekairui.user.dto.AdminUserResponse;
|
|
|
import com.xuekairui.user.enums.OperationType;
|
|
import com.xuekairui.user.enums.OperationType;
|
|
|
import com.xuekairui.user.service.AdminUserService;
|
|
import com.xuekairui.user.service.AdminUserService;
|
|
@@ -10,10 +11,10 @@ import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * 管理员账号管理接口(运营端)
|
|
|
|
|
- * <p>
|
|
|
|
|
- * 管理员列表查询、踢出等,操作 t_admin 表。
|
|
|
|
|
|
|
+ * 管理员账号 CRUD(运营端,操作 t_admin 表)
|
|
|
*/
|
|
*/
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/api/admin/admins")
|
|
@RequestMapping("/api/admin/admins")
|
|
@@ -22,6 +23,7 @@ public class AdminAccountController {
|
|
|
|
|
|
|
|
private final AdminUserService adminUserService;
|
|
private final AdminUserService adminUserService;
|
|
|
private final OperationAuditLogService auditLogService;
|
|
private final OperationAuditLogService auditLogService;
|
|
|
|
|
+ private final com.xuekairui.user.service.AdminAuthService adminAuthService;
|
|
|
|
|
|
|
|
@GetMapping
|
|
@GetMapping
|
|
|
public Result<Page<AdminUserResponse>> listAdmins(
|
|
public Result<Page<AdminUserResponse>> listAdmins(
|
|
@@ -30,14 +32,67 @@ public class AdminAccountController {
|
|
|
return Result.success(adminUserService.listAdmins(page, size));
|
|
return Result.success(adminUserService.listAdmins(page, size));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @GetMapping("/{id}")
|
|
|
|
|
+ public Result<AdminUserResponse> getAdmin(@PathVariable Long id) {
|
|
|
|
|
+ return Result.success(adminUserService.getAdmin(id));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping
|
|
|
|
|
+ public Result<AdminUserResponse> createAdmin(@RequestBody AdminUpsertRequest request,
|
|
|
|
|
+ HttpServletRequest httpRequest) {
|
|
|
|
|
+ Long operatorId = (Long) httpRequest.getAttribute("userId");
|
|
|
|
|
+ AdminUserResponse resp = adminUserService.createAdmin(request);
|
|
|
|
|
+ auditLogService.logSuccess(operatorId, "管理员", getOperatorRole(httpRequest),
|
|
|
|
|
+ OperationType.USER_UPDATE, "ADMIN_CREATE:" + resp.getId(), resp.getId());
|
|
|
|
|
+ return Result.success(resp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/{id}")
|
|
|
|
|
+ public Result<AdminUserResponse> updateAdmin(@PathVariable Long id,
|
|
|
|
|
+ @RequestBody AdminUpsertRequest request,
|
|
|
|
|
+ HttpServletRequest httpRequest) {
|
|
|
|
|
+ Long operatorId = (Long) httpRequest.getAttribute("userId");
|
|
|
|
|
+ AdminUserResponse resp = adminUserService.updateAdmin(id, request);
|
|
|
|
|
+ auditLogService.logSuccess(operatorId, "管理员", getOperatorRole(httpRequest),
|
|
|
|
|
+ OperationType.USER_UPDATE, "ADMIN_UPDATE:" + id, id);
|
|
|
|
|
+ return Result.success(resp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @DeleteMapping("/{id}")
|
|
|
|
|
+ public Result<String> deleteAdmin(@PathVariable Long id,
|
|
|
|
|
+ HttpServletRequest httpRequest) {
|
|
|
|
|
+ Long operatorId = (Long) httpRequest.getAttribute("userId");
|
|
|
|
|
+ adminUserService.deleteAdmin(id);
|
|
|
|
|
+ auditLogService.logSuccess(operatorId, "管理员", getOperatorRole(httpRequest),
|
|
|
|
|
+ OperationType.USER_UPDATE, "ADMIN_DELETE:" + id, id);
|
|
|
|
|
+ return Result.success("管理员已禁用");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/{id}/password")
|
|
|
|
|
+ public Result<String> resetPassword(@PathVariable Long id,
|
|
|
|
|
+ HttpServletRequest httpRequest) {
|
|
|
|
|
+ Long operatorId = (Long) httpRequest.getAttribute("userId");
|
|
|
|
|
+ String newPwd = adminAuthService.resetPassword(id);
|
|
|
|
|
+ auditLogService.logSuccess(operatorId, "管理员", getOperatorRole(httpRequest),
|
|
|
|
|
+ OperationType.USER_UPDATE, "ADMIN_RESET_PWD:" + id, id);
|
|
|
|
|
+ return Result.success(newPwd);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/password")
|
|
|
|
|
+ public Result<String> changePassword(@RequestBody Map<String, String> body,
|
|
|
|
|
+ HttpServletRequest httpRequest) {
|
|
|
|
|
+ Long adminId = (Long) httpRequest.getAttribute("userId");
|
|
|
|
|
+ adminAuthService.setPassword(adminId,
|
|
|
|
|
+ body.get("oldPassword"), body.get("newPassword"));
|
|
|
|
|
+ return Result.success("密码修改成功");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@PostMapping("/{adminId}/kick")
|
|
@PostMapping("/{adminId}/kick")
|
|
|
- public Result<String> kickAdmin(
|
|
|
|
|
- @PathVariable Long adminId,
|
|
|
|
|
- HttpServletRequest httpRequest) {
|
|
|
|
|
|
|
+ public Result<String> kickAdmin(@PathVariable Long adminId,
|
|
|
|
|
+ HttpServletRequest httpRequest) {
|
|
|
Long operatorId = (Long) httpRequest.getAttribute("userId");
|
|
Long operatorId = (Long) httpRequest.getAttribute("userId");
|
|
|
- String operatorRole = getOperatorRole(httpRequest);
|
|
|
|
|
adminUserService.kickAdmin(adminId, operatorId);
|
|
adminUserService.kickAdmin(adminId, operatorId);
|
|
|
- auditLogService.logSuccess(operatorId, "管理员", operatorRole,
|
|
|
|
|
|
|
+ auditLogService.logSuccess(operatorId, "管理员", getOperatorRole(httpRequest),
|
|
|
OperationType.USER_UPDATE, "ADMIN_KICK:" + adminId, adminId);
|
|
OperationType.USER_UPDATE, "ADMIN_KICK:" + adminId, adminId);
|
|
|
return Result.success("管理员已被强制退出");
|
|
return Result.success("管理员已被强制退出");
|
|
|
}
|
|
}
|