mes-processes/mes-plcSend/src/main/java/com/mes/interaction/vehicle/handler/LoadVehicleLogicHandler.java
@@ -1,10 +1,12 @@
package com.mes.interaction.vehicle.handler;
import com.mes.device.entity.DeviceConfig;
import com.mes.device.entity.DeviceStatus;
import com.mes.device.service.DeviceConfigService;
import com.mes.device.service.DeviceGroupRelationService;
import com.mes.device.service.DevicePlcOperationService;
import com.mes.device.service.GlassInfoService;
import com.mes.device.service.DeviceStatusService;
import com.mes.device.vo.DeviceGroupVO;
import com.mes.device.vo.DevicePlcVO;
import com.mes.interaction.BaseDeviceLogicHandler;
@@ -16,6 +18,8 @@
import com.mes.s7.enhanced.EnhancedS7Serializer;
import com.mes.s7.provider.S7SerializerProvider;
import com.mes.service.PlcDynamicDataService;
import com.mes.task.model.TaskExecutionContext;
import com.mes.interaction.workstation.scanner.handler.HorizontalScannerLogicHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -47,6 +51,9 @@
    
    @Autowired(required = false)
    private DeviceGroupRelationService deviceGroupRelationService;
    @Autowired(required = false)
    private DeviceStatusService deviceStatusService;
    
    @Autowired(required = false)
    private PlcDynamicDataService plcDynamicDataService;
@@ -187,6 +194,9 @@
                case "stopTaskMonitor":
                    result = handleStopTaskMonitor(deviceConfig);
                    break;
                case "setOnlineState":
                    result = handleSetOnlineState(deviceConfig, params, logicParams);
                    break;
                default:
                    log.warn("不支持的操作类型: {}", operation);
                    result = DevicePlcVO.OperationResult.builder()
@@ -219,8 +229,14 @@
     * 判断操作是否需要状态检查
     */
    private boolean needsStateCheck(String operation) {
        // 所有操作都需要检查状态,除了查询类操作
        return !"query".equals(operation) && !"status".equals(operation);
        // 所有操作都需要检查状态,除了查询类操作和特定内部检查
        if ("query".equals(operation) || "status".equals(operation)) {
            return false;
        }
        if ("checkMesConfirm".equals(operation)) {
            return false;
        }
        return true;
    }
    /**
@@ -256,7 +272,23 @@
        }
        
        // 从配置中获取速度(如果有)
        Double speed = getLogicParam(logicParams, "vehicleSpeed", null);
        Object speedObj = logicParams != null ? logicParams.get("vehicleSpeed") : null;
        Double speed = null;
        if (speedObj != null) {
            if (speedObj instanceof Double) {
                speed = (Double) speedObj;
            } else if (speedObj instanceof Integer) {
                speed = ((Integer) speedObj).doubleValue();
            } else if (speedObj instanceof Number) {
                speed = ((Number) speedObj).doubleValue();
            } else {
                try {
                    speed = Double.parseDouble(String.valueOf(speedObj));
                } catch (NumberFormatException e) {
                    log.warn("无法解析vehicleSpeed: {}", speedObj);
                }
            }
        }
        if (speed != null) {
            task.setSpeed(speed);
            task.calculateEstimatedEndTime();
@@ -284,7 +316,7 @@
        // 从逻辑参数中获取配置(从 extraParams.deviceLogic 读取)
        Integer vehicleCapacity = getLogicParam(logicParams, "vehicleCapacity", 6000);
        Integer glassIntervalMs = getLogicParam(logicParams, "glassIntervalMs", 1000);
        Integer glassGap = getLogicParam(logicParams, "glassGap", 200); // 玻璃之间的物理间隔(mm),默认200mm
        Boolean autoFeed = getLogicParam(logicParams, "autoFeed", true);
        Integer maxRetryCount = getLogicParam(logicParams, "maxRetryCount", 5);
@@ -301,14 +333,30 @@
        Integer positionValue = (Integer) params.get("positionValue");
        Boolean triggerRequest = (Boolean) params.getOrDefault("triggerRequest", autoFeed);
        List<GlassInfo> plannedGlasses = planGlassLoading(glassInfos, vehicleCapacity,
                getLogicParam(logicParams, "defaultGlassLength", 2000));
        if (plannedGlasses.isEmpty()) {
        List<GlassInfo> plannedGlasses = planGlassLoading(glassInfos, vehicleCapacity, glassGap,
                deviceConfig.getDeviceId());
        if (plannedGlasses == null) {
            // 玻璃没有长度时返回null表示错误
            return DevicePlcVO.OperationResult.builder()
                    .success(false)
                    .message("当前玻璃尺寸超出车辆容量,无法装载")
                    .message("玻璃信息缺少长度数据,无法进行容量计算。请检查MES程序是否正确提供玻璃长度。")
                    .build();
        }
        if (plannedGlasses.isEmpty()) {
            // 装不下,通知卧转立扫码设备暂停
            notifyScannerPause(params, true);
            log.warn("大车设备装不下,已通知卧转立扫码暂停: deviceId={}, glassCount={}, vehicleCapacity={}",
                    deviceConfig.getId(), glassInfos.size(), vehicleCapacity);
            return DevicePlcVO.OperationResult.builder()
                    .success(false)
                    .message("当前玻璃尺寸超出车辆容量,无法装载,已通知卧转立扫码暂停")
                    .build();
        }
        // 装得下,确保卧转立扫码继续运行
        notifyScannerPause(params, false);
        // 继续执行原有逻辑
        // 构建写入数据
        Map<String, Object> payload = new HashMap<>();
@@ -321,17 +369,21 @@
        }
        payload.put("plcGlassCount", plcSlots);
        // 写入位置信息
        // 写入位置信息:PLC侧期望的是 MES 编号(如1001/1002),而不是位置映射后的格子值
        Integer plcPosition = null;
        if (positionValue != null) {
            payload.put("inPosition", positionValue);
            // 如果调用方直接传了数值,则认为这是MES编号,直接写入
            plcPosition = positionValue;
        } else if (positionCode != null) {
            // 从位置映射中获取位置值
            @SuppressWarnings("unchecked")
            Map<String, Integer> positionMapping = getLogicParam(logicParams, "positionMapping", new HashMap<>());
            Integer mappedValue = positionMapping.get(positionCode);
            if (mappedValue != null) {
                payload.put("inPosition", mappedValue);
            // 尝试将位置代码解析为数字(例如 "900" -> 900)
            try {
                plcPosition = Integer.parseInt(positionCode.trim());
            } catch (NumberFormatException ignore) {
                // 非数字编码时,不写入inPosition,由PLC或后续逻辑自行处理
            }
        }
        if (plcPosition != null) {
            payload.put("inPosition", plcPosition);
        }
        // 自动触发请求字
@@ -347,18 +399,11 @@
        log.info("大车设备玻璃上料: deviceId={}, glassCount={}, position={}, plannedGlassIds={}",
                deviceConfig.getId(), plcSlots, positionCode, plannedGlasses);
        if (glassIntervalMs != null && glassIntervalMs > 0) {
            try {
                Thread.sleep(glassIntervalMs);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
        // 写入PLC,让大车开始装玻璃
        DevicePlcVO.OperationResult result = devicePlcOperationService.writeFields(
            deviceConfig.getId(), payload, operationName);
        
        // 如果执行成功,更新位置信息到状态,并启动状态监控
        // 如果执行成功,更新位置信息到状态
        if (Boolean.TRUE.equals(result.getSuccess())) {
            VehicleStatus status = statusManager.getOrCreateVehicleStatus(
                deviceConfig.getDeviceId(), deviceConfig.getDeviceName());
@@ -366,9 +411,16 @@
                VehiclePosition position = new VehiclePosition(positionCode, positionValue);
                status.setCurrentPosition(position);
            }
            // 启动自动状态监控,当 state=1 时自动协调卧转立设备
            startStateMonitoring(deviceConfig, logicParams);
            // 仅在“非多设备任务”场景下,才启动大车自身的自动状态监控和 MES 任务监控
            boolean inMultiDeviceTask = params != null && params.containsKey("_taskContext");
            if (!inMultiDeviceTask) {
                // 启动自动状态监控,当 state=1 时自动协调卧转立设备
                startStateMonitoring(deviceConfig, logicParams);
                // 从 PLC/MES 创建正式任务并启动监控的逻辑,保留给独立 MES 场景使用
                // 多设备任务场景下,这部分交由 TaskExecutionEngine 统一编排
            }
        }
        
        return result;
@@ -423,6 +475,7 @@
        Map<String, Object> payload = new HashMap<>();
        payload.put("plcRequest", 0);
        payload.put("plcReport", 0);
        payload.put("onlineState", Boolean.TRUE);
        
        log.info("大车设备重置: deviceId={}", deviceConfig.getId());
        
@@ -437,8 +490,65 @@
            statusManager.clearVehicleTask(deviceConfig.getDeviceId());
            statusManager.updateVehicleStatus(deviceConfig.getDeviceId(), VehicleState.IDLE);
            stopStateMonitoring(deviceConfig.getDeviceId());
            updateDeviceOnlineStatus(deviceConfig, true);
        }
        
        return result;
    }
    /**
     * 设置联机状态
     * @param deviceConfig 设备配置
     * @param params 参数,可包含 onlineState(1=联机,0=脱机)
     * @param logicParams 逻辑参数
     * @return 操作结果
     */
    private DevicePlcVO.OperationResult handleSetOnlineState(
            DeviceConfig deviceConfig,
            Map<String, Object> params,
            Map<String, Object> logicParams) {
        // 从参数中获取联机状态值,默认为true(联机)
        boolean onlineState = true;
        if (params != null && params.containsKey("onlineState")) {
            Object stateObj = params.get("onlineState");
            if (stateObj instanceof Boolean) {
                onlineState = (Boolean) stateObj;
            } else if (stateObj instanceof Number) {
                onlineState = ((Number) stateObj).intValue() != 0;
            } else if (stateObj instanceof String) {
                try {
                    String str = ((String) stateObj).trim();
                    if ("true".equalsIgnoreCase(str)) {
                        onlineState = true;
                    } else if ("false".equalsIgnoreCase(str)) {
                        onlineState = false;
                    } else {
                        onlineState = Integer.parseInt(str) != 0;
                    }
                } catch (NumberFormatException e) {
                    log.warn("解析onlineState失败,使用默认值true: deviceId={}, value={}",
                            deviceConfig.getId(), stateObj);
                }
            }
        }
        Map<String, Object> payload = new HashMap<>();
        payload.put("onlineState", onlineState);
        String stateText = onlineState ? "联机" : "脱机";
        log.info("大车设备设置联机状态: deviceId={}, onlineState={} ({})",
                deviceConfig.getId(), onlineState, stateText);
        DevicePlcVO.OperationResult result = devicePlcOperationService.writeFields(
                deviceConfig.getId(),
                payload,
                "大车设备-设置联机状态(" + stateText + ")"
        );
        if (Boolean.TRUE.equals(result.getSuccess())) {
            updateDeviceOnlineStatus(deviceConfig, onlineState);
        }
        return result;
    }
@@ -465,6 +575,7 @@
        payload.put("plcGlassCount", 0);
        payload.put("plcRequest", 0);
        payload.put("plcReport", 0);
        payload.put("onlineState", Boolean.TRUE);
        if (params != null && params.containsKey("positionValue")) {
            payload.put("inPosition", params.get("positionValue"));
@@ -485,9 +596,23 @@
            statusManager.clearVehicleTask(deviceConfig.getDeviceId());
            statusManager.updateVehicleStatus(deviceConfig.getDeviceId(), VehicleState.IDLE);
            stopStateMonitoring(deviceConfig.getDeviceId());
            updateDeviceOnlineStatus(deviceConfig, true);
        }
        
        return result;
    }
    private void updateDeviceOnlineStatus(DeviceConfig deviceConfig, boolean online) {
        if (deviceStatusService == null || deviceConfig == null || deviceConfig.getId() == null) {
            return;
        }
        try {
            String status = online ? DeviceStatus.Status.ONLINE : DeviceStatus.Status.OFFLINE;
            deviceStatusService.updateDeviceOnlineStatus(deviceConfig.getId(), status);
        } catch (Exception e) {
            log.warn("同步设备在线状态到数据库失败: deviceId={}, online={}, error={}",
                    deviceConfig.getDeviceId(), online, e.getMessage());
        }
    }
    private List<String> resolveGlassSlotFields(Map<String, Object> logicParams, int fallbackCount) {
@@ -525,9 +650,9 @@
            return "车辆容量(vehicleCapacity)必须大于0";
        }
        Integer glassIntervalMs = getLogicParam(logicParams, "glassIntervalMs", null);
        if (glassIntervalMs != null && glassIntervalMs < 0) {
            return "玻璃间隔时间(glassIntervalMs)不能为负数";
        Integer glassGap = getLogicParam(logicParams, "glassGap", null);
        if (glassGap != null && glassGap < 0) {
            return "玻璃间隔(glassGap)不能为负数";
        }
        return null; // 验证通过
@@ -537,7 +662,7 @@
    public String getDefaultLogicParams() {
        Map<String, Object> defaultParams = new HashMap<>();
        defaultParams.put("vehicleCapacity", 6000);
        defaultParams.put("glassIntervalMs", 1000);
        defaultParams.put("glassGap", 200); // 玻璃之间的物理间隔(mm),默认200mm
        defaultParams.put("autoFeed", true);
        defaultParams.put("maxRetryCount", 5);
        defaultParams.put("defaultGlassLength", 2000);
@@ -551,13 +676,6 @@
        defaultParams.put("taskMonitorIntervalMs", 1000); // 任务监控间隔(毫秒)
        defaultParams.put("mesConfirmTimeoutMs", 30000); // MES确认超时(毫秒)
        
        // 出片任务相关配置
        // outboundSlotRanges: 出片任务的startSlot范围,例如[1, 101]表示格子1~101都是出片任务
        // 如果不配置,则通过判断startSlot是否在positionMapping中来区分进片/出片
        List<Integer> outboundSlotRanges = new ArrayList<>();
        outboundSlotRanges.add(1);   // 最小格子编号
        outboundSlotRanges.add(101); // 最大格子编号
        defaultParams.put("outboundSlotRanges", outboundSlotRanges);
        
        // gridPositionMapping: 格子编号到位置的映射表(可选)
        // 如果不配置,则格子编号直接作为位置值
@@ -644,28 +762,56 @@
        return null;
    }
    /**
     * 规划玻璃装载
     * @param source 源玻璃列表
     * @param vehicleCapacity 车辆容量(mm)
     * @param glassGap 玻璃之间的物理间隔(mm),默认200mm
     * @param deviceId 设备ID(用于日志)
     * @return 规划后的玻璃列表,如果玻璃没有长度则返回null(用于测试MES程序)
     */
    private List<GlassInfo> planGlassLoading(List<GlassInfo> source,
                                             int vehicleCapacity,
                                             Integer defaultGlassLength) {
                                             int glassGap,
                                             String deviceId) {
        List<GlassInfo> planned = new ArrayList<>();
        int usedLength = 0;
        int capacity = Math.max(vehicleCapacity, 1);
        int fallbackLength = defaultGlassLength != null && defaultGlassLength > 0 ? defaultGlassLength : 2000;
        int gap = Math.max(glassGap, 0); // 确保间隔不为负数
        for (GlassInfo info : source) {
            int length = info.getLength() != null && info.getLength() > 0 ? info.getLength() : fallbackLength;
            Integer glassLength = info.getLength();
            if (glassLength == null || glassLength <= 0) {
                // 玻璃没有长度,直接报错(用于测试MES程序)
                log.error("玻璃[{}]缺少长度数据,无法进行容量计算。deviceId={},请检查MES程序是否正确提供玻璃长度。",
                        info.getGlassId(), deviceId);
                return null;
            }
            int length = glassLength;
            if (planned.isEmpty()) {
                // 第一块玻璃,不需要间隙
                planned.add(info.withLength(length));
                usedLength = length;
                continue;
            }
            if (usedLength + length <= capacity) {
            // 后续玻璃需要考虑间隙:玻璃长度 + 间隙
            int requiredLength = length + gap;
            if (usedLength + requiredLength <= capacity) {
                planned.add(info.withLength(length));
                usedLength += length;
                usedLength += requiredLength; // 包含间隙
            } else {
                // 装不下了,停止添加
                break;
            }
        }
        log.debug("玻璃装载规划: deviceId={}, total={}, planned={}, usedLength={}, capacity={}, glassGap={}",
                deviceId, source.size(), planned.size(), usedLength, capacity, gap);
        return planned;
    }
@@ -1269,15 +1415,19 @@
        // 这里简化处理:如果startSlot不在positionMapping中,且是数字,可能是格子编号
        // 可以通过配置指定格子编号范围,或者通过查找同组设备判断
        
        // 方法3:通过配置指定出片任务的startSlot范围
        // 方法3:通过配置指定车辆运动格子范围(兼容旧配置outboundSlotRanges)
        @SuppressWarnings("unchecked")
        List<Integer> outboundSlotRanges = getLogicParam(logicParams, "outboundSlotRanges", null);
        if (outboundSlotRanges != null && !outboundSlotRanges.isEmpty()) {
            // 如果配置了出片slot范围,检查startSlot是否在范围内
            // 例如:[1, 101] 表示格子1~101都是出片任务
            if (outboundSlotRanges.size() >= 2) {
                int minSlot = outboundSlotRanges.get(0);
                int maxSlot = outboundSlotRanges.get(1);
        List<Integer> vehicleSlotRange = getLogicParam(logicParams, "vehicleSlotRange", null);
        if (vehicleSlotRange == null || vehicleSlotRange.isEmpty()) {
            // 兼容旧配置
            vehicleSlotRange = getLogicParam(logicParams, "outboundSlotRanges", null);
        }
        if (vehicleSlotRange != null && !vehicleSlotRange.isEmpty()) {
            // 如果配置了车辆运动格子范围,检查startSlot是否在范围内
            // 例如:[1, 101] 表示车辆只能在格子1~101之间运动
            if (vehicleSlotRange.size() >= 2) {
                int minSlot = vehicleSlotRange.get(0);
                int maxSlot = vehicleSlotRange.get(1);
                if (startSlot >= minSlot && startSlot <= maxSlot) {
                    return true;
                }
@@ -1361,6 +1511,25 @@
     */
    private TimeCalculation calculateTime(Integer currentPos, Integer startPos, 
                                          Integer targetPos, Map<String, Object> logicParams) {
        // 验证车辆运动格子范围
        @SuppressWarnings("unchecked")
        List<Integer> vehicleSlotRange = getLogicParam(logicParams, "vehicleSlotRange", null);
        if (vehicleSlotRange == null || vehicleSlotRange.isEmpty()) {
            // 兼容旧配置
            vehicleSlotRange = getLogicParam(logicParams, "outboundSlotRanges", null);
        }
        if (vehicleSlotRange != null && vehicleSlotRange.size() >= 2) {
            int minSlot = vehicleSlotRange.get(0);
            int maxSlot = vehicleSlotRange.get(1);
            // 验证startPos和targetPos是否在允许的范围内
            if (startPos != null && (startPos < minSlot || startPos > maxSlot)) {
                log.warn("起始位置 {} 超出车辆运动格子范围 [{}, {}]", startPos, minSlot, maxSlot);
            }
            if (targetPos != null && (targetPos < minSlot || targetPos > maxSlot)) {
                log.warn("目标位置 {} 超出车辆运动格子范围 [{}, {}]", targetPos, minSlot, maxSlot);
            }
        }
        // 获取速度(格/秒,grid/s)
        Double speed = getLogicParam(logicParams, "vehicleSpeed", 1.0);
        if (speed == null || speed <= 0) {
@@ -1547,65 +1716,80 @@
            log.info("已给MES汇报({}任务): deviceId={}, glassId={}", 
                    taskType, deviceConfig.getDeviceId(), taskInfo.glassId);
            
            // 等待MES确认
            waitForMesConfirm(deviceConfig, serializer, taskInfo, logicParams);
            // 多设备任务场景下,不在这里阻塞等待MES确认,由任务引擎定时调用checkMesConfirm
        } catch (Exception e) {
            log.error("给MES汇报异常: deviceId={}", deviceConfig.getDeviceId(), e);
        }
    }
    /**
     * 等待MES确认
     * 检查MES确认状态(供任务引擎周期性调用)
     * 返回OperationResult.data中的 completed 标志表示是否已确认完成
     */
    private void waitForMesConfirm(DeviceConfig deviceConfig,
                                  EnhancedS7Serializer serializer,
                                  MesTaskInfo taskInfo,
                                  Map<String, Object> logicParams) {
    public DevicePlcVO.OperationResult checkMesConfirm(DeviceConfig deviceConfig,
                                                       Map<String, Object> logicParams) {
        if (plcDynamicDataService == null || s7SerializerProvider == null) {
            return DevicePlcVO.OperationResult.builder()
                    .success(false)
                    .message("PlcDynamicDataService或S7SerializerProvider未注入")
                    .build();
        }
        EnhancedS7Serializer serializer = s7SerializerProvider.getSerializer(deviceConfig);
        if (serializer == null) {
            return DevicePlcVO.OperationResult.builder()
                    .success(false)
                    .message("获取PLC序列化器失败")
                    .build();
        }
        Map<String, Object> data = new HashMap<>();
        try {
            // 读取确认字(假设字段名为mesConfirm)
            Integer maxWaitTime = getLogicParam(logicParams, "mesConfirmTimeoutMs", 30000); // 默认30秒
            long startTime = System.currentTimeMillis();
            while (System.currentTimeMillis() - startTime < maxWaitTime) {
                Object confirmValue = plcDynamicDataService.readPlcField(
                        deviceConfig, "mesConfirm", serializer);
                Integer confirm = parseInteger(confirmValue);
                if (confirm != null && confirm == 1) {
                    // MES已确认,清空state和汇报字
                    clearTaskStates(deviceConfig, serializer);
                    // 任务完成,恢复为空闲状态
                    statusManager.updateVehicleStatus(
                            deviceConfig.getDeviceId(), VehicleState.IDLE);
                    statusManager.clearVehicleTask(deviceConfig.getDeviceId());
                    // 移除任务
                    currentTasks.remove(deviceConfig.getDeviceId());
                    // 停止任务监控
                    handleStopTaskMonitor(deviceConfig);
                    // 恢复plcRequest=1(可以接收新任务)
                    Map<String, Object> payload = new HashMap<>();
                    payload.put("plcRequest", 1);
                    plcDynamicDataService.writePlcData(deviceConfig, payload, serializer);
                    log.info("MES任务已完成: deviceId={}, glassId={}",
                            deviceConfig.getDeviceId(), taskInfo.glassId);
                    return;
                }
                Thread.sleep(500); // 等待500ms后重试
            Object confirmValue = plcDynamicDataService.readPlcField(
                    deviceConfig, "mesConfirm", serializer);
            Integer confirm = parseInteger(confirmValue);
            boolean completed = confirm != null && confirm == 1;
            data.put("completed", completed);
            if (completed) {
                // MES已确认,清空state和汇报字
                clearTaskStates(deviceConfig, serializer);
                // 任务完成,恢复为空闲状态
                statusManager.updateVehicleStatus(
                        deviceConfig.getDeviceId(), VehicleState.IDLE);
                statusManager.clearVehicleTask(deviceConfig.getDeviceId());
                // 移除任务记录(如果有)
                currentTasks.remove(deviceConfig.getDeviceId());
                // 停止任务监控
                handleStopTaskMonitor(deviceConfig);
                // 恢复plcRequest=1(可以接收新任务)
                Map<String, Object> payload = new HashMap<>();
                payload.put("plcRequest", 1);
                plcDynamicDataService.writePlcData(deviceConfig, payload, serializer);
                log.info("MES任务已确认完成: deviceId={}", deviceConfig.getDeviceId());
                return DevicePlcVO.OperationResult.builder()
                        .success(true)
                        .message("MES任务已确认完成")
                        .data(data)
                        .build();
            }
            log.warn("等待MES确认超时: deviceId={}, glassId={}",
                    deviceConfig.getDeviceId(), taskInfo.glassId);
            return DevicePlcVO.OperationResult.builder()
                    .success(true)
                    .message("等待MES确认中")
                    .data(data)
                    .build();
        } catch (Exception e) {
            log.error("等待MES确认异常: deviceId={}", deviceConfig.getDeviceId(), e);
            log.error("检查MES确认状态异常: deviceId={}", deviceConfig.getDeviceId(), e);
            return DevicePlcVO.OperationResult.builder()
                    .success(false)
                    .message("检查MES确认状态异常: " + e.getMessage())
                    .data(data)
                    .build();
        }
    }
@@ -1715,5 +1899,25 @@
            Thread.currentThread().interrupt();
        }
    }
    /**
     * 通知卧转立扫码设备暂停或继续
     * @param params 参数,包含_taskContext引用
     * @param pause true=暂停,false=继续
     */
    private void notifyScannerPause(Map<String, Object> params, boolean pause) {
        if (params == null) {
            return;
        }
        Object contextObj = params.get("_taskContext");
        if (contextObj instanceof TaskExecutionContext) {
            TaskExecutionContext context = (TaskExecutionContext) contextObj;
            HorizontalScannerLogicHandler.setPauseFlag(context, pause);
            log.info("已通知卧转立扫码设备{}: pause={}", pause ? "暂停" : "继续", pause);
        } else {
            log.debug("未找到TaskExecutionContext,无法通知卧转立扫码设备暂停");
        }
    }
}