|
|
@@ -1,396 +0,0 @@
|
|
|
-//package com.ruoyi.interfaces.controller;
|
|
|
-//
|
|
|
-//import cn.com.goldenwater.app.gx.utils.JsonMapper;
|
|
|
-//import cn.com.goldenwater.app.gx.utils.LoggerUtils;
|
|
|
-//import com.ruoyi.interfaces.mapper.SysSearchMapper;
|
|
|
-//import com.ruoyi.interfaces.domain.SysSearch;
|
|
|
-//import cn.com.goldenwater.cmp.search.utils.ElasticSearchUtils;
|
|
|
-//import com.ruoyi.interfaces.core.page.Page;
|
|
|
-//import com.ruoyi.interfaces.core.page.PageUtils;
|
|
|
-//import com.ruoyi.common.core.controller.BaseController;
|
|
|
-//import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
-//import com.ruoyi.common.utils.uuid.IdUtils;
|
|
|
-//import com.github.pagehelper.PageHelper;
|
|
|
-//import com.github.pagehelper.PageInfo;
|
|
|
-//import io.swagger.annotations.Api;
|
|
|
-//import io.swagger.annotations.ApiOperation;
|
|
|
-//import org.apache.commons.lang3.StringUtils;
|
|
|
-//import org.apache.http.HttpResponse;
|
|
|
-//import org.apache.http.client.methods.HttpGet;
|
|
|
-//import org.apache.http.client.methods.HttpRequestBase;
|
|
|
-//import org.apache.http.client.protocol.HttpClientContext;
|
|
|
-//import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
-//import org.apache.http.params.CoreConnectionPNames;
|
|
|
-//import org.apache.http.util.EntityUtils;
|
|
|
-//import org.elasticsearch.ElasticsearchException;
|
|
|
-//import org.elasticsearch.action.DocWriteResponse;
|
|
|
-//import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
|
|
-//import org.elasticsearch.action.index.IndexResponse;
|
|
|
-//import org.elasticsearch.client.RestHighLevelClient;
|
|
|
-//import org.elasticsearch.rest.RestStatus;
|
|
|
-//import org.slf4j.Logger;
|
|
|
-//import org.slf4j.LoggerFactory;
|
|
|
-//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-//import org.springframework.beans.factory.annotation.Value;
|
|
|
-//import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-//import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-//import org.springframework.web.bind.annotation.RestController;
|
|
|
-//import org.springframework.web.servlet.ModelAndView;
|
|
|
-//
|
|
|
-//import javax.servlet.ServletOutputStream;
|
|
|
-//import javax.servlet.http.HttpServletRequest;
|
|
|
-//import javax.servlet.http.HttpServletResponse;
|
|
|
-//import java.io.IOException;
|
|
|
-//import java.io.InputStream;
|
|
|
-//import java.io.UnsupportedEncodingException;
|
|
|
-//import java.net.HttpURLConnection;
|
|
|
-//import java.net.MalformedURLException;
|
|
|
-//import java.net.URL;
|
|
|
-//import java.util.Enumeration;
|
|
|
-//import java.util.HashMap;
|
|
|
-//import java.util.List;
|
|
|
-//import java.util.Map;
|
|
|
-//
|
|
|
-//@RestController
|
|
|
-//@RequestMapping("/sys/search")
|
|
|
-//public class SysSearchController extends BaseController {
|
|
|
-// private static Logger logger = LoggerFactory.getLogger(SysSearchController.class);
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private SysSearchMapper sysSearchMapper;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private RestHighLevelClient client;
|
|
|
-//
|
|
|
-// @Value("${httpHost.host}")
|
|
|
-// private String host;
|
|
|
-//
|
|
|
-// @Value("${httpHost.port}")
|
|
|
-// private String port;
|
|
|
-//
|
|
|
-// @ApiOperation("添加索引")
|
|
|
-// @RequestMapping(value = "/add")
|
|
|
-// public AjaxResult add(SysSearch fullIndex) {
|
|
|
-// fullIndex.setId(IdUtils.simpleUUID());
|
|
|
-// return sysSearchMapper.insert(fullIndex) > 0 ? AjaxResult.success() : AjaxResult.error();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("删除索引")
|
|
|
-// @RequestMapping("/del")
|
|
|
-// public AjaxResult del(String ids) throws Exception {
|
|
|
-// String[] strs = ids.split(",");
|
|
|
-// int delete = 0;
|
|
|
-// for (String str : strs) {
|
|
|
-// SysSearch sysSearch = sysSearchMapper.selectByPrimaryKey(str);
|
|
|
-// if ("1".equals(sysSearch.getFlag())) {
|
|
|
-// ElasticSearchUtils.delIndex(client, sysSearch.getTitle());
|
|
|
-// }
|
|
|
-// delete += sysSearchMapper.deleteByPrimaryKey(str);
|
|
|
-// }
|
|
|
-// return delete == strs.length ? AjaxResult.success() : AjaxResult.error();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("修改索引")
|
|
|
-// @RequestMapping("/update")
|
|
|
-// public AjaxResult update(SysSearch fullIndex) {
|
|
|
-// /*RestHighLevelClient client, String index, String type, String id, String content*/
|
|
|
-// if ("1".equals(sysSearchMapper.selectByPrimaryKey(fullIndex.getId()).getFlag())) {
|
|
|
-// // ElasticSearchUtils.updateDocument(client , fullIndex.getName() ,"",fullIndex.getId(), fullIndex.getProp());
|
|
|
-// }
|
|
|
-// return sysSearchMapper.updateByPrimaryKeyWithBLOBs(fullIndex) > 0 ? AjaxResult.success() : AjaxResult.error();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("查询所有")
|
|
|
-// @RequestMapping("/list")
|
|
|
-// public Page list(int page, int rows, SysSearch fullIndex) {
|
|
|
-// PageHelper.startPage(page, rows);
|
|
|
-// List<SysSearch> list = sysSearchMapper.selectAll(fullIndex);
|
|
|
-// PageInfo<SysSearch> pageInfo = new PageInfo<SysSearch>(list);
|
|
|
-// return PageUtils.convert(pageInfo);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("去编辑页面")
|
|
|
-// @RequestMapping("/to_edit")
|
|
|
-// public ModelAndView toEdit(String id) {
|
|
|
-// ModelAndView modelAndView = new ModelAndView();
|
|
|
-// modelAndView.addObject("fullIndex", sysSearchMapper.selectByPrimaryKey(id));
|
|
|
-// modelAndView.setViewName("mng/sys_search_edit");
|
|
|
-// return modelAndView;
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("同步")
|
|
|
-// @RequestMapping("/sync")
|
|
|
-// public AjaxResult sync(SysSearch sysSearch) throws Exception {
|
|
|
-// sysSearch.setFlag("1");
|
|
|
-// sysSearch = sysSearchMapper.selectByPrimaryKey(sysSearch.getId());
|
|
|
-// AjaxResult AjaxResult = syncConnetion(sysSearch.getTitle(), sysSearch.getAliases(), sysSearch.getType(), sysSearch.getProp());
|
|
|
-// if (AjaxResult != null && AjaxResult.isSuccess()) {
|
|
|
-// sysSearch.setFlag("1");
|
|
|
-// return sysSearchMapper.updateFlag(sysSearch) > 0 ? AjaxResult.success() : AjaxResult.error();
|
|
|
-// }
|
|
|
-// return AjaxResult;
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 同步连接
|
|
|
-// *
|
|
|
-// * @param
|
|
|
-// */
|
|
|
-// public AjaxResult syncConnetion(@RequestParam(required = true) String index,
|
|
|
-// @RequestParam(required = false) String alias,
|
|
|
-// @RequestParam(required = false) String type,
|
|
|
-// @RequestParam(required = true) String source) throws Exception {
|
|
|
-// //判断网络连接状态
|
|
|
-// boolean flag = client.ping();
|
|
|
-// if (!flag) {
|
|
|
-// return AjaxResult.error("网络连接错误!");
|
|
|
-// } else {
|
|
|
-// //操作
|
|
|
-// //1、判断别名存不存在,如果不存在,则将索引名称与别名一致
|
|
|
-// if (StringUtils.isBlank(alias)) {
|
|
|
-// alias = index;
|
|
|
-// }
|
|
|
-// if (StringUtils.isBlank(type)) {
|
|
|
-// type = index;
|
|
|
-// }
|
|
|
-// //2、判断索引是否存在
|
|
|
-// try {
|
|
|
-// CreateIndexResponse response = ElasticSearchUtils.addIndex(client, index, alias, type, source);
|
|
|
-// if (response.isAcknowledged()) {////指示是否所有节点都已确认请求
|
|
|
-// return AjaxResult.success();
|
|
|
-// } else {
|
|
|
-// return AjaxResult.success("此索引已创建,但有节点未确认!");
|
|
|
-// }
|
|
|
-// //}
|
|
|
-// } catch (ElasticsearchException e) {
|
|
|
-// //在此处调用
|
|
|
-// logger.error(e.getLocalizedMessage(), e);
|
|
|
-// if (e.status() == RestStatus.FOUND) {
|
|
|
-// //如果没有找到要删除的索引,要执行某些操作
|
|
|
-// return AjaxResult.error("此索引已创建!");
|
|
|
-// } else {
|
|
|
-// return AjaxResult.error(e);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("查看索引详情")
|
|
|
-// @RequestMapping(value = "/selects")
|
|
|
-// public ModelAndView selects(String id) throws Exception {
|
|
|
-// ModelAndView modelAndView = new ModelAndView();
|
|
|
-// SysSearch sysSearch = sysSearchMapper.selectByPrimaryKey(id);
|
|
|
-// String url = "http://" + host + ":" + port + "/" + sysSearch.getTitle();
|
|
|
-// modelAndView.addObject("searchMess", connectServlet(url));
|
|
|
-// modelAndView.setViewName("mng/sys_search_xq");
|
|
|
-// return modelAndView;
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 获取访问的内容
|
|
|
-// *
|
|
|
-// * @return
|
|
|
-// */
|
|
|
-// public String connectServlet(String u) throws Exception {
|
|
|
-// String result = null;
|
|
|
-// try {
|
|
|
-// InputStream is = httpRequestToStream(u);
|
|
|
-// byte[] b = new byte[is.available()];
|
|
|
-// is.read(b);
|
|
|
-// result = new String(b);
|
|
|
-// } catch (IOException e) {
|
|
|
-// //在此处调用
|
|
|
-// logger.error(e.getLocalizedMessage(), e);
|
|
|
-// }
|
|
|
-// return result;
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * <pre>
|
|
|
-// * 方法体说明:向远程接口发起请求,返回字节流类型结果
|
|
|
-// * 作者:itar
|
|
|
-// * 日期:2015年3月17日 上午11:20:25
|
|
|
-// * @param url 接口地址
|
|
|
-// * @return InputStream 返回结果
|
|
|
-// * </pre>
|
|
|
-// */
|
|
|
-// public static InputStream httpRequestToStream(String url) {
|
|
|
-//
|
|
|
-// InputStream is = null;
|
|
|
-// try {
|
|
|
-// String parameters = "";
|
|
|
-// boolean hasParams = false;
|
|
|
-//
|
|
|
-// if (hasParams) {
|
|
|
-// parameters = parameters.substring(0, parameters.length() - 1);
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// URL u = new URL(url);
|
|
|
-// HttpURLConnection conn = (HttpURLConnection) u.openConnection();
|
|
|
-//
|
|
|
-// //请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Content-Type为“”空)
|
|
|
-// conn.setRequestProperty("Content-Type", "application/octet-stream");
|
|
|
-// //conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
|
|
-// //设置连接超时时间
|
|
|
-// conn.setConnectTimeout(50000);
|
|
|
-// //设置读取返回内容超时时间
|
|
|
-// conn.setReadTimeout(50000);
|
|
|
-// //设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认false
|
|
|
-//
|
|
|
-// //设置从HttpURLConnection对象读入,默认为true
|
|
|
-// conn.setDoInput(true);
|
|
|
-// //设置是否使用缓存,post方式不能使用缓存
|
|
|
-//
|
|
|
-// //设置请求方式,默认为GET
|
|
|
-// conn.setRequestMethod("GET");
|
|
|
-//
|
|
|
-// //post方式需要将传递的参数输出到conn对象中
|
|
|
-//
|
|
|
-// //从HttpURLConnection对象中读取响应的消息
|
|
|
-// //执行该语句时才正式发起请求
|
|
|
-// is = conn.getInputStream();
|
|
|
-// } catch (UnsupportedEncodingException e) {
|
|
|
-// //在此处调用
|
|
|
-// logger.error(e.getLocalizedMessage(), e);
|
|
|
-// } catch (MalformedURLException e) {
|
|
|
-// //在此处调用
|
|
|
-// logger.error(e.getLocalizedMessage(), e);
|
|
|
-// } catch (IOException e) {
|
|
|
-// //在此处调用
|
|
|
-// logger.error(e.getLocalizedMessage(), e);
|
|
|
-// }
|
|
|
-// return is;
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// @ApiOperation("/删除search中的某个索引")
|
|
|
-// @RequestMapping(value = "/del_search")
|
|
|
-// public AjaxResult delSearch(String index) throws Exception {
|
|
|
-// return ElasticSearchUtils.delIndex(client, index) ? AjaxResult.success() : AjaxResult.error();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("/去添加文档界面")
|
|
|
-// @RequestMapping(value = "/to_add_dox")
|
|
|
-// public ModelAndView toAddDox(String id) {
|
|
|
-// ModelAndView modelAndView = new ModelAndView();
|
|
|
-// SysSearch sysSearch = sysSearchMapper.selectByPrimaryKey(id);
|
|
|
-// modelAndView.addObject("sysSearch", sysSearch);
|
|
|
-// modelAndView.setViewName("mng/sys_search_doc");
|
|
|
-// return modelAndView;
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("/添加文档")
|
|
|
-// @RequestMapping(value = "/add_dox")
|
|
|
-// public AjaxResult addDox(String index, HttpServletRequest request) {
|
|
|
-// Enumeration<String> enumeration = request.getParameterNames();
|
|
|
-// Map map = new HashMap();
|
|
|
-// while (enumeration.hasMoreElements()) {
|
|
|
-// String key = (String) enumeration.nextElement();
|
|
|
-// String value = request.getParameter(key);
|
|
|
-// map.put(key, value);
|
|
|
-// }
|
|
|
-// try {
|
|
|
-//
|
|
|
-// // Map data = new HashMap();
|
|
|
-// // data.put("id",IdUtils.simpleUUID());
|
|
|
-// // data.put("author","lpj");
|
|
|
-// // data.put("publish_date","2018-08-29");
|
|
|
-//
|
|
|
-// // IndexResponse indexResponse = ElasticSearchUtils.addDocument(client ,index,"test", data );
|
|
|
-//
|
|
|
-// IndexResponse indexResponse = ElasticSearchUtils.addDocument(client, index, (String) map.get("type"), map);
|
|
|
-//
|
|
|
-// if (indexResponse.getResult() == DocWriteResponse.Result.CREATED) {
|
|
|
-// return AjaxResult.success();
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// //在此处调用
|
|
|
-// logger.error(e.getLocalizedMessage(), e);
|
|
|
-// }
|
|
|
-//
|
|
|
-// return AjaxResult.error();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("删除文档")
|
|
|
-// @RequestMapping(value = "/del_doc")
|
|
|
-// public AjaxResult delDoc(String index, String id, String type) {
|
|
|
-// try {
|
|
|
-// ElasticSearchUtils.delDocument(client, index, type, IdUtils.simpleUUID());
|
|
|
-// return AjaxResult.success();
|
|
|
-// } catch (Exception e) {
|
|
|
-// //在此处调用
|
|
|
-// logger.error(e.getLocalizedMessage(), e);
|
|
|
-// }
|
|
|
-//
|
|
|
-// return AjaxResult.error();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("/修改文档")
|
|
|
-// @RequestMapping(value = "/update_doc")
|
|
|
-// public AjaxResult updateDoc(String index, String type, String id, String content) {
|
|
|
-// try {
|
|
|
-// ElasticSearchUtils.updateDocument(client, index, type, id, content);
|
|
|
-// return AjaxResult.success();
|
|
|
-// } catch (Exception e) {
|
|
|
-// //在此处调用
|
|
|
-// logger.error(e.getLocalizedMessage(), e);
|
|
|
-// }
|
|
|
-// return AjaxResult.error();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("搜索")
|
|
|
-// @RequestMapping(value = "/search")
|
|
|
-// public void search(String content, HttpServletResponse response) throws Exception {
|
|
|
-// String url = "http://" + host + ":" + port + "/test/_search?q=" + content.replace(" ", "");
|
|
|
-// ServletOutputStream out = response.getOutputStream();
|
|
|
-// out.write(httpRequestToString(url).getBytes("utf-8"));
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * <pre>
|
|
|
-// * 方法体说明:向远程接口发起请求,返回字符串类型结果
|
|
|
-// * @param url 接口地址
|
|
|
-// * @return String 返回结果
|
|
|
-// * </pre>
|
|
|
-// */
|
|
|
-// public static String httpRequestToString(String url) {
|
|
|
-// //接口返回结果
|
|
|
-// String methodResult = null;
|
|
|
-// try {
|
|
|
-// String parameters = "";
|
|
|
-// boolean hasParams = false;
|
|
|
-//
|
|
|
-// if (hasParams) {
|
|
|
-// parameters = parameters.substring(0, parameters.length() - 1);
|
|
|
-// }
|
|
|
-//
|
|
|
-// //创建HttpClient连接对象
|
|
|
-// DefaultHttpClient client = new DefaultHttpClient();
|
|
|
-// HttpRequestBase method = null;
|
|
|
-// method = new HttpGet(url);
|
|
|
-// method.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 6000);
|
|
|
-// //设置参数内容类型
|
|
|
-// method.addHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
-// //httpClient本地上下文
|
|
|
-// HttpClientContext context = null;
|
|
|
-//
|
|
|
-// //访问接口,返回状态码
|
|
|
-// HttpResponse response = client.execute(method, context);
|
|
|
-// //返回状态码200,则访问接口成功
|
|
|
-// if (response.getStatusLine().getStatusCode() == 200) {
|
|
|
-// methodResult = EntityUtils.toString(response.getEntity());
|
|
|
-// }
|
|
|
-// client.close();
|
|
|
-// } catch (UnsupportedEncodingException e) {
|
|
|
-// //在此处调用
|
|
|
-// logger.error(e.getLocalizedMessage(), e);
|
|
|
-// } catch (IOException e) {
|
|
|
-// //在此处调用
|
|
|
-// logger.error(e.getLocalizedMessage(), e);
|
|
|
-// }
|
|
|
-// return methodResult;
|
|
|
-// }
|
|
|
-//
|
|
|
-//}
|