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 1c8599a3
authored
May 08, 2021
by
wnb0128
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
车家智能代码逻辑优化--think.wang
1 parent
9576aac6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
51 deletions
src/main/java/cn/com/glsx/smart/config/DeviceAddressProducer.java → src/main/java/cn/com/glsx/smart/component/DeviceAddressProducer.java
src/main/java/cn/com/glsx/smart/modules/controller/IndexController.java
src/main/java/cn/com/glsx/smart/modules/controller/UserKafkaController.java
src/main/java/cn/com/glsx/smart/modules/service/impl/UserKafkaServiceImpl.java
src/main/java/cn/com/glsx/smart/co
nfig
/DeviceAddressProducer.java
→
src/main/java/cn/com/glsx/smart/co
mponent
/DeviceAddressProducer.java
View file @
1c8599a
package
cn
.
com
.
glsx
.
smart
.
co
nfig
;
package
cn
.
com
.
glsx
.
smart
.
co
mponent
;
import
cn.com.glsx.smart.common.utils.GCJ2WGS
;
import
cn.com.glsx.smart.common.utils.GCJ2WGS
;
import
cn.com.glsx.smart.config.KafkaConfig
;
import
cn.com.glsx.smart.modules.model.pb.InstanceFence.Fence
;
import
cn.com.glsx.smart.modules.model.pb.InstanceFence.Fence
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
kafka.javaapi.producer.Producer
;
import
kafka.javaapi.producer.Producer
;
...
...
src/main/java/cn/com/glsx/smart/modules/controller/IndexController.java
View file @
1c8599a
package
cn
.
com
.
glsx
.
smart
.
modules
.
controller
;
package
cn
.
com
.
glsx
.
smart
.
modules
.
controller
;
import
cn.com.glsx.smart.co
nfig
.DeviceAddressProducer
;
import
cn.com.glsx.smart.co
mponent
.DeviceAddressProducer
;
import
cn.com.glsx.smart.modules.entity.SmartProduct
;
import
cn.com.glsx.smart.modules.entity.SmartProduct
;
import
cn.com.glsx.smart.modules.model.pb.InstanceFence.Fence
;
import
cn.com.glsx.smart.modules.model.pb.InstanceFence.Fence
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
...
src/main/java/cn/com/glsx/smart/modules/controller/UserKafkaController.java
View file @
1c8599a
package
cn
.
com
.
glsx
.
smart
.
modules
.
controller
;
package
cn
.
com
.
glsx
.
smart
.
modules
.
controller
;
import
cn.com.glsx.smart.co
nfig
.DeviceAddressProducer
;
import
cn.com.glsx.smart.co
mponent
.DeviceAddressProducer
;
import
cn.com.glsx.smart.modules.entity.SmartScene
;
import
cn.com.glsx.smart.modules.entity.SmartScene
;
import
cn.com.glsx.smart.modules.entity.SmartSceneData
;
import
cn.com.glsx.smart.modules.entity.SmartSceneData
;
import
cn.com.glsx.smart.modules.entity.SmartUserRelation
;
import
cn.com.glsx.smart.modules.entity.SmartUserRelation
;
...
@@ -54,29 +54,26 @@ public class UserKafkaController {
...
@@ -54,29 +54,26 @@ public class UserKafkaController {
* @return
* @return
*/
*/
@ResponseBody
@ResponseBody
@RequestMapping
(
value
=
"/updateUserAddress"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@RequestMapping
(
value
=
"/updateUserAddress"
,
method
=
{
RequestMethod
.
GET
})
public
boolean
updateUserAddress
(
@RequestParam
(
"userId"
)
Long
userId
,
@RequestParam
(
"phone"
)
String
phone
,
public
boolean
updateUserAddress
(
@RequestParam
(
"userId"
)
Long
userId
,
@RequestParam
(
"phone"
)
String
phone
,
@RequestParam
(
"lngAndLat"
)
String
lngAndLat
){
@RequestParam
(
"lngAndLat"
)
String
lngAndLat
){
log
.
info
(
"更新用户家庭地址:{} {} {}"
,
userId
,
phone
,
lngAndLat
);
log
.
info
(
"更新用户家庭地址:{} {} {}"
,
userId
,
phone
,
lngAndLat
);
SmartUserRelation
relation
=
getUserRelation
(
userId
,
phone
);
List
<
SmartScene
>
sceneList
=
this
.
getUserSceneData
(
userId
,
phone
);
if
(
relation
==
null
){
if
(
CollectionUtils
.
isEmpty
(
sceneList
)){
return
false
;
}
SmartScene
record
=
new
SmartScene
();
record
.
setUserId
(
relation
.
getId
());
List
<
SmartScene
>
sceneList
=
sceneService
.
getList
(
record
);
if
(
sceneList
.
isEmpty
()){
return
false
;
return
false
;
}
}
int
len
=
sceneList
.
size
();
int
len
=
sceneList
.
size
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
SmartScene
scene
=
sceneList
.
get
(
i
);
SmartScene
scene
=
sceneList
.
get
(
i
);
List
<
String
>
deviceList
=
userKafkaService
.
getSendDeviceList
(
//用户场景数据获取
sceneDataService
.
getBySceneId
(
scene
.
getId
()));
List
<
SmartSceneData
>
dataList
=
sceneDataService
.
getBySceneId
(
scene
.
getId
());
if
(
CollectionUtils
.
isNotEmpty
(
deviceList
)){
if
(
CollectionUtils
.
isNotEmpty
(
dataList
))
{
for
(
String
deviceId
:
deviceList
)
{
List
<
String
>
deviceList
=
userKafkaService
.
getSendDeviceList
(
dataList
);
//更新设备家位置
if
(
CollectionUtils
.
isNotEmpty
(
deviceList
))
{
addressProducer
.
pushUserDeviceData
(
deviceId
,
lngAndLat
,
Fence
.
OperationType
.
UPDATE_VALUE
);
for
(
String
deviceId
:
deviceList
)
{
//更新设备家位置
addressProducer
.
pushUserDeviceData
(
deviceId
,
lngAndLat
,
Fence
.
OperationType
.
UPDATE_VALUE
);
}
}
}
}
}
}
}
...
@@ -84,51 +81,56 @@ public class UserKafkaController {
...
@@ -84,51 +81,56 @@ public class UserKafkaController {
}
}
@ResponseBody
@ResponseBody
@RequestMapping
(
value
=
"/logoutUserScene"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@RequestMapping
(
value
=
"/logoutUserScene"
,
method
=
{
RequestMethod
.
GET
})
public
boolean
logoutUserScene
(
@RequestParam
(
"userId"
)
Long
userId
,
@RequestParam
(
"phone"
)
String
phone
)
{
public
boolean
logoutUserScene
(
@RequestParam
(
"userId"
)
Long
userId
,
@RequestParam
(
"phone"
)
String
phone
)
{
SmartUserRelation
relation
=
getUserRelation
(
userId
,
phone
);
log
.
info
(
"嘀嘀虎用户注销:{} {}"
,
userId
,
phone
);
if
(
relation
!=
null
)
{
List
<
SmartScene
>
sceneList
=
this
.
getUserSceneData
(
userId
,
phone
);
SmartScene
record
=
new
SmartScene
();
if
(
CollectionUtils
.
isEmpty
(
sceneList
)){
record
.
setUserId
(
relation
.
getId
());
return
false
;
List
<
SmartScene
>
sceneList
=
sceneService
.
getList
(
record
);
}
if
(
CollectionUtils
.
isNotEmpty
(
sceneList
))
{
for
(
SmartScene
scene
:
sceneList
)
{
int
len
=
sceneList
.
size
();
//用户场景数据获取
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
List
<
SmartSceneData
>
dataList
=
sceneDataService
.
getBySceneId
(
scene
.
getId
());
SmartScene
scene
=
sceneList
.
get
(
j
);
if
(
CollectionUtils
.
isNotEmpty
(
dataList
)){
List
<
SmartSceneData
>
dataList
=
sceneDataService
.
getBySceneId
(
scene
.
getId
());
//删除设备位置数据
if
(
CollectionUtils
.
isNotEmpty
(
dataList
)){
List
<
String
>
deviceList
=
userKafkaService
.
getSendDeviceList
(
dataList
);
List
<
String
>
deviceList
=
userKafkaService
.
getSendDeviceList
(
dataList
);
if
(
CollectionUtils
.
isNotEmpty
(
deviceList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
deviceList
))
{
for
(
String
deviceId
:
deviceList
)
{
for
(
String
deviceId
:
deviceList
)
{
addressProducer
.
pushUserDeviceData
(
deviceId
,
null
,
Fence
.
OperationType
.
DEL_VALUE
);
//删除设备信息
addressProducer
.
pushUserDeviceData
(
deviceId
,
null
,
Fence
.
OperationType
.
DEL_VALUE
);
//删除设备信息
}
}
}
//删除用户场景数据
int
i
=
sceneService
.
deleteByPrimaryKey
(
scene
.
getId
());
if
(
i
>
0
){
sceneDataService
.
deleteBySceneId
(
scene
.
getId
());
sceneLogService
.
insertWrapper
(
scene
.
getUserId
(),
"删除场景数据:"
+
scene
.
getId
(),
JSON
.
toJSONString
(
scene
));
}
}
}
}
}
}
//删除用户场景数据
int
i
=
sceneService
.
deleteByPrimaryKey
(
scene
.
getId
());
if
(
i
>
0
){
sceneDataService
.
deleteBySceneId
(
scene
.
getId
());
//添加用户场景删除日志
sceneLogService
.
insertWrapper
(
scene
.
getUserId
(),
"删除场景数据:"
+
scene
.
getId
(),
JSON
.
toJSONString
(
scene
));
}
}
}
return
true
;
return
true
;
}
}
/**
/**
* 获取车家智能用户关系
* 获取用户场景数据
*
* @param userId
* @param userId
* @param phone
* @param phone
* @return
* @return
*/
*/
private
SmartUserRelation
getUserRelation
(
Long
userId
,
String
phone
){
private
List
<
SmartScene
>
getUserSceneData
(
Long
userId
,
String
phone
){
SmartUserRelation
record
=
new
SmartUserRelation
();
SmartUserRelation
param
=
new
SmartUserRelation
();
record
.
setUserId
(
userId
);
param
.
setUserId
(
userId
);
record
.
setPhone
(
phone
);
param
.
setPhone
(
phone
);
// record.setChannel((byte)1);
SmartUserRelation
relation
=
userRelationService
.
getSingle
(
param
);
return
userRelationService
.
getSingle
(
record
);
if
(
relation
!=
null
)
{
//查询用户场景数据列表
SmartScene
record
=
new
SmartScene
();
record
.
setUserId
(
relation
.
getId
());
return
sceneService
.
getList
(
record
);
}
return
null
;
}
}
}
}
src/main/java/cn/com/glsx/smart/modules/service/impl/UserKafkaServiceImpl.java
View file @
1c8599a
package
cn
.
com
.
glsx
.
smart
.
modules
.
service
.
impl
;
package
cn
.
com
.
glsx
.
smart
.
modules
.
service
.
impl
;
import
cn.com.glsx.smart.co
nfig
.DeviceAddressProducer
;
import
cn.com.glsx.smart.co
mponent
.DeviceAddressProducer
;
import
cn.com.glsx.smart.common.constant.Constants
;
import
cn.com.glsx.smart.common.constant.Constants
;
import
cn.com.glsx.smart.modules.entity.SmartScene
;
import
cn.com.glsx.smart.modules.entity.SmartScene
;
import
cn.com.glsx.smart.modules.entity.SmartSceneData
;
import
cn.com.glsx.smart.modules.entity.SmartSceneData
;
...
...
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