fix(aihr): restore org snapshot anomaly counts

This commit is contained in:
2026-07-14 09:55:26 +08:00
parent 829ce331f6
commit 91bd28811d
4 changed files with 55 additions and 4 deletions
@@ -187,10 +187,10 @@ public class AihrOrgSyncService {
select count(*) from aihr_org_snapshot
""" + where + """
and (
person_name like '%?%'
or project_name like '%?%'
or dept_name like '%?%'
or position_name like '%?%'
instr(coalesce(person_name, ''), '?') > 0
or instr(coalesce(project_name, ''), '?') > 0
or instr(coalesce(dept_name, ''), '?') > 0
or instr(coalesce(position_name, ''), '?') > 0
)
""", args);
List<Object> rowArgs = new ArrayList<>(args);
@@ -6,11 +6,13 @@ import org.dromara.aihr.domain.AihrOrgSyncDto.SyncRequest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Tag;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.transaction.support.TransactionTemplate;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -54,6 +56,21 @@ public class AihrOrgSyncServiceTest {
assertFalse(AihrOrgSyncService.hasUnusablePhoneCandidate(mapper.readTree("{\"name\":\"张三\"}")));
}
@Test
public void snapshotSuspectTextQuerySearchesLiteralQuestionMarks() {
SnapshotJdbcTemplate jdbcTemplate = new SnapshotJdbcTemplate();
AihrOrgSyncService service = new AihrOrgSyncService(new ObjectMapper(), jdbcTemplate, mock(TransactionTemplate.class));
service.snapshot(null, null, null, null, 1, 20, null);
String suspectQuery = jdbcTemplate.queries.stream()
.filter(sql -> sql.contains("coalesce(person_name"))
.findFirst()
.orElseThrow();
assertTrue(suspectQuery.contains("instr(coalesce(person_name, ''), '?') > 0"));
assertFalse(suspectQuery.contains("like '%?%'"));
}
@Test
public void dryRunNeverTouchesSnapshotSchemaWhenExternalFetchFails() {
JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
@@ -110,4 +127,31 @@ public class AihrOrgSyncServiceTest {
server.stop(0);
}
}
private static final class SnapshotJdbcTemplate extends JdbcTemplate {
private final List<String> queries = new ArrayList<>();
@Override
public <T> T queryForObject(String sql, Class<T> requiredType) {
queries.add(sql);
return requiredType.cast(1);
}
@Override
public <T> T queryForObject(String sql, Class<T> requiredType, Object... args) {
queries.add(sql);
return requiredType.cast(0);
}
@Override
public <T> List<T> query(String sql, RowMapper<T> rowMapper, Object... args) {
queries.add(sql);
return List.of();
}
@Override
public void execute(String sql) {
// Schema setup is irrelevant for this query contract test.
}
}
}