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 9dfcd175
authored
Jan 05, 2021
by
leejoker
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
使用并行流和异步处理多线程
1 parent
1d93428c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
13 deletions
linkwe-admin/src/main/java/com/linkwechat/LinkWeChatApplication.java
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCustomerController.java
linkwe-admin/src/main/resources/application.yml
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerServiceImpl.java
linkwe-admin/src/main/java/com/linkwechat/LinkWeChatApplication.java
View file @
9dfcd17
...
@@ -6,6 +6,7 @@ import org.mybatis.spring.annotation.MapperScan;
...
@@ -6,6 +6,7 @@ import org.mybatis.spring.annotation.MapperScan;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.scheduling.annotation.EnableAsync
;
/**
/**
* 启动程序
* 启动程序
...
@@ -15,6 +16,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
...
@@ -15,6 +16,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
,
PageHelperAutoConfiguration
.
class
})
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
,
PageHelperAutoConfiguration
.
class
})
@MapperScan
(
"com.linkwechat.*.mapper"
)
@MapperScan
(
"com.linkwechat.*.mapper"
)
@ForestScan
(
basePackages
=
"com.linkwechat.wecom.client"
)
@ForestScan
(
basePackages
=
"com.linkwechat.wecom.client"
)
@EnableAsync
public
class
LinkWeChatApplication
public
class
LinkWeChatApplication
{
{
public
static
void
main
(
String
[]
args
)
public
static
void
main
(
String
[]
args
)
...
...
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCustomerController.java
View file @
9dfcd17
...
@@ -106,16 +106,12 @@ public class WeCustomerController extends BaseController
...
@@ -106,16 +106,12 @@ public class WeCustomerController extends BaseController
@PreAuthorize
(
"@ss.hasPermi('customerManage:customer:sync')"
)
@PreAuthorize
(
"@ss.hasPermi('customerManage:customer:sync')"
)
@Log
(
title
=
"企业微信客户同步接口"
,
businessType
=
BusinessType
.
DELETE
)
@Log
(
title
=
"企业微信客户同步接口"
,
businessType
=
BusinessType
.
DELETE
)
@GetMapping
(
"/synchWeCustomer"
)
@GetMapping
(
"/synchWeCustomer"
)
public
AjaxResult
synchWeCustomer
(){
public
AjaxResult
synchWeCustomer
()
{
SecurityContext
securityContext
=
SecurityContextHolder
.
getContext
();
try
{
try
{
Threads
.
SINGLE_THREAD_POOL
.
execute
(
new
Runnable
()
{
SecurityContext
context
=
SecurityContextHolder
.
getContext
();
@Override
SecurityContextHolder
.
setStrategyName
(
SecurityContextHolder
.
MODE_INHERITABLETHREADLOCAL
);
public
void
run
()
{
SecurityContextHolder
.
setContext
(
context
);
SecurityContextHolder
.
setContext
(
securityContext
);
weCustomerService
.
synchWeCustomer
();
weCustomerService
.
synchWeCustomer
();
}
});
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
linkwe-admin/src/main/resources/application.yml
View file @
9dfcd17
...
@@ -56,6 +56,11 @@ spring:
...
@@ -56,6 +56,11 @@ spring:
max-file-size
:
10MB
max-file-size
:
10MB
# 设置总上传的文件大小
# 设置总上传的文件大小
max-request-size
:
20MB
max-request-size
:
20MB
task
:
execution
:
pool
:
keep-alive
:
10s
thread-name-prefix
:
common-pool-
# 服务模块
# 服务模块
devtools
:
devtools
:
restart
:
restart
:
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerServiceImpl.java
View file @
9dfcd17
...
@@ -26,6 +26,7 @@ import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag;
...
@@ -26,6 +26,7 @@ import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag;
import
com.linkwechat.wecom.mapper.WeCustomerMapper
;
import
com.linkwechat.wecom.mapper.WeCustomerMapper
;
import
com.linkwechat.wecom.service.*
;
import
com.linkwechat.wecom.service.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.security.core.context.SecurityContext
;
import
org.springframework.security.core.context.SecurityContext
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -121,21 +122,18 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
...
@@ -121,21 +122,18 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
* @return
* @return
*/
*/
@Override
@Override
@Async
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
synchWeCustomer
()
{
public
void
synchWeCustomer
()
{
FollowUserList
followUserList
=
weCustomerClient
.
getFollowUserList
();
FollowUserList
followUserList
=
weCustomerClient
.
getFollowUserList
();
if
(
WeConstans
.
WE_SUCCESS_CODE
.
equals
(
followUserList
.
getErrcode
())
if
(
WeConstans
.
WE_SUCCESS_CODE
.
equals
(
followUserList
.
getErrcode
())
&&
ArrayUtil
.
isNotEmpty
(
followUserList
.
getFollow_user
()))
{
&&
ArrayUtil
.
isNotEmpty
(
followUserList
.
getFollow_user
()))
{
SecurityContext
securityContext
=
SecurityContextHolder
.
getContext
();
SecurityContext
securityContext
=
SecurityContextHolder
.
getContext
();
Arrays
.
asList
(
followUserList
.
getFollow_user
())
Arrays
.
asList
(
followUserList
.
getFollow_user
())
.
s
tream
().
forEach
(
k
->
{
.
parallelS
tream
().
forEach
(
k
->
{
try
{
try
{
Threads
.
SINGLE_THREAD_POOL
.
execute
(()
->
{
SecurityContextHolder
.
setContext
(
securityContext
);
SecurityContextHolder
.
setContext
(
securityContext
);
weFlowerCustomerHandle
(
k
);
weFlowerCustomerHandle
(
k
);
});
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
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