Browse Source

修复文档列表移动分类功能的 bug

dev-mcp
wanghanlin 4 weeks ago
parent
commit
c70d96c00d
  1. 34
      src/main/java/com/wok/supportbot/controller/DocumentController.java
  2. 3
      src/main/resources/static/components/DocList.js

34
src/main/java/com/wok/supportbot/controller/DocumentController.java

@ -542,14 +542,15 @@ public class DocumentController {
/** /**
* P1-2.2: 批量移动文档分类 * P1-2.2: 批量移动文档分类
* body: {ids: [Long], categoryId: Long}
* body: {ids: [Long], categoryId: Long | String}
* 注意categoryId 兼容 String 类型避免前端雪花 ID parseInt 丢失精度
*/ */
@PostMapping("/document/batch/move") @PostMapping("/document/batch/move")
@PreAuthorize("hasAnyRole('admin','kb_operator')") @PreAuthorize("hasAnyRole('admin','kb_operator')")
public ResponseEntity<Map<String, Object>> batchMoveDocuments(@RequestBody Map<String, Object> body) { public ResponseEntity<Map<String, Object>> batchMoveDocuments(@RequestBody Map<String, Object> body) {
try { try {
List<Long> ids = extractIds(body); List<Long> ids = extractIds(body);
Long categoryId = body.get("categoryId") != null ? ((Number) body.get("categoryId")).longValue() : 0L;
Long categoryId = extractCategoryId(body);
if (ids.isEmpty()) { if (ids.isEmpty()) {
return ResponseEntity.badRequest().body(Map.of( return ResponseEntity.badRequest().body(Map.of(
"success", false, "success", false,
@ -557,9 +558,18 @@ public class DocumentController {
)); ));
} }
int updatedCount = documentService.batchMoveDocuments(ids, categoryId); 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( return ResponseEntity.ok(Map.of(
"success", true, "success", true,
"message", String.format("已将 %d 个文档移动到目标分类", updatedCount)
"message", message,
"updatedCount", updatedCount
)); ));
} catch (Exception e) { } catch (Exception e) {
return ResponseEntity.status(500).body(Map.of( 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<String, Object> 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;
}
// ==================== 语义搜索 ==================== // ==================== 语义搜索 ====================
/** /**

3
src/main/resources/static/components/DocList.js

@ -398,7 +398,8 @@ export default {
const catName = catId === '0' ? '未分类' : store.getCategoryName(catId) const catName = catId === '0' ? '未分类' : store.getCategoryName(catId)
if (!confirm(`确定将选中的 ${ids.length} 个文档移动到「${catName}」?`)) return if (!confirm(`确定将选中的 ${ids.length} 个文档移动到「${catName}」?`)) return
try { 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) { if (json.success) {
toast(json.message, 'success') toast(json.message, 'success')
selectedIds.value = new Set() selectedIds.value = new Set()

Loading…
Cancel
Save