Admin
9 小时以前 c99808261b1b1460d22a7f7db5955a65080c3b4b
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToAPP/InboundBoxingAction.cs
@@ -13,6 +13,7 @@
using WIDESEA.Services.IServices.ToApp;
using WIDESEA.Services.Repositories;
using WIDESEA.Services.Services;
using WIDESEA_Common.LogEnum;
using WIDESEA_Entity.DomainModels;
@@ -53,6 +54,12 @@
                string LotNumber = saveModel.MainData["LotNumber"].ToString();
                //生产日期
                string ProductDate = saveModel.MainData["ProductDate"].ToString();
                // æ ‡å‡†å€¼
                string Standard_value = saveModel.MainData["Standard_value"].ToString();
                // äº§åœ°
                string Placeoforigin = saveModel.MainData["Placeoforigin"].ToString();
                if (string.IsNullOrEmpty(madeUnit) || string.IsNullOrEmpty(materielId) || string.IsNullOrEmpty(materielType) || string.IsNullOrEmpty(NewOrOld))
                    throw new Exception($"厂家/轮对/型号/检修类型都不能为空");
@@ -98,6 +105,8 @@
                if (dt_EmptyPallet == null)
                    throw new Exception($"托盘码:【{rfid}】,在托盘管理中,无该托盘,请先添加托盘信息");
            
                //判断轴承有效期是否超过2å¹´
                if (DateTime.Now > Convert.ToDateTime(ProductDate).AddYears(2))
@@ -123,7 +132,7 @@
                    newBoxDetail.boxdtl_materielid = materielId;
                    newBoxDetail.boxdtl_qty = "1";
                    newBoxDetail.boxdtl_operator = UserContext.Current.UserTrueName;
                    newBoxDetail.boxdtl_inboundUnit = "智粤";
                    newBoxDetail.boxdtl_inboundUnit = "北京动车段";
                    newBoxDetail.boxdtl_standard = NewOrOld;
                    newBoxDetail.boxdtl_carType = materielId;
                    newBoxDetail.boxdtl_type = materielType;
@@ -137,13 +146,12 @@
                    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();
                    info.mesInfo_id = Guid.NewGuid();
                    info.mesInfo_inUnit = "智粤";
                    info.mesInfo_inUnit = "北京动车段";
                    info.mesInfo_madeUnit = madeUnit;
                    info.mesInfo_carType = materielId;
                    info.mesInfo_type = materielType;
@@ -153,11 +161,55 @@
                    info.mesInfo_createType = "mes";
                    info.mesInfo_qrCode = qrCode;
                    info.mesInfo_createDate = DateTime.Now;
                    info.mesInfo_bak_3 = Standard_value; // ä»¥åŽæ ‡å‡†å€¼ä»Žè¿™é‡ŒèŽ·å– è‚–佼新增
                    info.mesInfo_bak_4 = Placeoforigin; // è½´æ‰¿çš„产地
                    Dt_mes_goods_infoRepository.Instance.Add(info, true);
                    //获取空货位
                    Dt_locationinfo emptyLocation = CommonFunction.GetEmptyLocationAction();
                    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} æ¬¡ï¼‰");
                    }
                    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);
                    //修改货位状态
@@ -180,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;
            }
        }
    }
}