refactor(search):重构搜索服务模块结构

- 将 han-note-search 模块拆分为 han-note-search-api 和 han-note-search-biz
- 调整包路径,统一添加 biz 子包以区分业务实现
- 更新相关类的导入路径以适配新的包结构
- 修改 Maven 模块配置,设置父模块打包方式为 pom- 添加新的 API 模块用于 RPC 接口定义
- 更新依赖配置,确保模块间正确引用
- 调整 IDEA 编译器配置以识别新模块
- 更新 HTTP 客户端测试数据和请求示例
- 添加 Feign 客户端支持以实现服务间通信
- 实现笔记文档重建功能并提供对外接口
- 增加数据对齐服务中远程调用搜索服务的能力
- 更新全局异常处理器和枚举类的包路径
- 调整应用启动类的 Mapper 扫描路径
- 更新 Elasticsearch 配置类和索引相关类路径
- 修改控制器和服务接口以支持新架构
- 更新测试类路径以匹配新的项目结构
This commit is contained in:
2025-11-03 16:00:22 +08:00
parent 218f4c6974
commit 2b2cd2be70
52 changed files with 512 additions and 181 deletions

View File

@@ -3,9 +3,11 @@ package com.hanserwei.hannote.data.align;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@MapperScan("com.hanserwei.hannote.data.align.domain.mapper")
@EnableFeignClients(basePackages = "com.hanserwei.hannote")
public class HannoteDataAlignApplication {
public static void main(String[] args) {
SpringApplication.run(HannoteDataAlignApplication.class, args);

View File

@@ -6,6 +6,7 @@ import com.hanserwei.hannote.data.align.constant.TableConstants;
import com.hanserwei.hannote.data.align.domain.mapper.DeleteRecordMapper;
import com.hanserwei.hannote.data.align.domain.mapper.SelectRecordMapper;
import com.hanserwei.hannote.data.align.domain.mapper.UpdateRecordMapper;
import com.hanserwei.hannote.data.align.rpc.SearchRpcService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
@@ -29,6 +30,8 @@ public class FansCountShardingXxlJob {
private DeleteRecordMapper deleteRecordMapper;
@Resource
private RedisTemplate<String, Object> redisTemplate;
@Resource
private SearchRpcService searchRpcService;
/**
* 分片广播任务
@@ -80,6 +83,8 @@ public class FansCountShardingXxlJob {
redisTemplate.opsForHash().put(redisKey, RedisKeyConstants.FIELD_FANS_TOTAL, fansTotal);
}
}
// 远程 RPC, 调用搜索服务,重新构建索引
searchRpcService.rebuildUserDocument(userId);
});
// 删除t_data_align_fans_count_temp_日期_分片序号中的记录

View File

@@ -6,6 +6,7 @@ import com.hanserwei.hannote.data.align.constant.TableConstants;
import com.hanserwei.hannote.data.align.domain.mapper.DeleteRecordMapper;
import com.hanserwei.hannote.data.align.domain.mapper.SelectRecordMapper;
import com.hanserwei.hannote.data.align.domain.mapper.UpdateRecordMapper;
import com.hanserwei.hannote.data.align.rpc.SearchRpcService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
@@ -33,6 +34,9 @@ public class NoteCollectCountShardingXxlJob {
@Resource
private RedisTemplate<String, Object> redisTemplate;
@Resource
private SearchRpcService searchRpcService;
@XxlJob("noteCollectCountShardingJobHandler")
public void noteCollectCountShardingJobHandler() throws Exception {
// 获取分片参数
@@ -81,6 +85,8 @@ public class NoteCollectCountShardingXxlJob {
redisTemplate.opsForHash().put(redisKey, RedisKeyConstants.FIELD_COLLECT_TOTAL, likeTotal);
}
}
// 远程 RPC, 调用搜索服务,重新构建文档
searchRpcService.rebuildNoteDocument(noteId);
});
// 4. 批量物理删除这一批次记录

View File

@@ -6,6 +6,7 @@ import com.hanserwei.hannote.data.align.constant.TableConstants;
import com.hanserwei.hannote.data.align.domain.mapper.DeleteRecordMapper;
import com.hanserwei.hannote.data.align.domain.mapper.SelectRecordMapper;
import com.hanserwei.hannote.data.align.domain.mapper.UpdateRecordMapper;
import com.hanserwei.hannote.data.align.rpc.SearchRpcService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
@@ -33,6 +34,9 @@ public class NoteLikeCountShardingXxlJob {
@Resource
private DeleteRecordMapper deleteRecordMapper;
@Resource
private SearchRpcService searchRpcService;
@XxlJob("noteLikeCountShardingJobHandler")
public void noteLikeCountShardingJobHandler() throws Exception {
// 获取分片参数
@@ -83,6 +87,9 @@ public class NoteLikeCountShardingXxlJob {
redisTemplate.opsForHash().put(redisKey, RedisKeyConstants.FIELD_LIKE_TOTAL, likeTotal);
}
}
// 远程 RPC, 调用搜索服务,重新构建文档
searchRpcService.rebuildNoteDocument(noteId);
});
// 4. 批量物理删除这一批次记录
deleteRecordMapper.batchDeleteDataAlignNoteLikeCountTempTable(tableNameSuffix, noteIds);

View File

@@ -6,6 +6,7 @@ import com.hanserwei.hannote.data.align.constant.TableConstants;
import com.hanserwei.hannote.data.align.domain.mapper.DeleteRecordMapper;
import com.hanserwei.hannote.data.align.domain.mapper.SelectRecordMapper;
import com.hanserwei.hannote.data.align.domain.mapper.UpdateRecordMapper;
import com.hanserwei.hannote.data.align.rpc.SearchRpcService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
@@ -29,6 +30,8 @@ public class NotePublishCountShardingXxlJob {
private DeleteRecordMapper deleteRecordMapper;
@Resource
private RedisTemplate<String, Object> redisTemplate;
@Resource
private SearchRpcService searchRpcService;
@XxlJob("notePublishCountShardingJobHandler")
public void notePublishCountShardingJobHandler() throws Exception {
@@ -72,6 +75,8 @@ public class NotePublishCountShardingXxlJob {
redisTemplate.opsForHash().put(redisKey, RedisKeyConstants.FIELD_NOTE_TOTAL, notePublishTotal);
}
}
// 远程 RPC, 调用搜索服务,重新构建索引
searchRpcService.rebuildUserDocument(userId);
});
// 删除 t_data_align_note_publish_count_temp_日期_分片序号

View File

@@ -0,0 +1,41 @@
package com.hanserwei.hannote.data.align.rpc;
import com.hanserwei.hannote.search.api.SearchFeignApi;
import com.hanserwei.hannote.search.dto.RebuildNoteDocumentReqDTO;
import com.hanserwei.hannote.search.dto.RebuildUserDocumentReqDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
@Component
public class SearchRpcService {
@Resource
private SearchFeignApi searchFeignApi;
/**
* 调用重建笔记文档接口
*
* @param noteId 笔记ID
*/
public void rebuildNoteDocument(Long noteId) {
RebuildNoteDocumentReqDTO rebuildNoteDocumentReqDTO = RebuildNoteDocumentReqDTO.builder()
.id(noteId)
.build();
searchFeignApi.rebuildNoteDocument(rebuildNoteDocumentReqDTO);
}
/**
* 调用重建用户文档接口
*
* @param userId 用户ID
*/
public void rebuildUserDocument(Long userId) {
RebuildUserDocumentReqDTO rebuildUserDocumentReqDTO = RebuildUserDocumentReqDTO.builder()
.id(userId)
.build();
searchFeignApi.rebuildUserDocument(rebuildUserDocumentReqDTO);
}
}