Commit 2af1c2a2 by levphon

bug修复-授权车辆不能是其自己可见车辆

1 parent b98abe65
......@@ -82,7 +82,9 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
*/
List<OrgVehicleModel> selectAbsolutelyVehicleSns(VehicleTreeSearch search);
Vehicle selectById(@Param("vehicleId") Long vehicleId);
Vehicle selectById(@Param("id") Long id);
List<Vehicle> selectByIds(@Param("ids") Collection<Long> ids);
/**
* genuine车架号查找车辆
......
......@@ -9,6 +9,7 @@ import com.glsx.plat.common.utils.StringUtils;
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.collections.CollectionUtils;
......@@ -56,28 +57,13 @@ public class UserApiService {
/**
* 根据用户id查找上级用户信息
*
* @param userId
* @return
*/
public User getSuperiorUserById(Long userId) {
R<User> userR = userService.getSuperiorUserById(userId);
if (userR == null) {
return null;
}
User user = userR.getData(User.class);
return user;
}
/**
* 根据用户id查找上级用户信息
*
* @param userIds
* @return
*/
public Map<Long, User> getSuperiorUserMapByIds(Collection<Long> userIds) {
Map<Long, User> userMap = Maps.newHashMap();
R<List<User>> listR = userService.getSuperiorUserByIds(userIds);
R<List<User>> listR = userService.getSuperiorByIds(userIds);
if (listR == null) {
return userMap;
}
......@@ -91,6 +77,21 @@ public class UserApiService {
}
/**
* 根据用户id查找下级用户(含自己)信息
*
* @param userId
* @return
*/
public Set<Long> getSubordinateById(Long userId) {
R<Set<Long>> setR = userService.getSubordinateById(userId);
if (setR == null) {
return Sets.newHashSet();
}
return setR.getDataList(new TypeToken<Set<Long>>() {
}.getType());
}
/**
* 根据用户名称查找用户id
*
* @param username
......
......@@ -234,8 +234,7 @@ public class VehicleMonitorSevice {
Map<String, Boolean> snsOnlineMap = Maps.newHashMap();
if (judgeOnline) {
//注意这里过滤了设备类型为空的数据,如果设备不在线,要检查设备类型数据是否同步或设置
Map<String, Integer> snsMap = modelList.stream().filter(m -> m.getDeviceType() != null)
.collect(Collectors.toMap(OrgVehicleModel::getSns, OrgVehicleModel::getDeviceType));
Map<String, Integer> snsMap = modelList.stream().filter(m -> m.getDeviceType() != null).collect(Collectors.toMap(OrgVehicleModel::getSns, OrgVehicleModel::getDeviceType, (o, n) -> n));
snsOnlineMap = deviceMonitorApiService.judgeIsOnline(snsMap);
}
......
......@@ -2029,6 +2029,14 @@ public class VehicleService {
public int assignVehicle(VehiclePermitAssignBO assignBO) {
List<VehiclePermit> list = Lists.newArrayList();
//被授权人的下级用户id(含自己)
Set<Long> subordinateIds = userApiService.getSubordinateById(assignBO.getReceiverId());
//当前被分享的车
List<Vehicle> vehicleList = vehicleMapper.selectByIds(assignBO.getVehicleIds());
Map<Long, Long> vehicleCreatedByMap = vehicleList.stream().collect(Collectors.toMap(Vehicle::getId, Vehicle::getCreatedBy));
// 2022/3/16 查出已经授权的和这次授权的比较,删除旧数据
List<VehiclePermit> vpList = vehiclePermitMapper.selectByReceiverId(assignBO.getReceiverId(), 0);
......@@ -2037,8 +2045,15 @@ public class VehicleService {
List<Long> addIdList = Lists.newArrayList();
assignBO.getVehicleIds().forEach(vehicleId -> {
//如果已经存在,则忽略
Long vehicleCreatedBy = vehicleCreatedByMap.get(vehicleId);
//如果车辆已经是其常规权限可见车辆,则忽略
if (subordinateIds.contains(vehicleCreatedBy)) {
log.warn("被授权人{}已经拥有车辆{}的常规授权,车辆归属人为{}", assignBO.getReceiverId(), vehicleId, vehicleCreatedBy);
return;
}
//如果被授权车辆已经授权过给被授权人,则忽略
if (existedVehicleIds.contains(vehicleId)) {
log.warn("被授权人{}已经拥有车辆{}的精确授权", assignBO.getReceiverId(), vehicleId);
return;
}
......
......@@ -367,10 +367,22 @@
</select>
<select id="selectById" resultMap="BaseResultMap">
select *
select
<include refid="Base_Column_List"/>
from t_vehicle
where id = #{id}
and del_flag = 0
</select>
<select id="selectByIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle
where id = #{vehicleId}
and del_flag = 0
where del_flag = 0
and id in
<foreach collection="ids" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</select>
<select id="getVehicleByVin" resultMap="BaseResultMap">
......
......@@ -499,13 +499,6 @@ public class VehicleServiceTest {
if (matches) {
System.out.println("matches = " + matches);
}
}
@Test
public void test17() {
User superiorUserById = userApiService.getSuperiorUserById(8102L);
System.out.println("superiorUserById = " + JSON.toJSONString(superiorUserById));
}
@Test
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!