Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-trialdrive-admin
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 cb9ac34e
authored
Aug 31, 2021
by
黄小葱
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
删除不必要的代码
1 parent
3097c088
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
423 deletions
src/main/java/cn/com/glsx/admin/modules/controller/VehicleMonitorController.java
src/main/java/cn/com/glsx/admin/modules/model/export/TrackModelExport.java
src/main/java/cn/com/glsx/admin/modules/service/VehicleMonitorSevice.java
src/main/java/cn/com/glsx/admin/modules/controller/VehicleMonitorController.java
View file @
cb9ac34
package
cn
.
com
.
glsx
.
admin
.
modules
.
controller
;
package
cn
.
com
.
glsx
.
admin
.
modules
.
controller
;
import
cn.com.glsx.admin.modules.model.OrgVehicleTree
;
import
cn.com.glsx.admin.modules.model.OrgVehicleTree
;
import
cn.com.glsx.admin.modules.model.ValidateGroups
;
import
cn.com.glsx.admin.modules.model.export.TrackModelExport
;
import
cn.com.glsx.admin.modules.model.param.MonitorQueryBo
;
import
cn.com.glsx.admin.modules.model.param.VehicleTreeSearch
;
import
cn.com.glsx.admin.modules.model.param.VehicleTreeSearch
;
import
cn.com.glsx.admin.modules.service.VehicleMonitorSevice
;
import
cn.com.glsx.admin.modules.service.VehicleMonitorSevice
;
import
cn.com.glsx.usercenter.api.dto.tree.OrgTreeModel
;
import
cn.com.glsx.usercenter.api.dto.tree.OrgTreeModel
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.office.excel.EasyExcelUtils
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
...
@@ -83,25 +78,10 @@ public class VehicleMonitorController {
...
@@ -83,25 +78,10 @@ public class VehicleMonitorController {
@ApiOperation
(
value
=
"查询车辆位置信息接口"
)
@ApiOperation
(
value
=
"查询车辆位置信息接口"
)
@GetMapping
(
"/vehiclelocation"
)
@GetMapping
(
"/vehiclelocation"
)
public
R
vehicleLocationInfo
(
String
sn
)
{
public
R
vehicleLocationInfo
(
String
sn
,
String
deviceCode
)
{
vehicleMonitorSevice
.
getVehicleLocation
(
sn
);
vehicleMonitorSevice
.
getVehicleLocation
(
sn
,
deviceCode
);
return
null
;
return
null
;
}
}
@ApiOperation
(
value
=
"轨迹回放"
)
@GetMapping
(
"/gettrackhistory"
)
public
R
getTrackHistory
(
@Validated
(
ValidateGroups
.
Insert
.
class
)
MonitorQueryBo
monitorQueryVo
)
{
List
<
TrackModelExport
>
trackHistoryList
=
vehicleMonitorSevice
.
getTrackHistory
(
monitorQueryVo
);
return
R
.
ok
().
data
(
trackHistoryList
);
}
@ApiOperation
(
value
=
"车辆轨迹导出"
)
@GetMapping
(
"/exportcsv"
)
public
void
exportCsv
(
@Validated
(
ValidateGroups
.
Insert
.
class
)
MonitorQueryBo
monitorQueryVo
)
throws
Exception
{
List
<
TrackModelExport
>
trackModelList
=
vehicleMonitorSevice
.
exportCsv
(
monitorQueryVo
);
// 调用公用方法导出 excel表格
EasyExcelUtils
.
writeExcel
(
response
,
trackModelList
,
"车辆轨迹表"
,
"有效试驾次数统计(按日)表"
,
TrackModelExport
.
class
);
}
}
}
src/main/java/cn/com/glsx/admin/modules/model/export/TrackModelExport.java
deleted
100644 → 0
View file @
3097c08
package
cn
.
com
.
glsx
.
admin
.
modules
.
model
.
export
;
import
com.alibaba.excel.annotation.ExcelIgnoreUnannotated
;
import
lombok.Data
;
import
javax.persistence.Column
;
/**
* 项目名:ne-shield-trialdrive-admin
* 包名: cn.com.glsx.admin.modules.model
* 作者: Yanglinlong
* 日期: 2021/5/21 16:05
*/
@Data
@ExcelIgnoreUnannotated
public
class
TrackModelExport
{
/**
* 用户Id
*/
private
int
userId
;
/**
* 经纬度时间
*/
@Column
(
name
=
"经纬度时间"
)
private
String
dateTime
;
/**
* 原始 经度
*/
@Column
(
name
=
"原始经度"
)
private
String
lat
;
/**
* 原始 纬度
*/
@Column
(
name
=
"原始纬度"
)
private
String
lng
;
/**
* 速度
*/
@Column
(
name
=
"速度"
)
private
String
speed
;
/**
* Google 纬度
*/
@Column
(
name
=
"Google纬度"
)
private
String
elat
;
/**
* Google 经度
*/
@Column
(
name
=
"Google经度"
)
private
String
elng
;
/**
* 车名
*/
@Column
(
name
=
"车名"
)
private
String
carName
;
/**
* 用户联系方式
*/
@Column
(
name
=
"用户联系方式"
)
private
String
userTel
;
/**
* 车牌号
*/
@Column
(
name
=
"车牌号"
)
private
String
carNum
;
/**
* 车架号
*/
@Column
(
name
=
"车架号"
)
private
String
standNo
;
/**
* 设备号
*/
@Column
(
name
=
"设备号"
)
private
String
sn
;
/**
* Baidu 经度
*/
@Column
(
name
=
"Baidu经度"
)
private
String
blat
;
/**
* Baidu 纬度
*/
@Column
(
name
=
"Baidu纬度"
)
private
String
blng
;
/**
* 海拔
*/
@Column
(
name
=
"海拔"
)
private
String
alt
;
/**
* 方向
*/
@Column
(
name
=
"方向"
)
private
String
dir
;
/**
* 存储时间
*/
@Column
(
name
=
"存储时间"
)
private
String
storeTime
;
/**
* 地址信息
*/
@Column
(
name
=
"地址信息"
)
private
String
address
;
}
src/main/java/cn/com/glsx/admin/modules/service/VehicleMonitorSevice.java
View file @
cb9ac34
package
cn
.
com
.
glsx
.
admin
.
modules
.
service
;
package
cn
.
com
.
glsx
.
admin
.
modules
.
service
;
import
cn.com.glsx.admin.common.constants.Constants
;
import
cn.com.glsx.admin.common.constants.ConstantsDevice
;
import
cn.com.glsx.admin.common.enums.ResultEnum
;
import
cn.com.glsx.admin.common.exception.AdminException
;
import
cn.com.glsx.admin.modules.entity.Device
;
import
cn.com.glsx.admin.modules.entity.Vehicle
;
import
cn.com.glsx.admin.modules.entity.VehicleDevice
;
import
cn.com.glsx.admin.modules.mapper.DeviceMapper
;
import
cn.com.glsx.admin.modules.mapper.VehicleDeviceMapper
;
import
cn.com.glsx.admin.modules.mapper.VehicleMapper
;
import
cn.com.glsx.admin.modules.mapper.VehicleMapper
;
import
cn.com.glsx.admin.modules.model.OrgVehicleModel
;
import
cn.com.glsx.admin.modules.model.OrgVehicleModel
;
import
cn.com.glsx.admin.modules.model.OrgVehicleTree
;
import
cn.com.glsx.admin.modules.model.OrgVehicleTree
;
import
cn.com.glsx.admin.modules.model.export.TrackModelExport
;
import
cn.com.glsx.admin.modules.model.param.DeviceLocation
;
import
cn.com.glsx.admin.modules.model.param.DeviceLocationBo
;
import
cn.com.glsx.admin.modules.model.param.DeviceLocationBo
;
import
cn.com.glsx.admin.modules.model.param.MonitorQueryBo
;
import
cn.com.glsx.admin.modules.model.param.VehicleTreeSearch
;
import
cn.com.glsx.admin.modules.model.param.VehicleTreeSearch
;
import
cn.com.glsx.admin.modules.utils.DateUtil
;
import
cn.com.glsx.alarm.api.AlarmFeignClient
;
import
cn.com.glsx.alarm.services.model.AlarmBo
;
import
cn.com.glsx.alarm.services.model.AlarmDto
;
import
cn.com.glsx.devicemonitor.api.dto.response.GpsBsData
;
import
cn.com.glsx.devicemonitor.api.dto.response.GpsLocation
;
import
cn.com.glsx.usercenter.api.dto.tree.OrgTreeModel
;
import
cn.com.glsx.usercenter.api.dto.tree.OrgTreeModel
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.glsx.plat.common.model.TreeModel
;
import
com.glsx.plat.common.model.TreeModel
;
import
com.glsx.plat.common.utils.TreeModelUtil
;
import
com.glsx.plat.common.utils.TreeModelUtil
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.core.web.R
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -52,22 +31,10 @@ import static java.util.stream.Collectors.groupingBy;
...
@@ -52,22 +31,10 @@ import static java.util.stream.Collectors.groupingBy;
@Service
@Service
public
class
VehicleMonitorSevice
{
public
class
VehicleMonitorSevice
{
// @Autowired
// private GpsBsService gpsBsService;
@Autowired
private
VehicleDeviceMapper
vehicleDeviceMapper
;
@Autowired
@Autowired
private
VehicleMapper
vehicleMapper
;
private
VehicleMapper
vehicleMapper
;
@Autowired
@Autowired
private
DeviceMapper
deviceMapper
;
@Autowired
private
AlarmFeignClient
alarmFeignClient
;
@Autowired
private
OrganizationApiService
organizationApiService
;
private
OrganizationApiService
organizationApiService
;
/**
/**
...
@@ -205,278 +172,41 @@ public class VehicleMonitorSevice {
...
@@ -205,278 +172,41 @@ public class VehicleMonitorSevice {
return
vehicleList
;
return
vehicleList
;
}
}
public
List
<
TrackModelExport
>
getTrackHistory
(
MonitorQueryBo
monitorQueryVo
)
{
log
.
info
(
"调用ICE接口查询历史轨迹数据"
);
List
<
TrackModelExport
>
trackModelList
=
new
ArrayList
<>();
VehicleDevice
vehicleDevice
=
vehicleDeviceMapper
.
getVehicleDeviceBySn
(
monitorQueryVo
.
getSn
());
if
(
vehicleDevice
==
null
)
{
// 没有查询到历史轨迹数据
throw
new
AdminException
(
ResultEnum
.
TRACKHISTORY_HAS_NO_DATA
);
}
Vehicle
vehicle
=
vehicleMapper
.
selectById
(
vehicleDevice
.
getVehicleId
());
R
gpsHistory
=
new
R
();
// R gpsHistory = gpsBsService.getLastGpsBsHistoryBySn(monitorQueryVo.getSn(), DeviceTypeRelationEnum.GPS.getDeviceCode(), monitorQueryVo.getStartTime(), monitorQueryVo.getEndTime());
if
(
gpsHistory
.
getData
()
==
null
)
{
// 没有查询到历史轨迹数据
throw
new
AdminException
(
ResultEnum
.
TRACKHISTORY_HAS_NO_DATA
);
}
List
<
GpsLocation
>
gpsHistoryData
=
JSON
.
parseArray
(
JSON
.
toJSONString
(
gpsHistory
.
getData
()),
GpsLocation
.
class
);
if
(
CollectionUtils
.
isNotEmpty
(
gpsHistoryData
))
{
String
maxSize
=
PropertiesUtils
.
getProperty
(
"repaly.size"
);
log
.
info
(
monitorQueryVo
.
getSn
()
+
"#获取gps的数据大小为#"
+
gpsHistoryData
.
size
());
if
(
gpsHistoryData
.
size
()
>
Integer
.
parseInt
(
maxSize
))
{
// 获取gps的数据条数已经超过最大限制
throw
new
AdminException
(
ResultEnum
.
TRACKHISTORY_HAS_EXCEED_LIMIT
);
}
for
(
GpsLocation
gps
:
gpsHistoryData
)
{
TrackModelExport
trackModelDTO
=
new
TrackModelExport
();
trackModelDTO
.
setLng
(
gps
.
getLng
());
trackModelDTO
.
setLat
(
gps
.
getLat
());
trackModelDTO
.
setElng
(
gps
.
getElng
());
trackModelDTO
.
setElat
(
gps
.
getElat
());
trackModelDTO
.
setBlng
(
gps
.
getBlng
());
trackModelDTO
.
setBlat
(
gps
.
getBlat
());
trackModelDTO
.
setDateTime
(
gps
.
getDateTime
());
trackModelDTO
.
setAddress
(
gps
.
getAddress
());
trackModelDTO
.
setAlt
(
gps
.
getAlt
());
trackModelDTO
.
setDir
(
gps
.
getDir
());
trackModelDTO
.
setStoreTime
(
gps
.
getStoreTime
());
trackModelDTO
.
setSpeed
(
gps
.
getSpeed
());
trackModelDTO
.
setCarName
(
vehicle
.
getOwnerName
());
trackModelDTO
.
setUserTel
(
vehicle
.
getOwnerTel
());
trackModelDTO
.
setStandNo
(
vehicle
.
getVin
());
trackModelDTO
.
setStoreTime
(
DateUtil
.
formatDate
(
vehicle
.
getBuyDate
()));
trackModelDTO
.
setSn
(
monitorQueryVo
.
getSn
());
trackModelList
.
add
(
trackModelDTO
);
}
}
return
trackModelList
;
}
public
List
<
TrackModelExport
>
exportCsv
(
MonitorQueryBo
monitorQueryVo
)
{
log
.
info
(
"调用ICE接口导出历史轨迹数据"
);
List
<
TrackModelExport
>
trackModelList
=
new
ArrayList
<>();
VehicleDevice
vehicleDevice
=
vehicleDeviceMapper
.
getVehicleDeviceBySn
(
monitorQueryVo
.
getSn
());
Vehicle
vehicle
=
vehicleMapper
.
selectById
(
vehicleDevice
.
getVehicleId
());
R
gpsHistory
=
new
R
();
// R gpsHistory = gpsBsService.getLastGpsBsHistoryBySn(monitorQueryVo.getSn(), DeviceTypeRelationEnum.GPS.getDeviceCode(), monitorQueryVo.getStartTime(), monitorQueryVo.getEndTime());
List
<
GpsLocation
>
gpsHistoryData
=
JSON
.
parseArray
(
JSON
.
toJSONString
(
gpsHistory
.
getData
()),
GpsLocation
.
class
);
if
(
CollectionUtils
.
isNotEmpty
(
gpsHistoryData
))
{
log
.
info
(
monitorQueryVo
.
getSn
()
+
"#获取gps的数据大小为#"
+
gpsHistoryData
.
size
());
for
(
GpsLocation
gps
:
gpsHistoryData
)
{
TrackModelExport
trackModelDTO
=
new
TrackModelExport
();
trackModelDTO
.
setLng
(
gps
.
getLng
());
trackModelDTO
.
setLat
(
gps
.
getLat
());
trackModelDTO
.
setElng
(
gps
.
getElng
());
trackModelDTO
.
setElat
(
gps
.
getElat
());
trackModelDTO
.
setBlng
(
gps
.
getBlng
());
trackModelDTO
.
setBlat
(
gps
.
getBlat
());
trackModelDTO
.
setDateTime
(
gps
.
getDateTime
());
trackModelDTO
.
setAddress
(
gps
.
getAddress
());
trackModelDTO
.
setAlt
(
gps
.
getAlt
());
trackModelDTO
.
setDir
(
gps
.
getDir
());
trackModelDTO
.
setStoreTime
(
gps
.
getStoreTime
());
trackModelDTO
.
setSpeed
(
gps
.
getSpeed
());
trackModelDTO
.
setCarName
(
vehicle
.
getOwnerName
());
trackModelDTO
.
setUserTel
(
vehicle
.
getOwnerTel
());
trackModelDTO
.
setStandNo
(
vehicle
.
getVin
());
trackModelDTO
.
setStoreTime
(
DateUtil
.
formatDate
(
vehicle
.
getBuyDate
()));
trackModelDTO
.
setSn
(
monitorQueryVo
.
getSn
());
trackModelList
.
add
(
trackModelDTO
);
}
}
return
trackModelList
;
}
/**
/**
* 获取车辆的位置信息
* 获取车辆的位置信息
*
*
* @param sn
* @param sn
*/
*/
public
DeviceLocationBo
getVehicleLocation
(
String
sn
)
{
public
DeviceLocationBo
getVehicleLocation
(
String
sn
,
String
deviceCode
)
{
DeviceLocationBo
retLocation
=
new
DeviceLocationBo
();
DeviceLocationBo
retLocation
=
new
DeviceLocationBo
();
R
gpsBsDataR
=
new
R
();
R
gpsBsDataR
=
new
R
();
// R gpsBsDataR = gpsBsService.getLastGpsBsBySn(sn, DeviceTypeRelationEnum.GPS.getDeviceCode());
// R gpsBsDataR = gpsBsService.getLastGpsBsBySn(sn, DeviceTypeRelationEnum.GPS.getDeviceCode());
if
(!
gpsBsDataR
.
isSuccess
())
{
// if (!gpsBsDataR.isSuccess()) {
log
.
info
(
"获取最后gps和基站数据失败"
);
// log.info("获取最后gps和基站数据失败");
// return retLocation;
// }
// if (gpsBsDataR.getData() == null) {
// log.info("获取最后gps和基站数据为空。");
// return retLocation;
// }
// GpsBsData gpsBsData = (GpsBsData) gpsBsDataR.getData();
// GpsLocation bsLocation = gpsBsData.getBsLocation();
// GpsLocation gpsLocation = gpsBsData.getGpsLocation();
// DeviceLocation gpsLoca = parseLocationInfo(gpsLocation, ConstantsDevice.DEVICE_LOCATION_GPS);
// DeviceLocation bsLoca = parseLocationInfo(bsLocation, ConstantsDevice.DEVICE_LOCATION_BS);
//
// retLocation.setSn(sn);
// retLocation.setGpsLocation(gpsLoca);
// retLocation.setBsLocation(bsLoca);
// //解析状态
// parseDeviceStatus(gpsLocation, bsLocation, retLocation);
// //构建基础信息
// buildBaseInfo(retLocation, sn);
// //构建报警数据
// buildAlarmData(retLocation, sn);
// log.info("monitor track sn:" + sn + "status:" + retLocation.getStatus());
return
retLocation
;
return
retLocation
;
}
}
if
(
gpsBsDataR
.
getData
()
==
null
)
{
log
.
info
(
"获取最后gps和基站数据为空。"
);
return
retLocation
;
}
GpsBsData
gpsBsData
=
(
GpsBsData
)
gpsBsDataR
.
getData
();
GpsLocation
bsLocation
=
gpsBsData
.
getBsLocation
();
GpsLocation
gpsLocation
=
gpsBsData
.
getGpsLocation
();
DeviceLocation
gpsLoca
=
parseLocationInfo
(
gpsLocation
,
ConstantsDevice
.
DEVICE_LOCATION_GPS
);
DeviceLocation
bsLoca
=
parseLocationInfo
(
bsLocation
,
ConstantsDevice
.
DEVICE_LOCATION_BS
);
retLocation
.
setSn
(
sn
);
retLocation
.
setGpsLocation
(
gpsLoca
);
retLocation
.
setBsLocation
(
bsLoca
);
//解析状态
parseDeviceStatus
(
gpsLocation
,
bsLocation
,
retLocation
);
//构建基础信息
buildBaseInfo
(
retLocation
,
sn
);
//构建报警数据
buildAlarmData
(
retLocation
,
sn
);
log
.
info
(
"monitor track sn:"
+
sn
+
"status:"
+
retLocation
.
getStatus
());
return
retLocation
;
}
/**
* 查找最外层的基础信息
*
* @param retLocation
*/
private
void
buildBaseInfo
(
DeviceLocationBo
retLocation
,
String
sn
)
{
//车辆信息
Vehicle
vehicle
=
vehicleMapper
.
findVehicleInfoBySn
(
sn
);
if
(
vehicle
!=
null
)
{
retLocation
.
setVin
(
vehicle
.
getVin
());
retLocation
.
setOwnerName
(
vehicle
.
getOwnerName
());
}
//设备信息
Device
device
=
deviceMapper
.
selectBySn
(
sn
);
retLocation
.
setSource
(
device
.
getSource
());
}
/**
* 构建断电报警信息
*
* @param location
* @param sn
*/
private
void
buildAlarmData
(
DeviceLocationBo
location
,
String
sn
)
{
AlarmBo
alarmBo
=
new
AlarmBo
();
alarmBo
.
setSnList
(
sn
);
//查询拆除报警(断电和光感)
R
<
AlarmDto
>
searchR
=
alarmFeignClient
.
search
(
alarmBo
);
if
(
searchR
==
null
||
!
searchR
.
isSuccess
())
{
log
.
info
(
"查找到拆除报警失败,sn:"
+
sn
);
return
;
}
List
<
AlarmDto
>
alarmDataList
=
JSON
.
parseArray
(
JSONArray
.
toJSONString
(
searchR
.
getData
()),
AlarmDto
.
class
);
if
(
CollectionUtils
.
isEmpty
(
alarmDataList
))
{
log
.
info
(
"未查找到拆除报警,sn:"
+
sn
);
return
;
}
Set
<
Integer
>
alarmSet
=
new
HashSet
<>();
for
(
AlarmDto
alarmDto
:
alarmDataList
)
{
alarmSet
.
add
(
alarmDto
.
getAlarmType
());
}
location
.
setAlarmTypeSet
(
alarmSet
);
}
/**
* 设置基站或gps的信息
*
* @param location
* @param locatType
* @return
*/
private
DeviceLocation
parseLocationInfo
(
GpsLocation
location
,
int
locatType
)
{
DeviceLocation
deviceLocation
=
new
DeviceLocation
();
if
(
location
==
null
)
{
return
deviceLocation
;
}
deviceLocation
.
setLat
(
location
.
getLat
());
deviceLocation
.
setLng
(
location
.
getLng
());
deviceLocation
.
setLocatType
(
locatType
);
deviceLocation
.
setTime
(
location
.
getDateTime
());
return
deviceLocation
;
}
/**
* 解析设备的状态
*
* @param gpsLocation
* @param bsLocation
* @param location
*/
private
void
parseDeviceStatus
(
GpsLocation
gpsLocation
,
GpsLocation
bsLocation
,
DeviceLocationBo
location
)
{
if
(
gpsLocation
==
null
&&
bsLocation
==
null
)
{
location
.
setStatus
(
ConstantsDevice
.
DEVICE_STATUS_OFFLINE
);
return
;
}
long
gpsDateLong
=
0
;
long
bsDateLong
=
0
;
String
speedStr
=
""
;
if
(
gpsLocation
!=
null
)
{
speedStr
=
gpsLocation
.
getSpeed
();
String
gpsDateTime
=
gpsLocation
.
getDateTime
();
Date
gpsDate
=
DateUtil
.
parseDate
(
gpsDateTime
);
gpsDateLong
=
gpsDate
!=
null
?
gpsDate
.
getTime
()
:
0
;
}
if
(
bsLocation
!=
null
)
{
String
bsDateTime
=
bsLocation
.
getDateTime
();
Date
bsDate
=
DateUtil
.
parseDate
(
bsDateTime
);
bsDateLong
=
bsDate
!=
null
?
bsDate
.
getTime
()
:
0
;
}
if
(
gpsDateLong
==
0
&&
bsDateLong
==
0
)
{
location
.
setStatus
(
ConstantsDevice
.
DEVICE_STATUS_OFFLINE
);
return
;
}
long
trackTime
=
Math
.
max
(
gpsDateLong
,
bsDateLong
);
long
now
=
System
.
currentTimeMillis
();
if
(
trackTime
>
now
)
{
trackTime
=
now
;
}
Integer
speed
=
0
;
try
{
speed
=
Integer
.
parseInt
(
speedStr
);
}
catch
(
NumberFormatException
num
)
{
log
.
info
(
"解析设备的速度异常,sn:"
+
location
.
getSn
()
+
";speed:"
+
speedStr
);
}
parseStatus
(
location
,
speed
,
trackTime
);
}
/**
* @param location
* @param speed
* @param trackTime
*/
private
void
parseStatus
(
DeviceLocationBo
location
,
Integer
speed
,
long
trackTime
)
{
long
now
=
System
.
currentTimeMillis
();
long
offlineTime
=
Constants
.
OFFLINE_TIME_OTHER
*
1000
;
if
(
now
-
trackTime
>
offlineTime
)
{
location
.
setStatus
(
ConstantsDevice
.
DEVICE_STATUS_OFFLINE
);
location
.
setStatusTime
(
DateUtil
.
formatTimeInSec
((
now
-
trackTime
)
/
1000
));
return
;
}
//无源设备 在线
if
(
location
.
getSource
()
==
ConstantsDevice
.
SOURCE_NO
)
{
location
.
setStatus
(
ConstantsDevice
.
DEVICE_STATUS_ONLINE
);
location
.
setStatusTime
(
DateUtil
.
formatTimeInSec
((
now
-
trackTime
)
/
1000
));
return
;
}
//有源设备 有速度 判断是否行驶
parseSourceStatus
(
location
,
speed
,
trackTime
);
}
/**
* 解析有源设备的状态
*
* @param location
* @param speed
* @param trackTime
*/
public
void
parseSourceStatus
(
DeviceLocationBo
location
,
Integer
speed
,
long
trackTime
)
{
long
now
=
System
.
currentTimeMillis
();
if
(
now
-
trackTime
>
Constants
.
ONLINE_SOURCE_TIME
)
{
//大于6分钟 有源在线
location
.
setStatus
(
ConstantsDevice
.
DEVICE_STATUS_ONLINE
);
location
.
setStatusTime
(
DateUtil
.
formatTimeInSec
((
now
-
trackTime
)
/
1000
));
return
;
}
if
(
speed
!=
null
&&
speed
>
0
)
{
//行驶状态
location
.
setStatus
(
ConstantsDevice
.
DEVICE_STATUS_DRIVING
);
return
;
}
//无速度 静止
location
.
setStatus
(
ConstantsDevice
.
DEVICE_STATUS_STATIC
);
location
.
setStatusTime
(
DateUtil
.
formatTimeInSec
((
now
-
trackTime
)
/
1000
));
}
}
}
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