适配QA问答对数据结构
This commit is contained in:
@@ -116,7 +116,24 @@ public class AnnotationResultService {
|
||||
AnnotationResultDetailResponse.QaContentDto qaContentDto = new AnnotationResultDetailResponse.QaContentDto(
|
||||
qaContent.records().stream()
|
||||
.map(r -> new AnnotationResultDetailResponse.QaRecordDto(
|
||||
r.id(), r.question(), r.answer(), r.requiresReview()))
|
||||
r.id(),
|
||||
r.batchId(),
|
||||
r.question(),
|
||||
r.answer(),
|
||||
r.requiresReview(),
|
||||
r.sourceSegments() != null ? new AnnotationResultDetailResponse.SourceSegmentsDto(
|
||||
r.sourceSegments().segment(),
|
||||
r.sourceSegments().chunkIndex(),
|
||||
r.sourceSegments().chunkTitle(),
|
||||
r.sourceSegments().chunkContent()) : null,
|
||||
r.questionCategory(),
|
||||
r.scores() != null ? new AnnotationResultDetailResponse.ScoresDto(
|
||||
r.scores().similarity(),
|
||||
r.scores().confidence1(),
|
||||
r.scores().confidence2(),
|
||||
r.scores().hallucination(),
|
||||
r.scores().trust()) : null,
|
||||
r.reviewComment()))
|
||||
.toList()
|
||||
);
|
||||
|
||||
@@ -127,7 +144,14 @@ public class AnnotationResultService {
|
||||
diffContent.records().stream()
|
||||
.map(r -> new AnnotationResultDetailResponse.DiffRecordDto(
|
||||
r.qaId(), r.question(), r.extractAnswer(),
|
||||
r.verifyAnswer(), r.diffReason(), r.mergedAnswer()))
|
||||
r.verifyAnswer(), r.diffReason(), r.mergedAnswer(),
|
||||
r.questionCategory(),
|
||||
r.scores() != null ? new AnnotationResultDetailResponse.ScoresDto(
|
||||
r.scores().similarity(),
|
||||
r.scores().confidence1(),
|
||||
r.scores().confidence2(),
|
||||
r.scores().hallucination(),
|
||||
r.scores().trust()) : null))
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
@@ -145,8 +169,6 @@ public class AnnotationResultService {
|
||||
result.getDiffSummaryFilePath(),
|
||||
qaContentDto,
|
||||
diffContentDto,
|
||||
result.getReviewComment(),
|
||||
result.getReviewedAt(),
|
||||
result.getCreatedAt()
|
||||
);
|
||||
}
|
||||
@@ -173,9 +195,23 @@ public class AnnotationResultService {
|
||||
List<AnnotationResultCompareResponse.QaRecord> qaRecords = qaContent.records().stream()
|
||||
.map(qa -> new AnnotationResultCompareResponse.QaRecord(
|
||||
qa.id(),
|
||||
qa.batchId(),
|
||||
qa.question(),
|
||||
qa.answer(),
|
||||
qa.requiresReview()
|
||||
qa.requiresReview(),
|
||||
qa.sourceSegments() != null ? new AnnotationResultCompareResponse.SourceSegments(
|
||||
qa.sourceSegments().segment(),
|
||||
qa.sourceSegments().chunkIndex(),
|
||||
qa.sourceSegments().chunkTitle(),
|
||||
qa.sourceSegments().chunkContent()) : null,
|
||||
qa.questionCategory(),
|
||||
qa.scores() != null ? new AnnotationResultCompareResponse.Scores(
|
||||
qa.scores().similarity(),
|
||||
qa.scores().confidence1(),
|
||||
qa.scores().confidence2(),
|
||||
qa.scores().hallucination(),
|
||||
qa.scores().trust()) : null,
|
||||
qa.reviewComment()
|
||||
)).toList();
|
||||
|
||||
// 转换差异记录
|
||||
@@ -187,7 +223,14 @@ public class AnnotationResultService {
|
||||
diff.extractAnswer(),
|
||||
diff.verifyAnswer(),
|
||||
diff.diffReason(),
|
||||
diff.mergedAnswer()
|
||||
diff.mergedAnswer(),
|
||||
diff.questionCategory(),
|
||||
diff.scores() != null ? new AnnotationResultCompareResponse.Scores(
|
||||
diff.scores().similarity(),
|
||||
diff.scores().confidence1(),
|
||||
diff.scores().confidence2(),
|
||||
diff.scores().hallucination(),
|
||||
diff.scores().trust()) : null
|
||||
)).toList() : List.of();
|
||||
|
||||
return new AnnotationResultCompareResponse(
|
||||
@@ -220,16 +263,22 @@ public class AnnotationResultService {
|
||||
// 读取当前 qa.json
|
||||
QaContent qaContent = loadQaContent(result);
|
||||
|
||||
// 更新 qa.json 的 answer 字段
|
||||
// 更新 qa.json 的 answer 字段和 reviewComment
|
||||
List<QaContent.QaRecord> updatedQaRecords = qaContent.records().stream()
|
||||
.map(record -> {
|
||||
String mergedAnswer = request.mergedAnswers().get(record.id());
|
||||
if (mergedAnswer != null) {
|
||||
String reviewComment = request.reviewComments() != null ? request.reviewComments().get(record.id()) : null;
|
||||
if (mergedAnswer != null || reviewComment != null) {
|
||||
return new QaContent.QaRecord(
|
||||
record.id(),
|
||||
record.batchId(),
|
||||
record.question(),
|
||||
mergedAnswer,
|
||||
false
|
||||
mergedAnswer != null ? mergedAnswer : record.answer(),
|
||||
false,
|
||||
record.sourceSegments(),
|
||||
record.questionCategory(),
|
||||
record.scores(),
|
||||
reviewComment != null ? reviewComment : record.reviewComment()
|
||||
);
|
||||
}
|
||||
return record;
|
||||
@@ -247,11 +296,18 @@ public class AnnotationResultService {
|
||||
);
|
||||
saveQaContent(result, updatedQaContent);
|
||||
|
||||
// 更新数据库记录
|
||||
result.setIsDeleted(Boolean.TRUE);
|
||||
result.setReviewerId(currentUser.userId());
|
||||
result.setReviewComment(request.reviewComment());
|
||||
result.setReviewedAt(LocalDateTime.now());
|
||||
// 更新数据库记录(使用 markArchived 保证幂等性,防止并发重复归档)
|
||||
int updated = annotationResultMapper.markArchived(
|
||||
result.getId(),
|
||||
currentUser.companyId(),
|
||||
currentUser.userId());
|
||||
|
||||
if (updated == 0) {
|
||||
// 记录已被其他进程归档
|
||||
throw new BusinessException(ResultCode.CONFLICT, "记录已被归档");
|
||||
}
|
||||
|
||||
// 更新 requires_manual_review 字段
|
||||
result.setRequiresManualReview(false);
|
||||
annotationResultMapper.updateById(result);
|
||||
|
||||
@@ -281,8 +337,6 @@ public class AnnotationResultService {
|
||||
result.getIsDeleted(),
|
||||
result.getQaContentFilePath(),
|
||||
result.getDiffSummaryFilePath(),
|
||||
result.getReviewComment(),
|
||||
result.getReviewedAt(),
|
||||
result.getCreatedAt()
|
||||
);
|
||||
}
|
||||
@@ -392,17 +446,15 @@ public class AnnotationResultService {
|
||||
|
||||
// 根据归档类型设置审核人信息
|
||||
if (isAutoArchive) {
|
||||
// 自动归档:reviewer_id为NULL,name和comment为"auto"
|
||||
// 自动归档:reviewer_id为NULL,name为"auto"
|
||||
historyBuilder
|
||||
.reviewerId(null)
|
||||
.reviewerName("auto")
|
||||
.reviewerComment("auto");
|
||||
.reviewerName("auto");
|
||||
} else {
|
||||
// 人工审核后归档:使用审核人信息
|
||||
historyBuilder
|
||||
.reviewerId(result.getReviewerId())
|
||||
.reviewerName(currentUser.realName())
|
||||
.reviewerComment(result.getReviewComment());
|
||||
.reviewerName(currentUser.realName());
|
||||
}
|
||||
|
||||
annotationResultHistoryMapper.insert(historyBuilder.build());
|
||||
@@ -436,7 +488,16 @@ public class AnnotationResultService {
|
||||
List<QaRecord> records,
|
||||
Metadata metadata
|
||||
) {
|
||||
private record QaRecord(String id, String question, String answer, Boolean requiresReview) {
|
||||
private record QaRecord(String id, Long batchId, String question, String answer,
|
||||
Boolean requiresReview, SourceSegments sourceSegments,
|
||||
String questionCategory, Scores scores, String reviewComment) {
|
||||
}
|
||||
|
||||
private record SourceSegments(String segment, Integer chunkIndex, String chunkTitle, String chunkContent) {
|
||||
}
|
||||
|
||||
private record Scores(Double similarity, Double confidence1, Double confidence2,
|
||||
Double hallucination, Double trust) {
|
||||
}
|
||||
|
||||
private record Metadata(String createdAt, String updatedAt) {
|
||||
@@ -451,7 +512,12 @@ public class AnnotationResultService {
|
||||
Metadata metadata
|
||||
) {
|
||||
private record DiffRecord(String qaId, String question, String extractAnswer,
|
||||
String verifyAnswer, String diffReason, String mergedAnswer) {
|
||||
String verifyAnswer, String diffReason, String mergedAnswer,
|
||||
String questionCategory, Scores scores) {
|
||||
}
|
||||
|
||||
private record Scores(Double similarity, Double confidence1, Double confidence2,
|
||||
Double hallucination, Double trust) {
|
||||
}
|
||||
|
||||
private record Metadata(String createdAt) {
|
||||
|
||||
Reference in New Issue
Block a user