|
@@ -0,0 +1,125 @@
|
|
|
+package com.fire.admin.service;
|
|
|
+
|
|
|
+import com.fire.admin.request.OrderSearchPram;
|
|
|
+import com.fire.es.OrderEsDto;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.logging.log4j.util.Strings;
|
|
|
+import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
+import org.elasticsearch.index.query.QueryBuilders;
|
|
|
+import org.elasticsearch.index.query.RangeQueryBuilder;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
|
|
+import org.springframework.data.elasticsearch.core.SearchHit;
|
|
|
+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 java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class OrderManagementService {
|
|
|
+ @Autowired
|
|
|
+ private ElasticsearchRestTemplate restTemplate;
|
|
|
+
|
|
|
+ public String orderSearch(OrderSearchPram orderSearchPram) {
|
|
|
+ //以创建时间倒序排列
|
|
|
+ Sort sort = Sort.by(Sort.Direction.DESC, "applyDate");
|
|
|
+ Date applyDateStart = orderSearchPram.getApplyDateStart();
|
|
|
+ Date applyDateEnd = orderSearchPram.getApplyDateEnd();
|
|
|
+
|
|
|
+ int page = 0;
|
|
|
+ int size = 10;
|
|
|
+ if (null != orderSearchPram.getPage()) {
|
|
|
+ page = orderSearchPram.getPage();
|
|
|
+ }
|
|
|
+ if (null != orderSearchPram.getSize()) {
|
|
|
+ size = orderSearchPram.getSize();
|
|
|
+ }
|
|
|
+ //分页条件
|
|
|
+ Pageable pageable = PageRequest.of(page, size, sort);
|
|
|
+ BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
|
|
+ RangeQueryBuilder rangeQueryBuilder = null;
|
|
|
+ //判断回调时间参数是否为空 不为空以回调时间来查询 否则用创建时间来查询
|
|
|
+ if (null != orderSearchPram.getCheckTimeStart()) {
|
|
|
+ rangeQueryBuilder = QueryBuilders.rangeQuery("checkTime")
|
|
|
+ .gte(orderSearchPram.getCheckTimeStart().getTime())
|
|
|
+ .lte(orderSearchPram.getCheckTimeEnd().getTime());
|
|
|
+ } else {
|
|
|
+ rangeQueryBuilder = QueryBuilders.rangeQuery("applyDate")
|
|
|
+ .gte(applyDateStart.getTime())
|
|
|
+ .lte(applyDateEnd.getTime());
|
|
|
+ }
|
|
|
+ //筛选条件
|
|
|
+ //订单号
|
|
|
+ if (Strings.isNotBlank(orderSearchPram.getOrderId())) {
|
|
|
+ boolQuery.must(QueryBuilders.termQuery("orderId", orderSearchPram.getOrderId()));
|
|
|
+ }
|
|
|
+ //商户订单号
|
|
|
+ if (Strings.isNotBlank(orderSearchPram.getExtorderId())) {
|
|
|
+ boolQuery.must(QueryBuilders.termQuery("extorderId", orderSearchPram.getExtorderId()));
|
|
|
+ }
|
|
|
+ //电话号码
|
|
|
+ if (Strings.isNotBlank(orderSearchPram.getUsedMobile())) {
|
|
|
+ boolQuery.must(QueryBuilders.termQuery("usedMobile", orderSearchPram.getUsedMobile()));
|
|
|
+ }
|
|
|
+ //电话号码
|
|
|
+ if (Strings.isNotBlank(orderSearchPram.getUsedMobile())) {
|
|
|
+ boolQuery.must(QueryBuilders.termQuery("usedMobile", orderSearchPram.getUsedMobile()));
|
|
|
+ }
|
|
|
+ //客户名称 暂时用的ID
|
|
|
+ if (Strings.isNotBlank(orderSearchPram.getEnterpriseIdDesc())) {
|
|
|
+ boolQuery.must(QueryBuilders.termQuery("enterpriseId", orderSearchPram.getEnterpriseIdDesc()));
|
|
|
+ }
|
|
|
+ //通道名称 暂时用的ID
|
|
|
+ if (Strings.isNotBlank(orderSearchPram.getChannelIdDesc())) {
|
|
|
+ boolQuery.must(QueryBuilders.termQuery("channelId", orderSearchPram.getChannelIdDesc()));
|
|
|
+ }
|
|
|
+ //订单状态
|
|
|
+ if (Strings.isNotBlank(orderSearchPram.getStatus())) {
|
|
|
+ boolQuery.must(QueryBuilders.termQuery("status", orderSearchPram.getStatus()));
|
|
|
+ }
|
|
|
+ //运营商
|
|
|
+ if (Strings.isNotBlank(orderSearchPram.getMobileOperator())) {
|
|
|
+ boolQuery.must(QueryBuilders.termQuery("mobileOperator", orderSearchPram.getMobileOperator()));
|
|
|
+ }
|
|
|
+ //面额
|
|
|
+ if (Strings.isNotBlank(orderSearchPram.getFlowAmount())) {
|
|
|
+ boolQuery.must(QueryBuilders.termQuery("flowAmount", orderSearchPram.getFlowAmount()));
|
|
|
+ }
|
|
|
+ //归属地
|
|
|
+ if (Strings.isNotBlank(orderSearchPram.getMobileHome())) {
|
|
|
+ BoolQueryBuilder tempQueryBuilder = QueryBuilders.boolQuery();
|
|
|
+ tempQueryBuilder.should(QueryBuilders.wildcardQuery("mobileHome.keyword", orderSearchPram.getMobileHome()));
|
|
|
+ boolQuery.must(tempQueryBuilder);
|
|
|
+ }
|
|
|
+
|
|
|
+ NativeSearchQuery query = new NativeSearchQueryBuilder()
|
|
|
+ .withPageable(pageable)
|
|
|
+ .withQuery(boolQuery.must(rangeQueryBuilder))
|
|
|
+ .build();
|
|
|
+ //查询数据
|
|
|
+ SearchHits<OrderEsDto> hits = restTemplate.search(query, OrderEsDto.class);
|
|
|
+ long total = hits.getTotalHits();
|
|
|
+ List<SearchHit<OrderEsDto>> searchHits = hits.getSearchHits();
|
|
|
+ System.out.println("一共" + total + "个");
|
|
|
+ System.out.println("搜索结果" + searchHits.size() + "个");
|
|
|
+ for (SearchHit<OrderEsDto> searchHit : searchHits) {
|
|
|
+ OrderEsDto stuEntity = searchHit.getContent();
|
|
|
+ log.info(stuEntity.toString());
|
|
|
+ }
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|