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
d79b8465
Commit
d79b8465
authored
Feb 03, 2020
by
桂前礼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finished
parent
175df8c6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
325 additions
and
76 deletions
+325
-76
BookGuideDelayDto.java
...main/java/com/pcloud/book/book/dto/BookGuideDelayDto.java
+23
-0
BookGuideBizImpl.java
...a/com/pcloud/book/keywords/biz/impl/BookGuideBizImpl.java
+17
-57
BookKeywordBizImpl.java
...com/pcloud/book/keywords/biz/impl/BookKeywordBizImpl.java
+94
-19
SelfRobotKeywordDao.java
...ava/com/pcloud/book/keywords/dao/SelfRobotKeywordDao.java
+2
-0
SelfRobotKeywordDaoImpl.java
...cloud/book/keywords/dao/impl/SelfRobotKeywordDaoImpl.java
+8
-0
KeyWordDelayRunner.java
...a/com/pcloud/book/keywords/runner/KeyWordDelayRunner.java
+173
-0
SelfRobotKeyword.xml
...book/src/main/resources/mapper/group/SelfRobotKeyword.xml
+8
-0
No files found.
pcloud-facade-book/src/main/java/com/pcloud/book/book/dto/BookGuideDelayDto.java
0 → 100644
View file @
d79b8465
package
com
.
pcloud
.
book
.
book
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.Date
;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public
class
BookGuideDelayDto
{
private
String
userWxId
;
private
Date
expireTime
;
private
String
keyword
;
private
String
ip
;
}
pcloud-service-book/src/main/java/com/pcloud/book/keywords/biz/impl/BookGuideBizImpl.java
View file @
d79b8465
package
com
.
pcloud
.
book
.
keywords
.
biz
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.pcloud.book.base.exception.BookBizException
;
import
com.pcloud.book.book.constant.BookConstant
;
import
com.pcloud.book.book.dto.BookGuideDelayDto
;
import
com.pcloud.book.consumer.channel.QrcodeSceneConsr
;
import
com.pcloud.book.consumer.content.ResourceConsr
;
import
com.pcloud.book.consumer.resource.ProductConsr
;
...
...
@@ -41,6 +43,7 @@ import com.pcloud.book.weixinclock.dao.WeixinClockGroupClassifyDao;
import
com.pcloud.book.weixinclock.dto.WeixinClockDto
;
import
com.pcloud.channelcenter.wechat.dto.AccountSettingDto
;
import
com.pcloud.common.core.aspect.ParamLog
;
import
com.pcloud.common.utils.DateUtils
;
import
com.pcloud.common.utils.ListUtils
;
import
com.pcloud.common.utils.cache.redis.JedisClusterUtils
;
import
com.pcloud.common.utils.httpclient.UrlUtils
;
...
...
@@ -64,6 +67,7 @@ import org.springframework.transaction.annotation.Transactional;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -158,63 +162,19 @@ public class BookGuideBizImpl implements BookGuideBiz {
bookGroupCipherUserDao
.
insert
(
bookGroupCipherUser
);
//好友引导语
sendFriendGuide
(
bookGroupId
,
agreeAddUserDTO
);
//回复关键词引导语
List
<
SelfRobotKeyword
>
selfRobotKeywords
=
selfRobotKeywordDao
.
getListByBookGroupId
(
bookGroupId
);
if
(!
ListUtils
.
isEmpty
(
selfRobotKeywords
)){
ThreadPoolUtils
.
SEND_MESSAGE_THREAD_POOL
.
execute
(()->{
for
(
SelfRobotKeyword
selfRobotKeyword:
selfRobotKeywords
){
try
{
if
(
"长江作业本"
.
equals
(
selfRobotKeyword
.
getKeyword
())){
Thread
.
sleep
(
1000
*
60
*
10
);
}
if
(!
StringUtil
.
isEmpty
(
selfRobotKeyword
.
getGuide
())){
SendTextMessageVO
vo
=
new
SendTextMessageVO
();
vo
.
setContent
(
selfRobotKeyword
.
getGuide
());
vo
.
setCode
(
SendMessageTypeEnum
.
SELF
.
getCode
());
vo
.
setWxId
(
agreeAddUserDTO
.
getRobotWxId
());
vo
.
setAltId
(
agreeAddUserDTO
.
getRobotWxId
());
vo
.
setWxGroupId
(
agreeAddUserDTO
.
getUserWxId
());
vo
.
setIp
(
agreeAddUserDTO
.
getIp
());
WxGroupSDK
.
sendTextMessage
(
vo
);
log
.
info
(
"临时demo发送个人号加好友信息"
+
vo
.
toString
());
}
if
(
"学前"
.
equals
(
selfRobotKeyword
.
getKeyword
())
&&
envStr
.
toUpperCase
().
equals
(
"PRO"
)&&
agreeAddUserDTO
.
getRobotWxId
().
equals
(
"wxid_x8i897ryabo722"
)){
SendGroupInviteVO
sendGroupInviteVO
=
new
SendGroupInviteVO
();
sendGroupInviteVO
.
setAltId
(
agreeAddUserDTO
.
getRobotWxId
());
sendGroupInviteVO
.
setWxId
(
agreeAddUserDTO
.
getUserWxId
());
sendGroupInviteVO
.
setWxGroupId
(
"23084048866@chatroom"
);
sendGroupInviteVO
.
setIp
(
agreeAddUserDTO
.
getIp
());
WxGroupSDK
.
sendGroupInvite
(
sendGroupInviteVO
);
log
.
info
(
"临时发送入群连接 sendGroupInviteVO:{}"
,
sendGroupInviteVO
);
}
if
(
"教辅书单"
.
equals
(
selfRobotKeyword
.
getKeyword
())){
List
<
SelfRobotKeywordReply
>
replyList
=
selfRobotKeywordReplyDao
.
getListByKeywordId
(
selfRobotKeyword
.
getId
());
if
(
ListUtils
.
isEmpty
(
replyList
)){
continue
;
}
for
(
SelfRobotKeywordReply
keywordReply
:
replyList
){
if
(
ReplyTypeEnum
.
RESOURCE
.
value
.
equals
(
keywordReply
.
getType
())){
SendFileVO
sendFileVO
=
new
SendFileVO
();
Map
<
Long
,
ResourceDTO
>
map
=
resourceConsr
.
mapByIds
(
Arrays
.
asList
(
keywordReply
.
getResourceId
()));
ResourceDTO
resourceDTO
=
map
.
get
(
keywordReply
.
getResourceId
());
if
(
resourceDTO
!=
null
)
{
sendFileVO
.
setFileUrl
(
resourceDTO
.
getFileUrl
());
sendFileVO
.
setFileName
(
resourceDTO
.
getResourceName
());
}
sendFileVO
.
setIp
(
agreeAddUserDTO
.
getIp
());
sendFileVO
.
setAltId
(
agreeAddUserDTO
.
getRobotWxId
());
sendFileVO
.
setWxId
(
agreeAddUserDTO
.
getUserWxId
());
WxGroupSDK
.
sendFile
(
sendFileVO
);
}
}
}
Thread
.
sleep
(
1000
*
40
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"发消息休眠5秒出错"
,
e
);
}
}
});
// TODO 引导语发送后 查询等待时间
int
time
=
60
;
// 向缓存中写入相关信息 延迟推送时间
if
(
envStr
.
toUpperCase
().
equals
(
"TEST"
)
&&
agreeAddUserDTO
.
getRobotWxId
().
equals
(
"wxid_zus32xb5ukjn22"
)
||
envStr
.
toUpperCase
().
equals
(
"UAT"
)
&&
agreeAddUserDTO
.
getRobotWxId
().
equals
(
"wxid_p7gywuxkk89112"
)
||
envStr
.
toUpperCase
().
equals
(
"PRO"
)
&&
agreeAddUserDTO
.
getRobotWxId
().
equals
(
"wxid_x8i897ryabo722"
))
{
List
<
SelfRobotKeyword
>
selfRobotKeywords
=
selfRobotKeywordDao
.
getListByBookGroupId
(
bookGroupId
);
BookGuideDelayDto
delayDto
=
new
BookGuideDelayDto
(
agreeAddUserDTO
.
getUserWxId
(),
DateUtils
.
addSecond
(
new
Date
(),
time
),
selfRobotKeywords
.
get
(
0
).
getKeyword
(),
agreeAddUserDTO
.
getIp
());
log
.
info
(
"[向缓存中写入相关信息 延迟推送时间]:{}"
,
JSONObject
.
toJSONString
(
delayDto
));
// 加好友 清除历史
JedisClusterUtils
.
hdel
(
agreeAddUserDTO
.
getRobotWxId
()+
"_DELAY_PUSH"
,
agreeAddUserDTO
.
getUserWxId
());
JedisClusterUtils
.
hset
(
agreeAddUserDTO
.
getRobotWxId
()+
"_DELAY_PUSH"
,
agreeAddUserDTO
.
getUserWxId
(),
JSONObject
.
toJSONString
(
delayDto
));
}
return
;
}
...
...
pcloud-service-book/src/main/java/com/pcloud/book/keywords/biz/impl/BookKeywordBizImpl.java
View file @
d79b8465
This diff is collapsed.
Click to expand it.
pcloud-service-book/src/main/java/com/pcloud/book/keywords/dao/SelfRobotKeywordDao.java
View file @
d79b8465
...
...
@@ -30,5 +30,7 @@ public interface SelfRobotKeywordDao extends BaseDao<SelfRobotKeyword> {
List
<
String
>
getKeywords
(
Long
bookGroupId
);
SelfRobotKeyword
getNextKeyWord
(
Long
bookGroupId
,
String
keyword
);
List
<
SelfRobotKeyword
>
getListByBookGroupIds
(
List
<
Long
>
bookGroupIds
);
}
pcloud-service-book/src/main/java/com/pcloud/book/keywords/dao/impl/SelfRobotKeywordDaoImpl.java
View file @
d79b8465
...
...
@@ -79,6 +79,14 @@ public class SelfRobotKeywordDaoImpl extends BaseDaoImpl<SelfRobotKeyword> imple
}
@Override
public
SelfRobotKeyword
getNextKeyWord
(
Long
bookGroupId
,
String
keyword
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"bookGroupId"
,
bookGroupId
);
map
.
put
(
"keyword"
,
keyword
);
return
this
.
getSqlSession
().
selectOne
(
this
.
getStatement
(
"getNextKeyWord"
),
map
);
}
@Override
public
List
<
SelfRobotKeyword
>
getListByBookGroupIds
(
List
<
Long
>
bookGroupIds
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"bookGroupIds"
,
bookGroupIds
);
...
...
pcloud-service-book/src/main/java/com/pcloud/book/keywords/runner/KeyWordDelayRunner.java
0 → 100644
View file @
d79b8465
package
com
.
pcloud
.
book
.
keywords
.
runner
;
import
com.alibaba.fastjson.JSONObject
;
import
com.pcloud.book.book.dto.BookGuideDelayDto
;
import
com.pcloud.book.consumer.content.ResourceConsr
;
import
com.pcloud.book.keywords.biz.BookKeywordBiz
;
import
com.pcloud.book.keywords.dao.SelfRobotKeywordDao
;
import
com.pcloud.book.keywords.dao.SelfRobotKeywordReplyDao
;
import
com.pcloud.book.keywords.entity.SelfRobotKeyword
;
import
com.pcloud.book.keywords.entity.SelfRobotKeywordReply
;
import
com.pcloud.book.keywords.enums.ReplyTypeEnum
;
import
com.pcloud.common.utils.DateUtils
;
import
com.pcloud.common.utils.ListUtils
;
import
com.pcloud.common.utils.cache.redis.JedisClusterUtils
;
import
com.pcloud.contentcenter.resource.dto.ResourceDTO
;
import
com.sdk.wxgroup.SendFileVO
;
import
com.sdk.wxgroup.SendGroupInviteVO
;
import
com.sdk.wxgroup.SendMessageTypeEnum
;
import
com.sdk.wxgroup.SendTextMessageVO
;
import
com.sdk.wxgroup.WxGroupSDK
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.stereotype.Component
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* 项目启动制行的任务
*
* @author Gui_q
* @since 2020年2月3日 12点14分
*/
@Component
@Slf4j
public
class
KeyWordDelayRunner
implements
ApplicationRunner
{
@Value
(
"${system.env}"
)
private
String
envStr
;
@Autowired
private
SelfRobotKeywordDao
selfRobotKeywordDao
;
@Autowired
private
BookKeywordBiz
bookKeywordBiz
;
@Autowired
private
ResourceConsr
resourceConsr
;
@Autowired
private
SelfRobotKeywordReplyDao
selfRobotKeywordReplyDao
;
@Override
public
void
run
(
ApplicationArguments
applicationArguments
)
throws
Exception
{
log
.
info
(
"[项目启动后 定时检查用户情况]"
);
if
(!
JedisClusterUtils
.
setnx
(
"KEYWORDDELAYRUNNER_LOCK"
,
"KEYWORDDELAYRUNNER_LOCK"
)){
JedisClusterUtils
.
expire
(
"KEYWORDDELAYRUNNER_LOCK"
,
15
*
60
);
return
;
}
Long
bookGroupId
=
0L
;
String
wxid
=
""
;
switch
(
envStr
.
toUpperCase
())
{
case
"TEST"
:
wxid
=
"wxid_zus32xb5ukjn22"
;
bookGroupId
=
1621L
;
break
;
case
"UAT"
:
wxid
=
"wxid_51ff9f099l9a22"
;
bookGroupId
=
449L
;
break
;
case
"PRO"
:
wxid
=
"wxid_x8i897ryabo722"
;
bookGroupId
=
23735L
;
break
;
}
String
finalWxid
=
wxid
;
Long
finalBookGroupId
=
bookGroupId
;
new
Thread
(()
->
{
while
(
true
)
{
try
{
Thread
.
sleep
(
1000
);
Map
<
String
,
String
>
friends
=
JedisClusterUtils
.
hgetAll
(
finalWxid
+
"_DELAY_PUSH"
);
if
(
friends
==
null
){
continue
;
}
Set
<
String
>
userSet
=
friends
.
keySet
();
for
(
String
userId
:
userSet
)
{
try
{
BookGuideDelayDto
bookGuideDelayDto
=
JSONObject
.
parseObject
(
friends
.
get
(
userId
),
BookGuideDelayDto
.
class
);
if
(
bookGuideDelayDto
.
getExpireTime
().
before
(
new
Date
()))
{
// 用户超时未答复 主动推送关键词
SelfRobotKeyword
selfRobotKeyword
=
selfRobotKeywordDao
.
getNextKeyWord
(
finalBookGroupId
,
bookGuideDelayDto
.
getKeyword
());
if
(
selfRobotKeyword
==
null
){
JedisClusterUtils
.
hdel
(
finalWxid
+
"_DELAY_PUSH"
,
userId
);
continue
;
}
// log.info("finalBookGroupId:{} bookGuideDelayDto:{}", finalBookGroupId, friends.get(userId));
// 用户否定回复 发送引导语
SendTextMessageVO
vo
=
new
SendTextMessageVO
();
vo
.
setContent
(
selfRobotKeyword
.
getGuide
());
vo
.
setCode
(
SendMessageTypeEnum
.
SELF
.
getCode
());
vo
.
setWxId
(
bookGuideDelayDto
.
getUserWxId
());
vo
.
setAltId
(
finalWxid
);
vo
.
setWxGroupId
(
bookGuideDelayDto
.
getUserWxId
());
vo
.
setIp
(
bookGuideDelayDto
.
getIp
());
WxGroupSDK
.
sendTextMessage
(
vo
);
if
(
"学前"
.
equals
(
selfRobotKeyword
.
getKeyword
())
&&
envStr
.
toUpperCase
().
equals
(
"PRO"
)
&&
finalWxid
.
equals
(
"wxid_x8i897ryabo722"
))
{
SendGroupInviteVO
sendGroupInviteVO
=
new
SendGroupInviteVO
();
sendGroupInviteVO
.
setAltId
(
finalWxid
);
sendGroupInviteVO
.
setWxId
(
bookGuideDelayDto
.
getUserWxId
());
sendGroupInviteVO
.
setWxGroupId
(
"23084048866@chatroom"
);
sendGroupInviteVO
.
setIp
(
bookGuideDelayDto
.
getIp
());
WxGroupSDK
.
sendGroupInvite
(
sendGroupInviteVO
);
log
.
info
(
"临时发送入群连接 sendGroupInviteVO:{}"
,
sendGroupInviteVO
);
}
if
(
"教辅书单"
.
equals
(
selfRobotKeyword
.
getKeyword
()))
{
List
<
SelfRobotKeywordReply
>
replyList
=
selfRobotKeywordReplyDao
.
getListByKeywordId
(
selfRobotKeyword
.
getId
());
if
(!
ListUtils
.
isEmpty
(
replyList
))
{
for
(
SelfRobotKeywordReply
keywordReply
:
replyList
)
{
if
(
ReplyTypeEnum
.
RESOURCE
.
value
.
equals
(
keywordReply
.
getType
()))
{
SendFileVO
sendFileVO
=
new
SendFileVO
();
Map
<
Long
,
ResourceDTO
>
map
=
resourceConsr
.
mapByIds
(
Arrays
.
asList
(
keywordReply
.
getResourceId
()));
ResourceDTO
resourceDTO
=
map
.
get
(
keywordReply
.
getResourceId
());
if
(
resourceDTO
!=
null
)
{
sendFileVO
.
setFileUrl
(
resourceDTO
.
getFileUrl
());
sendFileVO
.
setFileName
(
resourceDTO
.
getResourceName
());
}
sendFileVO
.
setIp
(
bookGuideDelayDto
.
getIp
());
sendFileVO
.
setAltId
(
finalWxid
);
sendFileVO
.
setWxId
(
bookGuideDelayDto
.
getUserWxId
());
WxGroupSDK
.
sendFile
(
sendFileVO
);
}
}
}
}
int
time
=
60
;
if
(
"背景音乐"
.
equals
(
selfRobotKeyword
.
getKeyword
())){
time
=
600
;
}
// 更新缓存中的关键词
BookGuideDelayDto
delayDto
=
BookGuideDelayDto
.
builder
().
userWxId
(
bookGuideDelayDto
.
getUserWxId
())
.
expireTime
(
DateUtils
.
addSecond
(
new
Date
(),
time
))
.
keyword
(
selfRobotKeyword
.
getKeyword
())
.
ip
(
bookGuideDelayDto
.
getIp
()).
build
();
JedisClusterUtils
.
hset
(
finalWxid
+
"_DELAY_PUSH"
,
bookGuideDelayDto
.
getUserWxId
(),
JSONObject
.
toJSONString
(
delayDto
));
}
}
catch
(
Exception
e
){
continue
;
}
}
}
catch
(
Exception
e
)
{
// log.info("[KeyWordDelayRunner] 关键词超时推送 失败",e);
}
}
}).
start
();
}
}
pcloud-service-book/src/main/resources/mapper/group/SelfRobotKeyword.xml
View file @
d79b8465
...
...
@@ -93,6 +93,14 @@
order by seq_num
</select>
<select
id=
"getNextKeyWord"
parameterType=
"map"
resultMap=
"BaseResultMap"
>
SELECT * FROM self_robot_keyword
WHERE book_group_id=#{bookGroupId}
AND seq_num > (SELECT seq_num FROM self_robot_keyword WHERE keyword = #{keyword} AND book_group_id=#{bookGroupId} LIMIT 1)
ORDER BY seq_num
LIMIT 1
</select>
<!--根据社群码和关键词获取-->
<select
id=
"getByBookGroupIdAndKeyword"
parameterType=
"map"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
...
...
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