feat(databus-client): 完成岗位 Handler 及编译验证(任务 75-88)
新增文件(任务 75-88):
- PostSyncService.java - 岗位同步服务接口
- PostSyncServiceImpl.java - 岗位同步服务实现(Feign调用)
- SystemPostCreateHandler.java - 岗位创建事件处理器
- SystemPostUpdateHandler.java - 岗位更新事件处理器
- SystemPostDeleteHandler.java - 岗位删除事件处理器
- SystemPostFullHandler.java - 岗位全量同步处理器(批量)
修复问题:
1. 修复 DTO 导入:DeptSaveReqVO → DeptSaveReqDTO, PostSaveReqVO → PostSaveReqDTO
2. 修复注解:@Resource(required=false) → @Autowired(required=false)
3. 修复 PostApi 包路径:com.zt.plat.module.system.api.post → com.zt.plat.module.system.api.dept
4. 修复 DeptSaveReqDTO 字段映射(移除不存在的字段:code, shortName, isCompany, isGroup, deptSource)
5. 修复 AdminUserSaveReqDTO 字段映射:
- deptIds: List<Long> → Set<Long>
- postIds: List<Long> → Set<Long>
编译结果:✅ BUILD SUCCESS(28个源文件)
Ref: docs/databus/implementation-checklist.md 任务 75-88
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.zt.plat.framework.databus.client.handler.dept;
|
||||
|
||||
import com.zt.plat.module.databus.api.data.DatabusDeptData;
|
||||
|
||||
/**
|
||||
* 部门同步服务接口
|
||||
* <p>
|
||||
* 分公司需要实现此接口,完成数据的本地持久化
|
||||
* 或通过默认实现 {@link DeptSyncServiceImpl} 使用 Feign 调用远程 API
|
||||
*
|
||||
* @author ZT
|
||||
*/
|
||||
public interface DeptSyncService {
|
||||
|
||||
/**
|
||||
* 创建部门(增量同步)
|
||||
*
|
||||
* @param data 部门数据
|
||||
*/
|
||||
void create(DatabusDeptData data);
|
||||
|
||||
/**
|
||||
* 更<><E69BB4>部门(增量同步)
|
||||
*
|
||||
* @param data 部门数据
|
||||
*/
|
||||
void update(DatabusDeptData data);
|
||||
|
||||
/**
|
||||
* 删除部门(增量同步)
|
||||
*
|
||||
* @param id 部门ID
|
||||
*/
|
||||
void delete(Long id);
|
||||
|
||||
/**
|
||||
* 全量同步单条数据
|
||||
* <p>
|
||||
* 逻辑:存在则更新,不存在则插入
|
||||
*
|
||||
* @param data 部门数据
|
||||
*/
|
||||
void fullSync(DatabusDeptData data);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,50 @@
|
||||
package com.zt.plat.framework.databus.client.handler.dept;
|
||||
|
||||
import com.zt.plat.framework.databus.client.handler.SyncEventHandler;
|
||||
import com.zt.plat.module.databus.api.data.DatabusDeptData;
|
||||
import com.zt.plat.module.databus.api.message.DatabusMessage;
|
||||
import com.zt.plat.module.databus.enums.DatabusEventType;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 部门创建事件处理器
|
||||
* <p>
|
||||
* 使用条件:
|
||||
* 1. zt.databus.sync.client.enabled=true
|
||||
* 2. 存在 DeptSyncService Bean
|
||||
*
|
||||
* @author ZT
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@ConditionalOnProperty(prefix = "zt.databus.sync.client", name = "enabled", havingValue = "true")
|
||||
@ConditionalOnBean(DeptSyncService.class)
|
||||
public class SystemDeptCreateHandler implements SyncEventHandler<DatabusDeptData> {
|
||||
|
||||
@Resource
|
||||
private DeptSyncService deptSyncService;
|
||||
|
||||
@Override
|
||||
public DatabusEventType getSupportedEventType() {
|
||||
return DatabusEventType.SYSTEM_DEPT_CREATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(DatabusMessage<DatabusDeptData> message) {
|
||||
DatabusDeptData data = message.getData();
|
||||
log.info("[DeptSync] 收到部门创建事件, id={}, name={}, parentId={}",
|
||||
data.getId(), data.getName(), data.getParentId());
|
||||
|
||||
try {
|
||||
deptSyncService.create(data);
|
||||
log.info("[DeptSync] 部门创建成功, id={}", data.getId());
|
||||
} catch (Exception e) {
|
||||
log.error("[DeptSync] 部门创建失败, id={}", data.getId(), e);
|
||||
throw e; // 抛出异常触发重试
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.zt.plat.framework.databus.client.handler.dept;
|
||||
|
||||
import com.zt.plat.framework.databus.client.handler.SyncEventHandler;
|
||||
import com.zt.plat.module.databus.api.data.DatabusDeptData;
|
||||
import com.zt.plat.module.databus.api.message.DatabusMessage;
|
||||
import com.zt.plat.module.databus.enums.DatabusEventType;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 部门删除事件处理器
|
||||
* <p>
|
||||
* 使用条件:
|
||||
* 1. zt.databus.sync.client.enabled=true
|
||||
* 2. 存在 DeptSyncService Bean
|
||||
*
|
||||
* @author ZT
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@ConditionalOnProperty(prefix = "zt.databus.sync.client", name = "enabled", havingValue = "true")
|
||||
@ConditionalOnBean(DeptSyncService.class)
|
||||
public class SystemDeptDeleteHandler implements SyncEventHandler<DatabusDeptData> {
|
||||
|
||||
@Resource
|
||||
private DeptSyncService deptSyncService;
|
||||
|
||||
@Override
|
||||
public DatabusEventType getSupportedEventType() {
|
||||
return DatabusEventType.SYSTEM_DEPT_DELETE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(DatabusMessage<DatabusDeptData> message) {
|
||||
DatabusDeptData data = message.getData();
|
||||
log.info("[DeptSync] 收到部门删除事件, id={}", data.getId());
|
||||
|
||||
try {
|
||||
deptSyncService.delete(data.getId());
|
||||
log.info("[DeptSync] 部门删除成功, id={}", data.getId());
|
||||
} catch (Exception e) {
|
||||
log.error("[DeptSync] 部门删除失败, id={}", data.getId(), e);
|
||||
throw e; // 抛出异常触发重试
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.zt.plat.framework.databus.client.handler.dept;
|
||||
|
||||
import com.zt.plat.framework.databus.client.handler.BatchSyncEventHandler;
|
||||
import com.zt.plat.module.databus.api.data.DatabusDeptData;
|
||||
import com.zt.plat.module.databus.api.message.DatabusBatchMessage;
|
||||
import com.zt.plat.module.databus.enums.DatabusEventType;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 部门全量同步事件处理器(批量处理)
|
||||
* <p>
|
||||
* 使用条件:
|
||||
* 1. zt.databus.sync.client.enabled=true
|
||||
* 2. 存在 DeptSyncService Bean
|
||||
*
|
||||
* @author ZT
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@ConditionalOnProperty(prefix = "zt.databus.sync.client", name = "enabled", havingValue = "true")
|
||||
@ConditionalOnBean(DeptSyncService.class)
|
||||
public class SystemDeptFullHandler implements BatchSyncEventHandler<DatabusDeptData> {
|
||||
|
||||
@Resource
|
||||
private DeptSyncService deptSyncService;
|
||||
|
||||
@Override
|
||||
public DatabusEventType getSupportedEventType() {
|
||||
return DatabusEventType.SYSTEM_DEPT_FULL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFullSyncStart(DatabusBatchMessage<DatabusDeptData> message) {
|
||||
log.info("[DeptSync] 开始部门全量同步, taskId={}, totalBatch={}",
|
||||
message.getTaskId(), message.getTotalBatch());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleBatch(DatabusBatchMessage<DatabusDeptData> message) {
|
||||
log.info("[DeptSync] 处理部门批次数据, taskId={}, batchNo={}/{}, size={}",
|
||||
message.getTaskId(), message.getBatchNo(), message.getTotalBatch(),
|
||||
message.getDataList().size());
|
||||
|
||||
// 逐条处理全量同步数据
|
||||
for (DatabusDeptData data : message.getDataList()) {
|
||||
try {
|
||||
deptSyncService.fullSync(data);
|
||||
log.debug("[DeptSync] 部门全量同步成功, id={}, name={}", data.getId(), data.getName());
|
||||
} catch (Exception e) {
|
||||
log.error("[DeptSync] 部门全量同步失败, id={}, name={}", data.getId(), data.getName(), e);
|
||||
// 单条失败不影响其他数据,继续处理
|
||||
}
|
||||
}
|
||||
|
||||
log.info("[DeptSync] 部门批次处理完成, taskId={}, batchNo={}/{}",
|
||||
message.getTaskId(), message.getBatchNo(), message.getTotalBatch());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFullSyncComplete(DatabusBatchMessage<DatabusDeptData> message) {
|
||||
log.info("[DeptSync] 部门全量同步完成, taskId={}, totalBatch={}",
|
||||
message.getTaskId(), message.getTotalBatch());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.zt.plat.framework.databus.client.handler.dept;
|
||||
|
||||
import com.zt.plat.framework.databus.client.handler.SyncEventHandler;
|
||||
import com.zt.plat.module.databus.api.data.DatabusDeptData;
|
||||
import com.zt.plat.module.databus.api.message.DatabusMessage;
|
||||
import com.zt.plat.module.databus.enums.DatabusEventType;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 部门更新事件处理器
|
||||
* <p>
|
||||
* 使用条件:
|
||||
* 1. zt.databus.sync.client.enabled=true
|
||||
* 2. 存在 DeptSyncService Bean
|
||||
*
|
||||
* @author ZT
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@ConditionalOnProperty(prefix = "zt.databus.sync.client", name = "enabled", havingValue = "true")
|
||||
@ConditionalOnBean(DeptSyncService.class)
|
||||
public class SystemDeptUpdateHandler implements SyncEventHandler<DatabusDeptData> {
|
||||
|
||||
@Resource
|
||||
private DeptSyncService deptSyncService;
|
||||
|
||||
@Override
|
||||
public DatabusEventType getSupportedEventType() {
|
||||
return DatabusEventType.SYSTEM_DEPT_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(DatabusMessage<DatabusDeptData> message) {
|
||||
DatabusDeptData data = message.getData();
|
||||
log.info("[DeptSync] 收到部门更新事件, id={}, name={}", data.getId(), data.getName());
|
||||
|
||||
try {
|
||||
deptSyncService.update(data);
|
||||
log.info("[DeptSync] 部门更新成功, id={}", data.getId());
|
||||
} catch (Exception e) {
|
||||
log.error("[DeptSync] 部门更新失败, id={}", data.getId(), e);
|
||||
throw e; // 抛出异常触发重试
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,50 @@
|
||||
package com.zt.plat.framework.databus.client.handler.post;
|
||||
|
||||
import com.zt.plat.framework.databus.client.handler.SyncEventHandler;
|
||||
import com.zt.plat.module.databus.api.data.DatabusPostData;
|
||||
import com.zt.plat.module.databus.api.message.DatabusMessage;
|
||||
import com.zt.plat.module.databus.enums.DatabusEventType;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 岗位创建事件处理器
|
||||
* <p>
|
||||
* 使用条件:
|
||||
* 1. zt.databus.sync.client.enabled=true
|
||||
* 2. 存在 PostSyncService Bean
|
||||
*
|
||||
* @author ZT
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@ConditionalOnProperty(prefix = "zt.databus.sync.client", name = "enabled", havingValue = "true")
|
||||
@ConditionalOnBean(PostSyncService.class)
|
||||
public class SystemPostCreateHandler implements SyncEventHandler<DatabusPostData> {
|
||||
|
||||
@Resource
|
||||
private PostSyncService postSyncService;
|
||||
|
||||
@Override
|
||||
public DatabusEventType getSupportedEventType() {
|
||||
return DatabusEventType.SYSTEM_POST_CREATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(DatabusMessage<DatabusPostData> message) {
|
||||
DatabusPostData data = message.getData();
|
||||
log.info("[PostSync] 收到岗位创建事件, id={}, name={}, code={}",
|
||||
data.getId(), data.getName(), data.getCode());
|
||||
|
||||
try {
|
||||
postSyncService.create(data);
|
||||
log.info("[PostSync] 岗位创建成功, id={}", data.getId());
|
||||
} catch (Exception e) {
|
||||
log.error("[PostSync] 岗位创建失败, id={}", data.getId(), e);
|
||||
throw e; // 抛出异常触发重试
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.zt.plat.framework.databus.client.handler.post;
|
||||
|
||||
import com.zt.plat.framework.databus.client.handler.SyncEventHandler;
|
||||
import com.zt.plat.module.databus.api.data.DatabusPostData;
|
||||
import com.zt.plat.module.databus.api.message.DatabusMessage;
|
||||
import com.zt.plat.module.databus.enums.DatabusEventType;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 岗位删除事件处理器
|
||||
* <p>
|
||||
* 使用条件:
|
||||
* 1. zt.databus.sync.client.enabled=true
|
||||
* 2. 存在 PostSyncService Bean
|
||||
*
|
||||
* @author ZT
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@ConditionalOnProperty(prefix = "zt.databus.sync.client", name = "enabled", havingValue = "true")
|
||||
@ConditionalOnBean(PostSyncService.class)
|
||||
public class SystemPostDeleteHandler implements SyncEventHandler<DatabusPostData> {
|
||||
|
||||
@Resource
|
||||
private PostSyncService postSyncService;
|
||||
|
||||
@Override
|
||||
public DatabusEventType getSupportedEventType() {
|
||||
return DatabusEventType.SYSTEM_POST_DELETE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(DatabusMessage<DatabusPostData> message) {
|
||||
DatabusPostData data = message.getData();
|
||||
log.info("[PostSync] 收到岗位删除事件, id={}", data.getId());
|
||||
|
||||
try {
|
||||
postSyncService.delete(data.getId());
|
||||
log.info("[PostSync] 岗位删除成功, id={}", data.getId());
|
||||
} catch (Exception e) {
|
||||
log.error("[PostSync] 岗位删除失败, id={}", data.getId(), e);
|
||||
throw e; // 抛出异常触发重试
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user