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:
38
han-note-search/han-note-search-api/pom.xml
Normal file
38
han-note-search/han-note-search-api/pom.xml
Normal file
@@ -0,0 +1,38 @@
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.hanserwei</groupId>
|
||||
<artifactId>han-note-search</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<!-- 打包方式 -->
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>han-note-search-api</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<description>RPC层, 供其他服务调用</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.hanserwei</groupId>
|
||||
<artifactId>hanserwei-common</artifactId>
|
||||
</dependency>
|
||||
<!-- OpenFeign -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 负载均衡 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.hanserwei.hannote.search.api;
|
||||
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.hannote.search.constant.ApiConstants;
|
||||
import com.hanserwei.hannote.search.dto.RebuildNoteDocumentReqDTO;
|
||||
import com.hanserwei.hannote.search.dto.RebuildUserDocumentReqDTO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@FeignClient(name = ApiConstants.SERVICE_NAME)
|
||||
public interface SearchFeignApi {
|
||||
|
||||
String PREFIX = "/search";
|
||||
|
||||
/**
|
||||
* 重建笔记文档
|
||||
*
|
||||
* @param rebuildNoteDocumentReqDTO 重建笔记文档请求参数对象,包含重建所需的相关信息
|
||||
* @return 返回重建操作的结果响应对象
|
||||
*/
|
||||
@PostMapping(value = PREFIX + "/note/document/rebuild")
|
||||
Response<?> rebuildNoteDocument(@RequestBody RebuildNoteDocumentReqDTO rebuildNoteDocumentReqDTO);
|
||||
|
||||
|
||||
/**
|
||||
* 重建用户文档
|
||||
*
|
||||
* @param rebuildUserDocumentReqDTO 重建用户文档请求参数对象,包含重建所需的相关信息
|
||||
* @return 返回重建操作的结果响应对象
|
||||
*/
|
||||
@PostMapping(value = PREFIX + "/user/document/rebuild")
|
||||
Response<?> rebuildUserDocument(@RequestBody RebuildUserDocumentReqDTO rebuildUserDocumentReqDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.hanserwei.hannote.search.constant;
|
||||
|
||||
public interface ApiConstants {
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
String SERVICE_NAME = "han-note-search";
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.hanserwei.hannote.search.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class RebuildNoteDocumentReqDTO {
|
||||
|
||||
@NotNull(message = "笔记 ID 不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.hanserwei.hannote.search.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class RebuildUserDocumentReqDTO {
|
||||
|
||||
@NotNull(message = "用户 ID 不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
||||
108
han-note-search/han-note-search-biz/pom.xml
Normal file
108
han-note-search/han-note-search-biz/pom.xml
Normal file
@@ -0,0 +1,108 @@
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- 指定父项目 -->
|
||||
<parent>
|
||||
<groupId>com.hanserwei</groupId>
|
||||
<artifactId>han-note-search</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<!-- 指定打包方式 -->
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>han-note-search-biz</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<description>搜索服务</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.hanserwei</groupId>
|
||||
<artifactId>hanserwei-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 业务接口日志组件 -->
|
||||
<dependency>
|
||||
<groupId>com.hanserwei</groupId>
|
||||
<artifactId>hanserwei-spring-boot-starter-biz-operationlog</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Jackson 组件 -->
|
||||
<dependency>
|
||||
<groupId>com.hanserwei</groupId>
|
||||
<artifactId>hanserwei-spring-boot-starter-jackson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 服务注册发现 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Elasticsearch 分布式搜索引擎 -->
|
||||
<dependency>
|
||||
<groupId>co.elastic.clients</groupId>
|
||||
<artifactId>elasticsearch-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-client</artifactId>
|
||||
</dependency>
|
||||
<!-- Canal -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.otter</groupId>
|
||||
<artifactId>canal.client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.otter</groupId>
|
||||
<artifactId>canal.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.otter</groupId>
|
||||
<artifactId>canal.protocol</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
<!-- Druid 数据库连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-3-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hanserwei</groupId>
|
||||
<artifactId>han-note-search-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search;
|
||||
package com.hanserwei.hannote.search.biz;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -7,7 +7,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
@MapperScan("com.hanserwei.hannote.search.domain.mapper")
|
||||
@MapperScan("com.hanserwei.hannote.search.biz.domain.mapper")
|
||||
public class HannoteSearchApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(HannoteSearchApplication.class, args);
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.canal;
|
||||
package com.hanserwei.hannote.search.biz.canal;
|
||||
|
||||
import com.alibaba.otter.canal.client.CanalConnector;
|
||||
import com.alibaba.otter.canal.client.CanalConnectors;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.canal;
|
||||
package com.hanserwei.hannote.search.biz.canal;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.canal;
|
||||
package com.hanserwei.hannote.search.biz.canal;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.elasticsearch.core.BulkRequest;
|
||||
@@ -9,11 +9,11 @@ import com.alibaba.otter.canal.protocol.CanalEntry;
|
||||
import com.alibaba.otter.canal.protocol.Message;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.hanserwei.framework.common.enums.StatusEnum;
|
||||
import com.hanserwei.hannote.search.domain.mapper.SelectMapper;
|
||||
import com.hanserwei.hannote.search.enums.NoteStatusEnum;
|
||||
import com.hanserwei.hannote.search.enums.NoteVisibleEnum;
|
||||
import com.hanserwei.hannote.search.index.NoteIndex;
|
||||
import com.hanserwei.hannote.search.index.UserIndex;
|
||||
import com.hanserwei.hannote.search.biz.domain.mapper.SelectMapper;
|
||||
import com.hanserwei.hannote.search.biz.enums.NoteStatusEnum;
|
||||
import com.hanserwei.hannote.search.biz.enums.NoteVisibleEnum;
|
||||
import com.hanserwei.hannote.search.biz.index.NoteIndex;
|
||||
import com.hanserwei.hannote.search.biz.index.UserIndex;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.config;
|
||||
package com.hanserwei.hannote.search.biz.config;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.hanserwei.hannote.search.controller;
|
||||
package com.hanserwei.hannote.search.biz.controller;
|
||||
|
||||
import com.hanserwei.framework.biz.operationlog.aspect.ApiOperationLog;
|
||||
import com.hanserwei.hannote.search.service.ExtDictService;
|
||||
import com.hanserwei.hannote.search.biz.service.ExtDictService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.hanserwei.hannote.search.controller;
|
||||
package com.hanserwei.hannote.search.biz.controller;
|
||||
|
||||
import com.hanserwei.framework.biz.operationlog.aspect.ApiOperationLog;
|
||||
import com.hanserwei.framework.common.response.PageResponse;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchNoteReqVO;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchNoteRspVO;
|
||||
import com.hanserwei.hannote.search.service.NoteService;
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchNoteReqVO;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchNoteRspVO;
|
||||
import com.hanserwei.hannote.search.biz.service.NoteService;
|
||||
import com.hanserwei.hannote.search.dto.RebuildNoteDocumentReqDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -27,4 +29,10 @@ public class NoteController {
|
||||
return noteService.searchNote(searchNoteReqVO);
|
||||
}
|
||||
|
||||
// ===================================== 对其他服务提供的接口 =====================================
|
||||
@PostMapping("/note/document/rebuild")
|
||||
@ApiOperationLog(description = "用户文档重建")
|
||||
public Response<Long> rebuildDocument(@Validated @RequestBody RebuildNoteDocumentReqDTO rebuildNoteDocumentReqDTO) {
|
||||
return noteService.rebuildDocument(rebuildNoteDocumentReqDTO);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.hanserwei.hannote.search.controller;
|
||||
package com.hanserwei.hannote.search.biz.controller;
|
||||
|
||||
import com.hanserwei.framework.biz.operationlog.aspect.ApiOperationLog;
|
||||
import com.hanserwei.framework.common.response.PageResponse;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchUserReqVO;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchUserRspVO;
|
||||
import com.hanserwei.hannote.search.service.UserService;
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchUserReqVO;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchUserRspVO;
|
||||
import com.hanserwei.hannote.search.biz.service.UserService;
|
||||
import com.hanserwei.hannote.search.dto.RebuildUserDocumentReqDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -27,4 +29,11 @@ public class UserController {
|
||||
return userService.searchUser(searchUserReqVO);
|
||||
}
|
||||
|
||||
// ===================================== 对其他服务提供的接口 =====================================
|
||||
@PostMapping("/user/document/rebuild")
|
||||
@ApiOperationLog(description = "用户文档重建")
|
||||
public Response<Long> rebuildDocument(@Validated @RequestBody RebuildUserDocumentReqDTO rebuildUserDocumentReqDTO) {
|
||||
return userService.rebuildDocument(rebuildUserDocumentReqDTO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.domain.mapper;
|
||||
package com.hanserwei.hannote.search.biz.domain.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.enums;
|
||||
package com.hanserwei.hannote.search.biz.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.enums;
|
||||
package com.hanserwei.hannote.search.biz.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.enums;
|
||||
package com.hanserwei.hannote.search.biz.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.enums;
|
||||
package com.hanserwei.hannote.search.biz.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.enums;
|
||||
package com.hanserwei.hannote.search.biz.enums;
|
||||
|
||||
import com.hanserwei.framework.common.exception.BaseExceptionInterface;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.hanserwei.hannote.search.exception;
|
||||
package com.hanserwei.hannote.search.biz.exception;
|
||||
|
||||
import com.hanserwei.framework.common.exception.ApiException;
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.hannote.search.enums.ResponseCodeEnum;
|
||||
import com.hanserwei.hannote.search.biz.enums.ResponseCodeEnum;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.BindingResult;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.index;
|
||||
package com.hanserwei.hannote.search.biz.index;
|
||||
|
||||
public class NoteIndex {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.index;
|
||||
package com.hanserwei.hannote.search.biz.index;
|
||||
|
||||
public class UserIndex {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.model.vo;
|
||||
package com.hanserwei.hannote.search.biz.model.vo;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.model.vo;
|
||||
package com.hanserwei.hannote.search.biz.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.model.vo;
|
||||
package com.hanserwei.hannote.search.biz.model.vo;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.model.vo;
|
||||
package com.hanserwei.hannote.search.biz.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.hanserwei.hannote.search.service;
|
||||
package com.hanserwei.hannote.search.biz.service;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.hanserwei.hannote.search.biz.service;
|
||||
|
||||
import com.hanserwei.framework.common.response.PageResponse;
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchNoteReqVO;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchNoteRspVO;
|
||||
import com.hanserwei.hannote.search.dto.RebuildNoteDocumentReqDTO;
|
||||
|
||||
public interface NoteService {
|
||||
|
||||
/**
|
||||
* 搜索笔记
|
||||
*
|
||||
* @param searchNoteReqVO 搜索笔记请求
|
||||
* @return 搜索笔记响应
|
||||
*/
|
||||
PageResponse<SearchNoteRspVO> searchNote(SearchNoteReqVO searchNoteReqVO);
|
||||
|
||||
/**
|
||||
* 重建笔记文档
|
||||
*
|
||||
* @param rebuildNoteDocumentReqDTO 重建笔记文档请求
|
||||
* @return 响应
|
||||
*/
|
||||
Response<Long> rebuildDocument(RebuildNoteDocumentReqDTO rebuildNoteDocumentReqDTO);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.hanserwei.hannote.search.biz.service;
|
||||
|
||||
import com.hanserwei.framework.common.response.PageResponse;
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchUserReqVO;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchUserRspVO;
|
||||
import com.hanserwei.hannote.search.dto.RebuildUserDocumentReqDTO;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
/**
|
||||
* 搜索用户
|
||||
*
|
||||
* @param searchUserReqVO 搜索用户请求
|
||||
* @return 搜索用户响应
|
||||
*/
|
||||
PageResponse<SearchUserRspVO> searchUser(SearchUserReqVO searchUserReqVO);
|
||||
|
||||
/**
|
||||
* 重建用户文档
|
||||
*
|
||||
* @param rebuildUserDocumentReqDTO 重建用户文档请求
|
||||
* @return 响应
|
||||
*/
|
||||
Response<Long> rebuildDocument(RebuildUserDocumentReqDTO rebuildUserDocumentReqDTO);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hanserwei.hannote.search.service.impl;
|
||||
package com.hanserwei.hannote.search.biz.service.impl;
|
||||
|
||||
import com.hanserwei.hannote.search.service.ExtDictService;
|
||||
import com.hanserwei.hannote.search.biz.service.ExtDictService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.hanserwei.hannote.search.service.impl;
|
||||
package com.hanserwei.hannote.search.biz.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.elasticsearch._types.SortOptions;
|
||||
import co.elastic.clients.elasticsearch._types.SortOrder;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.*;
|
||||
import co.elastic.clients.elasticsearch.core.IndexRequest;
|
||||
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
||||
import co.elastic.clients.elasticsearch.core.search.Highlight;
|
||||
@@ -13,14 +14,17 @@ import co.elastic.clients.elasticsearch.core.search.Hit;
|
||||
import co.elastic.clients.util.NamedValue;
|
||||
import com.hanserwei.framework.common.constant.DateConstants;
|
||||
import com.hanserwei.framework.common.response.PageResponse;
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.framework.common.utils.DateUtils;
|
||||
import com.hanserwei.framework.common.utils.NumberUtils;
|
||||
import com.hanserwei.hannote.search.enums.NotePublishTimeRangeEnum;
|
||||
import com.hanserwei.hannote.search.enums.NoteSortTypeEnum;
|
||||
import com.hanserwei.hannote.search.index.NoteIndex;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchNoteReqVO;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchNoteRspVO;
|
||||
import com.hanserwei.hannote.search.service.NoteService;
|
||||
import com.hanserwei.hannote.search.biz.domain.mapper.SelectMapper;
|
||||
import com.hanserwei.hannote.search.biz.enums.NotePublishTimeRangeEnum;
|
||||
import com.hanserwei.hannote.search.biz.enums.NoteSortTypeEnum;
|
||||
import com.hanserwei.hannote.search.biz.index.NoteIndex;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchNoteReqVO;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchNoteRspVO;
|
||||
import com.hanserwei.hannote.search.biz.service.NoteService;
|
||||
import com.hanserwei.hannote.search.dto.RebuildNoteDocumentReqDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -39,6 +43,8 @@ public class NoteServiceImpl implements NoteService {
|
||||
|
||||
@Resource
|
||||
private ElasticsearchClient client;
|
||||
@Resource
|
||||
private SelectMapper selectMapper;
|
||||
|
||||
@Override
|
||||
public PageResponse<SearchNoteRspVO> searchNote(SearchNoteReqVO searchNoteReqVO) {
|
||||
@@ -295,4 +301,30 @@ public class NoteServiceImpl implements NoteService {
|
||||
return PageResponse.success(searchNoteRspVOS, pageNo, total);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Long> rebuildDocument(RebuildNoteDocumentReqDTO rebuildNoteDocumentReqDTO) {
|
||||
Long noteId = rebuildNoteDocumentReqDTO.getId();
|
||||
|
||||
// 从数据库查询 Elasticsearch 索引数据
|
||||
List<Map<String, Object>> result = selectMapper.selectEsNoteIndexData(noteId, null);
|
||||
|
||||
// 遍历查询结果,将每条记录同步到 Elasticsearch
|
||||
for (Map<String, Object> recordMap : result) {
|
||||
IndexRequest<Object> request = IndexRequest.of(r -> r
|
||||
// 创建索引请求对象,指定索引名称
|
||||
.index(NoteIndex.NAME)
|
||||
// 设置文档的 ID,使用记录中的主键 “id” 字段值
|
||||
.id((String.valueOf(recordMap.get(NoteIndex.FIELD_NOTE_ID))))
|
||||
// 设置文档的内容,使用查询结果的记录数据
|
||||
.document(recordMap));
|
||||
try {
|
||||
// 将数据写入 Elasticsearch 索引
|
||||
client.index(request);
|
||||
} catch (IOException e) {
|
||||
log.error("==> 同步笔记数据异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
return Response.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.hanserwei.hannote.search.service.impl;
|
||||
package com.hanserwei.hannote.search.biz.service.impl;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.elasticsearch._types.SortOptions;
|
||||
import co.elastic.clients.elasticsearch._types.SortOrder;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.TextQueryType;
|
||||
import co.elastic.clients.elasticsearch.core.IndexRequest;
|
||||
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
||||
import co.elastic.clients.elasticsearch.core.search.Highlight;
|
||||
@@ -12,11 +13,14 @@ import co.elastic.clients.elasticsearch.core.search.HighlightField;
|
||||
import co.elastic.clients.elasticsearch.core.search.Hit;
|
||||
import co.elastic.clients.util.NamedValue;
|
||||
import com.hanserwei.framework.common.response.PageResponse;
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.framework.common.utils.NumberUtils;
|
||||
import com.hanserwei.hannote.search.index.UserIndex;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchUserReqVO;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchUserRspVO;
|
||||
import com.hanserwei.hannote.search.service.UserService;
|
||||
import com.hanserwei.hannote.search.biz.domain.mapper.SelectMapper;
|
||||
import com.hanserwei.hannote.search.biz.index.UserIndex;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchUserReqVO;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchUserRspVO;
|
||||
import com.hanserwei.hannote.search.biz.service.UserService;
|
||||
import com.hanserwei.hannote.search.dto.RebuildUserDocumentReqDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -32,6 +36,8 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Resource
|
||||
private ElasticsearchClient client;
|
||||
@Resource
|
||||
private SelectMapper selectMapper;
|
||||
|
||||
@Override
|
||||
public PageResponse<SearchUserRspVO> searchUser(SearchUserReqVO searchUserReqVO) {
|
||||
@@ -114,4 +120,30 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
return PageResponse.success(searchUserRspVOS, pageNo, total);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Long> rebuildDocument(RebuildUserDocumentReqDTO rebuildUserDocumentReqDTO) {
|
||||
Long userId = rebuildUserDocumentReqDTO.getId();
|
||||
|
||||
// 从数据库查询 Elasticsearch 索引数据
|
||||
List<Map<String, Object>> result = selectMapper.selectEsUserIndexData(userId);
|
||||
|
||||
// 遍历查询结果,将每条记录同步到 Elasticsearch
|
||||
for (Map<String, Object> recordMap : result) {
|
||||
IndexRequest<Object> request = IndexRequest.of(indexRequest -> indexRequest
|
||||
// 创建索引请求对象,指定索引名称
|
||||
.index(UserIndex.NAME)
|
||||
// 设置文档的 ID,使用记录中的主键 “id” 字段值
|
||||
.id((String.valueOf(recordMap.get(UserIndex.FIELD_USER_ID))))
|
||||
// 设置文档的内容,使用查询结果的记录数据
|
||||
.document(recordMap));
|
||||
// 将数据写入 Elasticsearch 索引
|
||||
try {
|
||||
client.index(request);
|
||||
} catch (IOException e) {
|
||||
log.error("==> 同步用户数据到 Elasticsearch 索引中失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return Response.success();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.hanserwei.hannote.search.domain.mapper.SelectMapper">
|
||||
<mapper namespace="com.hanserwei.hannote.search.biz.domain.mapper.SelectMapper">
|
||||
|
||||
<select id="selectEsNoteIndexData" resultType="map" parameterType="map">
|
||||
select n.id,
|
||||
n.title,
|
||||
n.topic_name as topic,
|
||||
n.type,
|
||||
n.img_uris,
|
||||
SUBSTRING_INDEX(n.img_uris, ',', 1) AS cover,
|
||||
DATE_FORMAT(n.create_time, '%Y-%m-%d %H:%i:%s') AS create_time,
|
||||
DATE_FORMAT(n.update_time, '%Y-%m-%d %H:%i:%s') AS update_time,
|
||||
u.nickname,
|
||||
u.avatar,
|
||||
u.nickname AS creator_nickname,
|
||||
u.avatar AS creator_avatar,
|
||||
IFNULL(nc.like_total, 0) as like_total,
|
||||
IFNULL(nc.collect_total, 0) as collect_total,
|
||||
IFNULL(nc.comment_total, 0) as comment_total
|
||||
@@ -3,7 +3,7 @@ package com.hanserwei.hannote.search;
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.elasticsearch._types.SortOrder;
|
||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchUserRspVO;
|
||||
import com.hanserwei.hannote.search.biz.model.vo.SearchUserRspVO;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -8,96 +8,17 @@
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<!-- 指定打包方式 -->
|
||||
<packaging>jar</packaging>
|
||||
<!-- 多模块项目需要配置打包方式为 pom -->
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>han-note-search-biz</module>
|
||||
<module>han-note-search-api</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>han-note-search</artifactId>
|
||||
<!-- 项目名称 -->
|
||||
<name>${project.artifactId}</name>
|
||||
<!-- 项目描述 -->
|
||||
<description>搜索服务</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.hanserwei</groupId>
|
||||
<artifactId>hanserwei-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 业务接口日志组件 -->
|
||||
<dependency>
|
||||
<groupId>com.hanserwei</groupId>
|
||||
<artifactId>hanserwei-spring-boot-starter-biz-operationlog</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Jackson 组件 -->
|
||||
<dependency>
|
||||
<groupId>com.hanserwei</groupId>
|
||||
<artifactId>hanserwei-spring-boot-starter-jackson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 服务注册发现 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Elasticsearch 分布式搜索引擎 -->
|
||||
<dependency>
|
||||
<groupId>co.elastic.clients</groupId>
|
||||
<artifactId>elasticsearch-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-client</artifactId>
|
||||
</dependency>
|
||||
<!-- Canal -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.otter</groupId>
|
||||
<artifactId>canal.client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.otter</groupId>
|
||||
<artifactId>canal.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.otter</groupId>
|
||||
<artifactId>canal.protocol</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
<!-- Druid 数据库连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-3-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.hanserwei.hannote.search.service;
|
||||
|
||||
import com.hanserwei.framework.common.response.PageResponse;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchNoteReqVO;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchNoteRspVO;
|
||||
|
||||
public interface NoteService {
|
||||
|
||||
/**
|
||||
* 搜索笔记
|
||||
*
|
||||
* @param searchNoteReqVO 搜索笔记请求
|
||||
* @return 搜索笔记响应
|
||||
*/
|
||||
PageResponse<SearchNoteRspVO> searchNote(SearchNoteReqVO searchNoteReqVO);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.hanserwei.hannote.search.service;
|
||||
|
||||
import com.hanserwei.framework.common.response.PageResponse;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchUserReqVO;
|
||||
import com.hanserwei.hannote.search.model.vo.SearchUserRspVO;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
/**
|
||||
* 搜索用户
|
||||
*
|
||||
* @param searchUserReqVO 搜索用户请求
|
||||
* @return 搜索用户响应
|
||||
*/
|
||||
PageResponse<SearchUserRspVO> searchUser(SearchUserReqVO searchUserReqVO);
|
||||
}
|
||||
Reference in New Issue
Block a user