1
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
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.model.vo.PageVO;
|
||||
import com.yunhai.bschclassmanage.service.ISysOperationLogService;
|
||||
import com.yunhai.bschclassmanage.utils.UserContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Config.API_PATH + "/syslog/")
|
||||
@CrossOrigin(originPatterns = {"*"}, allowCredentials = "true")
|
||||
public class SysOperationLogController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ISysOperationLogService sysOperationLogService;
|
||||
|
||||
/** 审计日志分页查询(默认按当前用户 schId 隔离) */
|
||||
@GetMapping("list")
|
||||
public PageVO<SysOperationLog> list(
|
||||
@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,
|
||||
Pageable pageable) {
|
||||
return sysOperationLogService.pageQuery(UserContext.getSchId(), uri, method,
|
||||
statusCode, logLevel, userId, pageable);
|
||||
}
|
||||
|
||||
/** 下载某条响应原文(GZIP 解压) */
|
||||
@GetMapping("download/{id}")
|
||||
public ResponseEntity<InputStreamResource> download(@PathVariable Long id) {
|
||||
String data = sysOperationLogService.getResponseData(id);
|
||||
if (data == null) data = "该条审计日志未记录响应数据";
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
try {
|
||||
headers.add(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=" + new String(("audit-" + id + ".txt").getBytes("gbk"), "iso8859-1"));
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
return ResponseEntity.ok().headers(headers)
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
.body(new InputStreamResource(bis));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user