Admin
15 小时以前 c99808261b1b1460d22a7f7db5955a65080c3b4b
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/Inbound/Partial/Dt_boxing_headService.cs
@@ -145,12 +145,50 @@
                    //newBoxDetail.boxdtl_text1 = 
                    Dt_boxing_headRepository.Instance.Add(newBoxHead, true);
                    Dt_boxing_detailRepository.Instance.Add(newBoxDetail, true);
                    //获取空货位
                    Dt_locationinfo emptyLocation = CommonFunction.GetEmptyLocationAction(1);
                    Dt_locationinfo emptyLocation;
                    int maxRetries = 20;
                    int retryCount = 0;
                    bool needRetry;
                    do
                    {
                        needRetry = false;  // é»˜è®¤ä¸éœ€è¦é‡è¯•
                        retryCount++;
                        //获取空货位
                        emptyLocation = CommonFunction.GetEmptyLocationAction(1);
                        if (emptyLocation == null)
                        {
                            return content.Error("无法获取库位");
                        }
                        // 2. æ£€æŸ¥åº“å­˜
                        if (IsEmptyPalletLocation(emptyLocation.location_id))
                        {
                            needRetry = true;
                            continue;  // ç›´æŽ¥è¿›å…¥ä¸‹ä¸€æ¬¡å¾ªçŽ¯ï¼ˆé‡è¯•ï¼‰
                        }
                        // 3. æ£€æŸ¥ä»»åŠ¡
                        if (Dt_taskinfoRepository.Instance.Find(x => x.task_endstation == emptyLocation.location_id).FirstOrDefault() != null)
                        {
                            needRetry = true;
                            continue;
                        }
                    } while (needRetry && retryCount < maxRetries);
                    // æ£€æŸ¥æ˜¯å¦è¶…过最大重试次数
                    if (retryCount >= maxRetries)
                    {
                        return content.Error($"无法找到可用库位(已尝试 {retryCount} æ¬¡ï¼‰");
                    }
                    LogRecord.WriteLog((int)LogEnum.InBound, $"托盘条码:{rfid},分配的货位号{emptyLocation.location_id},货位状态:{emptyLocation.location_state}");
                    Dt_boxing_headRepository.Instance.Add(newBoxHead, true);
                    Dt_boxing_detailRepository.Instance.Add(newBoxDetail, true);
                    //获取任务
                    Dt_taskinfo tmpTaskInfo = CommonFunction.AddWMSTask_BoxPalletIn(emptyLocation,
@@ -174,6 +212,34 @@
            }
             Logger.AddLog(LoggerType.Add, saveModel, content, content);
            return content;
        }
        /// <summary>
        /// æ£€æŸ¥æŒ‡å®šè´§ä½æ˜¯å¦ä¸ºç©ºæ‰˜ç›˜è´§ä½
        /// </summary>
        /// <param name="locationId">货位ID</param>
        /// <returns>true: æ˜¯ç©ºæ‰˜ç›˜è´§ä½, false: ä¸æ˜¯ç©ºæ‰˜ç›˜è´§ä½</returns>
        public bool IsEmptyPalletLocation(string locationId)
        {
            try
            {
                // æŸ¥è¯¢ç©ºæ‰˜ç›˜è´§ä½ä¿¡æ¯
                var emptyPalletLocation = VV_ContainerInfo_EmptyPalletRepository.Instance
                    .Find(x => x.location_id == locationId).FirstOrDefault();
                // æŸ¥è¯¢è´§ä½ä¸Šçš„容器信息
                var containerInfo = VV_ContainerInfoRepository.Instance
                    .Find(x => x.location_id == locationId).FirstOrDefault();
                bool isEmptyPallet = emptyPalletLocation != null || containerInfo != null;
                return isEmptyPallet;
            }
            catch (Exception ex)
            {
                LogRecord.WriteLog((int)LogEnum.Errer, $"检查空托盘货位失败,货位ID:{locationId},错误:{ex.Message}");
                return false;
            }
        }
@@ -200,9 +266,45 @@
                VV_ContainerInfo_EmptyPallet emptyCon = VV_ContainerInfo_EmptyPalletRepository.Instance.FindFirst(x => x.containerhead_barcode == barcode);
                if (emptyCon != null)
                    throw new Exception($"库存中存在托盘号:【{barcode}】的【空托】库存,请人工核实,所在货位:{emptyCon.location_id}");
                //获取空货位
                Dt_locationinfo emptyLocation;
                //说明是空托入库
                Dt_locationinfo emptyLocation = CommonFunction.GetEmptyLocationAction(1);
                int maxRetries = 20;
                int retryCount = 0;
                bool needRetry;
                do
                {
                    needRetry = false;  // é»˜è®¤ä¸éœ€è¦é‡è¯•
                    retryCount++;
                    //获取空货位
                    emptyLocation = CommonFunction.GetEmptyLocationAction(1);
                    if (emptyLocation == null)
                    {
                        return content.Error("无法获取库位");
                    }
                    // 2. æ£€æŸ¥åº“å­˜
                    if (IsEmptyPalletLocation(emptyLocation.location_id))
                    {
                        needRetry = true;
                        continue;  // ç›´æŽ¥è¿›å…¥ä¸‹ä¸€æ¬¡å¾ªçŽ¯ï¼ˆé‡è¯•ï¼‰
                    }
                    // 3. æ£€æŸ¥ä»»åŠ¡
                    if (Dt_taskinfoRepository.Instance.Find(x => x.task_endstation == emptyLocation.location_id).FirstOrDefault() != null)
                    {
                        needRetry = true;
                        continue;
                    }
                } while (needRetry && retryCount < maxRetries);
                // æ£€æŸ¥æ˜¯å¦è¶…过最大重试次数
                if (retryCount >= maxRetries)
                {
                    return content.Error($"无法找到可用库位(已尝试 {retryCount} æ¬¡ï¼‰");
                }
                LogRecord.WriteLog((int)LogEnum.InBound, $"托盘条码:{barcode},分配的货位号{emptyLocation.location_id},货位状态:{emptyLocation.location_state}");