|
@@ -13,12 +13,25 @@ import com.citu.module.menduner.system.controller.app.appbase.AppCommonRespVO;
|
|
|
import com.citu.module.menduner.system.controller.app.enterprise.vo.*;
|
|
|
import com.citu.module.menduner.system.convert.EnterpriseConvert;
|
|
|
import com.citu.module.menduner.system.dal.dataobject.enterprise.EnterpriseDO;
|
|
|
+import com.citu.module.menduner.system.dal.es.EsEnterpriseMergeDO;
|
|
|
+import com.citu.module.menduner.system.dal.es.enterprise.ESEnterpriseDO;
|
|
|
import com.citu.module.menduner.system.dal.mysql.enterprise.EnterpriseMapper;
|
|
|
import com.citu.module.menduner.system.dal.redis.RedisKeyConstants;
|
|
|
+import com.citu.module.menduner.system.dal.repository.ESEnterpriseDORepository;
|
|
|
import com.citu.module.menduner.system.enums.visits.MdeVisitsEnum;
|
|
|
import com.citu.module.menduner.system.mq.producer.MdeVisitsProducer;
|
|
|
+import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
+import org.elasticsearch.index.query.QueryBuilders;
|
|
|
+import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
|
|
+import org.springframework.data.elasticsearch.core.SearchHits;
|
|
|
+import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
|
|
+import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -44,6 +57,12 @@ public class EnterpriseServiceImpl implements EnterpriseService {
|
|
|
@Resource
|
|
|
private MdeVisitsProducer producer;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ESEnterpriseDORepository repository;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ElasticsearchRestTemplate elasticsearchTemplate;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Long createEnterprise(EnterpriseSaveReqVO createReqVO) {
|
|
@@ -215,16 +234,62 @@ public class EnterpriseServiceImpl implements EnterpriseService {
|
|
|
result.setList(list);
|
|
|
result.setTotal(2L);
|
|
|
|
|
|
+ //分页
|
|
|
+ BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
|
|
+
|
|
|
+ // 添加关键词查询条件
|
|
|
+ if (StringUtils.hasText(reqVO.getName())) {
|
|
|
+ boolQuery.must(QueryBuilders.matchQuery("name", reqVO.getName()));
|
|
|
+ boolQuery.must(QueryBuilders.matchQuery("anotherName", reqVO.getName()));
|
|
|
+ }
|
|
|
+ if (null!= reqVO.getAreaIds() ) {
|
|
|
+ boolQuery.should(QueryBuilders.termsQuery("areaIds", reqVO.getAreaIds()));
|
|
|
+ }
|
|
|
+ if (null!= reqVO.getIndustryIds()) {
|
|
|
+ boolQuery.should(QueryBuilders.termsQuery("industryIds", reqVO.getIndustryIds()));
|
|
|
+ }
|
|
|
+ // 添加范围查询条件
|
|
|
+ if (StringUtils.hasText(reqVO.getScale())) {
|
|
|
+ boolQuery.must(QueryBuilders.termQuery("scale", reqVO.getScale()));
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(reqVO.getFinancingStatus())) {
|
|
|
+ boolQuery.must(QueryBuilders.termQuery("financingStatus", reqVO.getFinancingStatus()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建分页
|
|
|
+ Pageable pageable = PageRequest.of(reqVO.getPageNo()-1, reqVO.getPageSize());
|
|
|
+
|
|
|
+ // 构建高亮
|
|
|
+ HighlightBuilder highlightBuilder = new HighlightBuilder();
|
|
|
+ highlightBuilder.field("name").preTags("<span style='color:red'>").postTags("</span>");
|
|
|
+ highlightBuilder.field("anotherName").preTags("<span style='color:red'>").postTags("</span>");
|
|
|
+
|
|
|
+// // 构建排序
|
|
|
+// Sort sort = Sort.by(Sort.Order.asc("name"));
|
|
|
+
|
|
|
+ NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
|
|
+ .withQuery(boolQuery)
|
|
|
+ .withHighlightFields( new HighlightBuilder
|
|
|
+ .Field("*")
|
|
|
+ .preTags("<span style='color:red'>")
|
|
|
+ .postTags("</span>").requireFieldMatch(false))
|
|
|
+// .withHighlightBuilder(new HighlightBuilder().preTags("<span style='color:red'>").postTags("</span>"))
|
|
|
+ .withPageable(pageable)
|
|
|
+// .withSort(sort)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ SearchHits<EsEnterpriseMergeDO> searchHits = elasticsearchTemplate.search(searchQuery, EsEnterpriseMergeDO.class);
|
|
|
+ System.out.println(searchHits);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public AppEnterpriseSimpleRespVO getEnterpriseSimple(Long id) {
|
|
|
- EnterpriseDO enterprise= enterpriseMapper.selectById(id);
|
|
|
- if(null == enterprise) {
|
|
|
+ EnterpriseDO enterprise = enterpriseMapper.selectById(id);
|
|
|
+ if (null == enterprise) {
|
|
|
throw exception(MDE_ENTERPRISE_NOT_EXISTS);
|
|
|
}
|
|
|
- return EnterpriseConvert.INSTANCE.convert(enterprise);
|
|
|
+ return EnterpriseConvert.INSTANCE.convert(enterprise);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -236,4 +301,30 @@ public class EnterpriseServiceImpl implements EnterpriseService {
|
|
|
public List<AppCommonRespVO> searchByName(String name) {
|
|
|
return enterpriseMapper.searchByName(name);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void test() {
|
|
|
+ EnterpriseDO enterprise = enterpriseMapper.selectById(1L);
|
|
|
+ if (null == enterprise) {
|
|
|
+ throw exception(MDE_ENTERPRISE_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ EsEnterpriseMergeDO esEnterprise = EnterpriseConvert.INSTANCE.convert2(enterprise);
|
|
|
+ ESEnterpriseDO entity = repository.save(esEnterprise);
|
|
|
+ System.out.println(entity);
|
|
|
+
|
|
|
+ Optional<EsEnterpriseMergeDO> query = repository.findById(1L);
|
|
|
+ if (query.isPresent()) {
|
|
|
+ EsEnterpriseMergeDO esEnterpriseDO = query.get();
|
|
|
+ System.out.println(esEnterpriseDO);
|
|
|
+
|
|
|
+ if (null != esEnterpriseDO.getWelfareList()
|
|
|
+ && esEnterpriseDO.getWelfareList().size() < 8) {
|
|
|
+ esEnterpriseDO.getWelfareList().add("我是测试");
|
|
|
+ entity = repository.save(esEnterpriseDO);
|
|
|
+ System.out.println(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|