1. 去除部门编码为空时,默认使用 id 作为 code 进行映射的逻辑

This commit is contained in:
chenbowen
2025-12-18 22:26:05 +08:00
parent 494de02d65
commit bdd22ed132
3 changed files with 205 additions and 2 deletions

View File

@@ -513,7 +513,7 @@ public class IWorkSyncProcessorImpl implements IWorkSyncProcessor {
req.setIsGroup(Boolean.FALSE); req.setIsGroup(Boolean.FALSE);
req.setDeptSource(DeptSourceEnum.IWORK.getSource()); req.setDeptSource(DeptSourceEnum.IWORK.getSource());
req.setExternalSystemCode(ExternalPlatformEnum.IWORK.getCode()); req.setExternalSystemCode(ExternalPlatformEnum.IWORK.getCode());
req.setExternalDeptCode(StrUtil.blankToDefault(trimToNull(data.getSubcompanycode()), String.valueOf(data.getId()))); req.setExternalDeptCode(trimToNull(data.getSubcompanycode()));
req.setExternalDeptName(data.getSubcompanyname()); req.setExternalDeptName(data.getSubcompanyname());
return req; return req;
} }
@@ -533,7 +533,7 @@ public class IWorkSyncProcessorImpl implements IWorkSyncProcessor {
req.setIsGroup(Boolean.FALSE); req.setIsGroup(Boolean.FALSE);
req.setDeptSource(DeptSourceEnum.IWORK.getSource()); req.setDeptSource(DeptSourceEnum.IWORK.getSource());
req.setExternalSystemCode(ExternalPlatformEnum.IWORK.getCode()); req.setExternalSystemCode(ExternalPlatformEnum.IWORK.getCode());
req.setExternalDeptCode(StrUtil.blankToDefault(trimToNull(data.getDepartmentcode()), String.valueOf(data.getId()))); req.setExternalDeptCode(trimToNull(data.getDepartmentcode()));
req.setExternalDeptName(data.getDepartmentname()); req.setExternalDeptName(data.getDepartmentname());
return req; return req;
} }

View File

@@ -0,0 +1,62 @@
package com.zt.plat.module.system.service.integration.iwork.impl;
import com.zt.plat.framework.test.core.ut.BaseMockitoUnitTest;
import com.zt.plat.module.system.controller.admin.integration.iwork.vo.IWorkFullSyncReqVO;
import com.zt.plat.module.system.controller.admin.integration.iwork.vo.IWorkHrDepartmentPageRespVO;
import com.zt.plat.module.system.enums.integration.IWorkSyncEntityTypeEnum;
import com.zt.plat.module.system.service.dept.DeptService;
import com.zt.plat.module.system.service.integration.iwork.IWorkOrgRestService;
import com.zt.plat.module.system.service.integration.iwork.IWorkSyncProcessor;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.stubbing.Answer;
import java.util.List;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
class IWorkSyncServiceImplTest extends BaseMockitoUnitTest {
@InjectMocks
private IWorkSyncServiceImpl syncService;
@Mock
private IWorkOrgRestService orgRestService;
@Mock
private IWorkSyncProcessor syncProcessor;
@Mock
private DeptService deptService;
@Test
void shouldBackfillCodesWhenPlaceholdersExistAfterFullSync() {
IWorkFullSyncReqVO reqVO = new IWorkFullSyncReqVO();
reqVO.setPageSize(1);
reqVO.setMaxPages(1);
IWorkHrDepartmentPageRespVO pageResp = new IWorkHrDepartmentPageRespVO();
pageResp.setSuccess(true);
IWorkHrDepartmentPageRespVO.Department dept = new IWorkHrDepartmentPageRespVO.Department();
dept.setId(1);
pageResp.setDataList(List.of(dept));
when(orgRestService.listDepartments(any())).thenReturn(pageResp);
// 在部门同步时标记占位 ID
doAnswer((Answer<IWorkSyncProcessor.BatchResult>) invocation -> {
IWorkSyncProcessor.DeptSyncContext context = invocation.getArgument(2);
if (context != null) {
context.getPlaceholderDeptIds().add(500L);
}
return IWorkSyncProcessor.BatchResult.empty();
}).when(syncProcessor).syncDepartments(any(), any(), any(IWorkSyncProcessor.DeptSyncContext.class));
when(syncProcessor.flushDeptPending(any(), any())).thenReturn(IWorkSyncProcessor.BatchResult.empty());
syncService.fullSyncDepartments(reqVO);
verify(deptService, times(1)).backfillMissingCodesWithoutEvent(argThat(set -> set.contains(500L)));
}
}