Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-kafkaconsumer-gpsbs
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 dc6b2cd0
authored
Jan 04, 2022
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化Gps基站消费逻辑
1 parent
e7f6ffdd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
src/main/java/cn/com/glsx/kafka/service/TransitHandleService.java
src/main/java/cn/com/glsx/kafka/service/TransitHandleService.java
View file @
dc6b2cd
...
...
@@ -7,12 +7,14 @@ import cn.hutool.core.date.DateUtil;
import
cn.hutool.core.util.ObjectUtil
;
import
com.glsx.plat.redis.utils.RedisUtils
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Sets
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.CopyOnWriteArraySet
;
/**
...
...
@@ -118,7 +120,7 @@ public class TransitHandleService {
// 当数据大小为500个 或者 时间间隔3秒 的时候 保存一次
if
(
System
.
currentTimeMillis
()
>=
tempTime
+
STEP
)
{
List
<
String
>
snTempList
=
Lists
.
newArrayLis
t
();
Set
<
String
>
snTempSet
=
Sets
.
newHashSe
t
();
log
.
info
(
"开始插入或者更新Gps和基站的数据大小==="
+
snSet
.
size
());
snSet
.
forEach
(
sn
->
{
Integer
lockValue
=
(
Integer
)
redisUtils
.
get
(
setKey
(
sn
));
...
...
@@ -126,7 +128,7 @@ public class TransitHandleService {
log
.
info
(
"设备号:"
+
sn
+
"已经在redis中加锁,在此服务器中不消费"
);
return
;
}
snTemp
Lis
t
.
add
(
sn
);
snTemp
Se
t
.
add
(
sn
);
//消费的设备号进行加锁 保证只在一台机器上处理入库操作
redisUtils
.
setnx
(
setKey
(
sn
),
1
,
60
);
});
...
...
@@ -136,7 +138,7 @@ public class TransitHandleService {
// 通过sn从 redis中获取数据 并入库
List
<
DeviceLocationDto
>
deviceLocationList
=
Lists
.
newArrayList
();
// 合并Gps 基站 停留状态数据
snTemp
Lis
t
.
forEach
(
sn
->
{
snTemp
Se
t
.
forEach
(
sn
->
{
DeviceLocationDto
gpsData
=
(
DeviceLocationDto
)
redisUtils
.
get
(
setKey
(
sn
,
Constants
.
GPS
));
// log.info("gpsData===" + JSONUtil.toJsonStr(gpsData));
if
(
ObjectUtil
.
isNull
(
gpsData
))
{
...
...
@@ -165,7 +167,7 @@ public class TransitHandleService {
// log.info("deviceLocationList===" + JSONUtil.toJsonStr(deviceLocationList));
remoteDeviceLocationService
.
saveOrUpdateDeviceLocationData
(
deviceLocationList
);
// 将sn解锁
snTemp
Lis
t
.
forEach
(
sn
->
{
snTemp
Se
t
.
forEach
(
sn
->
{
//对于已经入库的设备进行解锁
redisUtils
.
unlock
(
setKey
(
sn
),
0
);
});
...
...
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