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 3c013134
authored
Jan 04, 2022
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化Gps基站消费逻辑
1 parent
04d7b5fb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
37 deletions
src/main/java/cn/com/glsx/kafka/service/TransitHandleService.java
src/main/java/cn/com/glsx/kafka/service/TransitHandleService.java
View file @
3c01313
...
...
@@ -6,16 +6,10 @@ import cn.com.glsx.stdinterface.dto.DeviceLocationDto;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.plat.redis.utils.RedisUtils
;
import
com.google.common.collect.Lists
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.data.redis.core.RedisOperations
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.SessionCallback
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
...
...
@@ -36,10 +30,6 @@ public class TransitHandleService {
private
RedisUtils
redisUtils
;
@Autowired
@Qualifier
(
"restRedisTemplate"
)
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
@Autowired
private
RemoteDeviceLocationService
remoteDeviceLocationService
;
/**
...
...
@@ -146,35 +136,33 @@ public class TransitHandleService {
// 通过sn从 redis中获取数据 并入库
List
<
DeviceLocationDto
>
deviceLocationList
=
Lists
.
newArrayList
();
redisTemplate
.
executePipelined
(
new
SessionCallback
<
Object
>()
{
@Override
public
Object
execute
(
RedisOperations
redisOperations
)
throws
DataAccessException
{
snTempList
.
forEach
(
sn
->
{
Object
gpsObj
=
redisOperations
.
boundValueOps
(
setKey
(
sn
,
Constants
.
GPS
)).
get
();
log
.
info
(
"gpsObj==="
+
JSONUtil
.
toJsonStr
(
gpsObj
));
DeviceLocationDto
gpsData
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
gpsObj
),
DeviceLocationDto
.
class
);
if
(
ObjectUtil
.
isNull
(
gpsData
))
{
gpsData
=
new
DeviceLocationDto
();
}
Object
bsObj
=
redisOperations
.
boundValueOps
(
setKey
(
sn
,
Constants
.
BS
)).
get
();
log
.
info
(
"bsObj==="
+
JSONUtil
.
toJsonStr
(
bsObj
));
DeviceLocationDto
bsData
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
bsObj
),
DeviceLocationDto
.
class
);
if
(
ObjectUtil
.
isNull
(
bsData
))
{
bsData
=
new
DeviceLocationDto
();
}
Object
stayStatusObj
=
redisOperations
.
boundValueOps
(
setKey
(
sn
,
Constants
.
STAY_STATUS
)).
get
();
log
.
info
(
"stayStatusObj==="
+
JSONUtil
.
toJsonStr
(
stayStatusObj
));
DeviceLocationDto
stayStatusData
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
stayStatusObj
),
DeviceLocationDto
.
class
);
if
(
ObjectUtil
.
isNull
(
stayStatusData
))
{
stayStatusData
=
new
DeviceLocationDto
();
}
DeviceLocationDto
deviceLogin
=
mergeDeviceLogin
(
gpsData
,
bsData
,
stayStatusData
);
deviceLocationList
.
add
(
deviceLogin
);
});
return
null
;
// 合并Gps 基站 停留状态数据
snTempList
.
forEach
(
sn
->
{
DeviceLocationDto
gpsData
=
(
DeviceLocationDto
)
redisUtils
.
get
(
setKey
(
sn
,
Constants
.
GPS
));
log
.
info
(
"gpsData==="
+
JSONUtil
.
toJsonStr
(
gpsData
));
if
(
ObjectUtil
.
isNull
(
gpsData
))
{
gpsData
=
new
DeviceLocationDto
();
}
DeviceLocationDto
bsData
=
(
DeviceLocationDto
)
redisUtils
.
get
(
setKey
(
sn
,
Constants
.
BS
));
log
.
info
(
"bsData==="
+
JSONUtil
.
toJsonStr
(
bsData
));
if
(
ObjectUtil
.
isNull
(
bsData
))
{
bsData
=
new
DeviceLocationDto
();
}
DeviceLocationDto
stayStatusData
=
(
DeviceLocationDto
)
redisUtils
.
get
(
setKey
(
sn
,
Constants
.
STAY_STATUS
));
log
.
info
(
"stayStatusData==="
+
JSONUtil
.
toJsonStr
(
stayStatusData
));
if
(
ObjectUtil
.
isNull
(
stayStatusData
))
{
stayStatusData
=
new
DeviceLocationDto
();
}
},
redisTemplate
.
getValueSerializer
());
//如果数据都为空就return掉
if
(
ObjectUtil
.
isNull
(
gpsData
)
&&
ObjectUtil
.
isNull
(
bsData
)
&&
ObjectUtil
.
isNull
(
stayStatusData
))
{
return
;
}
DeviceLocationDto
deviceLogin
=
mergeDeviceLogin
(
gpsData
,
bsData
,
stayStatusData
);
deviceLocationList
.
add
(
deviceLogin
);
});
// 数据入库
log
.
info
(
"deviceLocationList==="
+
JSONUtil
.
toJsonStr
(
deviceLocationList
));
remoteDeviceLocationService
.
saveOrUpdateDeviceLocationData
(
deviceLocationList
);
// 将sn解锁
snTempList
.
forEach
(
sn
->
{
...
...
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