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