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 c2742a11
authored
Dec 31, 2021
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化设备停驶状态消费逻辑
1 parent
de233333
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
6 deletions
src/main/java/cn/com/glsx/kafka/service/TransitHandleService.java
src/test/java/cn/com/glsx/kafka/queue/remote/MainTest.java
src/main/java/cn/com/glsx/kafka/service/TransitHandleService.java
View file @
c2742a1
...
@@ -52,10 +52,6 @@ public class TransitHandleService {
...
@@ -52,10 +52,6 @@ public class TransitHandleService {
public
void
handleGpsAndBsData
(
DeviceLocationDto
deviceLocationDto
,
Integer
topicId
)
{
public
void
handleGpsAndBsData
(
DeviceLocationDto
deviceLocationDto
,
Integer
topicId
)
{
DeviceLocationDto
deviceLocationCache
=
(
DeviceLocationDto
)
redisUtils
.
get
(
setKey
(
deviceLocationDto
.
getSn
()));
DeviceLocationDto
deviceLocationCache
=
(
DeviceLocationDto
)
redisUtils
.
get
(
setKey
(
deviceLocationDto
.
getSn
()));
if
(
ObjectUtil
.
isNull
(
deviceLocationCache
))
{
if
(
ObjectUtil
.
isNull
(
deviceLocationCache
))
{
if
(
TopicsEnum
.
DEVICE_STATE
.
getId
().
equals
(
topicId
))
{
log
.
error
(
"该设备{}消费行驶状态前没有消费Gps或基站数据"
,
deviceLocationDto
.
getSn
());
return
;
}
// 缓存中没有 就是第一次插入数据 设置创建时间同步更新时间
// 缓存中没有 就是第一次插入数据 设置创建时间同步更新时间
deviceLocationDto
.
setCreatedTime
(
new
Date
());
deviceLocationDto
.
setCreatedTime
(
new
Date
());
log
.
info
(
"报警消费数据===sn:"
+
deviceLocationDto
.
getSn
()
+
"Gps时间:"
+
DateUtil
.
formatDateTime
(
deviceLocationDto
.
getLastGpsTime
())
+
"基站时间:"
+
DateUtil
.
formatDateTime
(
deviceLocationDto
.
getLastBsTime
()));
log
.
info
(
"报警消费数据===sn:"
+
deviceLocationDto
.
getSn
()
+
"Gps时间:"
+
DateUtil
.
formatDateTime
(
deviceLocationDto
.
getLastGpsTime
())
+
"基站时间:"
+
DateUtil
.
formatDateTime
(
deviceLocationDto
.
getLastBsTime
()));
...
@@ -66,7 +62,7 @@ public class TransitHandleService {
...
@@ -66,7 +62,7 @@ public class TransitHandleService {
boolean
flag
=
false
;
boolean
flag
=
false
;
Date
lastGpsTime
=
deviceLocationDto
.
getLastGpsTime
();
Date
lastGpsTime
=
deviceLocationDto
.
getLastGpsTime
();
Date
lastGpsTimeCache
=
deviceLocationCache
.
getLastGpsTime
();
Date
lastGpsTimeCache
=
deviceLocationCache
.
getLastGpsTime
();
if
(
judgeDate
(
lastGpsTime
,
lastGpsTimeCache
)
&&
lastGpsTime
.
after
(
lastGpsTimeCache
))
{
if
(
judgeDate
(
lastGpsTime
,
lastGpsTimeCache
)
&&
lastGpsTime
.
after
(
lastGpsTimeCache
)
||
judgeDateIsNull
(
lastGpsTimeCache
)
)
{
deviceLocationCache
.
setLastGpsTime
(
lastGpsTime
);
deviceLocationCache
.
setLastGpsTime
(
lastGpsTime
);
flag
=
true
;
flag
=
true
;
}
}
...
@@ -74,7 +70,7 @@ public class TransitHandleService {
...
@@ -74,7 +70,7 @@ public class TransitHandleService {
//基站时间比缓存中基站的时间大就更新缓存的时间
//基站时间比缓存中基站的时间大就更新缓存的时间
Date
lastBsTime
=
deviceLocationDto
.
getLastBsTime
();
Date
lastBsTime
=
deviceLocationDto
.
getLastBsTime
();
Date
lastBsTimeCache
=
deviceLocationCache
.
getLastBsTime
();
Date
lastBsTimeCache
=
deviceLocationCache
.
getLastBsTime
();
if
(
judgeDate
(
lastBsTime
,
lastBsTimeCache
)
&&
lastBsTime
.
after
(
lastBsTimeCache
))
{
if
(
judgeDate
(
lastBsTime
,
lastBsTimeCache
)
&&
lastBsTime
.
after
(
lastBsTimeCache
)
||
judgeDateIsNull
(
lastBsTimeCache
)
)
{
deviceLocationCache
.
setLastBsTime
(
lastBsTime
);
deviceLocationCache
.
setLastBsTime
(
lastBsTime
);
flag
=
true
;
flag
=
true
;
}
}
...
@@ -118,6 +114,16 @@ public class TransitHandleService {
...
@@ -118,6 +114,16 @@ public class TransitHandleService {
}
}
/**
/**
* 判断时间是否都为null
*
* @param date time
* @return
*/
private
Boolean
judgeDateIsNull
(
Date
date
)
{
return
ObjectUtil
.
isNull
(
date
);
}
/**
* 设置key值
* 设置key值
*
*
* @param key key
* @param key key
...
...
src/test/java/cn/com/glsx/kafka/queue/remote/MainTest.java
View file @
c2742a1
...
@@ -2,6 +2,7 @@ package cn.com.glsx.kafka.queue.remote;
...
@@ -2,6 +2,7 @@ package cn.com.glsx.kafka.queue.remote;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
java.util.Date
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
/**
...
@@ -16,5 +17,9 @@ public class MainTest {
...
@@ -16,5 +17,9 @@ public class MainTest {
hashMap
.
put
(
"789"
,
"456"
);
hashMap
.
put
(
"789"
,
"456"
);
System
.
out
.
println
(
"hashMap = "
+
JSONUtil
.
toJsonStr
(
hashMap
));
System
.
out
.
println
(
"hashMap = "
+
JSONUtil
.
toJsonStr
(
hashMap
));
System
.
out
.
println
(
"hashMap = "
+
JSONUtil
.
toJsonStr
(
hashMap
.
values
()));
System
.
out
.
println
(
"hashMap = "
+
JSONUtil
.
toJsonStr
(
hashMap
.
values
()));
Date
date
=
new
Date
();
boolean
after
=
date
.
after
(
null
);
System
.
out
.
println
(
"after = "
+
after
);
}
}
}
}
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