feat(databus): 完成阶段一+二-数据契约层与数据提供者
阶段一:数据契约层(任务 1-16) - 新增 DatabusDeptData, DatabusAdminUserData, DatabusPostData 数据对象 - 新增 CursorPageReqDTO, CursorPageResult 游标分页 DTO - 新增 DatabusDeptProviderApi, DatabusUserProviderApi, DatabusPostProviderApi Feign 接口 - 修改 system-api pom.xml 添加 databus-api 依赖 阶段二:数据提供者实现(任务 17-38) - 新增 DatabusDeptProviderApiImpl, DatabusUserProviderApiImpl, DatabusPostProviderApiImpl Feign 接口实现 - 实现游标分页查询(基于 cursorTime + cursorId 复合游标) - 新增 DatabusDeptChangeMessage, DatabusUserChangeMessage, DatabusPostChangeMessage MQ 消息类 - 新增 DatabusChangeProducer 消息生产者(支持部门、用户、岗位三实体) - 修改 DeptServiceImpl, AdminUserServiceImpl, PostServiceImpl 添加事件发布 技术要点: - 游标分页:cursorTime + cursorId 复合游标解决雪花ID乱序问题 - 事件发布:create/update/delete 操作后异步发送 MQ 消息 - 数据聚合:用户数据包含部门和岗位简要信息 Ref: docs/databus/implementation-checklist.md 任务 1-38
This commit is contained in:
@@ -22,6 +22,13 @@
|
||||
<artifactId>zt-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- DataBus API -->
|
||||
<dependency>
|
||||
<groupId>com.zt.plat</groupId>
|
||||
<artifactId>zt-module-databus-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Web 相关 -->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId> <!-- 接口文档:使用最新版本的 Swagger 模型 -->
|
||||
|
||||
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
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
File diff suppressed because it is too large
Load Diff
@@ -50,6 +50,8 @@ public class DeptServiceImpl implements DeptService {
|
||||
private DeptMapper deptMapper;
|
||||
@Resource
|
||||
private UserDeptMapper userDeptMapper;
|
||||
@Resource
|
||||
private com.zt.plat.module.system.mq.producer.databus.DatabusChangeProducer databusChangeProducer;
|
||||
|
||||
private static final String ROOT_CODE_PREFIX = "ZT";
|
||||
private static final int CODE_SEGMENT_LENGTH = 3;
|
||||
@@ -99,6 +101,10 @@ public class DeptServiceImpl implements DeptService {
|
||||
dept.setDeptSource(DeptSourceEnum.EXTERNAL.getSource());
|
||||
}
|
||||
deptMapper.insert(dept);
|
||||
|
||||
// 发布部门创建事件
|
||||
databusChangeProducer.sendDeptCreatedMessage(dept);
|
||||
|
||||
return dept.getId();
|
||||
}
|
||||
|
||||
@@ -153,6 +159,12 @@ public class DeptServiceImpl implements DeptService {
|
||||
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
|
||||
deptMapper.updateById(updateObj);
|
||||
|
||||
// 发布部门更新事件(重新查询获取完整数据)
|
||||
DeptDO updatedDept = deptMapper.selectById(updateObj.getId());
|
||||
if (updatedDept != null) {
|
||||
databusChangeProducer.sendDeptUpdatedMessage(updatedDept);
|
||||
}
|
||||
|
||||
if (parentChanged) {
|
||||
refreshChildCodesRecursively(updateObj.getId(), updateReqVO.getCode());
|
||||
}
|
||||
@@ -168,8 +180,16 @@ public class DeptServiceImpl implements DeptService {
|
||||
if (deptMapper.selectCountByParentId(id) > 0) {
|
||||
throw exception(DEPT_EXITS_CHILDREN);
|
||||
}
|
||||
|
||||
// 删除前先查询部门信息(用于发布事件)
|
||||
DeptDO dept = deptMapper.selectById(id);
|
||||
Long tenantId = (dept != null) ? dept.getTenantId() : null;
|
||||
|
||||
// 删除部门
|
||||
deptMapper.deleteById(id);
|
||||
|
||||
// 发布部门删除事件
|
||||
databusChangeProducer.sendDeptDeletedMessage(id, tenantId);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -34,6 +34,9 @@ public class PostServiceImpl implements PostService {
|
||||
@Resource
|
||||
private PostMapper postMapper;
|
||||
|
||||
@Resource
|
||||
private com.zt.plat.module.system.mq.producer.databus.DatabusChangeProducer databusChangeProducer;
|
||||
|
||||
@Override
|
||||
public Long createPost(PostSaveReqVO createReqVO) {
|
||||
// 校验正确性
|
||||
@@ -42,6 +45,10 @@ public class PostServiceImpl implements PostService {
|
||||
// 插入岗位
|
||||
PostDO post = BeanUtils.toBean(createReqVO, PostDO.class);
|
||||
postMapper.insert(post);
|
||||
|
||||
// 发布岗位创建事件
|
||||
databusChangeProducer.sendPostCreatedMessage(post);
|
||||
|
||||
return post.getId();
|
||||
}
|
||||
|
||||
@@ -53,14 +60,24 @@ public class PostServiceImpl implements PostService {
|
||||
// 更新岗位
|
||||
PostDO updateObj = BeanUtils.toBean(updateReqVO, PostDO.class);
|
||||
postMapper.updateById(updateObj);
|
||||
|
||||
// 发布岗位更新事件(重新查询获取完整数据)
|
||||
PostDO updatedPost = postMapper.selectById(updateObj.getId());
|
||||
if (updatedPost != null) {
|
||||
databusChangeProducer.sendPostUpdatedMessage(updatedPost);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePost(Long id) {
|
||||
// 校验是否存在
|
||||
validatePostExists(id);
|
||||
|
||||
// 删除部门
|
||||
postMapper.deleteById(id);
|
||||
|
||||
// 发布岗位删除事件(PostDO 不支持多租户,tenantId 为 null)
|
||||
databusChangeProducer.sendPostDeletedMessage(id);
|
||||
}
|
||||
|
||||
private void validatePostForCreateOrUpdate(Long id, String name, String code) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user