diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/common/security/satoken/ApiPathInterceptor.java b/nladmin-system/nlsso-server/src/main/java/org/nl/common/security/satoken/ApiPathInterceptor.java new file mode 100644 index 0000000..aad515b --- /dev/null +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/common/security/satoken/ApiPathInterceptor.java @@ -0,0 +1,23 @@ +package org.nl.common.security.satoken; + +import org.slf4j.MDC; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @Author: lyd + * @Date: 2025/5/29 + */ +@Component +public class ApiPathInterceptor implements HandlerInterceptor { + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { + // 获取请求的API路径并存入MDC + String apiPath = request.getRequestURI(); + MDC.put("apiPath", apiPath); + return true; + } +} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/common/security/satoken/SaTokenConfigure.java b/nladmin-system/nlsso-server/src/main/java/org/nl/common/security/satoken/SaTokenConfigure.java index 423c90b..2b3f2c2 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/common/security/satoken/SaTokenConfigure.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/common/security/satoken/SaTokenConfigure.java @@ -26,6 +26,8 @@ public class SaTokenConfigure implements WebMvcConfigurer { */ @Autowired private SecurityProperties securityProperties; + @Autowired + private ApiPathInterceptor apiPathInterceptor; /** * Sa-Token 整合 jwt (Simple 简单模式) @@ -42,6 +44,10 @@ public class SaTokenConfigure implements WebMvcConfigurer { */ @Override public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(apiPathInterceptor) + .addPathPatterns("/**") + // 设置最高优先级 + .order(0); /* * 注册 Sa-Token 拦截器,打开注解式鉴权功能 * .excludePathPatterns(securityProperties.getExcludes()): 白名单 diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/system/controller/notice/SysNoticeController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/system/controller/notice/SysNoticeController.java index 2b77318..dd03ab0 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/system/controller/notice/SysNoticeController.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/system/controller/notice/SysNoticeController.java @@ -30,7 +30,7 @@ public class SysNoticeController { private ISysNoticeService noticeService; @GetMapping - @Log("查询消息通知") +// @Log("查询消息通知") public ResponseEntity query(@RequestParam Map whereJson, PageQuery page){ return new ResponseEntity<>(TableDataInfo.build(noticeService.queryAll(whereJson,page)),HttpStatus.OK); } @@ -56,13 +56,13 @@ public class SysNoticeController { return new ResponseEntity<>(HttpStatus.OK); } - @Log("获取未读的接收消息条数") +// @Log("获取未读的接收消息条数") @GetMapping("/countByReceiveNotRead") public ResponseEntity countByReceiveNotRead(){ return new ResponseEntity<>(noticeService.countByReceiveNotRead(), HttpStatus.OK); } - @Log("接收消息分页") +// @Log("接收消息分页") @GetMapping("/pageByReceive") public ResponseEntity pageByReceive(){ return new ResponseEntity<>(noticeService.pageByReceive(), HttpStatus.OK); @@ -75,7 +75,7 @@ public class SysNoticeController { return new ResponseEntity<>(HttpStatus.NO_CONTENT); } - @Log("消息详情") +// @Log("消息详情") @PostMapping("/findById") public ResponseEntity findById(@RequestBody String id){ return new ResponseEntity<>(noticeService.getById(id), HttpStatus.OK); @@ -90,7 +90,6 @@ public class SysNoticeController { @Log("批量已读") @PostMapping("/changeRead") - public ResponseEntity changeRead(@RequestBody JSONObject jsonObject) { noticeService.changeRead(jsonObject); return new ResponseEntity<>(HttpStatus.NO_CONTENT); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/lucene/dto/EsLogDto.java b/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/lucene/dto/EsLogDto.java index 41bc822..7a15360 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/lucene/dto/EsLogDto.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/lucene/dto/EsLogDto.java @@ -35,6 +35,9 @@ public class EsLogDto { @Field(type = FieldType.Keyword) private String thread; + @Field(type = FieldType.Keyword) + private String apiPath; + @Field(type = FieldType.Keyword) private String logger; @Field(type = FieldType.Keyword) @@ -61,6 +64,14 @@ public class EsLogDto { this.time = time; } + public String getApiPath() { + return apiPath; + } + + public void setApiPath(String apiPath) { + this.apiPath = apiPath; + } + public String getMessage() { return message; } diff --git a/nladmin-ui/src/views/lucene/index.vue b/nladmin-ui/src/views/lucene/index.vue index 3eccf5c..1fdcee5 100644 --- a/nladmin-ui/src/views/lucene/index.vue +++ b/nladmin-ui/src/views/lucene/index.vue @@ -81,12 +81,6 @@
- - - - - -
{{ timestampToDate(log.time) }} - {{ log.currIp === null ? '0.0.0.0' : log.currIp }} - @@ -94,9 +88,15 @@ {{ log.logger }} - [{{ log.thread }}] - {{ log.tlogTraceId === null ? '无链路id' : log.tlogTraceId }} - - {{ log.message }} + + {{ log.message }} +
-
+
时间: @@ -105,6 +105,14 @@ {{ timestampToDate(log.time) }} + + + host: + + + {{ log.host }} + + 执行IP: @@ -113,6 +121,22 @@ {{ log.currIp === null ? '0.0.0.0' : log.currIp }} + + + API路径: + + + {{ log.apiPath === null ? '无' : log.apiPath }} + + + + + MDC标签: + + + {{ log.tag === null ? '未配置MDC' : log.tag }} + + 日志级别: @@ -150,7 +174,13 @@ 日志信息: - {{ log.message }} + + {{ log.message }} +
@@ -228,6 +258,60 @@ export default { return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}` }, + // 处理SQL复制 + handleCopySQL(message) { + // 1. 使用正则匹配SQL语句 + const sqlMatch = message.match(/\[ SQL: ([^\]]+)\s*\]/) + + if (sqlMatch && sqlMatch[1]) { + const sql = sqlMatch[1].trim() + this.copyToClipboard(sql) + } else { + this.$message.warning('未检测到可复制的SQL语句') + } + }, + + // 复制文本到剪贴板 + copyToClipboard(text) { + // 现代浏览器方法 + if (navigator.clipboard) { + navigator.clipboard.writeText(text) + .then(() => this.showSuccess()) + .catch(err => this.showError(err)) + } + // 兼容旧浏览器 + else { + const textarea = document.createElement('textarea') + textarea.value = text + textarea.style.position = 'fixed' + document.body.appendChild(textarea) + textarea.select() + + try { + const success = document.execCommand('copy') + success ? this.showSuccess() : this.showError() + } catch (err) { + this.showError(err) + } + + document.body.removeChild(textarea) + } + }, + + // 显示成功提示 + showSuccess() { + this.$message({ + message: 'SQL已复制到剪贴板', + type: 'success', + duration: 2000 + }) + }, + + // 显示错误提示 + showError(err) { + console.error('复制失败:', err) + this.$message.error('复制失败,请手动复制') + }, handleSizeChange(val) { this.query.size = val this.queryData() @@ -257,5 +341,13 @@ export default {