1. 提高 databus api 的网络失败重试次数,避免复用旧链接导致的 connection reset 错误

2. 兼容顶级组织同步时的组织编码生成逻辑
This commit is contained in:
chenbowen
2025-11-04 14:43:53 +08:00
parent b98f605dfd
commit 811270a4c5
6 changed files with 209 additions and 18 deletions

View File

@@ -84,6 +84,45 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
assertEquals(parentDept.getCode() + "001", childDept.getCode());
}
@Test
public void testCreateDept_topLevelAutoCodeAndDuplicates() {
DeptSaveReqVO topLevelReq = new DeptSaveReqVO();
topLevelReq.setParentId(DeptDO.PARENT_ID_ROOT);
topLevelReq.setName("总部");
topLevelReq.setSort(1);
topLevelReq.setStatus(CommonStatusEnum.ENABLE.getStatus());
topLevelReq.setDeptSource(1);
Long topLevelId = deptService.createDept(topLevelReq);
DeptDO firstTop = deptMapper.selectById(topLevelId);
assertEquals("ZT001", firstTop.getCode());
DeptSaveReqVO secondTopLevelReq = new DeptSaveReqVO();
secondTopLevelReq.setParentId(DeptDO.PARENT_ID_ROOT);
secondTopLevelReq.setName("总部");
secondTopLevelReq.setSort(2);
secondTopLevelReq.setStatus(CommonStatusEnum.ENABLE.getStatus());
secondTopLevelReq.setDeptSource(1);
Long secondTopId = deptService.createDept(secondTopLevelReq);
DeptDO secondTop = deptMapper.selectById(secondTopId);
assertEquals("ZT002", secondTop.getCode());
}
@Test
public void testCreateDept_topLevelRespectCustomCode() {
String customCode = "ROOT-001";
DeptSaveReqVO topLevelReq = new DeptSaveReqVO();
topLevelReq.setParentId(DeptDO.PARENT_ID_ROOT);
topLevelReq.setName("集团");
topLevelReq.setSort(1);
topLevelReq.setStatus(CommonStatusEnum.ENABLE.getStatus());
topLevelReq.setDeptSource(1);
topLevelReq.setCode(customCode);
Long deptId = deptService.createDept(topLevelReq);
DeptDO created = deptMapper.selectById(deptId);
assertEquals(customCode, created.getCode());
}
@Test
public void testUpdateDept() {
// mock 数据
@@ -205,20 +244,68 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
@Test
public void testValidateNameUnique_duplicate() {
// mock 数据
DeptDO deptDO = randomPojo(DeptDO.class).setDeptSource(null);
// mock 上级部门
DeptDO parentDept = randomPojo(DeptDO.class, o -> {
o.setParentId(DeptDO.PARENT_ID_ROOT);
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
}).setDeptSource(null);
deptMapper.insert(parentDept);
// mock 同级重名部门
String duplicateName = randomString(6);
DeptDO deptDO = randomPojo(DeptDO.class, o -> {
o.setParentId(parentDept.getId());
o.setName(duplicateName);
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
}).setDeptSource(null);
deptMapper.insert(deptDO);
// 准备参数
Long id = randomLongId();
Long parentId = deptDO.getParentId();
String name = deptDO.getName();
// 调用, 并断言异常
assertServiceException(() -> deptService.validateDeptNameUnique(id, parentId, name),
assertServiceException(() -> deptService.validateDeptNameUnique(randomLongId(), parentDept.getId(), duplicateName),
DEPT_NAME_DUPLICATE);
}
@Test
public void testValidateDeptNameUnique_topLevelDuplicateAllowed() {
// mock 顶级部门
String duplicateName = randomString(6);
DeptDO topLevelDept = randomPojo(DeptDO.class, o -> {
o.setParentId(DeptDO.PARENT_ID_ROOT);
o.setName(duplicateName);
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
}).setDeptSource(null);
deptMapper.insert(topLevelDept);
// 调用, 验证不会抛出异常
assertDoesNotThrow(() -> deptService.validateDeptNameUnique(null, DeptDO.PARENT_ID_ROOT, duplicateName));
}
@Test
public void testValidateDeptNameUnique_differentParentAllowed() {
// mock 不同上级部门
DeptDO parentA = randomPojo(DeptDO.class, o -> {
o.setParentId(DeptDO.PARENT_ID_ROOT);
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
}).setDeptSource(null);
deptMapper.insert(parentA);
DeptDO parentB = randomPojo(DeptDO.class, o -> {
o.setParentId(DeptDO.PARENT_ID_ROOT);
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
}).setDeptSource(null);
deptMapper.insert(parentB);
String duplicateName = randomString(6);
DeptDO childUnderA = randomPojo(DeptDO.class, o -> {
o.setParentId(parentA.getId());
o.setName(duplicateName);
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
}).setDeptSource(null);
deptMapper.insert(childUnderA);
// 调用, 验证不同父级可以重名
assertDoesNotThrow(() -> deptService.validateDeptNameUnique(null, parentB.getId(), duplicateName));
}
@Test
public void testGetDept() {
// mock 数据