longz
2026-06-30 80fd77e1bcb47726e440b8a728838189cd39a56a
DriverYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/crossCity/server/impl/LineShiftDriverServiceImpl.java
@@ -79,6 +79,7 @@
    private ILineService lineService;
    @Autowired
    private IReassignService reassignService;
    @Resource
    private LineMapper lineMapper;
@@ -446,28 +447,48 @@
            return new ArrayList<>();
        }
        // 如果提供了订单ID,使用新的改派逻辑(包含needConfirm字段)
        if (ToolUtil.isNotEmpty(orderIds)) {
            try {
                // 使用第一个订单ID来查询(改派场景通常是单个订单,多个订单取第一个)
                String firstOrderId = orderIds.split(",")[0].trim();
                List<Map<String, Object>> drivers = reassignService.queryDriver(firstOrderId);
                return OtherDriverShiftWarpper.fromMaps(drivers);
            } catch (Exception e) {
                e.printStackTrace();
                // 如果新逻辑失败,降级到旧逻辑
        List<Map<String, Object>> rows = lineShiftDriverMapper.queryOtherDriverShiftListWithShiftId(driverShiftId);
        // 同批次司机不需要确认。
        Set<Integer> driverIds = new HashSet<>();
        for (Map<String, Object> row : rows) {
            row.put("needConfirm", 1);
            if (row.get("driverId") != null) {
                driverIds.add(Integer.valueOf(row.get("driverId").toString()));
            }
        }
        // 旧逻辑:只查询同批次司机(兼容没有传orderIds的场景)
        List<Map<String, Object>> rows = lineShiftDriverMapper.queryOtherDriverShiftListWithShiftId(driverShiftId);
        // 旧逻辑默认都是同批次,不需要确认
        for (Map<String, Object> row : rows) {
            row.put("needConfirm", 1);
        // 扩展内容:对应时间段无订单且无其他预约批次的同公司其他司机,需要确认。
        Integer firstOrderId = getFirstOrderId(orderIds);
        if (firstOrderId != null) {
            List<Map<String, Object>> extraRows = lineShiftDriverMapper.queryAvailableCompanyDriversForShift(driverShiftId, firstOrderId);
            for (Map<String, Object> row : extraRows) {
                if (row.get("driverId") == null) {
                    continue;
                }
                Integer extraDriverId = Integer.valueOf(row.get("driverId").toString());
                if (driverIds.contains(extraDriverId)) {
                    continue;
                }
                row.put("needConfirm", 2);
                rows.add(row);
                driverIds.add(extraDriverId);
            }
        }
        return OtherDriverShiftWarpper.fromMaps(rows);
    }
    private Integer getFirstOrderId(String orderIds) {
        if (ToolUtil.isEmpty(orderIds)) {
            return null;
        }
        try {
            String firstOrderId = orderIds.split(",")[0].trim();
            return ToolUtil.isEmpty(firstOrderId) ? null : Integer.valueOf(firstOrderId);
        } catch (Exception e) {
            return null;
        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultUtil<Map<String, Object>> addSelfTrip(Integer driverId, AddSelfTripWarpper warpper) throws Exception {