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 d9e72060
authored
Apr 01, 2021
by
YaoYuHang
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
社群运营-企微消息推送异步化
1 parent
29600aa5
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
82 additions
and
47 deletions
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCommunityGroupSopController.java
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCommunityH5Controller.java
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCommunityPresTagGroupController.java
linkwe-admin/src/main/resources/application.yml
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WePresTagGroupTask.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeGroupSopService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWePresTagGroupTaskService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeGroupSopServiceImpl.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WePresTagGroupTaskServiceImpl.java
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCommunityGroupSopController.java
View file @
d9e7206
...
...
@@ -76,7 +76,12 @@ public class WeCommunityGroupSopController extends BaseController {
List
<
Long
>
materialIdList
=
groupSopDto
.
getMaterialIdList
();
// 上传的图片的URl列表
List
<
String
>
picList
=
groupSopDto
.
getPicList
();
return
toAjax
(
groupSopService
.
addGroupSop
(
weGroupSop
,
groupIdList
,
materialIdList
,
picList
));
int
affectedRows
=
groupSopService
.
addGroupSop
(
weGroupSop
,
groupIdList
,
materialIdList
,
picList
);
if
(
affectedRows
>
0
)
{
// 添加成功后进行异步消息推送
groupSopService
.
sendMessage
(
groupIdList
);
}
return
toAjax
(
affectedRows
);
}
/**
...
...
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCommunityH5Controller.java
View file @
d9e7206
...
...
@@ -80,7 +80,7 @@ public class WeCommunityH5Controller extends BaseController {
res
.
put
(
"todo"
,
todoList
);
doneList
.
addAll
(
tagGroupTaskService
.
getEmplTaskList
(
emplId
,
true
));
doneList
.
addAll
(
sopService
.
getEmplTaskList
(
emplId
,
true
));
res
.
put
(
"done"
,
todo
List
);
res
.
put
(
"done"
,
done
List
);
}
SysUser
user
=
userService
.
selectUserByUserName
(
emplId
);
boolean
isAdmin
=
user
!=
null
&&
user
.
isAdmin
();
...
...
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCommunityPresTagGroupController.java
View file @
d9e7206
...
...
@@ -5,6 +5,10 @@ import com.linkwechat.common.constant.HttpStatus;
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.utils.SecurityUtils
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.common.utils.bean.BeanUtils
;
import
com.linkwechat.wecom.domain.WePresTagGroupTask
;
import
com.linkwechat.wecom.domain.dto.WePresTagGroupTaskDto
;
import
com.linkwechat.wecom.domain.vo.WePresTagGroupTaskStatVo
;
import
com.linkwechat.wecom.domain.vo.WePresTagGroupTaskVo
;
...
...
@@ -56,7 +60,18 @@ public class WeCommunityPresTagGroupController extends BaseController {
if
(
null
==
groupCodeService
.
selectWeGroupCodeById
(
wePresTagGroupTaskDto
.
getGroupCodeId
()))
{
return
AjaxResult
.
error
(
HttpStatus
.
NOT_FOUND
,
"群活码不存在"
);
}
return
toAjax
(
taskService
.
add
(
wePresTagGroupTaskDto
));
// 创建新任务并保存
WePresTagGroupTask
task
=
new
WePresTagGroupTask
();
BeanUtils
.
copyProperties
(
wePresTagGroupTaskDto
,
task
);
task
.
setCreateBy
(
SecurityUtils
.
getUsername
());
List
<
String
>
tagList
=
wePresTagGroupTaskDto
.
getTagList
();
List
<
String
>
scopeList
=
wePresTagGroupTaskDto
.
getScopeList
();
int
affectedRows
=
taskService
.
add
(
task
,
tagList
,
scopeList
);
if
(
affectedRows
>
0
)
{
// 若保存成功,则进行异步消息推送
taskService
.
sendMessage
(
task
);
}
return
toAjax
(
affectedRows
);
}
/**
...
...
@@ -65,7 +80,11 @@ public class WeCommunityPresTagGroupController extends BaseController {
// @PreAuthorize("@ss.hasPermi('wecom:communitytagGroup:query')")
@GetMapping
(
path
=
"/{id}"
)
public
AjaxResult
getTask
(
@PathVariable
(
"id"
)
Long
id
)
{
return
AjaxResult
.
success
(
taskService
.
getTaskById
(
id
));
WePresTagGroupTaskVo
taskVo
=
taskService
.
getTaskById
(
id
);
if
(
StringUtils
.
isNull
(
taskVo
))
{
return
AjaxResult
.
error
(
HttpStatus
.
NOT_FOUND
,
"群活码不存在"
);
}
return
AjaxResult
.
success
();
}
/**
...
...
linkwe-admin/src/main/resources/application.yml
View file @
d9e7206
...
...
@@ -224,7 +224,7 @@ wecome:
# JS SDK 身份校验url
authorizeUrl
:
https://open.weixin.qq.com/connect/oauth2/authorize
# JS SDK身份校验成功后的redirect url
authorizeRedirectUrl
:
http://linkwechat.cn/mobile/#/task
authorizeRedirectUrl
:
http://
www.
linkwechat.cn/mobile/#/task
#腾讯云对象存储
cos
:
secretId
:
AKIDQRCizIeUGl13vakkDQMH0VkjhPr1rBBv
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WePresTagGroupTask.java
View file @
d9e7206
...
...
@@ -19,7 +19,7 @@ public class WePresTagGroupTask extends BaseEntity {
*主键ID
*/
@TableId
private
Long
taskId
=
SnowFlakeUtil
.
nextId
();
;
private
Long
taskId
=
SnowFlakeUtil
.
nextId
();
/**
* 任务名称
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeGroupSopService.java
View file @
d9e7206
package
com
.
linkwechat
.
wecom
.
service
;
import
com.linkwechat.wecom.domain.WeGroup
;
import
com.linkwechat.wecom.domain.WeGroupSop
;
import
com.linkwechat.wecom.domain.vo.WeCommunityTaskEmplVo
;
import
com.linkwechat.wecom.domain.vo.WeGroupSopVo
;
...
...
@@ -95,4 +96,10 @@ public interface IWeGroupSopService {
* @return 结果
*/
List
<
WeCommunityTaskEmplVo
>
getScopeListByRuleId
(
Long
ruleId
);
/**
* 向指定的群聊进行sop企微消息推送
* @param groupIdList 群聊id列表
*/
void
sendMessage
(
List
<
String
>
groupIdList
);
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWePresTagGroupTaskService.java
View file @
d9e7206
package
com
.
linkwechat
.
wecom
.
service
;
import
com.linkwechat.wecom.domain.WePresTagGroupTask
;
import
com.linkwechat.wecom.domain.WeTag
;
import
com.linkwechat.wecom.domain.dto.WePresTagGroupTaskDto
;
import
com.linkwechat.wecom.domain.vo.WeCommunityTaskEmplVo
;
...
...
@@ -14,12 +15,13 @@ import java.util.List;
public
interface
IWePresTagGroupTaskService
{
/**
* 新增建群任务
*
* @param taskDto 建群所需数据
* @return 数据库新增行数
* 添加新标签建群任务
* @param task 建群任务本体信息
* @param tagIdList 标签列表
* @param emplIdList 员工列表
* @return 结果
*/
int
add
(
WePresTagGroupTask
Dto
taskDto
);
int
add
(
WePresTagGroupTask
task
,
List
<
String
>
tagIdList
,
List
<
String
>
emplIdList
);
/**
* 根据条件查询任务列表
...
...
@@ -108,4 +110,10 @@ public interface IWePresTagGroupTaskService {
* @return 结果
*/
int
updateEmplTaskStatus
(
Long
taskId
,
String
emplId
);
/**
* 根据标签建群任务信息发送消息
* @param task 标签建群任务
*/
void
sendMessage
(
WePresTagGroupTask
task
);
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeGroupSopServiceImpl.java
View file @
d9e7206
...
...
@@ -18,6 +18,7 @@ import com.linkwechat.wecom.service.IWeGroupSopService;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -55,15 +56,12 @@ public class WeGroupSopServiceImpl extends ServiceImpl<WeGroupSopMapper, WeGroup
@Autowired
private
WeMessagePushClient
messagePushClient
;
@Value
(
"${wecome.authorizeUrl"
)
@Value
(
"${wecome.authorizeUrl
}
"
)
private
String
authorizeUrl
;
@Value
(
"${wecome.authorizeRedirectUrl"
)
@Value
(
"${wecome.authorizeRedirectUrl
}
"
)
private
String
authorizeRedirectUrl
;
@Value
(
"${wecome.callBack.appIdOrCorpId}"
)
private
String
corpId
;
/**
* 通过规则id获取sop规则
*
...
...
@@ -73,7 +71,9 @@ public class WeGroupSopServiceImpl extends ServiceImpl<WeGroupSopMapper, WeGroup
@Override
public
WeGroupSopVo
getGroupSopById
(
Long
ruleId
)
{
WeGroupSopVo
groupSopVo
=
groupSopMapper
.
getGroupSopById
(
ruleId
);
this
.
setChatAndMaterialAndPicList
(
groupSopVo
);
if
(
StringUtils
.
isNotNull
(
groupSopVo
))
{
setChatAndMaterialAndPicList
(
groupSopVo
);
}
return
groupSopVo
;
}
...
...
@@ -114,7 +114,6 @@ public class WeGroupSopServiceImpl extends ServiceImpl<WeGroupSopMapper, WeGroup
if
(
StringUtils
.
isNotEmpty
(
sopPicList
))
{
sopPicMapper
.
batchSopPic
(
sopPicList
);
}
this
.
sendMessage
(
ruleId
);
return
1
;
}
return
0
;
...
...
@@ -319,17 +318,23 @@ public class WeGroupSopServiceImpl extends ServiceImpl<WeGroupSopMapper, WeGroup
/**
* 消息推送(企微API 消息推送 - 发送应用消息)
*/
private
void
sendMessage
(
Long
ruleId
)
{
@Override
@Async
public
void
sendMessage
(
List
<
String
>
groupIdList
)
{
// 构造请求参数
WeMessagePushDto
pushDto
=
new
WeMessagePushDto
();
// 根据群聊获取员工(群主)列表
List
<
WeGroup
>
groupList
=
this
.
getGroupListByRuleId
(
ruleId
);
// 查询群聊列表,获取群主列表
QueryWrapper
<
WeGroup
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
in
(
"chat_id"
,
groupIdList
);
List
<
WeGroup
>
groupList
=
groupMapper
.
selectList
(
queryWrapper
);
String
toUser
=
groupList
.
stream
().
map
(
WeGroup:
:
getOwner
).
collect
(
Collectors
.
joining
(
"|"
));
pushDto
.
setTouser
(
toUser
);
// 获取agentId
WeCorpAccount
validWeCorpAccount
=
corpAccountService
.
findValidWeCorpAccount
();
String
agentId
=
validWeCorpAccount
.
getAgentId
();
String
corpId
=
validWeCorpAccount
.
getCorpId
();
if
(
StringUtils
.
isEmpty
(
agentId
))
{
throw
new
WeComException
(
"当前agentId不可用或不存在"
);
}
...
...
@@ -341,7 +346,7 @@ public class WeGroupSopServiceImpl extends ServiceImpl<WeGroupSopMapper, WeGroup
TextMessageDto
text
=
new
TextMessageDto
();
String
REDIRECT_URI
=
URLEncoder
.
encode
(
String
.
format
(
"%s?corpId=%s&agentId=%s&type=%s"
,
authorizeRedirectUrl
,
corpId
,
agentId
,
CommunityTaskType
.
SOP
.
getType
()));
String
context
=
String
.
format
(
"你有
一个新任务
,<a href='%s?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect'>请点击此链接查看</a>"
,
"你有
新的SOP待发送
,<a href='%s?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect'>请点击此链接查看</a>"
,
authorizeUrl
,
corpId
,
REDIRECT_URI
);
text
.
setContent
(
context
);
pushDto
.
setText
(
text
);
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WePresTagGroupTaskServiceImpl.java
View file @
d9e7206
...
...
@@ -27,6 +27,7 @@ import com.linkwechat.wecom.service.*;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -76,28 +77,18 @@ public class WePresTagGroupTaskServiceImpl extends ServiceImpl<WePresTagGroupTas
@Value
(
"${wecome.authorizeRedirectUrl}"
)
private
String
authorizeRedirectUrl
;
@Value
(
"${wecome.callBack.appIdOrCorpId}"
)
private
String
corpId
;
/**
* 新增建群任务
*
* @param taskDto 建群所需数据
* @return 数据库新增行数
* 添加新标签建群任务
* @param task 建群任务本体信息
* @param tagIdList 标签列表
* @param emplIdList 员工列表
* @return 结果
*/
@Override
@Transactional
public
int
add
(
WePresTagGroupTaskDto
taskDto
)
{
// 创建WeCommunityOldGroup对象进行存储
WePresTagGroupTask
task
=
new
WePresTagGroupTask
();
BeanUtils
.
copyProperties
(
taskDto
,
task
);
task
.
setCreateBy
(
SecurityUtils
.
getUsername
());
int
res
=
0
;
public
int
add
(
WePresTagGroupTask
task
,
List
<
String
>
tagIdList
,
List
<
String
>
emplIdList
)
{
if
(
taskMapper
.
insertTask
(
task
)
>
0
)
{
// 保存标签对象
List
<
String
>
tagIdList
=
taskDto
.
getTagList
();
if
(
CollectionUtil
.
isNotEmpty
(
tagIdList
))
{
List
<
WePresTagGroupTaskTag
>
taskTagList
=
tagIdList
.
stream
()
...
...
@@ -107,7 +98,6 @@ public class WePresTagGroupTaskServiceImpl extends ServiceImpl<WePresTagGroupTas
}
// 保存员工信息
List
<
String
>
emplIdList
=
taskDto
.
getScopeList
();
if
(
CollectionUtil
.
isNotEmpty
(
emplIdList
))
{
List
<
WePresTagGroupTaskScope
>
wePresTagGroupTaskScopeList
=
emplIdList
.
stream
()
...
...
@@ -115,13 +105,9 @@ public class WePresTagGroupTaskServiceImpl extends ServiceImpl<WePresTagGroupTas
.
collect
(
Collectors
.
toList
());
taskScopeMapper
.
batchBindsTaskScopes
(
wePresTagGroupTaskScopeList
);
}
this
.
sendMessage
(
task
);
res
=
1
;
return
1
;
}
return
res
;
return
0
;
}
/**
...
...
@@ -153,7 +139,9 @@ public class WePresTagGroupTaskServiceImpl extends ServiceImpl<WePresTagGroupTas
@Override
public
WePresTagGroupTaskVo
getTaskById
(
Long
taskId
)
{
WePresTagGroupTaskVo
taskVo
=
taskMapper
.
selectTaskById
(
taskId
);
this
.
setGroupCodeAndScopeAndTag
(
taskVo
);
if
(
StringUtils
.
isNotNull
(
taskVo
))
{
setGroupCodeAndScopeAndTag
(
taskVo
);
}
return
taskVo
;
}
...
...
@@ -348,7 +336,9 @@ public class WePresTagGroupTaskServiceImpl extends ServiceImpl<WePresTagGroupTas
*
* @param task 建群任务
*/
private
void
sendMessage
(
WePresTagGroupTask
task
)
{
@Override
@Async
public
void
sendMessage
(
WePresTagGroupTask
task
)
{
try
{
Integer
sendType
=
task
.
getSendType
();
...
...
@@ -423,6 +413,7 @@ public class WePresTagGroupTaskServiceImpl extends ServiceImpl<WePresTagGroupTas
// 获取agentId
WeCorpAccount
validWeCorpAccount
=
corpAccountService
.
findValidWeCorpAccount
();
String
agentId
=
validWeCorpAccount
.
getAgentId
();
String
corpId
=
validWeCorpAccount
.
getCorpId
();
if
(
StringUtils
.
isEmpty
(
agentId
))
{
throw
new
WeComException
(
"当前agentId不可用或不存在"
);
}
...
...
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