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 8e90d663
authored
Jan 11, 2022
by
linkwechat8856@163.com
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
客户列表索引查询优化
1 parent
222b9edc
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
205 additions
and
98 deletions
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCustomerController.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomer.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCustomerMapper.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCustomerService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerMessagePushServiceImpl.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerServiceImpl.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeTaskFissionServiceImpl.java
linkwe-wecom/src/main/resources/mapper/wecom/WeCustomerMapper.xml
linkwe-wecom/src/main/resources/mapper/wecom/WeFlowerCustomerTagRelMapper.xml
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCustomerController.java
View file @
8e90d66
package
com
.
linkwechat
.
web
.
controller
.
wecom
;
package
com
.
linkwechat
.
web
.
controller
.
wecom
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.linkwechat.common.annotation.Log
;
import
com.linkwechat.common.annotation.Log
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.core.controller.BaseController
;
import
com.linkwechat.common.core.controller.BaseController
;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.common.core.page.PageDomain
;
import
com.linkwechat.common.core.page.TableDataInfo
;
import
com.linkwechat.common.core.page.TableDataInfo
;
import
com.linkwechat.common.core.page.TableSupport
;
import
com.linkwechat.common.enums.BusinessType
;
import
com.linkwechat.common.enums.BusinessType
;
import
com.linkwechat.common.enums.TrackState
;
import
com.linkwechat.common.enums.TrajectoryType
;
import
com.linkwechat.common.exception.CustomException
;
import
com.linkwechat.common.exception.CustomException
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.wecom.constants.SynchRecordConstants
;
import
com.linkwechat.wecom.constants.SynchRecordConstants
;
import
com.linkwechat.wecom.domain.*
;
import
com.linkwechat.wecom.domain.*
;
import
com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo
;
import
com.linkwechat.wecom.domain.vo.WeMakeCustomerTag
;
import
com.linkwechat.wecom.domain.vo.WeMakeCustomerTag
;
import
com.linkwechat.wecom.domain.vo.WeOnTheJobCustomerVo
;
import
com.linkwechat.wecom.domain.vo.WeOnTheJobCustomerVo
;
import
com.linkwechat.wecom.service.IWeCustomerService
;
import
com.linkwechat.wecom.service.IWeCustomerService
;
...
@@ -25,7 +23,6 @@ import io.swagger.annotations.ApiOperation;
...
@@ -25,7 +23,6 @@ import io.swagger.annotations.ApiOperation;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -57,15 +54,19 @@ public class WeCustomerController extends BaseController
...
@@ -57,15 +54,19 @@ public class WeCustomerController extends BaseController
*********************************************************************************/
*********************************************************************************/
/**
/**
* 查询企业微信客户列表(分页)
* 查询企业微信客户列表(分页)
,优化百万数据分页查询,没有用框架自带分页
*/
*/
@GetMapping
(
"/findWeCustomerList"
)
@GetMapping
(
"/findWeCustomerList"
)
@ApiOperation
(
"查询企业微信客户列表"
)
@ApiOperation
(
"查询企业微信客户列表"
)
public
TableDataInfo
findWeCustomerList
(
WeCustomerList
weCustomerList
)
public
TableDataInfo
findWeCustomerList
(
WeCustomerList
weCustomerList
)
{
{
startPage
();
List
<
WeCustomerList
>
list
=
weCustomerService
.
findWeCustomerList
(
weCustomerList
);
List
<
WeCustomerList
>
list
=
weCustomerService
.
findWeCustomerList
(
weCustomerList
,
TableSupport
.
buildPageRequest
()
);
TableDataInfo
dataTable
=
getDataTable
(
list
);
TableDataInfo
dataTable
=
getDataTable
(
list
);
//设置总条数
dataTable
.
setTotal
(
weCustomerService
.
countWeCustomerList
(
weCustomerList
)
);
dataTable
.
setLastSyncTime
(
dataTable
.
setLastSyncTime
(
iWeSynchRecordService
.
findUpdateLatestTime
(
SynchRecordConstants
.
SYNCH_CUSTOMER
)
iWeSynchRecordService
.
findUpdateLatestTime
(
SynchRecordConstants
.
SYNCH_CUSTOMER
)
);
//最近同步时间
);
//最近同步时间
...
@@ -85,7 +86,7 @@ public class WeCustomerController extends BaseController
...
@@ -85,7 +86,7 @@ public class WeCustomerController extends BaseController
public
AjaxResult
findAllWeCustomerList
(
WeCustomerList
weCustomerList
)
public
AjaxResult
findAllWeCustomerList
(
WeCustomerList
weCustomerList
)
{
{
return
AjaxResult
.
success
(
return
AjaxResult
.
success
(
weCustomerService
.
findWeCustomerList
(
weCustomerList
)
weCustomerService
.
findWeCustomerList
(
weCustomerList
,
null
)
);
);
}
}
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomer.java
View file @
8e90d66
...
@@ -101,6 +101,11 @@ public class WeCustomer extends BaseEntity {
...
@@ -101,6 +101,11 @@ public class WeCustomer extends BaseEntity {
private
String
takeoverUserId
;
private
String
takeoverUserId
;
private
String
tagIds
;
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCustomerMapper.java
View file @
8e90d66
...
@@ -3,6 +3,7 @@ package com.linkwechat.wecom.mapper;
...
@@ -3,6 +3,7 @@ package com.linkwechat.wecom.mapper;
import
java.util.List
;
import
java.util.List
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.linkwechat.common.core.page.PageDomain
;
import
com.linkwechat.wecom.domain.*
;
import
com.linkwechat.wecom.domain.*
;
import
com.linkwechat.wecom.domain.vo.CusertomerBelongUserInfo
;
import
com.linkwechat.wecom.domain.vo.CusertomerBelongUserInfo
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
...
@@ -22,10 +23,17 @@ public interface WeCustomerMapper extends BaseMapper<WeCustomer>
...
@@ -22,10 +23,17 @@ public interface WeCustomerMapper extends BaseMapper<WeCustomer>
* @param weCustomerList
* @param weCustomerList
* @return
* @return
*/
*/
List
<
WeCustomerList
>
findWeCustomerList
(
@Param
(
"weCustomerList"
)
WeCustomerList
weCustomerList
);
List
<
WeCustomerList
>
findWeCustomerList
(
@Param
(
"weCustomerList"
)
WeCustomerList
weCustomerList
,
@Param
(
"pageDomain"
)
PageDomain
pageDomain
);
/**
/**
* 客户总数统计
* @param weCustomerList
* @return
*/
long
countWeCustomerList
(
@Param
(
"weCustomerList"
)
WeCustomerList
weCustomerList
);
/**
* 获取客户所在群
* 获取客户所在群
* @param userId
* @param userId
* @return
* @return
...
@@ -77,4 +85,7 @@ public interface WeCustomerMapper extends BaseMapper<WeCustomer>
...
@@ -77,4 +85,7 @@ public interface WeCustomerMapper extends BaseMapper<WeCustomer>
long
noRepeatCountCustomer
(
@Param
(
"weCustomerList"
)
WeCustomerList
weCustomerList
);
long
noRepeatCountCustomer
(
@Param
(
"weCustomerList"
)
WeCustomerList
weCustomerList
);
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCustomerService.java
View file @
8e90d66
package
com
.
linkwechat
.
wecom
.
service
;
package
com
.
linkwechat
.
wecom
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.linkwechat.common.core.page.PageDomain
;
import
com.linkwechat.wecom.domain.*
;
import
com.linkwechat.wecom.domain.*
;
import
com.linkwechat.wecom.domain.dto.WeWelcomeMsg
;
import
com.linkwechat.wecom.domain.dto.WeWelcomeMsg
;
import
com.linkwechat.wecom.domain.vo.WeCustomerDetailVo
;
import
com.linkwechat.wecom.domain.vo.WeCustomerDetailVo
;
import
com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo
;
import
com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo
;
import
com.linkwechat.wecom.domain.vo.WeMakeCustomerTag
;
import
com.linkwechat.wecom.domain.vo.WeMakeCustomerTag
;
import
com.linkwechat.wecom.domain.vo.WeOnTheJobCustomerVo
;
import
com.linkwechat.wecom.domain.vo.WeOnTheJobCustomerVo
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.ExecutionException
;
/**
/**
* 企业微信客户Service接口
* 企业微信客户Service接口
...
@@ -102,7 +105,14 @@ public interface IWeCustomerService extends IService<WeCustomer>
...
@@ -102,7 +105,14 @@ public interface IWeCustomerService extends IService<WeCustomer>
* @param weCustomerList
* @param weCustomerList
* @return
* @return
*/
*/
List
<
WeCustomerList
>
findWeCustomerList
(
WeCustomerList
weCustomerList
);
List
<
WeCustomerList
>
findWeCustomerList
(
WeCustomerList
weCustomerList
,
PageDomain
pageDomain
);
/**
* 客户总数统计
* @param weCustomerList
* @return
*/
long
countWeCustomerList
(
@Param
(
"weCustomerList"
)
WeCustomerList
weCustomerList
);
/**
/**
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerMessagePushServiceImpl.java
View file @
8e90d66
...
@@ -237,7 +237,7 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
...
@@ -237,7 +237,7 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
return
weCustomerService
.
findWeCustomerList
(
WeCustomerList
.
builder
()
return
weCustomerService
.
findWeCustomerList
(
WeCustomerList
.
builder
()
.
userIds
(
staffId
)
.
userIds
(
staffId
)
.
departmentIds
(
department
)
.
departmentIds
(
department
)
.
build
());
.
build
()
,
null
);
}
else
{
}
else
{
...
@@ -250,7 +250,7 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
...
@@ -250,7 +250,7 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
.
userIds
(
staffId
)
.
userIds
(
staffId
)
.
tagIds
(
tag
)
.
tagIds
(
tag
)
.
departmentIds
(
department
)
.
departmentIds
(
department
)
.
build
());
.
build
()
,
null
);
// WeCustomer weCustomer = new WeCustomer();
// WeCustomer weCustomer = new WeCustomer();
// weCustomer.setUserIds(staffId);
// weCustomer.setUserIds(staffId);
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerServiceImpl.java
View file @
8e90d66
...
@@ -5,9 +5,11 @@ import cn.hutool.core.collection.ListUtil;
...
@@ -5,9 +5,11 @@ import cn.hutool.core.collection.ListUtil;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.base.Joiner
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.linkwechat.common.constant.Constants
;
import
com.linkwechat.common.constant.Constants
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.core.page.PageDomain
;
import
com.linkwechat.common.enums.*
;
import
com.linkwechat.common.enums.*
;
import
com.linkwechat.common.exception.wecom.WeComException
;
import
com.linkwechat.common.exception.wecom.WeComException
;
import
com.linkwechat.common.utils.DateUtils
;
import
com.linkwechat.common.utils.DateUtils
;
...
@@ -32,11 +34,15 @@ import com.linkwechat.wecom.mapper.WeCustomerMapper;
...
@@ -32,11 +34,15 @@ 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.scheduling.annotation.Async
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
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
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
java.util.stream.Stream
;
...
@@ -80,6 +86,11 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
...
@@ -80,6 +86,11 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
@Autowired
private
ThreadPoolTaskExecutor
taskExecutor
;
/**
/**
* 重构版客户列表
* 重构版客户列表
...
@@ -88,52 +99,63 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
...
@@ -88,52 +99,63 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
* @return
* @return
*/
*/
@Override
@Override
public
List
<
WeCustomerList
>
findWeCustomerList
(
WeCustomerList
weCustomerList
)
{
public
List
<
WeCustomerList
>
findWeCustomerList
(
WeCustomerList
weCustomerList
,
PageDomain
pageDomain
)
{
return
this
.
baseMapper
.
findWeCustomerList
(
weCustomerList
);
return
this
.
baseMapper
.
findWeCustomerList
(
weCustomerList
,
pageDomain
);
}
}
/**
/**
* 客户
同步接口
* 客户
总数统计
*
*
@param weCustomerList
* @return
* @return
*/
*/
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
long
countWeCustomerList
(
WeCustomerList
weCustomerList
)
{
@SynchRecord
(
synchType
=
SynchRecordConstants
.
SYNCH_CUSTOMER
)
return
this
.
baseMapper
.
countWeCustomerList
(
weCustomerList
);
public
void
synchWeCustomer
()
{
}
SecurityContext
securityContext
=
SecurityContextHolder
.
getContext
();
//异步同步一下标签库,解决标签不同步问题
/**
Threads
.
SINGLE_THREAD_POOL
.
execute
(
new
Runnable
()
{
* 客户同步接口
*
* @return
*/
@Override
@Override
public
void
run
()
{
@SynchRecord
(
synchType
=
SynchRecordConstants
.
SYNCH_CUSTOMER
)
SecurityContextHolder
.
setContext
(
securityContext
);
@Async
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
()))
{
String
[]
follow_user
=
followUserList
.
getFollow_user
();
List
<
List
<
String
>>
partition
=
Lists
.
partition
(
Arrays
.
asList
(
followUserList
.
getFollow_user
()),
100
);
//此处逻辑,根据分片的数据,每片从线程池获取线程,然后启动不同线程处理下面的逻辑
for
(
List
<
String
>
follow_user:
partition
)
{
if
(
ArrayUtil
.
isNotEmpty
(
follow_user
))
{
List
<
ExternalUserDetail
>
externalUserDetails
=
new
ArrayList
<>();
List
<
ExternalUserDetail
>
externalUserDetails
=
new
ArrayList
<>();
getByUser
(
follow_user
,
null
,
externalUserDetails
);
getByUser
(
follow_user
.
stream
().
toArray
(
String
[]::
new
),
null
,
externalUserDetails
);
if
(
CollectionUtil
.
isNotEmpty
(
externalUserDetails
))
{
if
(
CollectionUtil
.
isNotEmpty
(
externalUserDetails
))
{
List
<
List
<
ExternalUserDetail
>>
userDetailPartition
=
Lists
.
partition
(
externalUserDetails
,
1000
);
for
(
List
<
ExternalUserDetail
>
details:
userDetailPartition
){
taskExecutor
.
submit
(()->{
//此处也可多线程数据分片处理
weFlowerCustomerHandle
(
weFlowerCustomerHandle
(
externalUserD
etails
,
true
d
etails
,
true
);
);
});
}
}
}
}
}
}
}
}
});
}
}
...
@@ -162,12 +184,14 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
...
@@ -162,12 +184,14 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
weCustomer
.
setFirstUserId
(
followInfo
.
getUserid
());
weCustomer
.
setFirstUserId
(
followInfo
.
getUserid
());
weCustomer
.
setFirstAddTime
(
new
Date
(
followInfo
.
getCreatetime
()
*
1000L
));
weCustomer
.
setFirstAddTime
(
new
Date
(
followInfo
.
getCreatetime
()
*
1000L
));
weCustomer
.
setAddMethod
(
followInfo
.
getAdd_way
());
weCustomer
.
setAddMethod
(
followInfo
.
getAdd_way
());
weCustomerList
.
add
(
weCustomer
);
if
(
isSynchCustomerTagRel
){
if
(
isSynchCustomerTagRel
){
List
<
String
>
tags
=
Stream
.
of
(
followInfo
.
getTag_id
()).
collect
(
Collectors
.
toList
());
List
<
String
>
tags
=
Stream
.
of
(
followInfo
.
getTag_id
()).
collect
(
Collectors
.
toList
());
if
(
CollectionUtil
.
isNotEmpty
(
tags
))
{
if
(
CollectionUtil
.
isNotEmpty
(
tags
))
{
tags
.
stream
().
forEach
(
tag
->
{
//获取标签
weCustomer
.
setTagIds
(
Joiner
.
on
(
","
).
join
(
tags
));
tags
.
stream
().
forEach
(
tag
->
{
weFlowerCustomerTagRels
.
add
(
weFlowerCustomerTagRels
.
add
(
WeFlowerCustomerTagRel
.
builder
()
WeFlowerCustomerTagRel
.
builder
()
.
userId
(
followInfo
.
getUserid
())
.
userId
(
followInfo
.
getUserid
())
...
@@ -181,6 +205,8 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
...
@@ -181,6 +205,8 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
}
}
}
}
weCustomerList
.
add
(
weCustomer
);
});
});
...
@@ -528,11 +554,6 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
...
@@ -528,11 +554,6 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
TrajectorySceneType
.
TRAJECTORY_TITLE_GXGRBQ
.
getType
(),
TrajectorySceneType
.
TRAJECTORY_TITLE_GXGRBQ
.
getType
(),
CollectionUtil
.
isNotEmpty
(
lodAddTag
)?
CollectionUtil
.
isNotEmpty
(
lodAddTag
)?
String
.
join
(
","
,
lodAddTag
.
stream
().
map
(
WeTag:
:
getName
).
collect
(
Collectors
.
toList
())):
"暂无标签"
,
null
);
String
.
join
(
","
,
lodAddTag
.
stream
().
map
(
WeTag:
:
getName
).
collect
(
Collectors
.
toList
())):
"暂无标签"
,
null
);
}
}
...
@@ -581,13 +602,12 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
...
@@ -581,13 +602,12 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
weCustomer
.
setState
(
followUser
.
getState
());
weCustomer
.
setState
(
followUser
.
getState
());
weCustomer
.
setFirstAddTime
(
new
Date
(
followUser
.
getCreatetime
()
*
1000L
));
weCustomer
.
setFirstAddTime
(
new
Date
(
followUser
.
getCreatetime
()
*
1000L
));
weCustomer
.
setAddMethod
(
followUser
.
getAddWay
());
weCustomer
.
setAddMethod
(
followUser
.
getAddWay
());
this
.
baseMapper
.
batchAddOrUpdate
(
ListUtil
.
toList
(
weCustomer
)
);
//设置标签
//设置标签
List
<
ExternalUserTag
>
tags
=
followUser
.
getTags
();
List
<
ExternalUserTag
>
tags
=
followUser
.
getTags
();
if
(
CollectionUtil
.
isNotEmpty
(
tags
)){
if
(
CollectionUtil
.
isNotEmpty
(
tags
)){
weCustomer
.
setTagIds
(
Joiner
.
on
(
","
).
join
(
tags
));
List
<
WeFlowerCustomerTagRel
>
tagRels
=
new
ArrayList
<>();
List
<
WeFlowerCustomerTagRel
>
tagRels
=
new
ArrayList
<>();
tags
.
stream
().
forEach
(
k
->{
tags
.
stream
().
forEach
(
k
->{
tagRels
.
add
(
tagRels
.
add
(
...
@@ -602,7 +622,9 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
...
@@ -602,7 +622,9 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
iWeFlowerCustomerTagRelService
.
batchAddOrUpdate
(
tagRels
);
iWeFlowerCustomerTagRelService
.
batchAddOrUpdate
(
tagRels
);
}
}
this
.
baseMapper
.
batchAddOrUpdate
(
ListUtil
.
toList
(
weCustomer
)
);
//生成轨迹
//生成轨迹
iWeCustomerTrajectoryService
.
createTrajectory
(
ListUtil
.
toList
(
iWeCustomerTrajectoryService
.
createTrajectory
(
ListUtil
.
toList
(
...
@@ -705,7 +727,8 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
...
@@ -705,7 +727,8 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
WeCustomerList
.
builder
()
WeCustomerList
.
builder
()
.
externalUserid
(
externalUserid
)
.
externalUserid
(
externalUserid
)
.
delFlag
(
delFlag
)
.
delFlag
(
delFlag
)
.
build
()
.
build
(),
null
);
);
if
(
CollectionUtil
.
isNotEmpty
(
weCustomerList
)){
if
(
CollectionUtil
.
isNotEmpty
(
weCustomerList
)){
BeanUtils
.
copyBeanProp
(
BeanUtils
.
copyBeanProp
(
...
@@ -755,7 +778,7 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
...
@@ -755,7 +778,7 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
.
externalUserid
(
externalUserid
)
.
externalUserid
(
externalUserid
)
.
userIds
(
userId
)
.
userIds
(
userId
)
.
delFlag
(
delFlag
)
.
delFlag
(
delFlag
)
.
build
());
.
build
()
,
null
);
if
(
CollectionUtil
.
isNotEmpty
(
weCustomerList
)){
if
(
CollectionUtil
.
isNotEmpty
(
weCustomerList
)){
List
<
WeCustomerDetail
.
CompanyOrPersonTag
>
companyTags
=
new
ArrayList
<>();
List
<
WeCustomerDetail
.
CompanyOrPersonTag
>
companyTags
=
new
ArrayList
<>();
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeTaskFissionServiceImpl.java
View file @
8e90d66
...
@@ -236,7 +236,7 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W
...
@@ -236,7 +236,7 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W
.
userIds
(
userIds
)
.
userIds
(
userIds
)
.
tagIds
(
weTaskFission
.
getCustomerTagId
().
replaceAll
(
"all"
,
""
))
.
tagIds
(
weTaskFission
.
getCustomerTagId
().
replaceAll
(
"all"
,
""
))
.
departmentIds
(
departmentIds
)
.
departmentIds
(
departmentIds
)
.
build
());
.
build
()
,
null
);
if
(
weCustomerList
!=
null
){
if
(
weCustomerList
!=
null
){
Map
<
String
,
Set
<
String
>>
userAndCustomerMap
=
weCustomerList
.
stream
().
collect
(
Collectors
.
groupingBy
(
WeCustomerList:
:
getFirstUserId
,
Collectors
.
mapping
(
WeCustomerList:
:
getExternalUserid
,
Collectors
.
toSet
())));
Map
<
String
,
Set
<
String
>>
userAndCustomerMap
=
weCustomerList
.
stream
().
collect
(
Collectors
.
groupingBy
(
WeCustomerList:
:
getFirstUserId
,
Collectors
.
mapping
(
WeCustomerList:
:
getExternalUserid
,
Collectors
.
toSet
())));
List
<
WeAddGroupMessageQuery
.
SenderInfo
>
senderList
=
new
ArrayList
<>();
List
<
WeAddGroupMessageQuery
.
SenderInfo
>
senderList
=
new
ArrayList
<>();
...
...
linkwe-wecom/src/main/resources/mapper/wecom/WeCustomerMapper.xml
View file @
8e90d66
...
@@ -9,11 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -9,11 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
wc.avatar,
wc.avatar,
wc.`name` as customerName,
wc.`name` as customerName,
wc.customer_type as customerType,
wc.customer_type as customerType,
GROUP_CONCAT(if(wt.tag_type=1,wt.`tag_id`,null )) as tagIds,
wc.tag_ids as tagIds,
GROUP_CONCAT(if(wt.tag_type=1,wt.`name`,null )) as tagNames,
GROUP_CONCAT(if(wt.tag_type=3,wt.`tag_id`,null )) as personTagIds,
GROUP_CONCAT(if(wt.tag_type=3,wt.`name`,null )) as personTagNames,
wu.user_name,
wc.external_userid,
wc.external_userid,
wc.first_user_id,
wc.first_user_id,
wc.track_state,
wc.track_state,
...
@@ -21,78 +17,137 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -21,78 +17,137 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
wc.first_add_time,
wc.first_add_time,
wc.birthday,
wc.birthday,
wc.gender,
wc.gender,
(SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id in (wu.department)) as departmentName,
wc.phone,
wc.phone,
wc.email,
wc.email,
wc.address,
wc.address,
wc.qq,
wc.qq,
wc.position,
wc.position,
wc.corp_name as corpName,
wc.corp_name as corpName,
wc.other_descr as otherDescr
wc.other_descr as otherDescr,
(SELECT GROUP_CONCAT(wu.user_name) FROM we_user wu WHERE wu.user_id=wc.first_user_id) as userName,
(SELECT GROUP_CONCAT(wt.tag_id) FROM we_flower_customer_tag_rel wfctr
LEFT JOIN we_tag wt ON wt.tag_id= wfctr.tag_id
WHERE wfctr.external_userid=wc.external_userid AND wc.first_user_id=wfctr.user_id AND wt.tag_type=3
) as personTagIds,
(SELECT GROUP_CONCAT(wt.name) FROM we_flower_customer_tag_rel wfctr
LEFT JOIN we_tag wt ON wt.tag_id= wfctr.tag_id
WHERE wfctr.external_userid=wc.external_userid AND wc.first_user_id=wfctr.user_id AND wt.tag_type=3
) as personTagNames,
(SELECT GROUP_CONCAT(wt.name) FROM we_flower_customer_tag_rel wfctr
LEFT JOIN we_tag wt ON wt.tag_id= wfctr.tag_id
WHERE wfctr.external_userid=wc.external_userid AND wc.first_user_id=wfctr.user_id AND wt.tag_type=1
) as tagNames
FROM
FROM
we_customer wc
we_customer wc
LEFT JOIN we_user wu ON wc.first_user_id=wu.user_id
JOIN
LEFT JOIN we_flower_customer_tag_rel wfctr ON wfctr.del_flag=0 AND wfctr.external_userid=wc.external_userid AND wfctr.user_id=wc.first_user_id
(
LEFT JOIN we_tag wt ON wt.tag_id=wfctr.tag_id
SELECT wcr.external_userid,wcr.first_user_id FROM we_customer wcr
<where>
<where>
<if
test=
"weCustomerList.gender !=null"
>
<if
test=
"weCustomerList.gender !=null"
>
AND wc.gender=#{weCustomerList.gender}
AND wc
r
.gender=#{weCustomerList.gender}
</if>
</if>
<if
test=
"weCustomerList.trackState !=null"
>
<if
test=
"weCustomerList.trackState !=null"
>
AND wc.track_state=#{weCustomerList.trackState}
AND wc
r
.track_state=#{weCustomerList.trackState}
</if>
</if>
<if
test=
"weCustomerList.addMethod !=null"
>
<if
test=
"weCustomerList.addMethod !=null"
>
AND wc.add_method=#{weCustomerList.addMethod}
AND wc
r
.add_method=#{weCustomerList.addMethod}
</if>
</if>
<if
test=
"weCustomerList.customerType !=null"
>
<if
test=
"weCustomerList.customerType !=null"
>
AND wc.customer_type=#{weCustomerList.customerType}
AND wc
r
.customer_type=#{weCustomerList.customerType}
</if>
</if>
<if
test=
"weCustomerList.externalUserid !=null"
>
<if
test=
"weCustomerList.externalUserid !=null"
>
AND wc.external_userid=#{weCustomerList.externalUserid}
AND wc
r
.external_userid=#{weCustomerList.externalUserid}
</if>
</if>
<if
test=
"weCustomerList.firstUserId !=null"
>
<if
test=
"weCustomerList.firstUserId !=null"
>
AND wc.first_user_id=#{weCustomerList.firstUserId}
AND wc
r
.first_user_id=#{weCustomerList.firstUserId}
</if>
</if>
<if
test=
"weCustomerList.departmentIds != null and weCustomerList.departmentIds !=''"
>
<if
test=
"weCustomerList.delFlag != null"
>
<if
test=
"weCustomerList.departmentIds.indexOf(',') != -1"
>
AND wcr.del_flag = #{weCustomerList.delFlag}
OR wu.department in
</if>
<foreach
item=
"item"
index=
"index"
collection=
"weCustomerList.departmentIds.split(',')"
open=
"("
separator=
","
close=
")"
>
<if
test=
"weCustomerList.name != null and weCustomerList.name !=''"
>
AND wcr.`name` like concat('%',#{weCustomerList.name,jdbcType=VARCHAR},'%')
</if>
<if
test=
"weCustomerList.userIds !=null and weCustomerList.userIds !=''"
>
AND wcr.first_user_id in
<foreach
collection=
"weCustomerList.userIds.split(',')"
item=
"item"
index=
"index"
open=
"("
close=
")"
separator=
","
>
#{item}
</foreach>
</if>
<if
test=
"weCustomerList.tagIds !=null and weCustomerList.tagIds !=''"
>
AND wcr.tag_id in
<foreach
collection=
"weCustomerList.tagIds.split(',')"
item=
"item"
index=
"index"
open=
"("
close=
")"
separator=
","
>
#{item}
#{item}
</foreach>
</foreach>
</if>
</if>
<if
test=
"weCustomerList.beginTime !=null and weCustomerList.beginTime != '' and weCustomerList.endTime !='' and weCustomerList.endTime != null"
>
AND date_format(wcr.first_add_time,'%Y-%m-%d') BETWEEN #{weCustomerList.beginTime} AND #{weCustomerList.endTime}
</if>
</where>
ORDER BY wcr.first_add_time desc
<if
test=
"pageDomain !=null"
>
<if
test=
"pageDomain.pageNum !=null and pageDomain.pageSize !=null"
>
limit #{pageDomain.pageNum} , #{pageDomain.pageSize}
</if>
</if>
) a ON a.external_userid=wc.external_userid AND a.first_user_id=wc.first_user_id
</select>
<select
id=
"countWeCustomerList"
resultType=
"long"
>
SELECT count(0) FROM we_customer wcr
<where>
<if
test=
"weCustomerList.gender !=null"
>
AND wcr.gender=#{weCustomerList.gender}
</if>
<if
test=
"weCustomerList.trackState !=null"
>
AND wcr.track_state=#{weCustomerList.trackState}
</if>
<if
test=
"weCustomerList.addMethod !=null"
>
AND wcr.add_method=#{weCustomerList.addMethod}
</if>
<if
test=
"weCustomerList.customerType !=null"
>
AND wcr.customer_type=#{weCustomerList.customerType}
</if>
<if
test=
"weCustomerList.externalUserid !=null"
>
AND wcr.external_userid=#{weCustomerList.externalUserid}
</if>
<if
test=
"weCustomerList.firstUserId !=null"
>
AND wcr.first_user_id=#{weCustomerList.firstUserId}
</if>
</if>
<if
test=
"weCustomerList.delFlag != null"
>
<if
test=
"weCustomerList.delFlag != null"
>
AND wc.del_flag = #{weCustomerList.delFlag}
AND wc
r
.del_flag = #{weCustomerList.delFlag}
</if>
</if>
<if
test=
"weCustomerList.name != null and weCustomerList.name !=''"
>
<if
test=
"weCustomerList.name != null and weCustomerList.name !=''"
>
AND wc.`name` like concat('%',#{weCustomerList.name,jdbcType=VARCHAR},'%')
AND wc
r
.`name` like concat('%',#{weCustomerList.name,jdbcType=VARCHAR},'%')
</if>
</if>
<if
test=
"weCustomerList.userIds !=null and weCustomerList.userIds !=''"
>
<if
test=
"weCustomerList.userIds !=null and weCustomerList.userIds !=''"
>
AND wc.first_user_id in
AND wc
r
.first_user_id in
<foreach
collection=
"weCustomerList.userIds.split(',')"
item=
"item"
index=
"index"
open=
"("
close=
")"
separator=
","
>
<foreach
collection=
"weCustomerList.userIds.split(',')"
item=
"item"
index=
"index"
open=
"("
close=
")"
separator=
","
>
#{item}
#{item}
</foreach>
</foreach>
</if>
</if>
<if
test=
"weCustomerList.tagIds !=null and weCustomerList.tagIds !=''"
>
<if
test=
"weCustomerList.tagIds !=null and weCustomerList.tagIds !=''"
>
AND w
t
.tag_id in
AND w
cr
.tag_id in
<foreach
collection=
"weCustomerList.tagIds.split(',')"
item=
"item"
index=
"index"
open=
"("
close=
")"
separator=
","
>
<foreach
collection=
"weCustomerList.tagIds.split(',')"
item=
"item"
index=
"index"
open=
"("
close=
")"
separator=
","
>
#{item}
#{item}
</foreach>
</foreach>
</if>
</if>
<if
test=
"weCustomerList.beginTime !=null and weCustomerList.beginTime != '' and weCustomerList.endTime !='' and weCustomerList.endTime != null"
>
<if
test=
"weCustomerList.beginTime !=null and weCustomerList.beginTime != '' and weCustomerList.endTime !='' and weCustomerList.endTime != null"
>
AND date_format(wc.first_add_time,'%Y-%m-%d') BETWEEN #{weCustomerList.beginTime} AND #{weCustomerList.endTime}
AND date_format(wc
r
.first_add_time,'%Y-%m-%d') BETWEEN #{weCustomerList.beginTime} AND #{weCustomerList.endTime}
</if>
</if>
</where>
</where>
GROUP BY wc.external_userid,wc.first_user_id
ORDER BY wcr.first_add_time desc
ORDER BY wc.first_add_time desc
</select>
</select>
...
@@ -210,35 +265,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -210,35 +265,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
phone,
phone,
add_method,
add_method,
del_flag,
del_flag,
state
state,
tag_ids
) values
) values
<foreach
collection=
"weCustomers"
item=
"item"
index=
"index"
separator=
","
>
<foreach
collection=
"weCustomers"
item=
"item"
index=
"index"
separator=
","
>
(#{item.externalUserid},#{item.customerName},#{item.avatar},#{item.customerType},#{item.gender}, #{item.unionid},#{item.birthday},
(#{item.externalUserid},#{item.customerName},#{item.avatar},#{item.customerType},#{item.gender}, #{item.unionid},#{item.birthday},
#{item.corpName},#{item.position},#{item.isOpenChat}, #{item.createTime},
#{item.corpName},#{item.position},#{item.isOpenChat}, #{item.createTime},
#{item.createBy},#{item.firstUserId},#{item.firstAddTime},#{item.qq},#{item.email},#{item.address},#{item.phone},#{item.addMethod},#{item.delFlag},
#{item.createBy},#{item.firstUserId},#{item.firstAddTime},#{item.qq},#{item.email},#{item.address},#{item.phone},#{item.addMethod},#{item.delFlag},
#{item.state}
#{item.state}
,#{item.tagIds}
)
)
</foreach>
</foreach>
ON DUPLICATE KEY UPDATE
ON DUPLICATE KEY UPDATE
NAME=IF(TRIM(VALUES(NAME)) !='',VALUES(NAME),we_customer.NAME),
NAME=IFNULL(VALUES(NAME),we_customer.NAME),
avatar=IF(TRIM(VALUES(avatar)) !='', VALUES(avatar), we_customer.avatar),
avatar=IFNULL(VALUES(avatar), we_customer.avatar),
customer_type=IF(VALUES(customer_type),VALUES(customer_type),we_customer.customer_type),
customer_type=IFNULL(VALUES(customer_type),we_customer.customer_type),
gender=IF(VALUES(gender), VALUES(gender), we_customer.gender),
gender=IFNULL(VALUES(gender), we_customer.gender),
unionid=IF(TRIM(VALUES(unionid)) !='', VALUES(unionid), we_customer.unionid),
unionid=IFNULL(VALUES(unionid), we_customer.unionid),
birthday=IF(VALUES(birthday),VALUES(birthday), we_customer.birthday),
birthday=IFNULL(VALUES(birthday), we_customer.birthday),
corp_name=IF(TRIM(VALUES(corp_name)) !='', VALUES(corp_name), we_customer.corp_name),
corp_name=IFNULL(VALUES(corp_name), we_customer.corp_name),
position=IF(TRIM(VALUES(position)) != '',VALUES(position) , we_customer.position),
position=IFNULL(VALUES(position), we_customer.position),
is_open_chat=IF(VALUES(is_open_chat), VALUES(is_open_chat), we_customer.is_open_chat),
is_open_chat=IFNULL(VALUES(is_open_chat), we_customer.is_open_chat),
first_user_id=IF(TRIM(VALUES(first_user_id)) !='', VALUES(first_user_id), we_customer.first_user_id),
first_user_id=IFNULL(VALUES(first_user_id), we_customer.first_user_id),
first_add_time=IF(VALUES(first_add_time), VALUES(first_add_time), we_customer.first_add_time),
first_add_time=IFNULL(VALUES(first_add_time),we_customer.first_add_time),
qq=IF(TRIM(VALUES(qq)) !='', VALUES(qq), we_customer.qq),
qq=IFNULL(VALUES(qq), we_customer.qq),
email=IF(TRIM(VALUES(email)) != '', VALUES(email), we_customer.email),
email=IFNULL(VALUES(email), we_customer.email),
address=IF(TRIM(VALUES(address)) != '', VALUES(address), we_customer.address),
address=IFNULL(VALUES(address), we_customer.address),
phone=IF(TRIM(VALUES(phone)) != '', VALUES(phone), we_customer.phone),
phone=IFNULL(VALUES(phone), we_customer.phone),
add_method=IF(VALUES(add_method), VALUES(add_method), we_customer.add_method),
add_method=IFNULL(VALUES(add_method), we_customer.add_method),
del_flag=IFNULL(VALUES(del_flag),we_customer.del_flag),
del_flag=IFNULL(VALUES(del_flag),we_customer.del_flag),
del_flag=IFNULL(VALUES(del_flag),we_customer.del_flag),
del_flag=IF(VALUES(del_flag),VALUES(del_flag),we_customer.del_flag
),
state=IFNULL(VALUES(state),we_customer.state
),
state=IF(TRIM(VALUES(state)) != '',VALUES(state),we_customer.state
);
tag_ids=IFNULL(VALUES(tag_ids),we_customer.tag_ids
);
</insert>
</insert>
...
...
linkwe-wecom/src/main/resources/mapper/wecom/WeFlowerCustomerTagRelMapper.xml
View file @
8e90d66
...
@@ -85,9 +85,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -85,9 +85,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
(#{item.userId},#{item.externalUserid},#{item.tagId},NOW(),#{item.isCompanyTag},#{item.delFlag})
(#{item.userId},#{item.externalUserid},#{item.tagId},NOW(),#{item.isCompanyTag},#{item.delFlag})
</foreach>
</foreach>
ON DUPLICATE KEY UPDATE
ON DUPLICATE KEY UPDATE
user_id=IF
(TRIM(VALUES(user_id)) !='',
VALUES(user_id), we_flower_customer_tag_rel.user_id),
user_id=IF
NULL(
VALUES(user_id), we_flower_customer_tag_rel.user_id),
external_userid=IF
(TRIM(VALUES(external_userid)) !='',
VALUES(external_userid), we_flower_customer_tag_rel.external_userid),
external_userid=IF
NULL(
VALUES(external_userid), we_flower_customer_tag_rel.external_userid),
tag_id=IF
(TRIM(VALUES(tag_id)) !='',
VALUES(tag_id), we_flower_customer_tag_rel.tag_id),
tag_id=IF
NULL(
VALUES(tag_id), we_flower_customer_tag_rel.tag_id),
del_flag=IFNULL(VALUES(del_flag),we_flower_customer_tag_rel.del_flag);
del_flag=IFNULL(VALUES(del_flag),we_flower_customer_tag_rel.del_flag);
</insert>
</insert>
...
...
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