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 90ce949a
authored
Sep 10, 2021
by
黄小葱
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改bug 调整代码结构
1 parent
4e87dc55
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
614 additions
and
53 deletions
pom.xml
src/main/java/cn/com/glsx/devicemonitor/modules/controller/DeviceController.java → src/main/java/cn/com/glsx/devicemonitor/modules/api/DeviceApiController.java
src/main/java/cn/com/glsx/devicemonitor/modules/controller/GpsBsController.java → src/main/java/cn/com/glsx/devicemonitor/modules/api/GpsBsApiController.java
src/main/java/cn/com/glsx/devicemonitor/modules/controller/MonitorController.java
src/main/java/cn/com/glsx/devicemonitor/modules/model/TrackInfoBo.java
src/main/java/cn/com/glsx/devicemonitor/modules/model/report/StayPointReport.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/MonitorServiceImpl.java
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/RemoteDeviceService.java
src/main/java/cn/com/glsx/devicemonitor/modules/utils/Coder.java
src/main/java/cn/com/glsx/devicemonitor/modules/utils/GopUtil.java
src/main/java/cn/com/glsx/devicemonitor/modules/utils/MD5Util.java
src/main/resources/bootstrap.properties
src/test/java/cn/com/glsx/test/gpsbs/MonitorTest.java
src/test/java/cn/com/glsx/test/gpsbs/TestDeviceController.java
src/test/java/cn/com/glsx/test/gpsbs/TestGpsBsController.java
pom.xml
View file @
90ce949
...
...
@@ -59,7 +59,6 @@
<dependency>
<groupId>
com.glsx
</groupId>
<artifactId>
rest-admin-swagger2
</artifactId>
<version>
${neshield.common.version}
</version>
</dependency>
<!-- office -->
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/
controller/Device
Controller.java
→
src/main/java/cn/com/glsx/devicemonitor/modules/
api/DeviceApi
Controller.java
View file @
90ce949
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
controller
;
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
api
;
import
cn.com.glsx.devicemonitor.api.dto.response.DeviceDTO
;
import
cn.com.glsx.devicemonitor.api.dto.response.DeviceStatusModel
;
import
cn.com.glsx.devicemonitor.common.ConstantsDevice
;
import
cn.com.glsx.devicemonitor.modules.service.DeviceService
;
import
com.glsx.plat.core.web.R
;
import
io.swagger.annotations.Api
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -18,8 +20,9 @@ import javax.validation.constraints.NotBlank;
@Slf4j
@Validated
@RestController
@RequestMapping
(
"/device"
)
public
class
DeviceController
{
@RequestMapping
(
"/api/device"
)
@Api
(
value
=
"设备查询服务"
,
tags
=
"设备查询服务"
)
public
class
DeviceApiController
{
@Autowired
private
DeviceService
deviceService
;
...
...
@@ -29,9 +32,9 @@ public class DeviceController {
* @param sn
* @return
*/
@GetMapping
(
value
=
"/getDeviceBySn"
)
@GetMapping
(
value
=
"/getDeviceBySn"
,
consumes
=
MediaType
.
APPLICATION_FORM_URLENCODED_VALUE
)
public
R
getDeviceBySn
(
@NotBlank
(
message
=
"设备号不能为空"
)
@RequestParam
(
value
=
"sn"
)
String
sn
)
{
DeviceDTO
deviceDTO
=
deviceService
.
getDeviceBySn
(
sn
);
DeviceDTO
deviceDTO
=
deviceService
.
getDevice
DTO
BySn
(
sn
);
return
R
.
ok
().
data
(
deviceDTO
);
}
...
...
@@ -42,7 +45,7 @@ public class DeviceController {
* @param offlineTime
* @return
*/
@GetMapping
(
value
=
"/getDeviceStatusBySn"
)
@GetMapping
(
value
=
"/getDeviceStatusBySn"
,
consumes
=
MediaType
.
APPLICATION_FORM_URLENCODED_VALUE
)
public
R
getDeviceStatusBySn
(
@NotBlank
(
message
=
"设备号不能为空"
)
@RequestParam
(
value
=
"sn"
)
String
sn
,
Long
offlineTime
)
{
if
(
offlineTime
==
null
||
offlineTime
==
0
)
{
offlineTime
=
ConstantsDevice
.
OFFLINE_TIME_OTHER
;
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/
controller/GpsBs
Controller.java
→
src/main/java/cn/com/glsx/devicemonitor/modules/
api/GpsBsApi
Controller.java
View file @
90ce949
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
controller
;
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
api
;
import
cn.com.glsx.devicemonitor.api.dto.request.GpsBsLastBatchRequest
;
import
cn.com.glsx.devicemonitor.api.dto.response.DeviceLocationBo
;
...
...
@@ -10,12 +10,11 @@ import cn.com.glsx.devicemonitor.common.ConstantsDevice;
import
cn.com.glsx.devicemonitor.modules.service.GpsBsLocationService
;
import
cn.com.glsx.devicemonitor.modules.service.MonitorService
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.exception.SystemMessage
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.
util.StringUtils
;
import
org.springframework.
http.MediaType
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -32,9 +31,9 @@ import java.util.List;
@Slf4j
@Validated
@RestController
@RequestMapping
(
"/location"
)
@RequestMapping
(
"/
api/
location"
)
@Api
(
value
=
"gpsAndBs"
,
tags
=
"gps和基站位置服务"
)
public
class
GpsBsController
{
public
class
GpsBs
Api
Controller
{
@Autowired
private
GpsBsLocationService
gpsBsLocationService
;
...
...
@@ -47,7 +46,7 @@ public class GpsBsController {
* @param gpsBsLastBatchRequest
* @return
*/
@PostMapping
(
value
=
"/lastgpsbs/batch"
)
@PostMapping
(
value
=
"/lastgpsbs/batch"
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
R
getLastGpsBsBatch
(
@Validated
@RequestBody
GpsBsLastBatchRequest
gpsBsLastBatchRequest
)
{
if
(!
gpsBsLastBatchRequest
.
getDeviceTypeRelationEnum
().
getBizDeviceType
().
equals
(
DeviceTypeRelationEnum
.
GPS
.
getBizDeviceType
()))
{
return
R
.
error
(
BussinessExceptionEnum
.
UNSUPORT_DEVICE
.
getCode
(),
BussinessExceptionEnum
.
UNSUPORT_DEVICE
.
getMessage
());
...
...
@@ -62,7 +61,7 @@ public class GpsBsController {
* @param deviceCode
* @return
*/
@GetMapping
(
value
=
"/single"
)
@GetMapping
(
value
=
"/single"
,
consumes
=
MediaType
.
APPLICATION_FORM_URLENCODED_VALUE
)
public
R
getLastGpsBsBySn
(
@NotBlank
(
message
=
"设备号不能为空"
)
@RequestParam
(
value
=
"sn"
)
String
sn
,
@NotBlank
(
message
=
"设备编码不能为空"
)
@RequestParam
(
value
=
"deviceCode"
)
String
deviceCode
)
{
if
(!
DeviceTypeRelationEnum
.
findByDeviceCode
(
deviceCode
).
equals
(
DeviceTypeRelationEnum
.
GPS
))
{
return
R
.
error
(
BussinessExceptionEnum
.
UNSUPORT_DEVICE
.
getCode
(),
BussinessExceptionEnum
.
UNSUPORT_DEVICE
.
getMessage
());
...
...
@@ -77,7 +76,7 @@ public class GpsBsController {
* @param deviceCode
* @return
*/
@GetMapping
(
value
=
"/single/history"
)
@GetMapping
(
value
=
"/single/history"
,
consumes
=
MediaType
.
APPLICATION_FORM_URLENCODED_VALUE
)
public
R
getLastGpsBsHistoryBySn
(
@NotBlank
(
message
=
"设备号不能为空"
)
@RequestParam
(
value
=
"sn"
)
String
sn
,
@NotBlank
(
message
=
"设备编码不能为空"
)
@RequestParam
(
value
=
"deviceCode"
)
String
deviceCode
,
@NotBlank
(
message
=
"开始时间不能为空"
)
@RequestParam
(
value
=
"startTime"
)
String
startTime
,
@NotBlank
(
message
=
"结束时间不能为空"
)
@RequestParam
(
value
=
"endTime"
)
String
endTime
)
{
if
(!
DeviceTypeRelationEnum
.
GPS
.
equals
(
DeviceTypeRelationEnum
.
findByDeviceCode
(
deviceCode
)))
{
...
...
@@ -93,7 +92,7 @@ public class GpsBsController {
* @return
*/
@ApiOperation
(
value
=
"车辆监控信息"
)
@GetMapping
(
value
=
"/devicemonitorinfo"
)
@GetMapping
(
value
=
"/devicemonitorinfo"
,
consumes
=
MediaType
.
APPLICATION_FORM_URLENCODED_VALUE
)
public
R
listDeviceMonitorInfo
(
@NotBlank
(
message
=
"设备号不能为空"
)
@RequestParam
(
value
=
"sns"
)
String
sns
,
@NotBlank
(
message
=
"设备编码不能为空"
)
@RequestParam
(
value
=
"deviceCode"
)
String
deviceCode
)
{
if
(!
DeviceTypeRelationEnum
.
findByDeviceCode
(
deviceCode
).
equals
(
DeviceTypeRelationEnum
.
GPS
))
{
return
R
.
error
(
BussinessExceptionEnum
.
UNSUPORT_DEVICE
.
getCode
(),
BussinessExceptionEnum
.
UNSUPORT_DEVICE
.
getMessage
());
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/controller/MonitorController.java
View file @
90ce949
...
...
@@ -9,6 +9,7 @@ import com.glsx.plat.common.utils.DateUtils;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.office.excel.EasyExcelUtils
;
import
io.swagger.annotations.Api
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -27,6 +28,7 @@ import java.util.List;
@Slf4j
@Validated
@RestController
@Api
(
value
=
"设备监控模块"
,
tags
=
"设备监控模块"
)
@RequestMapping
(
"/monitor"
)
public
class
MonitorController
{
...
...
@@ -57,7 +59,7 @@ public class MonitorController {
* @return
*/
@PostMapping
(
value
=
"/exporttrackpoint"
)
public
void
exportTrackPoint
(
HttpServletResponse
response
,
@Validated
ExpTrackPointModel
expTrackPoint
)
{
public
void
exportTrackPoint
(
@RequestBody
@Validated
ExpTrackPointModel
expTrackPoint
)
{
if
(
StringUtils
.
isBlank
(
expTrackPoint
.
getExpData
()))
{
log
.
info
(
"导出数据为空"
);
return
;
...
...
@@ -94,7 +96,7 @@ public class MonitorController {
* @return
*/
@PostMapping
(
value
=
"/exportstaypoint"
)
public
void
exportStayPoint
(
HttpServletResponse
response
,
@Validated
ExpStayPointRequest
spRequest
)
{
public
void
exportStayPoint
(
@RequestBody
@Validated
ExpStayPointRequest
spRequest
)
{
if
(
StringUtils
.
isBlank
(
spRequest
.
getExpData
()))
{
throw
new
AdminException
(
"数据为空"
);
}
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/model/TrackInfoBo.java
0 → 100644
View file @
90ce949
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
model
;
import
lombok.Data
;
import
java.util.Date
;
@Data
public
class
TrackInfoBo
{
private
Integer
deviceType
;
private
String
sn
;
private
String
imsi
;
private
String
iccid
;
/**
* imei 设备唯一标识;
*/
private
String
imei
;
private
String
simPhone
;
private
Integer
isActive
;
private
Date
activeDate
;
private
String
checkCode
;
private
Integer
modelId
;
private
Integer
issub
;
private
Date
createTime
;
private
Integer
source
;
private
Integer
deviceId
;
/**
* 设备版本
*/
private
String
softVersion
;
private
String
partner
;
}
\ No newline at end of file
src/main/java/cn/com/glsx/devicemonitor/modules/model/report/StayPointReport.java
View file @
90ce949
...
...
@@ -12,7 +12,6 @@ import lombok.Data;
@Data
public
class
StayPointReport
{
@ExcelProperty
(
value
=
"姓名"
,
index
=
0
)
private
String
name
;
/**
...
...
@@ -30,25 +29,21 @@ public class StayPointReport {
*/
@ExcelProperty
(
value
=
"店面名称"
,
index
=
3
)
private
String
shopName
;
/**
* 停留开始时间
*/
@ExcelProperty
(
value
=
"停留开始时间"
,
index
=
4
)
private
String
begintime
;
/**
* 结束停留时间
*/
@ExcelProperty
(
value
=
"停留结束时间"
,
index
=
5
)
private
String
endtime
;
/**
* 停留时长
*/
@ExcelProperty
(
value
=
"停留时长"
,
index
=
6
)
private
String
duration
;
/**
* 定位方式 默认gps
*/
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/service/DeviceService.java
View file @
90ce949
...
...
@@ -2,6 +2,8 @@ package cn.com.glsx.devicemonitor.modules.service;
import
cn.com.glsx.devicemonitor.api.dto.response.DeviceDTO
;
import
cn.com.glsx.devicemonitor.api.dto.response.DeviceStatusModel
;
import
cn.com.glsx.devicemonitor.modules.entity.Device
;
import
cn.com.glsx.devicemonitor.modules.model.TrackInfoBo
;
/**
* @desc 提供设备相关的服务
...
...
@@ -10,11 +12,17 @@ import cn.com.glsx.devicemonitor.api.dto.response.DeviceStatusModel;
public
interface
DeviceService
{
/**
* 基本信息
* @param sn
* @return
*/
Device
getDeviceBySn
(
String
sn
);
/**
* 根据设备号查询设备信息
* @param sn
* @return
*/
DeviceDTO
getDeviceBySn
(
String
sn
);
DeviceDTO
getDevice
DTO
BySn
(
String
sn
);
/**
* 获取设备的在线状态
...
...
@@ -23,4 +31,19 @@ public interface DeviceService {
* @return
*/
DeviceStatusModel
getDeviceStatusBySn
(
String
sn
,
Long
offlineTime
);
/**
* 远程获取e盾的设备信息
* @param sn
* @return
*/
TrackInfoBo
getTrackInfoBo
(
String
sn
);
/**
* 查询设备(本地库没有,查询旧E盾)
* @param sn
* @return
*/
Device
getDeviceOrRemote
(
String
sn
)
;
}
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/DeviceServiceImpl.java
View file @
90ce949
...
...
@@ -4,6 +4,7 @@ import cn.com.glsx.alarm.services.model.DeviceLoginDto;
import
cn.com.glsx.devicemonitor.api.dto.response.*
;
import
cn.com.glsx.devicemonitor.modules.entity.Device
;
import
cn.com.glsx.devicemonitor.modules.mapper.DeviceMapper
;
import
cn.com.glsx.devicemonitor.modules.model.TrackInfoBo
;
import
cn.com.glsx.devicemonitor.modules.service.DeviceService
;
import
cn.com.glsx.devicemonitor.modules.utils.DeviceUtils
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -11,6 +12,8 @@ import org.springframework.beans.BeanUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
@Slf4j
@Service
public
class
DeviceServiceImpl
implements
DeviceService
{
...
...
@@ -21,9 +24,20 @@ public class DeviceServiceImpl implements DeviceService {
@Autowired
private
AlarmCenterApiImpl
alarmCenterApi
;
@Autowired
private
RemoteDeviceService
remoteDeviceService
;
@Override
public
DeviceDTO
getDeviceBySn
(
String
sn
)
{
Device
device
=
deviceMapper
.
selectBySn
(
sn
);
public
Device
getDeviceBySn
(
String
sn
)
{
return
deviceMapper
.
selectBySn
(
sn
);
}
@Override
public
DeviceDTO
getDeviceDTOBySn
(
String
sn
)
{
Device
device
=
getDeviceOrRemote
(
sn
);
if
(
device
==
null
)
{
return
null
;
}
DeviceDTO
deviceDTO
=
new
DeviceDTO
();
BeanUtils
.
copyProperties
(
device
,
deviceDTO
);
return
deviceDTO
;
...
...
@@ -43,6 +57,52 @@ public class DeviceServiceImpl implements DeviceService {
return
statusModel
;
}
@Override
public
TrackInfoBo
getTrackInfoBo
(
String
sn
)
{
return
remoteDeviceService
.
getDeviceBySn
(
sn
);
}
@Override
public
Device
getDeviceOrRemote
(
String
sn
)
{
Device
device
=
deviceMapper
.
selectBySn
(
sn
);
if
(
device
!=
null
)
{
return
device
;
}
TrackInfoBo
trackInfoBo
=
remoteDeviceService
.
getDeviceBySn
(
sn
);
if
(
trackInfoBo
==
null
)
{
return
null
;
}
device
=
new
Device
();
BeanUtils
.
copyProperties
(
trackInfoBo
,
device
);
return
device
;
}
/**
* 保存从E盾过来的设备
*
* @param trackInfo
* @param createId
*/
public
int
saveTrackInfoBo
(
TrackInfoBo
trackInfo
,
Long
createId
)
{
if
(
trackInfo
==
null
)
{
return
0
;
}
Device
device
=
new
Device
();
BeanUtils
.
copyProperties
(
trackInfo
,
device
);
// device.setName("");
device
.
setSim
(
trackInfo
.
getSimPhone
());
device
.
setManufacturer
(
trackInfo
.
getPartner
());
device
.
setActivateStatus
(
trackInfo
.
getIsActive
());
device
.
setActivateTime
(
trackInfo
.
getActiveDate
());
device
.
setCreatedBy
(
createId
);
device
.
setCreatedDate
(
new
Date
());
return
insertDevice
(
device
);
}
public
int
insertDevice
(
Device
device
)
{
return
deviceMapper
.
insert
(
device
);
}
}
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/MonitorServiceImpl.java
View file @
90ce949
...
...
@@ -13,10 +13,10 @@ import cn.com.glsx.devicemonitor.iceprotocol.mile.GpsLoc;
import
cn.com.glsx.devicemonitor.iceprotocol.mile.StayPointRecord
;
import
cn.com.glsx.devicemonitor.modules.components.HDaoMileComponent
;
import
cn.com.glsx.devicemonitor.modules.entity.Device
;
import
cn.com.glsx.devicemonitor.modules.mapper.DeviceMapper
;
import
cn.com.glsx.devicemonitor.modules.model.*
;
import
cn.com.glsx.devicemonitor.modules.model.report.StayPointReport
;
import
cn.com.glsx.devicemonitor.modules.model.report.TrackPointReport
;
import
cn.com.glsx.devicemonitor.modules.service.DeviceService
;
import
cn.com.glsx.devicemonitor.modules.service.GpsBsLocationService
;
import
cn.com.glsx.devicemonitor.modules.service.MonitorService
;
import
cn.com.glsx.devicemonitor.modules.utils.DeviceUtils
;
...
...
@@ -25,7 +25,6 @@ import cn.com.glsx.devicemonitor.modules.utils.LocationUtil;
import
com.alibaba.nacos.common.utils.CollectionUtils
;
import
com.glsx.plat.common.utils.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -45,7 +44,7 @@ import java.util.*;
public
class
MonitorServiceImpl
implements
MonitorService
{
@Autowired
private
Device
Mapper
deviceMapper
;
private
Device
Service
deviceService
;
@Autowired
private
GpsBsLocationService
gpsBsLocationService
;
...
...
@@ -64,9 +63,9 @@ public class MonitorServiceImpl implements MonitorService {
throw
new
AdminException
(
"所选设备数量太多"
);
}
for
(
String
sn
:
snArr
)
{
Device
device
=
device
Mapper
.
selectBySn
(
sn
);
Device
device
=
device
Service
.
getDeviceOrRemote
(
sn
);
if
(
device
==
null
)
{
log
.
info
(
sn
+
"
设备未入库"
);
log
.
info
(
sn
+
"设备未入库"
);
continue
;
}
DeviceLocationBo
deviceLocationBo
=
new
DeviceLocationBo
();
...
...
@@ -98,6 +97,7 @@ public class MonitorServiceImpl implements MonitorService {
return
retList
;
}
@Override
public
List
<
TrackResponse
>
listTrackPoint
(
TrackRequest
trackRequest
)
{
List
<
TrackResponse
>
resList
=
new
ArrayList
<>();
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/service/impl/RemoteDeviceService.java
0 → 100644
View file @
90ce949
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
service
.
impl
;
import
cn.com.glsx.devicemonitor.modules.model.TrackInfoBo
;
import
cn.com.glsx.devicemonitor.modules.utils.GopUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.common.utils.HttpUtils
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.stereotype.Service
;
import
java.util.TreeMap
;
@Slf4j
@Service
public
class
RemoteDeviceService
{
/**
* 调用e盾标准接口获取设备信息
* @param sn
*/
public
TrackInfoBo
getDeviceBySn
(
String
sn
)
{
String
url
=
PropertiesUtils
.
getProperty
(
"edun.otsi.url"
)
+
"/api/device/getInfoBySn"
;
String
appKet
=
PropertiesUtils
.
getProperty
(
"edun.otsi.appKet"
);
String
appSecret
=
PropertiesUtils
.
getProperty
(
"edun.otsi.appSecret"
);
TreeMap
<
String
,
Object
>
tparams
=
new
TreeMap
<>();
tparams
.
put
(
"appKey"
,
appKet
);
tparams
.
put
(
"sn"
,
sn
);
//加密得到sign
String
sign
=
GopUtil
.
sign
(
tparams
,
appSecret
);
tparams
.
put
(
"sign"
,
sign
);
String
result
=
HttpUtils
.
get
(
url
,
tparams
);
JSONObject
resultObj
=
JSONObject
.
parseObject
(
result
);
if
(
resultObj
==
null
)
{
log
.
info
(
"remote getInfoBysn result is null"
);
return
null
;
}
String
returnCode
=
resultObj
.
getString
(
"returnCode"
);
String
message
=
resultObj
.
getString
(
"message"
);
if
(
StringUtils
.
isBlank
(
returnCode
)
||
!
"0"
.
equals
(
returnCode
))
{
log
.
info
(
"remote getInfoBysn fail! returnCode:"
+
returnCode
+
"; message:"
+
message
);
return
null
;
}
String
data
=
resultObj
.
getString
(
"data"
);
if
(
StringUtils
.
isBlank
(
data
))
{
return
null
;
}
TrackInfoBo
trackInfoBo
=
JSONObject
.
parseObject
(
data
,
TrackInfoBo
.
class
);
return
trackInfoBo
;
}
}
src/main/java/cn/com/glsx/devicemonitor/modules/utils/Coder.java
0 → 100644
View file @
90ce949
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
utils
;
import
sun.misc.BASE64Decoder
;
import
sun.misc.BASE64Encoder
;
import
javax.crypto.KeyGenerator
;
import
javax.crypto.Mac
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.security.MessageDigest
;
public
class
Coder
{
public
static
final
String
KEY_SHA
=
"SHA"
;
public
static
final
String
KEY_MD5
=
"MD5"
;
/**
* MAC算法可选以下多种算法
*
* <pre>
* HmacMD5
* HmacSHA1
* HmacSHA256
* HmacSHA384
* HmacSHA512
* </pre>
*/
public
static
final
String
KEY_MAC
=
"HmacMD5"
;
/**
* BASE64解密
*
* @param key
* @return
* @throws Exception
*/
public
static
byte
[]
decryptBASE64
(
String
key
)
throws
Exception
{
return
(
new
BASE64Decoder
()).
decodeBuffer
(
key
);
}
/**
* BASE64加密
*
* @param key
* @return
* @throws Exception
*/
public
static
String
encryptBASE64
(
byte
[]
key
)
throws
Exception
{
return
(
new
BASE64Encoder
()).
encodeBuffer
(
key
);
}
/**
* MD5加密
*
* @param data
* @return
* @throws Exception
*/
public
static
byte
[]
encryptMD5
(
byte
[]
data
)
throws
Exception
{
MessageDigest
md5
=
MessageDigest
.
getInstance
(
KEY_MD5
);
md5
.
update
(
data
);
return
md5
.
digest
();
}
/**
* SHA加密
*
* @param data
* @return
* @throws Exception
*/
public
static
byte
[]
encryptSHA
(
byte
[]
data
)
throws
Exception
{
MessageDigest
sha
=
MessageDigest
.
getInstance
(
KEY_SHA
);
sha
.
update
(
data
);
return
sha
.
digest
();
}
/**
* 初始化HMAC密钥
*
* @return
* @throws Exception
*/
public
static
String
initMacKey
()
throws
Exception
{
KeyGenerator
keyGenerator
=
KeyGenerator
.
getInstance
(
KEY_MAC
);
SecretKey
secretKey
=
keyGenerator
.
generateKey
();
return
encryptBASE64
(
secretKey
.
getEncoded
());
}
/**
* HMAC加密
*
* @param data
* @param key
* @return
* @throws Exception
*/
public
static
byte
[]
encryptHMAC
(
byte
[]
data
,
String
key
)
throws
Exception
{
SecretKey
secretKey
=
new
SecretKeySpec
(
decryptBASE64
(
key
),
KEY_MAC
);
Mac
mac
=
Mac
.
getInstance
(
secretKey
.
getAlgorithm
());
mac
.
init
(
secretKey
);
return
mac
.
doFinal
(
data
);
}
}
src/main/java/cn/com/glsx/devicemonitor/modules/utils/GopUtil.java
0 → 100644
View file @
90ce949
/**
* 版权声明:深圳市广联赛讯有限公司 版权所有 违者必究 2012
* 日 期:12-6-2
*/
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
utils
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
/**
* <pre>
* 功能说明:
* </pre>
*
* @author 徐少敏
* @version 1.0
*/
public
class
GopUtil
{
/**
* 使用<code>secret</code>对paramValues按以下算法进行签名: <br/>
* uppercase(hex(sha1(secretkey1value1key2value2...secret))
*
* @param paramValues 参数列表
* @param secret
* @return
*/
public
static
String
sign
(
Map
<
String
,
Object
>
paramValues
,
String
secret
)
{
return
sign
(
paramValues
,
null
,
secret
);
}
/**
* 对paramValues进行签名,其中ignoreParamNames这些参数不参与签名
*
* @param paramValues
* @param ignoreParamNames
* @param secret
* @return
*/
public
static
String
sign
(
Map
<
String
,
Object
>
paramValues
,
List
<
String
>
ignoreParamNames
,
String
secret
)
{
StringBuilder
sb
=
new
StringBuilder
();
List
<
String
>
paramNames
=
new
ArrayList
<>(
paramValues
.
size
());
paramNames
.
addAll
(
paramValues
.
keySet
());
if
(
ignoreParamNames
!=
null
&&
ignoreParamNames
.
size
()
>
0
)
{
for
(
String
ignoreParamName
:
ignoreParamNames
)
{
paramNames
.
remove
(
ignoreParamName
);
}
}
Collections
.
sort
(
paramNames
);
sb
.
append
(
secret
);
for
(
String
paramName
:
paramNames
)
{
sb
.
append
(
paramName
).
append
(
paramValues
.
get
(
paramName
));
}
sb
.
append
(
secret
);
return
MD5Util
.
convert32
(
sb
.
toString
());
}
/**
* 参数md5加密
*
* @param params
* @return
*/
public
static
String
getParamsMD5Sign
(
Map
<
String
,
Object
>
params
)
{
StringBuffer
paramsStr
=
new
StringBuffer
();
for
(
Map
.
Entry
<
String
,
Object
>
param
:
params
.
entrySet
())
{
paramsStr
.
append
(
param
.
getKey
()).
append
(
param
.
getValue
());
}
return
MD5Util
.
encrypt
(
paramsStr
.
toString
()).
toUpperCase
();
}
public
static
String
utf8Encoding
(
String
value
,
String
sourceCharsetName
)
{
try
{
return
new
String
(
value
.
getBytes
(
sourceCharsetName
),
StandardCharsets
.
UTF_8
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
IllegalArgumentException
(
e
);
}
}
public
static
String
getUUID
()
{
UUID
uuid
=
UUID
.
randomUUID
();
return
uuid
.
toString
().
toUpperCase
();
}
public
static
void
main
(
String
[]
args
)
{
String
uuid
=
getUUID
();
System
.
out
.
println
(
uuid
.
replaceAll
(
"-"
,
""
));
}
}
src/main/java/cn/com/glsx/devicemonitor/modules/utils/MD5Util.java
0 → 100644
View file @
90ce949
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
utils
;
import
java.io.UnsupportedEncodingException
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Map
;
public
class
MD5Util
{
private
static
final
String
hexDigits
[]
=
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
};
private
static
String
byteArrayToHexString
(
byte
b
[])
{
StringBuffer
resultSb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
b
.
length
;
i
++)
{
resultSb
.
append
(
byteToHexString
(
b
[
i
]));
}
return
resultSb
.
toString
();
}
private
static
String
byteToHexString
(
byte
b
)
{
int
n
=
b
;
if
(
n
<
0
)
n
+=
256
;
int
d1
=
n
/
16
;
int
d2
=
n
%
16
;
return
hexDigits
[
d1
]
+
hexDigits
[
d2
];
}
public
static
String
encode
(
String
origin
)
{
return
encode
(
origin
,
"UTF-8"
);
}
public
static
String
encode
(
String
origin
,
String
charsetname
)
{
String
resultString
=
null
;
try
{
resultString
=
new
String
(
origin
);
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
if
(
charsetname
==
null
||
""
.
equals
(
charsetname
))
resultString
=
byteArrayToHexString
(
md
.
digest
(
resultString
.
getBytes
()));
else
resultString
=
byteArrayToHexString
(
md
.
digest
(
resultString
.
getBytes
(
charsetname
)));
}
catch
(
Exception
exception
)
{
}
return
resultString
;
}
/**
* md5加密方法
* @param str
* @return
*/
public
static
String
encrypt
(
String
str
)
{
try
{
byte
b
[]
=
Coder
.
encryptMD5
(
str
.
getBytes
(
"utf-8"
));
StringBuffer
buf
=
new
StringBuffer
();
String
stmp
=
""
;
for
(
int
n
=
0
;
n
<
b
.
length
;
n
++)
{
stmp
=
Integer
.
toHexString
(
b
[
n
]
&
0XFF
);
if
(
stmp
.
length
()
==
1
)
buf
.
append
(
"0"
).
append
(
stmp
);
else
buf
.
append
(
stmp
);
}
return
buf
.
toString
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
""
;
}
public
static
String
MD516
(
String
sourceStr
)
{
String
result
=
""
;
try
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
try
{
md
.
update
(
sourceStr
.
getBytes
(
"GBK"
));
}
catch
(
UnsupportedEncodingException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
byte
b
[]
=
md
.
digest
();
int
i
;
StringBuffer
buf
=
new
StringBuffer
(
""
);
for
(
int
offset
=
0
;
offset
<
b
.
length
;
offset
++)
{
i
=
b
[
offset
];
if
(
i
<
0
)
i
+=
256
;
if
(
i
<
16
)
buf
.
append
(
"0"
);
buf
.
append
(
Integer
.
toHexString
(
i
));
}
result
=
buf
.
toString
();
result
=
result
.
toString
().
substring
(
8
,
24
);
}
catch
(
NoSuchAlgorithmException
e
)
{
System
.
out
.
println
(
e
);
}
return
result
;
}
/**
* 获取MD5加密的sign
*
* @param params
* @return
*/
public
static
String
getParamsMD5Sign
(
Map
<
Object
,
Object
>
params
)
{
StringBuffer
paramsStr
=
new
StringBuffer
();
for
(
Map
.
Entry
<
Object
,
Object
>
param
:
params
.
entrySet
())
{
paramsStr
.
append
(
param
.
getKey
()).
append
(
param
.
getValue
());
}
return
MD5Util
.
encrypt
(
paramsStr
.
toString
()).
toUpperCase
();
}
/**
* 32位MD5加密算法
* @param s
* @return
*/
public
static
String
convert32
(
String
s
){
char
hexChars
[]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
try
{
byte
[]
bytes
=
s
.
getBytes
(
"UTF-8"
);
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
md
.
update
(
bytes
);
bytes
=
md
.
digest
();
int
j
=
bytes
.
length
;
char
[]
chars
=
new
char
[
j
*
2
];
int
k
=
0
;
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
byte
b
=
bytes
[
i
];
chars
[
k
++]
=
hexChars
[
b
>>>
4
&
0xf
];
chars
[
k
++]
=
hexChars
[
b
&
0xf
];
}
return
new
String
(
chars
);
}
catch
(
Exception
e
){
return
null
;
}
}
/**
* 16位MD5加密算法
* @param s
* @return
*/
public
static
String
convert16
(
String
s
){
char
hexChars
[]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
try
{
byte
[]
bytes
=
s
.
getBytes
();
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
md
.
update
(
bytes
);
bytes
=
md
.
digest
();
int
j
=
bytes
.
length
;
char
[]
chars
=
new
char
[
j
*
2
];
int
k
=
0
;
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
byte
b
=
bytes
[
i
];
chars
[
k
++]
=
hexChars
[
b
>>>
4
&
0xf
];
chars
[
k
++]
=
hexChars
[
b
&
0xf
];
}
return
new
String
(
chars
).
substring
(
8
,
24
);
}
catch
(
Exception
e
){
return
null
;
}
}
}
src/main/resources/bootstrap.properties
View file @
90ce949
...
...
@@ -3,7 +3,7 @@ spring.application.name=ne-shield-devicemonitor
##\u5F00\u53D1\u4E2D\u9700\u8981\u8BFB\u53D6\u7684\u914D\u7F6E\u6587\u4EF6
profile.active
=
dev
server.servlet.context-
path
=
/
ne-shield-
devicemonitor
server.servlet.context-
path
=
/devicemonitor
#\u6307\u5B9Adate\u8F93\u51FA\u683C\u5F0F\u4E3Ayyyy-MM-dd HH:mm:ss
spring.jackson.date-
format
=
yyyy-MM-dd HH:mm:ss
...
...
@@ -21,6 +21,7 @@ logging.path=/data/java_log/jetty/${spring.application.name}/${spring.applicatio
#nacos配置中心
spring.cloud.nacos.config.server-
addr
=
192.168.3.206:8848
#spring.cloud.nacos.config.server-addr=192.168.0.63:8848
#nacos配置id,完整dataId=${spring.cloud.nacos.config.prefix}-${spring.profiles.active}.${file-extension(由新增配置时选的文件类型决定)}
#示例:http://192.168.0.63:8848/nacos/v1/cs/configs?dataId=glsx-rest-admin.properties&group=DEV_GROUP
...
...
@@ -33,6 +34,8 @@ spring.profiles.active=${profile.active}
spring.cloud.nacos.config.file-
extension
=
properties
spring.main.allow-bean-definition-
overriding
=
true
#微服务sentinel、zipkin、actuator等公共配置
spring.cloud.nacos.config.shared-configs[0].data-
id
=
glsx-rest-microservice-share.properties
spring.cloud.nacos.config.shared-configs[0]
.group
=
DEV_GROUP
...
...
@@ -41,4 +44,6 @@ spring.cloud.nacos.config.shared-configs[0].refresh=true
#数据库、redis等公共配置
spring.cloud.nacos.config.shared-configs[1]
.group
=
NESHIELD_DEV_GROUP
spring.cloud.nacos.config.shared-configs[1].data-
id
=
glsx-ne-shield-share-dev.properties
spring.cloud.nacos.config.shared-configs[1]
.refresh
=
true
\ No newline at end of file
spring.cloud.nacos.config.shared-configs[1]
.refresh
=
true
swagger2.basePackage
=
cn.com.glsx.devicemonitor.modules
\ No newline at end of file
src/test/java/cn/com/glsx/test/gpsbs/MonitorTest.java
View file @
90ce949
...
...
@@ -12,7 +12,7 @@ import java.util.Map;
* @create: 2021-08-24 15
**/
public
class
MonitorTest
{
private
static
String
localUrl
=
"http://localhost:8
080/ne-shield-
devicemonitor"
;
private
static
String
localUrl
=
"http://localhost:8
300/
devicemonitor"
;
private
static
String
serverUrl
=
localUrl
;
...
...
@@ -34,7 +34,7 @@ public class MonitorTest {
public
static
void
getdevicemonitorinfoTest
()
{
String
url
=
serverUrl
+
"/monitor/
get
devicemonitorinfo"
;
String
url
=
serverUrl
+
"/monitor/devicemonitorinfo"
;
String
sn
=
"75108160001,1610816002"
;
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"sns"
,
sn
);
...
...
@@ -45,7 +45,7 @@ public class MonitorTest {
public
static
void
liststaypointTest
()
{
String
url
=
serverUrl
+
"/
monitor
/liststaypoint"
;
String
url
=
serverUrl
+
"/
location
/liststaypoint"
;
String
sn
=
"1610816002"
;
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"sn"
,
sn
);
...
...
src/test/java/cn/com/glsx/test/gpsbs/TestDeviceController.java
View file @
90ce949
...
...
@@ -7,12 +7,12 @@ import java.util.Map;
public
class
TestDeviceController
{
private
static
String
localUrl
=
"http://localhost:8
08
0/ne-shield-devicemonitor"
;
private
static
String
localUrl
=
"http://localhost:8
30
0/ne-shield-devicemonitor"
;
private
static
String
serverUrl
=
localUrl
;
public
static
void
main
(
String
[]
args
)
{
getDeviceStatusBySnTest
();
}
public
static
void
testGetDeviceBySn
()
{
...
...
@@ -24,15 +24,6 @@ public class TestDeviceController {
System
.
out
.
println
(
res
);
}
public
static
void
testGetDeviceMonitorInfo
()
{
String
url
=
serverUrl
+
"/device/getDeviceMonitorInfo"
;
String
sn
=
"8130912152"
;
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"sn"
,
sn
);
paramMap
.
put
(
"deviceCode"
,
"gps"
);
String
res
=
HttpUtil
.
get
(
url
,
paramMap
,
20000
);
System
.
out
.
println
(
res
);
}
public
static
void
getDeviceStatusBySnTest
()
{
String
url
=
serverUrl
+
"/device/getDeviceStatusBySn"
;
...
...
src/test/java/cn/com/glsx/test/gpsbs/TestGpsBsController.java
View file @
90ce949
...
...
@@ -20,18 +20,14 @@ import java.util.Map;
*/
public
class
TestGpsBsController
{
private
static
String
localUrl
=
"http://localhost:8
08
0"
;
private
static
String
localUrl
=
"http://localhost:8
30
0"
;
private
static
String
devUrl
=
"http://192.168.3.181:8300"
;
private
static
String
testUrl
=
"http://192.168.3.220:9047"
;
private
static
String
serverUrl
=
testUrl
;
public
static
void
main
(
String
[]
args
)
{
batchGpsBs
();
singleSn
();
historySn
();
devicemonitorinfoTest
();
}
private
static
void
batchGpsBs
()
{
...
...
@@ -74,4 +70,17 @@ public class TestGpsBsController {
System
.
out
.
println
(
res
);
}
public
static
void
devicemonitorinfoTest
()
{
String
url
=
localUrl
+
"/devicemonitor/location/devicemonitorinfo"
;
String
sns
=
"75108160001,1610816002"
;
String
deviceCode
=
DeviceTypeRelationEnum
.
GPS
.
getDeviceCode
();
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"sns"
,
sns
);
paramMap
.
put
(
"deviceCode"
,
deviceCode
);
String
res
=
HttpUtil
.
get
(
url
,
paramMap
,
20000
);
System
.
out
.
println
(
res
);
}
}
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