| | |
| | |
|
| | | @Resource
|
| | | private HelpCenterService helpCenterService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private HelpClassService helpClassService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private AppVersionService appVersionService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private AdActivityVersionControlService adActivityVersionControlService;
|
| | | |
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 查询帮助列表
|
| | | * @param callback
|
| | |
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "query")
|
| | | public void query(String callback,AcceptData acceptData, Long pageId, Integer pageSize, String key, Long cid,
|
| | | public void query(String callback, AcceptData acceptData, Long pageId, Integer pageSize, String key, Long cid,
|
| | | PrintWriter out) {
|
| | | try {
|
| | | if (pageSize == null) |
| | | if (pageSize == null)
|
| | | pageSize = Constant.PAGE_SIZE;
|
| | | |
| | |
|
| | | if (cid != null && cid == 0)
|
| | | cid = null; // 查询全部
|
| | | |
| | | if (!StringUtil.isNullOrEmpty(key)) |
| | |
|
| | | if (!StringUtil.isNullOrEmpty(key))
|
| | | key = key.trim();
|
| | | |
| | |
|
| | | if (pageId == null)
|
| | | pageId = 0L;
|
| | | |
| | | List<HelpCenter> list = helpCenterService.listValid(pageId, pageSize, key, cid);
|
| | | if (list == null) {
|
| | | pageId = 0L;
|
| | | list = new ArrayList<HelpCenter>(); |
| | | } else if (list.size() == 0) {
|
| | |
|
| | | List<HelpCenter> list1 = helpCenterService.listValid(pageId, pageSize, key, cid);
|
| | | List<HelpCenter> list = new ArrayList<>();
|
| | | if (list1 != null && list1.size() > 0)
|
| | | list.addAll(list1);
|
| | |
|
| | | if (list.size() == 0) {
|
| | | pageId = 0L;
|
| | | } else {
|
| | | pageId = list.get(list.size()-1).getId();
|
| | | |
| | | pageId = list.get(list.size() - 1).getId();
|
| | |
|
| | | // 版本过滤
|
| | | int version = Integer.parseInt(acceptData.getVersion());
|
| | | String platform = acceptData.getPlatform().toLowerCase();
|
| | | List<AppVersionInfo> versionList = appVersionService.listByPlatformAndMinVersionCode(platform,version);
|
| | | List<AppVersionInfo> versionList = appVersionService.listByPlatformAndMinVersionCode(platform, version);
|
| | | if (versionList == null || versionList.size() <= 0) {
|
| | | list.clear();
|
| | | } else {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("pageId", pageId);
|
| | | data.put("result_list", JsonUtil.getApiCommonGson().toJson(list));
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 获取帮助详情
|
| | | * @param callback
|
| | |
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getInfo")
|
| | | public void getInfo(String callback, Long id, PrintWriter out){
|
| | | public void getInfo(String callback, Long id, PrintWriter out) {
|
| | | try {
|
| | | if (id == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("该内容不存在"));
|
| | |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("该内容已不存在"));
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | String html = null;
|
| | | HelpInfo helpInfo = helpCenterService.getHelpInfoCache(id);
|
| | | if (helpInfo != null) {
|
| | | html = helpInfo.getHtml();
|
| | | }
|
| | | |
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("id",crrent.getId());
|
| | | data.put("title",crrent.getTitle());
|
| | | data.put("id", crrent.getId());
|
| | | data.put("title", crrent.getTitle());
|
| | | data.put("html", html);
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
| | | } catch (Exception e) {
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 查询启用的分类
|
| | | * @param callback
|
| | |
| | | if (list == null || list.size() == 0) {
|
| | | list = new ArrayList<>();
|
| | | }
|
| | | |
| | |
|
| | | // 版本过滤
|
| | | int version = Integer.parseInt(acceptData.getVersion());
|
| | | String platform = acceptData.getPlatform().toLowerCase();
|
| | | List<AppVersionInfo> versionList = appVersionService.listByPlatformAndMinVersionCode(platform,version);
|
| | | List<AppVersionInfo> versionList = appVersionService.listByPlatformAndMinVersionCode(platform, version);
|
| | | if (versionList == null || versionList.size() <= 0) {
|
| | | list.clear();
|
| | | } else {
|
| | |
| | | versionIdList.add(versionInfo.getId());
|
| | | Set<Long> sets = adActivityVersionControlService.filterSourceIdByVersion(sourceIdList,
|
| | | AdActivityType.helpClass, versionIdList);
|
| | | |
| | |
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | if (!sets.contains(list.get(i).getId())) {
|
| | | list.remove(i--);
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | }
|
| | |
| | | import java.util.List;
|
| | | import java.util.concurrent.TimeUnit;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.apache.http.HttpHost;
|
| | | import org.elasticsearch.action.delete.DeleteRequest;
|
| | | import org.elasticsearch.action.get.GetRequest;
|
| | | import org.elasticsearch.action.get.GetResponse;
|
| | |
| | | import org.elasticsearch.action.search.SearchRequest;
|
| | | import org.elasticsearch.action.search.SearchResponse;
|
| | | import org.elasticsearch.action.update.UpdateRequest;
|
| | | //import org.elasticsearch.action.update.UpdateRequest;
|
| | | import org.elasticsearch.client.RequestOptions;
|
| | | import org.elasticsearch.client.RestClient;
|
| | | import org.elasticsearch.client.RestHighLevelClient;
|
| | | import org.elasticsearch.common.unit.TimeValue;
|
| | | import org.elasticsearch.common.xcontent.XContentType;
|
| | | import org.elasticsearch.index.query.QueryBuilders;
|
| | | import org.elasticsearch.search.SearchHit;
|
| | | import org.elasticsearch.search.SearchHits;
|
| | | import org.elasticsearch.search.builder.SearchSourceBuilder;
|
| | | import org.springframework.data.elasticsearch.annotations.Document;
|
| | | import org.springframework.stereotype.Repository;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | |
|
| | | import org.springframework.data.elasticsearch.annotations.Document;
|
| | | import com.yeshi.fanli.service.manger.ElasticManger;
|
| | |
|
| | |
|
| | |
|
| | | @Repository
|
| | | public abstract class ElasticBaseDao<T> {
|
| | | // 地址
|
| | | private static String host = "192.168.1.200";
|
| | | // 端口
|
| | | private static Integer port = 9200;
|
| | |
|
| | | @Resource |
| | | protected ElasticManger elasticManger;
|
| | |
|
| | | // 初始化api客户端
|
| | | public static RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(host, port,"http")));;
|
| | |
|
| | | /**
|
| | | * 获取index
|
| | |
| | | public String getDocument(Class<?> entityClass) {
|
| | | if (entityClass.isAnnotationPresent(Document.class)) {
|
| | | Document doc = (Document)entityClass.getAnnotation(Document.class);
|
| | | System.out.println(doc.indexName());
|
| | | return doc.indexName();
|
| | | }
|
| | | |
| | | String name = entityClass.getName();
|
| | | return name.substring(name.lastIndexOf(".") + 1, name.length());
|
| | | }
|
| | |
| | | */
|
| | | public void save(T bean) {
|
| | | String document = getDocument(bean.getClass());
|
| | | |
| | | String json = JsonUtil.getSimpleGson().toJson(bean);
|
| | | IndexRequest request = new IndexRequest(document);
|
| | | request.source(json, XContentType.JSON);
|
| | | // 同步执行
|
| | | try {
|
| | | client.index(request, RequestOptions.DEFAULT);
|
| | | elasticManger.getClient().index(request, RequestOptions.DEFAULT);
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | request.source(json, XContentType.JSON);
|
| | | // 同步执行
|
| | | try {
|
| | | client.index(request, RequestOptions.DEFAULT);
|
| | | elasticManger.getClient().index(request, RequestOptions.DEFAULT);
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | String json = new GsonBuilder().create().toJson(bean);
|
| | | request.doc(json, XContentType.JSON);
|
| | | try {
|
| | | client.update(request, RequestOptions.DEFAULT);
|
| | | elasticManger.getClient().update(request, RequestOptions.DEFAULT);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | String document = getDocument(entityClass);
|
| | | DeleteRequest request = new DeleteRequest(document, id);
|
| | | try {
|
| | | client.delete(request, RequestOptions.DEFAULT);
|
| | | elasticManger.getClient().delete(request, RequestOptions.DEFAULT);
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | String document = getDocument(entityClass);
|
| | | GetRequest request = new GetRequest(document, id);
|
| | | try {
|
| | | GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
|
| | | GetResponse getResponse = elasticManger.getClient().get(request, RequestOptions.DEFAULT);
|
| | | if (getResponse.isExists()) {
|
| | | String content = getResponse.getSourceAsString();
|
| | | return new Gson().fromJson(content, entityClass);
|
| | |
| | | searchRequest.indices(index);
|
| | | searchRequest.source(sourceBuilder);
|
| | | try {
|
| | | SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
| | | SearchResponse searchResponse = elasticManger.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
| | | SearchHits hits = searchResponse.getHits();
|
| | | SearchHit[] searchHits = hits.getHits();
|
| | |
|
| | |
| | | import java.io.IOException;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | | import java.util.concurrent.TimeUnit;
|
| | |
|
| | | import org.elasticsearch.action.search.SearchRequest;
|
| | | import org.elasticsearch.action.search.SearchResponse;
|
| | | import org.elasticsearch.client.RequestOptions;
|
| | | import org.elasticsearch.common.unit.Fuzziness;
|
| | | import org.elasticsearch.common.unit.TimeValue;
|
| | | import org.elasticsearch.index.query.BoolQueryBuilder;
|
| | | import org.elasticsearch.index.query.MatchQueryBuilder;
|
| | | import org.elasticsearch.index.query.QueryBuilders;
|
| | | import org.elasticsearch.index.query.TermQueryBuilder;
|
| | | import org.elasticsearch.search.SearchHit;
|
| | | import org.elasticsearch.search.SearchHits;
|
| | | import org.elasticsearch.search.builder.SearchSourceBuilder;
|
| | |
| | | */
|
| | | public List<ESOrder> query(String key, String uid, List<Integer> listPlatform) {
|
| | | List<ESOrder> list = new ArrayList<ESOrder>();
|
| | | // 商品名称匹配
|
| | | BoolQueryBuilder should1 = QueryBuilders.boolQuery().should(QueryBuilders.matchPhraseQuery("orderNo", key))
|
| | | .should(QueryBuilders.matchPhraseQuery("goodsName", key));
|
| | | // 商品名称模糊全词匹配
|
| | | BoolQueryBuilder should1 = QueryBuilders.boolQuery().should(QueryBuilders.wildcardQuery("orderNo.keyword", "*" + key + "*"))
|
| | | .should(QueryBuilders.wildcardQuery("goodsName.keyword", "*" + key + "*"));
|
| | | // 用户id匹配
|
| | | BoolQueryBuilder should2 = QueryBuilders.boolQuery().should(QueryBuilders.termQuery("uid", uid))
|
| | | .should(QueryBuilders.termQuery("uidDirect", uid)).should(QueryBuilders.termQuery("uidDirect", uid));
|
| | | .should(QueryBuilders.termQuery("uidDirect", uid)).should(QueryBuilders.termQuery("uidIndirect", uid));
|
| | |
|
| | | // 查询创建
|
| | | SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
|
| | |
| | | }
|
| | | sourceBuilder.query(QueryBuilders.boolQuery().must(should1).must(should2).must(should3));
|
| | | }
|
| | | |
| | | //最大查询数为200
|
| | | sourceBuilder.size(200);
|
| | | //超时20s
|
| | | sourceBuilder.timeout(new TimeValue(20, TimeUnit.SECONDS));
|
| | | SearchRequest searchRequest = new SearchRequest();
|
| | | searchRequest.indices(getDocument(ESOrder.class));
|
| | | searchRequest.source(sourceBuilder);
|
| | | try {
|
| | | SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
| | | SearchResponse searchResponse = elasticManger.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
| | | SearchHits hits = searchResponse.getHits();
|
| | | SearchHit[] searchHits = hits.getHits();
|
| | | Gson gson = new Gson();
|
| | |
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | |
| | | }
|
New file |
| | |
| | | package com.yeshi.fanli.dao.mybatis.order;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | import org.apache.ibatis.annotations.Param;
|
| | |
|
| | | import com.yeshi.fanli.entity.order.ESOrder;
|
| | |
|
| | | public interface OrderSearchIndexMapper {
|
| | |
|
| | | /**
|
| | | * |
| | | * @Title: listByHBIds
|
| | | * @Description: 根据主hongbaoId检索
|
| | | * @param hbIdList
|
| | | * @return |
| | | * List<ESOrder> 返回类型
|
| | | * @throws
|
| | | */
|
| | | List<ESOrder> listByHBIds(@Param("hbIdList") List<Long> hbIdList);
|
| | |
|
| | | /**
|
| | | * |
| | | * @Title: listHBId
|
| | | * @Description: 检索需要新增的hongBaoId
|
| | | * @param start
|
| | | * @param count
|
| | | * @return |
| | | * List<Long> 返回类型
|
| | | * @throws
|
| | | */
|
| | | List<Long> listHBId(@Param("start") long start, @Param("count") int count);
|
| | |
|
| | | /**
|
| | | * 根据hongBaoId删除
|
| | | * @Title: deleteByHBIds
|
| | | * @Description: |
| | | * @param hbIdList
|
| | | * @return |
| | | * int 返回类型
|
| | | * @throws
|
| | | */
|
| | | int deleteByHBIds(@Param("hbIdList") List<Long> hbIdList);
|
| | |
|
| | | } |
New file |
| | |
| | | package com.yeshi.fanli.job;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.yeshi.utils.StringUtil;
|
| | |
|
| | | import com.xxl.job.core.biz.model.ReturnT;
|
| | | import com.xxl.job.core.handler.annotation.XxlJob;
|
| | | import com.yeshi.fanli.service.inter.order.ESOrderService;
|
| | |
|
| | | /**
|
| | | * 搜索引擎任务
|
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | | @Component
|
| | | public class ElasticSearchJob {
|
| | |
|
| | | @Resource
|
| | | private ESOrderService esOrderService;
|
| | |
|
| | | /**
|
| | | * 每两个小时进行更新品牌商品信息
|
| | | */
|
| | | @XxlJob("orderSearchIndexAddHandler")
|
| | | public ReturnT<String> orderSearchIndexAddHandler(String param) throws Exception {
|
| | | Integer count = null;
|
| | | if (!StringUtil.isNullOrEmpty(param))
|
| | | count = Integer.parseInt(param);
|
| | | addIndex(count);
|
| | | return ReturnT.SUCCESS;
|
| | | }
|
| | |
|
| | | public void addIndex(Integer count) {
|
| | | if (count == null)
|
| | | count = 200;
|
| | | esOrderService.syncAddOrder(count);
|
| | | }
|
| | |
|
| | | }
|
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?>
|
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | |
|
| | |
|
| | | <mapper namespace="com.yeshi.fanli.dao.mybatis.order.OrderSearchIndexMapper">
|
| | |
|
| | | <resultMap id="BASERESULTMAP" type="com.yeshi.fanli.entity.order.ESOrder">
|
| | | <result column="uid" property="uid" jdbcType="BIGINT" />
|
| | | <result column="uidDirect" property="uidDirect" jdbcType="BIGINT" />
|
| | | <result column="uidIndirect" property="uidIndirect" jdbcType="BIGINT" />
|
| | | <result column="goodsName" property="goodsName" jdbcType="VARCHAR" />
|
| | | <result column="orderNo" property="orderNo" jdbcType="VARCHAR" />
|
| | | <result column="tradeId" property="tradeId" jdbcType="VARCHAR" />
|
| | | <result column="platform" property="platform" jdbcType="INTEGER" />
|
| | | </resultMap>
|
| | |
|
| | | <select id="listByHBIds" resultMap="BASERESULTMAP">
|
| | |
|
| | | SELECT CONCAT(a.platform,'#',a.tradeId) AS id,a.uid,v.`hb_uid` AS
|
| | | uidDirect,vv.`hb_uid` AS
|
| | | uidIndirect,a.goodsName,a.orderNo,a.tradeId,a.platform FROM (
|
| | |
|
| | | SELECT
|
| | | v.`hb_id`,co.`co_uid` AS uid,g.`cog_title` AS
|
| | | goodsName,CO.`co_order_no` AS orderNo,co.`co_trade_id` AS
|
| | | tradeId,co.`co_source_type` AS platform FROM yeshi_ec_common_order co
|
| | |
|
| | | LEFT JOIN yeshi_ec_hongbao_order ho ON ho.`ho_order_id`=co.`co_id`
|
| | |
|
| | | LEFT JOIN yeshi_ec_hongbao_v2 v ON v.`hb_id`=ho.`ho_hongbao_id`
|
| | |
|
| | | LEFT
|
| | | JOIN yeshi_ec_common_order_goods g ON
|
| | | g.`cog_id`=co.`co_order_goods_id`
|
| | |
|
| | | <foreach collection="hbIdList" item="hbId" open=" WHERE ("
|
| | | separator=" or " close=")">
|
| | | v.hb_id=#{hbId}
|
| | | </foreach>
|
| | |
|
| | | ) a
|
| | |
|
| | | LEFT JOIN yeshi_ec_hongbao_v2 v ON v.hb_pid=a.hb_id AND
|
| | | (v.`hb_type`=6 OR
|
| | | v.`hb_type`=21)
|
| | |
|
| | | LEFT JOIN yeshi_ec_hongbao_v2 vv ON
|
| | | vv.hb_pid=a.hb_id AND (vv.`hb_type`=7
|
| | | OR vv.`hb_type`=22)
|
| | |
|
| | | </select>
|
| | |
|
| | | <select id="listHBId" resultType="java.lang.Long">
|
| | |
|
| | | select id from
|
| | | yeshi_ec_common_order_change_trigger limit #{start},#{count}
|
| | |
|
| | | </select>
|
| | |
|
| | |
|
| | | <delete id="deleteByHBIds">
|
| | | delete from yeshi_ec_common_order_change_trigger
|
| | | <foreach collection="hbIdList" open=" where (" separator=" or "
|
| | | item="hbId" close=")">
|
| | | id=#{hbId}
|
| | | </foreach>
|
| | | </delete>
|
| | |
|
| | |
|
| | |
|
| | | </mapper>
|
| | |
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.yeshi.fanli.dao.elastic.ESOrderDao;
|
| | | import com.yeshi.fanli.dao.mybatis.order.OrderSearchIndexMapper;
|
| | | import com.yeshi.fanli.entity.order.ESOrder;
|
| | | import com.yeshi.fanli.service.inter.order.ESOrderService;
|
| | |
|
| | |
| | | public class ESOrderServiceImpl implements ESOrderService {
|
| | |
|
| | | @Resource
|
| | | private ESOrderDao esOrderDao;
|
| | | private OrderSearchIndexMapper orderSearchIndexMapper;
|
| | |
|
| | | @Resource
|
| | | private ESOrderDao esOrderDao;
|
| | |
|
| | | @Override
|
| | | public void add(ESOrder record) {
|
| | | esOrderDao.save(record, record.getPlatform() + "#" + record.getTradeId());
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public List<ESOrder> query(String key, String uid, List<Integer> listPlatform) {
|
| | | return esOrderDao.query(key, uid, listPlatform);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void syncAddOrder(int count) {
|
| | | List<Long> hbIdList = orderSearchIndexMapper.listHBId(0, count);
|
| | | if (hbIdList == null || hbIdList.size() == 0)
|
| | | return;
|
| | | List<ESOrder> list = orderSearchIndexMapper.listByHBIds(hbIdList);
|
| | | if (list != null)
|
| | | for (ESOrder order : list) {
|
| | | add(order);
|
| | | }
|
| | | orderSearchIndexMapper.deleteByHBIds(hbIdList);
|
| | | }
|
| | | }
|
| | |
| | | * @return
|
| | | */
|
| | | List<ESOrder> query(String key, String uid, List<Integer> listPlatform);
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * @Title: syncAddOrder
|
| | | * @Description: 同步新增加的订单
|
| | | * @param count |
| | | * void 返回类型
|
| | | * @throws
|
| | | */
|
| | | void syncAddOrder(int count);
|
| | |
|
| | | }
|
New file |
| | |
| | | package com.yeshi.fanli.service.manger;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.apache.http.Header;
|
| | | import org.apache.http.HeaderElement;
|
| | | import org.apache.http.HttpHost;
|
| | | import org.apache.http.ParseException;
|
| | | import org.apache.http.auth.AuthScope;
|
| | | import org.apache.http.auth.UsernamePasswordCredentials;
|
| | | import org.apache.http.client.CredentialsProvider;
|
| | | import org.apache.http.impl.client.BasicCredentialsProvider;
|
| | | import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
|
| | | import org.elasticsearch.client.RestClient;
|
| | | import org.elasticsearch.client.RestClientBuilder;
|
| | | import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;
|
| | | import org.elasticsearch.client.RestHighLevelClient;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | @Component
|
| | | public class ElasticManger {
|
| | |
|
| | | @Resource(name = "httpHostbean")
|
| | | private HttpHost httpHost;
|
| | |
|
| | | // 初始化api客户端
|
| | | public static RestHighLevelClient client = null;
|
| | |
|
| | | public RestHighLevelClient getClient() {
|
| | | if (client == null) {
|
| | | final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
| | | credentialsProvider.setCredentials(AuthScope.ANY,
|
| | | new UsernamePasswordCredentials("elastic", "banliapp2019"));
|
| | |
|
| | | RestClientBuilder builder = RestClient.builder(httpHost)
|
| | | .setHttpClientConfigCallback(new HttpClientConfigCallback() {
|
| | | @Override
|
| | | public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
|
| | | return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
|
| | | }
|
| | | });
|
| | |
|
| | | Header hear[] = new Header[] { new Header() {
|
| | |
|
| | | @Override
|
| | | public String getValue() {
|
| | | return "application/json; charset=UTF-8";
|
| | | }
|
| | | |
| | | @Override
|
| | | public String getName() {
|
| | | return "Content-Type";
|
| | | }
|
| | | |
| | | @Override
|
| | | public HeaderElement[] getElements() throws ParseException {
|
| | | return null;
|
| | | }
|
| | | }, new Header() {
|
| | | |
| | | @Override
|
| | | public String getValue() {
|
| | | return "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7";
|
| | | }
|
| | | |
| | | @Override
|
| | | public String getName() {
|
| | | return "Accept-Language";
|
| | | }
|
| | | |
| | | @Override
|
| | | public HeaderElement[] getElements() throws ParseException {
|
| | | return null;
|
| | | }
|
| | | },
|
| | |
|
| | | };
|
| | | builder.setDefaultHeaders(hear);
|
| | | client = new RestHighLevelClient(builder);
|
| | | }
|
| | | return client;
|
| | | }
|
| | | }
|
New file |
| | |
| | | elastic.scheme=http
|
| | | elastic.port=9200
|
| | | elastic.host=172.16.16.3 |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?>
|
| | | <beans xmlns="http://www.springframework.org/schema/beans"
|
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xmlns:context="http://www.springframework.org/schema/context"
|
| | | xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
| | | |
| | | <bean name="inetAddressbean" class="java.net.InetAddress"></bean> |
| | | <bean name="httpHostbean" class="org.apache.http.HttpHost">
|
| | | <constructor-arg ref="inetAddressbean"></constructor-arg>
|
| | | <constructor-arg value="${elastic.host}" ></constructor-arg>
|
| | | <constructor-arg value="${elastic.port}"></constructor-arg>
|
| | | <constructor-arg value="${elastic.scheme}"></constructor-arg> |
| | | </bean> |
| | | </beans> |
| | |
| | | <value>classpath:mongo.properties</value>
|
| | | <value>classpath:rocketmq.properties</value>
|
| | | <value>classpath:xxl-job-executor.properties</value>
|
| | | <value>classpath:elasticsearch.properties</value>
|
| | | </array>
|
| | | </property>
|
| | | </bean>
|
| | |
|
| | | <import resource="classpath:rocketmq.xml" />
|
| | | <import resource="classpath:xxl-job.xml" />
|
| | | <import resource="classpath:elasticsearch.xml" />
|
| | | |
| | | |
| | |
|
| | |
|
| | |
|