Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-devicemonitor
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 1e5fccf4
authored
Jun 15, 2022
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'feature' of
http://192.168.3.233:8090/eshiled-new/ne-shield-devicemonitor
2 parents
1ac106b8
c74b6cb5
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
245 additions
and
11 deletions
src/main/java/cn/com/glsx/devicemonitor/modules/api/FeignDeviceController.java
src/main/java/cn/com/glsx/devicemonitor/modules/components/HdaoGpsComponent.java
src/main/java/cn/com/glsx/devicemonitor/modules/model/TrackInfoDTO.java
src/main/java/cn/com/glsx/devicemonitor/modules/model/response/GetEShieldTrackInfoListResp.java
src/main/java/cn/com/glsx/devicemonitor/modules/service/DeviceService.java
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/DeviceServiceImpl.java
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/EShieldService.java
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/GpsBsLocationServiceImpl.java
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/MonitorServiceImpl.java
src/test/java/cn/com/glsx/devicemonitor/modules/components/HdaoGpsComponentTest.java
src/test/java/cn/com/glsx/devicemonitor/modules/service/impl/DeviceServiceImplTest.java
src/test/java/cn/com/glsx/devicemonitor/modules/service/impl/EShieldServiceTest.java
src/main/java/cn/com/glsx/devicemonitor/modules/api/FeignDeviceController.java
View file @
1e5fccf
...
...
@@ -50,7 +50,7 @@ public class FeignDeviceController implements DeviceFeignService {
}
@Override
@GetMapping
(
{
"/getOrStoreDeviceBySn"
}
)
@GetMapping
(
value
=
"/getOrStoreDeviceBySn"
)
public
R
<
DeviceDTO
>
getOrStoreDeviceBySn
(
@RequestParam
(
value
=
"sn"
)
String
sn
,
@RequestParam
(
value
=
"storeIfNotExists"
)
Boolean
storeIfNotExists
)
{
if
(
storeIfNotExists
==
null
)
{
storeIfNotExists
=
false
;
...
...
@@ -59,6 +59,13 @@ public class FeignDeviceController implements DeviceFeignService {
return
R
.
ok
().
data
(
deviceDTO
);
}
@Override
@PostMapping
(
value
=
"/getOrStoreDeviceBySns"
)
public
R
<
List
<
DeviceDTO
>>
getOrStoreDeviceBySns
(
List
<
String
>
sns
)
{
List
<
DeviceDTO
>
deviceDTOList
=
deviceService
.
getOrStoreDeviceBySns
(
sns
);
return
R
.
ok
().
data
(
deviceDTOList
);
}
/**
* 获取设备的状态
*
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/components/HdaoGpsComponent.java
View file @
1e5fccf
...
...
@@ -867,8 +867,11 @@ public class HdaoGpsComponent {
DataGpsLocation
gpsLocation
=
new
DataGpsLocation
();
gpsLocation
.
setSn
(
sn
);
gpsLocation
.
setLat
(
lngLat
[
0
]);
gpsLocation
.
setLng
(
lngLat
[
1
]);
gpsLocation
.
setLng
(
lngLat
[
0
]);
gpsLocation
.
setLat
(
lngLat
[
1
]);
gpsLocation
.
setElng
(
lngLat
[
0
]);
gpsLocation
.
setElat
(
lngLat
[
1
]);
gpsLocation
.
setAddress
(
wifiMapInfoModel
.
getDesc
());
gpsLocation
.
setStoreTime
(
DateUtil
.
formatDateTime
(
date
));
gpsLocation
.
setDateTime
(
DateUtil
.
formatDateTime
(
date
));
return
gpsLocation
;
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/model/TrackInfoDTO.java
View file @
1e5fccf
...
...
@@ -42,4 +42,8 @@ public class TrackInfoDTO {
private
String
partner
;
/**
* 设备类型名称
*/
private
String
deviceClassifyName
;
}
\ No newline at end of file
src/main/java/cn/com/glsx/devicemonitor/modules/model/response/GetEShieldTrackInfoListResp.java
0 → 100644
View file @
1e5fccf
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
model
.
response
;
import
cn.com.glsx.devicemonitor.modules.model.TrackInfoDTO
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
GetEShieldTrackInfoListResp
extends
AbstractEShieldResponse
{
/**
* 设备集合
*/
private
List
<
TrackInfoDTO
>
data
;
}
src/main/java/cn/com/glsx/devicemonitor/modules/service/DeviceService.java
View file @
1e5fccf
...
...
@@ -49,6 +49,15 @@ public interface DeviceService {
*/
DeviceDTO
getDeviceDTOBySn
(
String
sn
,
Boolean
storeIfNotExists
);
/**
* 根据设备号批量查询设备信息,不存在就同步
*
* @param sns 设备号集合
* @return
*/
List
<
DeviceDTO
>
getOrStoreDeviceBySns
(
List
<
String
>
sns
);
/**
* 获取设备的在线状态
*
...
...
@@ -66,6 +75,14 @@ public interface DeviceService {
*/
Device
getDeviceOrRemote
(
String
sn
,
Boolean
storeIfNotExists
);
/**
* 批量查询设备(本地库没有,查询旧E盾)
*
* @param sns 设备号集合
* @return
*/
List
<
Device
>
getDeviceListOrRemote
(
List
<
String
>
sns
);
/**
* 获取设备上点总次数
...
...
@@ -100,5 +117,4 @@ public interface DeviceService {
* @return
*/
Map
<
String
,
DeviceTypeRelationEnum
>
getDeviceTypes
(
List
<
String
>
snList
);
}
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/DeviceServiceImpl.java
View file @
1e5fccf
...
...
@@ -15,9 +15,11 @@ import cn.com.glsx.devicemonitor.modules.mapper.DeviceMapper;
import
cn.com.glsx.devicemonitor.modules.model.TrackInfoDTO
;
import
cn.com.glsx.devicemonitor.modules.service.DeviceService
;
import
cn.com.glsx.devicemonitor.modules.utils.DeviceUtils
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.date.StopWatch
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.nacos.common.utils.CollectionUtils
;
import
com.alibaba.nacos.common.utils.StringUtils
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -89,6 +91,19 @@ public class DeviceServiceImpl implements DeviceService {
}
@Override
public
List
<
DeviceDTO
>
getOrStoreDeviceBySns
(
List
<
String
>
sns
)
{
if
(
CollectionUtil
.
isEmpty
(
sns
))
{
return
null
;
}
List
<
Device
>
deviceList
=
getDeviceListOrRemote
(
sns
);
return
deviceList
.
stream
().
map
(
device
->
{
DeviceDTO
deviceDTO
=
new
DeviceDTO
();
BeanUtils
.
copyProperties
(
device
,
deviceDTO
);
return
deviceDTO
;
}).
collect
(
Collectors
.
toList
());
}
@Override
public
DeviceStatusModel
getDeviceStatusBySn
(
String
sn
,
Long
offlineTime
)
{
Device
device
=
getDeviceOrRemote
(
sn
,
false
);
if
(
device
==
null
)
{
...
...
@@ -184,12 +199,44 @@ public class DeviceServiceImpl implements DeviceService {
return
device
;
}
@Override
public
List
<
Device
>
getDeviceListOrRemote
(
List
<
String
>
sns
)
{
List
<
Device
>
deviceList
=
deviceMapper
.
selectBySns
(
sns
);
List
<
String
>
dbSnList
=
deviceList
.
stream
().
map
(
Device:
:
getSn
).
collect
(
Collectors
.
toList
());
// 获取不在数据库中的设备号集合(老E盾没有同步过来的设备号)
List
<
String
>
remoteSnList
=
sns
.
stream
().
filter
(
sn
->
!
dbSnList
.
contains
(
sn
)).
collect
(
Collectors
.
toList
());
List
<
Device
>
remoteDeviceList
=
getRemoteDeviceList
(
StringUtils
.
join
(
remoteSnList
,
","
));
if
(
CollectionUtil
.
isNotEmpty
(
remoteDeviceList
))
{
//如果老E盾存在 则同步老E盾中的设备数据到新E盾
deviceMapper
.
insertList
(
remoteDeviceList
);
deviceList
.
addAll
(
remoteDeviceList
);
}
return
deviceList
;
}
/**
* 通过设备号获取老E盾设备号数据
*
* @param sn 设备号
* @return
*/
public
Device
getRemoteDevice
(
String
sn
)
{
TrackInfoDTO
trackInfoDTO
=
eShieldService
.
getDeviceBySn
(
sn
);
return
convertDevice
(
trackInfoDTO
,
0L
);
}
/**
* 根据设备号集合获取老E盾设备号数据
*
* @param sns 设备号集合
* @return
*/
public
List
<
Device
>
getRemoteDeviceList
(
String
sns
)
{
List
<
TrackInfoDTO
>
trackInfoDTOList
=
eShieldService
.
getDeviceListBySns
(
sns
);
return
convertDeviceList
(
trackInfoDTOList
,
0L
);
}
/**
* 保存从E盾过来的设备
*
* @param trackInfo
...
...
@@ -210,6 +257,32 @@ public class DeviceServiceImpl implements DeviceService {
return
device
;
}
/**
* 保存从E盾过来的设备
*
* @param trackInfoList 设备号集合
* @param createId 默认创建人
*/
public
List
<
Device
>
convertDeviceList
(
List
<
TrackInfoDTO
>
trackInfoList
,
Long
createId
)
{
if
(
CollectionUtil
.
isEmpty
(
trackInfoList
))
{
return
null
;
}
List
<
Device
>
deviceList
=
Lists
.
newArrayList
();
for
(
TrackInfoDTO
trackInfo
:
trackInfoList
)
{
Device
device
=
new
Device
();
BeanUtils
.
copyProperties
(
trackInfo
,
device
);
device
.
setManufacturer
(
trackInfo
.
getPartner
());
device
.
setModelName
(
trackInfo
.
getDeviceClassifyName
());
device
.
setSource
(
trackInfo
.
getSource
());
device
.
setActivateStatus
(
trackInfo
.
getIsActive
());
device
.
setActivateTime
(
trackInfo
.
getActiveDate
());
device
.
setCreatedBy
(
createId
);
device
.
setCreatedDate
(
new
Date
());
deviceList
.
add
(
device
);
}
return
deviceList
;
}
@Override
public
Integer
getDevicesTotalCount
(
String
sn
)
{
DevicesTotalCountResHolder
res
=
new
DevicesTotalCountResHolder
();
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/EShieldService.java
View file @
1e5fccf
...
...
@@ -3,6 +3,7 @@ package cn.com.glsx.devicemonitor.modules.service.impl;
import
cn.com.glsx.devicemonitor.config.EShieldConfig
;
import
cn.com.glsx.devicemonitor.modules.model.TrackInfoDTO
;
import
cn.com.glsx.devicemonitor.modules.model.response.GetDeviceClassifyNameResp
;
import
cn.com.glsx.devicemonitor.modules.model.response.GetEShieldTrackInfoListResp
;
import
cn.com.glsx.devicemonitor.modules.model.response.GetEShieldTrackInfoResp
;
import
cn.com.glsx.devicemonitor.modules.utils.GopUtil
;
import
com.alibaba.fastjson.JSONObject
;
...
...
@@ -11,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.TreeMap
;
@Slf4j
...
...
@@ -44,6 +46,29 @@ public class EShieldService {
}
/**
* 调用e盾标准接口批量获取设备信息
*
* @param sns 设备号集合 用 , 分隔
*/
public
List
<
TrackInfoDTO
>
getDeviceListBySns
(
String
sns
)
{
String
url
=
config
.
getApiUrl
()
+
"/api/device/getInfoListBySns"
;
TreeMap
<
String
,
Object
>
tparams
=
new
TreeMap
<>();
tparams
.
put
(
"appKey"
,
config
.
getAppId
());
tparams
.
put
(
"sns"
,
sns
);
//加密得到sign
String
sign
=
GopUtil
.
sign
(
tparams
,
config
.
getAppSecret
());
tparams
.
put
(
"sign"
,
sign
);
String
result
=
HttpUtils
.
get
(
url
,
tparams
);
log
.
info
(
"getInfoListBySns result {}"
,
result
);
GetEShieldTrackInfoListResp
resp
=
JSONObject
.
parseObject
(
result
,
GetEShieldTrackInfoListResp
.
class
);
if
(!
"0"
.
equals
(
resp
.
getReturnCode
()))
{
log
.
info
(
"remote getInfoListBySns fail! returnCode:"
+
resp
.
getReturnCode
()
+
"; message:"
+
resp
.
getMessage
());
return
null
;
}
return
resp
.
getData
();
}
/**
* 调用e盾标准接口获取设备型号
*
* @param sn 设备号
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/GpsBsLocationServiceImpl.java
View file @
1e5fccf
...
...
@@ -97,7 +97,12 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService {
gpsBsData
.
setGpsLocation
(
DataLocationConvert
.
convertDataToGpsLocation
(
gpsLocation
));
}
//补充获取wifi的定位
DataGpsLocation
wifiLocation
=
getDeviceLastWifiInfoBySn
(
sn
);
boolean
hasWifi
=
isHasWifi
(
sn
);
gpsBsData
.
setHasWifi
(
hasWifi
);
if
(!
hasWifi
)
{
continue
;
}
DataGpsLocation
wifiLocation
=
hdaoGpsComponent
.
getWifiLocation
(
sn
);
if
(
wifiLocation
!=
null
)
{
gpsBsData
.
setWifiLocation
(
DataLocationConvert
.
convertDataToGpsLocation
(
wifiLocation
));
}
...
...
@@ -138,7 +143,12 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService {
if
(
bsLocation
!=
null
)
{
gpsBsData
.
setBsLocation
(
DataLocationConvert
.
convertDataToGpsLocation
(
bsLocation
));
}
DataGpsLocation
wifiLocation
=
getDeviceLastWifiInfoBySn
(
sn
);
boolean
hasWifi
=
isHasWifi
(
sn
);
gpsBsData
.
setHasWifi
(
hasWifi
);
DataGpsLocation
wifiLocation
=
null
;
if
(
hasWifi
)
{
wifiLocation
=
hdaoGpsComponent
.
getWifiLocation
(
sn
);
}
if
(
wifiLocation
!=
null
)
{
gpsBsData
.
setWifiLocation
(
DataLocationConvert
.
convertDataToGpsLocation
(
wifiLocation
));
}
...
...
@@ -360,6 +370,15 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService {
*/
public
DataGpsLocation
getDeviceLastWifiInfoBySn
(
String
sn
)
{
//具有wifi定位的设备起始号
boolean
hasWifi
=
isHasWifi
(
sn
);
if
(!
hasWifi
)
{
return
null
;
}
DataGpsLocation
wifiLocation
=
hdaoGpsComponent
.
getWifiLocation
(
sn
);
return
wifiLocation
;
}
private
boolean
isHasWifi
(
String
sn
)
{
String
wifiSns
=
PropertiesUtils
.
getProperty
(
"wifi.sn.start.location"
);
boolean
hasWifi
=
false
;
if
(
StringUtils
.
isNotBlank
(
wifiSns
))
{
...
...
@@ -371,11 +390,7 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService {
}
}
}
if
(!
hasWifi
)
{
return
null
;
}
DataGpsLocation
wifiLocation
=
hdaoGpsComponent
.
getWifiLocation
(
sn
);
return
wifiLocation
;
return
hasWifi
;
}
@Override
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/MonitorServiceImpl.java
View file @
1e5fccf
...
...
@@ -5,6 +5,7 @@ import cn.com.glsx.devicemonitor.api.dto.response.DeviceLocationDTO;
import
cn.com.glsx.devicemonitor.api.dto.response.DeviceStatusModel
;
import
cn.com.glsx.devicemonitor.api.dto.response.GpsBsData
;
import
cn.com.glsx.devicemonitor.api.dto.response.GpsLocation
;
import
cn.com.glsx.devicemonitor.api.enums.DeviceStatusEnum
;
import
cn.com.glsx.devicemonitor.api.enums.DeviceTypeRelationEnum
;
import
cn.com.glsx.devicemonitor.iceprotocol.mile.GpsLoc
;
import
cn.com.glsx.devicemonitor.iceprotocol.mile.StayPointRecord
;
...
...
@@ -295,6 +296,8 @@ public class MonitorServiceImpl implements MonitorService {
public
void
getDeviceOnlineStatus
(
DeviceLocationDTO
locationDTO
,
long
offlineTime
)
{
DeviceLocation
deviceLogin
=
deviceLocationMapper
.
selectBySn
(
locationDTO
.
getSn
());
if
(
deviceLogin
==
null
)
{
//从来没有上点记录,按离线处理
locationDTO
.
setStatus
(
DeviceStatusEnum
.
OFFLINE
.
getCode
());
return
;
}
...
...
src/test/java/cn/com/glsx/devicemonitor/modules/components/HdaoGpsComponentTest.java
0 → 100644
View file @
1e5fccf
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
components
;
import
cn.com.glsx.Application
;
import
cn.com.glsx.devicemonitor.modules.entity.inner.DataGpsLocation
;
import
com.alibaba.fastjson.JSON
;
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
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
/**
* @author xiangyanlin
* @date 2022/6/6
*/
@Slf4j
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Application
.
class
,
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
class
HdaoGpsComponentTest
{
@Autowired
private
HdaoGpsComponent
hdaoGpsComponent
;
@Test
public
void
testGet
(){
DataGpsLocation
wifiLocation
=
hdaoGpsComponent
.
getWifiLocation
(
"4711124038"
);
System
.
out
.
println
(
JSON
.
toJSONString
(
wifiLocation
));
}
}
\ No newline at end of file
src/test/java/cn/com/glsx/devicemonitor/modules/service/impl/DeviceServiceImplTest.java
0 → 100644
View file @
1e5fccf
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
service
.
impl
;
import
cn.com.glsx.Application
;
import
cn.com.glsx.devicemonitor.modules.entity.Device
;
import
cn.com.glsx.devicemonitor.modules.service.DeviceService
;
import
cn.hutool.json.JSONUtil
;
import
com.google.common.collect.Lists
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.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.List
;
@Slf4j
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Application
.
class
,
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
public
class
DeviceServiceImplTest
{
@Autowired
private
DeviceService
deviceService
;
@Test
public
void
getDeviceListOrRemote
()
{
List
<
Device
>
deviceListOrRemote
=
deviceService
.
getDeviceListOrRemote
(
Lists
.
newArrayList
(
"8130902004"
));
System
.
out
.
println
(
"deviceListOrRemote = "
+
JSONUtil
.
toJsonStr
(
deviceListOrRemote
));
}
}
\ No newline at end of file
src/test/java/cn/com/glsx/devicemonitor/modules/service/impl/EShieldServiceTest.java
View file @
1e5fccf
...
...
@@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
java.util.List
;
@Slf4j
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Application
.
class
,
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
...
...
@@ -22,4 +24,10 @@ class EShieldServiceTest {
TrackInfoDTO
deviceBySn
=
eShieldService
.
getDeviceBySn
(
"45106800001"
);
System
.
out
.
println
(
"deviceBySn = "
+
JSONUtil
.
toJsonStr
(
deviceBySn
));
}
@Test
public
void
TestGetDeviceListBySns
()
{
List
<
TrackInfoDTO
>
deviceBySnList
=
eShieldService
.
getDeviceListBySns
(
"45106800001,8130902003"
);
System
.
out
.
println
(
"deviceBySn = "
+
JSONUtil
.
toJsonStr
(
deviceBySnList
));
}
}
\ 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