|
|
|
@ -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<Map<String, Object>> batchMoveDocuments(@RequestBody Map<String, Object> body) { |
|
|
|
try { |
|
|
|
List<Long> 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<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; |
|
|
|
} |
|
|
|
|
|
|
|
// ==================== 语义搜索 ==================== |
|
|
|
|
|
|
|
/** |
|
|
|
|