Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
chejia-smart-service
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 b6dc18cd
authored
Apr 11, 2021
by
wnb0128
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
车家智能数据服务 推送kafka--think.wang
1 parent
85d88ef1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
25 deletions
pom.xml
src/main/java/com/glsx/smart/config/DeviceAddressProducer.java
src/main/java/com/glsx/smart/controller/SceneController.java
src/main/java/com/glsx/smart/controller/UserKafkaController.java
src/main/java/com/glsx/smart/service/UserKafkaService.java
src/main/java/com/glsx/smart/service/impl/UserKafkaServiceImpl.java
pom.xml
View file @
b6dc18c
...
@@ -67,6 +67,12 @@
...
@@ -67,6 +67,12 @@
<artifactId>
rest-admin-kafka
</artifactId>
<artifactId>
rest-admin-kafka
</artifactId>
</dependency>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.kafka</groupId>-->
<!-- <artifactId>spring-kafka</artifactId>-->
<!-- <version>2.5.6.RELEASE</version>-->
<!-- </dependency>-->
<dependency>
<dependency>
<groupId>
com.glsx
</groupId>
<groupId>
com.glsx
</groupId>
<artifactId>
rest-admin-swagger2
</artifactId>
<artifactId>
rest-admin-swagger2
</artifactId>
...
...
src/main/java/com/glsx/smart/config/DeviceAddressProducer.java
0 → 100644
View file @
b6dc18c
package
com
.
glsx
.
smart
.
config
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.smart.constant.Constants
;
import
com.glsx.smart.pojo.DeviceMessage
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.kafka.core.KafkaTemplate
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
/**
* @author think.wang
* @version 1.0.0
* @Title DeviceAddressProducer
* @Package com.glsx.smart.config
* @Description 设备围栏数据kafka推送
* @date 2021/4/11
*/
@Slf4j
@Component
public
class
DeviceAddressProducer
{
@Resource
private
KafkaTemplate
kafkaTemplate
;
/**
* 推送设备经纬度数据
* @param deviceId
* @param lngAndLat
* @param type 1新增 2更新 3删除
*/
public
void
pushUserDeviceData
(
String
deviceId
,
String
lngAndLat
,
Integer
type
)
{
//kafka 发送消息数据封装
DeviceMessage
message
=
new
DeviceMessage
();
message
.
setDeviceId
(
deviceId
);
message
.
setLngAndLat
(
lngAndLat
);
message
.
setType
(
type
);
log
.
info
(
"推送kafka topic【{}】的数据:{}"
,
Constants
.
DEVICE_DATA_TOPIC
,
message
.
toString
());
//推送kafka
kafkaTemplate
.
send
(
Constants
.
DEVICE_DATA_TOPIC
,
JSON
.
toJSONString
(
message
));
}
}
src/main/java/com/glsx/smart/controller/SceneController.java
View file @
b6dc18c
...
@@ -6,6 +6,7 @@ import com.glsx.smart.pojo.OrderResponse;
...
@@ -6,6 +6,7 @@ import com.glsx.smart.pojo.OrderResponse;
import
com.glsx.smart.service.SmartSceneDataService
;
import
com.glsx.smart.service.SmartSceneDataService
;
import
com.glsx.smart.service.SmartSceneLogService
;
import
com.glsx.smart.service.SmartSceneLogService
;
import
com.glsx.smart.service.SmartSceneService
;
import
com.glsx.smart.service.SmartSceneService
;
import
com.glsx.smart.service.UserKafkaService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -39,6 +40,9 @@ public class SceneController {
...
@@ -39,6 +40,9 @@ public class SceneController {
@Autowired
@Autowired
private
SmartSceneDataService
sceneDataService
;
private
SmartSceneDataService
sceneDataService
;
@Autowired
private
UserKafkaService
userKafkaService
;
@RequestMapping
(
value
=
"/getList"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
@RequestMapping
(
value
=
"/getList"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
List
<
SmartScene
>
getList
(
@RequestBody
SmartScene
scene
)
{
public
List
<
SmartScene
>
getList
(
@RequestBody
SmartScene
scene
)
{
log
.
info
(
"/scene/getList param: {}"
,
JSON
.
toJSONString
(
scene
));
log
.
info
(
"/scene/getList param: {}"
,
JSON
.
toJSONString
(
scene
));
...
@@ -61,6 +65,7 @@ public class SceneController {
...
@@ -61,6 +65,7 @@ public class SceneController {
log
.
info
(
"用户新增调用/scene/add param: {}"
,
JSON
.
toJSONString
(
scene
));
log
.
info
(
"用户新增调用/scene/add param: {}"
,
JSON
.
toJSONString
(
scene
));
boolean
flag
=
sceneService
.
insert
(
scene
)
>
0
?
true
:
false
;
boolean
flag
=
sceneService
.
insert
(
scene
)
>
0
?
true
:
false
;
if
(
flag
){
if
(
flag
){
userKafkaService
.
addDeviceData
(
scene
);
//推送数据至kafka
sceneLogService
.
insertWrapper
(
scene
.
getUserId
(),
sceneLogService
.
insertWrapper
(
scene
.
getUserId
(),
"新增场景数据:"
+
scene
.
getId
(),
JSON
.
toJSONString
(
scene
));
"新增场景数据:"
+
scene
.
getId
(),
JSON
.
toJSONString
(
scene
));
}
}
...
@@ -73,6 +78,7 @@ public class SceneController {
...
@@ -73,6 +78,7 @@ public class SceneController {
log
.
info
(
"用户更新调用/scene/update param: {}"
,
JSON
.
toJSONString
(
scene
));
log
.
info
(
"用户更新调用/scene/update param: {}"
,
JSON
.
toJSONString
(
scene
));
boolean
flag
=
sceneService
.
update
(
scene
)
>
0
?
true
:
false
;
boolean
flag
=
sceneService
.
update
(
scene
)
>
0
?
true
:
false
;
if
(
flag
){
if
(
flag
){
userKafkaService
.
addDeviceData
(
scene
);
//推送数据至kafka
sceneLogService
.
insertWrapper
(
scene
.
getUserId
(),
sceneLogService
.
insertWrapper
(
scene
.
getUserId
(),
"更新场景数据:"
+
scene
.
getId
(),
JSON
.
toJSONString
(
scene
));
"更新场景数据:"
+
scene
.
getId
(),
JSON
.
toJSONString
(
scene
));
}
}
...
...
src/main/java/com/glsx/smart/controller/UserKafkaController.java
View file @
b6dc18c
package
com
.
glsx
.
smart
.
controller
;
package
com
.
glsx
.
smart
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.smart.config.DeviceAddressProducer
;
import
com.glsx.smart.dao.entity.SmartScene
;
import
com.glsx.smart.dao.entity.SmartScene
;
import
com.glsx.smart.dao.entity.SmartUserRelation
;
import
com.glsx.smart.dao.entity.SmartUserRelation
;
import
com.glsx.smart.service.*
;
import
com.glsx.smart.service.*
;
...
@@ -39,6 +40,9 @@ public class UserKafkaController {
...
@@ -39,6 +40,9 @@ public class UserKafkaController {
@Autowired
@Autowired
private
SmartSceneDataService
sceneDataService
;
private
SmartSceneDataService
sceneDataService
;
@Autowired
private
DeviceAddressProducer
addressProducer
;
/**
/**
* 更新用户场景
* 更新用户场景
*
*
...
@@ -69,7 +73,7 @@ public class UserKafkaController {
...
@@ -69,7 +73,7 @@ public class UserKafkaController {
if
(
CollectionUtils
.
isNotEmpty
(
deviceList
)){
if
(
CollectionUtils
.
isNotEmpty
(
deviceList
)){
for
(
String
deviceId
:
deviceList
)
{
for
(
String
deviceId
:
deviceList
)
{
//更新设备家位置
//更新设备家位置
userKafkaService
.
pushUserDeviceData
(
deviceId
,
lngAndLat
,
2
);
addressProducer
.
pushUserDeviceData
(
deviceId
,
lngAndLat
,
2
);
}
}
}
}
}
}
...
@@ -92,7 +96,7 @@ public class UserKafkaController {
...
@@ -92,7 +96,7 @@ public class UserKafkaController {
sceneDataService
.
getBySceneId
(
scene
.
getId
()));
sceneDataService
.
getBySceneId
(
scene
.
getId
()));
if
(
CollectionUtils
.
isNotEmpty
(
deviceList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
deviceList
))
{
for
(
String
deviceId
:
deviceList
)
{
for
(
String
deviceId
:
deviceList
)
{
userKafkaService
.
pushUserDeviceData
(
deviceId
,
null
,
3
);
//删除设备信息
addressProducer
.
pushUserDeviceData
(
deviceId
,
null
,
3
);
//删除设备信息
}
}
}
}
//删除用户场景数据
//删除用户场景数据
...
...
src/main/java/com/glsx/smart/service/UserKafkaService.java
View file @
b6dc18c
...
@@ -14,5 +14,4 @@ public interface UserKafkaService {
...
@@ -14,5 +14,4 @@ public interface UserKafkaService {
UserAddressSmart
getPointUser
(
Long
userId
);
UserAddressSmart
getPointUser
(
Long
userId
);
void
pushUserDeviceData
(
String
deviceId
,
String
lngAndLat
,
Integer
type
);
}
}
src/main/java/com/glsx/smart/service/impl/UserKafkaServiceImpl.java
View file @
b6dc18c
...
@@ -3,17 +3,17 @@ package com.glsx.smart.service.impl;
...
@@ -3,17 +3,17 @@ package com.glsx.smart.service.impl;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.platform.user.entity.UserAddressSmart
;
import
com.glsx.platform.user.entity.UserAddressSmart
;
import
com.glsx.platform.user.service.UserAddressSmartService
;
import
com.glsx.platform.user.service.UserAddressSmartService
;
import
com.glsx.smart.config.DeviceAddressProducer
;
import
com.glsx.smart.constant.Constants
;
import
com.glsx.smart.constant.Constants
;
import
com.glsx.smart.dao.entity.SmartScene
;
import
com.glsx.smart.dao.entity.SmartScene
;
import
com.glsx.smart.dao.entity.SmartSceneData
;
import
com.glsx.smart.dao.entity.SmartSceneData
;
import
com.glsx.smart.dao.entity.SmartUserRelation
;
import
com.glsx.smart.dao.entity.SmartUserRelation
;
import
com.glsx.smart.dao.mapper.SmartUserRelationMapper
;
import
com.glsx.smart.dao.mapper.SmartUserRelationMapper
;
import
com.glsx.smart.pojo.DeviceMessage
;
import
com.glsx.smart.service.UserKafkaService
;
import
com.glsx.smart.service.UserKafkaService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.dubbo.config.annotation.DubboReference
;
import
org.apache.dubbo.config.annotation.DubboReference
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.kafka.core.KafkaTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
...
@@ -41,8 +41,8 @@ public class UserKafkaServiceImpl implements UserKafkaService {
...
@@ -41,8 +41,8 @@ public class UserKafkaServiceImpl implements UserKafkaService {
@DubboReference
(
version
=
"1.0.0"
)
@DubboReference
(
version
=
"1.0.0"
)
private
UserAddressSmartService
userAddressSmartService
;
private
UserAddressSmartService
userAddressSmartService
;
@
Resource
@
Autowired
private
KafkaTemplate
kafkaTemplate
;
private
DeviceAddressProducer
addressProducer
;
@Resource
@Resource
private
SmartUserRelationMapper
userRelationMapper
;
private
SmartUserRelationMapper
userRelationMapper
;
...
@@ -61,7 +61,7 @@ public class UserKafkaServiceImpl implements UserKafkaService {
...
@@ -61,7 +61,7 @@ public class UserKafkaServiceImpl implements UserKafkaService {
String
lngAndLat
=
userAddress
.
getLng
()
+
":"
+
userAddress
.
getLat
();
String
lngAndLat
=
userAddress
.
getLng
()
+
":"
+
userAddress
.
getLat
();
log
.
info
(
"推送的设备:{} 及其经纬度:{}"
,
deviceList
.
toString
(),
lngAndLat
);
log
.
info
(
"推送的设备:{} 及其经纬度:{}"
,
deviceList
.
toString
(),
lngAndLat
);
for
(
String
deviceId
:
deviceList
)
{
for
(
String
deviceId
:
deviceList
)
{
this
.
pushUserDeviceData
(
deviceId
,
lngAndLat
,
1
);
addressProducer
.
pushUserDeviceData
(
deviceId
,
lngAndLat
,
1
);
}
}
}
}
...
@@ -112,21 +112,4 @@ public class UserKafkaServiceImpl implements UserKafkaService {
...
@@ -112,21 +112,4 @@ public class UserKafkaServiceImpl implements UserKafkaService {
return
null
;
return
null
;
}
}
/**
* 推送设备经纬度数据
* @param deviceId
* @param lngAndLat
* @param type 1新增 2更新 3删除
*/
@Override
public
void
pushUserDeviceData
(
String
deviceId
,
String
lngAndLat
,
Integer
type
)
{
//kafka 发送消息数据封装
DeviceMessage
message
=
new
DeviceMessage
();
message
.
setDeviceId
(
deviceId
);
message
.
setLngAndLat
(
lngAndLat
);
message
.
setType
(
type
);
log
.
info
(
"推送kafka topic【{}】的数据:{}"
,
Constants
.
DEVICE_DATA_TOPIC
,
message
.
toString
());
//推送kafka
kafkaTemplate
.
send
(
Constants
.
DEVICE_DATA_TOPIC
,
JSON
.
toJSONString
(
message
));
}
}
}
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