1. 新增生成自有组织 CODE,同步其他系统额外生成编码映射关系
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -5,11 +5,20 @@ import com.zt.plat.framework.common.util.object.ObjectUtils;
|
||||
import com.zt.plat.framework.test.core.ut.BaseDbUnitTest;
|
||||
import com.zt.plat.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
||||
import com.zt.plat.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
|
||||
import com.zt.plat.module.system.controller.admin.dept.vo.depexternalcode.DeptExternalCodeSaveReqVO;
|
||||
import com.zt.plat.module.system.dal.dataobject.dept.DeptDO;
|
||||
import com.zt.plat.module.system.dal.mysql.dept.DeptExternalCodeMapper;
|
||||
import com.zt.plat.module.system.dal.mysql.dept.DeptMapper;
|
||||
import com.zt.plat.module.system.service.dept.DeptExternalCodeServiceImpl;
|
||||
import com.zt.plat.module.system.dal.redis.RedisKeyConstants;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -27,13 +36,31 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
*
|
||||
* @author niudehua
|
||||
*/
|
||||
@Import(DeptServiceImpl.class)
|
||||
@Import({DeptServiceImpl.class, DeptExternalCodeServiceImpl.class, DeptServiceImplTest.CacheConfig.class})
|
||||
public class DeptServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private DeptServiceImpl deptService;
|
||||
@Resource
|
||||
private DeptMapper deptMapper;
|
||||
@Resource
|
||||
private DeptExternalCodeServiceImpl deptExternalCodeService;
|
||||
@Resource
|
||||
private DeptExternalCodeMapper deptExternalCodeMapper;
|
||||
@Resource
|
||||
private CacheManager cacheManager;
|
||||
|
||||
@TestConfiguration
|
||||
@EnableCaching
|
||||
static class CacheConfig {
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
return new ConcurrentMapCacheManager(
|
||||
RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
|
||||
RedisKeyConstants.DEPT_EXTERNAL_CODE_LIST
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private Long createDept(Long parentId, String name, int sort) {
|
||||
DeptSaveReqVO reqVO = new DeptSaveReqVO();
|
||||
@@ -108,7 +135,7 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateDept_topLevelRespectCustomCode() {
|
||||
public void testCreateDept_topLevelAutoCode_ignoreCustomInput() {
|
||||
String customCode = "ROOT-001";
|
||||
DeptSaveReqVO topLevelReq = new DeptSaveReqVO();
|
||||
topLevelReq.setParentId(DeptDO.PARENT_ID_ROOT);
|
||||
@@ -120,7 +147,7 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
Long deptId = deptService.createDept(topLevelReq);
|
||||
DeptDO created = deptMapper.selectById(deptId);
|
||||
assertEquals(customCode, created.getCode());
|
||||
assertEquals("ZT001", created.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,6 +214,29 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
|
||||
assertNull(deptMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteDept_cascadeExternalCodesAndEvictCache() {
|
||||
Long deptId = createDept(DeptDO.PARENT_ID_ROOT, "总部", 1);
|
||||
|
||||
// 创建映射并预热缓存
|
||||
DeptExternalCodeSaveReqVO createReq = new DeptExternalCodeSaveReqVO();
|
||||
createReq.setDeptId(deptId);
|
||||
createReq.setSystemCode("ERP");
|
||||
createReq.setExternalDeptCode("ERP-001");
|
||||
deptExternalCodeService.createDeptExternalCode(createReq);
|
||||
deptExternalCodeService.getDeptExternalCodeListByDeptId(deptId);
|
||||
assertNotNull(cacheManager.getCache(com.zt.plat.module.system.dal.redis.RedisKeyConstants.DEPT_EXTERNAL_CODE_LIST)
|
||||
.get(deptId));
|
||||
|
||||
// 删除部门
|
||||
deptService.deleteDept(deptId);
|
||||
|
||||
// 校验映射被删除且缓存被清理
|
||||
assertTrue(deptExternalCodeMapper.selectListByDeptId(deptId).isEmpty());
|
||||
assertNull(cacheManager.getCache(com.zt.plat.module.system.dal.redis.RedisKeyConstants.DEPT_EXTERNAL_CODE_LIST)
|
||||
.get(deptId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteDept_exitsChildren() {
|
||||
// mock 数据
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
DELETE FROM "system_dept";
|
||||
DELETE FROM "system_dept_external_code";
|
||||
DELETE FROM "system_dict_data";
|
||||
DELETE FROM "system_role";
|
||||
DELETE FROM "system_role_menu";
|
||||
|
||||
@@ -34,6 +34,27 @@ CREATE TABLE IF NOT EXISTS "system_dept" (
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '部门表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "system_dept_external_code" (
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"dept_id" bigint NOT NULL,
|
||||
"system_code" varchar(64) NOT NULL,
|
||||
"external_dept_code" varchar(128) NOT NULL,
|
||||
"external_dept_name" varchar(255),
|
||||
"status" tinyint DEFAULT 0 NOT NULL,
|
||||
"remark" varchar(512),
|
||||
"tenant_id" bigint DEFAULT 0,
|
||||
"creator" varchar(64),
|
||||
"create_time" timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar(64),
|
||||
"update_time" timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" tinyint DEFAULT 0 NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '部门外部组织编码映射';
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "uk_system_dept_external_code_ext" ON "system_dept_external_code" ("tenant_id", "system_code", "external_dept_code");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "uk_system_dept_external_code_dept" ON "system_dept_external_code" ("tenant_id", "system_code", "dept_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_system_dept_external_code_dept" ON "system_dept_external_code" ("tenant_id", "dept_id");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "system_dict_data" (
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"sort" int NOT NULL DEFAULT '0',
|
||||
|
||||
Reference in New Issue
Block a user