1. 统一 iwork 的同步组织代码生成逻辑
This commit is contained in:
@@ -16,6 +16,7 @@ import com.zt.plat.module.system.dal.dataobject.dept.DeptDO;
|
|||||||
import com.zt.plat.module.system.dal.dataobject.userdept.UserDeptDO;
|
import com.zt.plat.module.system.dal.dataobject.userdept.UserDeptDO;
|
||||||
import com.zt.plat.module.system.dal.mysql.dept.DeptMapper;
|
import com.zt.plat.module.system.dal.mysql.dept.DeptMapper;
|
||||||
import com.zt.plat.module.system.dal.mysql.userdept.UserDeptMapper;
|
import com.zt.plat.module.system.dal.mysql.userdept.UserDeptMapper;
|
||||||
|
import com.zt.plat.module.system.service.dept.DeptExternalCodeService;
|
||||||
import com.zt.plat.module.system.dal.redis.RedisKeyConstants;
|
import com.zt.plat.module.system.dal.redis.RedisKeyConstants;
|
||||||
import com.zt.plat.module.system.enums.dept.DeptSourceEnum;
|
import com.zt.plat.module.system.enums.dept.DeptSourceEnum;
|
||||||
import com.zt.plat.module.system.service.permission.PermissionService;
|
import com.zt.plat.module.system.service.permission.PermissionService;
|
||||||
@@ -56,6 +57,8 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
@Resource
|
@Resource
|
||||||
private com.zt.plat.module.system.mq.producer.databus.DatabusChangeProducer databusChangeProducer;
|
private com.zt.plat.module.system.mq.producer.databus.DatabusChangeProducer databusChangeProducer;
|
||||||
|
@Resource
|
||||||
|
private DeptExternalCodeService deptExternalCodeService;
|
||||||
|
|
||||||
private static final String ROOT_CODE_PREFIX = "ZT";
|
private static final String ROOT_CODE_PREFIX = "ZT";
|
||||||
private static final String EXTERNAL_CODE_PREFIX = "CU";
|
private static final String EXTERNAL_CODE_PREFIX = "CU";
|
||||||
@@ -101,12 +104,24 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
}
|
}
|
||||||
deptMapper.insert(dept);
|
deptMapper.insert(dept);
|
||||||
|
|
||||||
|
// 外部编码映射
|
||||||
|
upsertExternalMappingIfPresent(dept.getId(), createReqVO);
|
||||||
|
|
||||||
// 发布部门创建事件
|
// 发布部门创建事件
|
||||||
databusChangeProducer.sendDeptCreatedMessage(dept);
|
databusChangeProducer.sendDeptCreatedMessage(dept);
|
||||||
|
|
||||||
return dept.getId();
|
return dept.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void upsertExternalMappingIfPresent(Long deptId, DeptSaveReqVO reqVO) {
|
||||||
|
String systemCode = StrUtil.trimToNull(reqVO.getExternalSystemCode());
|
||||||
|
String externalCode = StrUtil.trimToNull(reqVO.getExternalDeptCode());
|
||||||
|
if (StrUtil.hasEmpty(systemCode, externalCode) || deptId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String externalName = StrUtil.trimToNull(reqVO.getExternalDeptName());
|
||||||
|
deptExternalCodeService.saveOrUpdateDeptExternalCode(deptId, systemCode, externalCode, externalName, reqVO.getStatus());
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
|
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
|
||||||
allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存
|
allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存
|
||||||
@@ -141,6 +156,9 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
|
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
|
||||||
deptMapper.updateById(updateObj);
|
deptMapper.updateById(updateObj);
|
||||||
|
|
||||||
|
// 外部编码映射
|
||||||
|
upsertExternalMappingIfPresent(updateObj.getId(), updateReqVO);
|
||||||
|
|
||||||
// 发布部门更新事件(重新查询获取完整数据)
|
// 发布部门更新事件(重新查询获取完整数据)
|
||||||
DeptDO updatedDept = deptMapper.selectById(updateObj.getId());
|
DeptDO updatedDept = deptMapper.selectById(updateObj.getId());
|
||||||
if (updatedDept != null) {
|
if (updatedDept != null) {
|
||||||
@@ -164,6 +182,9 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
DeptDO dept = deptMapper.selectById(id);
|
DeptDO dept = deptMapper.selectById(id);
|
||||||
Long tenantId = (dept != null) ? dept.getTenantId() : null;
|
Long tenantId = (dept != null) ? dept.getTenantId() : null;
|
||||||
|
|
||||||
|
// 级联删除外部编码映射
|
||||||
|
deptExternalCodeService.deleteDeptExternalCodesByDeptId(id);
|
||||||
|
|
||||||
// 删除部门
|
// 删除部门
|
||||||
deptMapper.deleteById(id);
|
deptMapper.deleteById(id);
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,11 @@ 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.dal.mysql.dept.DeptMapper;
|
||||||
import com.zt.plat.module.system.dal.redis.RedisKeyConstants;
|
import com.zt.plat.module.system.dal.redis.RedisKeyConstants;
|
||||||
import com.zt.plat.module.system.enums.dept.DeptSourceEnum;
|
import com.zt.plat.module.system.enums.dept.DeptSourceEnum;
|
||||||
|
import com.zt.plat.module.system.service.permission.PermissionService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.TestConfiguration;
|
import org.springframework.boot.test.context.TestConfiguration;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
import org.springframework.cache.CacheManager;
|
import org.springframework.cache.CacheManager;
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||||
@@ -51,6 +53,9 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
|
|||||||
@Resource
|
@Resource
|
||||||
private CacheManager cacheManager;
|
private CacheManager cacheManager;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private PermissionService permissionService;
|
||||||
|
|
||||||
@TestConfiguration
|
@TestConfiguration
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
static class CacheConfig {
|
static class CacheConfig {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ create table IF NOT EXISTS system_user_dept (
|
|||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS "system_dept" (
|
CREATE TABLE IF NOT EXISTS "system_dept" (
|
||||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||||
"code" varchar(64) NOT NULL DEFAULT '',
|
"code" varchar(64) DEFAULT NULL,
|
||||||
"name" varchar(30) NOT NULL DEFAULT '',
|
"name" varchar(30) NOT NULL DEFAULT '',
|
||||||
"short_name" varchar(30) DEFAULT '',
|
"short_name" varchar(30) DEFAULT '',
|
||||||
"parent_id" bigint NOT NULL DEFAULT '0',
|
"parent_id" bigint NOT NULL DEFAULT '0',
|
||||||
@@ -51,9 +51,8 @@ CREATE TABLE IF NOT EXISTS "system_dept_external_code" (
|
|||||||
PRIMARY KEY ("id")
|
PRIMARY KEY ("id")
|
||||||
) COMMENT '部门外部组织编码映射';
|
) 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 INDEX IF NOT EXISTS "idx_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", "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" (
|
CREATE TABLE IF NOT EXISTS "system_dict_data" (
|
||||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||||
|
|||||||
Reference in New Issue
Block a user