fix(aihr): scope interview results to tenant

This commit is contained in:
2026-07-14 06:32:01 +08:00
parent 0f647f8086
commit c7f4ce4a48
2 changed files with 18 additions and 2 deletions
@@ -119,9 +119,10 @@ public class AihrInterviewService {
StringBuilder sql = new StringBuilder("""
SELECT finished_time, candidate_name, position_code, total_score, result, ai_summary, questions_json
FROM aihr_interview_result
WHERE tenant_id = '000000'
WHERE tenant_id = ?
""");
List<Object> args = new ArrayList<>();
args.add(tenantId());
if (!isBlank(candidateId)) {
sql.append(" AND candidate_id = ?");
args.add(clean(candidateId));
@@ -222,7 +223,7 @@ public class AihrInterviewService {
INSERT INTO aihr_interview_result
(tenant_id, session_id, candidate_id, candidate_name, position_code, total_score, result,
suggestion, ai_summary, evidence, source, answers_json, questions_json, dimensions_json, finished_time, create_time, update_time)
VALUES ('000000', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now(), now())
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now(), now())
ON DUPLICATE KEY UPDATE
candidate_id = VALUES(candidate_id),
candidate_name = VALUES(candidate_name),
@@ -239,6 +240,7 @@ public class AihrInterviewService {
finished_time = VALUES(finished_time),
update_time = now()
""",
tenantId(),
sessionId,
session.candidate().id(),
session.candidate().name(),
@@ -3,6 +3,7 @@ package org.dromara.aihr.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.dromara.aihr.domain.AihrInterviewDto.CandidateLinkRequest;
import org.dromara.aihr.domain.AihrInterviewDto.CandidateLinkResponse;
import org.dromara.aihr.domain.AihrInterviewDto.RecordResponse;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -89,4 +90,17 @@ class AihrInterviewServiceTest {
assertSame(linked, result);
verify(jdbcTemplate).update(anyString(), eq("000000"), eq("candidate-3"), eq("employee-3"), eq("hr"));
}
@Test
@Tag("dev")
void interviewRecordsAreScopedToCurrentTenant() {
JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
AihrInterviewService service = new AihrInterviewService(new ObjectMapper(), null, jdbcTemplate);
when(jdbcTemplate.query(anyString(), org.mockito.ArgumentMatchers.<RowMapper<RecordResponse>>any(), eq("000000")))
.thenReturn(java.util.List.of());
assertEquals(java.util.List.of(), service.records(20));
verify(jdbcTemplate).query(anyString(), org.mockito.ArgumentMatchers.<RowMapper<RecordResponse>>any(), eq("000000"));
}
}