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:
hewencai
2025-12-01 22:25:28 +08:00
parent 7fae3203bc
commit f5ba493f95
19 changed files with 1939 additions and 0 deletions

View File

@@ -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 模型 -->

View File

@@ -0,0 +1,160 @@
package com.zt.plat.module.system.api.mq;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* Databus 部门变更消息
* <p>
* 用于跨服务传递部门变更通知
*
* @author ZT
*/
@Data
@Accessors(chain = true)
public class DatabusDeptChangeMessage implements Serializable {
/**
* 消息 Topic
*/
public static final String TOPIC = "databus-change-system-dept";
/**
* 事件动作create-创建 update-更新 delete-删除
*/
private String action;
/**
* 部门ID
*/
private Long deptId;
/**
* 部门编码
*/
private String deptCode;
/**
* 部门名称
*/
private String deptName;
/**
* 部门简称
*/
private String shortName;
/**
* 上级部门ID
*/
private Long parentId;
/**
* 排序
*/
private Integer sort;
/**
* 负责人用户ID
*/
private Long leaderUserId;
/**
* 联系电话
*/
private String phone;
/**
* 邮箱
*/
private String email;
/**
* 状态0正常 1停用
*/
private Integer status;
/**
* 是否公司
*/
private Boolean isCompany;
/**
* 是否集团
*/
private Boolean isGroup;
/**
* 部门来源类型
*/
private Integer deptSource;
/**
* 租户ID
*/
private Long tenantId;
/**
* 事件时间
*/
private LocalDateTime eventTime;
// ==================== 静态工厂方法 ====================
public static DatabusDeptChangeMessage create(Long deptId, String deptCode, String deptName, String shortName,
Long parentId, Integer sort, Long leaderUserId, String phone,
String email, Integer status, Boolean isCompany, Boolean isGroup,
Integer deptSource, Long tenantId, LocalDateTime createTime) {
return new DatabusDeptChangeMessage()
.setAction("create")
.setDeptId(deptId)
.setDeptCode(deptCode)
.setDeptName(deptName)
.setShortName(shortName)
.setParentId(parentId)
.setSort(sort)
.setLeaderUserId(leaderUserId)
.setPhone(phone)
.setEmail(email)
.setStatus(status)
.setIsCompany(isCompany)
.setIsGroup(isGroup)
.setDeptSource(deptSource)
.setTenantId(tenantId)
.setEventTime(createTime != null ? createTime : LocalDateTime.now());
}
public static DatabusDeptChangeMessage update(Long deptId, String deptCode, String deptName, String shortName,
Long parentId, Integer sort, Long leaderUserId, String phone,
String email, Integer status, Boolean isCompany, Boolean isGroup,
Integer deptSource, Long tenantId, LocalDateTime updateTime) {
return new DatabusDeptChangeMessage()
.setAction("update")
.setDeptId(deptId)
.setDeptCode(deptCode)
.setDeptName(deptName)
.setShortName(shortName)
.setParentId(parentId)
.setSort(sort)
.setLeaderUserId(leaderUserId)
.setPhone(phone)
.setEmail(email)
.setStatus(status)
.setIsCompany(isCompany)
.setIsGroup(isGroup)
.setDeptSource(deptSource)
.setTenantId(tenantId)
.setEventTime(updateTime != null ? updateTime : LocalDateTime.now());
}
public static DatabusDeptChangeMessage delete(Long deptId, Long tenantId) {
return new DatabusDeptChangeMessage()
.setAction("delete")
.setDeptId(deptId)
.setTenantId(tenantId)
.setEventTime(LocalDateTime.now());
}
}

View File

@@ -0,0 +1,109 @@
package com.zt.plat.module.system.api.mq;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* Databus 岗位变更消息
* <p>
* 用于跨服务传递岗位变更通知
*
* @author ZT
*/
@Data
@Accessors(chain = true)
public class DatabusPostChangeMessage implements Serializable {
/**
* 消息 Topic
*/
public static final String TOPIC = "databus-change-system-post";
/**
* 事件动作create-创建 update-更新 delete-删除
*/
private String action;
/**
* 岗位ID
*/
private Long postId;
/**
* 岗位编码
*/
private String postCode;
/**
* 岗位名称
*/
private String postName;
/**
* 排序
*/
private Integer sort;
/**
* 状态0正常 1停用
*/
private Integer status;
/**
* 备注
*/
private String remark;
/**
* 租户IDPostDO 不支持多租户,固定为 null
*/
private Long tenantId;
/**
* 事件时间
*/
private LocalDateTime eventTime;
// ==================== 静态工厂方法 ====================
public static DatabusPostChangeMessage create(Long postId, String postCode, String postName,
Integer sort, Integer status, String remark,
LocalDateTime createTime) {
return new DatabusPostChangeMessage()
.setAction("create")
.setPostId(postId)
.setPostCode(postCode)
.setPostName(postName)
.setSort(sort)
.setStatus(status)
.setRemark(remark)
.setTenantId(null) // PostDO 不支持多租户
.setEventTime(createTime != null ? createTime : LocalDateTime.now());
}
public static DatabusPostChangeMessage update(Long postId, String postCode, String postName,
Integer sort, Integer status, String remark,
LocalDateTime updateTime) {
return new DatabusPostChangeMessage()
.setAction("update")
.setPostId(postId)
.setPostCode(postCode)
.setPostName(postName)
.setSort(sort)
.setStatus(status)
.setRemark(remark)
.setTenantId(null) // PostDO 不支持多租户
.setEventTime(updateTime != null ? updateTime : LocalDateTime.now());
}
public static DatabusPostChangeMessage delete(Long postId) {
return new DatabusPostChangeMessage()
.setAction("delete")
.setPostId(postId)
.setTenantId(null) // PostDO 不支持多租户
.setEventTime(LocalDateTime.now());
}
}

View File

@@ -0,0 +1,154 @@
package com.zt.plat.module.system.api.mq;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Set;
/**
* Databus 用户变更消息
* <p>
* 用于跨服务传递用户变更通知
*
* @author ZT
*/
@Data
@Accessors(chain = true)
public class DatabusUserChangeMessage implements Serializable {
/**
* 消息 Topic
*/
public static final String TOPIC = "databus-change-system-user";
/**
* 事件动作create-创建 update-更新 delete-删除
*/
private String action;
/**
* 用户ID
*/
private Long userId;
/**
* 用户名
*/
private String username;
/**
* 昵称
*/
private String nickname;
/**
* 备注
*/
private String remark;
/**
* 部门ID集合
*/
private Set<Long> deptIds;
/**
* 岗位ID集合
*/
private Set<Long> postIds;
/**
* 邮箱
*/
private String email;
/**
* 手机号码
*/
private String mobile;
/**
* 用户性别0未知 1男 2女
*/
private Integer sex;
/**
* 头像地址
*/
private String avatar;
/**
* 状态0正常 1停用
*/
private Integer status;
/**
* 用户来源类型
*/
private Integer userSource;
/**
* 租户ID
*/
private Long tenantId;
/**
* 事件时间
*/
private LocalDateTime eventTime;
// ==================== 静态工厂方法 ====================
public static DatabusUserChangeMessage create(Long userId, String username, String nickname, String remark,
Set<Long> deptIds, Set<Long> postIds, String email, String mobile,
Integer sex, String avatar, Integer status, Integer userSource,
Long tenantId, LocalDateTime createTime) {
return new DatabusUserChangeMessage()
.setAction("create")
.setUserId(userId)
.setUsername(username)
.setNickname(nickname)
.setRemark(remark)
.setDeptIds(deptIds)
.setPostIds(postIds)
.setEmail(email)
.setMobile(mobile)
.setSex(sex)
.setAvatar(avatar)
.setStatus(status)
.setUserSource(userSource)
.setTenantId(tenantId)
.setEventTime(createTime != null ? createTime : LocalDateTime.now());
}
public static DatabusUserChangeMessage update(Long userId, String username, String nickname, String remark,
Set<Long> deptIds, Set<Long> postIds, String email, String mobile,
Integer sex, String avatar, Integer status, Integer userSource,
Long tenantId, LocalDateTime updateTime) {
return new DatabusUserChangeMessage()
.setAction("update")
.setUserId(userId)
.setUsername(username)
.setNickname(nickname)
.setRemark(remark)
.setDeptIds(deptIds)
.setPostIds(postIds)
.setEmail(email)
.setMobile(mobile)
.setSex(sex)
.setAvatar(avatar)
.setStatus(status)
.setUserSource(userSource)
.setTenantId(tenantId)
.setEventTime(updateTime != null ? updateTime : LocalDateTime.now());
}
public static DatabusUserChangeMessage delete(Long userId, Long tenantId) {
return new DatabusUserChangeMessage()
.setAction("delete")
.setUserId(userId)
.setTenantId(tenantId)
.setEventTime(LocalDateTime.now());
}
}