Browse Source

修复保存faq报错问题

TDesign-Vue-Next-1.20.6
wanghanlin 2 weeks ago
parent
commit
1dc9cc9fe6
  1. 2
      frontend/src/views/FaqManager.vue
  2. 9
      src/main/java/com/wok/supportbot/controller/FaqController.java
  3. 4
      src/main/java/com/wok/supportbot/entity/CategoryNode.java
  4. 31
      src/main/java/com/wok/supportbot/service/FaqService.java

2
frontend/src/views/FaqManager.vue

@ -106,7 +106,7 @@ const columns = [
const statusOptions = [{label:'全部状态',value:''},{label:'启用',value:'ENABLED'},{label:'禁用',value:'DISABLED'}] 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 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() }) onMounted(() => { loadCategories(); loadList(); loadStats() })

9
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; Long operatorId = body.get("operatorId") != null ? Long.valueOf(body.get("operatorId").toString()) : null;
String remark = body.get("remark") != null ? body.get("remark").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()) { if (question == null || question.isBlank()) {
return ResponseEntity.status(400).body(Map.of("success", false, "message", "问题内容不能为空")); 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; String originalAnswer = body.get("originalAnswer") != null ? body.get("originalAnswer").toString() : null;
Long operatorId = body.get("operatorId") != null ? Long.valueOf(body.get("operatorId").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()) { if (similarQuestion == null || similarQuestion.isBlank()) {
return ResponseEntity.status(400).body(Map.of("success", false, "message", "相似问题不能为空")); 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; Long operatorId = body.get("operatorId") != null ? Long.valueOf(body.get("operatorId").toString()) : null;
String remark = body.get("remark") != null ? body.get("remark").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()) { if (answer == null || answer.isBlank()) {
return ResponseEntity.status(400).body(Map.of("success", false, "message", "答案内容不能为空")); return ResponseEntity.status(400).body(Map.of("success", false, "message", "答案内容不能为空"));
} }

4
src/main/java/com/wok/supportbot/entity/CategoryNode.java

@ -1,5 +1,7 @@
package com.wok.supportbot.entity; 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.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -24,6 +26,7 @@ public class CategoryNode implements Serializable {
/** /**
* 分类ID * 分类ID
*/ */
@JsonSerialize(using = ToStringSerializer.class)
private Long id; private Long id;
/** /**
@ -39,6 +42,7 @@ public class CategoryNode implements Serializable {
/** /**
* 父分类ID * 父分类ID
*/ */
@JsonSerialize(using = ToStringSerializer.class)
private Long parentId; private Long parentId;
/** /**

31
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, private void linkAndMarkProcessed(Long feedbackId, Long faqId, String actionType,
String originalQuestion, String originalAnswer, String originalQuestion, String originalAnswer,
Long operatorId, String remark) { Long operatorId, String remark) {
if (feedbackId == null) {
return;
}
FaqFeedbackLink link = FaqFeedbackLink.builder() FaqFeedbackLink link = FaqFeedbackLink.builder()
.feedbackId(feedbackId) .feedbackId(feedbackId)
.faqId(faqId) .faqId(faqId)
@ -125,15 +128,17 @@ public class FaqService {
public KnowledgeFaq createFromFeedback(KnowledgeFaq faq, Long feedbackId, public KnowledgeFaq createFromFeedback(KnowledgeFaq faq, Long feedbackId,
String originalQuestion, String originalAnswer, String originalQuestion, String originalAnswer,
Long operatorId, String remark) { Long operatorId, String remark) {
// 校验反馈仅验证存在性
if (messageFeedbackService.getById(feedbackId) == null) {
// 校验反馈仅验证存在性无反馈时降级为普通创建
if (feedbackId != null && messageFeedbackService.getById(feedbackId) == null) {
throw new IllegalArgumentException("反馈不存在: feedbackId=" + feedbackId); throw new IllegalArgumentException("反馈不存在: feedbackId=" + feedbackId);
} }
KnowledgeFaq created = create(faq); 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; return created;
} }
@ -157,8 +162,7 @@ public class FaqService {
if (existing == null) { if (existing == null) {
throw new IllegalArgumentException("FAQ 不存在: id=" + faqId); 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); throw new IllegalArgumentException("反馈不存在: feedbackId=" + feedbackId);
} }
if (similarQuestion == null || similarQuestion.isBlank()) { if (similarQuestion == null || similarQuestion.isBlank()) {
@ -180,8 +184,10 @@ public class FaqService {
computeEmbeddingAsync(faqId, existing.getQuestion()); 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; return existing;
} }
@ -205,8 +211,7 @@ public class FaqService {
if (existing == null) { if (existing == null) {
throw new IllegalArgumentException("FAQ 不存在: id=" + faqId); 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); throw new IllegalArgumentException("反馈不存在: feedbackId=" + feedbackId);
} }
if (answer == null || answer.isBlank()) { if (answer == null || answer.isBlank()) {
@ -220,8 +225,10 @@ public class FaqService {
// 答案变更也重新计算向量语义可能变化 // 答案变更也重新计算向量语义可能变化
computeEmbeddingAsync(faqId, existing.getQuestion()); 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; return existing;
} }

Loading…
Cancel
Save