Compare commits
No commits in common. "0f46cb038962a563d8e4422f2c7b69740d94d571" and "ddb7392b16228efd4d6a6c353eee1b9ffe04957f" have entirely different histories.
0f46cb0389
...
ddb7392b16
@ -29,11 +29,6 @@
|
||||
<artifactId>tmerclub-common-rocketmq</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.moyuer.cloud</groupId>
|
||||
<artifactId>tmerclub-common-loacl</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.moyuer.cloud</groupId>
|
||||
<artifactId>tmerclub-api-product</artifactId>
|
||||
|
@ -1,99 +0,0 @@
|
||||
package com.tmerclub.cloud.search.builder;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.tmerclub.cloud.api.dto.EsPageDTO;
|
||||
import com.tmerclub.cloud.api.vo.EsPageVO;
|
||||
import com.tmerclub.cloud.common.constant.Constant;
|
||||
import com.tmerclub.cloud.common.i18n.I18nMessage;
|
||||
import com.tmerclub.cloud.common.local.dto.CueProductSearchDTO;
|
||||
import com.tmerclub.cloud.common.local.vo.CueProductSearchVO;
|
||||
import com.tmerclub.cloud.common.product.vo.search.SpuSearchVO;
|
||||
import com.tmerclub.cloud.common.util.Json;
|
||||
import com.tmerclub.cloud.search.constant.EsConstant;
|
||||
import com.tmerclub.cloud.search.constant.EsIndexEnum;
|
||||
import com.tmerclub.cloud.search.util.EsSearchUtil;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 本地生活-球杆商品搜索请求构建
|
||||
*
|
||||
* @author: frank
|
||||
* @create: 2025-04-13
|
||||
**/
|
||||
@Component
|
||||
public class LocalCueProductSearchRequestBuilder {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(LocalCueProductSearchRequestBuilder.class);
|
||||
|
||||
/**
|
||||
* 通过搜索信息分页搜索es数据的信息
|
||||
*
|
||||
* @param pageDTO 分页数据
|
||||
* @param cueProductSearchDTO 商品搜索条件
|
||||
* @return 搜索结果
|
||||
*/
|
||||
public SearchResponse pageSearchResult(EsPageDTO pageDTO, CueProductSearchDTO cueProductSearchDTO) {
|
||||
//1、准备检索请求
|
||||
SearchRequest searchRequest = buildSearchRequest(pageDTO, cueProductSearchDTO);
|
||||
return EsSearchUtil.search(searchRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备检索请求
|
||||
*
|
||||
* @param pageDTO 分页参数
|
||||
* @param param 搜索参数
|
||||
* @return 搜索结果
|
||||
*/
|
||||
private SearchRequest buildSearchRequest(EsPageDTO pageDTO, CueProductSearchDTO param) {
|
||||
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
Integer lang = I18nMessage.getLang();
|
||||
|
||||
// 构建bool-query
|
||||
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
|
||||
|
||||
// 关键字搜索
|
||||
keywordSearch(param, boolQueryBuilder, lang);
|
||||
|
||||
searchSourceBuilder.query(boolQueryBuilder);
|
||||
|
||||
// 分页
|
||||
if (Objects.nonNull(pageDTO)) {
|
||||
searchSourceBuilder.from((pageDTO.getPageNum() - 1) * pageDTO.getPageSize());
|
||||
searchSourceBuilder.size(pageDTO.getPageSize());
|
||||
}
|
||||
|
||||
log.info("构建的DSL语句 {}", searchSourceBuilder);
|
||||
|
||||
return new SearchRequest(new String[]{EsIndexEnum.CUE_PRODUCT.value()}, searchSourceBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键字搜索
|
||||
*/
|
||||
private void keywordSearch(CueProductSearchDTO param, BoolQueryBuilder boolQueryBuilder, Integer lang) {
|
||||
if (ObjectUtil.isEmpty(param.getProductName())) {
|
||||
return;
|
||||
}
|
||||
log.error("---------------------{}", param.getProductName());
|
||||
// 创建查询语句 ES中must和should不能同时使用 同时使用should失效 嵌套多个must 将should条件拼接在一个must中即可
|
||||
BoolQueryBuilder keywordShouldQuery = QueryBuilders.boolQuery();
|
||||
keywordShouldQuery.should(QueryBuilders.wildcardQuery(EsConstant.CUE_PRODUCT_NAME, "*" + param.getProductName() + "*"));
|
||||
boolQueryBuilder.must(keywordShouldQuery);
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package com.tmerclub.cloud.search.builder;
|
||||
|
||||
import com.tmerclub.cloud.api.dto.EsPageDTO;
|
||||
import com.tmerclub.cloud.api.vo.EsPageVO;
|
||||
import com.tmerclub.cloud.common.local.vo.CueProductSearchVO;
|
||||
import com.tmerclub.cloud.common.util.Json;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 本地生活-球杆商品搜索结果构建
|
||||
*
|
||||
* @author: frank
|
||||
* @create: 2025-04-13
|
||||
**/
|
||||
@Component
|
||||
public class LocalCueProductSearchResponseBuilder {
|
||||
private static final Logger log = LoggerFactory.getLogger(LocalCueProductSearchResponseBuilder.class);
|
||||
|
||||
|
||||
/**
|
||||
* 获取搜索结果列表
|
||||
*
|
||||
* @param response 搜索结果
|
||||
* @return 搜索结果列表
|
||||
*/
|
||||
public List<CueProductSearchVO> getProductSearchList(SearchResponse response) {
|
||||
|
||||
// 1、返回的所有查询到的商品
|
||||
List<CueProductSearchVO> cueProductSearchVOList = new ArrayList<>();
|
||||
//===============列表信息====================//
|
||||
SearchHits hits = response.getHits();
|
||||
for (SearchHit hit : hits) {
|
||||
String json = hit.getSourceAsString();
|
||||
CueProductSearchVO cueProductSearchVO = Json.parseObject(json, CueProductSearchVO.class);
|
||||
cueProductSearchVOList.add(cueProductSearchVO);
|
||||
}
|
||||
return cueProductSearchVOList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建分页数据
|
||||
*
|
||||
* @param pageDTO 分页参数
|
||||
* @param esPageVO 分页返回对象
|
||||
* @param response 搜索结果
|
||||
*/
|
||||
public void buildSearchPage(EsPageDTO pageDTO, EsPageVO<?> esPageVO, SearchResponse response) {
|
||||
//总记录数
|
||||
long total = response.getHits().getTotalHits().value;
|
||||
esPageVO.setTotal(total);
|
||||
// 总页码
|
||||
int totalPages = (int) total % pageDTO.getPageSize() == 0 ?
|
||||
(int) total / pageDTO.getPageSize() : ((int) total / pageDTO.getPageSize() + 1);
|
||||
esPageVO.setPages(totalPages);
|
||||
}
|
||||
}
|
@ -168,11 +168,6 @@ public interface EsConstant {
|
||||
String SUPPLIER_NAME = "supplierName";
|
||||
String SUPPLIER_ID = "supplierId";
|
||||
|
||||
/**
|
||||
* 球杆商品
|
||||
*/
|
||||
String CUE_PRODUCT_NAME = "productName";
|
||||
|
||||
/**
|
||||
* 商品指定返回字段
|
||||
*/
|
||||
|
@ -1,10 +1,10 @@
|
||||
|
||||
package com.tmerclub.cloud.search.constant;
|
||||
|
||||
import com.tmerclub.cloud.common.constant.Constant;
|
||||
|
||||
/**
|
||||
* es当中的index
|
||||
*
|
||||
* @author tmerclub
|
||||
* @date 2020/11/12
|
||||
*/
|
||||
@ -38,21 +38,16 @@ public enum EsIndexEnum {
|
||||
/**
|
||||
* 调拨订单
|
||||
*/
|
||||
ALLOT_ORDER(Constant.NAME_SPACE + "allot-order"),
|
||||
|
||||
/**
|
||||
* 球杆商品
|
||||
*/
|
||||
CUE_PRODUCT(Constant.NAME_SPACE + "cue_product"),
|
||||
ALLOT_ORDER(Constant.NAME_SPACE + "allot-order")
|
||||
;
|
||||
|
||||
private final String value;
|
||||
|
||||
EsIndexEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
EsIndexEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
package com.tmerclub.cloud.search.controller.app;
|
||||
|
||||
import com.tmerclub.cloud.api.dto.EsPageDTO;
|
||||
import com.tmerclub.cloud.api.vo.EsPageVO;
|
||||
import com.tmerclub.cloud.common.local.dto.CueProductSearchDTO;
|
||||
import com.tmerclub.cloud.common.local.vo.CueProductSearchVO;
|
||||
import com.tmerclub.cloud.common.response.ServerResponseEntity;
|
||||
import com.tmerclub.cloud.search.manager.LocalCueProductSearchManager;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 本地生活-球杆商品搜索
|
||||
*
|
||||
* @author: frank
|
||||
* @create: 2025-04-12
|
||||
**/
|
||||
@Tag(name = "本地生活-球杆商品搜索")
|
||||
@RestController("localCueProductSearchController")
|
||||
@RequestMapping("/ua/cueProductSearch")
|
||||
public class LocalCueProductSearchController {
|
||||
|
||||
@Resource
|
||||
LocalCueProductSearchManager localCueProductSearchManager;
|
||||
|
||||
/**
|
||||
* APP端搜索球杆商品接口
|
||||
*
|
||||
* @param pageDTO 分页参数
|
||||
* @param cueProductSearchDTO 搜索参数
|
||||
* @return 分页结果集
|
||||
*/
|
||||
@GetMapping("/searchCueProductPage")
|
||||
@Operation(summary = "APP端搜索球杆商品接口", description = "APP端搜索球杆商品接口")
|
||||
public ServerResponseEntity<EsPageVO<CueProductSearchVO>> searchCueProductPage(@Valid EsPageDTO pageDTO, CueProductSearchDTO cueProductSearchDTO) {
|
||||
EsPageVO<CueProductSearchVO> page = localCueProductSearchManager.page(pageDTO, cueProductSearchDTO);
|
||||
return ServerResponseEntity.success(page);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package com.tmerclub.cloud.search.manager;
|
||||
|
||||
import com.tmerclub.cloud.api.dto.EsPageDTO;
|
||||
import com.tmerclub.cloud.api.vo.EsPageVO;
|
||||
import com.tmerclub.cloud.common.local.dto.CueProductSearchDTO;
|
||||
import com.tmerclub.cloud.common.local.vo.CueProductSearchVO;
|
||||
import com.tmerclub.cloud.search.builder.LocalCueProductSearchRequestBuilder;
|
||||
import com.tmerclub.cloud.search.builder.LocalCueProductSearchResponseBuilder;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 本地生活-球杆商品搜索
|
||||
*
|
||||
* @author: frank
|
||||
* @create: 2025-04-13
|
||||
**/
|
||||
@Component
|
||||
public class LocalCueProductSearchManager {
|
||||
private static final Logger log = LoggerFactory.getLogger(LocalCueProductSearchManager.class);
|
||||
|
||||
@Resource
|
||||
LocalCueProductSearchRequestBuilder localCueProductSearchRequestBuilder;
|
||||
@Resource
|
||||
LocalCueProductSearchResponseBuilder localCueProductSearchResponseBuilder;
|
||||
|
||||
/**
|
||||
* 分页搜索
|
||||
*
|
||||
* @param pageDTO 分页信息
|
||||
* @param cueProductSearchDTO 搜索条件
|
||||
* @return EsPageVO<CueProductSearchVO>
|
||||
*/
|
||||
public EsPageVO<CueProductSearchVO> page(EsPageDTO pageDTO, CueProductSearchDTO cueProductSearchDTO) {
|
||||
SearchResponse response = localCueProductSearchRequestBuilder.pageSearchResult(pageDTO, cueProductSearchDTO);
|
||||
return buildSearchResult(pageDTO, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建搜索结果数据
|
||||
*
|
||||
* @param pageDTO 分页信息
|
||||
* @param response 搜索结果
|
||||
* @return EsPageVO<CueProductSearchVO>
|
||||
*/
|
||||
private EsPageVO<CueProductSearchVO> buildSearchResult(EsPageDTO pageDTO, SearchResponse response) {
|
||||
EsPageVO<CueProductSearchVO> esPageVO = new EsPageVO<>();
|
||||
|
||||
// 1、返回的所有查询到的商品
|
||||
List<CueProductSearchVO> cueProductSearchVOS = localCueProductSearchResponseBuilder.getProductSearchList(response);
|
||||
esPageVO.setList(cueProductSearchVOS);
|
||||
|
||||
// 2、分页信息
|
||||
localCueProductSearchResponseBuilder.buildSearchPage(pageDTO, esPageVO, response);
|
||||
return esPageVO;
|
||||
}
|
||||
}
|
@ -30,4 +30,4 @@ dubbo:
|
||||
consumer:
|
||||
loadbalance: dev
|
||||
registry:
|
||||
group: dubbo-yang
|
||||
group: dubbo-default
|
||||
|
Loading…
x
Reference in New Issue
Block a user