1. 新增外部系统编码部门编码关联管理
2. 新增统一的 api 对外门户管理 3. 修正各个模块的 api 命名
This commit is contained in:
@@ -35,6 +35,18 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
|
||||
@Resource
|
||||
private DeptMapper deptMapper;
|
||||
|
||||
private Long createDept(Long parentId, String name, int sort) {
|
||||
DeptSaveReqVO reqVO = new DeptSaveReqVO();
|
||||
reqVO.setParentId(parentId);
|
||||
reqVO.setName(name);
|
||||
reqVO.setSort(sort);
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setDeptSource(1);
|
||||
reqVO.setIsCompany(false);
|
||||
reqVO.setIsGroup(false);
|
||||
return deptService.createDept(reqVO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateDept() {
|
||||
// 准备参数
|
||||
@@ -42,6 +54,7 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
|
||||
o.setId(null); // 防止 id 被设置
|
||||
o.setParentId(DeptDO.PARENT_ID_ROOT);
|
||||
o.setStatus(randomCommonStatus());
|
||||
o.setCode(null);
|
||||
}).setDeptSource(1);
|
||||
|
||||
// 调用
|
||||
@@ -50,13 +63,35 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
|
||||
assertNotNull(deptId);
|
||||
// 校验记录的属性是否正确
|
||||
DeptDO deptDO = deptMapper.selectById(deptId);
|
||||
assertPojoEquals(reqVO, deptDO, "id");
|
||||
assertPojoEquals(reqVO, deptDO, "id", "code");
|
||||
assertEquals("ZT001", deptDO.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateDept_childCodeGeneration() {
|
||||
Long parentId = createDept(DeptDO.PARENT_ID_ROOT, "总部", 1);
|
||||
DeptDO parentDept = deptMapper.selectById(parentId);
|
||||
|
||||
DeptSaveReqVO childReq = new DeptSaveReqVO();
|
||||
childReq.setParentId(parentId);
|
||||
childReq.setName("事业部");
|
||||
childReq.setSort(1);
|
||||
childReq.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
childReq.setDeptSource(1);
|
||||
Long childId = deptService.createDept(childReq);
|
||||
|
||||
DeptDO childDept = deptMapper.selectById(childId);
|
||||
assertEquals(parentDept.getCode() + "001", childDept.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDept() {
|
||||
// mock 数据
|
||||
DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())).setDeptSource(null);
|
||||
DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> {
|
||||
o.setStatus(randomCommonStatus());
|
||||
o.setParentId(DeptDO.PARENT_ID_ROOT);
|
||||
}).setDeptSource(null);
|
||||
dbDeptDO.setCode("ZT001");
|
||||
deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
DeptSaveReqVO reqVO = randomPojo(DeptSaveReqVO.class, o -> {
|
||||
@@ -65,12 +100,38 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
|
||||
o.setId(dbDeptDO.getId());
|
||||
o.setStatus(randomCommonStatus());
|
||||
}).setDeptSource(1);
|
||||
reqVO.setCode(dbDeptDO.getCode());
|
||||
|
||||
// 调用
|
||||
deptService.updateDept(reqVO);
|
||||
// 校验是否更新正确
|
||||
DeptDO deptDO = deptMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, deptDO);
|
||||
assertPojoEquals(reqVO, deptDO, "code");
|
||||
assertEquals("ZT001", deptDO.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDept_parentChangedRebuildsCodes() {
|
||||
Long parentAId = createDept(DeptDO.PARENT_ID_ROOT, "A公司", 1);
|
||||
Long parentBId = createDept(DeptDO.PARENT_ID_ROOT, "B公司", 2);
|
||||
Long childId = createDept(parentAId, "子部门", 1);
|
||||
Long grandChildId = createDept(childId, "子部门-一组", 1);
|
||||
|
||||
DeptDO parentB = deptMapper.selectById(parentBId);
|
||||
|
||||
DeptSaveReqVO updateReq = new DeptSaveReqVO();
|
||||
updateReq.setId(childId);
|
||||
updateReq.setName("子部门");
|
||||
updateReq.setParentId(parentBId);
|
||||
updateReq.setSort(1);
|
||||
updateReq.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
updateReq.setDeptSource(1);
|
||||
deptService.updateDept(updateReq);
|
||||
|
||||
DeptDO updatedChild = deptMapper.selectById(childId);
|
||||
DeptDO updatedGrandChild = deptMapper.selectById(grandChildId);
|
||||
assertEquals(parentB.getCode() + "001", updatedChild.getCode());
|
||||
assertEquals(updatedChild.getCode() + "001", updatedGrandChild.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -293,4 +354,44 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
|
||||
assertServiceException(() -> deptService.validateDeptList(ids), DEPT_NOT_ENABLE, deptDO.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializeDeptCodes() {
|
||||
DeptDO root1 = randomPojo(DeptDO.class, o -> {
|
||||
o.setParentId(DeptDO.PARENT_ID_ROOT);
|
||||
o.setSort(1);
|
||||
o.setCode(null);
|
||||
}).setDeptSource(null);
|
||||
deptMapper.insert(root1);
|
||||
DeptDO root2 = randomPojo(DeptDO.class, o -> {
|
||||
o.setParentId(DeptDO.PARENT_ID_ROOT);
|
||||
o.setSort(2);
|
||||
o.setCode(null);
|
||||
}).setDeptSource(null);
|
||||
deptMapper.insert(root2);
|
||||
DeptDO child1 = randomPojo(DeptDO.class, o -> {
|
||||
o.setParentId(root1.getId());
|
||||
o.setSort(1);
|
||||
o.setCode(null);
|
||||
}).setDeptSource(null);
|
||||
deptMapper.insert(child1);
|
||||
DeptDO child2 = randomPojo(DeptDO.class, o -> {
|
||||
o.setParentId(root1.getId());
|
||||
o.setSort(2);
|
||||
o.setCode(null);
|
||||
}).setDeptSource(null);
|
||||
deptMapper.insert(child2);
|
||||
|
||||
deptService.initializeDeptCodes();
|
||||
|
||||
DeptDO updatedRoot1 = deptMapper.selectById(root1.getId());
|
||||
DeptDO updatedRoot2 = deptMapper.selectById(root2.getId());
|
||||
DeptDO updatedChild1 = deptMapper.selectById(child1.getId());
|
||||
DeptDO updatedChild2 = deptMapper.selectById(child2.getId());
|
||||
|
||||
assertEquals("ZT001", updatedRoot1.getCode());
|
||||
assertEquals("ZT002", updatedRoot2.getCode());
|
||||
assertEquals("ZT001001", updatedChild1.getCode());
|
||||
assertEquals("ZT001002", updatedChild2.getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user