fix(aihr): validate knowledge feedback links
This commit is contained in:
+15
-1
@@ -231,6 +231,7 @@ public class AihrSopSeedService {
|
||||
throw new ServiceException("缺少片段ID");
|
||||
}
|
||||
validateFeedbackFragmentOwnership(fragmentIds);
|
||||
Long reviewId = normalizeFeedbackReviewId(request.reviewId());
|
||||
ensureAnswerFeedbackTable();
|
||||
String reviewStatus = "down".equals(verdict) ? "待复核" : "已复核";
|
||||
Timestamp now = Timestamp.valueOf(java.time.LocalDateTime.now());
|
||||
@@ -258,7 +259,7 @@ public class AihrSopSeedService {
|
||||
firstNonBlank(request.category(), "sop"),
|
||||
firstNonBlank(request.position(), "生活顾问"),
|
||||
normalizeSearchSource(request.source()),
|
||||
request.reviewId(),
|
||||
reviewId,
|
||||
reviewStatus,
|
||||
now,
|
||||
now
|
||||
@@ -2109,6 +2110,19 @@ public class AihrSopSeedService {
|
||||
}
|
||||
}
|
||||
|
||||
private Long normalizeFeedbackReviewId(Long reviewId) {
|
||||
if (reviewId == null || reviewId <= 0) {
|
||||
return null;
|
||||
}
|
||||
ensureSopReviewTable();
|
||||
Integer count = jdbcTemplate.queryForObject("""
|
||||
SELECT COUNT(*)
|
||||
FROM aihr_sop_answer_review
|
||||
WHERE tenant_id = ? AND id = ?
|
||||
""", Integer.class, tenantId(), reviewId);
|
||||
return count != null && count > 0 ? reviewId : null;
|
||||
}
|
||||
|
||||
private static String formatTimestamp(Timestamp timestamp) {
|
||||
return timestamp == null ? "" : timestamp.toLocalDateTime().format(TIME_FORMATTER);
|
||||
}
|
||||
|
||||
+13
@@ -142,6 +142,19 @@ public class AihrSopSeedServiceTest {
|
||||
assertTrue(code.contains("WHERE tenant_id = ? AND id IN (%s)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("dev")
|
||||
public void answerFeedbackNormalizesReviewOwnership() throws Exception {
|
||||
Path source = Path.of("src/main/java/org/dromara/aihr/service/AihrSopSeedService.java");
|
||||
if (!Files.exists(source)) {
|
||||
source = Path.of("ruoyi-modules/ruoyi-aihr/src/main/java/org/dromara/aihr/service/AihrSopSeedService.java");
|
||||
}
|
||||
String code = Files.readString(source);
|
||||
|
||||
assertTrue(code.contains("Long reviewId = normalizeFeedbackReviewId(request.reviewId())"));
|
||||
assertTrue(code.contains("WHERE tenant_id = ? AND id = ?"));
|
||||
}
|
||||
|
||||
private static AihrSopSeedService.KnowledgeHit hit(Long fragmentId, String title) {
|
||||
return new AihrSopSeedService.KnowledgeHit(fragmentId, title, "sop", "", "doc-" + fragmentId, "片段内容", 1, 1.0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user