1. 新增生成自有组织 CODE,同步其他系统额外生成编码映射关系
This commit is contained in:
@@ -23,6 +23,15 @@ public class DeptSaveReqVO {
|
||||
@Size(max = 50, message = "部门编码长度不能超过 50 个字符")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "外部系统标识,用于建立编码映射", example = "ERP")
|
||||
private String externalSystemCode;
|
||||
|
||||
@Schema(description = "外部系统组织编码,用于建立映射", example = "ERP-001")
|
||||
private String externalDeptCode;
|
||||
|
||||
@Schema(description = "外部系统组织名称", example = "ERP总部")
|
||||
private String externalDeptName;
|
||||
|
||||
@Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "ZT")
|
||||
@NotBlank(message = "部门名称不能为空")
|
||||
@Size(max = 30, message = "部门名称长度不能超过 30 个字符")
|
||||
|
||||
@@ -37,6 +37,10 @@ public interface DeptExternalCodeMapper extends BaseMapperX<DeptExternalCodeDO>
|
||||
return selectList(DeptExternalCodeDO::getDeptId, deptId);
|
||||
}
|
||||
|
||||
default int deleteByDeptId(Long deptId) {
|
||||
return delete(DeptExternalCodeDO::getDeptId, deptId);
|
||||
}
|
||||
|
||||
default List<DeptExternalCodeDO> selectListBySystemCode(String systemCode) {
|
||||
return selectList(DeptExternalCodeDO::getSystemCode, systemCode);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,14 @@ public interface RedisKeyConstants {
|
||||
*/
|
||||
String DEPT_CHILDREN_ID_LIST = "dept_children_ids";
|
||||
|
||||
/**
|
||||
* 指定部门的外部组织编码映射列表缓存
|
||||
* <p>
|
||||
* KEY 格式:dept_external_code_list:{deptId}
|
||||
* VALUE 数据类型:String 映射列表
|
||||
*/
|
||||
String DEPT_EXTERNAL_CODE_LIST = "dept_external_code_list";
|
||||
|
||||
/**
|
||||
* 角色的缓存
|
||||
* <p>
|
||||
|
||||
@@ -49,6 +49,26 @@ public interface DeptExternalCodeService {
|
||||
*/
|
||||
List<DeptExternalCodeDO> getDeptExternalCodeListByDeptId(Long deptId);
|
||||
|
||||
/**
|
||||
* 根据部门与外部系统保存/更新映射(存在则更新,不存在则创建)
|
||||
*
|
||||
* @param deptId 本系统部门 ID
|
||||
* @param systemCode 外部系统标识
|
||||
* @param externalDeptCode 外部系统组织编码
|
||||
* @param externalDeptName 外部系统组织名称(可选)
|
||||
* @param status 状态,默认启用
|
||||
* @return 映射记录 ID
|
||||
*/
|
||||
Long saveOrUpdateDeptExternalCode(Long deptId, String systemCode, String externalDeptCode, String externalDeptName,
|
||||
Integer status);
|
||||
|
||||
/**
|
||||
* 根据部门删除全部外部编码映射
|
||||
*
|
||||
* @param deptId 部门编号
|
||||
*/
|
||||
void deleteDeptExternalCodesByDeptId(Long deptId);
|
||||
|
||||
/**
|
||||
* 根据外部系统与外部组织编码查询映射
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
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