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 192cf98e
authored
Mar 16, 2022
by
levphon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
车辆精确授权优化
授权组件升级
1 parent
46aa163a
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
93 additions
and
46 deletions
pom.xml
src/main/java/cn/com/glsx/admin/modules/controller/VehicleController.java
src/main/java/cn/com/glsx/admin/modules/mapper/VehicleMapper.java
src/main/java/cn/com/glsx/admin/modules/model/imports/VinWorkOrderNoImportListener.java
src/main/java/cn/com/glsx/admin/modules/model/imports/WorkOrderImportListener.java
src/main/java/cn/com/glsx/admin/modules/service/UserApiService.java
src/main/java/cn/com/glsx/admin/modules/service/VehicleService.java
src/main/resources/mapper/VehicleMapper.xml
pom.xml
View file @
192cf98
...
...
@@ -15,8 +15,8 @@
<dependencies>
<dependency>
<groupId>
com.glsx
</groupId>
<artifactId>
glsx-
ne-shield-auth-client
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<artifactId>
ne-shield-auth-client
</artifactId>
<version>
1.
1.
0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
...
...
src/main/java/cn/com/glsx/admin/modules/controller/VehicleController.java
View file @
192cf98
...
...
@@ -4,6 +4,7 @@ import cn.com.glsx.admin.common.constants.Constants;
import
cn.com.glsx.admin.common.enums.OrgVehicleTreeIdTag
;
import
cn.com.glsx.admin.common.enums.ResultEnum
;
import
cn.com.glsx.admin.common.exception.AdminException
;
import
cn.com.glsx.admin.modules.entity.Vehicle
;
import
cn.com.glsx.admin.modules.model.*
;
import
cn.com.glsx.admin.modules.model.export.TrialDriveVehicleExport
;
import
cn.com.glsx.admin.modules.model.export.VehicleInfoReportExport
;
...
...
@@ -32,6 +33,7 @@ import com.glsx.plat.office.excel.EasyExcelUtils;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -500,14 +502,14 @@ public class VehicleController {
}
/**
* @param oId
* @param oId
s
* @return
*/
@ApiOperation
(
value
=
"选择车辆树组织节点,获取组织权限用户所有车辆id"
)
@GetMapping
(
"/ovlist"
)
public
R
<
List
<
OrgVehicleTree
>>
selectTree
(
@RequestParam
(
"oId
"
)
Long
oId
)
{
public
R
<
List
<
OrgVehicleTree
>>
selectTree
(
@RequestParam
(
"oId
s"
)
List
<
Long
>
oIds
)
{
List
<
OrgVehicleModel
>
modelList
=
vehicleService
.
selectTreeByOrgId
(
oId
);
List
<
OrgVehicleModel
>
modelList
=
vehicleService
.
selectTreeByOrgId
s
(
oIds
);
List
<
OrgVehicleTree
>
list
=
vehicleService
.
convert2ovt
(
modelList
);
...
...
@@ -515,14 +517,14 @@ public class VehicleController {
}
/**
* @param uId
* @param uId
s
* @return
*/
@ApiOperation
(
value
=
"选择车辆树用户节点,获取用户权限所有车辆id"
)
@GetMapping
(
"/uvlist"
)
public
R
<
List
<
OrgVehicleTree
>>
vehicleList
(
@RequestParam
(
"uId
"
)
String
uId
)
{
public
R
<
List
<
OrgVehicleTree
>>
vehicleList
(
@RequestParam
(
"uId
s"
)
List
<
String
>
uIds
)
{
List
<
OrgVehicleModel
>
modelList
=
vehicleService
.
selectVehiclesByUserId
(
Long
.
valueOf
(
uId
.
replace
(
OrgVehicleTreeIdTag
.
USER
.
getTag
(),
""
))
);
List
<
OrgVehicleModel
>
modelList
=
vehicleService
.
selectVehiclesByUserId
s
(
uIds
);
List
<
OrgVehicleTree
>
list
=
vehicleService
.
convert2ovt
(
modelList
);
...
...
@@ -542,4 +544,10 @@ public class VehicleController {
return
R
.
ok
().
data
(
list
);
}
@GetMapping
(
"/permit/shared"
)
public
R
getSharedVehicles
()
{
List
<
Vehicle
>
list
=
vehicleService
.
getSharedVehicles
();
return
R
.
ok
().
data
(
list
);
}
}
src/main/java/cn/com/glsx/admin/modules/mapper/VehicleMapper.java
View file @
192cf98
...
...
@@ -4,6 +4,7 @@ import cn.com.glsx.admin.modules.entity.Vehicle;
import
cn.com.glsx.admin.modules.model.*
;
import
cn.com.glsx.admin.modules.model.export.*
;
import
cn.com.glsx.admin.modules.model.param.*
;
import
com.glsx.plat.common.annotation.DataOnlyShared
;
import
com.glsx.plat.common.annotation.DataPerm
;
import
com.glsx.plat.common.annotation.DataPermShare
;
import
com.glsx.plat.mybatis.mapper.CommonBaseMapper
;
...
...
@@ -276,4 +277,12 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
*/
Vehicle
selectBizWorkNoAndVin
(
@Param
(
"bizOrderNo"
)
String
bizOrderNo
,
@Param
(
"vin"
)
String
vin
);
/**
* 查询用户被分享的车辆数据
*
* @return
*/
@DataOnlyShared
List
<
Vehicle
>
selectAllShared
();
}
\ No newline at end of file
src/main/java/cn/com/glsx/admin/modules/model/imports/VinWorkOrderNoImportListener.java
View file @
192cf98
...
...
@@ -154,7 +154,7 @@ public class VinWorkOrderNoImportListener extends AnalysisEventListener<VinWorkO
// 2022/3/15 校验是否已经授权
boolean
receiverHasPermit
=
vehicleService
.
checkReceiverPermit
(
receiverId
,
vehicle
);
if
(
!
receiverHasPermit
)
{
if
(
receiverHasPermit
)
{
vwi
.
setImportFailReason
(
"车辆已被授权过"
);
log
.
warn
(
vwi
.
toString
());
return
false
;
...
...
@@ -183,7 +183,7 @@ public class VinWorkOrderNoImportListener extends AnalysisEventListener<VinWorkO
if
(
CollectionUtils
.
isNotEmpty
(
failList
))
{
baseImportInfo
.
setFailNum
(
failList
.
size
());
String
filename
=
"失败信息导出"
+
DateUtils
.
formatSerial
(
new
Date
())
+
".xlsx"
;
String
filename
=
"失败信息导出"
+
DateUtils
.
formatSerial
(
new
Date
());
//生成导入失败数据excel文件
String
filepath
=
buildFailFile
(
filename
,
failList
);
...
...
src/main/java/cn/com/glsx/admin/modules/model/imports/WorkOrderImportListener.java
View file @
192cf98
...
...
@@ -208,7 +208,7 @@ public class WorkOrderImportListener extends AnalysisEventListener<WorkOrderImpo
if
(
CollectionUtils
.
isNotEmpty
(
failList
))
{
baseImportInfo
.
setFailNum
(
failList
.
size
());
String
filename
=
"失败信息导出"
+
DateUtils
.
formatSerial
(
new
Date
())
+
".xlsx"
;
String
filename
=
"失败信息导出"
+
DateUtils
.
formatSerial
(
new
Date
());
//生成导入失败数据excel文件
String
filepath
=
buildFailFile
(
filename
,
failList
);
...
...
src/main/java/cn/com/glsx/admin/modules/service/UserApiService.java
View file @
192cf98
package
cn
.
com
.
glsx
.
admin
.
modules
.
service
;
import
cn.com.glsx.admin.common.enums.OrgVehicleTreeIdTag
;
import
cn.com.glsx.admin.modules.model.param.BasicSearch
;
import
cn.com.glsx.usercenter.api.dto.request.FindUserRequest
;
import
cn.com.glsx.usercenter.api.dto.response.User
;
...
...
@@ -11,7 +12,6 @@ import com.google.common.collect.Maps;
import
com.google.gson.reflect.TypeToken
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.map.HashedMap
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -218,7 +218,7 @@ public class UserApiService {
if
(
CollectionUtils
.
isEmpty
(
search
.
getCheckedOrgIds
()))
{
return
;
}
if
(
"u"
.
equals
(
search
.
getOrgType
()))
{
if
(
OrgVehicleTreeIdTag
.
USER
.
getTag
()
.
equals
(
search
.
getOrgType
()))
{
search
.
setCheckedUserIdsStr
(
StringUtils
.
join
(
search
.
getCheckedOrgIds
().
toArray
(),
","
));
}
else
{
List
<
User
>
userList
=
this
.
findAllByOrg
(
Lists
.
newArrayList
(
search
.
getCheckedOrgIds
()));
...
...
src/main/java/cn/com/glsx/admin/modules/service/VehicleService.java
View file @
192cf98
...
...
@@ -50,6 +50,7 @@ import com.glsx.plat.context.utils.PropertiesUtils;
import
com.glsx.plat.core.web.R
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Sets
;
import
com.google.gson.reflect.TypeToken
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.beanutils.ConvertUtils
;
...
...
@@ -1083,6 +1084,7 @@ public class VehicleService {
/**
* 给设备添加设备状态
*
* @param vehicleInfoList
*/
private
void
buildDeviceStatusCommon
(
List
<
VehicleInfoPageDTO
>
vehicleInfoList
)
{
...
...
@@ -1096,8 +1098,8 @@ public class VehicleService {
deviceSearchDTO
.
setOfflineTime
(
0L
);
log
.
info
(
"批量调用设备状态查询接口==="
+
sns
.
size
());
R
<
List
<
DeviceStatusModel
>>
listDeviceStatusR
=
deviceFeignService
.
listDeviceStatusBySns
(
deviceSearchDTO
);
log
.
info
(
"批量调用设备状态返回结果==="
+
((
listDeviceStatusR
!=
null
)?
listDeviceStatusR
.
getCode
():
"error"
));
if
(
listDeviceStatusR
==
null
)
{
log
.
info
(
"批量调用设备状态返回结果==="
+
((
listDeviceStatusR
!=
null
)
?
listDeviceStatusR
.
getCode
()
:
"error"
));
if
(
listDeviceStatusR
==
null
)
{
return
;
}
...
...
@@ -1109,10 +1111,10 @@ public class VehicleService {
return
;
}
Map
<
String
,
DeviceStatusModel
>
deviceStatusModelMap
=
deviceStatusModelList
.
stream
().
collect
(
Collectors
.
toMap
(
DeviceStatusModel:
:
getSn
,
Function
.
identity
(),
(
v1
,
v2
)->
v1
));
Map
<
String
,
DeviceStatusModel
>
deviceStatusModelMap
=
deviceStatusModelList
.
stream
().
collect
(
Collectors
.
toMap
(
DeviceStatusModel:
:
getSn
,
Function
.
identity
(),
(
v1
,
v2
)
->
v1
));
for
(
VehicleInfoPageDTO
vehicleInfoPageDTO
:
vehicleInfoList
)
{
DeviceStatusModel
deviceStatusModel
=
deviceStatusModelMap
.
get
(
vehicleInfoPageDTO
.
getSn
());
if
(
deviceStatusModel
==
null
||
deviceStatusModel
.
getStatus
()==
null
)
{
if
(
deviceStatusModel
==
null
||
deviceStatusModel
.
getStatus
()
==
null
)
{
continue
;
}
Integer
deviceStatus
=
deviceStatusModel
.
getStatus
();
...
...
@@ -1254,6 +1256,7 @@ public class VehicleService {
/**
* 给导出数据增加设备状态
*
* @param vehicleInfoReportExportList
*/
private
void
buildDeviceStatusExpert
(
List
<
VehicleInfoReportExport
>
vehicleInfoReportExportList
)
{
...
...
@@ -1265,7 +1268,7 @@ public class VehicleService {
deviceSearchDTO
.
setSns
(
sns
);
deviceSearchDTO
.
setOfflineTime
(
0L
);
R
<
List
<
DeviceStatusModel
>>
listDeviceStatusR
=
deviceFeignService
.
listDeviceStatusBySns
(
deviceSearchDTO
);
if
(
listDeviceStatusR
==
null
)
{
if
(
listDeviceStatusR
==
null
)
{
return
;
}
// 状态(0 行驶中 1 静止 2离线 3 在线)
...
...
@@ -1276,10 +1279,10 @@ public class VehicleService {
return
;
}
Map
<
String
,
DeviceStatusModel
>
deviceStatusModelMap
=
deviceStatusModelList
.
stream
().
collect
(
Collectors
.
toMap
(
DeviceStatusModel:
:
getSn
,
Function
.
identity
(),
(
v1
,
v2
)->
v1
));
Map
<
String
,
DeviceStatusModel
>
deviceStatusModelMap
=
deviceStatusModelList
.
stream
().
collect
(
Collectors
.
toMap
(
DeviceStatusModel:
:
getSn
,
Function
.
identity
(),
(
v1
,
v2
)
->
v1
));
for
(
VehicleInfoReportExport
vehicleInfoReportExport
:
vehicleInfoReportExportList
)
{
DeviceStatusModel
deviceStatusModel
=
deviceStatusModelMap
.
get
(
vehicleInfoReportExport
.
getSn
());
if
(
deviceStatusModel
==
null
||
deviceStatusModel
.
getStatus
()==
null
)
{
if
(
deviceStatusModel
==
null
||
deviceStatusModel
.
getStatus
()
==
null
)
{
continue
;
}
Integer
deviceStatus
=
deviceStatusModel
.
getStatus
();
...
...
@@ -1842,14 +1845,18 @@ public class VehicleService {
/**
* 用户勾选车辆树 某节点 全选下面所有车辆时候 需要返回给前端所有设备id
*
* @param oid
* @param oid
s
* @return
*/
public
List
<
OrgVehicleModel
>
selectTreeByOrgId
(
Long
oid
)
{
public
List
<
OrgVehicleModel
>
selectTreeByOrgIds
(
List
<
Long
>
oids
)
{
if
(
CollectionUtils
.
isEmpty
(
oids
))
{
return
Lists
.
newArrayList
();
}
StopWatch
sw
=
new
StopWatch
();
sw
.
start
(
"task1"
);
//待优化,这里只需要拿组织下的用户即可,可以在用户服务端过滤掉组织
List
<
OrgTreeModel
>
orgTreeModelList
=
organizationApiService
.
orgTree
(
new
VehicleTreeSearch
().
setOrgIds
(
Lists
.
newArrayList
(
oid
)
));
List
<
OrgTreeModel
>
orgTreeModelList
=
organizationApiService
.
orgTree
(
new
VehicleTreeSearch
().
setOrgIds
(
oids
));
if
(
CollectionUtils
.
isEmpty
(
orgTreeModelList
))
{
return
Lists
.
newArrayList
();
...
...
@@ -1873,7 +1880,7 @@ public class VehicleService {
VehicleTreeSearch
vtSearch
=
new
VehicleTreeSearch
();
vtSearch
.
setUserIds
(
userIdList
);
List
<
OrgVehicleModel
>
modelList
=
vehicleMapper
.
selectOrgVehicle
(
vtSearch
);
log
.
info
(
"组织{}下面总车辆设备数{}"
,
oid
,
modelList
.
size
());
log
.
info
(
"组织{}下面总车辆设备数{}"
,
oid
s
,
modelList
.
size
());
sw
.
stop
();
log
.
info
(
"selectTreeByOrgId任务耗时概览:{},总耗时:{}秒"
,
sw
.
prettyPrint
(),
sw
.
getTotalTimeSeconds
());
...
...
@@ -1883,21 +1890,26 @@ public class VehicleService {
/**
* 组织树选择用户id获取车辆列表
*
* @param userId
* @param userId
s
* @return
*/
public
List
<
OrgVehicleModel
>
selectVehiclesByUserId
(
Long
userId
)
{
if
(
userId
==
null
)
{
public
List
<
OrgVehicleModel
>
selectVehiclesByUserId
s
(
List
<
String
>
userIds
)
{
if
(
CollectionUtils
.
isEmpty
(
userIds
)
)
{
return
Lists
.
newArrayList
();
}
Set
<
Long
>
userIdSet
=
Sets
.
newHashSet
();
userIds
.
forEach
(
userIdStr
->
{
userIdSet
.
add
(
Long
.
valueOf
(
userIdStr
.
replace
(
OrgVehicleTreeIdTag
.
USER
.
getTag
(),
""
)));
});
StopWatch
sw
=
new
StopWatch
();
sw
.
start
(
"task1"
);
VehicleTreeSearch
vtSearch
=
new
VehicleTreeSearch
();
vtSearch
.
setUserIds
(
Lists
.
newArrayList
(
userId
)
);
vtSearch
.
setUserIds
(
userIdSet
);
List
<
OrgVehicleModel
>
modelList
=
vehicleMapper
.
selectOrgVehicle
(
vtSearch
);
log
.
info
(
"用户{}下面总车辆设备数{}"
,
userId
,
modelList
.
size
());
log
.
info
(
"用户{}下面总车辆设备数{}"
,
userId
s
,
modelList
.
size
());
sw
.
stop
();
log
.
info
(
"selectVehiclesByUserId任务耗时概览:{},总耗时:{}秒"
,
sw
.
prettyPrint
(),
sw
.
getTotalTimeSeconds
());
...
...
@@ -1983,6 +1995,9 @@ public class VehicleService {
if
(
vehicle
==
null
||
vehicle
.
getCreatedBy
()
==
null
)
{
return
false
;
}
if
(
ShieldContextHolder
.
isSuperAdmin
())
{
return
true
;
}
return
ShieldContextHolder
.
getVisibleCreatorIds
().
contains
(
vehicle
.
getCreatedBy
());
}
...
...
@@ -2009,8 +2024,9 @@ public class VehicleService {
vp
.
setCreatedDate
(
now
);
list
.
add
(
vp
);
});
// TODO: 2022/3/15 重复性处理
vehiclePermitMapper
.
insertList
(
list
);
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
vehiclePermitMapper
.
insertList
(
list
);
}
}
public
List
<
VehiclePermitDTO
>
getAssignVehicle
(
Long
receiverId
)
{
...
...
@@ -2018,4 +2034,9 @@ public class VehicleService {
return
list
;
}
public
List
<
Vehicle
>
getSharedVehicles
()
{
List
<
Vehicle
>
list
=
vehicleMapper
.
selectAllShared
();
return
list
;
}
}
src/main/resources/mapper/VehicleMapper.xml
View file @
192cf98
...
...
@@ -741,9 +741,9 @@
and tvd.del_flag = 0
<if
test=
"offlineStartTime != null and offlineStartTime != ''"
>
and ((tdl.last_gps_time
<
#{offlineStartTime} and tdl.last_bs_time
<
#{offlineStartTime})
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and tdl.last_bs_time
<
#{offlineStartTime})
or (tdl.last_gps_time
<
#{offlineStartTime} and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and tdl.last_bs_time
<
#{offlineStartTime})
or (tdl.last_gps_time
<
#{offlineStartTime} and tdl.last_bs_time is null)
)
</if>
<if
test=
"activeStartTime != null and activeStartTime != ''"
>
...
...
@@ -881,9 +881,9 @@
left join t_device_location tdl on tdl.sn = td.sn
WHERE tvd.del_flag = 0 and tv.del_flag = 0 and tvd.bind_status = 1
and ((timestampdiff(SECOND, tdl.last_gps_time, now())
>
#{offlineTime} and timestampdiff(SECOND, tdl.last_bs_time, now())
>
#{offlineTime})
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and timestampdiff(SECOND, tdl.last_bs_time, now())
>
#{offlineTime})
or (timestampdiff(SECOND, tdl.last_gps_time, now())
>
#{offlineTime} and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and timestampdiff(SECOND, tdl.last_bs_time, now())
>
#{offlineTime})
or (timestampdiff(SECOND, tdl.last_gps_time, now())
>
#{offlineTime} and tdl.last_bs_time is null)
)
<if
test=
"offlineSnStr != null and offlineSnStr != ''"
>
and tvd.sn not in (${offlineSnStr})
...
...
@@ -930,9 +930,9 @@
<!--离线时间-->
<if
test=
"lostBegin != null"
>
and ((tdl.last_gps_time
<
#{lostBegin} and tdl.last_bs_time
<
#{lostBegin})
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and tdl.last_bs_time
<
#{lostBegin})
or (tdl.last_gps_time
<
#{lostBegin} and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and tdl.last_bs_time
<
#{lostBegin})
or (tdl.last_gps_time
<
#{lostBegin} and tdl.last_bs_time is null)
)
</if>
</select>
...
...
@@ -964,22 +964,31 @@
</select>
<select
id=
"getVehicleAndDeviceMap"
resultType=
"java.util.HashMap"
>
SELECT tv.vin ,GROUP_CONCAT(tvd.sn)
FROM t_vehicle tv LEFT JOIN t_vehicle_device tvd ON tvd.vehicle_id = tv.id
SELECT tv.vin, GROUP_CONCAT(tvd.sn)
FROM t_vehicle tv
LEFT JOIN t_vehicle_device tvd ON tvd.vehicle_id = tv.id
WHERE tv.del_flag = 0
GROUP BY tv.vin;
</select>
<select
id=
"getVehicleByPermission"
resultType=
"java.lang.String"
>
select distinct vin from t_vehicle where del_flag = 0;
select distinct vin
from t_vehicle
where del_flag = 0;
</select>
<select
id=
"selectBizWorkNoAndVin"
resultMap=
"BaseResultMap"
>
select tv.*
from t_vehicle tv
left join t_workorder tw on tw.id = tv.workorder_id
left join t_workorder tw on tw.id = tv.workorder_id
where tv.del_flag = 0
and tw.partner_order_no = #{bizOrderNo}
and tv.vin = #{vin}
</select>
<select
id=
"selectAllShared"
resultMap=
"BaseResultMap"
>
select tv.*
from t_vehicle tv
where tv.del_flag = 0
and tw.partner_order_no = #{bizOrderNo}
and tv.vin = #{vin}
</select>
</mapper>
\ 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