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
d8e83388
Commit
d8e83388
authored
Aug 13, 2019
by
裴大威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat 群人数更新
parent
a5cc4c1c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
149 additions
and
2 deletions
+149
-2
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
No files found.
pcloud-service-book/src/main/java/com/pcloud/book/group/biz/impl/GroupQrcodeBizImpl.java
View file @
d8e83388
...
@@ -13,7 +13,9 @@ import com.pcloud.book.group.biz.BookGroupClassifyBiz;
...
@@ -13,7 +13,9 @@ import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import
com.pcloud.book.group.biz.GroupAnnouncementBiz
;
import
com.pcloud.book.group.biz.GroupAnnouncementBiz
;
import
com.pcloud.book.group.biz.GroupQrcodeBiz
;
import
com.pcloud.book.group.biz.GroupQrcodeBiz
;
import
com.pcloud.book.group.biz.WeixinQrcodeBiz
;
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.dao.GroupQrcodeDao
;
import
com.pcloud.book.group.dto.AutoUpdateGroupNumDTO
;
import
com.pcloud.book.group.dto.BookWxQrcodeDTO
;
import
com.pcloud.book.group.dto.BookWxQrcodeDTO
;
import
com.pcloud.book.group.dto.ChangeGroupNameDTO
;
import
com.pcloud.book.group.dto.ChangeGroupNameDTO
;
import
com.pcloud.book.group.dto.GroupAndUserNumberDTO
;
import
com.pcloud.book.group.dto.GroupAndUserNumberDTO
;
...
@@ -65,6 +67,9 @@ import java.util.HashMap;
...
@@ -65,6 +67,9 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
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
java.util.stream.Collectors
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -103,6 +108,72 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
...
@@ -103,6 +108,72 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
private
LabelConsr
labelConsr
;
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
@Override
@ParamLog
(
"updateGroupQrcode"
)
@ParamLog
(
"updateGroupQrcode"
)
public
void
updateGroupQrcode
(
UpdateGroupQrcodeRequestVO
vo
)
{
public
void
updateGroupQrcode
(
UpdateGroupQrcodeRequestVO
vo
)
{
...
@@ -243,8 +314,19 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
...
@@ -243,8 +314,19 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
if
(
groupQrcodeDTO
==
null
)
{
if
(
groupQrcodeDTO
==
null
)
{
return
;
return
;
}
}
//更新用户数
//更新用户数(由于微信有延迟及时更新可能会数据对不上,所以调用方法延迟30s,统一处理)
groupQrcodeDao
.
updateUserNumber
(
weixinGroupId
,
memberCount
);
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
()))
{
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 @
d8e83388
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 @
d8e83388
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
;
}
}
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