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 e10f4036
authored
May 20, 2022
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化设备激活信息保存逻辑
1 parent
a8261f7b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
119 additions
and
47 deletions
src/main/java/cn/com/glsx/stdinterface/modules/controller/DeviceActiveController.java
src/main/java/cn/com/glsx/stdinterface/modules/multithread/AsyncTasks.java
src/main/java/cn/com/glsx/stdinterface/modules/service/DeviceActiveService.java
src/main/java/cn/com/glsx/stdinterface/modules/controller/DeviceActiveController.java
View file @
e10f403
...
...
@@ -44,6 +44,7 @@ public class DeviceActiveController implements DeviceActiveClient {
* @param snList 设备号集合
* @return
*/
@Override
@PostMapping
(
"/saveActiveInfoFlush"
)
@ApiOperation
(
value
=
"手动更新设备激活定位点"
)
@SysLog
(
module
=
"设备激活"
,
value
=
"手动更新设备激活定位点"
,
action
=
OperateType
.
QUERY
,
saveLog
=
false
)
...
...
src/main/java/cn/com/glsx/stdinterface/modules/multithread/AsyncTasks.java
View file @
e10f403
...
...
@@ -7,6 +7,7 @@ import cn.com.glsx.stdinterface.modules.entity.VehicleDevice;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper
;
import
cn.com.glsx.stdinterface.modules.remote.RemoteGpsBsService
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.glsx.plat.common.utils.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -44,6 +45,7 @@ public class AsyncTasks {
return
;
}
lastGpsBsList
.
forEach
(
gpsBsData
->
{
log
.
info
(
"gpsBsData==="
+
JSONUtil
.
toJsonStr
(
gpsBsData
));
VehicleDevice
vehicleDevice
=
new
VehicleDevice
();
vehicleDevice
.
setSn
(
gpsBsData
.
getSn
());
GpsLocation
gpsLocation
=
gpsBsData
.
getGpsLocation
();
...
...
@@ -105,7 +107,7 @@ public class AsyncTasks {
vehicleDevice
.
setSn
(
gpsBsData
.
getSn
());
GpsLocation
gpsLocation
=
gpsBsData
.
getGpsLocation
();
// 默认保存GPS定位数据 没有GPS定位数据 保存BS定位数据
if
(
Object
s
.
non
Null
(
gpsLocation
))
{
if
(
Object
Util
.
isNot
Null
(
gpsLocation
))
{
vehicleDevice
.
setActiveLocationDate
(
DateUtils
.
stringToDate
(
gpsLocation
.
getDateTime
(),
DateUtils
.
NORMAL_DATE_TIME_PATTERN
));
vehicleDevice
.
setActiveLocationType
(
Constants
.
LocationType
.
GPS
);
vehicleDevice
.
setActiveLocationLng
(
gpsLocation
.
getLng
());
...
...
@@ -116,7 +118,7 @@ public class AsyncTasks {
vehicleDeviceMapper
.
updateVehicleDeviceBysn
(
vehicleDevice
);
}
else
{
GpsLocation
bsLocation
=
gpsBsData
.
getBsLocation
();
if
(
Object
s
.
non
Null
(
bsLocation
))
{
if
(
Object
Util
.
isNot
Null
(
bsLocation
))
{
vehicleDevice
.
setActiveLocationDate
(
DateUtils
.
stringToDate
(
bsLocation
.
getDateTime
(),
DateUtils
.
NORMAL_DATE_TIME_PATTERN
));
vehicleDevice
.
setActiveLocationType
(
Constants
.
LocationType
.
BS
);
vehicleDevice
.
setActiveLocationLng
(
bsLocation
.
getLng
());
...
...
src/main/java/cn/com/glsx/stdinterface/modules/service/DeviceActiveService.java
View file @
e10f403
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
service
;
import
cn.com.glsx.devicemonitor.api.dto.response.GpsBsData
;
import
cn.com.glsx.devicemonitor.api.dto.response.GpsLocation
;
import
cn.com.glsx.stdinterface.common.constants.Constants
;
import
cn.com.glsx.stdinterface.modules.entity.VehicleDevice
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper
;
import
cn.com.glsx.stdinterface.modules.multithread.AsyncTasks
;
import
cn.com.glsx.stdinterface.modules.remote.RemoteGpsBsService
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.glsx.plat.common.multithread.ListSplitIterator
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.glsx.plat.common.utils.DateUtils
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.google.common.collect.Lists
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -14,7 +21,7 @@ import org.springframework.util.StopWatch;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.List
;
import
java.util.
concurrent.CountDownLatch
;
import
java.util.
Objects
;
/**
* 设备激活 service
...
...
@@ -31,9 +38,6 @@ public class DeviceActiveService {
@Autowired
private
VehicleDeviceMapper
vehicleDeviceMapper
;
@Autowired
private
AsyncTasks
asyncTasks
;
/**
* 保存设备激活信息 feign 调用
*
...
...
@@ -44,37 +48,9 @@ public class DeviceActiveService {
log
.
info
(
"saveActiveInfo snList is null"
);
return
;
}
saveActiveInfoSync
(
snList
);
}
/**
* 多线程补充设备激活经纬度数据和激活地址
*
* @param dataList 设备号集合大小
*/
public
void
saveActiveInfoSync
(
List
<
String
>
dataList
)
{
log
.
info
(
"###save active info data start###"
);
if
(
CollectionUtils
.
isEmpty
(
dataList
))
{
return
;
}
StopWatch
sw
=
new
StopWatch
();
sw
.
start
(
"saveActiveInfoSync"
);
ListSplitIterator
<
String
>
listSplitIterator
=
new
ListSplitIterator
<>(
dataList
,
100
);
CountDownLatch
countDownLatch
=
new
CountDownLatch
(
listSplitIterator
.
size
());
while
(
listSplitIterator
.
hasNext
())
{
List
<
String
>
snList
=
listSplitIterator
.
next
();
asyncTasks
.
saveActiveInfo
(
snList
,
countDownLatch
,
remoteGpsBsService
,
vehicleDeviceMapper
);
}
try
{
countDownLatch
.
await
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
sw
.
stop
();
log
.
info
(
"###save active info data end"
+
sw
.
getLastTaskTimeMillis
()
+
"ms###"
);
saveActiveInfoByFeign
(
snList
);
}
/**
* 保存设备激活信息 by 定时任务调用
*
...
...
@@ -100,16 +76,8 @@ public class DeviceActiveService {
}
StopWatch
sw
=
new
StopWatch
();
sw
.
start
(
"saveActiveInfoSyncByTask"
);
ListSplitIterator
<
String
>
listSplitIterator
=
new
ListSplitIterator
<>(
dataList
,
50
);
CountDownLatch
countDownLatch
=
new
CountDownLatch
(
listSplitIterator
.
size
());
while
(
listSplitIterator
.
hasNext
())
{
List
<
String
>
snList
=
listSplitIterator
.
next
();
asyncTasks
.
saveActiveInfoByTask
(
snList
,
countDownLatch
,
remoteGpsBsService
,
vehicleDeviceMapper
);
}
try
{
countDownLatch
.
await
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
for
(
String
sn
:
dataList
)
{
saveActiveInfoByTask
(
sn
);
}
sw
.
stop
();
log
.
info
(
"###save active info by task data end"
+
sw
.
getLastTaskTimeMillis
()
+
"ms###"
);
...
...
@@ -137,4 +105,105 @@ public class DeviceActiveService {
log
.
info
(
"allUnActiveInfoSnList size==="
+
allUnActiveInfoSnList
.
size
());
saveActiveInfoByTask
(
allUnActiveInfoSnList
);
}
public
void
saveActiveInfoByFeign
(
List
<
String
>
snList
)
{
if
(
CollectionUtil
.
isEmpty
(
snList
))
{
log
.
info
(
"snList is null"
);
return
;
}
try
{
log
.
info
(
"saveActiveInfoByFeign 开始同步激活信息,snList==="
+
JSONUtil
.
toJsonStr
(
snList
));
List
<
GpsBsData
>
lastGpsBsList
=
remoteGpsBsService
.
getLastGpsBsListBySns
(
snList
);
if
(
CollectionUtil
.
isEmpty
(
lastGpsBsList
))
{
log
.
info
(
"saveActiveInfoByFeign lastGpsBsList is null"
);
return
;
}
lastGpsBsList
.
forEach
(
gpsBsData
->
{
log
.
info
(
"Feign gpsBsData==="
+
JSONUtil
.
toJsonStr
(
gpsBsData
));
VehicleDevice
vehicleDevice
=
new
VehicleDevice
();
vehicleDevice
.
setSn
(
gpsBsData
.
getSn
());
GpsLocation
gpsLocation
=
gpsBsData
.
getGpsLocation
();
// 默认保存GPS定位数据 没有GPS定位数据 保存BS定位数据
if
(
Objects
.
nonNull
(
gpsLocation
))
{
vehicleDevice
.
setActiveLocationDate
(
DateUtils
.
stringToDate
(
gpsLocation
.
getDateTime
(),
DateUtils
.
NORMAL_DATE_TIME_PATTERN
));
vehicleDevice
.
setActiveLocationType
(
Constants
.
LocationType
.
GPS
);
vehicleDevice
.
setActiveLocationLng
(
gpsLocation
.
getLng
());
vehicleDevice
.
setActiveLocationLat
(
gpsLocation
.
getLat
());
vehicleDevice
.
setActiveLocationAddress
(
gpsLocation
.
getAddress
());
// 保存激活信息
log
.
info
(
"active device info gps:"
+
JSONUtil
.
toJsonStr
(
vehicleDevice
));
vehicleDeviceMapper
.
updateVehicleDeviceBysn
(
vehicleDevice
);
}
else
{
GpsLocation
bsLocation
=
gpsBsData
.
getBsLocation
();
if
(
Objects
.
nonNull
(
bsLocation
))
{
vehicleDevice
.
setActiveLocationDate
(
DateUtils
.
stringToDate
(
bsLocation
.
getDateTime
(),
DateUtils
.
NORMAL_DATE_TIME_PATTERN
));
vehicleDevice
.
setActiveLocationType
(
Constants
.
LocationType
.
BS
);
vehicleDevice
.
setActiveLocationLng
(
bsLocation
.
getLng
());
vehicleDevice
.
setActiveLocationLat
(
bsLocation
.
getLat
());
vehicleDevice
.
setActiveLocationAddress
(
bsLocation
.
getAddress
());
// 保存激活信息
log
.
info
(
"active device info bs:"
+
JSONUtil
.
toJsonStr
(
vehicleDevice
));
vehicleDeviceMapper
.
updateVehicleDeviceBysn
(
vehicleDevice
);
}
}
});
}
catch
(
Exception
e
)
{
log
.
info
(
"saveActiveInfoByFeign异常信息==="
+
e
.
getMessage
(),
e
);
}
finally
{
log
.
info
(
Thread
.
currentThread
().
getName
()
+
"关闭资源"
);
}
}
/**
* 通过sn同步设备激活信息
*
* @param sn 设备号
*/
public
void
saveActiveInfoByTask
(
String
sn
)
{
if
(
StringUtils
.
isEmpty
(
sn
))
{
log
.
info
(
"sn is null"
);
return
;
}
try
{
log
.
info
(
"saveActiveInfoByTask 开始同步激活信息,sn==="
+
sn
);
List
<
GpsBsData
>
lastGpsBsList
=
remoteGpsBsService
.
getFirstGpsBsBatch
(
Lists
.
newArrayList
(
sn
));
if
(
CollectionUtil
.
isEmpty
(
lastGpsBsList
))
{
log
.
info
(
"saveActiveInfoByTask lastGpsBsList is null"
);
return
;
}
lastGpsBsList
.
forEach
(
gpsBsData
->
{
log
.
info
(
"Task gpsBsData==="
+
JSONUtil
.
toJsonStr
(
gpsBsData
));
VehicleDevice
vehicleDevice
=
new
VehicleDevice
();
vehicleDevice
.
setSn
(
gpsBsData
.
getSn
());
GpsLocation
gpsLocation
=
gpsBsData
.
getGpsLocation
();
// 默认保存GPS定位数据 没有GPS定位数据 保存BS定位数据
if
(
ObjectUtil
.
isNotNull
(
gpsLocation
))
{
vehicleDevice
.
setActiveLocationDate
(
DateUtils
.
stringToDate
(
gpsLocation
.
getDateTime
(),
DateUtils
.
NORMAL_DATE_TIME_PATTERN
));
vehicleDevice
.
setActiveLocationType
(
Constants
.
LocationType
.
GPS
);
vehicleDevice
.
setActiveLocationLng
(
gpsLocation
.
getLng
());
vehicleDevice
.
setActiveLocationLat
(
gpsLocation
.
getLat
());
vehicleDevice
.
setActiveLocationAddress
(
gpsLocation
.
getAddress
());
// 保存激活信息
log
.
info
(
"active device info by task gps:"
+
JSONUtil
.
toJsonStr
(
vehicleDevice
));
vehicleDeviceMapper
.
updateVehicleDeviceBysn
(
vehicleDevice
);
}
else
{
GpsLocation
bsLocation
=
gpsBsData
.
getBsLocation
();
if
(
ObjectUtil
.
isNotNull
(
bsLocation
))
{
vehicleDevice
.
setActiveLocationDate
(
DateUtils
.
stringToDate
(
bsLocation
.
getDateTime
(),
DateUtils
.
NORMAL_DATE_TIME_PATTERN
));
vehicleDevice
.
setActiveLocationType
(
Constants
.
LocationType
.
BS
);
vehicleDevice
.
setActiveLocationLng
(
bsLocation
.
getLng
());
vehicleDevice
.
setActiveLocationLat
(
bsLocation
.
getLat
());
vehicleDevice
.
setActiveLocationAddress
(
bsLocation
.
getAddress
());
// 保存激活信息
log
.
info
(
"active device info by task bs:"
+
JSONUtil
.
toJsonStr
(
vehicleDevice
));
vehicleDeviceMapper
.
updateVehicleDeviceBysn
(
vehicleDevice
);
}
}
});
}
catch
(
Exception
e
)
{
log
.
info
(
"saveActiveInfoByTask异常信息==="
+
e
.
getMessage
(),
e
);
}
finally
{
log
.
info
(
Thread
.
currentThread
().
getName
()
+
"关闭资源"
);
}
}
}
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