wanshenmean
昨天 05999b9c77f009ac9a7e98366bc3d23fbb8e83e7
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/Workflow/RobotWorkflowOrchestrator.cs
@@ -118,7 +118,7 @@
                // - 手臂上有物料(RobotArmObject == 1)
                // - 任务状态为 RobotPickFinish(已记录取货完成)
                if ((latestState.CurrentAction == "PickFinished" || latestState.CurrentAction == "AllPickFinished")
                    && (latestState.RobotArmObject.IsNullOrEmpty() || latestState.RobotArmObject == 1)
                    //&& (latestState.RobotArmObject.IsNullOrEmpty() || latestState.RobotArmObject == 1)
                    && task.RobotTaskState == TaskRobotStatusEnum.RobotPickFinish.GetHashCode())
                {
                    QuartzLogHelper.LogInfo(_logger, $"ExecuteAsync:满足放货条件,开始下发放货任务,任务号: {task.RobotTaskNum}", latestState.RobotCrane?.DeviceName ?? ipAddress);
@@ -133,7 +133,7 @@
                // - 手臂上无物料(RobotArmObject == 0)
                // - 任务状态为 RobotPutFinish 或不是 RobotExecuting
                else if ((latestState.CurrentAction == "PutFinished" || latestState.CurrentAction == "AllPutFinished" || latestState.CurrentAction.IsNullOrEmpty())
                    && (latestState.RobotArmObject.IsNullOrEmpty() || latestState.RobotArmObject == 0)
                    //&& (latestState.RobotArmObject.IsNullOrEmpty() || latestState.RobotArmObject == 0)
                    && (task.RobotTaskState == TaskRobotStatusEnum.RobotPutFinish.GetHashCode() || task.RobotTaskState != TaskRobotStatusEnum.RobotExecuting.GetHashCode()))
                {
                    QuartzLogHelper.LogInfo(_logger, $"ExecuteAsync:满足取货条件,开始下发取货任务,任务号: {task.RobotTaskNum}", latestState.RobotCrane?.DeviceName ?? ipAddress);
@@ -168,6 +168,9 @@
                int currentCompletedCount = state?.RobotTaskTotalNum ?? 0;
                bool isFlowA = task.RobotSourceAddressLineCode is "11001" or "11010";
                await _taskProcessor.SendSocketRobotNumAsync(task, state, false);
                Thread.Sleep(500);
                // ==================== Phase 2: 放正常电芯到目标托盘(两流向相同)====================
                // PickFinished 到达:Phase 1 的 Pick 命令完成,现在下发 Put 命令放正常电芯
@@ -239,8 +242,6 @@
                    return;
                }
                // 非批次模式或其他阶段不下发指令
                return;
            }
            // 非换盘任务:使用原有格式
@@ -273,7 +274,7 @@
                    if (_stateManager.TryUpdateStateSafely(ipAddress, stateToUpdate))
                    {
                        await _robotTaskService.UpdateRobotTaskAsync(task);
                        //await _robotTaskService.UpdateRobotTaskAsync(task);
                    }
                }
            }
@@ -337,17 +338,23 @@
                // 如果条码生成成功
                if (!string.IsNullOrEmpty(trayBarcode1) && !string.IsNullOrEmpty(trayBarcode2))
                {
                    if (stateForUpdate.CellBarcode.Contains(trayBarcode1) || stateForUpdate.CellBarcode.Contains(trayBarcode2))
                    {
                        QuartzLogHelper.LogInfo(_logger, $"HandlePutFinishedStateAsync:读取的托盘条码已存在,可能存在重复,任务号: {task.RobotTaskNum}", stateForUpdate?.RobotCrane?.DeviceName ?? ipAddress);
                    //if (stateForUpdate.CellBarcode.Contains(trayBarcode1) || stateForUpdate.CellBarcode.Contains(trayBarcode2))
                    //{
                    //    QuartzLogHelper.LogInfo(_logger, $"HandlePutFinishedStateAsync:读取的电芯条码已存在,可能存在重复,任务号: {task.RobotTaskNum}", stateForUpdate?.RobotCrane?.DeviceName ?? ipAddress);
                        // 发送取货指令 标记扫码NG,放货时不使用这些条码,并放入NG口
                        //await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate, true);
                        return;
                    }
                    else
                    //    // 发送取货指令 标记扫码NG,放货时不使用这些条码,并放入NG口
                    //    //await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate, true);
                    //    return;
                    //}
                    //else
                    {
                        QuartzLogHelper.LogInfo(_logger, $"HandlePutFinishedStateAsync:读取的托盘条码唯一,继续执行,任务号: {task.RobotTaskNum}", stateForUpdate?.RobotCrane?.DeviceName ?? ipAddress);
                        if (trayBarcode1.Length < 13 || trayBarcode2.Length < 13)
                        {
                            QuartzLogHelper.LogError(_logger, $"HandlePutFinishedStateAsync:电芯条码长度不达标,任务号: {task.RobotTaskNum},读取电芯条码成功: 【{trayBarcode1}】-----【{trayBarcode2}】", stateForUpdate?.RobotCrane?.DeviceName ?? ipAddress);
                            return;
                        }
                        QuartzLogHelper.LogInfo(_logger, $"HandlePutFinishedStateAsync:读取的电芯条码唯一,继续执行,任务号: {task.RobotTaskNum}", stateForUpdate?.RobotCrane?.DeviceName ?? ipAddress);
                        // 将条码添加到状态中,供后续放货时使用
                        stateForUpdate.CellBarcode = new List<string>()
@@ -357,7 +364,7 @@
                    }
                    // 记录日志:读取托盘条码成功
                    QuartzLogHelper.LogInfo(_logger, $"HandlePutFinishedStateAsync:读取托盘条码成功: 【{trayBarcode1}】-----【{trayBarcode2}】,任务号: {task.RobotTaskNum}", stateForUpdate?.RobotCrane?.DeviceName ?? ipAddress);
                    QuartzLogHelper.LogInfo(_logger, $"HandlePutFinishedStateAsync:读取电芯条码成功: 【{trayBarcode1}】-----【{trayBarcode2}】,任务号: {task.RobotTaskNum}", stateForUpdate?.RobotCrane?.DeviceName ?? ipAddress);
                    // 发送取货指令
                    await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate);
@@ -383,8 +390,11 @@
                // 判断流向(null-safe)
                bool isFlowA = task.RobotSourceAddressLineCode is "11001" or "11010";
                await _taskProcessor.SendSocketRobotNumAsync(task, stateForUpdate);
                Thread.Sleep(500);
                // 目标数量为48:直接走原有逻辑,不进入批次模式
                if (targetNormalCount == targetTotal)
                if (targetNormalCount + currentCompletedCount == targetTotal)
                {
                    await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate);
                    return;