xiazhengtongxue
2026-04-07 b0b5deb5825684bca5b3fa7c2ab59f60ce0e799f
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/Partial/SCExecutionBlock.cs
@@ -51,8 +51,31 @@
                }
                if (shallowLocation.LocationStatus == (int)LocationStatusEnum.Free) return content.OK();
                //判断是否有移库任务
                //判断当前浅货位是否有出库任务
                var OutTask = _taskService.GeOutCuTaskQueue(shallowLocation.LocationCode);
                if (OutTask != null)
                {
                    //进行下发给堆垛机任务
                    WCSginseng outresult = _taskService.SC_IssueTasks(OutTask.TaskId, int.Parse(OutTask.Roadway), OutTask.TaskNum, OutTask.PalletCode, int.Parse(OutTask.PalletType), OutTask.CurrentAddress, OutTask.NextAddress, OutTask.TargetAddress);
                    if (outresult.IsSuccess)
                    {
                        OutTask.TaskStatus = (int)OutTaskStatusEnum.SC_OutExecuting;
                        OutTask.Dispatchertime = DateTime.Now;
                        _taskService.UpdateData(OutTask);
                        return content.OK();
                    }
                    else
                    {
                        UpdateTaskStatus(dt_Task, outresult,0, 1);
                        return content.Error($"下发wcs失败,原因:{outresult.Message}");
                    }
                }
                //判断是否有移库任务
                var TransferTask = _taskService.GeRelocationTaskQueue(shallowLocation.LocationCode);
                if (TransferTask != null)
                {
@@ -61,13 +84,13 @@
                    if (result.IsSuccess)
                    {
                        TransferTask.TaskStatus = (int)RelocationTaskStatusEnum.RelocationExecuting;
                        TransferTask.Dispatchertime = DateTime.Now;
                        _taskService.UpdateData(TransferTask);
                        return content.OK();
                    }
                    else
                    {
                        UpdateTaskStatus(dt_Task, result,
                        successStatus: dt_Task.TaskStatus == (int)InTaskStatusEnum.PLC_InFinish ? (int)InTaskStatusEnum.SC_IntExecuting : (int)OutTaskStatusEnum.SC_OutExecuting, 1);
                        UpdateTaskStatus(dt_Task, result,0,1);  //默认不需要更改状态传0
                        return content.Error($"下发wcs失败,原因:{result.Message}");
                    }
@@ -78,7 +101,7 @@
                if (CuttTransferTask) return content.Error("当前有移库任务,不可下发");
                if (shallowLocation.LocationStatus != (int)LocationStatusEnum.InStock) return content.Error();
                if (shallowLocation.LocationStatus != (int)LocationStatusEnum.InStock) return content.Error($"库位状态异常,当前状态:{(LocationStatusEnum)shallowLocation.LocationStatus},应为:{LocationStatusEnum.InStock}");
                //生成移库任务
                return content = GenerateTransferTask(shallowLocation.LocationCode);
@@ -91,6 +114,7 @@
        }
        //生成移库任务
        public WebResponseContent GenerateTransferTask(string shallowLocation)
        {
            WebResponseContent webResponse = new WebResponseContent();
@@ -100,44 +124,59 @@
                Dt_StockInfo dt_StockInfo = _stockInfoService.Repository.QueryData(x => x.LocationCode == shallowLocation).FirstOrDefault();
                Dt_LocationInfo newLocation = _locationInfoService.GetLocation(OriginalLocation.RoadwayNo, OriginalLocation.LocationType);
                List<Dt_LocationInfo> dt_Locations = new List<Dt_LocationInfo>();
                var TransferTask = _taskService.GeRelocationTaskQueue(shallowLocation);
                MES_parameter mES_Parame = _taskService.ApplicationChangeStorageLocation(dt_StockInfo.PalletCode, OriginalLocation.LocationCode, newLocation.LocationCode);
                if (mES_Parame != null)
                {
                    if (mES_Parame.Result == "Y")
                    {
                        //进行生成任务,下发任务至MES
                        Dt_Task task = new Dt_Task();
                        task.TaskNum = $"REL{DateTime.Now:yyyyMMddHHmmss}{new Random().Next(1000, 9999)}";
                        //task.TaskNum = "0";
                        task.PalletCode = dt_StockInfo.PalletCode;
                        task.PalletType = dt_StockInfo.PalletType;
                        task.Roadway = OriginalLocation.RoadwayNo;
                        task.TaskType = (int)TaskTypeEnum.Relocation;
                        task.TaskStatus = (int)RelocationTaskStatusEnum.RelocationNew;
                        task.SourceAddress = OriginalLocation.LocationCode;
                        task.TargetAddress = newLocation.LocationCode;
                        task.CurrentAddress = OriginalLocation.LocationCode;
                        task.NextAddress = newLocation.LocationCode;
                        task.WarehouseId = OriginalLocation.WarehouseId;
                        task.OrderNo = "";
                        task.Grade = 1;
                        task.Creater = "MES";
                        task.CreateDate = DateTime.Now;
                        OriginalLocation.LocationStatus = (int)LocationStatusEnum.Lock;
                        newLocation.LocationStatus = (int)LocationStatusEnum.Lock;
                        dt_StockInfo.StockStatus = (int)StockStatusEmun.移库锁定;
                        dt_Locations.Add(OriginalLocation);
                        dt_Locations.Add(newLocation);
                        _unitOfWorkManage.BeginTran();
                //进行生成任务,下发任务至MES
                Dt_Task task = new Dt_Task();
                task.TaskNum = "0";
                task.PalletCode = dt_StockInfo.PalletCode;
                task.PalletType = dt_StockInfo.PalletType;
                task.Roadway = OriginalLocation.RoadwayNo;
                task.TaskType = (int)TaskTypeEnum.Relocation;
                task.TaskStatus = (int)RelocationTaskStatusEnum.RelocationNew;
                task.SourceAddress = OriginalLocation.LocationCode;
                task.TargetAddress = newLocation.LocationCode;
                task.CurrentAddress = OriginalLocation.LocationCode;
                task.NextAddress = newLocation.LocationCode;
                task.WarehouseId = OriginalLocation.WarehouseId;
                task.OrderNo = "";
                task.Grade = 1;
                task.Creater = "MES";
                task.CreateDate = DateTime.Now;
                        int TaskId = _taskService.Repository.AddData(task);
                        _locationInfoService.UpdateData(dt_Locations);
                        _stockInfoService.UpdateData(dt_StockInfo);
                        _unitOfWorkManage.CommitTran();
                        return webResponse.Error("已生成移库任务");
                    }
                    else
                    {
                OriginalLocation.LocationStatus = (int)LocationStatusEnum.Lock;
                newLocation.LocationStatus = (int)LocationStatusEnum.Lock;
                dt_StockInfo.StockStatus = (int)StockStatusEmun.移库锁定;
                        WriteLog.Write_Log("WMS_移库故障", $"EMS申请储位异动返回失败内容", "失败", $"MES不允许移动====>>>>返回内容:{mES_Parame.ToJson()}");
                        return webResponse.Error($"申请储位异动,MES不允许移动====>>>>返回内容:{mES_Parame.ToJson()}");
                    }
                }
                else
                {
                    WriteLog.Write_Log("WMS_移库故障", $"EMS申请储位异动返回失败内容", "失败", $"申请储位异动,MES返回为空");
                    return webResponse.Error("申请储位异动,MES返回为空");
                }
                dt_Locations.Add(OriginalLocation);
                dt_Locations.Add(newLocation);
                _unitOfWorkManage.BeginTran();
                int TaskId = _taskService.Repository.AddData(task);
                _locationInfoService.UpdateData(dt_Locations);
                _stockInfoService.UpdateData(dt_StockInfo);
                _unitOfWorkManage.CommitTran();
                return webResponse.Error("已生成移库任务");
                //进行下发给堆垛机任务
                /*WCSginseng result = _taskService.SC_IssueTasks(
                    TaskId,
@@ -160,7 +199,7 @@
                    return webResponse.Error($"下发移库失败,原因:{result.Message}");
                }*/
                /*MES_parameter mES_Parame = _taskService.ApplicationChangeStorageLocation(dt_StockInfo.PalletCode, OriginalLocation.LocationCode, newLocation.LocationCode);
                /* MES_parameter mES_Parame = _taskService.ApplicationChangeStorageLocation(dt_StockInfo.PalletCode, OriginalLocation.LocationCode, newLocation.LocationCode);
                if (mES_Parame != null)
                {
                    if (mES_Parame.Result == "Y")