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 4391254c
authored
Apr 13, 2022
by
向延琳
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
新e盾消费电量数据
1 parent
3cbdeaa5
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
1 deletions
src/main/java/cn/com/glsx/kafka/config/KafkaConsumerConfig.java
src/main/java/cn/com/glsx/kafka/model/BatteryDTO.java
src/main/java/cn/com/glsx/kafka/queue/consumer/KafkaBatteryConsumer.java
src/main/java/cn/com/glsx/kafka/queue/consumer/KafkaJourneyConsumer.java
src/main/java/cn/com/glsx/kafka/config/KafkaConsumerConfig.java
View file @
4391254
...
@@ -98,6 +98,15 @@ public class KafkaConsumerConfig {
...
@@ -98,6 +98,15 @@ public class KafkaConsumerConfig {
}
}
@Bean
(
initMethod
=
"init"
,
destroyMethod
=
"destroy"
)
@Bean
(
initMethod
=
"init"
,
destroyMethod
=
"destroy"
)
KafkaBatteryConsumer
kafkaBatteryConsumer
(
@Value
(
"${mq.kafka.device.battery.topic}"
)
String
topic
)
{
KafkaBatteryConsumer
kafkaBatteryConsumer
=
new
KafkaBatteryConsumer
();
kafkaBatteryConsumer
.
setnThreads
(
nThreads
);
kafkaBatteryConsumer
.
setConsumerConfig
(
gpsConsumerConfig
);
kafkaBatteryConsumer
.
setTopic
(
topic
);
return
kafkaBatteryConsumer
;
}
@Bean
(
initMethod
=
"init"
,
destroyMethod
=
"destroy"
)
FenceAlarmConsumer
fenceAlarmConsumer
(
@Value
(
"${mq.kafka.fence.alarm.topic}"
)
String
topic
)
{
FenceAlarmConsumer
fenceAlarmConsumer
(
@Value
(
"${mq.kafka.fence.alarm.topic}"
)
String
topic
)
{
FenceAlarmConsumer
fenceAlarmConsumer
=
new
FenceAlarmConsumer
();
FenceAlarmConsumer
fenceAlarmConsumer
=
new
FenceAlarmConsumer
();
fenceAlarmConsumer
.
setnThreads
(
nThreads
);
fenceAlarmConsumer
.
setnThreads
(
nThreads
);
...
...
src/main/java/cn/com/glsx/kafka/model/BatteryDTO.java
0 → 100644
View file @
4391254
package
cn
.
com
.
glsx
.
kafka
.
model
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* 电量
* @author xiangyanlin
* @date 2022/4/12
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public
class
BatteryDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* id
*/
private
Integer
id
;
/**
* 设备号
*/
private
String
sn
;
/**
* 电量
*/
private
Integer
SOC
;
/**
* 电量上传时间
*/
private
String
alarmTime
;
/**
* 创建时间
*/
private
String
createTime
;
/**
* 更新时间
*/
private
String
updateTime
;
}
src/main/java/cn/com/glsx/kafka/queue/consumer/KafkaBatteryConsumer.java
0 → 100644
View file @
4391254
package
cn
.
com
.
glsx
.
kafka
.
queue
.
consumer
;
import
cn.com.glsx.kafka.model.BatteryDTO
;
import
cn.com.glsx.kafka.queue.base.MessageReceiver
;
import
cn.com.glsx.stdinterface.api.BatteryClient
;
import
cn.com.glsx.stdinterface.dto.DevicePowerDTO
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.common.utils.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.nio.charset.Charset
;
import
java.util.Optional
;
/**
* 消费电量数据
*
* @author xiangyanlin
* @date 2022/4/12
*/
@Slf4j
public
class
KafkaBatteryConsumer
extends
MessageReceiver
{
@Autowired
private
BatteryClient
batteryClient
;
@Override
public
void
processMessage
(
String
topic
,
byte
[]
message
)
throws
Exception
{
String
devicePowerJson
=
new
String
(
message
,
Charset
.
defaultCharset
());
log
.
info
(
"{}"
,
"电量消息:"
+
devicePowerJson
);
if
(
StringUtils
.
isEmpty
(
devicePowerJson
))
{
return
;
}
BatteryDTO
devicePower
=
JSONObject
.
parseObject
(
devicePowerJson
,
BatteryDTO
.
class
);
//电量信息保存入库
DevicePowerDTO
devicePowerDTO
=
convert
(
devicePower
);
batteryClient
.
saveBatteryInfo
(
devicePowerDTO
);
}
public
DevicePowerDTO
convert
(
BatteryDTO
batteryDTO
)
{
DevicePowerDTO
devicePowerDTO
=
new
DevicePowerDTO
();
Optional
.
ofNullable
(
batteryDTO
.
getId
())
.
map
(
Integer:
:
longValue
)
.
ifPresent
(
devicePowerDTO:
:
setId
);
devicePowerDTO
.
setSn
(
batteryDTO
.
getSn
());
devicePowerDTO
.
setAlarmTime
(
DateUtils
.
parse
(
batteryDTO
.
getAlarmTime
()));
devicePowerDTO
.
setSoc
(
batteryDTO
.
getSOC
());
devicePowerDTO
.
setCreatedDate
(
DateUtils
.
parse
(
batteryDTO
.
getCreateTime
()));
devicePowerDTO
.
setUpdatedDate
(
DateUtils
.
parse
(
batteryDTO
.
getUpdateTime
()));
return
devicePowerDTO
;
}
}
src/main/java/cn/com/glsx/kafka/queue/consumer/KafkaJourneyConsumer.java
View file @
4391254
...
@@ -9,7 +9,6 @@ import com.alibaba.fastjson.JSON;
...
@@ -9,7 +9,6 @@ import com.alibaba.fastjson.JSON;
import
com.glsx.plat.common.utils.DateUtils
;
import
com.glsx.plat.common.utils.DateUtils
;
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
;
/**
/**
* 行程数据消费
* 行程数据消费
...
...
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