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
233755c6
Commit
233755c6
authored
Aug 13, 2019
by
阮思源
Browse files
Options
Browse Files
Download
Plain Diff
合并
parents
c9cff496
d8e83388
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
180 additions
and
3 deletions
+180
-3
BookConstant.java
...main/java/com/pcloud/book/book/constant/BookConstant.java
+5
-0
GroupQrcodeBizImpl.java
...va/com/pcloud/book/group/biz/impl/GroupQrcodeBizImpl.java
+84
-2
BookBusinessConstants.java
...om/pcloud/book/group/constants/BookBusinessConstants.java
+18
-0
AutoUpdateGroupNumDTO.java
...java/com/pcloud/book/group/dto/AutoUpdateGroupNumDTO.java
+47
-0
BookGuideBizImpl.java
...a/com/pcloud/book/keywords/biz/impl/BookGuideBizImpl.java
+26
-1
No files found.
pcloud-facade-book/src/main/java/com/pcloud/book/book/constant/BookConstant.java
View file @
233755c6
...
...
@@ -17,6 +17,11 @@ import java.util.Map;
public
class
BookConstant
{
/**
* 微信小号每天拉人次数缓存前缀
*/
public
static
final
String
WXGROUP_ADD_USER_NUM
=
CacheConstant
.
BOOK
+
"WXGROUP_ADD_USER_NUM:"
;
/**
* 图书基础缓存前缀名称
*/
public
static
final
String
BOOK_CACHE
=
CacheConstant
.
BOOK
+
"BOOK:"
;
...
...
pcloud-service-book/src/main/java/com/pcloud/book/group/biz/impl/GroupQrcodeBizImpl.java
View file @
233755c6
...
...
@@ -13,7 +13,9 @@ import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import
com.pcloud.book.group.biz.GroupAnnouncementBiz
;
import
com.pcloud.book.group.biz.GroupQrcodeBiz
;
import
com.pcloud.book.group.biz.WeixinQrcodeBiz
;
import
com.pcloud.book.group.constants.BookBusinessConstants
;
import
com.pcloud.book.group.dao.GroupQrcodeDao
;
import
com.pcloud.book.group.dto.AutoUpdateGroupNumDTO
;
import
com.pcloud.book.group.dto.BookWxQrcodeDTO
;
import
com.pcloud.book.group.dto.ChangeGroupNameDTO
;
import
com.pcloud.book.group.dto.GroupAndUserNumberDTO
;
...
...
@@ -65,6 +67,9 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.stream.Collectors
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -103,6 +108,72 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
private
LabelConsr
labelConsr
;
/**
* 自动更新群人数线程是否开始执行
*/
private
static
final
AtomicBoolean
IS_START
=
new
AtomicBoolean
(
false
);
/**
* 处理群人数线程池
*/
private
static
final
ExecutorService
SINGLE_THREAD_EXECUTOR
=
Executors
.
newSingleThreadExecutor
();
/**
* 更新群人数线程
*/
private
void
updateGroupNum
()
{
// 若已开始则无需再启动
if
(
IS_START
.
get
())
{
return
;
}
// 若设置时已经为true则代表已经有线程执行成功
final
boolean
andSet
=
IS_START
.
getAndSet
(
true
);
if
(
andSet
)
{
return
;
}
SINGLE_THREAD_EXECUTOR
.
execute
(()
->
{
while
(
true
)
{
try
{
if
(
BookBusinessConstants
.
GROUP_NUM_DTO_MAP
.
size
()
<
1
)
{
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"[updateGroupNum] InterruptedException:{}"
,
e
);
}
continue
;
}
log
.
info
(
"[更新群人数] start GROUP_NUM_DTO_MAP:{}"
,
BookBusinessConstants
.
GROUP_NUM_DTO_MAP
);
for
(
Map
.
Entry
<
String
,
AutoUpdateGroupNumDTO
>
entry
:
BookBusinessConstants
.
GROUP_NUM_DTO_MAP
.
entrySet
())
{
final
AutoUpdateGroupNumDTO
value
=
entry
.
getValue
();
// 没到时间不执行(小于30s并且小于3个人不执行)
final
boolean
b
=
null
==
value
||
((
System
.
currentTimeMillis
()
+
10
)
<
value
.
getStartTime
().
getTime
()
&&
value
.
getNum
().
get
()
<
3
);
if
(
b
)
{
log
.
info
(
"[更新群人数] null == value:{}"
,
entry
);
continue
;
}
Integer
peopleCounts
=
WxGroupSDK
.
getPeopleCounts
(
value
.
getWxGroupId
(),
value
.
getRobotId
(),
value
.
getIp
());
if
(
null
==
peopleCounts
||
peopleCounts
<
1
)
{
log
.
info
(
"[更新群人数] null == peopleCounts || peopleCounts < 1 entry:{}; peopleCounts:{}"
,
entry
,
peopleCounts
);
continue
;
}
log
.
info
(
"[更新群人数] entry:{}, peopleCounts:{}"
,
entry
,
peopleCounts
);
groupQrcodeDao
.
updateUserNumber
(
value
.
getWxGroupId
(),
peopleCounts
);
BookBusinessConstants
.
GROUP_NUM_DTO_MAP
.
remove
(
entry
.
getKey
());
}
}
catch
(
Exception
e
)
{
log
.
error
(
"[updateGroupNum] : Exception:{}"
,
e
);
}
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"[updateGroupNum] InterruptedException:{}"
,
e
);
}
}
});
}
@Override
@ParamLog
(
"updateGroupQrcode"
)
public
void
updateGroupQrcode
(
UpdateGroupQrcodeRequestVO
vo
)
{
...
...
@@ -243,8 +314,19 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
if
(
groupQrcodeDTO
==
null
)
{
return
;
}
//更新用户数
groupQrcodeDao
.
updateUserNumber
(
weixinGroupId
,
memberCount
);
//更新用户数(由于微信有延迟及时更新可能会数据对不上,所以调用方法延迟30s,统一处理)
AutoUpdateGroupNumDTO
numDTO
=
BookBusinessConstants
.
GROUP_NUM_DTO_MAP
.
get
(
weixinGroupId
);
if
(
null
==
numDTO
){
numDTO
=
new
AutoUpdateGroupNumDTO
(
weixinGroupId
,
robotId
,
ip
,
new
Date
());
}
else
{
numDTO
.
getNum
().
incrementAndGet
();
numDTO
.
setStartTime
(
new
Date
());
}
BookBusinessConstants
.
GROUP_NUM_DTO_MAP
.
put
(
weixinGroupId
,
numDTO
);
// 启动更新群人数线程
if
(!
IS_START
.
get
())
{
this
.
updateGroupNum
();
}
//如果人数超过限制,重新分配群
if
(
memberCount
>=
groupQrcodeDTO
.
getChangeNumber
()
&&
QrcodeStatusEnum
.
ON_USE
.
value
.
equals
(
groupQrcodeDTO
.
getQrcodeState
()))
{
//修改状态,重新分配一个群
...
...
pcloud-service-book/src/main/java/com/pcloud/book/group/constants/BookBusinessConstants.java
0 → 100644
View file @
233755c6
package
com
.
pcloud
.
book
.
group
.
constants
;
import
com.pcloud.book.group.dto.AutoUpdateGroupNumDTO
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* book业务常量类
*/
public
class
BookBusinessConstants
{
/**
* 需更新微信群信息
*/
public
static
final
Map
<
String
,
AutoUpdateGroupNumDTO
>
GROUP_NUM_DTO_MAP
=
new
ConcurrentHashMap
<>(
128
);
}
pcloud-service-book/src/main/java/com/pcloud/book/group/dto/AutoUpdateGroupNumDTO.java
0 → 100644
View file @
233755c6
package
com
.
pcloud
.
book
.
group
.
dto
;
import
java.util.Date
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
lombok.Data
;
/**
* 自动更新群人数DTO
*/
@Data
public
class
AutoUpdateGroupNumDTO
{
/**
* 群id
*/
private
String
wxGroupId
;
/**
* 机器人id
*/
private
String
robotId
;
/**
* wxGroupIp
*/
private
String
ip
;
/**
* 当前触发次数
*/
private
AtomicInteger
num
=
new
AtomicInteger
(
1
);
/**
* 开始更新时间(犹豫微信有延迟,所以新用户进群之后30s再次更新群人数)
*/
private
Date
startTime
;
public
AutoUpdateGroupNumDTO
()
{
}
public
AutoUpdateGroupNumDTO
(
String
wxGroupId
,
String
robotId
,
String
ip
,
Date
startTime
)
{
this
.
wxGroupId
=
wxGroupId
;
this
.
robotId
=
robotId
;
this
.
ip
=
ip
;
this
.
num
=
new
AtomicInteger
(
1
);
this
.
startTime
=
startTime
;
}
}
pcloud-service-book/src/main/java/com/pcloud/book/keywords/biz/impl/BookGuideBizImpl.java
View file @
233755c6
package
com
.
pcloud
.
book
.
keywords
.
biz
.
impl
;
import
com.pcloud.book.base.exception.BookBizException
;
import
com.pcloud.book.book.constant.BookConstant
;
import
com.pcloud.book.clock.check.BookClockCheck
;
import
com.pcloud.book.clock.dao.BookClockKeywordDao
;
import
com.pcloud.book.clock.dto.BookClockKeywordDTO
;
...
...
@@ -36,9 +37,11 @@ import com.pcloud.book.keywords.vo.UpdateGuideVO;
import
com.pcloud.channelcenter.wechat.dto.AccountSettingDto
;
import
com.pcloud.common.core.aspect.ParamLog
;
import
com.pcloud.common.utils.ListUtils
;
import
com.pcloud.common.utils.cache.redis.JedisClusterUtils
;
import
com.pcloud.common.utils.string.StringUtil
;
import
com.pcloud.wechatgroup.message.dto.AgreeAddUserDTO
;
import
com.sdk.wxgroup.AddToGroupVO
;
import
com.sdk.wxgroup.SendGroupInviteVO
;
import
com.sdk.wxgroup.SendMessageTypeEnum
;
import
com.sdk.wxgroup.SendTextMessageVO
;
import
com.sdk.wxgroup.WxGroupSDK
;
...
...
@@ -101,7 +104,10 @@ public class BookGuideBizImpl implements BookGuideBiz {
log
.
info
(
"[同意加好友发送欢迎语] 参数为空 agreeAddUserDTO:{}"
,
agreeAddUserDTO
);
return
;
}
final
String
cipher
=
wechatGroupConsr
.
getCipherByRobotAndUserWxId
(
agreeAddUserDTO
.
getRobotWxId
(),
agreeAddUserDTO
.
getUserWxId
());
String
cipher
=
agreeAddUserDTO
.
getCipher
();
if
(
StringUtil
.
isBlank
(
cipher
))
{
cipher
=
wechatGroupConsr
.
getCipherByRobotAndUserWxId
(
agreeAddUserDTO
.
getRobotWxId
(),
agreeAddUserDTO
.
getUserWxId
());
}
if
(
StringUtil
.
isBlank
(
cipher
))
{
log
.
info
(
"[同意加好友发送欢迎语] 暗号为空 agreeAddUserDTO:{}"
,
agreeAddUserDTO
);
return
;
...
...
@@ -121,10 +127,23 @@ public class BookGuideBizImpl implements BookGuideBiz {
SendWeixinRequestTools
.
sendKeywordsInfo
(
keywords
,
agreeAddUserDTO
.
getRobotWxId
(),
agreeAddUserDTO
.
getUserWxId
(),
agreeAddUserDTO
.
getIp
());
// 拉群
final
String
wxGroupId
=
bookGroupClassifyBiz
.
getWxGroupIdByClassifyIdAndWechatId
(
dto
.
getClassifyId
(),
dto
.
getWechatUserId
());
final
Integer
peopleCounts
=
WxGroupSDK
.
getPeopleCounts
(
wxGroupId
,
agreeAddUserDTO
.
getRobotWxId
(),
agreeAddUserDTO
.
getIp
());
// 邀请好友进群有次数限制,目前测试为每天只能拉30-40人就操作频繁,所以在此加判断,超过30人或者群人数超过30人就发送邀请链接
final
String
num
=
JedisClusterUtils
.
get
(
BookConstant
.
WXGROUP_ADD_USER_NUM
+
agreeAddUserDTO
.
getRobotWxId
());
log
.
info
(
"[同意加好友发送欢迎语] 拉群 agreeAddUserDTO:{}, wxGroupId:{}, peopleCounts:{}, num:{}"
,
agreeAddUserDTO
,
wxGroupId
,
peopleCounts
,
num
);
if
(
StringUtil
.
isBlank
(
wxGroupId
))
{
log
.
info
(
"[同意加好友发送欢迎语] 拉群 没有找到群 bookGroupClassifyBiz.getGroupQrcode4ClassifyWechat JoinGroupCipherDTO :{}"
,
dto
);
return
;
}
if
((!
StringUtil
.
isBlank
(
num
)
&&
Integer
.
parseInt
(
num
)
>=
30
)
||
peopleCounts
>=
30
)
{
SendGroupInviteVO
sendGroupInviteVO
=
new
SendGroupInviteVO
();
sendGroupInviteVO
.
setAltId
(
agreeAddUserDTO
.
getRobotWxId
());
sendGroupInviteVO
.
setWxId
(
agreeAddUserDTO
.
getUserWxId
());
sendGroupInviteVO
.
setWxGroupId
(
wxGroupId
);
WxGroupSDK
.
sendGroupInvite
(
sendGroupInviteVO
);
log
.
info
(
"[同意加好友发送欢迎语] 发送进群链接 sendGroupInviteVO:{}"
,
sendGroupInviteVO
);
return
;
}
AddToGroupVO
vo1
=
new
AddToGroupVO
();
vo1
.
setWxGroupId
(
wxGroupId
);
vo1
.
setWxId
(
agreeAddUserDTO
.
getUserWxId
());
...
...
@@ -137,6 +156,12 @@ public class BookGuideBizImpl implements BookGuideBiz {
log
.
info
(
"根据群id查询群信息groupQrcodeInfo"
,
groupQrcodeInfo
.
toString
());
log
.
info
(
"更新暗号的群cipher="
+
cipher
+
"wxId="
+
agreeAddUserDTO
.
getUserWxId
()
+
"qrcodeId="
+
groupQrcodeInfo
.
getId
());
joinGroupCipherDao
.
updateQrcodeId
(
cipher
,
agreeAddUserDTO
.
getUserWxId
(),
groupQrcodeInfo
.
getId
());
// 拉一次+1
if
(
StringUtil
.
isBlank
(
num
))
{
JedisClusterUtils
.
getSet
(
BookConstant
.
WXGROUP_ADD_USER_NUM
+
agreeAddUserDTO
.
getRobotWxId
(),
"1"
,
3600
*
24
);
}
else
{
JedisClusterUtils
.
incr
(
BookConstant
.
WXGROUP_ADD_USER_NUM
+
agreeAddUserDTO
.
getRobotWxId
());
}
}
@Override
...
...
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