刘磊
9 天以前 2de09bec5cc05bf875543fa8956167ca7db73021
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Location/LocationInfoService.cs
@@ -102,6 +102,62 @@
        }
    }
    /// <summary>
    /// æ£€æŸ¥å¹¶ç”Ÿæˆç§»åº“任务或返回入库任务
    /// </summary>
    /// <param name="locationID">任务号</param>
    /// <returns>任务对象</returns>
    public virtual async Task<Dt_Task> InTransferCheckAsync(RequestTaskDto input)
    {
        try
        {
            int taskNum = input.taskNum;
            // æ ¹æ®ä»»åŠ¡å·èŽ·å–å…¥åº“ä»»åŠ¡
            var inboundTask = await _taskRepository.QueryFirstAsync(x => x.TaskNum == taskNum);
            if (inboundTask == null)
                return null;
            LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "根据任务号获取任务", $"任务号:{taskNum},任务数据:{inboundTask}");
            var location = await BaseDal.QueryFirstAsync(x => x.LocationCode == inboundTask.TargetAddress);
            LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "获取指定库位的货位数据", $"货位号:{inboundTask.TargetAddress},货位数据:{location}");
            // æ£€æŸ¥æ˜¯å¦éœ€è¦è¿›è¡Œç§»åº“
            if (CheckForInternalTransfer(location))
            {
                LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库", $"货位号:{inboundTask.TargetAddress},货位数据:{location}");
                // è®¡ç®—对应位置的相对库位 ï¼ˆå¥‡æ•°è¡Œçš„下一行或者偶数行的上一行)
                var newLocationID = GetRelativeLocationID(location);
                LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,组建需要移库货位号", $"新的库位ID:{newLocationID}");
                var relocationTask = await _taskRepository.QueryFirstAsync(x => x.TargetAddress == newLocationID && x.Roadway == inboundTask.Roadway && x.TaskType == (int)TaskTypeEnum.Relocation);
                if (relocationTask != null) return relocationTask;
                // èŽ·å–æ–°çš„åº“ä½çš„ä»»åŠ¡
                var internalTransferTask = await _taskRepository.QueryFirstAsync(x => x.TargetAddress == newLocationID && x.Roadway == inboundTask.Roadway && x.TaskState == (int)TaskOutStatusEnum.OutNew);
                LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,获取新库位的任务", $"新库位任务:{internalTransferTask}");
                // å¦‚果新的库位没有找到对应的任务
                if (internalTransferTask == null)
                {
                    LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,未获取到新库位任务", $"");
                    return await InHandleLocation(inboundTask.TargetAddress, newLocationID, inboundTask);
                }
                LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,获取到新库位任务直接返回", $"新库位任务:{internalTransferTask}");
                // ç›´æŽ¥è¿”回一深位出库任务
                return internalTransferTask;
            }
            // è¿”回当前库位的出库任务
            return inboundTask;
        }
        catch (Exception)
        {
            return null;
        }
    }
    public override WebResponseContent UpdateData(SaveModel saveModel)
    {
        int id = saveModel.MainData["id"].ObjToInt();
@@ -253,6 +309,32 @@
    #endregion å¯ç”¨ç¦ç”¨è´§ä½
    #region å¤§å±åº“位状态获取
    public WebResponseContent LocationStatus()
    {
        WebResponseContent content = new WebResponseContent();
        // èŽ·å–æ‰€æœ‰åº“ä½æ•°æ®
        List<DtLocationInfo> locations = BaseDal.QueryData();
        // æŒ‰LocationStatus分组统计
        var statusGroups = locations
            .GroupBy(l => l.LocationStatus)
            .Select(g => new
            {
                Status = g.Key==0?"空货位": g.Key == 1 ? "锁定": g.Key == 2 ? "有货": "有货禁用",
                Count = g.Count(),
            })
            .ToList();
        // å°†ç»Ÿè®¡ç»“果放入响应内容
        content.Data = statusGroups;
        return content;
    }
    #endregion
    #region å†…部方法
    #region ç§»åº“方法
@@ -331,6 +413,61 @@
    }
    /// <summary>
    /// å¤„理入库没有任务的库位情况
    /// </summary>
    /// <param name="originalLocationID">原始库位ID</param>
    /// <param name="newLocationID">新的库位ID</param>
    /// <param name="outboundTask">出库任务</param>
    /// <returns>生成的移库任务或原始出库任务</returns>
    private async Task<Dt_Task> InHandleLocation(string originalLocationID, string newLocationID, Dt_Task inboundTask)
    {
        // åˆ¤æ–­è¯¥ä½ç½®æ˜¯å¦æœ‰åº“å­˜
        var stockInfo = await _WheelsStockRepository.QueryFirstAsync(x => x.Wheels_Location == newLocationID);
        LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,未获取到新库位任务", $"该位置是否有库存:{stockInfo}");
        if (stockInfo == null)
        {
            LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,未获取到库存数据", $"直接返回原先出库任务:{inboundTask}");
            // å¦‚果没有库存,直接返回当前出库任务
            return inboundTask;
        }
        else
        {
            // å¦‚果有库存,生成移库任务
            var emptyLocation = RequestLocation("SC1");
            if (emptyLocation == null) throw new Exception("暂无空库");
            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.Wheels_Location,
                Grade = 99,
                MaterialNo = stockInfo.Wheels_Type,
                NextAddress = emptyLocation.LocationCode,
                PalletCode = stockInfo.Wheels_Num,
                Remark = "移库",
                Roadway = "SC1",
                SourceAddress = stockInfo.Wheels_Location,
                TaskNum = taskNo,
                TargetAddress = emptyLocation.LocationCode,
                TaskState = (int)TaskStatus.Created,
                TaskType = (int)TaskTypeEnum.Relocation,
                Dispatchertime = DateTime.Now,
            };
            LogFactory.GetLog("检查是否需要移库").InfoFormat(true, "需要移库,新建移库任务", $"移库任务数据:{newTransferTask}");
            //修改库位状态
            emptyLocation.LocationStatus = (int)LocationEnum.FreeDisable;
            BaseDal.UpdateData(emptyLocation);
            return await _taskRepository.Create(newTransferTask);
        }
    }
    /// <summary>
    /// æ ¹æ®è´§ä½æ˜¯å¦éœ€è¦ç§»åº“
    /// </summary>
    /// <param name="locationID">货位ID</param>
@@ -361,16 +498,19 @@
                if (locationInfos == null || locationInfos.Count == 0)
                {
                    locationInfos = BaseDal.QueryData(x => x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo == "SC1" && x.EnalbeStatus == 1 && x.LocationType == 1);
                }
                var location = GetEmptyLocation(locationInfos);
                var location = GetEmptyLocation(locationInfos); //找出货位
                if (location != null)
                {
                    if (location.Depth == 2)
                    {
                        int row = location.Row;
                        int relativeLine = row % 2 == 1 ? row + 1 : row - 1;
                        //int relativeLine = row % 2 == 1 ? row + 1 : row - 1;
                        int relativeLine = row == 1 ? row + 1 : row - 1;
                        var insideLocation = BaseDal.QueryFirst(x => x.Row == relativeLine && x.Layer == location.Layer && x.Column == location.Column);