elasticsearch应用于产品列表
package com.linkwee.web.service; import java.util.List; import com.linkwee.api.request.cim.ProductPageListClassifyRequest; import com.linkwee.api.request.cim.ProductPageListRecommendRequest; import com.linkwee.api.request.cim.ProductPageListRequest; import com.linkwee.api.request.cim.ScreenProductPageListRequest; import com.linkwee.api.response.cim.ProductPageListResponse; import com.linkwee.core.orm.paging.Page; public interface ElasticsearchProductService { /** * 查询产品列表 * @param productPageListRequest * @param page * @return */ public List<ProductPageListResponse> elasticSearchQueryProductPageList(ProductPageListRequest productPageListRequest,Page<ProductPageListResponse> page); /** * 产品分类列表(901,902) * @param productPageListClassifyRequest * @param page * @return */ public List<ProductPageListResponse> elasticSearchQueryProductCateExtendsPageList(ProductPageListClassifyRequest productPageListClassifyRequest,Page<ProductPageListResponse> page); /** * 热推产品分页 * @param productPageListClassifyRequest * @param page * @return */ public List<ProductPageListResponse> elasticSearchQueryHotRecommendPageList(ProductPageListClassifyRequest productPageListClassifyRequest,Page<ProductPageListResponse> page); /** * 产品分类列表(产品类型表) * @param productPageListClassifyRequest * @param page * @return */ public List<ProductPageListResponse> elasticSearchQueryProductCatePageList(ProductPageListClassifyRequest productPageListClassifyRequest,Page<ProductPageListResponse> page); /** * 用户理财师推荐的产品列表 * @param productPageListRecommendRequest * @param page * @return */ public List<ProductPageListResponse> elasticSearchQueryRecdProductPageList(ProductPageListRecommendRequest productPageListRecommendRequest,Page<ProductPageListResponse> page); /** * 产品筛选列表分页(PC ) * @param productPageListRequest * @param page * @return */ public List<ProductPageListResponse> elasticSearchQueryProductScreenPageList(ScreenProductPageListRequest screenProductPageListRequest,Page<ProductPageListResponse> page); }
上述代码是产品列表涉及的主要服务方法,下面是具体实现:
package com.linkwee.web.service.impl; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.apache.commons.lang.StringUtils; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; import org.elasticsearch.index.query.support.QueryInnerHitBuilder; import org.elasticsearch.script.Script; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.ScoreSortBuilder; import org.elasticsearch.search.sort.SortBuilder; import org.elasticsearch.search.sort.SortOrder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.databind.ObjectMapper; import com.linkwee.api.request.cim.ProductPageListClassifyRequest; import com.linkwee.api.request.cim.ProductPageListRecommendRequest; import com.linkwee.api.request.cim.ProductPageListRequest; import com.linkwee.api.request.cim.ScreenProductPageListRequest; import com.linkwee.api.response.cim.ElasticsearchProductListResponse; import com.linkwee.api.response.cim.ProductPageListResponse; import com.linkwee.core.orm.paging.Page; import com.linkwee.web.model.CimOrginfo; import com.linkwee.web.service.CimOrginfoService; import com.linkwee.web.service.ElasticsearchProductService; import com.linkwee.xoss.helper.ElasticsearchHelper; /** * elasticSearch查询服务 * @author Administrator * */ @Service("elasticsearchProductService") public class ElasticsearchProductServiceImpl implements ElasticsearchProductService{ Logger LOGGER = LoggerFactory.getLogger(this.getClass()); @Autowired private ElasticsearchHelper elasticsearchHelper; @Resource private CimOrginfoService cimOrginfoService; public List<ProductPageListResponse> elasticSearchQueryProductPageList(ProductPageListRequest productPageListRequest,Page<ProductPageListResponse> page){ List<ProductPageListResponse> productPageListResponses = new ArrayList<ProductPageListResponse>(); try { TransportClient client = elasticsearchHelper.getElasticSearchClient(); SearchRequestBuilder searchRequestBuilder = client.prepareSearch("logstash-supermarket-online").setTypes("productFull"); BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery() .must(QueryBuilders.termQuery("orgStatus", 1)) .must(QueryBuilders.termQuery("status", 1)) .must(QueryBuilders.termQuery("auditStatus", 1)) .must(QueryBuilders.scriptQuery(new Script("doc['buyTotalMoney'].value > doc['buyedTotalMoney'].value")));// if(!productPageListRequest.getIfHaveGray()){ queryBuilder.must(QueryBuilders.termQuery("orgGrayStatus", 0)); } if(StringUtils.isNotBlank(productPageListRequest.getOrgNumber())){ queryBuilder.must(QueryBuilders.termQuery("orgNumber.raw", productPageListRequest.getOrgNumber())); } searchRequestBuilder = searchRequestBuilder.setQuery(queryBuilder);//QueryBuilders.boolQuery().filter(queryBuilder) SortBuilder isSallingSort = new FieldSortBuilder("isSalling").order(SortOrder.DESC); SortBuilder commonSort = null; SortBuilder timeSort = null; Integer cnSort = productPageListRequest.getSort(); Integer cnOrder = productPageListRequest.getOrder(); if(cnSort != null && cnOrder != null){ if(cnSort == 1){ commonSort = new FieldSortBuilder("showIndex"); }else if(cnSort == 2 && cnOrder == 0){ commonSort = new FieldSortBuilder("flowMinRate"); }else if(cnSort == 2 && cnOrder == 1){ commonSort = new FieldSortBuilder("flowMaxRate"); }else if(cnSort == 3 && cnOrder == 0){ commonSort = new FieldSortBuilder("deadLineMinValue"); }else if(cnSort == 3 && cnOrder == 1){ commonSort = new FieldSortBuilder("deadLineMaxValue"); }else if(cnSort == 4){ commonSort = new FieldSortBuilder("feeRatio"); } if(cnOrder == 0){ commonSort.order(SortOrder.ASC); }else if(cnOrder == 1){ commonSort.order(SortOrder.DESC); } timeSort = new FieldSortBuilder("createTime").order(SortOrder.DESC); } searchRequestBuilder.addSort(isSallingSort); if(commonSort != null){ searchRequestBuilder.addSort(commonSort); } if(timeSort != null){ searchRequestBuilder.addSort(timeSort); } SearchResponse searchResponse = searchRequestBuilder.setFrom((page.getPageNo()-1)*page.getPageSize()).setSize(page.getPageSize()).get();//178271C881504FBCBF1DF80DE9944D66 SearchHits hits = searchResponse.getHits(); ObjectMapper mapper = new ObjectMapper(); page.setTotalCount((int) hits.getTotalHits()); page.setTotalPages((int) (hits.getTotalHits()%page.getPageSize() == 0 ? hits.getTotalHits()/page.getPageSize() : hits.getTotalHits()/page.getPageSize() +1)); for (int i = 0; i < hits.getHits().length; i++) { Map<String, Object> temp = hits.getHits()[i].getSource(); temp = elasticsearchHelper.removeUseless(temp); ElasticsearchProductListResponse elasticsearchProductListResponse = mapper.readValue(JSONObject.toJSON(temp).toString(), ElasticsearchProductListResponse.class); productPageListResponses.add(elasticsearchHelper.conversProductPageListResponses(productPageListRequest,elasticsearchProductListResponse)); } } catch (Exception e) { LOGGER.info("elasticSearch查询产品列表异常", e); } return productPageListResponses; } @Override public List<ProductPageListResponse> elasticSearchQueryProductCateExtendsPageList(ProductPageListClassifyRequest productPageListClassifyRequest,Page<ProductPageListResponse> page) { List<ProductPageListResponse> productPageListResponses = new ArrayList<ProductPageListResponse>(); try { TransportClient client = elasticsearchHelper.getElasticSearchClient(); SearchRequestBuilder searchRequestBuilder = client.prepareSearch("logstash-supermarket-online").setTypes("productFull"); BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery() .must(QueryBuilders.termQuery("orgStatus", 1)) .must(QueryBuilders.termQuery("status", 1)) .must(QueryBuilders.termQuery("auditStatus", 1)) .must(QueryBuilders.scriptQuery(new Script("doc['buyTotalMoney'].value > doc['buyedTotalMoney'].value")));// if(!productPageListClassifyRequest.getIfHaveGray()){ queryBuilder.must(QueryBuilders.termQuery("orgGrayStatus", 0)); } if(StringUtils.isNotBlank(productPageListClassifyRequest.getOrgNumber())){ queryBuilder.must(QueryBuilders.termQuery("orgNumber.raw", productPageListClassifyRequest.getOrgNumber())); } if(productPageListClassifyRequest.getCateId() == 901){ queryBuilder.must(QueryBuilders.termQuery("orgFeeType", 1)); }else if(productPageListClassifyRequest.getCateId() == 902){ queryBuilder.must(QueryBuilders.termQuery("orgFeeType", 2)); } searchRequestBuilder = searchRequestBuilder.setQuery(queryBuilder); SortBuilder isSallingSort = new FieldSortBuilder("isSalling").order(SortOrder.DESC); SortBuilder commonSort = null; SortBuilder timeSort = null; Integer cnSort = productPageListClassifyRequest.getSort(); Integer cnOrder = productPageListClassifyRequest.getOrder(); if(cnSort != null && cnOrder != null){ if(cnSort == 1){ commonSort = new FieldSortBuilder("showIndex"); }else if(cnSort == 2 && cnOrder == 0){ commonSort = new FieldSortBuilder("flowMinRate"); }else if(cnSort == 2 && cnOrder == 1){ commonSort = new FieldSortBuilder("flowMaxRate"); }else if(cnSort == 3 && cnOrder == 0){ commonSort = new FieldSortBuilder("deadLineMinValue"); }else if(cnSort == 3 && cnOrder == 1){ commonSort = new FieldSortBuilder("deadLineMaxValue"); }else if(cnSort == 4){ commonSort = new FieldSortBuilder("feeRatio"); } if(cnOrder == 0){ commonSort.order(SortOrder.ASC); }else if(cnOrder == 1){ commonSort.order(SortOrder.DESC); } timeSort = new FieldSortBuilder("createTime").order(SortOrder.DESC); } searchRequestBuilder.addSort(isSallingSort); if(commonSort != null){ searchRequestBuilder.addSort(commonSort); } if(timeSort != null){ searchRequestBuilder.addSort(timeSort); } SearchResponse searchResponse = searchRequestBuilder.setFrom((page.getPageNo()-1)*page.getPageSize()).setSize(page.getPageSize()).get();//178271C881504FBCBF1DF80DE9944D66 SearchHits hits = searchResponse.getHits(); ObjectMapper mapper = new ObjectMapper(); page.setTotalCount((int) hits.getTotalHits()); page.setTotalPages((int) (hits.getTotalHits()%page.getPageSize() == 0 ? hits.getTotalHits()/page.getPageSize() : hits.getTotalHits()/page.getPageSize() +1)); for (int i = 0; i < hits.getHits().length; i++) { Map<String, Object> temp = hits.getHits()[i].getSource(); temp = elasticsearchHelper.removeUseless(temp); ElasticsearchProductListResponse elasticsearchProductListResponse = mapper.readValue(JSONObject.toJSON(temp).toString(), ElasticsearchProductListResponse.class); productPageListResponses.add(elasticsearchHelper.conversProductPageListResponses(productPageListClassifyRequest,elasticsearchProductListResponse)); } } catch (Exception e) { LOGGER.info("elasticSearch查询产品分类列表异常", e); } return productPageListResponses; } @Override public List<ProductPageListResponse> elasticSearchQueryHotRecommendPageList(ProductPageListClassifyRequest productPageListClassifyRequest,Page<ProductPageListResponse> page) { List<ProductPageListResponse> productPageListResponses = new ArrayList<ProductPageListResponse>(); try { TransportClient client = elasticsearchHelper.getElasticSearchClient(); SearchRequestBuilder searchRequestBuilder = client.prepareSearch("logstash-supermarket-online").setTypes("productFull"); BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery() .must(QueryBuilders.termQuery("orgStatus", 1)) .must(QueryBuilders.termQuery("status", 1)) .must(QueryBuilders.termQuery("auditStatus", 1)) .must(QueryBuilders.termQuery("orgIsstaticproduct", 0)) .must(QueryBuilders.scriptQuery(new Script("doc['buyTotalMoney'].value > doc['buyedTotalMoney'].value"))).boost(0);// if(!productPageListClassifyRequest.getIfHaveGray()){ queryBuilder.must(QueryBuilders.termQuery("orgGrayStatus", 0)).boost(0); } queryBuilder.must(QueryBuilders.hasChildQuery("productRef", QueryBuilders.scriptQuery(new Script("new Period(new Date().getTime(), doc['recommendTime'].value).getDays() <= 2"))).innerHit(new QueryInnerHitBuilder()).scoreMode("sum")); searchRequestBuilder = searchRequestBuilder.setQuery(queryBuilder); SortBuilder recommendTimesSort = new ScoreSortBuilder().order(SortOrder.DESC); //SortBuilder recommendTimesSort = new ScriptSortBuilder(new Script(""), "number").order(SortOrder.DESC);//inner_hits.productRef.hits.total searchRequestBuilder.addSort(recommendTimesSort); SearchResponse searchResponse = searchRequestBuilder.setFrom((page.getPageNo()-1)*page.getPageSize()).setSize(page.getPageSize()).get();//178271C881504FBCBF1DF80DE9944D66 SearchHits hits = searchResponse.getHits(); ObjectMapper mapper = new ObjectMapper(); page.setTotalCount((int) hits.getTotalHits()); page.setTotalPages((int) (hits.getTotalHits()%page.getPageSize() == 0 ? hits.getTotalHits()/page.getPageSize() : hits.getTotalHits()/page.getPageSize() +1)); for (int i = 0; i < hits.getHits().length; i++) { Map<String, Object> temp = hits.getHits()[i].getSource(); //Map<String, SearchHits> tempXXX = hits.getHits()[i].getInnerHits(); /*System.out.println(tempXXX.get("productRef").getTotalHits()); System.out.println(hits.getHits()[i].getScore());*/ temp = elasticsearchHelper.removeUseless(temp); ElasticsearchProductListResponse elasticsearchProductListResponse = mapper.readValue(JSONObject.toJSON(temp).toString(), ElasticsearchProductListResponse.class); productPageListResponses.add(elasticsearchHelper.conversProductPageListResponses(productPageListClassifyRequest,elasticsearchProductListResponse)); } } catch (Exception e) { LOGGER.info("elasticSearch查询热推产品列表分页异常", e); } return productPageListResponses; } @Override public List<ProductPageListResponse> elasticSearchQueryProductCatePageList(ProductPageListClassifyRequest productPageListClassifyRequest,Page<ProductPageListResponse> page) { List<ProductPageListResponse> productPageListResponses = new ArrayList<ProductPageListResponse>(); try { TransportClient client = elasticsearchHelper.getElasticSearchClient(); SearchRequestBuilder searchRequestBuilder = client.prepareSearch("logstash-supermarket-online").setTypes("productFull"); BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery() .must(QueryBuilders.termQuery("orgStatus", 1)) .must(QueryBuilders.termQuery("status", 1)) .must(QueryBuilders.termQuery("auditStatus", 1)) .must(QueryBuilders.scriptQuery(new Script("doc['buyTotalMoney'].value > doc['buyedTotalMoney'].value"))).boost(0);// if(!productPageListClassifyRequest.getIfHaveGray()){ queryBuilder.must(QueryBuilders.termQuery("orgGrayStatus", 0).boost(0)); } if(StringUtils.isNotBlank(productPageListClassifyRequest.getOrgNumber())){ queryBuilder.must(QueryBuilders.termQuery("orgNumber.raw", productPageListClassifyRequest.getOrgNumber()).boost(0)); } if(productPageListClassifyRequest.getCateId() != null){ queryBuilder .must(QueryBuilders.hasChildQuery( "productInfoCateAll", QueryBuilders.boolQuery() .must(QueryBuilders.functionScoreQuery(ScoreFunctionBuilders.fieldValueFactorFunction("sort").factor(1))) .must(QueryBuilders.boolQuery() .must(QueryBuilders.termQuery("cateId",productPageListClassifyRequest.getCateId())) .must(QueryBuilders.termQuery("disabled",0)) .boost(0))) .innerHit(new QueryInnerHitBuilder()) .scoreMode("avg")); } searchRequestBuilder = searchRequestBuilder.setQuery(queryBuilder); SortBuilder isSallingSort = new FieldSortBuilder("isSalling").order(SortOrder.DESC); SortBuilder tpicSortSort = new ScoreSortBuilder().order(SortOrder.DESC); SortBuilder commonSort = null; SortBuilder timeSort = null; Integer cnSort = productPageListClassifyRequest.getSort(); Integer cnOrder = productPageListClassifyRequest.getOrder(); if(cnSort != null && cnOrder != null){ if(cnSort == 1){ commonSort = new FieldSortBuilder("showIndex"); }else if(cnSort == 2 && cnOrder == 0){ commonSort = new FieldSortBuilder("flowMinRate"); }else if(cnSort == 2 && cnOrder == 1){ commonSort = new FieldSortBuilder("flowMaxRate"); }else if(cnSort == 3 && cnOrder == 0){ commonSort = new FieldSortBuilder("deadLineMinValue"); }else if(cnSort == 3 && cnOrder == 1){ commonSort = new FieldSortBuilder("deadLineMaxValue"); }else if(cnSort == 4){ commonSort = new FieldSortBuilder("feeRatio"); } if(cnOrder == 0){ commonSort.order(SortOrder.ASC); }else if(cnOrder == 1){ commonSort.order(SortOrder.DESC); } timeSort = new FieldSortBuilder("createTime").order(SortOrder.DESC); } searchRequestBuilder.addSort(isSallingSort); searchRequestBuilder.addSort(tpicSortSort); if(commonSort != null){ searchRequestBuilder.addSort(commonSort); } if(timeSort != null){ searchRequestBuilder.addSort(timeSort); } SearchResponse searchResponse = searchRequestBuilder.setFrom((page.getPageNo()-1)*page.getPageSize()).setSize(page.getPageSize()).get();//178271C881504FBCBF1DF80DE9944D66 SearchHits hits = searchResponse.getHits(); ObjectMapper mapper = new ObjectMapper(); page.setTotalCount((int) hits.getTotalHits()); page.setTotalPages((int) (hits.getTotalHits()%page.getPageSize() == 0 ? hits.getTotalHits()/page.getPageSize() : hits.getTotalHits()/page.getPageSize() +1)); for (int i = 0; i < hits.getHits().length; i++) { Map<String, Object> temp = hits.getHits()[i].getSource(); //System.out.println(hits.getHits()[i].getScore()); temp = elasticsearchHelper.removeUseless(temp); ElasticsearchProductListResponse elasticsearchProductListResponse = mapper.readValue(JSONObject.toJSON(temp).toString(), ElasticsearchProductListResponse.class); productPageListResponses.add(elasticsearchHelper.conversProductPageListResponses(productPageListClassifyRequest,elasticsearchProductListResponse)); } } catch (Exception e) { LOGGER.info("elasticSearch查询产品分类列表异常", e); } return productPageListResponses; } @Override public List<ProductPageListResponse> elasticSearchQueryRecdProductPageList(ProductPageListRecommendRequest productPageListRecommendRequest,Page<ProductPageListResponse> page) { List<ProductPageListResponse> productPageListResponses = new ArrayList<ProductPageListResponse>(); try { TransportClient client = elasticsearchHelper.getElasticSearchClient(); SearchRequestBuilder searchRequestBuilder = client.prepareSearch("logstash-supermarket-online").setTypes("productFull"); BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery() .must(QueryBuilders.termQuery("orgStatus", 1)) .must(QueryBuilders.termQuery("status", 1)) .must(QueryBuilders.termQuery("auditStatus", 1)) .must(QueryBuilders.scriptQuery(new Script("doc['buyTotalMoney'].value > doc['buyedTotalMoney'].value")));// if(!productPageListRecommendRequest.getIfHaveGray()){ queryBuilder.must(QueryBuilders.termQuery("orgGrayStatus", 0)); } if(StringUtils.isNotBlank(productPageListRecommendRequest.getOrgNumber())){ queryBuilder.must(QueryBuilders.termQuery("orgNumber.raw", productPageListRecommendRequest.getOrgNumber())); } queryBuilder .must(QueryBuilders .hasChildQuery( "productRef", QueryBuilders.boolQuery() .must(QueryBuilders.termQuery("investorUserId", productPageListRecommendRequest.getUserId())) .must(QueryBuilders.termQuery("saleUserId", productPageListRecommendRequest.getCfplannerUserId())) ) .innerHit(new QueryInnerHitBuilder()) ); searchRequestBuilder = searchRequestBuilder.setQuery(queryBuilder); SortBuilder commonSort = null; SortBuilder timeSort = null; Integer cnSort = productPageListRecommendRequest.getSort(); Integer cnOrder = productPageListRecommendRequest.getOrder(); if(cnSort != null && cnOrder != null){ if(cnSort == 1){ commonSort = new FieldSortBuilder("showIndex"); }else if(cnSort == 2 && cnOrder == 0){ commonSort = new FieldSortBuilder("flowMinRate"); }else if(cnSort == 2 && cnOrder == 1){ commonSort = new FieldSortBuilder("flowMaxRate"); }else if(cnSort == 3 && cnOrder == 0){ commonSort = new FieldSortBuilder("deadLineMinValue"); }else if(cnSort == 3 && cnOrder == 1){ commonSort = new FieldSortBuilder("deadLineMaxValue"); }else if(cnSort == 4){ commonSort = new FieldSortBuilder("feeRatio"); } if(cnOrder == 0){ commonSort.order(SortOrder.ASC); }else if(cnOrder == 1){ commonSort.order(SortOrder.DESC); } timeSort = new FieldSortBuilder("createTime").order(SortOrder.DESC); } if(commonSort != null){ searchRequestBuilder.addSort(commonSort); } if(timeSort != null){ searchRequestBuilder.addSort(timeSort); } SearchResponse searchResponse = searchRequestBuilder.setFrom((page.getPageNo()-1)*page.getPageSize()).setSize(page.getPageSize()).get();//178271C881504FBCBF1DF80DE9944D66 SearchHits hits = searchResponse.getHits(); ObjectMapper mapper = new ObjectMapper(); page.setTotalCount((int) hits.getTotalHits()); page.setTotalPages((int) (hits.getTotalHits()%page.getPageSize() == 0 ? hits.getTotalHits()/page.getPageSize() : hits.getTotalHits()/page.getPageSize() +1)); for (int i = 0; i < hits.getHits().length; i++) { Map<String, Object> temp = hits.getHits()[i].getSource(); temp = elasticsearchHelper.removeUseless(temp); ElasticsearchProductListResponse elasticsearchProductListResponse = mapper.readValue(JSONObject.toJSON(temp).toString(), ElasticsearchProductListResponse.class); productPageListResponses.add(elasticsearchHelper.conversProductPageListResponses(productPageListRecommendRequest,elasticsearchProductListResponse)); } } catch (Exception e) { LOGGER.info("elasticSearch查询客户的理财师推荐产品列表分页异常", e); } return productPageListResponses; } @Override public List<ProductPageListResponse> elasticSearchQueryProductScreenPageList(ScreenProductPageListRequest screenProductPageListRequest,Page<ProductPageListResponse> page) { List<ProductPageListResponse> productPageListResponses = new ArrayList<ProductPageListResponse>(); try { TransportClient client = elasticsearchHelper.getElasticSearchClient(); SearchRequestBuilder searchRequestBuilder = client.prepareSearch("logstash-supermarket-online").setTypes("productFull"); BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery() .must(QueryBuilders.termQuery("orgStatus", 1)) .must(QueryBuilders.termQuery("status", 1)) .must(QueryBuilders.termQuery("auditStatus", 1)) .must(QueryBuilders.scriptQuery(new Script("doc['saleStartTime'].value < new Date().getTime()"))) .must(QueryBuilders.scriptQuery(new Script("doc['buyTotalMoney'].value > doc['buyedTotalMoney'].value")));// if(!screenProductPageListRequest.getIfHaveGray()){ queryBuilder.must(QueryBuilders.termQuery("orgGrayStatus", 0)); } if(StringUtils.isNotBlank(screenProductPageListRequest.getOrgNumber())){ queryBuilder.must(QueryBuilders.termQuery("orgNumber.raw", screenProductPageListRequest.getOrgNumber())); } if(StringUtils.isNotBlank(screenProductPageListRequest.getMinDeadLine()) && StringUtils.isNotBlank(screenProductPageListRequest.getMaxDeadLine())){ queryBuilder.must(QueryBuilders.boolQuery().minimumNumberShouldMatch(1) .should(QueryBuilders.boolQuery().must(QueryBuilders.rangeQuery("deadLineMinValue").lte(screenProductPageListRequest.getMinDeadLine())).must(QueryBuilders.rangeQuery("deadLineMaxValue").gte(screenProductPageListRequest.getMaxDeadLine()))) .should(QueryBuilders.boolQuery().must(QueryBuilders.rangeQuery("deadLineMinValue").gte(screenProductPageListRequest.getMinDeadLine())).must(QueryBuilders.rangeQuery("deadLineMinValue").lte(screenProductPageListRequest.getMaxDeadLine()))) .should(QueryBuilders.boolQuery().must(QueryBuilders.rangeQuery("deadLineMaxValue").gte(screenProductPageListRequest.getMinDeadLine())).must(QueryBuilders.rangeQuery("deadLineMaxValue").lte(screenProductPageListRequest.getMaxDeadLine()))) ); } if(StringUtils.isNotBlank(screenProductPageListRequest.getMinYearProfit()) && StringUtils.isNotBlank(screenProductPageListRequest.getMaxYearProfit())){ queryBuilder.must(QueryBuilders.boolQuery().minimumNumberShouldMatch(1) .should(QueryBuilders.boolQuery().must(QueryBuilders.rangeQuery("flowMinRate").lte(screenProductPageListRequest.getMinYearProfit())).must(QueryBuilders.rangeQuery("flowMaxRate").gte(screenProductPageListRequest.getMaxYearProfit()))) .should(QueryBuilders.boolQuery().must(QueryBuilders.rangeQuery("flowMinRate").gte(screenProductPageListRequest.getMinYearProfit())).must(QueryBuilders.rangeQuery("flowMinRate").lte(screenProductPageListRequest.getMaxYearProfit()))) .should(QueryBuilders.boolQuery().must(QueryBuilders.rangeQuery("flowMaxRate").gte(screenProductPageListRequest.getMinYearProfit())).must(QueryBuilders.rangeQuery("flowMaxRate").lte(screenProductPageListRequest.getMaxYearProfit()))) ); } if(StringUtils.isNotBlank(screenProductPageListRequest.getPlatformContext())){ List<String> orgNumberList = new ArrayList<String>(); CimOrginfo cimOrginfo = new CimOrginfo(); cimOrginfo.setContext(screenProductPageListRequest.getPlatformContext()); List<CimOrginfo> orgInfoList= cimOrginfoService.selectListByCondition(cimOrginfo); for(CimOrginfo temp : orgInfoList){ orgNumberList.add(temp.getOrgNumber()); } queryBuilder.must(QueryBuilders.termsQuery("orgNumber.raw", orgNumberList)); } if(StringUtils.isNotBlank(screenProductPageListRequest.getSecurityLevel())){ queryBuilder.must(QueryBuilders.scriptQuery(new Script("doc['orgGrade.raw'].value.toInteger() " + screenProductPageListRequest.getSecurityLevel()))); } searchRequestBuilder = searchRequestBuilder.setQuery(queryBuilder); SortBuilder isSallingSort = new FieldSortBuilder("isSalling").order(SortOrder.DESC); SortBuilder commonSort = null; SortBuilder timeSort = null; Integer cnSort = screenProductPageListRequest.getSort(); Integer cnOrder = screenProductPageListRequest.getOrder(); if(cnSort != null && cnOrder != null){ if(cnSort == 1){ commonSort = new FieldSortBuilder("showIndex"); }else if(cnSort == 2 && cnOrder == 0){ commonSort = new FieldSortBuilder("flowMinRate"); }else if(cnSort == 2 && cnOrder == 1){ commonSort = new FieldSortBuilder("flowMaxRate"); }else if(cnSort == 3 && cnOrder == 0){ commonSort = new FieldSortBuilder("deadLineMinValue"); }else if(cnSort == 3 && cnOrder == 1){ commonSort = new FieldSortBuilder("deadLineMaxValue"); }else if(cnSort == 4){ commonSort = new FieldSortBuilder("feeRatio"); } if(cnOrder == 0){ commonSort.order(SortOrder.ASC); }else if(cnOrder == 1){ commonSort.order(SortOrder.DESC); } timeSort = new FieldSortBuilder("createTime").order(SortOrder.DESC); } searchRequestBuilder.addSort(isSallingSort); if(commonSort != null){ searchRequestBuilder.addSort(commonSort); } if(timeSort != null){ searchRequestBuilder.addSort(timeSort); } SearchResponse searchResponse = searchRequestBuilder.setFrom((page.getPageNo()-1)*page.getPageSize()).setSize(page.getPageSize()).get();//178271C881504FBCBF1DF80DE9944D66 SearchHits hits = searchResponse.getHits(); ObjectMapper mapper = new ObjectMapper(); page.setTotalCount((int) hits.getTotalHits()); page.setTotalPages((int) (hits.getTotalHits()%page.getPageSize() == 0 ? hits.getTotalHits()/page.getPageSize() : hits.getTotalHits()/page.getPageSize() +1)); for (int i = 0; i < hits.getHits().length; i++) { Map<String, Object> temp = hits.getHits()[i].getSource(); temp = elasticsearchHelper.removeUseless(temp); ElasticsearchProductListResponse elasticsearchProductListResponse = mapper.readValue(JSONObject.toJSON(temp).toString(), ElasticsearchProductListResponse.class); productPageListResponses.add(elasticsearchHelper.conversProductPageListResponses(screenProductPageListRequest,elasticsearchProductListResponse)); } } catch (Exception e) { LOGGER.info("elasticSearch查询产品列表异常", e); } return productPageListResponses; } }
产品列表的列表返回对象为:
package com.linkwee.api.response.cim; import java.math.BigDecimal; import java.util.Date; import java.util.List; import com.linkwee.web.model.ActivityList; import com.linkwee.web.model.CimOrgMemberInfo; import com.linkwee.web.model.CimProduct; public class ElasticsearchProductListResponse extends CimProduct { /** * */ private static final long serialVersionUID = 1L; /** *主键,自增长 */ private Integer orgId; /** *机构编码-不重复字段 */ private String orgNumber; /** *机构名称 */ private String orgName; /** *机构后台账户 */ private String orgAccount; /** *机构后台密码 */ private String orgPassword; /** *平台背景 */ private String orgContext; /** *注册资本 */ private String orgCapital; /** *上线时间 */ private Date orgUpTime; /** *所在城市 */ private String orgCity; /** *icp备案 */ private String orgIcpFiling; /** *法人代表 */ private String orgRepresentative; /** *联系方式 */ private String orgContact; /** *主页平台logo */ private String orgPlatformIco; /** *平台列表logo */ private String orgPlatformlistIco; /** *平台详情图片 */ private String orgPlatformDetailImg; /** *营业执照 */ private String orgBusinessLicense; /** *首页推荐,是否首页推荐0-不推荐、1-推荐 */ private Integer orgRecommend; /** *安全评级 1-B,2-BB,3-BBB,4-A,5-AA,6-AAA */ private String orgGrade; /** *机构列表排名 */ private Integer orgTop; /** *首页推荐机构排名 */ private Integer orgHomepageSort; /** *合作状态.0-合作结束,1-合作中 */ private Integer orgStatus; /** *备注 */ private String orgRemark; /** *创建时间 */ private Date orgCreateTime; /** *更新时间 */ private Date orgUpdateTime; /** *最小年化收益 */ private BigDecimal orgMinProfit; /** *最大年化收益 */ private BigDecimal orgMaxProfit; /** *平台产品最小佣金率 */ private BigDecimal orgMinFeeRatio; /** *平台产品最大佣金率 */ private BigDecimal orgMaxFeeRatio; /** *最小产品期限 */ private Integer orgMinDeadLine; /** *最大产品期限 */ private Integer orgMaxDeadLine; /** *产品最小期限天数 自定义显示 */ private String orgDeadLineMinSelfDefined; /** *产品最大期限天数 自定义显示 */ private String orgDeadLineMaxSelfDefined; /** *机构官网的url */ private String orgUrl; /** *平台产品跳转地址 */ private String orgProductUrl; /** *平台用户中心跳转地址 */ private String orgUsercenterUrl; /** *绑定用户地址 */ private String orgBindUserUrl; /** *查帐号是否存在于第三方平台url */ private String orgUserExistUrl; /** *用户资产余额查询接口(可选) */ private String orgUserbalanceUrl; /** *资金托管 */ private String orgTrusteeship; /** *机构简介 */ private String orgProfile; /** *安全保障 */ private String orgSecurity; /** * 机构产品佣金率 */ private BigDecimal orgFeeRatio; /** * 收费类型 * 1:cpa-按投资人数量进行收费 * 2:cps-按投资金额进行收费 */ private Integer orgFeeType; /** *投资期限限制(天) */ private Integer orgInvestdeadlineLimit; /** * 产品期限 */ private String orgDeadLineValueText; /** * 团队信息 */ private List<CimOrgMemberInfo> orgTeams; //= new ArrayList<CimOrgMemberInfo>() /** * 平台下可投的产品数量 */ private Integer orgUsableProductNums; /** * pc 优质平台广告图片 */ private String orgAdvertisement; /** * pc 优质平台广告图片跳转链接 */ private String orgAdvertisementUrl; /** *是否虚拟机构/未对接机构 (1:是 ,0:否) */ private Integer orgIsstaticproduct; /** *机构亮点介绍(多个以英文逗号分隔) */ private String orgAdvantage; /** *机构标签(多个以英文逗号分隔) */ private String orgTag; /** * 产品自定义标签(多个以英文逗号分隔) */ private String orgProductTag; /** *投资攻略 */ private String orgInvestStrategy; /** * 攻略 */ private String orgPlannerStrategy; /** * 机构活动宣传图 */ private List<ActivityList> orgActivitys; /** * 平台自定义标签(多个以英文逗号分隔) */ private String orgInvestTag; /** * 平台自定义标签(多个以英文逗号分隔) */ private String orgPlannerTag; /** * 产品自定义标签(多个以英文逗号分隔) */ private String orgPlannerProductTag; /** * 对接的机构类型(0:移动+PC ,1:移动 ,2:PC ) */ private Integer orgJointType; /** * 机构灰度状态(0:否,1:是) */ private Integer orgGrayStatus; /** * 最新入驻平台图片(PC ) */ private String orgNewestImg; /** * 平台主页logo(PC ) */ private String orgPcPlatformImg; /** * 平台列表logo(PC ) */ private String orgPcPlatformListImg; /** * 平台详情图片(PC ) */ private String orgPcPlatformDetailImg; /** * 是否有红包 */ private boolean orgHashRedpacket; /** *产品被投资总额 */ private BigDecimal buyedTotalMoney; /** *产品已投资人数 */ private Integer buyedTotalPeople; private String investorProductDetailUrl; private String channelProductDetailUrl; private Integer isSalling; private String cateId; private String investorTags; private String channelTags; private double orgDiffFeeRatio; private String orgUpdater; /** *资金托管 */ private String trusteeship; /** *金额限制(元) */ private BigDecimal orgAmountLimit; /** *创建人 */ private String orgCreator; /** *机构考察报告名称(PC ) */ private String orgInvestigationReport; /** *机构考察报告下载地址(PC ) */ private String orgInvestigationReportUrl; /** *机构缴纳的保证金 */ private BigDecimal orgMargin; /** *荣誉 */ private String orgHonor; /** *债券转让(PC ) */ private String orgDebentureTransfer; /** *投标保障(PC ) */ private String orgBidSecurity; /** *保障模式(PC ) */ private String orgSecurityMode; /** *网站备案详情(PC ) */ private String orgWebsiteRecords; /** *机构联系方式详情(PC ) */ private String orgContactDetails; /** * 机构合作结束跳转地址 */ private String orgCooperationEndUrl; /*public Integer getOrgId() { return orgId; } public void setOrgId(Integer orgId) { this.orgId = orgId; }*/ public String getOrgNumber() { return orgNumber; } public void setOrgNumber(String orgNumber) { this.orgNumber = orgNumber; } public String getOrgName() { return orgName; } public void setOrgName(String orgName) { this.orgName = orgName; } public String getOrgAccount() { return orgAccount; } public void setOrgAccount(String orgAccount) { this.orgAccount = orgAccount; } public String getOrgPassword() { return orgPassword; } public void setOrgPassword(String orgPassword) { this.orgPassword = orgPassword; } public String getOrgContext() { return orgContext; } public void setOrgContext(String orgContext) { this.orgContext = orgContext; } public String getOrgCapital() { return orgCapital; } public void setOrgCapital(String orgCapital) { this.orgCapital = orgCapital; } public Date getOrgUpTime() { return orgUpTime; } public void setOrgUpTime(Date orgUpTime) { this.orgUpTime = orgUpTime; } public String getOrgCity() { return orgCity; } public void setOrgCity(String orgCity) { this.orgCity = orgCity; } public String getOrgIcpFiling() { return orgIcpFiling; } public void setOrgIcpFiling(String orgIcpFiling) { this.orgIcpFiling = orgIcpFiling; } public String getOrgRepresentative() { return orgRepresentative; } public void setOrgRepresentative(String orgRepresentative) { this.orgRepresentative = orgRepresentative; } public String getOrgContact() { return orgContact; } public void setOrgContact(String orgContact) { this.orgContact = orgContact; } public String getOrgPlatformIco() { return orgPlatformIco; } public void setOrgPlatformIco(String orgPlatformIco) { this.orgPlatformIco = orgPlatformIco; } public String getOrgPlatformlistIco() { return orgPlatformlistIco; } public void setOrgPlatformlistIco(String orgPlatformlistIco) { this.orgPlatformlistIco = orgPlatformlistIco; } public String getOrgPlatformDetailImg() { return orgPlatformDetailImg; } public void setOrgPlatformDetailImg(String orgPlatformDetailImg) { this.orgPlatformDetailImg = orgPlatformDetailImg; } public String getOrgBusinessLicense() { return orgBusinessLicense; } public void setOrgBusinessLicense(String orgBusinessLicense) { this.orgBusinessLicense = orgBusinessLicense; } public Integer getOrgRecommend() { return orgRecommend; } public void setOrgRecommend(Integer orgRecommend) { this.orgRecommend = orgRecommend; } public String getOrgGrade() { return orgGrade; } public void setOrgGrade(String orgGrade) { this.orgGrade = orgGrade; } public Integer getOrgTop() { return orgTop; } public void setOrgTop(Integer orgTop) { this.orgTop = orgTop; } public Integer getOrgHomepageSort() { return orgHomepageSort; } public void setOrgHomepageSort(Integer orgHomepageSort) { this.orgHomepageSort = orgHomepageSort; } public Integer getOrgStatus() { return orgStatus; } public void setOrgStatus(Integer orgStatus) { this.orgStatus = orgStatus; } public String getOrgRemark() { return orgRemark; } public void setOrgRemark(String orgRemark) { this.orgRemark = orgRemark; } public Date getOrgCreateTime() { return orgCreateTime; } public void setOrgCreateTime(Date orgCreateTime) { this.orgCreateTime = orgCreateTime; } public Date getOrgUpdateTime() { return orgUpdateTime; } public void setOrgUpdateTime(Date orgUpdateTime) { this.orgUpdateTime = orgUpdateTime; } public BigDecimal getOrgMinProfit() { return orgMinProfit; } public void setOrgMinProfit(BigDecimal orgMinProfit) { this.orgMinProfit = orgMinProfit; } public BigDecimal getOrgMaxProfit() { return orgMaxProfit; } public void setOrgMaxProfit(BigDecimal orgMaxProfit) { this.orgMaxProfit = orgMaxProfit; } public BigDecimal getOrgMinFeeRatio() { return orgMinFeeRatio; } public void setOrgMinFeeRatio(BigDecimal orgMinFeeRatio) { this.orgMinFeeRatio = orgMinFeeRatio; } public BigDecimal getOrgMaxFeeRatio() { return orgMaxFeeRatio; } public void setOrgMaxFeeRatio(BigDecimal orgMaxFeeRatio) { this.orgMaxFeeRatio = orgMaxFeeRatio; } public Integer getOrgMinDeadLine() { return orgMinDeadLine; } public void setOrgMinDeadLine(Integer orgMinDeadLine) { this.orgMinDeadLine = orgMinDeadLine; } public Integer getOrgMaxDeadLine() { return orgMaxDeadLine; } public void setOrgMaxDeadLine(Integer orgMaxDeadLine) { this.orgMaxDeadLine = orgMaxDeadLine; } public String getOrgDeadLineMinSelfDefined() { return orgDeadLineMinSelfDefined; } public void setOrgDeadLineMinSelfDefined(String orgDeadLineMinSelfDefined) { this.orgDeadLineMinSelfDefined = orgDeadLineMinSelfDefined; } public String getOrgDeadLineMaxSelfDefined() { return orgDeadLineMaxSelfDefined; } public void setOrgDeadLineMaxSelfDefined(String orgDeadLineMaxSelfDefined) { this.orgDeadLineMaxSelfDefined = orgDeadLineMaxSelfDefined; } public String getOrgUrl() { return orgUrl; } public void setOrgUrl(String orgUrl) { this.orgUrl = orgUrl; } public String getOrgProductUrl() { return orgProductUrl; } public void setOrgProductUrl(String orgProductUrl) { this.orgProductUrl = orgProductUrl; } public String getOrgUsercenterUrl() { return orgUsercenterUrl; } public void setOrgUsercenterUrl(String orgUsercenterUrl) { this.orgUsercenterUrl = orgUsercenterUrl; } public String getOrgBindUserUrl() { return orgBindUserUrl; } public void setOrgBindUserUrl(String orgBindUserUrl) { this.orgBindUserUrl = orgBindUserUrl; } public String getOrgUserExistUrl() { return orgUserExistUrl; } public void setOrgUserExistUrl(String orgUserExistUrl) { this.orgUserExistUrl = orgUserExistUrl; } public String getOrgUserbalanceUrl() { return orgUserbalanceUrl; } public void setOrgUserbalanceUrl(String orgUserbalanceUrl) { this.orgUserbalanceUrl = orgUserbalanceUrl; } public String getOrgTrusteeship() { return orgTrusteeship; } public void setOrgTrusteeship(String orgTrusteeship) { this.orgTrusteeship = orgTrusteeship; } public String getOrgProfile() { return orgProfile; } public void setOrgProfile(String orgProfile) { this.orgProfile = orgProfile; } public String getOrgSecurity() { return orgSecurity; } public void setOrgSecurity(String orgSecurity) { this.orgSecurity = orgSecurity; } public BigDecimal getOrgFeeRatio() { return orgFeeRatio; } public void setOrgFeeRatio(BigDecimal orgFeeRatio) { this.orgFeeRatio = orgFeeRatio; } public Integer getOrgFeeType() { return orgFeeType; } public void setOrgFeeType(Integer orgFeeType) { this.orgFeeType = orgFeeType; } public Integer getOrgInvestdeadlineLimit() { return orgInvestdeadlineLimit; } public void setOrgInvestdeadlineLimit(Integer orgInvestdeadlineLimit) { this.orgInvestdeadlineLimit = orgInvestdeadlineLimit; } public String getOrgDeadLineValueText() { return orgDeadLineValueText; } public void setOrgDeadLineValueText(String orgDeadLineValueText) { this.orgDeadLineValueText = orgDeadLineValueText; } public List<CimOrgMemberInfo> getOrgTeams() { return orgTeams; } public void setOrgTeams(List<CimOrgMemberInfo> orgTeams) { this.orgTeams = orgTeams; } public Integer getOrgUsableProductNums() { return orgUsableProductNums; } public void setOrgUsableProductNums(Integer orgUsableProductNums) { this.orgUsableProductNums = orgUsableProductNums; } public String getOrgAdvertisement() { return orgAdvertisement; } public void setOrgAdvertisement(String orgAdvertisement) { this.orgAdvertisement = orgAdvertisement; } public String getOrgAdvertisementUrl() { return orgAdvertisementUrl; } public void setOrgAdvertisementUrl(String orgAdvertisementUrl) { this.orgAdvertisementUrl = orgAdvertisementUrl; } public Integer getOrgIsstaticproduct() { return orgIsstaticproduct; } public void setOrgIsstaticproduct(Integer orgIsstaticproduct) { this.orgIsstaticproduct = orgIsstaticproduct; } public String getOrgAdvantage() { return orgAdvantage; } public void setOrgAdvantage(String orgAdvantage) { this.orgAdvantage = orgAdvantage; } public String getOrgTag() { return orgTag; } public void setOrgTag(String orgTag) { this.orgTag = orgTag; } public String getOrgProductTag() { return orgProductTag; } public void setOrgProductTag(String orgProductTag) { this.orgProductTag = orgProductTag; } public String getOrgInvestStrategy() { return orgInvestStrategy; } public void setOrgInvestStrategy(String orgInvestStrategy) { this.orgInvestStrategy = orgInvestStrategy; } public String getOrgPlannerStrategy() { return orgPlannerStrategy; } public void setOrgPlannerStrategy(String orgPlannerStrategy) { this.orgPlannerStrategy = orgPlannerStrategy; } public List<ActivityList> getOrgActivitys() { return orgActivitys; } public void setOrgActivitys(List<ActivityList> orgActivitys) { this.orgActivitys = orgActivitys; } public String getOrgInvestTag() { return orgInvestTag; } public void setOrgInvestTag(String orgInvestTag) { this.orgInvestTag = orgInvestTag; } public String getOrgPlannerTag() { return orgPlannerTag; } public void setOrgPlannerTag(String orgPlannerTag) { this.orgPlannerTag = orgPlannerTag; } public String getOrgPlannerProductTag() { return orgPlannerProductTag; } public void setOrgPlannerProductTag(String orgPlannerProductTag) { this.orgPlannerProductTag = orgPlannerProductTag; } public Integer getOrgJointType() { return orgJointType; } public void setOrgJointType(Integer orgJointType) { this.orgJointType = orgJointType; } public Integer getOrgGrayStatus() { return orgGrayStatus; } public void setOrgGrayStatus(Integer orgGrayStatus) { this.orgGrayStatus = orgGrayStatus; } public String getOrgNewestImg() { return orgNewestImg; } public void setOrgNewestImg(String orgNewestImg) { this.orgNewestImg = orgNewestImg; } public String getOrgPcPlatformImg() { return orgPcPlatformImg; } public void setOrgPcPlatformImg(String orgPcPlatformImg) { this.orgPcPlatformImg = orgPcPlatformImg; } public String getOrgPcPlatformListImg() { return orgPcPlatformListImg; } public void setOrgPcPlatformListImg(String orgPcPlatformListImg) { this.orgPcPlatformListImg = orgPcPlatformListImg; } public String getOrgPcPlatformDetailImg() { return orgPcPlatformDetailImg; } public void setOrgPcPlatformDetailImg(String orgPcPlatformDetailImg) { this.orgPcPlatformDetailImg = orgPcPlatformDetailImg; } public boolean isOrgHashRedpacket() { return orgHashRedpacket; } public void setOrgHashRedpacket(boolean orgHashRedpacket) { this.orgHashRedpacket = orgHashRedpacket; } public BigDecimal getBuyedTotalMoney() { return buyedTotalMoney; } public void setBuyedTotalMoney(BigDecimal buyedTotalMoney) { this.buyedTotalMoney = buyedTotalMoney; } public Integer getBuyedTotalPeople() { return buyedTotalPeople; } public void setBuyedTotalPeople(Integer buyedTotalPeople) { this.buyedTotalPeople = buyedTotalPeople; } public String getInvestorProductDetailUrl() { return investorProductDetailUrl; } public void setInvestorProductDetailUrl(String investorProductDetailUrl) { this.investorProductDetailUrl = investorProductDetailUrl; } public String getChannelProductDetailUrl() { return channelProductDetailUrl; } public void setChannelProductDetailUrl(String channelProductDetailUrl) { this.channelProductDetailUrl = channelProductDetailUrl; } public Integer getIsSalling() { return isSalling; } public void setIsSalling(Integer isSalling) { this.isSalling = isSalling; } public String getCateId() { return cateId; } public void setCateId(String cateId) { this.cateId = cateId; } public String getInvestorTags() { return investorTags; } public void setInvestorTags(String investorTags) { this.investorTags = investorTags; } public String getChannelTags() { return channelTags; } public void setChannelTags(String channelTags) { this.channelTags = channelTags; } public double getOrgDiffFeeRatio() { return orgDiffFeeRatio; } public void setOrgDiffFeeRatio(double orgDiffFeeRatio) { this.orgDiffFeeRatio = orgDiffFeeRatio; } public String getOrgUpdater() { return orgUpdater; } public void setOrgUpdater(String orgUpdater) { this.orgUpdater = orgUpdater; } public String getTrusteeship() { return trusteeship; } public void setTrusteeship(String trusteeship) { this.trusteeship = trusteeship; } public BigDecimal getOrgAmountLimit() { return orgAmountLimit; } public void setOrgAmountLimit(BigDecimal orgAmountLimit) { this.orgAmountLimit = orgAmountLimit; } public String getOrgCreator() { return orgCreator; } public void setOrgCreator(String orgCreator) { this.orgCreator = orgCreator; } public String getOrgInvestigationReport() { return orgInvestigationReport; } public void setOrgInvestigationReport(String orgInvestigationReport) { this.orgInvestigationReport = orgInvestigationReport; } public String getOrgInvestigationReportUrl() { return orgInvestigationReportUrl; } public void setOrgInvestigationReportUrl(String orgInvestigationReportUrl) { this.orgInvestigationReportUrl = orgInvestigationReportUrl; } public BigDecimal getOrgMargin() { return orgMargin; } public void setOrgMargin(BigDecimal orgMargin) { this.orgMargin = orgMargin; } public String getOrgHonor() { return orgHonor; } public void setOrgHonor(String orgHonor) { this.orgHonor = orgHonor; } public String getOrgDebentureTransfer() { return orgDebentureTransfer; } public void setOrgDebentureTransfer(String orgDebentureTransfer) { this.orgDebentureTransfer = orgDebentureTransfer; } public String getOrgBidSecurity() { return orgBidSecurity; } public void setOrgBidSecurity(String orgBidSecurity) { this.orgBidSecurity = orgBidSecurity; } public String getOrgSecurityMode() { return orgSecurityMode; } public void setOrgSecurityMode(String orgSecurityMode) { this.orgSecurityMode = orgSecurityMode; } public String getOrgWebsiteRecords() { return orgWebsiteRecords; } public void setOrgWebsiteRecords(String orgWebsiteRecords) { this.orgWebsiteRecords = orgWebsiteRecords; } public String getOrgContactDetails() { return orgContactDetails; } public void setOrgContactDetails(String orgContactDetails) { this.orgContactDetails = orgContactDetails; } public Integer getOrgId() { return orgId; } public void setOrgId(Integer orgId) { this.orgId = orgId; } public String getOrgCooperationEndUrl() { return orgCooperationEndUrl; } public void setOrgCooperationEndUrl(String orgCooperationEndUrl) { this.orgCooperationEndUrl = orgCooperationEndUrl; } }
elasticsearchHelper类:
package com.linkwee.xoss.helper; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Map; import javassist.expr.NewArray; import javax.annotation.Resource; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.cfg.MapperConfig; import com.fasterxml.jackson.databind.introspect.AnnotatedField; import com.fasterxml.jackson.databind.introspect.AnnotatedMethod; import com.linkwee.api.request.cim.ProductDetailRequest; import com.linkwee.api.request.cim.ProductPageListRequest; import com.linkwee.api.response.cim.ElasticsearchProductListResponse; import com.linkwee.api.response.cim.ProductPageListResponse; import com.linkwee.web.dao.CimProductMapper; import com.linkwee.web.dao.CimProductStatisticsMapper; @Component public class ElasticsearchHelper { @Resource private CimProductMapper cimProductMapper; private final static String splitStr = "_"; public ObjectMapper elasticSearchTrans() { ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(new PropertyNamingStrategy() { private static final long serialVersionUID = 1L; @Override public String nameForField(MapperConfig<?> config, AnnotatedField field, String defaultName) { return convert(defaultName); } @Override public String nameForGetterMethod(MapperConfig<?> config, AnnotatedMethod method, String defaultName) { return convert(defaultName); } @Override public String nameForSetterMethod(MapperConfig<?> config, AnnotatedMethod method, String defaultName) { String a = convert(defaultName); return a; } public String convert(String param) { if (param == null || "".equals(param.trim())) { return ""; } int len = param.length(); StringBuilder sb = new StringBuilder(len); for (int i = 0; i < len; i++) { char c = param.charAt(i); if (Character.isUpperCase(c)) { sb.append(splitStr); sb.append(Character.toLowerCase(c)); } else { sb.append(c); } } return sb.toString(); } }); return mapper; } public Map<String, Object> removeUseless(Map<String, Object> temp) { temp.remove("@version"); temp.remove("@timestamp"); temp.remove("type"); return temp; } public TransportClient getElasticSearchClient() throws UnknownHostException { Settings settings = Settings.settingsBuilder() .put("cluster.name", "my-application") .put("client.transport.sniff", true).build(); TransportClient client = TransportClient .builder() .settings(settings) .build() .addTransportAddress( new InetSocketTransportAddress(InetAddress .getByName("10.16.0.205"), 9300)); return client; } /** * 将elasticsearch对象转化成ProductPageListResponse对象 * @param productPageListRequest * @param elasticsearchProductListResponse * @return */ public ProductPageListResponse conversProductPageListResponses(ProductPageListRequest productPageListRequest,ElasticsearchProductListResponse elasticsearchProductListResponse){ ProductPageListResponse productPageListResponse = new ProductPageListResponse(); BeanUtils.copyProperties(elasticsearchProductListResponse,productPageListResponse); productPageListResponse.setProductLogo(elasticsearchProductListResponse.getOrgPlatformlistIco()); productPageListResponse.setGrade(elasticsearchProductListResponse.getOrgGrade()); if(productPageListRequest.getAppKind().equals("channel")){ productPageListResponse.setProductDetailUrl(elasticsearchProductListResponse.getChannelProductDetailUrl()); ProductDetailRequest productDetailRequest = new ProductDetailRequest(); productDetailRequest.setProductId(elasticsearchProductListResponse.getProductId()); productDetailRequest.setUserId(productPageListRequest.getUserId()); productPageListResponse.setCfpRecommend(cimProductMapper.queryRecommandTimes(productDetailRequest).toString()); }else { productPageListResponse.setProductDetailUrl(elasticsearchProductListResponse.getInvestorProductDetailUrl()); } return productPageListResponse; } }