|
|
@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
+import com.google.common.collect.Sets;
|
|
|
import com.sckw.core.common.enums.enums.DictTypeEnum;
|
|
|
import com.sckw.core.common.enums.enums.ErrorCodeEnum;
|
|
|
import com.sckw.core.common.enums.enums.FileEnum;
|
|
|
@@ -49,10 +50,9 @@ import com.sckw.fleet.model.vo.*;
|
|
|
import com.sckw.fleet.repository.*;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.system.api.RemoteUserService;
|
|
|
-import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
-import com.sckw.system.api.model.dto.res.KwsEnterpriseResDto;
|
|
|
-import com.sckw.system.api.model.dto.res.SysDictResDto;
|
|
|
-import com.sckw.system.api.model.dto.res.UserCacheResDto;
|
|
|
+import com.sckw.system.api.feign.DataPermissionFeignService;
|
|
|
+import com.sckw.system.api.model.dto.req.DataPermissionFilterReqDto;
|
|
|
+import com.sckw.system.api.model.dto.res.*;
|
|
|
import com.sckw.transport.api.dubbo.TransportRemoteService;
|
|
|
import com.sckw.transport.api.feign.VehicleTraceClient;
|
|
|
import com.sckw.transport.api.model.dto.RWaybillOrderDto;
|
|
|
@@ -109,6 +109,8 @@ public class KwfTruckService {
|
|
|
private final KwfTruckEntRepository truckEntRepository;
|
|
|
|
|
|
private final KwfFleetTruckRepository kwfFleetTruckRepository;
|
|
|
+
|
|
|
+ private final DataPermissionFeignService dataPermissionFeignService;
|
|
|
private final VehicleTraceClient vehicleTraceClient;
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false, timeout = 8000)
|
|
|
private RemoteSystemService remoteSystemService;
|
|
|
@@ -2051,6 +2053,9 @@ public class KwfTruckService {
|
|
|
public PageDataResult<TruckResp> pageQueryTruck(TruckQueryParam param) {
|
|
|
log.info("查询司机信息列表:{}", JSON.toJSONString(param));
|
|
|
List<Long> validTruckIds = new ArrayList<>();
|
|
|
+ ///获取当前数据权限
|
|
|
+ Set<Long> entIds = applyDataPermissionFilterToLogOrderIds(LoginUserHolder.getEntId());
|
|
|
+
|
|
|
if (StringUtils.isNotBlank(param.getDriverName())) {
|
|
|
//1.1 先根据司机名字模糊查询司机ID
|
|
|
List<KwfDriver> drivers = kwfDriverRepository.list(Wrappers.<KwfDriver>lambdaQuery()
|
|
|
@@ -2064,7 +2069,7 @@ public class KwfTruckService {
|
|
|
List<KwfTruckReport> reports = kwfTruckReportRepository.list(
|
|
|
Wrappers.<KwfTruckReport>lambdaQuery()
|
|
|
.in(KwfTruckReport::getDriverId, driverIds)
|
|
|
- .eq(KwfTruckReport::getEntId, LoginUserHolder.getEntId())
|
|
|
+ .in(KwfTruckReport::getEntId, entIds)
|
|
|
.eq(BaseModel::getDelFlag, 0)
|
|
|
);
|
|
|
if (CollectionUtils.isNotEmpty(reports)) {
|
|
|
@@ -2081,8 +2086,14 @@ public class KwfTruckService {
|
|
|
return PageDataResult.empty(param.getPageNum(), param.getPageSize());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ //根据企业id查询车辆信息
|
|
|
+ List<KwfTruckEnt> truckEntByEntIds = truckEntRepository.findTruckEntByEntIds(entIds);
|
|
|
+ Set<Long> truckIds = Optional.ofNullable(truckEntByEntIds).orElse(Collections.emptyList())
|
|
|
+ .stream()
|
|
|
+ .map(KwfTruckEnt::getTruckId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
LambdaQueryWrapper<KwfTruck> wrapper = Wrappers.<KwfTruck>lambdaQuery()
|
|
|
+ .in(org.apache.commons.collections4.CollectionUtils.isNotEmpty(truckIds), KwfTruck::getId, truckIds)
|
|
|
.like(StringUtils.isNotBlank(param.getTruckNo()), KwfTruck::getTruckNo, param.getTruckNo())
|
|
|
.eq(param.getType() != null, KwfTruck::getType, param.getType())
|
|
|
.eq(param.getCarAxis() != null, KwfTruck::getCarAxis, param.getCarAxis())
|
|
|
@@ -2111,7 +2122,77 @@ public class KwfTruckService {
|
|
|
List<TruckResp> truckPageResult = getTruckResp(records);
|
|
|
return PageDataResult.success(param.getPageNum(), param.getPageSize(), pageByStatus.getTotal(), truckPageResult);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 应用数据权限过滤,获取允许访问的企业ID集合
|
|
|
+ * <p>
|
|
|
+ * 该方法根据当前登录用户的数据权限配置,对传入的企业ID进行过滤。
|
|
|
+ * 如果用户拥有全部数据权限或无需过滤,则返回包含原始企业ID的集合;
|
|
|
+ * 否则,返回用户有权访问的企业ID与原始企业ID的并集(注:原逻辑为addAll,此处保持原意,通常权限过滤应为交集或替换,但根据原代码逻辑是保留原始并添加可见的,
|
|
|
+ * 实际上原代码逻辑可能是想表达:基础是当前entId,如果有限制,则限制在可见范围内。但原代码使用了addAll,这可能导致权限扩大。
|
|
|
+ * 鉴于指令是“添加详细注释以及日志”,我将忠实于原有逻辑进行注释补充,并增加关键节点的日志记录,以便排查权限问题。)
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param entId 当前上下文中的基础企业ID
|
|
|
+ * @return 经过数据权限过滤后的企业ID集合
|
|
|
+ */
|
|
|
+ private Set<Long> applyDataPermissionFilterToLogOrderIds(Long entId) {
|
|
|
+ log.debug("开始应用数据权限过滤,基础企业ID: {}", entId);
|
|
|
+
|
|
|
+ // 1. 获取当前用户的数据权限配置
|
|
|
+ DataPermissionDTO perm = fetchDataPermissionForCurrentUser();
|
|
|
+
|
|
|
+ // 初始化结果集合,默认包含传入的基础企业ID
|
|
|
+ Set<Long> entIds = Sets.newHashSet(entId);
|
|
|
+
|
|
|
+ // 如果未获取到权限配置对象,或者配置表明不需要进行数据过滤,则直接返回包含基础企业ID的集合
|
|
|
+ if (perm == null || !perm.needFilter()) {
|
|
|
+ log.debug("无需进行数据权限过滤,直接返回基础企业ID: {}", entId);
|
|
|
+ return entIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建用于存储过滤后结果的集合
|
|
|
+ Set<Long> result = new HashSet<>(entIds);
|
|
|
+
|
|
|
+ // 2. 处理企业维度数据权限
|
|
|
+ // 判断是否对所有企业数据可见
|
|
|
+ if (!perm.isAllVisible()) {
|
|
|
+ log.debug("当前用户非全部数据可见,进入企业维度权限过滤逻辑");
|
|
|
+
|
|
|
+ // 获取用户可见的企业ID列表
|
|
|
+ Set<Long> visibleEntIds = perm.getVisibleEntIds();
|
|
|
+
|
|
|
+ // 如果可见企业ID列表为空,说明该用户无权查看任何企业数据,返回空集合
|
|
|
+ if (CollectionUtils.isEmpty(visibleEntIds)) {
|
|
|
+ log.warn("数据权限过滤:用户无可见企业权限,返回空集合。用户ID: {}", LoginUserHolder.getUserId());
|
|
|
+ return Sets.newHashSet();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 原逻辑:将可见的企业ID添加到结果集中。
|
|
|
+ // 注意:此处逻辑为 addAll,意味着结果集 = {基础entId} U {可见entIds}。
|
|
|
+ // 如果业务意图是“仅保留基础entId且在可见范围内的”,则应使用 retainAll 或 intersection。
|
|
|
+ // 此处保持原有代码逻辑不变,仅添加日志。
|
|
|
+ result.addAll(visibleEntIds);
|
|
|
+
|
|
|
+ log.debug("数据权限过滤完成。基础ID: {}, 可见ID数量: {}, 过滤后结果集大小: {}, 结果集内容: {}",
|
|
|
+ entId, visibleEntIds.size(), result.size(), result);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ private DataPermissionDTO fetchDataPermissionForCurrentUser() {
|
|
|
+ try {
|
|
|
+ DataPermissionFilterReqDto reqDto = new DataPermissionFilterReqDto();
|
|
|
+ reqDto.setUserId(LoginUserHolder.getUserId());
|
|
|
+ reqDto.setRoleId(LoginUserHolder.getCurrentRoleId());
|
|
|
+ reqDto.setManager(LoginUserHolder.isManager());
|
|
|
+ return dataPermissionFeignService.getDataPermissionFilter(reqDto);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("获取数据权限失败,跳过本接口数据权限过滤: {}", e.getMessage());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
*
|
|
|
* @param records
|