Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
仟微科技
Link Wechat
提交
66627870
Link Wechat
项目概览
仟微科技
/
Link Wechat
通知
48
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Link Wechat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
66627870
编写于
11月 06, 2020
作者:
S
sunxiwang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
客户条件查询功能完善;
客户同步异步采用多线程方式,调用批量获取客户详情接口优化同步速度; 客户列表导出暂时可以导出客户基本信息
上级
f2bf716f
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
411 addition
and
250 deletion
+411
-250
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCustomerController.java
...linkwechat/web/controller/wecom/WeCustomerController.java
+30
-18
linkwe-admin/src/main/resources/application.yml
linkwe-admin/src/main/resources/application.yml
+6
-5
linkwe-common/src/main/java/com/linkwechat/common/constant/WeConstans.java
.../main/java/com/linkwechat/common/constant/WeConstans.java
+2
-1
linkwe-common/src/main/java/com/linkwechat/common/utils/Threads.java
...on/src/main/java/com/linkwechat/common/utils/Threads.java
+14
-5
linkwe-framework/src/main/java/com/linkwechat/framework/manager/ShutdownManager.java
...ava/com/linkwechat/framework/manager/ShutdownManager.java
+3
-0
linkwe-ui/src/api/customer/index.js
linkwe-ui/src/api/customer/index.js
+10
-0
linkwe-ui/src/views/customerManage/customer.vue
linkwe-ui/src/views/customerManage/customer.vue
+26
-4
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerClient.java
...in/java/com/linkwechat/wecom/client/WeCustomerClient.java
+10
-0
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomer.java
...src/main/java/com/linkwechat/wecom/domain/WeCustomer.java
+13
-3
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserDetail.java
...kwechat/wecom/domain/dto/customer/ExternalUserDetail.java
+21
-0
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserList.java
...inkwechat/wecom/domain/dto/customer/ExternalUserList.java
+4
-0
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCustomerMapper.java
...in/java/com/linkwechat/wecom/mapper/WeCustomerMapper.java
+6
-6
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCustomerService.java
...java/com/linkwechat/wecom/service/IWeCustomerService.java
+11
-2
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeAccessTokenServiceImpl.java
...nkwechat/wecom/service/impl/WeAccessTokenServiceImpl.java
+1
-0
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerServiceImpl.java
.../linkwechat/wecom/service/impl/WeCustomerServiceImpl.java
+210
-194
linkwe-wecom/src/main/resources/mapper/wecom/WeCustomerMapper.xml
...ecom/src/main/resources/mapper/wecom/WeCustomerMapper.xml
+44
-12
未找到文件。
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCustomerController.java
浏览文件 @
66627870
...
...
@@ -8,10 +8,13 @@ import com.linkwechat.common.core.controller.BaseController;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.common.core.page.TableDataInfo
;
import
com.linkwechat.common.enums.BusinessType
;
import
com.linkwechat.common.utils.Threads
;
import
com.linkwechat.common.utils.poi.ExcelUtil
;
import
com.linkwechat.wecom.domain.vo.WeMakeCustomerTag
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.context.SecurityContext
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -62,27 +65,27 @@ public class WeCustomerController extends BaseController
return
AjaxResult
.
success
(
weCustomerService
.
getCustomersByUserId
(
userId
));
}
//
/**
//
* 导出企业微信客户列表
//
*/
//
@PreAuthorize("@ss.hasPermi('wecom:customer:export')")
//
@Log(title = "企业微信客户", businessType = BusinessType.EXPORT)
//
@GetMapping("/export")
//
public AjaxResult export(WeCustomer weCustomer)
//
{
//
List<WeCustomer> list = weCustomerService.selectWeCustomerList(weCustomer);
//
ExcelUtil<WeCustomer> util = new ExcelUtil<WeCustomer>(WeCustomer.class);
//
return util.exportExcel(list, "customer");
//
}
/**
* 导出企业微信客户列表
*/
@PreAuthorize
(
"@ss.hasPermi('wecom:customer:export')"
)
@Log
(
title
=
"企业微信客户"
,
businessType
=
BusinessType
.
EXPORT
)
@GetMapping
(
"/export"
)
public
AjaxResult
export
(
WeCustomer
weCustomer
)
{
List
<
WeCustomer
>
list
=
weCustomerService
.
selectWeCustomerList
(
weCustomer
);
ExcelUtil
<
WeCustomer
>
util
=
new
ExcelUtil
<
WeCustomer
>(
WeCustomer
.
class
);
return
util
.
exportExcel
(
list
,
"customer"
);
}
/**
* 获取企业微信客户详细信息
*/
@PreAuthorize
(
"@ss.hasPermi('customerManage:customer:view')"
)
@GetMapping
(
value
=
"/{
i
d}"
)
public
AjaxResult
getInfo
(
@PathVariable
(
"
id"
)
Long
i
d
)
@GetMapping
(
value
=
"/{
externalUserI
d}"
)
public
AjaxResult
getInfo
(
@PathVariable
(
"
externalUserId"
)
String
externalUserI
d
)
{
return
AjaxResult
.
success
(
weCustomerService
.
selectWeCustomerById
(
i
d
));
return
AjaxResult
.
success
(
weCustomerService
.
selectWeCustomerById
(
externalUserI
d
));
}
...
...
@@ -108,9 +111,18 @@ public class WeCustomerController extends BaseController
@Log
(
title
=
"企业微信客户同步接口"
,
businessType
=
BusinessType
.
DELETE
)
@GetMapping
(
"/synchWeCustomer"
)
public
AjaxResult
synchWeCustomer
(){
weCustomerService
.
synchWeCustomer
();
SecurityContext
securityContext
=
SecurityContextHolder
.
getContext
();
try
{
Threads
.
SINGLE_THREAD_POOL
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
SecurityContextHolder
.
setContext
(
securityContext
);
weCustomerService
.
synchWeCustomer
();
}
});
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
AjaxResult
.
success
(
WeConstans
.
SYNCH_TIP
);
}
...
...
linkwe-admin/src/main/resources/application.yml
浏览文件 @
66627870
...
...
@@ -44,7 +44,7 @@ spring:
messages
:
# 国际化资源文件路径
basename
:
i18n/messages
profiles
:
profiles
:
active
:
druid
# 文件上传
servlet
:
...
...
@@ -65,7 +65,7 @@ spring:
# 端口,默认为6379
port
:
6379
# 密码
password
:
password
:
# 连接超时时间
timeout
:
10s
lettuce
:
...
...
@@ -105,11 +105,11 @@ mybatis-plus:
# configLocation: classpath:mybatis/mybatis-config.xml
# PageHelper分页插件
pagehelper
:
pagehelper
:
helperDialect
:
mysql
reasonable
:
true
supportMethodsArguments
:
true
params
:
count=countSql
params
:
count=countSql
# Swagger配置
swagger
:
...
...
@@ -119,7 +119,7 @@ swagger:
pathMapping
:
# 防止XSS攻击
xss
:
xss
:
# 过滤开关
enabled
:
true
# 排除链接(多个用逗号分隔)
...
...
@@ -148,6 +148,7 @@ wecome:
-
/externalcontact/edit_corp_tag
-
/externalcontact/list
-
/externalcontact/get
-
/externalcontact/batch/get_by_user
-
/externalcontact/groupchat/list
-
/externalcontact/groupchat/get
-
/externalcontact/mark_tag
...
...
linkwe-common/src/main/java/com/linkwechat/common/constant/WeConstans.java
浏览文件 @
66627870
...
...
@@ -170,5 +170,6 @@ public class WeConstans {
public
static
final
String
COMMA
=
","
;
public
static
final
String
USER_ID
=
"userid"
;
public
static
final
String
CURSOR
=
"cursor"
;
}
linkwe-common/src/main/java/com/linkwechat/common/utils/Threads.java
浏览文件 @
66627870
package
com.linkwechat.common.utils
;
import
java.util.concurrent.CancellationException
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.*
;
import
com.google.common.util.concurrent.ThreadFactoryBuilder
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -17,6 +15,17 @@ public class Threads
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Threads
.
class
);
private
static
final
int
CORE_POOL_SIZE
=
Runtime
.
getRuntime
().
availableProcessors
();
private
static
final
ThreadFactory
NAMED_THREAD_FACTORY
=
new
ThreadFactoryBuilder
().
setNameFormat
(
"common-pool-%d"
).
build
();
/**
* 创建线程池
*/
public
static
final
ThreadPoolExecutor
SINGLE_THREAD_POOL
=
new
ThreadPoolExecutor
(
CORE_POOL_SIZE
,
CORE_POOL_SIZE
+
1
,
10
l
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingQueue
<>(
1024
),
NAMED_THREAD_FACTORY
);
/**
* sleep等待,单位为毫秒
*/
...
...
linkwe-framework/src/main/java/com/linkwechat/framework/manager/ShutdownManager.java
浏览文件 @
66627870
package
com.linkwechat.framework.manager
;
import
com.linkwechat.common.utils.Threads
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
...
...
@@ -30,6 +31,8 @@ public class ShutdownManager
{
logger
.
info
(
"====关闭后台任务任务线程池===="
);
AsyncManager
.
me
().
shutdown
();
logger
.
info
(
"====关闭后台线程池===="
);
Threads
.
shutdownAndAwaitTermination
(
Threads
.
SINGLE_THREAD_POOL
);
}
catch
(
Exception
e
)
{
...
...
linkwe-ui/src/api/customer/index.js
浏览文件 @
66627870
...
...
@@ -17,6 +17,7 @@ const service = config.services.wecom + '/customer'
export
function
getList
(
params
)
{
return
request
({
url
:
service
+
'
/list
'
,
method
:
'
get
'
,
params
})
}
...
...
@@ -84,4 +85,13 @@ export function updateBirthday(data) {
method
:
'
PUT
'
,
data
})
}
// 导出用户
export
function
exportCustomer
(
query
)
{
return
request
({
url
:
service
+
'
/export
'
,
method
:
'
get
'
,
params
:
query
})
}
\ No newline at end of file
linkwe-ui/src/views/customerManage/customer.vue
浏览文件 @
66627870
...
...
@@ -15,7 +15,7 @@ export default {
pageNum
:
1
,
pageSize
:
10
,
name
:
""
,
// "客户名称",
userId
:
""
,
// "添加人id",
userId
s
:
""
,
// "添加人id",
tagIds
:
""
,
// "标签id,多个标签,id使用逗号隔开",
beginTime
:
""
,
// "开始时间",
endTime
:
""
,
// "结束时间"
...
...
@@ -96,6 +96,9 @@ export default {
if
(
this
.
dateRange
[
0
])
{
this
.
query
.
beginTime
=
this
.
dateRange
[
0
];
this
.
query
.
endTime
=
this
.
dateRange
[
1
];
}
else
{
this
.
query
.
beginTime
=
""
;
this
.
query
.
endTime
=
""
;
}
page
&&
(
this
.
query
.
pageNum
=
page
);
this
.
loading
=
true
;
...
...
@@ -173,11 +176,30 @@ export default {
api
.
sync
().
then
(()
=>
{
loading
.
close
();
this
.
msgSuccess
(
"
后台开始同步数据,请稍后关注进度
"
);
});
}).
catch
(
fail
=>
{
loading
.
close
();
console
.
log
(
fail
)
});;
},
/** 导出按钮操作 */
exportCustomer
()
{
const
queryParams
=
this
.
query
;
this
.
$confirm
(
"
是否确认导出所有客户数据项?
"
,
"
警告
"
,
{
confirmButtonText
:
"
确定
"
,
cancelButtonText
:
"
取消
"
,
type
:
"
warning
"
,
})
.
then
(
function
()
{
return
api
.
exportCustomer
(
queryParams
);
})
.
then
((
response
)
=>
{
this
.
download
(
response
.
msg
);
})
.
catch
(
function
()
{});
},
selectedUser
(
list
)
{
this
.
queryUser
=
list
;
this
.
query
.
userId
=
list
.
map
((
d
)
=>
d
.
i
d
)
+
""
;
this
.
query
.
userId
s
=
list
.
map
((
d
)
=>
d
.
userI
d
)
+
""
;
},
submitSelectTag
(
formName
)
{
if
(
this
.
tagDialogType
.
type
===
"
query
"
)
{
...
...
@@ -267,7 +289,7 @@ export default {
<el-button
v-hasPermi=
"['customerManage:customer:export']"
type=
"cyan"
@
click=
"
isMoreFilter = !isMoreFilt
er"
@
click=
"
exportCustom
er"
>
导出列表
</el-button>
</el-form-item>
</el-form>
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerClient.java
浏览文件 @
66627870
...
...
@@ -10,6 +10,8 @@ import com.linkwechat.wecom.domain.dto.customer.ExternalUserDetail;
import
com.linkwechat.wecom.domain.dto.customer.ExternalUserList
;
import
com.linkwechat.wecom.domain.dto.customer.FollowUserList
;
import
java.util.Map
;
/**
* @description: 获取配置客户联系人功能的成员
* @author: HaoN
...
...
@@ -42,6 +44,14 @@ public interface WeCustomerClient {
@Request
(
url
=
"/externalcontact/get"
)
ExternalUserDetail
get
(
@Query
(
"external_userid"
)
String
externalUserid
);
/**
* 根据企业成员id批量获取客户详情
* @param query
* @return
*/
@Request
(
url
=
"/externalcontact/batch/get_by_user"
,
type
=
"POST"
)
ExternalUserList
getByUser
(
@DataObject
Map
<
String
,
Object
>
query
);
/**
* 修改客户备注信息
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomer.java
浏览文件 @
66627870
...
...
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableField;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.linkwechat.common.annotation.Excel
;
import
com.linkwechat.common.annotation.Excels
;
import
com.linkwechat.common.core.domain.BaseEntity
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
import
lombok.AllArgsConstructor
;
...
...
@@ -29,7 +31,7 @@ import javax.validation.constraints.NotBlank;
@AllArgsConstructor
@NoArgsConstructor
@TableName
(
"we_customer"
)
public
class
WeCustomer
public
class
WeCustomer
extends
BaseEntity
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -40,15 +42,18 @@ public class WeCustomer
private
String
externalUserid
;
/** 外部联系人名称 */
@Excel
(
name
=
"客户"
)
private
String
name
;
/** 外部联系人头像 */
private
String
avatar
;
/** 外部联系人的类型,1表示该外部联系人是微信用户,2表示该外部联系人是企业微信用户 */
@Excel
(
name
=
"客户类型"
,
readConverterExp
=
"1=微信,2=企业微信"
)
private
Integer
type
;
/** 外部联系人性别 0-未知 1-男性 2-女性 */
@Excel
(
name
=
"性别"
,
readConverterExp
=
"0=未知,1=男性,2=女性"
)
private
Integer
gender
;
/** 外部联系人在微信开放平台的唯一身份标识,通过此字段企业可将外部联系人与公众号/小程序用户关联起来。 */
...
...
@@ -60,6 +65,7 @@ public class WeCustomer
/** 客户企业简称 */
@Excel
(
name
=
"公司名称"
)
private
String
corpName
;
/** 客户企业全称 */
...
...
@@ -72,8 +78,12 @@ public class WeCustomer
@TableField
(
exist
=
false
)
private
List
<
WeFlowerCustomerRel
>
weFlowerCustomerRels
;
/** 添加人id */
@TableField
(
exist
=
false
)
private
String
userIds
;
/** 标签 */
@TableField
(
exist
=
false
)
private
String
tagIds
;
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserDetail.java
浏览文件 @
66627870
...
...
@@ -21,6 +21,7 @@ public class ExternalUserDetail extends WeResultDto {
/** 客户联系人 */
private
List
<
FollowUser
>
follow_user
;
private
List
<
FollowInfo
>
follow_info
;
@Data
...
...
@@ -68,4 +69,24 @@ public class ExternalUserDetail extends WeResultDto {
private
List
<
ExternalUserTag
>
tags
;
}
@Data
public
class
FollowInfo
{
/**该成员对此外部联系人的备注*/
private
String
remark
;
/**该成员对此外部联系人的描述*/
private
String
description
;
/**该成员添加此外部联系人的时间*/
private
long
createtime
;
/**该成员对此客户备注的企业名称*/
private
String
remark_company
;
/**该成员对此客户备注的手机号码*/
private
String
[]
remark_mobiles
;
/**该成员添加此客户的来源*/
private
Integer
add_way
;
/**发起添加的userid,如果成员主动添加,为成员的userid;如果是客户主动添加,则为客户的外部联系人userid;如果是内部成员共享/管理员分配,则为对应的成员/管理员userid*/
private
String
oper_userid
;
/**标签**/
private
String
[]
tag_id
;
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserList.java
浏览文件 @
66627870
...
...
@@ -3,6 +3,8 @@ package com.linkwechat.wecom.domain.dto.customer;
import
com.linkwechat.wecom.domain.dto.WeResultDto
;
import
lombok.Data
;
import
java.util.List
;
/**
* @description: 客户列表
* @author: HaoN
...
...
@@ -11,4 +13,6 @@ import lombok.Data;
@Data
public
class
ExternalUserList
extends
WeResultDto
{
private
String
[]
external_userid
;
private
List
<
ExternalUserDetail
>
external_contact_list
;
private
String
next_cursor
;
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCustomerMapper.java
浏览文件 @
66627870
...
...
@@ -18,10 +18,10 @@ public interface WeCustomerMapper extends BaseMapper<WeCustomer>
/**
* 查询企业微信客户
*
* @param
i
d 企业微信客户ID
* @param
externalUserI
d 企业微信客户ID
* @return 企业微信客户
*/
public
WeCustomer
selectWeCustomerById
(
Long
i
d
);
public
WeCustomer
selectWeCustomerById
(
String
externalUserI
d
);
/**
* 查询企业微信客户列表
...
...
@@ -50,18 +50,18 @@ public interface WeCustomerMapper extends BaseMapper<WeCustomer>
/**
* 删除企业微信客户
*
* @param
i
d 企业微信客户ID
* @param
externalUserI
d 企业微信客户ID
* @return 结果
*/
public
int
deleteWeCustomerById
(
Long
i
d
);
public
int
deleteWeCustomerById
(
String
externalUserI
d
);
/**
* 批量删除企业微信客户
*
* @param
i
ds 需要删除的数据ID
* @param
externalUserI
ds 需要删除的数据ID
* @return 结果
*/
public
int
deleteWeCustomerByIds
(
Long
[]
i
ds
);
public
int
deleteWeCustomerByIds
(
String
[]
externalUserI
ds
);
/**
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCustomerService.java
浏览文件 @
66627870
...
...
@@ -19,10 +19,19 @@ public interface IWeCustomerService extends IService<WeCustomer>
/**
* 查询企业微信客户
*
* @param
i
d 企业微信客户ID
* @param
externalUserI
d 企业微信客户ID
* @return 企业微信客户
*/
public
WeCustomer
selectWeCustomerById
(
Long
id
);
public
WeCustomer
selectWeCustomerById
(
String
externalUserId
);
/**
* 新增/修改企业微信客户
*
* @param weCustomer 企业微信客户
* @return 修改结果
*/
@Override
public
boolean
saveOrUpdate
(
WeCustomer
weCustomer
);
/**
* 查询企业微信客户列表
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeAccessTokenServiceImpl.java
浏览文件 @
66627870
...
...
@@ -96,6 +96,7 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
if
(
StringUtils
.
isNotEmpty
(
token
)){
redisCache
.
setCacheObject
(
accessTokenKey
,
token
,
expires_in
.
intValue
(),
TimeUnit
.
SECONDS
);
weAccessToken
=
token
;
}
}
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerServiceImpl.java
浏览文件 @
66627870
...
...
@@ -7,13 +7,18 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.utils.SecurityUtils
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.common.utils.Threads
;
import
com.linkwechat.common.utils.bean.BeanUtils
;
import
com.linkwechat.wecom.client.WeCropTagClient
;
import
com.linkwechat.wecom.client.WeCustomerClient
;
import
com.linkwechat.wecom.client.WeUserClient
;
import
com.linkwechat.wecom.domain.*
;
import
com.linkwechat.wecom.domain.dto.AllocateWeCustomerDto
;
import
com.linkwechat.wecom.domain.dto.customer.*
;
import
com.linkwechat.wecom.domain.dto.customer.CutomerTagEdit
;
import
com.linkwechat.wecom.domain.dto.customer.ExternalUserDetail
;
import
com.linkwechat.wecom.domain.dto.customer.ExternalUserList
;
import
com.linkwechat.wecom.domain.dto.customer.FollowUserList
;
import
com.linkwechat.wecom.domain.dto.tag.WeCropGroupTagDto
;
import
com.linkwechat.wecom.domain.dto.tag.WeCropGroupTagListDto
;
import
com.linkwechat.wecom.domain.dto.tag.WeCropTagDto
;
...
...
@@ -23,21 +28,23 @@ import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag;
import
com.linkwechat.wecom.mapper.WeCustomerMapper
;
import
com.linkwechat.wecom.service.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.context.SecurityContext
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
/**
* 企业微信客户Service业务层处理
*
*
* @author ruoyi
* @date 2020-09-13
*/
@Service
public
class
WeCustomerServiceImpl
extends
ServiceImpl
<
WeCustomerMapper
,
WeCustomer
>
implements
IWeCustomerService
{
public
class
WeCustomerServiceImpl
extends
ServiceImpl
<
WeCustomerMapper
,
WeCustomer
>
implements
IWeCustomerService
{
@Autowired
private
WeCustomerMapper
weCustomerMapper
;
...
...
@@ -72,38 +79,46 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
private
WeUserClient
weUserClient
;
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
boolean
saveOrUpdate
(
WeCustomer
weCustomer
)
{
if
(
weCustomer
.
getExternalUserid
()
!=
null
)
{
WeCustomer
weCustomerBean
=
selectWeCustomerById
(
weCustomer
.
getExternalUserid
());
if
(
weCustomerBean
!=
null
)
{
return
weCustomerMapper
.
updateWeCustomer
(
weCustomer
)
==
1
;
}
else
{
return
weCustomerMapper
.
insertWeCustomer
(
weCustomer
)
==
1
;
}
}
return
false
;
}
/**
* 查询企业微信客户
*
* @param
i
d 企业微信客户ID
*
* @param
externalUserI
d 企业微信客户ID
* @return 企业微信客户
*/
@Override
public
WeCustomer
selectWeCustomerById
(
Long
id
)
{
return
weCustomerMapper
.
selectWeCustomerById
(
id
);
public
WeCustomer
selectWeCustomerById
(
String
externalUserId
)
{
return
weCustomerMapper
.
selectWeCustomerById
(
externalUserId
);
}
/**
* 查询企业微信客户列表
*
*
* @param weCustomer 企业微信客户
* @return 企业微信客户
*/
@Override
public
List
<
WeCustomer
>
selectWeCustomerList
(
WeCustomer
weCustomer
)
{
public
List
<
WeCustomer
>
selectWeCustomerList
(
WeCustomer
weCustomer
)
{
return
weCustomerMapper
.
selectWeCustomerList
(
weCustomer
);
}
/**
* 客户同步接口
*
* @return
*/
@Override
...
...
@@ -112,164 +127,171 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
FollowUserList
followUserList
=
weCustomerClient
.
getFollowUserList
();
if
(
WeConstans
.
WE_SUCCESS_CODE
.
equals
(
followUserList
.
getErrcode
())
&&
ArrayUtil
.
isNotEmpty
(
followUserList
.
getFollow_user
()))
{
if
(
WeConstans
.
WE_SUCCESS_CODE
.
equals
(
followUserList
.
getErrcode
())
&&
ArrayUtil
.
isNotEmpty
(
followUserList
.
getFollow_user
()))
{
SecurityContext
securityContext
=
SecurityContextHolder
.
getContext
();
Arrays
.
asList
(
followUserList
.
getFollow_user
())
.
stream
().
forEach
(
k
->{
//获取指定联系人对应的客户
ExternalUserList
externalUsers
=
weCustomerClient
.
list
(
k
);
if
(
WeConstans
.
WE_SUCCESS_CODE
.
equals
(
externalUsers
.
getErrcode
())
||
WeConstans
.
NOT_EXIST_CONTACT
.
equals
(
externalUsers
.
getErrcode
())
&&
ArrayUtil
.
isNotEmpty
(
externalUsers
.
getExternal_userid
())){
Arrays
.
asList
(
externalUsers
.
getExternal_userid
()).
forEach
(
v
->{
//获取指定客户的详情
ExternalUserDetail
externalUserDetail
=
weCustomerClient
.
get
(
v
);
if
(
WeConstans
.
WE_SUCCESS_CODE
.
equals
(
externalUserDetail
.
getErrcode
())){
//客户入库
WeCustomer
weCustomer
=
new
WeCustomer
();
BeanUtils
.
copyPropertiesignoreOther
(
externalUserDetail
.
getExternal_contact
(),
weCustomer
);
this
.
saveOrUpdate
(
weCustomer
);
//客户与通讯录客户关系
List
<
WeTag
>
weTags
=
new
ArrayList
<>();
List
<
WeTagGroup
>
weGroups
=
new
ArrayList
<>();
List
<
WeFlowerCustomerTagRel
>
weFlowerCustomerTagRels
=
new
ArrayList
<>();
List
<
WeFlowerCustomerRel
>
weFlowerCustomerRel
=
new
ArrayList
<>();
externalUserDetail
.
getFollow_user
().
stream
().
forEach
(
kk
->{
.
stream
().
forEach
(
k
->
{
try
{
Threads
.
SINGLE_THREAD_POOL
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
SecurityContextHolder
.
setContext
(
securityContext
);
weFlowerCustomerHandle
(
k
);
}
});
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
});
}
}
/**
* 客户同步业务处理
*
* @param userId 开通权限的企业成员id
*/
private
void
weFlowerCustomerHandle
(
String
userId
)
{
List
<
ExternalUserDetail
>
list
=
new
ArrayList
<>();
getByUser
(
userId
,
null
,
list
);
list
.
forEach
(
userDetail
->
{
//客户入库
WeCustomer
weCustomer
=
new
WeCustomer
();
BeanUtils
.
copyPropertiesignoreOther
(
userDetail
.
getExternal_contact
(),
weCustomer
);
this
.
saveOrUpdate
(
weCustomer
);
//客户与通讯录客户关系
List
<
WeTag
>
weTags
=
new
ArrayList
<>();
List
<
WeTagGroup
>
weGroups
=
new
ArrayList
<>();
List
<
WeFlowerCustomerTagRel
>
weFlowerCustomerTagRels
=
new
ArrayList
<>();
List
<
WeFlowerCustomerRel
>
weFlowerCustomerRel
=
new
ArrayList
<>();
userDetail
.
getFollow_info
().
stream
().
forEach
(
kk
->
{
// WeFlowerCustomerRel weFlowerCustomerRelOne=new WeFlowerCustomerRel();
// BeanUtils.copyPropertiesignoreOther(kk,weFlowerCustomerRelOne);
Long
weFlowerCustomerRelId
=
SnowFlakeUtil
.
nextId
();
Long
weFlowerCustomerRelId
=
SnowFlakeUtil
.
nextId
();
// weFlowerCustomerRelOne.setId(weFlowerCustomerRelId);
// weFlowerCustomerRelOne.setExternalUserid(weCustomer.getExternalUserid());
weFlowerCustomerRel
.
add
(
WeFlowerCustomerRel
.
builder
()
.
id
(
weFlowerCustomerRelId
)
.
userId
(
kk
.
getUserid
())
.
description
(
kk
.
getDescription
())
.
remarkCorpName
(
kk
.
getRemark_company
())
.
remarkMobiles
(
kk
.
getRemark_mobiles
())
.
operUserid
(
kk
.
getOper_userid
())
.
addWay
(
kk
.
getAdd_way
())
.
externalUserid
(
weCustomer
.
getExternalUserid
())
.
createTime
(
new
Date
(
kk
.
getCreatetime
()
*
1000L
))
.
build
());
List
<
ExternalUserTag
>
tags
=
kk
.
getTags
();
if
(
CollectionUtil
.
isNotEmpty
(
tags
)){
//获取相关标签组
WeCropGroupTagListDto
weCropGroupTagListDto
=
weCropTagClient
.
getCorpTagListByTagIds
(
WeFindCropTagParam
.
builder
()
.
tag_id
(
ArrayUtil
.
toArray
(
tags
.
stream
().
map
(
ExternalUserTag:
:
getTag_id
).
collect
(
Collectors
.
toList
()),
String
.
class
))
.
build
());
if
(
weCropGroupTagListDto
.
getErrcode
().
equals
(
WeConstans
.
WE_SUCCESS_CODE
)){
List
<
WeCropGroupTagDto
>
tagGroups
=
weCropGroupTagListDto
.
getTag_group
();
if
(
CollectionUtil
.
isNotEmpty
(
tagGroups
)){
tagGroups
.
stream
().
forEach
(
tagGroup
->{
weGroups
.
add
(
WeTagGroup
.
builder
()
.
groupId
(
tagGroup
.
getGroup_id
())
.
gourpName
(
tagGroup
.
getGroup_name
())
.
createBy
(
SecurityUtils
.
getUsername
())
.
build
()
);
List
<
WeCropTagDto
>
weCropTagDtos
=
tagGroup
.
getTag
();
if
(
CollectionUtil
.
isNotEmpty
(
weCropTagDtos
)){
Set
<
String
>
tagIdsSet
=
weCropTagDtos
.
stream
().
map
(
WeCropTagDto:
:
getId
).
collect
(
Collectors
.
toSet
());
tags
.
stream
().
forEach
(
tag
->{
if
(
tagIdsSet
.
contains
(
tag
.
getTag_id
())){
weTags
.
add
(
WeTag
.
builder
()
.
groupId
(
tagGroup
.
getGroup_id
())
.
tagId
(
tag
.
getTag_id
())
.
name
(
tag
.
getTag_name
())
.
build
()
);
weFlowerCustomerTagRels
.
add
(
WeFlowerCustomerTagRel
.
builder
()
.
flowerCustomerRelId
(
weFlowerCustomerRelId
)
.
tagId
(
tag
.
getTag_id
())
.
createTime
(
new
Date
())
.
build
()
);
}
});
}
});
weFlowerCustomerRel
.
add
(
WeFlowerCustomerRel
.
builder
()
.
id
(
weFlowerCustomerRelId
)
.
userId
(
userId
)
.
description
(
kk
.
getDescription
())
.
remarkCorpName
(
kk
.
getRemark_company
())
.
remarkMobiles
(
kk
.
getRemark_mobiles
())
.
operUserid
(
kk
.
getOper_userid
())
.
addWay
(
kk
.
getAdd_way
())
.
externalUserid
(
weCustomer
.
getExternalUserid
())
.
createTime
(
new
Date
(
kk
.
getCreatetime
()
*
1000L
))
.
build
());
List
<
String
>
tags
=
Stream
.
of
(
kk
.
getTag_id
()).
collect
(
Collectors
.
toList
());
if
(
CollectionUtil
.
isNotEmpty
(
tags
))
{
//获取相关标签组
WeCropGroupTagListDto
weCropGroupTagListDto
=
weCropTagClient
.
getCorpTagListByTagIds
(
WeFindCropTagParam
.
builder
()
.
tag_id
(
kk
.
getTag_id
())
.
build
());
if
(
weCropGroupTagListDto
.
getErrcode
().
equals
(
WeConstans
.
WE_SUCCESS_CODE
))
{
List
<
WeCropGroupTagDto
>
tagGroups
=
weCropGroupTagListDto
.
getTag_group
();
if
(
CollectionUtil
.
isNotEmpty
(
tagGroups
))
{
tagGroups
.
stream
().
forEach
(
tagGroup
->
{
weGroups
.
add
(
WeTagGroup
.
builder
()
.
groupId
(
tagGroup
.
getGroup_id
())
.
gourpName
(
tagGroup
.
getGroup_name
())
.
createBy
(
SecurityUtils
.
getUsername
())
.
build
()
);
List
<
WeCropTagDto
>
weCropTagDtos
=
tagGroup
.
getTag
();
if
(
CollectionUtil
.
isNotEmpty
(
weCropTagDtos
))
{
Map
<
String
,
String
>
map
=
weCropTagDtos
.
stream
().
collect
(
Collectors
.
toMap
(
WeCropTagDto:
:
getId
,
WeCropTagDto:
:
getName
));
tags
.
forEach
(
tag
->
{
if
(
map
.
containsKey
(
tag
))
{
weTags
.
add
(
WeTag
.
builder
()
.
groupId
(
tagGroup
.
getGroup_id
())
.
tagId
(
tag
)
.
name
(
map
.
get
(
tag
))
.
build
()
);
weFlowerCustomerTagRels
.
add
(
WeFlowerCustomerTagRel
.
builder
()
.
flowerCustomerRelId
(
weFlowerCustomerRelId
)
.
tagId
(
tag
)
.
createTime
(
new
Date
())
.
build
()
);
}
}
});
}
});
List
<
WeFlowerCustomerRel
>
weFlowerCustomerRels
=
iWeFlowerCustomerRelService
.
list
(
new
LambdaQueryWrapper
<
WeFlowerCustomerRel
>()
.
eq
(
WeFlowerCustomerRel:
:
getExternalUserid
,
weCustomer
.
getExternalUserid
()));
if
(
CollectionUtil
.
isNotEmpty
(
weFlowerCustomerRels
)){
List
<
Long
>
weFlowerCustomerRelIds
=
weFlowerCustomerRels
.
stream
().
map
(
WeFlowerCustomerRel:
:
getId
).
collect
(
Collectors
.
toList
());
iWeFlowerCustomerTagRelService
.
remove
(
new
LambdaQueryWrapper
<
WeFlowerCustomerTagRel
>().
in
(
WeFlowerCustomerTagRel:
:
getFlowerCustomerRelId
,
weFlowerCustomerRelIds
)
);
iWeFlowerCustomerRelService
.
removeByIds
(
weFlowerCustomerRelIds
);
}
iWeFlowerCustomerRelService
.
saveBatch
(
weFlowerCustomerRel
);
});
//设置标签跟客户关系,标签和标签组,saveOrUpdate,建立标签与添加人关系
if
(
CollectionUtil
.
isNotEmpty
(
weTags
)&&
CollectionUtil
.
isNotEmpty
(
weGroups
)){
iWeTagService
.
saveOrUpdateBatch
(
weTags
);
iWeTagGroupService
.
saveOrUpdateBatch
(
weGroups
);
iWeFlowerCustomerTagRelService
.
saveOrUpdateBatch
(
weFlowerCustomerTagRels
);
}
}
}
}
});
List
<
WeFlowerCustomerRel
>
weFlowerCustomerRels
=
iWeFlowerCustomerRelService
.
list
(
new
LambdaQueryWrapper
<
WeFlowerCustomerRel
>()
.
eq
(
WeFlowerCustomerRel:
:
getExternalUserid
,
weCustomer
.
getExternalUserid
()));
if
(
CollectionUtil
.
isNotEmpty
(
weFlowerCustomerRels
))
{
List
<
Long
>
weFlowerCustomerRelIds
=
weFlowerCustomerRels
.
stream
().
map
(
WeFlowerCustomerRel:
:
getId
).
collect
(
Collectors
.
toList
());
iWeFlowerCustomerTagRelService
.
remove
(
new
LambdaQueryWrapper
<
WeFlowerCustomerTagRel
>().
in
(
WeFlowerCustomerTagRel:
:
getFlowerCustomerRelId
,
weFlowerCustomerRelIds
)
);
});
iWeFlowerCustomerRelService
.
removeByIds
(
weFlowerCustomerRelIds
);
}
}
}
);
iWeFlowerCustomerRelService
.
saveBatch
(
weFlowerCustomerRel
);
//设置标签跟客户关系,标签和标签组,saveOrUpdate,建立标签与添加人关系
if
(
CollectionUtil
.
isNotEmpty
(
weTags
)
&&
CollectionUtil
.
isNotEmpty
(
weGroups
))
{
iWeTagService
.
saveOrUpdateBatch
(
weTags
);
iWeTagGroupService
.
saveOrUpdateBatch
(
weGroups
);
iWeFlowerCustomerTagRelService
.
saveOrUpdateBatch
(
weFlowerCustomerTagRels
);
}
});
}
/**
* 批量获取客户详情
*
* @param userId 企业成员的userid
* @param nextCursor 用于分页查询的游标
* @param list 返回结果
*/
private
void
getByUser
(
String
userId
,
String
nextCursor
,
List
<
ExternalUserDetail
>
list
)
{
Map
<
String
,
Object
>
query
=
new
HashMap
<>(
16
);
query
.
put
(
WeConstans
.
USER_ID
,
userId
);
query
.
put
(
WeConstans
.
CURSOR
,
nextCursor
);
ExternalUserList
externalUserList
=
weCustomerClient
.
getByUser
(
query
);
if
(
WeConstans
.
WE_SUCCESS_CODE
.
equals
(
externalUserList
.
getErrcode
())
||
WeConstans
.
NOT_EXIST_CONTACT
.
equals
(
externalUserList
.
getErrcode
())
&&
ArrayUtil
.
isNotEmpty
(
externalUserList
.
getExternal_contact_list
()))
{
list
.
addAll
(
externalUserList
.
getExternal_contact_list
());
if
(
StringUtils
.
isNotEmpty
(
externalUserList
.
getNext_cursor
()))
{
getByUser
(
userId
,
externalUserList
.
getNext_cursor
(),
list
);
}
}
}
/**
* 分配离职员工客户
*
* @param weLeaveUserInfoAllocateVo
*/
@Override
...
...
@@ -279,12 +301,11 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
List
<
WeFlowerCustomerRel
>
weFlowerCustomerRels
=
iWeFlowerCustomerRelService
.
list
(
new
LambdaQueryWrapper
<
WeFlowerCustomerRel
>()
.
eq
(
WeFlowerCustomerRel:
:
getUserId
,
weLeaveUserInfoAllocateVo
.
getHandoverUserid
()));
if
(
CollectionUtil
.
isNotEmpty
(
weFlowerCustomerRels
)){
if
(
CollectionUtil
.
isNotEmpty
(
weFlowerCustomerRels
))
{
List
<
WeAllocateCustomer
>
weAllocateCustomers
=
new
ArrayList
<>();
weFlowerCustomerRels
.
stream
().
forEach
(
k
->
{
List
<
WeAllocateCustomer
>
weAllocateCustomers
=
new
ArrayList
<>();
weFlowerCustomerRels
.
stream
().
forEach
(
k
->
{
k
.
setUserId
(
weLeaveUserInfoAllocateVo
.
getTakeoverUserid
());
weAllocateCustomers
.
add
(
WeAllocateCustomer
.
builder
()
...
...
@@ -300,12 +321,12 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
iWeFlowerCustomerRelService
.
saveOrUpdateBatch
(
weFlowerCustomerRels
);
if
(
CollectionUtil
.
isNotEmpty
(
weAllocateCustomers
))
{
if
(
CollectionUtil
.
isNotEmpty
(
weAllocateCustomers
))
{
//记录分配历史
if
(
iWeAllocateCustomerService
.
saveBatch
(
weAllocateCustomers
))
{
if
(
iWeAllocateCustomerService
.
saveBatch
(
weAllocateCustomers
))
{
//同步企业微信端
weAllocateCustomers
.
stream
().
forEach
(
v
->
{
weAllocateCustomers
.
stream
().
forEach
(
v
->
{
weUserClient
.
allocateCustomer
(
AllocateWeCustomerDto
.
builder
()
.
external_userid
(
v
.
getExternalUserid
())
.
handover_userid
(
v
.
getHandoverUserid
())
...
...
@@ -318,8 +339,6 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
}
}
}
...
...
@@ -327,6 +346,7 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
/**
* 客户打标签
*
* @param weMakeCustomerTag
*/
@Override
...
...
@@ -336,43 +356,41 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
//查询出当前用户对应的
List
<
WeFlowerCustomerRel
>
flowerCustomerRels
=
iWeFlowerCustomerRelService
.
list
(
new
LambdaQueryWrapper
<
WeFlowerCustomerRel
>()
.
eq
(
WeFlowerCustomerRel:
:
getExternalUserid
,
weMakeCustomerTag
.
getExternalUserid
()));
if
(
CollectionUtil
.
isNotEmpty
(
flowerCustomerRels
)){
if
(
CollectionUtil
.
isNotEmpty
(
flowerCustomerRels
))
{
List
<
WeTag
>
addTags
=
weMakeCustomerTag
.
getAddTag
();
if
(
CollectionUtil
.
isNotEmpty
(
addTags
)){
if
(
CollectionUtil
.
isNotEmpty
(
addTags
))
{
addTags
.
removeAll
(
Collections
.
singleton
(
null
));
List
<
WeFlowerCustomerTagRel
>
tagRels
=
new
ArrayList
<>();
List
<
CutomerTagEdit
>
cutomerTagEdits
=
new
ArrayList
<>();
flowerCustomerRels
.
stream
().
forEach
(
customer
->{
CutomerTagEdit
cutomerTagEdit
=
CutomerTagEdit
.
builder
()
.
userid
(
customer
.
getUserId
())
.
external_userid
(
customer
.
getExternalUserid
())
.
build
();
List
<
String
>
tags
=
new
ArrayList
<>();
addTags
.
stream
().
forEach
(
tag
->{
tags
.
add
(
tag
.
getTagId
());
tagRels
.
add
(
WeFlowerCustomerTagRel
.
builder
()
.
flowerCustomerRelId
(
customer
.
getId
())
.
tagId
(
tag
.
getTagId
())
.
createTime
(
new
Date
())
.
build
()
);
});
cutomerTagEdit
.
setAdd_tag
(
ArrayUtil
.
toArray
(
tags
,
String
.
class
));
cutomerTagEdits
.
add
(
cutomerTagEdit
);
List
<
WeFlowerCustomerTagRel
>
tagRels
=
new
ArrayList
<>();
List
<
CutomerTagEdit
>
cutomerTagEdits
=
new
ArrayList
<>();
flowerCustomerRels
.
stream
().
forEach
(
customer
->
{
CutomerTagEdit
cutomerTagEdit
=
CutomerTagEdit
.
builder
()
.
userid
(
customer
.
getUserId
())
.
external_userid
(
customer
.
getExternalUserid
())
.
build
();
List
<
String
>
tags
=
new
ArrayList
<>();
addTags
.
stream
().
forEach
(
tag
->
{
tags
.
add
(
tag
.
getTagId
());
tagRels
.
add
(
WeFlowerCustomerTagRel
.
builder
()
.
flowerCustomerRelId
(
customer
.
getId
())
.
tagId
(
tag
.
getTagId
())
.
createTime
(
new
Date
())
.
build
()
);
});
if
(
iWeFlowerCustomerTagRelService
.
saveOrUpdateBatch
(
tagRels
)){
if
(
CollectionUtil
.
isNotEmpty
(
cutomerTagEdits
)){
cutomerTagEdits
.
stream
().
forEach
(
k
->{
cutomerTagEdit
.
setAdd_tag
(
ArrayUtil
.
toArray
(
tags
,
String
.
class
));
cutomerTagEdits
.
add
(
cutomerTagEdit
);
});
if
(
iWeFlowerCustomerTagRelService
.
saveOrUpdateBatch
(
tagRels
))
{
if
(
CollectionUtil
.
isNotEmpty
(
cutomerTagEdits
))
{
cutomerTagEdits
.
stream
().
forEach
(
k
->
{
weCustomerClient
.
makeCustomerLabel
(
k
);
...
...
@@ -383,12 +401,12 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
}
}
/**
* 移除客户标签
*
* @param weMakeCustomerTag
*/
@Override
...
...
@@ -397,7 +415,7 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
List
<
WeTag
>
addTags
=
weMakeCustomerTag
.
getAddTag
();
if
(
CollectionUtil
.
isNotEmpty
(
addTags
))
{
if
(
CollectionUtil
.
isNotEmpty
(
addTags
))
{
//获取当前客户需要移除的标签
List
<
WeFlowerCustomerTagRel
>
removeTag
=
iWeFlowerCustomerTagRelService
.
list
(
new
LambdaQueryWrapper
<
WeFlowerCustomerTagRel
>()
...
...
@@ -411,15 +429,15 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
List
<
WeFlowerCustomerRel
>
flowerCustomerRels
=
iWeFlowerCustomerRelService
.
list
(
new
LambdaQueryWrapper
<
WeFlowerCustomerRel
>()
.
eq
(
WeFlowerCustomerRel:
:
getExternalUserid
,
weMakeCustomerTag
.
getExternalUserid
()));
if
(
CollectionUtil
.
isNotEmpty
(
flowerCustomerRels
)
)
{
if
(
CollectionUtil
.
isNotEmpty
(
flowerCustomerRels
))
{
if
(
iWeFlowerCustomerTagRelService
.
remove
(
if
(
iWeFlowerCustomerTagRelService
.
remove
(
new
LambdaQueryWrapper
<
WeFlowerCustomerTagRel
>()
.
in
(
WeFlowerCustomerTagRel:
:
getFlowerCustomerRelId
,
flowerCustomerRels
.
stream
().
map
(
WeFlowerCustomerRel:
:
getId
).
collect
(
Collectors
.
toList
()))
.
in
(
WeFlowerCustomerTagRel:
:
getTagId
,
removeTag
.
stream
().
map
(
WeFlowerCustomerTagRel:
:
getTagId
).
collect
(
Collectors
.
toList
()))
)){
))
{
flowerCustomerRels
.
stream
().
forEach
(
k
->
{
flowerCustomerRels
.
stream
().
forEach
(
k
->
{
weCustomerClient
.
makeCustomerLabel
(
CutomerTagEdit
.
builder
()
.
external_userid
(
k
.
getExternalUserid
())
...
...
@@ -439,14 +457,12 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
}
}
/**
* 根据员工ID获取客户
*
* @param userId
* @return
*/
...
...
linkwe-wecom/src/main/resources/mapper/wecom/WeCustomerMapper.xml
浏览文件 @
66627870
...
...
@@ -37,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql
id=
"selectWeCustomerVo"
>
select
id,
external_userid, name, avatar, type, gender, unionid, birthday, corp_name, corp_full_name, position from we_customer
select external_userid, name, avatar, type, gender, unionid, birthday, corp_name, corp_full_name, position from we_customer
</sql>
<select
id=
"selectWeCustomerList"
parameterType=
"WeCustomer"
resultMap=
"WeCustomerResult"
>
...
...
@@ -73,17 +73,50 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN we_user wu ON wu.user_id=wfcr.user_id
LEFT JOIN we_flower_customer_tag_rel wfcrf ON wfcrf.flower_customer_rel_id = wfcr.id
LEFT JOIN we_tag wt ON wt.tag_id = wfcrf.tag_id
<where>
<if
test=
"name != null and name !=''"
>
AND wc.name like concat('%', #{name}, '%')
</if>
<if
test=
"userIds != null and userIds !=''"
>
<if
test=
"userIds.indexOf(',') != -1"
>
and wfcr.user_id in
<foreach
item=
"item"
index=
"index"
collection=
"userIds.split(',')"
open=
"("
separator=
","
close=
")"
>
#{item}
</foreach>
</if>
<if
test=
"userIds.indexOf(',') == -1"
>
and wfcr.user_id=#{userIds}
</if>
</if>
<if
test=
"tagIds != null and tagIds !=''"
>
<if
test=
"tagIds.indexOf(',') != -1"
>
and wt.tag_id in
<foreach
item=
"item"
index=
"index"
collection=
"tagIds.split(',')"
open=
"("
separator=
","
close=
")"
>
#{item}
</foreach>
</if>
<if
test=
"tagIds.indexOf(',') == -1"
>
and wt.tag_id=#{tagIds}
</if>
</if>
<if
test=
"beginTime != null and beginTime != ''"
>
<!-- 开始时间检索 -->
AND date_format(wfcr.create_time,'%y%m%d')
>
= date_format(#{beginTime},'%y%m%d')
</if>
<if
test=
"endTime != null and endTime != ''"
>
<!-- 结束时间检索 -->
AND date_format(wfcr.create_time,'%y%m%d')
<
= date_format(#{endTime},'%y%m%d')
</if>
</where>
</select>
<select
id=
"selectWeCustomerById"
parameterType=
"
Lo
ng"
resultMap=
"WeCustomerResult"
>
<select
id=
"selectWeCustomerById"
parameterType=
"
Stri
ng"
resultMap=
"WeCustomerResult"
>
<include
refid=
"selectWeCustomerVo"
/>
where
id = #{i
d}
where
external_userid = #{externalUserI
d}
</select>
<insert
id=
"insertWeCustomer"
parameterType=
"WeCustomer"
>
insert into we_customer
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
<if
test=
"externalUserid != null"
>
external_userid,
</if>
<if
test=
"name != null"
>
name,
</if>
<if
test=
"avatar != null"
>
avatar,
</if>
...
...
@@ -96,7 +129,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if
test=
"position != null"
>
position,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id},
</if>
<if
test=
"externalUserid != null"
>
#{externalUserid},
</if>
<if
test=
"name != null"
>
#{name},
</if>
<if
test=
"avatar != null"
>
#{avatar},
</if>
...
...
@@ -124,17 +156,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if
test=
"corpFullName != null"
>
corp_full_name = #{corpFullName},
</if>
<if
test=
"position != null"
>
position = #{position},
</if>
</trim>
where
id = #{
id}
where
external_userid = #{externalUser
id}
</update>
<delete
id=
"deleteWeCustomerById"
parameterType=
"
Lo
ng"
>
delete from we_customer where
id = #{i
d}
<delete
id=
"deleteWeCustomerById"
parameterType=
"
Stri
ng"
>
delete from we_customer where
external_userid = #{externalUserI
d}
</delete>
<delete
id=
"deleteWeCustomerByIds"
parameterType=
"String"
>
delete from we_customer where
id in
<foreach
item=
"i
d
"
collection=
"array"
open=
"("
separator=
","
close=
")"
>
#{i
d
}
<delete
id=
"deleteWeCustomerByIds"
>
delete from we_customer where
external_userid in
<foreach
item=
"i
tem
"
collection=
"array"
open=
"("
separator=
","
close=
")"
>
#{i
tem
}
</foreach>
</delete>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录