|
|
@ -14,17 +14,17 @@ import lombok.RequiredArgsConstructor; |
|
|
|
import org.dromara.productManagement.domain.*; |
|
|
|
import org.dromara.productManagement.mapper.PmgSupplierProductModelDetailsMapper; |
|
|
|
import org.dromara.productManagement.mapper.PmgSupplierProductModelMapper; |
|
|
|
import org.elasticsearch.action.search.SearchRequest; |
|
|
|
import org.elasticsearch.action.search.SearchResponse; |
|
|
|
import org.elasticsearch.client.RequestOptions; |
|
|
|
import org.elasticsearch.client.RestHighLevelClient; |
|
|
|
import org.elasticsearch.index.query.QueryBuilders; |
|
|
|
import org.elasticsearch.search.SearchHit; |
|
|
|
import org.elasticsearch.search.SearchHits; |
|
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder; |
|
|
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
//import org.elasticsearch.action.search.SearchRequest;
|
|
|
|
//import org.elasticsearch.action.search.SearchResponse;
|
|
|
|
//import org.elasticsearch.client.RequestOptions;
|
|
|
|
//import org.elasticsearch.client.RestHighLevelClient;
|
|
|
|
//import org.elasticsearch.index.query.QueryBuilders;
|
|
|
|
//import org.elasticsearch.search.SearchHit;
|
|
|
|
//import org.elasticsearch.search.SearchHits;
|
|
|
|
//import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
|
|
//import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
|
|
|
//import org.springframework.beans.BeanUtils;
|
|
|
|
//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.dromara.productManagement.domain.bo.PmgSupplierProductsBo; |
|
|
|
import org.dromara.productManagement.domain.vo.PmgSupplierProductsVo; |
|
|
@ -49,8 +49,8 @@ public class PmgSupplierProductsServiceImpl implements IPmgSupplierProductsServi |
|
|
|
private final PmgSupplierProductsMapper baseMapper; |
|
|
|
private final PmgSupplierProductModelDetailsMapper supplierProductModelDetailsMapper; |
|
|
|
private final PmgSupplierProductModelMapper supplierProductModelMapper; |
|
|
|
@Autowired |
|
|
|
private RestHighLevelClient client; |
|
|
|
// @Autowired
|
|
|
|
// private RestHighLevelClient client;
|
|
|
|
/** |
|
|
|
* 查询供应商产品管理 |
|
|
|
* |
|
|
@ -188,54 +188,55 @@ public class PmgSupplierProductsServiceImpl implements IPmgSupplierProductsServi |
|
|
|
return baseMapper.deleteBatchIds(ids) > 0; |
|
|
|
} |
|
|
|
public Page<PmgSupplierProductsVo> querypagebyes(PmgSupplierProductsBo bo, PageQuery pageQuery) { |
|
|
|
// 执行查询
|
|
|
|
Page<PmgSupplierProductsVo> supplierProductsVOPage = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()); |
|
|
|
List<PmgSupplierProductsVo> supplierProductsVOList =new ArrayList<>(); |
|
|
|
String productName = bo.getProductName(); |
|
|
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); |
|
|
|
SearchRequest searchRequest = new SearchRequest("pmg_supplier_products"); |
|
|
|
// //高亮器
|
|
|
|
HighlightBuilder highlightBuilder = new HighlightBuilder(); |
|
|
|
highlightBuilder.requireFieldMatch(false)//多字段时,需要设置为false//因为高亮查询默认是对查询字段即description就行高亮,可以关闭字段匹配,这样就可以对查询到的多个字段(前提是有关键词并且改字段可以分词)进行高亮显示
|
|
|
|
.field("product_name")//若有关键字切可以分词,则可以高亮,写*可以匹配所有字段
|
|
|
|
.field("product_specifications")//若有关键字切可以分词,则可以高亮,写*可以匹配所有字段
|
|
|
|
.preTags("<span style=\"color: red;\">")//手动前缀标签
|
|
|
|
.postTags("</span>"); |
|
|
|
searchSourceBuilder |
|
|
|
.query(QueryBuilders.multiMatchQuery(productName, "product_name", "product_specifications")) |
|
|
|
.highlighter(highlightBuilder) |
|
|
|
.from(pageQuery.getPageNum()-1) //起始位置:start=(page-1)*size
|
|
|
|
.size(pageQuery.getPageSize()); //每页显示条数;
|
|
|
|
|
|
|
|
searchRequest.source(searchSourceBuilder); |
|
|
|
try { |
|
|
|
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); |
|
|
|
// 解析结果
|
|
|
|
SearchHits hits = response.getHits(); |
|
|
|
|
|
|
|
|
|
|
|
supplierProductsVOPage.setTotal(response.getHits().getTotalHits().value); |
|
|
|
SearchHit[] searchHits = hits.getHits(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
for (SearchHit hit : searchHits) { |
|
|
|
String json =mapper.writeValueAsString(hit.getSourceAsMap()); |
|
|
|
SupplierProductsDTO supplierProductsDTO = mapper.readValue(json, SupplierProductsDTO.class); |
|
|
|
PmgSupplierProductsVo supplierProductsVO = new PmgSupplierProductsVo(); |
|
|
|
BeanUtils.copyProperties(supplierProductsDTO,supplierProductsVO); |
|
|
|
if(hit.getHighlightFields().get("product_name")!=null){ |
|
|
|
supplierProductsVO.setProductName(hit.getHighlightFields().get("product_name").getFragments()[0].toString()); |
|
|
|
|
|
|
|
} |
|
|
|
if(hit.getHighlightFields().get("product_specifications")!=null){ |
|
|
|
supplierProductsVO.setProductSpecifications(hit.getHighlightFields().get("product_specifications").getFragments()[0].toString()); |
|
|
|
|
|
|
|
} |
|
|
|
supplierProductsVOList.add(supplierProductsVO); |
|
|
|
} |
|
|
|
supplierProductsVOPage.setRecords(supplierProductsVOList); |
|
|
|
return supplierProductsVOPage; |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
// // 执行查询
|
|
|
|
// Page<PmgSupplierProductsVo> supplierProductsVOPage = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
|
|
|
|
// List<PmgSupplierProductsVo> supplierProductsVOList =new ArrayList<>();
|
|
|
|
// String productName = bo.getProductName();
|
|
|
|
// SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
|
|
// SearchRequest searchRequest = new SearchRequest("pmg_supplier_products");
|
|
|
|
// // //高亮器
|
|
|
|
// HighlightBuilder highlightBuilder = new HighlightBuilder();
|
|
|
|
// highlightBuilder.requireFieldMatch(false)//多字段时,需要设置为false//因为高亮查询默认是对查询字段即description就行高亮,可以关闭字段匹配,这样就可以对查询到的多个字段(前提是有关键词并且改字段可以分词)进行高亮显示
|
|
|
|
// .field("product_name")//若有关键字切可以分词,则可以高亮,写*可以匹配所有字段
|
|
|
|
// .field("product_specifications")//若有关键字切可以分词,则可以高亮,写*可以匹配所有字段
|
|
|
|
// .preTags("<span style=\"color: red;\">")//手动前缀标签
|
|
|
|
// .postTags("</span>");
|
|
|
|
// searchSourceBuilder
|
|
|
|
// .query(QueryBuilders.multiMatchQuery(productName, "product_name", "product_specifications"))
|
|
|
|
// .highlighter(highlightBuilder)
|
|
|
|
// .from(pageQuery.getPageNum()-1) //起始位置:start=(page-1)*size
|
|
|
|
// .size(pageQuery.getPageSize()); //每页显示条数;
|
|
|
|
//
|
|
|
|
// searchRequest.source(searchSourceBuilder);
|
|
|
|
// try {
|
|
|
|
// SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
|
|
|
|
// // 解析结果
|
|
|
|
// SearchHits hits = response.getHits();
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// supplierProductsVOPage.setTotal(response.getHits().getTotalHits().value);
|
|
|
|
// SearchHit[] searchHits = hits.getHits();
|
|
|
|
// ObjectMapper mapper = new ObjectMapper();
|
|
|
|
// for (SearchHit hit : searchHits) {
|
|
|
|
// String json =mapper.writeValueAsString(hit.getSourceAsMap());
|
|
|
|
// SupplierProductsDTO supplierProductsDTO = mapper.readValue(json, SupplierProductsDTO.class);
|
|
|
|
// PmgSupplierProductsVo supplierProductsVO = new PmgSupplierProductsVo();
|
|
|
|
// BeanUtils.copyProperties(supplierProductsDTO,supplierProductsVO);
|
|
|
|
// if(hit.getHighlightFields().get("product_name")!=null){
|
|
|
|
// supplierProductsVO.setProductName(hit.getHighlightFields().get("product_name").getFragments()[0].toString());
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// if(hit.getHighlightFields().get("product_specifications")!=null){
|
|
|
|
// supplierProductsVO.setProductSpecifications(hit.getHighlightFields().get("product_specifications").getFragments()[0].toString());
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// supplierProductsVOList.add(supplierProductsVO);
|
|
|
|
// }
|
|
|
|
// supplierProductsVOPage.setRecords(supplierProductsVOList);
|
|
|
|
// return supplierProductsVOPage;
|
|
|
|
// } catch (Exception e) {
|
|
|
|
// throw new RuntimeException(e);
|
|
|
|
// }
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|