1. 统一 iwork 的同步组织代码生成逻辑

This commit is contained in:
chenbowen
2025-12-18 14:18:56 +08:00
parent 870c6a5f88
commit 1fa7416905
3 changed files with 29 additions and 4 deletions

View File

@@ -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.mysql.dept.DeptMapper;
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.enums.dept.DeptSourceEnum;
import com.zt.plat.module.system.service.permission.PermissionService;
@@ -56,6 +57,8 @@ public class DeptServiceImpl implements DeptService {
private PermissionService permissionService;
@Resource
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 EXTERNAL_CODE_PREFIX = "CU";
@@ -101,12 +104,24 @@ public class DeptServiceImpl implements DeptService {
}
deptMapper.insert(dept);
// 外部编码映射
upsertExternalMappingIfPresent(dept.getId(), createReqVO);
// 发布部门创建事件
databusChangeProducer.sendDeptCreatedMessage(dept);
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
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存
@@ -141,6 +156,9 @@ public class DeptServiceImpl implements DeptService {
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
deptMapper.updateById(updateObj);
// 外部编码映射
upsertExternalMappingIfPresent(updateObj.getId(), updateReqVO);
// 发布部门更新事件(重新查询获取完整数据)
DeptDO updatedDept = deptMapper.selectById(updateObj.getId());
if (updatedDept != null) {
@@ -164,6 +182,9 @@ public class DeptServiceImpl implements DeptService {
DeptDO dept = deptMapper.selectById(id);
Long tenantId = (dept != null) ? dept.getTenantId() : null;
// 级联删除外部编码映射
deptExternalCodeService.deleteDeptExternalCodesByDeptId(id);
// 删除部门
deptMapper.deleteById(id);