From 2a889bf2b917b72fcc03104f5064cf305ce1612b Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期六, 07 三月 2026 21:02:19 +0800
Subject: [PATCH] 修改bug

---
 xp-robotaxi-vehicle-convoy-boot/src/main/java/com/xiaopeng/vehicleConvoy/service/impl/XpFleetServiceImpl.java |   56 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/xp-robotaxi-vehicle-convoy-boot/src/main/java/com/xiaopeng/vehicleConvoy/service/impl/XpFleetServiceImpl.java b/xp-robotaxi-vehicle-convoy-boot/src/main/java/com/xiaopeng/vehicleConvoy/service/impl/XpFleetServiceImpl.java
index f579c7f..d190ac7 100644
--- a/xp-robotaxi-vehicle-convoy-boot/src/main/java/com/xiaopeng/vehicleConvoy/service/impl/XpFleetServiceImpl.java
+++ b/xp-robotaxi-vehicle-convoy-boot/src/main/java/com/xiaopeng/vehicleConvoy/service/impl/XpFleetServiceImpl.java
@@ -185,6 +185,7 @@
             if (excludeFleetId != null) {
                 wrapper.ne(XpFleetOperations::getFleetId, excludeFleetId);
             }
+            wrapper.last("limit 1");
             XpFleetOperations operations = xpFleetOperationsService.getOne(wrapper);
             if (operations != null) {
                 // 查询人员姓名和车队名称
@@ -218,6 +219,7 @@
             if (excludeFleetId != null) {
                 wrapper.ne(XpFleetVehicle::getFleetId, excludeFleetId);
             }
+            wrapper.last("limit 1");
             XpFleetVehicle fleetVehicle = xpFleetVehicleService.getOne(wrapper);
             if (fleetVehicle != null) {
                 // 车辆已绑定其他车队,自动解绑
@@ -238,15 +240,53 @@
         FleetDetailVO vo = new FleetDetailVO();
         BeanUtils.copyProperties(fleet, vo);
 
-        // 3. 统计人员数量
-        long userCount = xpFleetOperationsService.count(new LambdaQueryWrapper<XpFleetOperations>()
-                .eq(XpFleetOperations::getFleetId, id));
-        vo.setUserCount((int) userCount);
+        // 3. 统计人员数量(过滤已删除人员)
+        List<Long> bindUserIds = xpFleetOperationsService.lambdaQuery()
+                .eq(XpFleetOperations::getFleetId, id)
+                .list()
+                .stream()
+                .map(XpFleetOperations::getOperationsUserId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .collect(Collectors.toList());
+        int userCount = 0;
+        if (!CollectionUtils.isEmpty(bindUserIds)) {
+            try {
+                R<List<XpOperationsUser>> usersResult = xpOperationUserClient.listByIds(bindUserIds);
+                if (usersResult != null && usersResult.getData() != null) {
+                    userCount = usersResult.getData().size();
+                } else {
+                    userCount = bindUserIds.size();
+                }
+            } catch (Exception e) {
+                userCount = bindUserIds.size();
+            }
+        }
+        vo.setUserCount(userCount);
 
-        // 4. 统计车辆数量
-        long vehicleCount = xpFleetVehicleService.count(new LambdaQueryWrapper<XpFleetVehicle>()
-                .eq(XpFleetVehicle::getFleetId, id));
-        vo.setVehicleCount((int) vehicleCount);
+        // 4. 统计车辆数量(过滤已删除车辆)
+        List<Long> bindVehicleIds = xpFleetVehicleService.lambdaQuery()
+                .eq(XpFleetVehicle::getFleetId, id)
+                .list()
+                .stream()
+                .map(XpFleetVehicle::getVehicleId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .collect(Collectors.toList());
+        int vehicleCount = 0;
+        if (!CollectionUtils.isEmpty(bindVehicleIds)) {
+            try {
+                R<List<XpVehicle>> vehiclesResult = xpVehicleClient.listByIds(bindVehicleIds);
+                if (vehiclesResult != null && vehiclesResult.getData() != null) {
+                    vehicleCount = vehiclesResult.getData().size();
+                } else {
+                    vehicleCount = bindVehicleIds.size();
+                }
+            } catch (Exception e) {
+                vehicleCount = bindVehicleIds.size();
+            }
+        }
+        vo.setVehicleCount(vehicleCount);
 
         // 5. 查询负责人信息
         if (fleet.getOperationsUserId() != null) {

--
Gitblit v1.7.1