diff --git a/frontend/src/views/FaqManager.vue b/frontend/src/views/FaqManager.vue index 4160276..eb30aff 100644 --- a/frontend/src/views/FaqManager.vue +++ b/frontend/src/views/FaqManager.vue @@ -106,7 +106,7 @@ const columns = [ const statusOptions = [{label:'全部状态',value:''},{label:'启用',value:'ENABLED'},{label:'禁用',value:'DISABLED'}] const categoryOptions = computed(()=>[{label:'全部分类',value:''},...flatCategories.value.map(c=>({label:c.path,value:String(c.id)}))]) -const categoryOptions2 = computed(()=>[{label:'不分类',value:null as any},...flatCategories.value.map(c=>({label:c.path,value:c.id}))]) +const categoryOptions2 = computed(()=>[{label:'不分类',value:null as any},...flatCategories.value.map(c=>({label:c.path,value:String(c.id)}))]) onMounted(() => { loadCategories(); loadList(); loadStats() }) diff --git a/src/main/java/com/wok/supportbot/controller/FaqController.java b/src/main/java/com/wok/supportbot/controller/FaqController.java index 0944791..2ad1a88 100644 --- a/src/main/java/com/wok/supportbot/controller/FaqController.java +++ b/src/main/java/com/wok/supportbot/controller/FaqController.java @@ -71,9 +71,6 @@ public class FaqController { Long operatorId = body.get("operatorId") != null ? Long.valueOf(body.get("operatorId").toString()) : null; String remark = body.get("remark") != null ? body.get("remark").toString() : null; - if (feedbackId == null) { - return ResponseEntity.status(400).body(Map.of("success", false, "message", "feedbackId 不能为空")); - } if (question == null || question.isBlank()) { return ResponseEntity.status(400).body(Map.of("success", false, "message", "问题内容不能为空")); } @@ -118,9 +115,6 @@ public class FaqController { String originalAnswer = body.get("originalAnswer") != null ? body.get("originalAnswer").toString() : null; Long operatorId = body.get("operatorId") != null ? Long.valueOf(body.get("operatorId").toString()) : null; - if (feedbackId == null) { - return ResponseEntity.status(400).body(Map.of("success", false, "message", "feedbackId 不能为空")); - } if (similarQuestion == null || similarQuestion.isBlank()) { return ResponseEntity.status(400).body(Map.of("success", false, "message", "相似问题不能为空")); } @@ -156,9 +150,6 @@ public class FaqController { Long operatorId = body.get("operatorId") != null ? Long.valueOf(body.get("operatorId").toString()) : null; String remark = body.get("remark") != null ? body.get("remark").toString() : null; - if (feedbackId == null) { - return ResponseEntity.status(400).body(Map.of("success", false, "message", "feedbackId 不能为空")); - } if (answer == null || answer.isBlank()) { return ResponseEntity.status(400).body(Map.of("success", false, "message", "答案内容不能为空")); } diff --git a/src/main/java/com/wok/supportbot/entity/CategoryNode.java b/src/main/java/com/wok/supportbot/entity/CategoryNode.java index 74cac6f..804a65e 100644 --- a/src/main/java/com/wok/supportbot/entity/CategoryNode.java +++ b/src/main/java/com/wok/supportbot/entity/CategoryNode.java @@ -1,5 +1,7 @@ package com.wok.supportbot.entity; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -24,6 +26,7 @@ public class CategoryNode implements Serializable { /** * 分类ID */ + @JsonSerialize(using = ToStringSerializer.class) private Long id; /** @@ -39,6 +42,7 @@ public class CategoryNode implements Serializable { /** * 父分类ID */ + @JsonSerialize(using = ToStringSerializer.class) private Long parentId; /** diff --git a/src/main/java/com/wok/supportbot/service/FaqService.java b/src/main/java/com/wok/supportbot/service/FaqService.java index 08deb47..2ad621a 100644 --- a/src/main/java/com/wok/supportbot/service/FaqService.java +++ b/src/main/java/com/wok/supportbot/service/FaqService.java @@ -90,6 +90,9 @@ public class FaqService { private void linkAndMarkProcessed(Long feedbackId, Long faqId, String actionType, String originalQuestion, String originalAnswer, Long operatorId, String remark) { + if (feedbackId == null) { + return; + } FaqFeedbackLink link = FaqFeedbackLink.builder() .feedbackId(feedbackId) .faqId(faqId) @@ -125,15 +128,17 @@ public class FaqService { public KnowledgeFaq createFromFeedback(KnowledgeFaq faq, Long feedbackId, String originalQuestion, String originalAnswer, Long operatorId, String remark) { - // 校验反馈(仅验证存在性) - if (messageFeedbackService.getById(feedbackId) == null) { + // 校验反馈(仅验证存在性),无反馈时降级为普通创建 + if (feedbackId != null && messageFeedbackService.getById(feedbackId) == null) { throw new IllegalArgumentException("反馈不存在: feedbackId=" + feedbackId); } KnowledgeFaq created = create(faq); - // 记录关联关系 + 标记反馈已处理 - linkAndMarkProcessed(feedbackId, created.getId(), "create", originalQuestion, originalAnswer, operatorId, remark); + // 记录关联关系 + 标记反馈已处理(仅当存在反馈时) + if (feedbackId != null) { + linkAndMarkProcessed(feedbackId, created.getId(), "create", originalQuestion, originalAnswer, operatorId, remark); + } return created; } @@ -157,8 +162,7 @@ public class FaqService { if (existing == null) { throw new IllegalArgumentException("FAQ 不存在: id=" + faqId); } - MessageFeedback feedback = messageFeedbackService.getById(feedbackId); - if (feedback == null) { + if (feedbackId != null && messageFeedbackService.getById(feedbackId) == null) { throw new IllegalArgumentException("反馈不存在: feedbackId=" + feedbackId); } if (similarQuestion == null || similarQuestion.isBlank()) { @@ -180,8 +184,10 @@ public class FaqService { computeEmbeddingAsync(faqId, existing.getQuestion()); } - // 记录关联关系 + 标记反馈已处理 - linkAndMarkProcessed(feedbackId, faqId, "append_similar", trimmed, originalAnswer, operatorId, remark); + // 记录关联关系 + 标记反馈已处理(仅当存在反馈时) + if (feedbackId != null) { + linkAndMarkProcessed(feedbackId, faqId, "append_similar", trimmed, originalAnswer, operatorId, remark); + } return existing; } @@ -205,8 +211,7 @@ public class FaqService { if (existing == null) { throw new IllegalArgumentException("FAQ 不存在: id=" + faqId); } - MessageFeedback feedback = messageFeedbackService.getById(feedbackId); - if (feedback == null) { + if (feedbackId != null && messageFeedbackService.getById(feedbackId) == null) { throw new IllegalArgumentException("反馈不存在: feedbackId=" + feedbackId); } if (answer == null || answer.isBlank()) { @@ -220,8 +225,10 @@ public class FaqService { // 答案变更也重新计算向量(语义可能变化) computeEmbeddingAsync(faqId, existing.getQuestion()); - // 记录关联关系 + 标记反馈已处理 - linkAndMarkProcessed(feedbackId, faqId, "edit_answer", originalQuestion, answer, operatorId, remark); + // 记录关联关系 + 标记反馈已处理(仅当存在反馈时) + if (feedbackId != null) { + linkAndMarkProcessed(feedbackId, faqId, "edit_answer", originalQuestion, answer, operatorId, remark); + } return existing; }