刘磊
2024-12-24 e2bb2738c6ddb1d013837924dc639b0f6f63662b
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
@@ -163,105 +163,121 @@
    private async Task<Dt_Task> CreateInToOutTaskAsync(RequestTaskDto input, Dt_StationManager stationManager)
    {
        //if (stationManager.stationType != 5) throw new Exception("错误的调取");
        input.EquiCodeMOM = "24MEJQ11-1006-1";
        // 创建一个TrayCellsStatusDto对象,并赋值
        TrayCellsStatusDto trayCells = new TrayCellsStatusDto()
        try
        {
            Software = "WMS",
            TrayBarcode = input.PalletCode,
            //EquipmentCode = "EQ_CWJZ01"
            EquipmentCode = input.EquiCodeMOM
        };
            //if (stationManager.stationType != 5) throw new Exception("错误的调取");
        // 调用GetTrayCellStatusAsync方法,获取整盘电芯
        WebResponseContent content = await GetTrayCellStatusAsync(trayCells);
        // 如果状态为false,则返回content
        if (!content.Status) throw new Exception(content.Message);
            input.EquiCodeMOM = "24MEJQ11-1006-1";
        // 添加组盘信息
        // 将content.Data转换为ResultTrayCellsStatus对象
        var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString());
        if (result.SerialNos.Count <= 0)
        {
            ConsoleHelper.WriteErrorLine(result.MOMMessage);
            if (stationManager.stationType != 3)
            // 创建一个TrayCellsStatusDto对象,并赋值
            TrayCellsStatusDto trayCells = new TrayCellsStatusDto()
            {
                var taskNG = new Dt_Task
                Software = "WMS",
                TrayBarcode = input.PalletCode,
                //EquipmentCode = "EQ_CWJZ01"
                EquipmentCode = input.EquiCodeMOM
            };
            // 调用GetTrayCellStatusAsync方法,获取整盘电芯
            WebResponseContent content = await GetTrayCellStatusAsync(trayCells);
            // 如果状态为false,则返回content
            if (!content.Status) throw new Exception(content.Message);
            // 组盘信息
            // 将content.Data转换为ResultTrayCellsStatus对象
            var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString());
            if (result.SerialNos.Count <= 0)
            {
                ConsoleHelper.WriteErrorLine(result.MOMMessage);
                if (stationManager.stationType != 3)
                {
                    CurrentAddress = input.Position,
                    Grade = 3,
                    Roadway = input.Roadways,
                    TargetAddress = stationManager.stationNGLocation,
                    Dispatchertime = DateTime.Now,
                    MaterialNo = "",
                    NextAddress = stationManager.stationNGChildCode,
                    OrderNo = null,
                    PalletCode = input.PalletCode,
                    SourceAddress = stationManager.stationLocation,
                    TaskState = (int)TaskInStatusEnum.Line_InFinish,
                    TaskType = (int)TaskOutboundTypeEnum.InToOut,
                    TaskNum = await BaseDal.GetTaskNo(),
                    Creater = "Systeam"
                };
                return taskNG;
            }
            else
            {
                return null;
            }
        }
        // 处理异常电芯情况
        var serialNosError = result.SerialNos.Where(x => x.SerialNoStatus != 1).ToList();
        if (serialNosError.Count > 0)
        {
            if (stationManager.stationType != 3)
            {
                var taskNG = new Dt_Task
                    var taskNG = new Dt_Task
                    {
                        CurrentAddress = input.Position,
                        Grade = 3,
                        Roadway = input.Roadways,
                        TargetAddress = stationManager.stationNGLocation,
                        Dispatchertime = DateTime.Now,
                        MaterialNo = "",
                        NextAddress = stationManager.stationNGChildCode,
                        OrderNo = null,
                        PalletCode = input.PalletCode,
                        SourceAddress = stationManager.stationLocation,
                        TaskState = (int)TaskInStatusEnum.Line_InFinish,
                        TaskType = (int)TaskOutboundTypeEnum.InToOut,
                        TaskNum = await BaseDal.GetTaskNo(),
                        Creater = "Systeam"
                    };
                    return taskNG;
                }
                else
                {
                    CurrentAddress = input.Position,
                    Grade = 1,
                    Roadway = input.Roadways,
                    TargetAddress = stationManager.stationNGLocation,
                    Dispatchertime = DateTime.Now,
                    MaterialNo = "",
                    NextAddress = stationManager.stationNGChildCode,
                    OrderNo = null,
                    PalletCode = input.PalletCode,
                    SourceAddress = stationManager.stationLocation,
                    TaskState = (int)TaskInStatusEnum.Line_InFinish,
                    TaskType = (int)TaskOutboundTypeEnum.OutNG,
                    TaskNum = await BaseDal.GetTaskNo(),
                    Creater = "Systeam"
                };
                return taskNG;
                    //无电芯 → 当空框? 还是返回异常?
                    return null;
                }
            }
            // 处理异常电芯情况
            var serialNosError = result.SerialNos.Where(x => x.SerialNoStatus != 1).ToList();
            if (serialNosError.Count > 0)
            {
                if (stationManager.stationType != 3)
                {
                    var taskNG = new Dt_Task
                    {
                        CurrentAddress = input.Position,
                        Grade = 1,
                        Roadway = input.Roadways,
                        TargetAddress = stationManager.stationNGLocation,
                        Dispatchertime = DateTime.Now,
                        MaterialNo = "",
                        NextAddress = stationManager.stationNGChildCode,
                        OrderNo = null,
                        PalletCode = input.PalletCode,
                        SourceAddress = stationManager.stationLocation,
                        TaskState = (int)TaskInStatusEnum.Line_InFinish,
                        TaskType = (int)TaskOutboundTypeEnum.InToOut,
                        TaskNum = await BaseDal.GetTaskNo(),
                        Creater = "Systeam"
                    };
                    return taskNG;
                }
                else
                {
                    Console.WriteLine($"站台{stationManager.stationChildCode}MOM返回电芯异常:{result.MOMMessage}");
                    return null;
                }
            }
            //else
            //{
            //    throw new Exception($"站台{stationManager.stationChildCode}MOM返回电芯异常:{result.MOMMessage}");
            //}
            var targetStation = _stationManagerRepository.QueryFirst(x => x.stationPLC == stationManager.stationPLC && x.Roadway == stationManager.Roadway && x.stationType == 2);
            var task = new Dt_Task
            {
                CurrentAddress = input.Position,
                Grade = 3,
                Roadway = input.Roadways,
                TargetAddress = targetStation.stationLocation,
                Dispatchertime = DateTime.Now,
                MaterialNo = "",
                NextAddress = input.Roadways,
                OrderNo = null,
                PalletCode = input.PalletCode,
                SourceAddress = stationManager.stationLocation,
                TaskState = (int)TaskInStatusEnum.Line_InFinish,
                TaskType = (int)TaskOutboundTypeEnum.InToOut,
                TaskNum = await BaseDal.GetTaskNo(),
                Creater = "Systeam"
            };
            return task;
        }
        var targetStation = _stationManagerRepository.QueryFirst(x => x.stationPLC == stationManager.stationPLC && x.Roadway == stationManager.Roadway && x.stationType == 2);
        var task = new Dt_Task
        catch (Exception ex)
        {
            CurrentAddress = input.Position,
            Grade = 1,
            Roadway = input.Roadways,
            TargetAddress = targetStation.stationLocation,
            Dispatchertime = DateTime.Now,
            MaterialNo = "",
            NextAddress = input.Roadways,
            OrderNo = null,
            PalletCode = input.PalletCode,
            SourceAddress = stationManager.stationLocation,
            TaskState = (int)TaskInStatusEnum.Line_InFinish,
            TaskType = (int)TaskOutboundTypeEnum.InToOut,
            TaskNum = await BaseDal.GetTaskNo(),
            Creater = "Systeam"
        };
        return task;
            throw new Exception(ex.Message);
        }
    }
    #endregion 直接出库任务
@@ -521,7 +537,8 @@
        {
            //添加历史
            var taskHty = CreateHistoricalTask(task);
            // 添加历史任务
            var isTaskHtyAdd = await _task_HtyRepository.AddDataAsync(taskHty) > 0;
            //删除任务
            BaseDal.DeleteData(task);
@@ -578,7 +595,7 @@
                var Epmtytask = new Dt_Task
                {
                    CurrentAddress = input.Position,
                    Grade = 3,  //优先处理异常排出口的任务 防止正常需排出异常口的任务堵线
                    Grade = 4,  //优先处理异常排出口的任务 防止正常需排出异常口的任务堵线
                    Roadway = input.Roadways,
                    TargetAddress = EmptylocationInfo.LocationCode,
                    Dispatchertime = DateTime.Now,
@@ -846,20 +863,21 @@
        WebResponseContent content = new WebResponseContent();
        try
        {
            Dt_StationManager station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == json.Position);
            Dt_StationManager station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == json.Position && x.stationType == 12 && x.stationArea == "Call");
            DtStockInfo stockInfo = _stockInfoRepository.QueryFirst(X => X.IsFull && X.AreaCode == "CWSC3" && X.ProductionLine == station.productLine);
            if (stockInfo == null) throw new Exception("库内无满足条件的库存可出库");
            Dt_StationManager OutStation = _stationManagerRepository.QueryFirst(x => x.stationPLC == "1016" && x.stationType == 10);
            DtLocationInfo locationInfo = _locationRepository.QueryFirst(x => x.AreaId == 5 && x.LocationCode == stockInfo.LocationCode);
            Dt_StationManager OutStation = _stationManagerRepository.QueryFirst(x => x.stationPLC == "1016" && x.stationType == 10 && x.Roadway == locationInfo.RoadwayNo && x.stationStatus == "1");
            // 创建新任务实例
            var task = new Dt_Task
            {
                CurrentAddress = stockInfo.LocationInfo.RoadwayNo,
                CurrentAddress = locationInfo.RoadwayNo,
                Grade = 1,
                Roadway = stockInfo.LocationInfo.RoadwayNo,
                Roadway = locationInfo.RoadwayNo,
                TargetAddress = json.Position,
                Dispatchertime = DateTime.Now,
                MaterialNo = "",
@@ -880,6 +898,7 @@
        }
        catch (Exception ex)
        {
            Console.WriteLine($"CW3至包装出库异常:{ex.ToString()}");
            return content.Error($"失败:{ex.Message}");
        }
    }