Admin
12 小时以前 c99808261b1b1460d22a7f7db5955a65080c3b4b
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToAPP/InboundBoxingAction.cs
@@ -146,8 +146,7 @@
                    newBoxDetail.boxdtl_text2 = LotNumber;
                    newBoxDetail.boxdtl_text3 = ProductDate;
                    Dt_boxing_headRepository.Instance.Add(newBoxHead, true);
                    Dt_boxing_detailRepository.Instance.Add(newBoxDetail, true);
                    Dt_mes_goods_info info = new Dt_mes_goods_info();
@@ -165,21 +164,51 @@
                    info.mesInfo_bak_3 = Standard_value; // ä»¥åŽæ ‡å‡†å€¼ä»Žè¿™é‡ŒèŽ·å– è‚–佼新增
                    info.mesInfo_bak_4 = Placeoforigin; // è½´æ‰¿çš„产地
                    Dt_mes_goods_infoRepository.Instance.Add(info, true);
                    //获取空货位
                    Dt_locationinfo emptyLocation = CommonFunction.GetEmptyLocationAction(1);
                    Dt_locationinfo emptyLocation;
                    VV_ContainerInfo_EmptyPallet SelectLocation = VV_ContainerInfo_EmptyPalletRepository.Instance.FindFirst(x => x.location_id == emptyLocation.location_id);
                    VV_ContainerInfo conInfohw = VV_ContainerInfoRepository.Instance.FindFirst(x => x.location_id == emptyLocation.location_id);
                    if (SelectLocation != null || conInfohw != null)
                    int maxRetries = 20;
                    int retryCount = 0;
                    bool needRetry;
                    do
                    {
                        LogRecord.WriteLog((int)LogEnum.InBound, $"分配的货位已有货,货位号{emptyLocation.location_id}");
                        throw new Exception($"分配的货位已有货,货位号{SelectLocation.location_id}");
                        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} æ¬¡ï¼‰");
                    }
                    Dt_boxing_headRepository.Instance.Add(newBoxHead, true);
                    Dt_boxing_detailRepository.Instance.Add(newBoxDetail, true);
                    Dt_mes_goods_infoRepository.Instance.Add(info, true);
                    //获取任务
                    Dt_taskinfo tmpTaskInfo = CommonFunction.AddWMSTask_BoxPalletIn(emptyLocation, rfid, materielId, qrCode, materielType);
@@ -203,5 +232,33 @@
            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;
            }
        }
    }
}