xiaojiao
20 小时以前 ff8b20f321a8b70ec3bdc208b9f383fd71718108
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToWCS/Partial/InboundLogic.cs
@@ -6,6 +6,7 @@
using WIDESEA.Common;
using WIDESEA.Common.EquipEnum;
using WIDESEA.Core.Enums;
using WIDESEA.Core.ManageUser;
using WIDESEA.Core.Services;
using WIDESEA.Core.Utilities;
using WIDESEA.Entity.DomainModels;
@@ -59,11 +60,15 @@
        public WebResponseContent ReceiveWeightResultFromWCS(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                string barcode = saveModel.MainData["barcode"].ToString();
                string weight = saveModel.MainData["weight"].ToString();
                if (weight == null || weight == "0")
                {
                    throw new Exception($"托盘号:【{barcode}】,重量不对不符合规定");
                }
                Dt_taskinfo taskInfo = Dt_taskinfoRepository.Instance.FindFirst(x => x.task_barcode == barcode);
                if (null == taskInfo)
@@ -73,10 +78,10 @@
                //没有组盘信息,说明该重量是空托盘的重量
                if (null == boxHead)
                {
                    Dt_EmptyPallet dt_Empty= Dt_EmptyPalletRepository.Instance.FindFirst(x => x.EmptyPallet_name == barcode);
                    Dt_EmptyPallet dt_Empty = Dt_EmptyPalletRepository.Instance.FindFirst(x => x.EmptyPallet_name == barcode);
                    if (null == dt_Empty)
                    {
                        Dt_EmptyPallet dt_Empty1=new Dt_EmptyPallet();
                        Dt_EmptyPallet dt_Empty1 = new Dt_EmptyPallet();
                        dt_Empty1.EmptyPallet_name = barcode;
                        dt_Empty1.EmptyPallet_palletweight = weight;
                        dt_Empty1.EmptyPallet_creator = "WMS";
@@ -84,13 +89,12 @@
                        dt_Empty1.EmptyPallet_modifier = "WMS";
                        dt_Empty1.EmptyPallet_modifiertime = DateTime.Now;
                        Dt_EmptyPalletRepository.Instance.Add(dt_Empty1,true);
                        taskInfo.task_weight = weight;
                    }
                    else
                    {
                        taskInfo.task_weight = dt_Empty.EmptyPallet_palletweight;
                    }
                    Dt_taskinfoRepository.Instance.Update(taskInfo, true);
                }
                else//有组盘信息,说明该重量是轴承实托的重量
@@ -164,6 +168,23 @@
            }
            Logger.AddLog(Core.Enums.LoggerType.Edit, saveModel, content, content);
            return content;
        }
        /// <summary>
        /// èŽ·å–å…¥åº“åŒºåŸŸå’Œå‡ºåº“åŒºåŸŸçš„æ¨¡å¼
        /// </summary>
        /// <returns></returns>
        public WebResponseContent GetInorOutMODELS(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                return content;
            }
            catch (Exception)
            {
                throw;
            }
        }
@@ -431,6 +452,7 @@
        /// <returns></returns>
        public WebResponseContent InboundRequstFromWCS(SaveModel saveModel)
        {
            LogRecord.WriteLog((int)LogEnum.InBound, $"{DateTime.Now},空托回库申请入库 åˆ›å»ºäºº{UserContext.Current.UserTrueName} æ‰˜ç›˜å·ï¼š{saveModel.MainData["barcode"].ToString()}");
            WebResponseContent content = new WebResponseContent();
            string barcode = string.Empty;
            try
@@ -457,8 +479,47 @@
                }
                content = Dt_taskinfoRepository.Instance.DbContextBeginTransaction(() =>
                {
                    //获取空货位
                    Dt_locationinfo emptyLocation = CommonFunction.GetEmptyLocationAction();
                    Dt_locationinfo emptyLocation;
                    int maxRetries = 20;
                    int retryCount = 0;
                    bool needRetry;
                    do
                    {
                        needRetry = false;  // é»˜è®¤ä¸éœ€è¦é‡è¯•
                        retryCount++;
                        //获取空货位
                        emptyLocation = CommonFunction.GetEmptyLocationAction(2);
                        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}");
                    Dt_taskinfo taskinfo = new Dt_taskinfo();
                    taskinfo.task_id = Guid.NewGuid();
@@ -498,6 +559,35 @@
            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;
            }
        }
    }
}