Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2f53e257
authored
Dec 19, 2020
by
sunxiwang
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
获取对应内部联系人列表分页处理
1 parent
549cde10
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
30 deletions
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeConversationArchiveController.java
linkwe-common/src/main/java/com/linkwechat/common/core/elasticsearch/ElasticSearch.java
linkwe-common/src/main/java/com/linkwechat/common/enums/BusinessType.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeConversationArchiveService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeConversationArchiveServiceImpl.java
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeConversationArchiveController.java
View file @
2f53e25
...
@@ -2,8 +2,7 @@ package com.linkwechat.web.controller.wecom;
...
@@ -2,8 +2,7 @@ package com.linkwechat.web.controller.wecom;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.extension.api.R
;
import
com.baomidou.mybatisplus.extension.api.R
;
import
com.linkwechat.common.annotation.Log
;
import
com.github.pagehelper.PageInfo
;
import
com.linkwechat.common.enums.BusinessType
;
import
com.linkwechat.wecom.service.IWeConversationArchiveService
;
import
com.linkwechat.wecom.service.IWeConversationArchiveService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -12,8 +11,6 @@ import org.springframework.web.bind.annotation.GetMapping;
...
@@ -12,8 +11,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
/**
* @author sxw
* @author sxw
* @description 会话存档controller
* @description 会话存档controller
...
@@ -32,9 +29,8 @@ public class WeConversationArchiveController {
...
@@ -32,9 +29,8 @@ public class WeConversationArchiveController {
* @return
* @return
*/
*/
@PreAuthorize
(
"@ss.hasPermi('conversationArchive:InternalContact:list')"
)
@PreAuthorize
(
"@ss.hasPermi('conversationArchive:InternalContact:list')"
)
@Log
(
title
=
"获取内部联系人列表"
,
businessType
=
BusinessType
.
SELECT
)
@GetMapping
(
"/getInternalContactList"
)
@GetMapping
(
"/getInternalContactList"
)
public
R
<
List
<
JSONObject
>>
getInternalContactList
(
String
userId
,
int
pageSize
,
int
pageNum
)
{
public
R
<
PageInfo
<
JSONObject
>>
getInternalContactList
(
String
userId
,
int
pageSize
,
int
pageNum
)
{
return
R
.
ok
(
weConversationArchiveService
.
getInternalContactList
(
userId
,
pageSize
,
pageNum
));
return
R
.
ok
(
weConversationArchiveService
.
getInternalContactList
(
userId
,
pageSize
,
pageNum
));
}
}
}
}
linkwe-common/src/main/java/com/linkwechat/common/core/elasticsearch/ElasticSearch.java
View file @
2f53e25
package
com
.
linkwechat
.
common
.
core
.
elasticsearch
;
package
com
.
linkwechat
.
common
.
core
.
elasticsearch
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.github.pagehelper.PageInfo
;
import
com.linkwechat.common.core.domain.elastic.ElasticSearchEntity
;
import
com.linkwechat.common.core.domain.elastic.ElasticSearchEntity
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest
;
import
org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest
;
...
@@ -24,6 +25,9 @@ import org.elasticsearch.index.reindex.DeleteByQueryRequest;
...
@@ -24,6 +25,9 @@ import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import
org.elasticsearch.search.SearchHit
;
import
org.elasticsearch.search.SearchHit
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageImpl
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -163,7 +167,7 @@ public class ElasticSearch {
...
@@ -163,7 +167,7 @@ public class ElasticSearch {
* @since
* @since
*/
*/
public
void
insertOrUpdateOne
(
String
idxName
,
ElasticSearchEntity
entity
)
{
public
void
insertOrUpdateOne
(
String
idxName
,
ElasticSearchEntity
entity
)
{
IndexRequest
request
=
new
IndexRequest
(
idxName
,
"_doc"
);
IndexRequest
request
=
new
IndexRequest
(
idxName
,
"_doc"
);
log
.
error
(
"Data : id={},entity={}"
,
entity
.
getId
(),
JSON
.
toJSONString
(
entity
.
getData
()));
log
.
error
(
"Data : id={},entity={}"
,
entity
.
getId
(),
JSON
.
toJSONString
(
entity
.
getData
()));
request
.
id
(
entity
.
getId
());
request
.
id
(
entity
.
getId
());
request
.
source
(
entity
.
getData
(),
XContentType
.
JSON
);
request
.
source
(
entity
.
getData
(),
XContentType
.
JSON
);
...
@@ -190,7 +194,7 @@ public class ElasticSearch {
...
@@ -190,7 +194,7 @@ public class ElasticSearch {
*/
*/
public
void
insertBatch
(
String
idxName
,
List
<
ElasticSearchEntity
>
list
)
{
public
void
insertBatch
(
String
idxName
,
List
<
ElasticSearchEntity
>
list
)
{
BulkRequest
request
=
new
BulkRequest
();
BulkRequest
request
=
new
BulkRequest
();
list
.
forEach
(
item
->
request
.
add
(
new
IndexRequest
(
idxName
,
"_doc"
).
id
(
item
.
getId
())
list
.
forEach
(
item
->
request
.
add
(
new
IndexRequest
(
idxName
,
"_doc"
).
id
(
item
.
getId
())
.
source
(
item
.
getData
(),
XContentType
.
JSON
)));
.
source
(
item
.
getData
(),
XContentType
.
JSON
)));
try
{
try
{
restHighLevelClient
.
bulk
(
request
,
RequestOptions
.
DEFAULT
);
restHighLevelClient
.
bulk
(
request
,
RequestOptions
.
DEFAULT
);
...
@@ -213,7 +217,7 @@ public class ElasticSearch {
...
@@ -213,7 +217,7 @@ public class ElasticSearch {
*/
*/
public
<
T
>
void
deleteBatch
(
String
idxName
,
Collection
<
T
>
idList
)
{
public
<
T
>
void
deleteBatch
(
String
idxName
,
Collection
<
T
>
idList
)
{
BulkRequest
request
=
new
BulkRequest
();
BulkRequest
request
=
new
BulkRequest
();
idList
.
forEach
(
item
->
request
.
add
(
new
DeleteRequest
(
idxName
,
"_doc"
,
item
.
toString
())));
idList
.
forEach
(
item
->
request
.
add
(
new
DeleteRequest
(
idxName
,
"_doc"
,
item
.
toString
())));
try
{
try
{
restHighLevelClient
.
bulk
(
request
,
RequestOptions
.
DEFAULT
);
restHighLevelClient
.
bulk
(
request
,
RequestOptions
.
DEFAULT
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -237,6 +241,7 @@ public class ElasticSearch {
...
@@ -237,6 +241,7 @@ public class ElasticSearch {
request
.
source
(
builder
);
request
.
source
(
builder
);
try
{
try
{
SearchResponse
response
=
restHighLevelClient
.
search
(
request
,
RequestOptions
.
DEFAULT
);
SearchResponse
response
=
restHighLevelClient
.
search
(
request
,
RequestOptions
.
DEFAULT
);
long
totalHits
=
response
.
getHits
().
getTotalHits
().
value
;
SearchHit
[]
hits
=
response
.
getHits
().
getHits
();
SearchHit
[]
hits
=
response
.
getHits
().
getHits
();
List
<
T
>
res
=
new
ArrayList
<>(
hits
.
length
);
List
<
T
>
res
=
new
ArrayList
<>(
hits
.
length
);
for
(
SearchHit
hit
:
hits
)
{
for
(
SearchHit
hit
:
hits
)
{
...
@@ -247,6 +252,32 @@ public class ElasticSearch {
...
@@ -247,6 +252,32 @@ public class ElasticSearch {
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
}
}
public
<
T
>
PageInfo
<
T
>
searchPage
(
String
idxName
,
SearchSourceBuilder
builder
,
int
pageNum
,
int
pageSize
,
Class
<
T
>
c
)
{
SearchRequest
request
=
new
SearchRequest
(
idxName
);
request
.
source
(
builder
);
try
{
SearchResponse
response
=
restHighLevelClient
.
search
(
request
,
RequestOptions
.
DEFAULT
);
int
totalHits
=(
int
)
response
.
getHits
().
getTotalHits
().
value
;
SearchHit
[]
hits
=
response
.
getHits
().
getHits
();
List
<
T
>
res
=
new
ArrayList
<>(
hits
.
length
);
for
(
SearchHit
hit
:
hits
)
{
res
.
add
(
JSON
.
parseObject
(
hit
.
getSourceAsString
(),
c
));
}
// 封装分页
PageInfo
<
T
>
page
=
new
PageInfo
<>();
page
.
setList
(
res
);
page
.
setPageNum
(
pageNum
);
page
.
setPageSize
(
pageSize
);
page
.
setTotal
(
totalHits
);
page
.
setPages
(
totalHits
==
0
?
0
:
(
totalHits
%
pageNum
==
0
?
totalHits
/
pageNum
:
(
totalHits
/
pageNum
)
+
1
));
page
.
setHasNextPage
(
page
.
getPageNum
()
<
page
.
getPages
());
return
page
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
/**
/**
* 删除index
* 删除index
*
*
...
...
linkwe-common/src/main/java/com/linkwechat/common/enums/BusinessType.java
View file @
2f53e25
...
@@ -2,11 +2,10 @@ package com.linkwechat.common.enums;
...
@@ -2,11 +2,10 @@ package com.linkwechat.common.enums;
/**
/**
* 业务操作类型
* 业务操作类型
*
*
* @author ruoyi
* @author ruoyi
*/
*/
public
enum
BusinessType
public
enum
BusinessType
{
{
/**
/**
* 其它
* 其它
*/
*/
...
@@ -51,13 +50,9 @@ public enum BusinessType
...
@@ -51,13 +50,9 @@ public enum BusinessType
* 生成代码
* 生成代码
*/
*/
GENCODE
,
GENCODE
,
/**
/**
* 清空数据
* 清空数据
*/
*/
CLEAN
,
CLEAN
,
/**
* 查询
*/
SELECT
,
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeConversationArchiveService.java
View file @
2f53e25
package
com
.
linkwechat
.
wecom
.
service
;
package
com
.
linkwechat
.
wecom
.
service
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.pagehelper.PageInfo
;
import
java.util.List
;
/**
/**
* @author sxw
* @author sxw
...
@@ -16,5 +15,5 @@ public interface IWeConversationArchiveService {
...
@@ -16,5 +15,5 @@ public interface IWeConversationArchiveService {
* @param userId
* @param userId
* @return
* @return
*/
*/
List
<
JSONObject
>
getInternalContactList
(
String
userId
,
int
pageSize
,
int
pageNum
);
PageInfo
<
JSONObject
>
getInternalContactList
(
String
userId
,
int
pageSize
,
int
pageNum
);
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeConversationArchiveServiceImpl.java
View file @
2f53e25
package
com
.
linkwechat
.
wecom
.
service
.
impl
;
package
com
.
linkwechat
.
wecom
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.pagehelper.PageInfo
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.core.elasticsearch.ElasticSearch
;
import
com.linkwechat.common.core.elasticsearch.ElasticSearch
;
import
com.linkwechat.wecom.service.IWeConversationArchiveService
;
import
com.linkwechat.wecom.service.IWeConversationArchiveService
;
...
@@ -12,8 +13,6 @@ import org.elasticsearch.search.sort.SortOrder;
...
@@ -12,8 +13,6 @@ import org.elasticsearch.search.sort.SortOrder;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
/**
* @author sxw
* @author sxw
* @description 会话存档业务实现类
* @description 会话存档业务实现类
...
@@ -32,16 +31,16 @@ public class WeConversationArchiveServiceImpl implements IWeConversationArchiveS
...
@@ -32,16 +31,16 @@ public class WeConversationArchiveServiceImpl implements IWeConversationArchiveS
* @return
* @return
*/
*/
@Override
@Override
public
List
<
JSONObject
>
getInternalContactList
(
String
userId
,
int
pageSize
,
int
pageNum
)
{
public
PageInfo
<
JSONObject
>
getInternalContactList
(
String
userId
,
int
pageSize
,
int
pageNum
)
{
SearchSourceBuilder
builder
=
new
SearchSourceBuilder
();
SearchSourceBuilder
builder
=
new
SearchSourceBuilder
();
builder
.
size
(
pageSize
);
int
from
=
(
pageSize
-
1
)
*
pageNum
;
builder
.
from
(
pageNum
);
builder
.
size
(
pageNum
);
builder
.
sort
(
"msgtime"
,
SortOrder
.
ASC
);
builder
.
from
(
from
);
builder
.
sort
(
"msgtime"
,
SortOrder
.
ASC
);
BoolQueryBuilder
boolQueryBuilder
=
QueryBuilders
.
boolQuery
()
BoolQueryBuilder
boolQueryBuilder
=
QueryBuilders
.
boolQuery
()
.
must
(
QueryBuilders
.
termsQuery
(
"tolist.keyword"
,
userId
))
.
must
(
QueryBuilders
.
termsQuery
(
"tolist.keyword"
,
userId
))
.
must
(
QueryBuilders
.
termQuery
(
"roomid"
,
""
));
.
must
(
QueryBuilders
.
termQuery
(
"roomid"
,
""
));
builder
.
query
(
boolQueryBuilder
);
builder
.
query
(
boolQueryBuilder
);
List
<
JSONObject
>
search
=
elasticSearch
.
search
(
WeConstans
.
WECOM_FINANCE_INDEX
,
builder
,
JSONObject
.
class
);
return
elasticSearch
.
searchPage
(
WeConstans
.
WECOM_FINANCE_INDEX
,
builder
,
pageNum
,
pageSize
,
JSONObject
.
class
);
return
search
;
}
}
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment