提交 8c685274 编写于 作者: S sunxiwang

添加会话存档全局查询接口

上级 03b4ef8f
......@@ -53,4 +53,16 @@ public class WeConversationArchiveController extends BaseController {
}
/**
* 获取全局会话数据接口
*
* @param query 入参
* @return
*/
@PreAuthorize("@ss.hasPermi('conversationArchive:chatAllContact:list')")
@GetMapping("/getChatAllList")
public TableDataInfo getChatAllList(ConversationArchiveQuery query) {
return getDataTable(weConversationArchiveService.getChatAllList(query));
}
}
package com.linkwechat.common.core.domain;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
/**
......@@ -13,12 +12,21 @@ public class ConversationArchiveQuery extends BaseEntity {
/** 发送人Id */
private String fromId;
/** 成员名称 */
private String userName;
/** 接收人Id */
private String receiveId;
/** 客户姓名 */
private String customerName;
/** 群聊Id */
private String roomId;
/** 类型 */
private String msgType;
/** 关键词 **/
private String keyWord;
}
package com.linkwechat.common.core.elasticsearch;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linkwechat.common.core.domain.elastic.ElasticSearchEntity;
......@@ -18,6 +19,7 @@ import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
......@@ -25,6 +27,7 @@ import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
......@@ -32,9 +35,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.*;
/**
* @author sxw
......@@ -263,11 +264,24 @@ public class ElasticSearch {
SearchHit[] hits = response.getHits().getHits();
List<T> res = new ArrayList<>(hits.length);
for (SearchHit hit : hits) {
res.add(JSON.parseObject(hit.getSourceAsString(), c));
//解析高亮字段
//获取当前命中的对象的高亮的字段
Map<String, HighlightField> highlightFields = hit.getHighlightFields();
HighlightField hghlightContent = highlightFields.get("text.content");
String newName = "";
if (hghlightContent != null){
//获取该高亮字段的高亮信息
Text[] fragments = hghlightContent.getFragments();
//将前缀、关键词、后缀进行拼接
for (Text fragment : fragments) {
newName += fragment;
}
}
Map<String, Object> sourceAsMap = hit.getSourceAsMap();
sourceAsMap.put("content",newName);
res.add(JSON.parseObject(JSONObject.toJSONString(sourceAsMap), c));
}
// 封装分页
PageHelper.startPage(1,2);
PageInfo<T> page = new PageInfo<>();
page.setList(res);
page.setPageNum(pageNum);
......
......@@ -38,5 +38,13 @@ public interface IWeConversationArchiveService {
* @return
*/
JSONObject getFinalChatRoomContactInfo(String fromId, String roomId);
/**
* 获取全局会话数据接口
*
* @param query 参
* @return
*/
PageInfo<JSONObject> getChatAllList(ConversationArchiveQuery query);
}
......@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -160,4 +161,45 @@ public class WeConversationArchiveServiceImpl implements IWeConversationArchiveS
return null;
}
}
@Override
public PageInfo<JSONObject> getChatAllList(ConversationArchiveQuery query) {
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum() == null ? 1 : pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize() == null ? 10 : pageDomain.getPageSize();
SearchSourceBuilder builder = new SearchSourceBuilder();
int from = (pageNum - 1) * pageSize;
builder.size(pageSize);
builder.from(from);
builder.sort("msgtime", SortOrder.DESC);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
//成员姓名查询
if(StringUtils.isNotEmpty(query.getUserName())){
boolQueryBuilder.must(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("fromInfo.name",query.getUserName()))
.mustNot(QueryBuilders.existsQuery("fromInfo.externalUserid")));
}
//客户姓名查询
if(StringUtils.isNotEmpty(query.getCustomerName())){
boolQueryBuilder.must(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("fromInfo.name",query.getCustomerName()))
.must(QueryBuilders.existsQuery("fromInfo.externalUserid")));
}
//关键词查询并高亮显示
if (StringUtils.isNotEmpty(query.getKeyWord())){
boolQueryBuilder.must(QueryBuilders.multiMatchQuery(query.getKeyWord(),"text.content"));
builder.highlighter(new HighlightBuilder().field("text.content"));
}
//时间范围查询
if (StringUtils.isNotEmpty(query.getBeginTime()) && StringUtils.isNotEmpty(query.getEndTime())) {
Date beginTime = DateUtils.dateTime(query.getBeginTime(), DateUtils.YYYY_MM_DD);
Date endTime = DateUtils.dateTime(query.getEndTime(), DateUtils.YYYY_MM_DD);
boolQueryBuilder.filter(QueryBuilders.rangeQuery("msgtime").gte(beginTime).lte(endTime));
}
builder.query(boolQueryBuilder);
PageInfo<JSONObject> pageInfo = elasticSearch.searchPage(WeConstans.WECOM_FINANCE_INDEX, builder, pageNum, pageSize, JSONObject.class);
return pageInfo;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册