|
|
@ -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; |
|
|
} |
|
|
} |
|
|
|