Admin
2 天以前 679893ee68e2f7d422431bb22b665e9217f23410
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Location/LocationInfoService.cs
@@ -84,18 +84,21 @@
                // èŽ·å–æ–°çš„åº“ä½çš„ä»»åŠ¡
                var internalTransferTask = await _taskRepository.QueryFirstAsync(x => x.SourceAddress == newLocationID && x.Roadway == outboundTask.Roadway && x.TaskState == (int)TaskOutStatusEnum.OutNew);
                LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,获取新库位的任务", $"新库位任务:{internalTransferTask}");
                LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,未获取到新库位任务", $"");
                return await HandleNoTaskAtLocation(outboundTask.SourceAddress, newLocationID, outboundTask);
                // å¦‚果新的库位没有找到对应的任务
                if (internalTransferTask == null)
                /*if (internalTransferTask == null)
                {
                    LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,未获取到新库位任务", $"");
                    return await HandleNoTaskAtLocation(outboundTask.SourceAddress, newLocationID, outboundTask);
                }
                LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,获取到新库位任务直接返回", $"新库位任务:{internalTransferTask}");
                // ç›´æŽ¥è¿”回一深位出库任务
                return internalTransferTask;
                return internalTransferTask;*/
            }
            // è¿”回当前库位的出库任务
@@ -382,53 +385,70 @@
    /// <returns>生成的移库任务或原始出库任务</returns>
    private async Task<Dt_Task> HandleNoTaskAtLocation(string originalLocationID, string newLocationID, Dt_Task outboundTask)
    {
        // åˆ¤æ–­è¯¥ä½ç½®æ˜¯å¦æœ‰åº“å­˜
        var stockInfo = await _WheelsStockRepository.QueryFirstAsync(x => x.Wheels_Location == newLocationID);
        // åˆ¤æ–­è¯¥ä½ç½®æ˜¯å¦æœ‰åº“å­˜
        var zdpInfo = await _zdpStockRepository.QueryFirstAsync(x => x.Zdp_Location == newLocationID);
        LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,未获取到新库位任务", $"该位置是否有库存:{stockInfo}");
        if (stockInfo == null && zdpInfo==null)
        try
        {
            LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,未获取到库存数据", $"直接返回原先出库任务:{outboundTask}");
            // å¦‚果没有库存,直接返回当前出库任务
            return outboundTask;
        }
        else
        {
            // å¦‚果有库存,生成移库任务
            var emptyLocation = RequestLocation("SC1");
            if (emptyLocation == null) throw new Exception("暂无空库");
            // åˆ¤æ–­è¯¥ä½ç½®æ˜¯å¦æœ‰åº“å­˜
            var stockInfo = await _WheelsStockRepository.QueryFirstAsync(x => x.Wheels_Location == newLocationID);
            LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,查找能移库货位", $"货位数据:{emptyLocation}");
            var taskNo = await _taskRepository.GetTaskNo();
            Dt_Task newTransferTask = new Dt_Task()
            // åˆ¤æ–­è¯¥ä½ç½®æ˜¯å¦æœ‰åº“å­˜
            var zdpInfo = await _zdpStockRepository.QueryFirstAsync(x => x.Zdp_Location == newLocationID);
            LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "获取的库存信息", $"根据货位编号:{newLocationID},该位置是否有库存:{stockInfo.ToJson()}");
            if (stockInfo == null && zdpInfo == null)
            {
                CreateDate = DateTime.Now,
                Creater = App.User.UserName == null ? "admin" : App.User.UserName,
                CurrentAddress = stockInfo != null ?stockInfo.Wheels_Location: zdpInfo.Zdp_Location,
                Grade = 99,
                MaterialNo = stockInfo != null ? stockInfo.Wheels_Type: "2",
                NextAddress = emptyLocation.LocationCode,
                PalletCode = stockInfo != null ? stockInfo.Wheels_Num : zdpInfo.Zdp_code,
                Remark = "移库",
                Roadway = "SC1",
                SourceAddress = stockInfo != null ? stockInfo.Wheels_Location : zdpInfo.Zdp_Location,
                TaskNum = taskNo,
                TargetAddress = emptyLocation.LocationCode,
                TaskState = (int)TaskStatus.Created,
                TaskType = (int)TaskTypeEnum.Relocation,
                Dispatchertime = DateTime.Now,
            };
            LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,新建移库任务", $"移库任务数据:{newTransferTask}");
                LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,未获取到库存数据", $"直接返回原先出库任务:{outboundTask}");
                // å¦‚果没有库存,直接返回当前出库任务
                return outboundTask;
            }
            else
            {
                // å¦‚果有库存,生成移库任务
                var emptyLocation = RequestLocation("SC1");
                if (emptyLocation == null) throw new Exception("暂无空库");
            //修改库位状态
            emptyLocation.LocationStatus = (int)LocationEnum.FreeDisable;
            BaseDal.UpdateData(emptyLocation);
                LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,查找能移库货位", $"货位数据:{emptyLocation}");
                var taskNo = await _taskRepository.GetTaskNo();
                Dt_Task newTransferTask = new Dt_Task()
                {
                    CreateDate = DateTime.Now,
                    Creater = App.User.UserName == null ? "admin" : App.User.UserName,
                    CurrentAddress = stockInfo != null ? stockInfo.Wheels_Location : zdpInfo.Zdp_Location,
                    Grade = 99,
                    MaterialNo = stockInfo != null ? stockInfo.Wheels_Type : "2",
                    NextAddress = emptyLocation.LocationCode,
                    PalletCode = stockInfo != null ? stockInfo.Wheels_Num : zdpInfo.Zdp_code,
                    Remark = "移库",
                    Roadway = "SC1",
                    SourceAddress = stockInfo != null ? stockInfo.Wheels_Location : zdpInfo.Zdp_Location,
                    TaskNum = taskNo,
                    TargetAddress = emptyLocation.LocationCode,
                    TaskState = (int)TaskStatus.Created,
                    TaskType = (int)TaskTypeEnum.Relocation,
                    Dispatchertime = DateTime.Now,
                };
                LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,新建移库任务", $"移库任务数据:{newTransferTask.ToJson()}");
            return await _taskRepository.Create(newTransferTask);
                // èŽ·å–æ–°çš„åº“ä½çš„ä»»åŠ¡
                var internalTransferTask = await _taskRepository.QueryFirstAsync(x => x.SourceAddress == newLocationID && x.Roadway == outboundTask.Roadway && x.TaskState == (int)TaskOutStatusEnum.OutNew);
                if (internalTransferTask != null)
                {
                    internalTransferTask.SourceAddress = emptyLocation.LocationCode;
                    internalTransferTask.CurrentAddress = emptyLocation.LocationCode;
                    await _taskRepository.Update(internalTransferTask);
                }
                //修改库位状态
                emptyLocation.LocationStatus = (int)LocationEnum.FreeDisable;
                BaseDal.UpdateData(emptyLocation);
                return await _taskRepository.Create(newTransferTask);
            }
        }
        catch (Exception ex)
        {
            LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "方法:HandleNoTaskAtLocation", $"出错,原因:{ex.ToJson()}");
            throw;
        }
    }