From c70d96c00d4867a9482864c8d2954cd861b27d96 Mon Sep 17 00:00:00 2001 From: wanghanlin <1533525126@qq.com> Date: Wed, 1 Jul 2026 15:42:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E6=A1=A3=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=A7=BB=E5=8A=A8=E5=88=86=E7=B1=BB=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DocumentController.java | 34 +++++++++++++++++-- .../resources/static/components/DocList.js | 3 +- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/wok/supportbot/controller/DocumentController.java b/src/main/java/com/wok/supportbot/controller/DocumentController.java index f073c20..f20c301 100644 --- a/src/main/java/com/wok/supportbot/controller/DocumentController.java +++ b/src/main/java/com/wok/supportbot/controller/DocumentController.java @@ -542,14 +542,15 @@ public class DocumentController { /** * P1-2.2: 批量移动文档分类 - * body: {ids: [Long], categoryId: Long} + * body: {ids: [Long], categoryId: Long | String} + * 注意:categoryId 兼容 String 类型,避免前端雪花 ID 经 parseInt 丢失精度 */ @PostMapping("/document/batch/move") @PreAuthorize("hasAnyRole('admin','kb_operator')") public ResponseEntity> batchMoveDocuments(@RequestBody Map body) { try { List ids = extractIds(body); - Long categoryId = body.get("categoryId") != null ? ((Number) body.get("categoryId")).longValue() : 0L; + Long categoryId = extractCategoryId(body); if (ids.isEmpty()) { return ResponseEntity.badRequest().body(Map.of( "success", false, @@ -557,9 +558,18 @@ public class DocumentController { )); } int updatedCount = documentService.batchMoveDocuments(ids, categoryId); + int requestedCount = ids.size(); + String message; + if (updatedCount == requestedCount) { + message = String.format("已将 %d 个文档移动到目标分类", updatedCount); + } else { + message = String.format("移动完成:成功 %d 个,%d 个文档未找到", + updatedCount, requestedCount - updatedCount); + } return ResponseEntity.ok(Map.of( "success", true, - "message", String.format("已将 %d 个文档移动到目标分类", updatedCount) + "message", message, + "updatedCount", updatedCount )); } catch (Exception e) { return ResponseEntity.status(500).body(Map.of( @@ -569,6 +579,24 @@ public class DocumentController { } } + /** + * 从请求体中提取 categoryId,兼容 Number 和 String 两种类型 + * 前端雪花 ID 超出 JS Number.MAX_SAFE_INTEGER,需以 String 传递以避免精度丢失 + */ + private Long extractCategoryId(Map body) { + Object raw = body.get("categoryId"); + if (raw == null) { + return 0L; + } + if (raw instanceof Number) { + return ((Number) raw).longValue(); + } + if (raw instanceof String str) { + return str.isEmpty() ? 0L : Long.parseLong(str); + } + return 0L; + } + // ==================== 语义搜索 ==================== /** diff --git a/src/main/resources/static/components/DocList.js b/src/main/resources/static/components/DocList.js index 316e96a..0a8a119 100644 --- a/src/main/resources/static/components/DocList.js +++ b/src/main/resources/static/components/DocList.js @@ -398,7 +398,8 @@ export default { const catName = catId === '0' ? '未分类' : store.getCategoryName(catId) if (!confirm(`确定将选中的 ${ids.length} 个文档移动到「${catName}」?`)) return try { - const json = await batchMoveDocuments(ids, catId === '0' ? 0 : parseInt(catId)) + // 注意:不可用 parseInt,雪花 ID 超出 Number.MAX_SAFE_INTEGER 会丢失精度 + const json = await batchMoveDocuments(ids, catId === '0' ? 0 : catId) if (json.success) { toast(json.message, 'success') selectedIds.value = new Set()