Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
徐少华
midjourney-proxy
Commits
e1163d49
Commit
e1163d49
authored
Nov 06, 2019
by
朱亚洁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
高峰期关键词回复
parent
712acea2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
147 deletions
+111
-147
BookKeywordBizImpl.java
...com/pcloud/book/keywords/biz/impl/BookKeywordBizImpl.java
+109
-146
BookKeyword.Mapper.xml
...src/main/resources/mapper/keywords/BookKeyword.Mapper.xml
+2
-1
No files found.
pcloud-service-book/src/main/java/com/pcloud/book/keywords/biz/impl/BookKeywordBizImpl.java
View file @
e1163d49
...
@@ -2,7 +2,6 @@ package com.pcloud.book.keywords.biz.impl;
...
@@ -2,7 +2,6 @@ package com.pcloud.book.keywords.biz.impl;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Sets
;
import
com.pcloud.appcenter.app.dto.AppDto
;
import
com.pcloud.appcenter.app.dto.AppDto
;
import
com.pcloud.book.base.exception.BookBizException
;
import
com.pcloud.book.base.exception.BookBizException
;
...
@@ -23,7 +22,6 @@ import com.pcloud.book.group.dao.GroupQrcodeDao;
...
@@ -23,7 +22,6 @@ import com.pcloud.book.group.dao.GroupQrcodeDao;
import
com.pcloud.book.group.dao.JoinGroupCipherDao
;
import
com.pcloud.book.group.dao.JoinGroupCipherDao
;
import
com.pcloud.book.group.dto.BookGroupDTO
;
import
com.pcloud.book.group.dto.BookGroupDTO
;
import
com.pcloud.book.group.dto.GroupClassifyQrcodeDTO
;
import
com.pcloud.book.group.dto.GroupClassifyQrcodeDTO
;
import
com.pcloud.book.group.dto.JoinGroupCipherDTO
;
import
com.pcloud.book.group.entity.AppTouchRecord
;
import
com.pcloud.book.group.entity.AppTouchRecord
;
import
com.pcloud.book.group.entity.BookGroup
;
import
com.pcloud.book.group.entity.BookGroup
;
import
com.pcloud.book.group.entity.BookGroupCipherUser
;
import
com.pcloud.book.group.entity.BookGroupCipherUser
;
...
@@ -36,7 +34,6 @@ import com.pcloud.book.group.tools.SendWeixinRequestTools;
...
@@ -36,7 +34,6 @@ import com.pcloud.book.group.tools.SendWeixinRequestTools;
import
com.pcloud.book.group.vo.ClassifyNameVO
;
import
com.pcloud.book.group.vo.ClassifyNameVO
;
import
com.pcloud.book.group.vo.ClassifyVO
;
import
com.pcloud.book.group.vo.ClassifyVO
;
import
com.pcloud.book.group.vo.GroupQrcode4ClassifyVO
;
import
com.pcloud.book.group.vo.GroupQrcode4ClassifyVO
;
import
com.pcloud.book.group.vo.GroupQrcodeBaseInfoVO
;
import
com.pcloud.book.group.vo.ListClassifyVO
;
import
com.pcloud.book.group.vo.ListClassifyVO
;
import
com.pcloud.book.keywords.biz.BookKeywordBiz
;
import
com.pcloud.book.keywords.biz.BookKeywordBiz
;
import
com.pcloud.book.keywords.dao.BookKeywordDao
;
import
com.pcloud.book.keywords.dao.BookKeywordDao
;
...
@@ -100,7 +97,6 @@ import java.util.HashMap;
...
@@ -100,7 +97,6 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.TreeSet
;
import
java.util.TreeSet
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -305,7 +301,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
...
@@ -305,7 +301,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
private
void
checkKeyword
(
String
keywords
,
Long
classifyId
,
Long
bookGroupId
,
Long
keywordId
)
{
private
void
checkKeyword
(
String
keywords
,
Long
classifyId
,
Long
bookGroupId
,
Long
keywordId
)
{
Boolean
isHaveKeyword
=
bookKeywordDao
.
checkKeyword
(
keywords
,
classifyId
,
bookGroupId
,
keywordId
);
Boolean
isHaveKeyword
=
bookKeywordDao
.
checkKeyword
(
keywords
,
classifyId
,
bookGroupId
,
keywordId
);
if
(
isHaveKeyword
)
{
if
(
isHaveKeyword
)
{
throw
new
BookBizException
(
BookBizException
.
ERROR
,
"关键词"
+
keywords
+
"已存在!"
);
throw
new
BookBizException
(
BookBizException
.
ERROR
,
"关键词"
+
keywords
+
"已存在!"
);
}
}
}
}
...
@@ -381,11 +377,11 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
...
@@ -381,11 +377,11 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
bookKeyword
.
setRank
(
setRankVO
.
getRank
());
bookKeyword
.
setRank
(
setRankVO
.
getRank
());
bookKeyword
.
setUpdateUser
(
partyId
);
bookKeyword
.
setUpdateUser
(
partyId
);
KeywordVO
byBookKeyword
=
bookKeywordDao
.
getByBookKeyword
(
setRankVO
.
getBookKeywordId
());
KeywordVO
byBookKeyword
=
bookKeywordDao
.
getByBookKeyword
(
setRankVO
.
getBookKeywordId
());
if
(
byBookKeyword
!=
null
&&
(
byBookKeyword
.
getClassifyId
()
==
null
||
byBookKeyword
.
getClassifyId
()
==
0
)){
if
(
byBookKeyword
!=
null
&&
(
byBookKeyword
.
getClassifyId
()
==
null
||
byBookKeyword
.
getClassifyId
()
==
0
))
{
Long
bookGroupId
=
byBookKeyword
.
getBookGroupId
();
Long
bookGroupId
=
byBookKeyword
.
getBookGroupId
();
Long
keywordId
=
byBookKeyword
.
getKeywordId
();
Long
keywordId
=
byBookKeyword
.
getKeywordId
();
bookKeywordDao
.
updateRank
(
bookGroupId
,
setRankVO
.
getRank
(),
partyId
,
keywordId
);
bookKeywordDao
.
updateRank
(
bookGroupId
,
setRankVO
.
getRank
(),
partyId
,
keywordId
);
}
else
{
}
else
{
bookKeywordDao
.
setRank
(
bookKeyword
);
bookKeywordDao
.
setRank
(
bookKeyword
);
}
}
}
}
...
@@ -469,12 +465,6 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
...
@@ -469,12 +465,6 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
if
(
Objects
.
isNull
(
sendTextDTO
))
{
if
(
Objects
.
isNull
(
sendTextDTO
))
{
return
;
return
;
}
}
// 刘娜需求 1001282 群不推送关键词
final
String
content
=
sendTextDTO
.
getTextContent
().
trim
();
final
String
userWxId
=
sendTextDTO
.
getWechatUserId
();
final
String
ip
=
sendTextDTO
.
getIp
();
final
Integer
code
=
sendTextDTO
.
getCode
();
String
robotId
=
sendTextDTO
.
getWxId
();
if
(
SendMessageTypeEnum
.
GROUP
.
getCode
().
equals
(
sendTextDTO
.
getCode
()))
{
if
(
SendMessageTypeEnum
.
GROUP
.
getCode
().
equals
(
sendTextDTO
.
getCode
()))
{
this
.
sendKeywordMessageToGroup
(
sendTextDTO
);
this
.
sendKeywordMessageToGroup
(
sendTextDTO
);
return
;
return
;
...
@@ -484,128 +474,6 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
...
@@ -484,128 +474,6 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
//判断是否为某个群分类名称
//判断是否为某个群分类名称
inviteToGroupByKeyword
(
sendTextDTO
);
inviteToGroupByKeyword
(
sendTextDTO
);
}
}
//个人机器人接收消息的时候,weixinGroupId就是userWxId,也就是用户的id,robotId是接收的机器人的id
//简单过滤非关键词的词
if
(
StringUtil
.
isEmpty
(
content
)
||
content
.
length
()
>
20
)
{
return
;
}
// TODO 根据小号和用户id获取所有相关的分类id,若该关键词存在多本书,则组装成文本加链接一次发送
final
List
<
JoinGroupCipherDTO
>
dtos
=
bookGroupBiz
.
getClassifyIdsByWxIdAndAltId
(
userWxId
,
robotId
);
if
(
CollectionUtils
.
isEmpty
(
dtos
))
{
log
.
info
(
"[关键词消息回复] classifyIds is null"
);
return
;
}
final
Set
<
Long
>
cIds
=
Sets
.
newHashSet
();
final
Set
<
Long
>
bIds
=
Sets
.
newHashSet
();
Map
<
Long
,
Long
>
classifyToBookGroupMap
=
new
HashMap
<>();
Map
<
Long
,
Long
>
classifyToQrcodeMap
=
new
HashMap
<>();
for
(
JoinGroupCipherDTO
dto
:
dtos
)
{
cIds
.
add
(
dto
.
getClassifyId
());
bIds
.
add
(
dto
.
getBookGroupId
());
classifyToBookGroupMap
.
put
(
dto
.
getClassifyId
(),
dto
.
getBookGroupId
());
classifyToQrcodeMap
.
put
(
dto
.
getClassifyId
(),
dto
.
getQrcodeId
());
}
final
List
<
Long
>
classifyIds
=
Lists
.
newArrayList
(
cIds
);
List
<
ReplyKeywordDTO
>
replyKeywordDTOs
=
new
ArrayList
<>();
Map
<
Long
,
Long
>
keywordClassifyIdMap
=
new
HashMap
<>();
List
<
Long
>
keywordIds
=
new
ArrayList
<>();
for
(
Long
classifyId
:
classifyIds
)
{
//获取匹配关键词
ReplyKeywordDTO
replyKeywordDTO
=
bookKeywordDao
.
getKeywordId
(
classifyId
,
classifyToBookGroupMap
.
get
(
classifyId
),
content
);
if
(
replyKeywordDTO
==
null
)
{
continue
;
}
keywordClassifyIdMap
.
put
(
replyKeywordDTO
.
getKeywordId
(),
classifyId
);
//避免一本书下两个分类的关键词重复
if
(!
keywordIds
.
contains
(
replyKeywordDTO
.
getKeywordId
()))
{
replyKeywordDTOs
.
add
(
replyKeywordDTO
);
keywordIds
.
add
(
replyKeywordDTO
.
getKeywordId
());
}
}
final
List
<
GroupClassifyQrcodeDTO
>
qrcodeDTOS
=
bookGroupClassifyBiz
.
listClassifyQrcodeInfo
(
classifyIds
);
if
(
CollectionUtils
.
isEmpty
(
replyKeywordDTOs
))
{
log
.
info
(
"[关键词消息回复] keywordIds is null"
);
return
;
}
if
(
CollectionUtils
.
isEmpty
(
qrcodeDTOS
))
{
log
.
info
(
"[关键词消息回复] qrcodeDTOS is null"
);
return
;
}
final
Map
<
Long
,
GroupClassifyQrcodeDTO
>
classifyMap
=
qrcodeDTOS
.
stream
().
collect
(
Collectors
.
toMap
(
GroupClassifyQrcodeDTO:
:
getClassifyId
,
p
->
p
,
(
v1
,
v2
)
->
v2
));
// 记录循环插入,消息一条发送
for
(
ReplyKeywordDTO
replyKeywordDTO
:
replyKeywordDTOs
)
{
log
.
info
(
"[关键词回复原始数据] : sendKeywordMessage replyKeywordDTO :{}, robotId:{}, altId:{}"
,
replyKeywordDTO
,
robotId
,
userWxId
);
// 处理链接地址
Long
classifyId
=
keywordClassifyIdMap
.
get
(
replyKeywordDTO
.
getKeywordId
());
final
GroupClassifyQrcodeDTO
dto
=
classifyMap
.
get
(
classifyId
);
if
(
null
==
dto
)
{
log
.
info
(
"[关键词消息回复] 分类信息为空 replyKeywordDTO:{}; classifyMap:{}"
,
replyKeywordDTO
,
classifyMap
);
continue
;
}
final
boolean
isApp
=
ReplyTypeEnum
.
APP
.
value
.
equals
(
replyKeywordDTO
.
getReplyType
());
final
boolean
isLink
=
ReplyTypeEnum
.
LINK
.
value
.
equals
(
replyKeywordDTO
.
getReplyType
());
Long
qrcodeId
=
classifyToQrcodeMap
.
get
(
dto
.
getClassifyId
());
GroupQrcodeBaseInfoVO
qrcodeInfo
=
groupQrcodeDao
.
getBaseById
(
qrcodeId
);
if
(
isApp
||
isLink
)
{
AccountSettingDto
accountSettingDto
=
qrcodeSceneConsr
.
getWechatInfo
(
dto
.
getChannelId
());
String
linkUrl
=
SendWeixinRequestTools
.
splitUrlNew
(
accountSettingDto
,
replyKeywordDTO
.
getLinkUrl
(),
dto
.
getBookGroupId
(),
dto
.
getClassifyId
(),
qrcodeId
);
String
shortUrl4Own
=
UrlUtils
.
getShortUrl4Own
(
linkUrl
);
replyKeywordDTO
.
setLinkUrl
(
linkUrl
);
if
(
replyKeywordDTO
.
getLinkUrl
().
contains
(
"/live/"
))
{
// 获取直播课信息
List
<
CourseListDto
>
list4BroadcastReminder
=
liveCons
.
getList4BroadcastReminder
(
replyKeywordDTO
.
getServeId
(),
replyKeywordDTO
.
getServeType
());
replyKeywordDTO
.
setReplyType
(
ReplyTypeEnum
.
TEXT
.
value
);
StringBuilder
sb
=
new
StringBuilder
(
"【"
);
sb
.
append
(
CollectionUtils
.
isEmpty
(
list4BroadcastReminder
)
?
replyKeywordDTO
.
getDescription
()
:
list4BroadcastReminder
.
get
(
0
).
getTableTitle
())
.
append
(
"】近期将开播的课程\n"
);
if
(!
CollectionUtils
.
isEmpty
(
list4BroadcastReminder
))
{
for
(
CourseListDto
listDto
:
list4BroadcastReminder
)
{
sb
.
append
(
"第"
).
append
(
listDto
.
getSequenceNum
()).
append
(
"课:"
).
append
(
listDto
.
getTitle
()).
append
(
"\n"
);
}
}
sb
.
append
(
"查看更多课程表链接:"
).
append
(
shortUrl4Own
);
replyKeywordDTO
.
setContent
(
sb
.
toString
());
}
if
(!
StringUtil
.
isEmpty
(
linkUrl
))
{
replyKeywordDTO
.
setShortLinkUrl
(
shortUrl4Own
);
}
}
String
redisContent
=
JedisClusterUtils
.
getJson
(
"BOOK:KEYWORD:"
+
userWxId
+
"-"
+
replyKeywordDTO
.
getKeywordId
(),
String
.
class
);
// 同一群10秒内不回复同一关键词
if
(
insertBookKeywordRecord
(
qrcodeInfo
.
getWeixinGroupId
(),
userWxId
,
replyKeywordDTO
,
dto
,
redisContent
))
{
return
;
}
//获取推送消息机器人
// 20190704改为收发一体
if
(
StringUtil
.
isBlank
(
robotId
))
{
log
.
info
(
"[关键词消息回复] robotId is null content:{}, robotId:{},weixinGroupId:{}"
,
content
,
robotId
,
qrcodeInfo
.
getWeixinGroupId
());
robotId
=
wechatGroupConsr
.
getRobotIdByGroupId
(
qrcodeInfo
.
getWeixinGroupId
());
}
log
.
info
(
"[关键词回复发送数据] : sendKeywordMessage replyKeywordDTO :{}, robotId:{}, weixinGroupId:{}"
,
replyKeywordDTO
,
robotId
,
qrcodeInfo
.
getWeixinGroupId
());
//新增关键词触发记录
addKeywordAppTouchRecord
(
replyKeywordDTO
,
qrcodeInfo
.
getWeixinGroupId
(),
dto
.
getClassifyId
(),
dto
.
getBookGroupId
());
}
// 单条还是按原来的发送
if
(
replyKeywordDTOs
.
size
()
<=
1
)
{
SendWeixinRequestTools
.
sendKeywordMessage
(
replyKeywordDTOs
.
get
(
0
),
robotId
,
userWxId
,
ip
,
code
);
}
else
{
// 多条时文字,应用,链接组装成一条发送
ReplyKeywordDTO
d
=
new
ReplyKeywordDTO
();
final
StringBuilder
sb
=
new
StringBuilder
();
for
(
ReplyKeywordDTO
dto
:
replyKeywordDTOs
)
{
if
(
ReplyTypeEnum
.
APP
.
value
.
equals
(
dto
.
getReplyType
())
||
ReplyTypeEnum
.
LINK
.
value
.
equals
(
dto
.
getReplyType
()))
{
sb
.
append
(
dto
.
getKeywords
()).
append
(
":"
).
append
(
dto
.
getShortLinkUrl
()).
append
(
"\n"
);
}
else
if
(
ReplyTypeEnum
.
TEXT
.
value
.
equals
(
dto
.
getReplyType
()))
{
sb
.
append
(
dto
.
getKeywords
()).
append
(
":"
).
append
(
dto
.
getContent
()).
append
(
"\n"
);
}
else
if
(
ReplyTypeEnum
.
IMAGE
.
value
.
equals
(
dto
.
getReplyType
()))
{
SendWeixinRequestTools
.
sendKeywordMessage
(
dto
,
robotId
,
userWxId
,
ip
,
code
);
}
}
d
.
setContent
(
sb
.
toString
());
d
.
setReplyType
(
ReplyTypeEnum
.
TEXT
.
value
);
SendWeixinRequestTools
.
sendKeywordMessage
(
d
,
robotId
,
userWxId
,
ip
,
code
);
}
}
}
@ParamLog
(
"获取的关键词是否为社群书的暗号"
)
@ParamLog
(
"获取的关键词是否为社群书的暗号"
)
...
@@ -614,7 +482,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
...
@@ -614,7 +482,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
if
(
bookGroup
!=
null
)
{
if
(
bookGroup
!=
null
)
{
try
{
try
{
addBookGroupCipherUser
(
sendTextDTO
,
bookGroup
.
getId
());
addBookGroupCipherUser
(
sendTextDTO
,
bookGroup
.
getId
());
dealByBookGroup
(
sendTextDTO
,
bookGroup
.
getId
(),
false
);
dealByBookGroup
(
sendTextDTO
,
bookGroup
.
getId
(),
false
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"拉群出错"
+
e
.
getMessage
());
log
.
error
(
"拉群出错"
+
e
.
getMessage
());
}
}
...
@@ -622,8 +490,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
...
@@ -622,8 +490,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
}
}
@ParamLog
(
"增加暗号对应书记录"
)
@ParamLog
(
"增加暗号对应书记录"
)
private
void
addBookGroupCipherUser
(
SendTextDTO
sendTextDTO
,
Long
bookGroupId
){
private
void
addBookGroupCipherUser
(
SendTextDTO
sendTextDTO
,
Long
bookGroupId
)
{
BookGroupCipherUser
bookGroupCipherUser
=
new
BookGroupCipherUser
();
BookGroupCipherUser
bookGroupCipherUser
=
new
BookGroupCipherUser
();
bookGroupCipherUser
.
setBookGroupCipher
(
sendTextDTO
.
getTextContent
());
bookGroupCipherUser
.
setBookGroupCipher
(
sendTextDTO
.
getTextContent
());
bookGroupCipherUser
.
setBookGroupId
(
bookGroupId
);
bookGroupCipherUser
.
setBookGroupId
(
bookGroupId
);
bookGroupCipherUser
.
setWxUserId
(
sendTextDTO
.
getWechatUserId
());
bookGroupCipherUser
.
setWxUserId
(
sendTextDTO
.
getWechatUserId
());
...
@@ -636,8 +504,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
...
@@ -636,8 +504,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
public
void
dealByBookGroup
(
SendTextDTO
sendTextDTO
,
Long
bookGroupId
,
Boolean
isPushUpdate
)
{
public
void
dealByBookGroup
(
SendTextDTO
sendTextDTO
,
Long
bookGroupId
,
Boolean
isPushUpdate
)
{
BookGroupDTO
bookGroupDTO
=
bookGroupDao
.
getBookBaseInfoById
(
bookGroupId
);
BookGroupDTO
bookGroupDTO
=
bookGroupDao
.
getBookBaseInfoById
(
bookGroupId
);
String
text
=
""
;
String
text
=
""
;
if
(
isPushUpdate
!=
null
&&
isPushUpdate
)
{
if
(
isPushUpdate
!=
null
&&
isPushUpdate
)
{
text
=
text
+
"有更新!\n"
;
text
=
text
+
"有更新!\n"
;
}
}
Boolean
isInviteGroup
=
bookGroupDTO
.
getIsInviteGroup
();
Boolean
isInviteGroup
=
bookGroupDTO
.
getIsInviteGroup
();
// 获取配置的资源服务
// 获取配置的资源服务
...
@@ -722,7 +590,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
...
@@ -722,7 +590,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
@ParamLog
(
"发送收到暗号后的本书介绍"
)
@ParamLog
(
"发送收到暗号后的本书介绍"
)
private
void
sendText
(
SendTextDTO
sendTextDTO
,
String
content
)
{
private
void
sendText
(
SendTextDTO
sendTextDTO
,
String
content
)
{
if
(
StringUtil
.
isEmpty
(
content
)){
if
(
StringUtil
.
isEmpty
(
content
))
{
return
;
return
;
}
}
String
userWxId
=
sendTextDTO
.
getWechatUserId
();
String
userWxId
=
sendTextDTO
.
getWechatUserId
();
...
@@ -787,7 +655,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
...
@@ -787,7 +655,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
sendGroupInviteVO
.
setWxGroupId
(
groupQrcode4ClassifyVO
.
getWeixinGroupId
());
sendGroupInviteVO
.
setWxGroupId
(
groupQrcode4ClassifyVO
.
getWeixinGroupId
());
sendGroupInviteVO
.
setIp
(
sendTextDTO
.
getIp
());
sendGroupInviteVO
.
setIp
(
sendTextDTO
.
getIp
());
WxGroupSDK
.
sendGroupInvite
(
sendGroupInviteVO
);
WxGroupSDK
.
sendGroupInvite
(
sendGroupInviteVO
);
log
.
info
(
"邀请入群"
+
sendGroupInviteVO
.
toString
());
log
.
info
(
"邀请入群"
+
sendGroupInviteVO
.
toString
());
}
}
}
}
}
}
...
@@ -849,10 +717,105 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
...
@@ -849,10 +717,105 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
}
}
// 去除被发送内容完整包含的关键词
// 去除被发送内容完整包含的关键词
List
<
ReplyKeywordDTO
>
collect
=
keywordDTOS
.
stream
().
filter
(
x
->
content
.
contains
(
x
.
getKeywords
())).
collect
(
Collectors
.
toList
());
List
<
ReplyKeywordDTO
>
collect
=
keywordDTOS
.
stream
().
filter
(
x
->
content
.
contains
(
x
.
getKeywords
())).
collect
(
Collectors
.
toList
());
// 组装发送关键词
if
(
ListUtils
.
isEmpty
(
collect
)){
for
(
ReplyKeywordDTO
dto
:
collect
)
{
log
.
info
(
"[关键词消息回复] replyKeywordDTO is null"
);
sendKeyword
(
sendTextDTO
,
dto
,
classifyQrcodeInfo
);
return
;
}
//包含图片或文本的关键词回复
List
<
ReplyKeywordDTO
>
ImgKeyword
=
keywordDTOS
.
stream
()
.
filter
(
p
->
(
ReplyTypeEnum
.
IMAGE
.
value
.
equals
(
p
.
getReplyType
())
||
ReplyTypeEnum
.
TEXT
.
value
.
equals
(
p
.
getReplyType
()))).
collect
(
Collectors
.
toList
());
//不包含图片和文字且18点到9点 则合并关键词详情,其他情况走之前的模式
if
(
CollectionUtils
.
isEmpty
(
ImgKeyword
)
&&
!
DateUtils
.
isInBetweenTimes
(
"13:00:00"
,
"18:00:00"
))
{
sendKeyWordAtPeak
(
collect
,
keywordDTOS
,
classifyQrcodeInfo
,
sendTextDTO
);
}
else
{
// 组装发送关键词
for
(
ReplyKeywordDTO
dto
:
collect
)
{
sendKeyword
(
sendTextDTO
,
dto
,
classifyQrcodeInfo
);
}
}
}
@ParamLog
(
"高峰期关键词发送"
)
public
void
sendKeyWordAtPeak
(
List
<
ReplyKeywordDTO
>
replyKeyWords
,
List
<
ReplyKeywordDTO
>
keywordsAll
,
GroupClassifyQrcodeDTO
classifyQrcodeInfo
,
SendTextDTO
sendTextDTO
)
{
final
String
ip
=
sendTextDTO
.
getIp
();
final
Integer
code
=
sendTextDTO
.
getCode
();
final
String
weixinGroupId
=
sendTextDTO
.
getWechatGroupId
();
final
String
userWxId
=
sendTextDTO
.
getWechatUserId
();
String
robotId
=
sendTextDTO
.
getWxId
();
if
(
StringUtil
.
isBlank
(
robotId
))
{
log
.
info
(
"[关键词消息回复] robotId is null :{}, robotId:{},weixinGroupId:{}"
,
robotId
,
weixinGroupId
);
robotId
=
wechatGroupConsr
.
getRobotIdByGroupId
(
weixinGroupId
);
}
//10min内不回复关键词
String
redisContent
=
JedisClusterUtils
.
getJson
(
"BOOK:KEYWORD_PEAK:"
+
weixinGroupId
,
String
.
class
);
if
(!
StringUtil
.
isEmpty
(
redisContent
))
{
insertBookKeywordRecord
(
classifyQrcodeInfo
,
replyKeyWords
.
get
(
0
).
getKeywordId
(),
userWxId
,
weixinGroupId
,
false
);
return
;
}
else
{
JedisClusterUtils
.
setJson
(
"BOOK:KEYWORD_PEAK:"
+
weixinGroupId
,
weixinGroupId
,
10
*
60
);
insertBookKeywordRecord
(
classifyQrcodeInfo
,
replyKeyWords
.
get
(
0
).
getKeywordId
(),
userWxId
,
weixinGroupId
,
true
);
}
AccountSettingDto
accountSettingDto
=
qrcodeSceneConsr
.
getWechatInfo
(
classifyQrcodeInfo
.
getChannelId
());
StringBuilder
sb
=
new
StringBuilder
();
//目标关键词回复+文案
combineKeyWord
(
replyKeyWords
,
classifyQrcodeInfo
,
accountSettingDto
,
sb
);
if
(
keywordsAll
.
size
()>
replyKeyWords
.
size
()){
sb
.
append
(
"--------------------------------\n为避免晚间群消息干扰,10分钟内只响应一次关键词,请直接点击下面的链接,获取本群其他资源服务:\n\n"
);
//剩余关键词回复
for
(
ReplyKeywordDTO
replyKeywordDTO
:
keywordsAll
)
{
List
<
ReplyKeywordDTO
>
collect
=
replyKeyWords
.
stream
().
filter
(
x
->
replyKeywordDTO
.
getKeywords
().
equals
(
x
.
getKeywords
())).
collect
(
Collectors
.
toList
());
if
(!
ListUtils
.
isEmpty
(
collect
)){
continue
;
}
List
<
ReplyKeywordDTO
>
addKeyWordList
=
new
ArrayList
<>();
addKeyWordList
.
add
(
replyKeywordDTO
);
StringBuilder
toAdd
=
combineKeyWord
(
addKeyWordList
,
classifyQrcodeInfo
,
accountSettingDto
,
new
StringBuilder
());
StringBuilder
content
=
sb
.
append
(
toAdd
);
if
(
content
.
length
()
>
LE
)
{
replyKeywordDTO
.
setReplyType
(
ReplyTypeEnum
.
TEXT
.
value
);
replyKeywordDTO
.
setContent
(
sb
.
toString
());
SendWeixinRequestTools
.
sendKeywordMessage
(
replyKeywordDTO
,
robotId
,
weixinGroupId
,
ip
,
code
);
sb
=
toAdd
;
}
else
{
sb
=
content
;
}
}
}
ReplyKeywordDTO
keywordDTO
=
replyKeyWords
.
get
(
0
);
keywordDTO
.
setReplyType
(
ReplyTypeEnum
.
TEXT
.
value
);
keywordDTO
.
setContent
(
sb
.
toString
());
SendWeixinRequestTools
.
sendKeywordMessage
(
keywordDTO
,
robotId
,
weixinGroupId
,
ip
,
code
);
for
(
ReplyKeywordDTO
replyKeywordDTO
:
replyKeyWords
)
{
//新增关键词触发记录
addKeywordAppTouchRecord
(
replyKeywordDTO
,
weixinGroupId
,
classifyQrcodeInfo
.
getClassifyId
(),
classifyQrcodeInfo
.
getBookGroupId
());
//第一推送关键词消息埋点
String
keywordsKey
=
"BOOK:FIRSTKEYWORD:"
+
DateUtils
.
getShortDateStr
()
+
"-"
+
weixinGroupId
;
Boolean
isSend
=
JedisClusterUtils
.
getJson
(
keywordsKey
,
Boolean
.
class
);
if
(
isSend
!=
null
&&
isSend
)
{
return
;
}
JedisClusterUtils
.
setJson
(
keywordsKey
,
true
);
JedisClusterUtils
.
expire
(
keywordsKey
,
86400
);
RobotReplyDTO
robotReplyDTO
=
new
RobotReplyDTO
();
robotReplyDTO
.
setKeyWord
(
sendTextDTO
.
getTextContent
().
trim
());
robotReplyDTO
.
setWxGroupId
(
weixinGroupId
);
robotReplyDTO
.
setWxUserId
(
userWxId
);
wechatGroupConsr
.
addFirstRobotReplyRecord
(
robotReplyDTO
);
}
}
/**
*合并关键词回复
*/
private
StringBuilder
combineKeyWord
(
List
<
ReplyKeywordDTO
>
keywordsAll
,
GroupClassifyQrcodeDTO
classifyQrcodeInfo
,
AccountSettingDto
accountSettingDto
,
StringBuilder
sb
)
{
for
(
ReplyKeywordDTO
keyword
:
keywordsAll
)
{
if
(
ReplyTypeEnum
.
LINK
.
value
.
equals
(
keyword
.
getReplyType
())
||
ReplyTypeEnum
.
APP
.
value
.
equals
(
keyword
.
getReplyType
()))
{
String
linkUrl
=
SendWeixinRequestTools
.
splitUrlNew
(
accountSettingDto
,
keyword
.
getLinkUrl
(),
classifyQrcodeInfo
.
getBookGroupId
(),
classifyQrcodeInfo
.
getClassifyId
(),
classifyQrcodeInfo
.
getGroupQrcodeId
());
sb
.
append
(
" "
).
append
(
keyword
.
getContent
()).
append
(
"\n->"
).
append
(
UrlUtils
.
getShortUrl4Own
(
linkUrl
)).
append
(
"\n"
).
append
(
"\n"
);
}
}
}
return
sb
;
}
}
/**
/**
...
...
pcloud-service-book/src/main/resources/mapper/keywords/BookKeyword.Mapper.xml
View file @
e1163d49
...
@@ -228,7 +228,8 @@
...
@@ -228,7 +228,8 @@
bk.is_delete = 0 AND k.is_delete = 0
bk.is_delete = 0 AND k.is_delete = 0
AND classify_id in (0, ${classifyId})
AND classify_id in (0, ${classifyId})
AND book_group_id = #{bookGroupId}
AND book_group_id = #{bookGroupId}
order by set_type desc, matching_rule desc, bk.id desc
GROUP BY k.id
order by set_type desc, matching_rule desc, bk.id desc
</select>
</select>
<select
id=
"getKeywordIds"
resultType=
"ReplyKeywordDTO"
parameterType=
"map"
>
<select
id=
"getKeywordIds"
resultType=
"ReplyKeywordDTO"
parameterType=
"map"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment