fix(aihr): require explicit org sync dry run
This commit is contained in:
+4
-1
@@ -74,6 +74,9 @@ public class AihrOrgSyncService {
|
||||
|
||||
public SyncResponse sync(SyncRequest request) {
|
||||
SyncRequest req = request == null ? new SyncRequest(null, null, null, null, null, null, null, null) : request;
|
||||
if (req.dryRun() == null) {
|
||||
throw new IllegalArgumentException("组织同步必须明确传 dryRun=true 预检或 dryRun=false 写入");
|
||||
}
|
||||
String baseUrl = normalizeBaseUrl(configuredBaseUrl);
|
||||
if (baseUrl.isBlank()) {
|
||||
throw new IllegalArgumentException("请先配置 AIHR_ORG_SYNC_BASE_URL,值为外部开放平台 /api/open/v1 前缀");
|
||||
@@ -81,7 +84,7 @@ public class AihrOrgSyncService {
|
||||
|
||||
int pageSize = clamp(req.pageSize(), DEFAULT_PAGE_SIZE, 1, MAX_PAGE_SIZE);
|
||||
int maxPages = clamp(req.maxPages(), DEFAULT_MAX_PAGES, 1, DEFAULT_MAX_PAGES);
|
||||
boolean dryRun = Boolean.TRUE.equals(req.dryRun());
|
||||
boolean dryRun = req.dryRun();
|
||||
if (!dryRun) {
|
||||
requireSnapshotTable();
|
||||
}
|
||||
|
||||
+12
@@ -42,6 +42,18 @@ public class AihrOrgSyncServiceTest {
|
||||
assertFalse(AihrOrgSyncService.hasUnsafeReplaceData(22, 22, 0, 22, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void syncRequiresExplicitDryRunMode() {
|
||||
JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||
TransactionTemplate transactionTemplate = mock(TransactionTemplate.class);
|
||||
AihrOrgSyncService service = new AihrOrgSyncService(new ObjectMapper(), jdbcTemplate, transactionTemplate);
|
||||
|
||||
IllegalArgumentException error = assertThrows(IllegalArgumentException.class, () -> service.sync(null));
|
||||
|
||||
assertTrue(error.getMessage().contains("dryRun"));
|
||||
verifyNoInteractions(jdbcTemplate, transactionTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicateExternalPartyIdsAreCountedAfterTheFirstOccurrence() {
|
||||
assertEquals(1, AihrOrgSyncService.countDuplicatePartyIds(List.of("EMP-1", "EMP-2", "EMP-1")));
|
||||
|
||||
Reference in New Issue
Block a user