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 39a6c29c
authored
Apr 24, 2021
by
fz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1.返回最新时间手机蓝牙以及感应到单独查车钥匙,和用户查车钥匙接口
1 parent
d92a2ab7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
16 deletions
src/main/java/com/glsx/smart/service/impl/AiLockingKeyServiceImpl.java
src/main/java/com/glsx/smart/service/impl/AiLockingKeyServiceImpl.java
View file @
39a6c29
...
...
@@ -20,9 +20,9 @@ import org.springframework.beans.BeanUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.*
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.stream.Collectors
;
/**
* <p>Description:智能车钥匙service
...
...
@@ -249,6 +249,7 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
//存在,更新感应状态
blueSense
=
blueSenseList
.
get
(
0
);
blueSense
.
setAutoSenseStatus
(
autoSenseStatus
);
blueSense
.
setCreateTime
(
new
Date
());
smartKeyBlueSenseService
.
updateByPrimaryKeySelective
(
blueSense
);
}
...
...
@@ -258,21 +259,84 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
//根据用户ID查询车钥匙
@Override
public
R
getAllKeyByUser
(
SmartCarKeyUserRequest
request
)
{
long
userId
=
Long
.
valueOf
(
request
.
getUserId
());
SmartVehicleBlueKeyExample
example
=
new
SmartVehicleBlueKeyExample
();
example
.
createCriteria
()
.
andUserIdEqualTo
(
Long
.
valueOf
(
request
.
getUserId
())
)
.
andUserIdEqualTo
(
userId
)
.
andIsDeleteEqualTo
(
0
);
List
<
SmartVehicleBlueKey
>
keyList
=
smartVehicleBlueKeyService
.
selectByExample
(
example
);
//如果没有数据直接返回
if
(
CollectionUtils
.
isEmpty
(
keyList
))
{
return
R
.
ok
().
data
(
keyList
);
return
R
.
ok
().
data
(
null
);
}
//转化为sn,完整车钥匙数据
Map
<
String
,
SmartCarKeyResponse
>
smartCarKeyResponseMap
=
keyList
.
stream
().
map
(
key
->
{
SmartCarKeyResponse
response
=
new
SmartCarKeyResponse
();
//拷贝属性
BeanUtils
.
copyProperties
(
key
,
response
);
return
response
;
}).
collect
(
Collectors
.
toMap
(
SmartCarKeyResponse:
:
getSn
,
item
->
item
));
List
<
SmartCarKeyResponse
>
responseList
=
new
ArrayList
<>(
smartCarKeyResponseMap
.
values
());
//给没有名称的钥匙设置名字
AtomicInteger
num
=
new
AtomicInteger
(
1
);
key
List
.
stream
()
response
List
.
stream
()
.
filter
(
key
->
StringUtils
.
isBlank
(
key
.
getKeyName
()))
.
forEach
(
key
->
key
.
setKeyName
(
"钥匙"
+
num
.
getAndIncrement
()));
//根据用户查询蓝牙,感应列表
SmartKeyBlueSenseExample
blueSenseExampl
=
new
SmartKeyBlueSenseExample
();
blueSenseExampl
.
createCriteria
()
.
andUserIdEqualTo
(
userId
)
.
andIsDeleteEqualTo
(
0
);
List
<
SmartKeyBlueSense
>
smartKeyBlueSenseList
=
smartKeyBlueSenseService
.
selectByExample
(
blueSenseExampl
);
//如果用户下没有蓝牙记录
if
(
CollectionUtils
.
isEmpty
(
smartKeyBlueSenseList
))
{
return
R
.
ok
().
data
(
responseList
);
}
//转化为sn,蓝牙感应数据
Map
<
String
,
SmartKeyBlueSense
>
blueSenseListMap
=
new
HashMap
<>();
smartKeyBlueSenseList
.
stream
().
forEach
(
blueSense
->
{
String
sn
=
blueSense
.
getSn
();
SmartKeyBlueSense
data
=
null
;
if
(
blueSenseListMap
.
containsKey
(
sn
))
{
data
=
blueSenseListMap
.
get
(
sn
);
}
else
{
data
=
new
SmartKeyBlueSense
();
}
Date
time1
=
blueSense
.
getCreateTime
();
Date
time2
=
data
.
getCreateTime
();
if
(
null
==
time2
)
{
data
.
setCreateTime
(
time1
);
}
else
{
//time1小于time2返回-1,time1大于time2返回1,相等返回0
int
res
=
time1
.
compareTo
(
time2
);
if
(
res
==
1
)
data
.
setCreateTime
(
time1
);
}
blueSenseListMap
.
put
(
sn
,
data
);
});
//将蓝牙感应数据添加
responseList
.
stream
().
forEach
(
response
->{
String
sn
=
response
.
getSn
();
if
(
blueSenseListMap
.
containsKey
(
sn
)){
SmartKeyBlueSense
blueSense
=
blueSenseListMap
.
get
(
sn
);
response
.
setMobileBlueMac
(
blueSense
.
getMobileBlueMac
());
response
.
setAutoSenseStatus
(
blueSense
.
getAutoSenseStatus
());
}
});
return
R
.
ok
().
data
(
keyList
);
}
...
...
@@ -421,22 +485,13 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
//userID查询关联的手机蓝牙mac,自动感应状态
SmartKeyBlueSense
smartKeyBlueSense
=
getMobileBlueSenseByUser
(
carkey
.
getUserId
(),
carkey
.
getSn
());
if
(
null
!
=
smartKeyBlueSense
)
if
(
null
=
=
smartKeyBlueSense
)
return
;
response
.
setMobileBlueMac
(
smartKeyBlueSense
.
getMobileBlueMac
());
response
.
setAutoSenseStatus
(
smartKeyBlueSense
.
getAutoSenseStatus
());
}
private
SmartKeyBlueSense
getMobileBlueSenseByUser
(
Long
userId
,
String
sn
)
{
SmartKeyBlueSense
blueSense
=
null
;
SmartKeyBlueSenseExample
example
=
new
SmartKeyBlueSenseExample
();
example
.
createCriteria
().
andUserIdEqualTo
(
userId
).
andSnEqualTo
(
sn
).
andIsDeleteEqualTo
(
0
);
List
<
SmartKeyBlueSense
>
smartKeyBlueSenseList
=
smartKeyBlueSenseService
.
selectByExample
(
example
);
if
(
CollectionUtils
.
isNotEmpty
(
smartKeyBlueSenseList
))
blueSense
=
smartKeyBlueSenseList
.
get
(
0
);
return
blueSense
;
}
//查询车钥匙example,根据用户ID和sn查
private
SmartVehicleBlueKeyExample
getBlueKeyExampleBysn
(
Long
userId
,
String
sn
)
{
...
...
@@ -458,6 +513,33 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
return
example
;
}
private
SmartKeyBlueSense
getMobileBlueSenseByUser
(
Long
userId
,
String
sn
)
{
SmartKeyBlueSenseExample
example
=
getBlueSenseExampleBysn
(
userId
,
sn
);
List
<
SmartKeyBlueSense
>
smartKeyBlueSenseList
=
smartKeyBlueSenseService
.
selectByExample
(
example
);
return
getRecentBlueMacAutoSense
(
smartKeyBlueSenseList
);
}
//获取最新的手机蓝牙,自动感应记录
private
SmartKeyBlueSense
getRecentBlueMacAutoSense
(
List
<
SmartKeyBlueSense
>
smartKeyBlueSenseList
)
{
if
(
CollectionUtils
.
isEmpty
(
smartKeyBlueSenseList
))
return
null
;
smartKeyBlueSenseList
.
sort
((
SmartKeyBlueSense
o1
,
SmartKeyBlueSense
o2
)
->
{
Date
date1
=
o1
.
getCreateTime
();
Date
date2
=
o2
.
getCreateTime
();
if
(
null
==
date1
)
return
1
;
if
(
null
==
date2
)
return
-
1
;
return
o2
.
getCreateTime
().
compareTo
(
o1
.
getCreateTime
());
}
);
return
smartKeyBlueSenseList
.
get
(
0
);
}
//获取crep(雪花算法+userid)
private
String
getCrepCode
()
{
String
snowId
=
Long
.
toHexString
(
snowflakeWorker
.
nextId
());
...
...
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