Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-kafkaconsumer
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 25abeda6
authored
May 12, 2022
by
向延琳
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
去掉报错的方法
1 parent
36c39117
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
5 deletions
src/main/java/cn/com/glsx/kafka/queue/consumer/KafkaOverSpeedConsumer.java
src/main/java/cn/com/glsx/kafka/service/OverSpeedService.java
src/test/java/cn/com/glsx/kafka/service/OverSpeedServiceTest.java
src/main/java/cn/com/glsx/kafka/queue/consumer/KafkaOverSpeedConsumer.java
View file @
25abeda
...
...
@@ -3,13 +3,9 @@ package cn.com.glsx.kafka.queue.consumer;
import
cn.com.glsx.kafka.protocol.KafkaJourneyOverSpeed
;
import
cn.com.glsx.kafka.queue.base.MessageReceiver
;
import
cn.com.glsx.kafka.service.OverSpeedService
;
import
cn.com.glsx.stdinterface.api.DeviceSpeedingClient
;
import
cn.com.glsx.stdinterface.dto.DeviceSpeedingDTO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.Date
;
/**
* 超速报警消费类
*
...
...
@@ -25,8 +21,9 @@ public class KafkaOverSpeedConsumer extends MessageReceiver {
@Override
public
void
processMessage
(
String
topic
,
byte
[]
message
)
throws
Exception
{
log
.
info
(
"超速消费开始"
);
KafkaJourneyOverSpeed
.
track_journey_overspeed_req
req
=
KafkaJourneyOverSpeed
.
track_journey_overspeed_req
.
parseFrom
(
message
);
log
.
info
(
"超速报警记录:{}"
+
req
.
toString
());
overSpeedService
.
saveDeviceSpeeding
(
req
);
...
...
src/main/java/cn/com/glsx/kafka/service/OverSpeedService.java
View file @
25abeda
...
...
@@ -8,6 +8,7 @@ import cn.com.glsx.stdinterface.dto.DeviceSpeedingDTO;
import
cn.com.glsx.stdinterface.dto.VehicleDeviceDto
;
import
cn.com.glsx.stdinterface.dto.VehicleDto
;
import
cn.hutool.core.date.DateUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -43,6 +44,7 @@ public class OverSpeedService {
Long
createBy
=
Optional
.
ofNullable
(
vehicle
).
map
(
VehicleDto:
:
getCreateBy
).
orElse
(
0L
);
log
.
info
(
"createBy{}"
,
createBy
);
DeviceSpeedingDTO
deviceSpeedingDTO
=
buildDeviceSpeedingDTO
(
req
,
vdId
,
createBy
);
log
.
info
(
"超速报警记录:{}"
+
JSON
.
toJSONString
(
deviceSpeedingDTO
));
deviceSpeedingClient
.
saveDeviceSpeeding
(
deviceSpeedingDTO
);
}
...
...
src/test/java/cn/com/glsx/kafka/service/OverSpeedServiceTest.java
0 → 100644
View file @
25abeda
package
cn
.
com
.
glsx
.
kafka
.
service
;
import
cn.com.glsx.Application
;
import
cn.com.glsx.stdinterface.api.DeviceSpeedingClient
;
import
cn.com.glsx.stdinterface.dto.DeviceSpeedingDTO
;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.jupiter.api.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
java.util.Date
;
/**
* @author xiangyanlin
* @date 2022/5/12
*/
@Slf4j
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Application
.
class
,
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
class
OverSpeedServiceTest
{
@Autowired
private
DeviceSpeedingClient
deviceSpeedingClient
;
@Test
public
void
test
()
{
DeviceSpeedingDTO
deviceSpeedingDTO
=
new
DeviceSpeedingDTO
();
deviceSpeedingDTO
.
setSn
(
"100101"
);
deviceSpeedingDTO
.
setVdId
(
2L
);
deviceSpeedingDTO
.
setBeginTime
(
new
Date
());
deviceSpeedingDTO
.
setEndTime
(
new
Date
());
deviceSpeedingDTO
.
setDuration
(
100L
);
deviceSpeedingDTO
.
setAverageSpeed
(
100.0
);
deviceSpeedingDTO
.
setUpdatedDate
(
new
Date
());
deviceSpeedingDTO
.
setCreatedDate
(
new
Date
());
R
r
=
deviceSpeedingClient
.
saveDeviceSpeeding
(
deviceSpeedingDTO
);
System
.
out
.
println
(
r
);
}
}
\ No newline at end of file
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