运维页面
This commit is contained in:
+33
-4
@@ -3,9 +3,11 @@ package com.yunhai.bschclassmanage.controller.api;
|
||||
import com.yunhai.bschclassmanage.config.Config;
|
||||
import com.yunhai.bschclassmanage.controller.BaseController;
|
||||
import com.yunhai.bschclassmanage.entity.SysOperationLog;
|
||||
import com.yunhai.bschclassmanage.enums.UserType;
|
||||
import com.yunhai.bschclassmanage.model.vo.PageVO;
|
||||
import com.yunhai.bschclassmanage.service.ISysOperationLogService;
|
||||
import com.yunhai.bschclassmanage.utils.UserContext;
|
||||
import com.yunhai.platform.utils.exception.DException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -16,6 +18,8 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Config.API_PATH + "/syslog/")
|
||||
@@ -25,22 +29,35 @@ public class SysOperationLogController extends BaseController {
|
||||
@Autowired
|
||||
private ISysOperationLogService sysOperationLogService;
|
||||
|
||||
/** 审计日志分页查询(默认按当前用户 schId 隔离) */
|
||||
/**
|
||||
* 超管校验:非超级管理员直接抛异常阻断(运维工作台仅超级管理员可访问)
|
||||
*/
|
||||
private void denyIfNotSuperAdmin() {
|
||||
boolean isSuperAdmin = UserType.SUPER_ADMINISTRATOR.getId().equals(UserContext.getType());
|
||||
if (!isSuperAdmin) {
|
||||
throw new DException("无权限:仅超级管理员可访问接口日志");
|
||||
}
|
||||
}
|
||||
|
||||
/** 审计日志分页查询;schId 为"所选学校"筛选条件(非登录用户隔离),不传则查全部学校 */
|
||||
@GetMapping("list")
|
||||
public PageVO<SysOperationLog> list(
|
||||
@RequestParam(required = false) Integer schId,
|
||||
@RequestParam(required = false) String uri,
|
||||
@RequestParam(required = false) String method,
|
||||
@RequestParam(required = false) Integer statusCode,
|
||||
@RequestParam(required = false) Integer logLevel,
|
||||
@RequestParam(required = false) Integer userId,
|
||||
@RequestParam(required = false) String userName,
|
||||
Pageable pageable) {
|
||||
return sysOperationLogService.pageQuery(UserContext.getSchId(), uri, method,
|
||||
statusCode, logLevel, userId, pageable);
|
||||
denyIfNotSuperAdmin();
|
||||
return sysOperationLogService.pageQuery(schId, uri, method,
|
||||
statusCode, logLevel, userName, pageable);
|
||||
}
|
||||
|
||||
/** 下载某条响应原文(GZIP 解压) */
|
||||
@GetMapping("download/{id}")
|
||||
public ResponseEntity<InputStreamResource> download(@PathVariable Long id) {
|
||||
denyIfNotSuperAdmin();
|
||||
String data = sysOperationLogService.getResponseData(id);
|
||||
if (data == null) data = "该条审计日志未记录响应数据";
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
|
||||
@@ -55,4 +72,16 @@ public class SysOperationLogController extends BaseController {
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
.body(new InputStreamResource(bis));
|
||||
}
|
||||
|
||||
/** 重试某条失败的操作:按记录中的 classMethod + requestParams 反射重放原始操作 */
|
||||
@PostMapping("retry/{id}")
|
||||
public Map<String, Object> retry(@PathVariable Long id) {
|
||||
denyIfNotSuperAdmin();
|
||||
Object result = sysOperationLogService.retry(id);
|
||||
Map<String, Object> m = new LinkedHashMap<>();
|
||||
m.put("success", true);
|
||||
m.put("message", "重试已提交,执行结果见新增的审计日志");
|
||||
if (result != null) m.put("data", result);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user