Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-standard-interfaces
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5400679f
authored
Feb 23, 2022
by
王欣伟
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
仲利请款代码开发
1 parent
ccf4e5c9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
330 additions
and
41 deletions
src/main/java/cn/com/glsx/stdinterface/common/constants/Constants.java
src/main/java/cn/com/glsx/stdinterface/modules/service/WorkOrderService.java
src/main/java/cn/com/glsx/stdinterface/modules/util/DateUtils.java
src/main/java/cn/com/glsx/stdinterface/modules/util/DeviceLocationUtil.java
src/main/java/cn/com/glsx/stdinterface/common/constants/Constants.java
View file @
5400679
...
...
@@ -80,4 +80,74 @@ public final class Constants {
*/
public
static
final
int
ALARM_REC_LIGHT
=
99
;
/**
* 位置有效性验证
*/
public
static
class
Verification
{
/**
* 有源设备定位有效时间4h内;单位毫秒
*/
public
static
final
long
WIRED_TIME
=
14400000
;
/**
* 无源源设备定位有效时间24h10min内;单位毫秒
*/
public
static
final
long
WIRELESS_TIME
=
87000000
;
/**
* 设备定位状态 0有效定位
*/
public
static
final
int
SN_VALID
=
0
;
/**
* 设备定位状态 1无效定位
*/
public
static
final
int
SN_INVALID
=
1
;
}
/**
* 设备有源无源状态
*/
public
static
class
DeviceSource
{
/**
* 有源设备
*/
public
static
final
int
WIRED
=
1
;
/**
* 无源设备
*/
public
static
final
int
WIRELESS
=
0
;
}
/**
* 设备车辆行驶状态
*/
public
static
class
DeviceOnline
{
/**
* 行驶
*/
public
static
final
int
DRIVING
=
0
;
/**
* 静止
*/
public
static
final
int
STANDSTILL
=
1
;
/**
* 离线
*/
public
static
final
int
OFFLINE
=
2
;
/**
* 在线
*/
public
static
final
int
ONLINE
=
3
;
}
}
src/main/java/cn/com/glsx/stdinterface/modules/service/WorkOrderService.java
View file @
5400679
...
...
@@ -11,6 +11,7 @@ import cn.com.glsx.devicemonitor.api.enums.DeviceTypeRelationEnum;
import
cn.com.glsx.devicemonitor.api.enums.DeviceWireTypeEnum
;
import
cn.com.glsx.devicemonitor.api.feign.DeviceFeignService
;
import
cn.com.glsx.devicemonitor.api.feign.GpsBsFeignService
;
import
cn.com.glsx.stdinterface.common.constants.Constants
;
import
cn.com.glsx.stdinterface.common.exception.StdInterfaceException
;
import
cn.com.glsx.stdinterface.dto.*
;
import
cn.com.glsx.stdinterface.enums.BizServiceTypeEnum
;
...
...
@@ -22,6 +23,7 @@ import cn.com.glsx.stdinterface.modules.converter.WorkOrderVehicleConverter;
import
cn.com.glsx.stdinterface.modules.entity.*
;
import
cn.com.glsx.stdinterface.modules.mapper.*
;
import
cn.com.glsx.stdinterface.modules.remote.NotifyCenterService
;
import
cn.com.glsx.stdinterface.modules.util.DeviceLocationUtil
;
import
cn.com.glsx.usercenter.api.dto.response.User
;
import
cn.com.glsx.usercenter.api.feign.ApiUserService
;
import
cn.hutool.core.collection.CollectionUtil
;
...
...
@@ -1067,55 +1069,67 @@ public class WorkOrderService {
//查车辆
Vehicle
vehicle
=
vehicleMapper
.
selectByWorkOrderId
(
workOrder
.
getId
());
if
(
vehicle
!=
null
)
{
verifyDTO
.
setLesseeName
(
vehicle
.
getOwnerName
());
verifyDTO
.
setVin
(
vehicle
.
getVin
());
//查车辆设备
List
<
VehicleDevice
>
deviceList
=
vehicleDeviceMapper
.
selectBindingDevicesByVehicleId
(
vehicle
.
getId
());
List
<
String
>
snList
=
deviceList
.
stream
().
map
(
VehicleDevice:
:
getSn
).
collect
(
Collectors
.
toList
());
if
(
vehicle
==
null
)
{
throw
new
StdInterfaceException
(
"656565"
,
String
.
format
(
"工单%s未完成"
,
verifyBO
.
getBizWorkOrderNo
()));
}
List
<
WorkOrderDeviceAddressItem
>
list
=
Lists
.
newArrayList
();
verifyDTO
.
setLesseeName
(
vehicle
.
getOwnerName
());
verifyDTO
.
setVin
(
vehicle
.
getVin
());
//查位置点
Map
<
String
,
GpsBsData
>
gpsBsDataMap
=
getLastGpsBsBatchBySns
(
snList
);
//查车辆设备
List
<
VehicleDevice
>
deviceList
=
vehicleDeviceMapper
.
selectBindingDevicesByVehicleId
(
vehicle
.
getId
());
List
<
String
>
snList
=
deviceList
.
stream
().
map
(
VehicleDevice:
:
getSn
).
collect
(
Collectors
.
toList
());
List
<
WorkOrderDeviceAddressItem
>
list
=
Lists
.
newArrayList
();
snList
.
forEach
(
sn
->
{
WorkOrderDeviceAddressItem
addressItem
=
new
WorkOrderDeviceAddressItem
();
//位置是否有效的配置
long
wiredTime
=
Constants
.
Verification
.
WIRED_TIME
;
long
wirelessTime
=
Constants
.
Verification
.
WIRELESS_TIME
;
//查位置点
Map
<
String
,
GpsBsData
>
gpsBsDataMap
=
getLastGpsBsBatchBySns
(
snList
);
snList
.
forEach
(
sn
->
{
WorkOrderDeviceAddressItem
addressItem
=
new
WorkOrderDeviceAddressItem
();
R
<
DeviceDTO
>
deviceDTOR
=
deviceFeignService
.
getDeviceBySn
(
sn
);
DeviceDTO
deviceDTO
=
deviceDTOR
.
getData
(
DeviceDTO
.
class
);
R
<
DeviceDTO
>
deviceDTOR
=
deviceFeignService
.
getDeviceBySn
(
sn
);
DeviceDTO
deviceDTO
=
deviceDTOR
.
getData
(
DeviceDTO
.
class
);
addressItem
.
setSn
(
sn
);
addressItem
.
setSim
(
deviceDTO
.
getSim
());
addressItem
.
setDeviceType
(
deviceDTO
.
getSource
()
==
1
?
"有线设备"
:
"无线设备"
);
addressItem
.
setSn
(
sn
);
addressItem
.
setSim
(
deviceDTO
.
getSim
());
addressItem
.
setDeviceType
(
deviceDTO
.
getSource
()==
Constants
.
DeviceSource
.
WIRED
?
"有线设备"
:
"无线设备"
);
GpsBsData
gpsBsData
=
gpsBsDataMap
.
get
(
sn
);
if
(
gpsBsData
!=
null
)
{
String
speedValue
=
""
;
// 获取 Gps 定位数据
GpsLocation
gpsLocation
=
gpsBsData
.
getGpsLocation
();
if
(
gpsLocation
!=
null
)
{
addressItem
.
setGpsLat
(
gpsLocation
.
getLat
());
addressItem
.
setGpsLng
(
gpsLocation
.
getLng
());
addressItem
.
setGpsPosition
(
gpsLocation
.
getAddress
());
addressItem
.
setGpsTime
(
gpsLocation
.
getDateTime
());
speedValue
=
gpsLocation
.
getSpeed
();
}
GpsBsData
gpsBsData
=
gpsBsDataMap
.
get
(
sn
);
if
(
gpsBsData
!=
null
)
{
// 获取 Gps 定位数据
GpsLocation
gpsLocation
=
gpsBsData
.
getGpsLocation
();
if
(
gpsLocation
!=
null
)
{
addressItem
.
setGpsLat
(
gpsLocation
.
getLat
());
addressItem
.
setGpsLng
(
gpsLocation
.
getLng
());
addressItem
.
setGpsPosition
(
gpsLocation
.
getAddress
());
addressItem
.
setGpsTime
(
gpsLocation
.
getDateTime
());
}
// 获取基站定位数据
GpsLocation
bsLocation
=
gpsBsData
.
getBsLocation
();
if
(
bsLocation
!=
null
)
{
addressItem
.
setBsPosition
(
bsLocation
.
getAddress
());
addressItem
.
setBsTime
(
bsLocation
.
getDateTime
());
}
// 获取基站定位数据
GpsLocation
bsLocation
=
gpsBsData
.
getBsLocation
();
if
(
bsLocation
!=
null
)
{
addressItem
.
setBsPosition
(
bsLocation
.
getAddress
());
addressItem
.
setBsTime
(
bsLocation
.
getDateTime
());
}
// TODO: 2022/2/22
addressItem
.
setType
(
0
);
addressItem
.
setStatus
(
3
);
// 如果基站时间为空,则将GPS时间填充到基站时间中
if
(
StringUtils
.
isBlank
(
addressItem
.
getBsTime
()))
{
addressItem
.
setBsTime
(
addressItem
.
getGpsTime
());
}
list
.
add
(
addressItem
);
});
verifyDTO
.
setList
(
list
);
}
// 设置设备位置有效状态
addressItem
.
setType
(
DeviceLocationUtil
.
resolutionGpsType
(
addressItem
.
getGpsTime
(),
addressItem
.
getBsTime
(),
deviceDTO
.
getSource
()));
// 设置设备位置行驶状态
addressItem
.
setStatus
(
DeviceLocationUtil
.
resolutionDeviceOnlineStatus
(
addressItem
,
deviceDTO
.
getSource
(),
speedValue
));
}
list
.
add
(
addressItem
);
});
verifyDTO
.
setList
(
list
);
return
verifyDTO
;
}
...
...
src/main/java/cn/com/glsx/stdinterface/modules/util/DateUtils.java
View file @
5400679
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 日期处理
*
* @author yll
*/
@Slf4j
public
class
DateUtils
extends
com
.
glsx
.
plat
.
common
.
utils
.
DateUtils
{
public
final
static
String
[]
pattern
=
{
"yyyy-MM-dd HH:mm:ss"
};
public
final
static
long
defaultTimeDiff
=
-
1
l
;
public
static
String
pattern19
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
String
pattern14
=
"yyyyMMddHHmmss"
;
public
static
String
pattern10
=
"yyyy-MM-dd"
;
public
static
String
pattern8
=
"yyyyMMdd"
;
public
static
String
pattern6
=
"HHmmss"
;
private
static
final
Map
<
String
,
ThreadLocal
<
SimpleDateFormat
>>
pool
=
new
HashMap
<
String
,
ThreadLocal
<
SimpleDateFormat
>>();
private
static
final
Object
lock
=
new
Object
();
public
static
SimpleDateFormat
getDateFormat
(
String
pattern
)
{
ThreadLocal
<
SimpleDateFormat
>
tl
=
pool
.
get
(
pattern
);
if
(
tl
==
null
)
{
synchronized
(
lock
)
{
tl
=
pool
.
get
(
pattern
);
if
(
tl
==
null
)
{
final
String
p
=
pattern
;
tl
=
new
ThreadLocal
<
SimpleDateFormat
>()
{
protected
synchronized
SimpleDateFormat
initialValue
()
{
return
new
SimpleDateFormat
(
p
);
}
};
pool
.
put
(
p
,
tl
);
}
}
}
return
tl
.
get
();
}
/**
* 时间字符串转日期
* @param dateStr
* @param pattern
* @return
*/
public
static
Date
toDate
(
String
dateStr
,
String
pattern
)
{
try
{
return
getDateFormat
(
pattern
).
parse
(
dateStr
);
}
catch
(
ParseException
e
)
{
log
.
error
(
"dateUtil parseException"
,
e
);
}
return
null
;
}
/**
* 日期转时间字符串
* @param date
* @param pattern
* @return
*/
public
static
String
toString
(
Date
date
,
String
pattern
)
{
return
getDateFormat
(
pattern
).
format
(
date
);
}
public
static
String
nowString
(
String
pattern
)
{
return
getDateFormat
(
pattern
).
format
(
new
Date
());
}
/**
* 格式化传的时间为 X天X小时X分
*
...
...
@@ -28,4 +101,27 @@ public class DateUtils extends com.glsx.plat.common.utils.DateUtils {
return
"0"
;
}
}
/**
* 计算当前时间与指定时间的时间差
*
* @param time
* @return
* @author lidh
*/
@SuppressWarnings
(
"null"
)
public
static
long
getTimeDifference
(
String
time
)
{
if
(
StringUtils
.
isBlank
(
time
))
{
return
defaultTimeDiff
;
}
try
{
Date
parseDate
=
DateUtils
.
parseDate
(
time
,
pattern
);
long
difference
=
System
.
currentTimeMillis
()
-
parseDate
.
getTime
();
return
difference
;
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
return
defaultTimeDiff
;
}
}
src/main/java/cn/com/glsx/stdinterface/modules/util/DeviceLocationUtil.java
0 → 100644
View file @
5400679
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
util
;
import
cn.com.glsx.stdinterface.common.constants.Constants
;
import
cn.com.glsx.stdinterface.dto.WorkOrderDeviceAddressItem
;
import
org.apache.commons.lang.StringUtils
;
import
java.util.Date
;
/**
* 设备位置信息 - 工具类
*/
public
class
DeviceLocationUtil
{
/**
* 解析设备位置状态:有效,无效
* @param gpsTime
* @param bsTime
* @param source
* @return
*/
public
static
Integer
resolutionGpsType
(
String
gpsTime
,
String
bsTime
,
Integer
source
)
{
if
(
StringUtils
.
isBlank
(
gpsTime
)
&&
StringUtils
.
isEmpty
(
bsTime
))
{
return
Constants
.
Verification
.
SN_INVALID
;
}
int
currentSource
=
(
source
==
null
)?
Constants
.
DeviceSource
.
WIRED
:
Constants
.
DeviceSource
.
WIRELESS
;
long
differBase
=
(
currentSource
==
Constants
.
DeviceSource
.
WIRED
)?
Constants
.
Verification
.
WIRED_TIME
:
Constants
.
Verification
.
WIRELESS_TIME
;
if
(
StringUtils
.
isBlank
(
gpsTime
))
{
return
Constants
.
Verification
.
SN_INVALID
;
}
long
timeDiff
=
DateUtils
.
getTimeDifference
(
gpsTime
);
if
(
currentSource
==
Constants
.
DeviceSource
.
WIRELESS
)
{
long
gpsDiffer
=
DateUtils
.
getTimeDifference
(
gpsTime
);
long
bsDiffer
=
DateUtils
.
getTimeDifference
(
bsTime
);
timeDiff
=
(
gpsDiffer
>
bsDiffer
)?
gpsDiffer:
bsDiffer
;
}
return
timeDiff
>
differBase
?
Constants
.
Verification
.
SN_INVALID
:
Constants
.
Verification
.
SN_VALID
;
}
/**
* 解析设备在线状态
* @param addressItem
* @param source
* @param speedValue
* @return
*/
public
static
Integer
resolutionDeviceOnlineStatus
(
WorkOrderDeviceAddressItem
addressItem
,
Integer
source
,
String
speedValue
)
{
if
(
StringUtils
.
isBlank
(
addressItem
.
getGpsTime
()))
{
return
Constants
.
DeviceOnline
.
OFFLINE
;
}
int
currentSource
=
(
source
==
null
)?
Constants
.
DeviceSource
.
WIRED
:
Constants
.
DeviceSource
.
WIRELESS
;
int
speed
=
StringUtils
.
isEmpty
(
speedValue
)?
0
:
Integer
.
parseInt
(
speedValue
);
Date
gpsDate
=
DateUtils
.
toDate
(
addressItem
.
getGpsTime
(),
DateUtils
.
pattern19
);
Date
bsDate
=
DateUtils
.
toDate
(
addressItem
.
getBsTime
(),
DateUtils
.
pattern19
);
long
rtTrckTime
=
(
gpsDate
!=
null
)?
gpsDate
.
getTime
():
0
l
;
long
gprsTime
=
(
bsDate
!=
null
)?
bsDate
.
getTime
():
0
l
;
int
status
=
0
;
long
now
=
System
.
currentTimeMillis
();
if
(
gprsTime
==
0
&&
rtTrckTime
==
0
)
{
//离线
status
=
Constants
.
DeviceOnline
.
OFFLINE
;
}
else
if
(
gprsTime
==
0
&&
rtTrckTime
!=
0
)
{
status
=
commonResolutionOnline
(
now
,
rtTrckTime
,
speed
,
currentSource
);
}
else
if
(
gprsTime
!=
0
&&
rtTrckTime
==
0
)
{
status
=
commonResolutionOnline
(
now
,
gprsTime
,
speed
,
currentSource
);
}
else
{
long
time
=
0
;
time
=
gprsTime
>=
rtTrckTime
?
gprsTime
:
rtTrckTime
;
status
=
commonResolutionOnline
(
now
,
time
,
speed
,
currentSource
);
}
return
status
;
}
/**
* 根据当前时间判断设备的行驶状态
* @param now
* @param rtTrckTime
* @param speed
* @param currentSource
* @return
*/
private
static
int
commonResolutionOnline
(
long
now
,
long
rtTrckTime
,
int
speed
,
int
currentSource
)
{
int
status
=
Constants
.
DeviceOnline
.
DRIVING
;
if
(
now
-
rtTrckTime
>
3
*
24
*
60
*
60
*
1000
)
{
status
=
Constants
.
DeviceOnline
.
OFFLINE
;
}
else
{
if
(
currentSource
==
Constants
.
DeviceSource
.
WIRELESS
)
{
status
=
Constants
.
DeviceOnline
.
ONLINE
;
}
else
{
if
(
now
-
rtTrckTime
>
6
*
60
*
1000
)
{
//大于6分钟 有源在线
status
=
Constants
.
DeviceOnline
.
ONLINE
;
}
else
{
if
(
speed
>
0
)
{
//行驶状态
status
=
Constants
.
DeviceOnline
.
DRIVING
;
}
else
{
status
=
Constants
.
DeviceOnline
.
STANDSTILL
;
}
}
}
}
return
status
;
}
}
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