From 2aec0a99e559fb11b7046b148e5f357b3208cb66 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期五, 12 九月 2025 10:06:22 +0800
Subject: [PATCH] 推送最新代码

---
 项目代码/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs |  174 ++++++++++++++++++++++++---------------------------------
 1 files changed, 74 insertions(+), 100 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
index 4c3a92f..4b35f88 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
@@ -141,6 +141,7 @@
                 {
                     return content.Error($"鏈壘鍒板彲鍒嗛厤宸烽亾");
                 }
+                //鐢熸垚浠诲姟
                 Dt_Task newTask = new Dt_Task()
                 {
                     CurrentAddress = stationCode,
@@ -154,6 +155,7 @@
                     TaskStatus = TaskStatusEnum.New.ObjToInt(),
                     WarehouseId = stockInfo.WarehouseId,
                     PalletType = stockInfo.PalletType,
+                    TaskLength = (int)stockInfo.MaterielWide
                 };
 
                 if (stockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt())
@@ -277,28 +279,34 @@
                 }
 
                 string roadwayNo = "";
-                //闄愬埗鐩村緞
-                if (stockInfo.MaterielThickness > 800)
+                
+                if (stockInfo.MaterielInvOrgId==MaterielInvOrgEnum.鏂板巶.ObjToInt())
                 {
-                    //鑾峰彇鍒嗛厤
-                    List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("YL")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
-                    if (stockInfo.MaterielWide > 2200)
+                    //闄愬埗鐩村緞
+                    if (stockInfo.MaterielThickness <= 1250)
                     {
-                        locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo=="SC02_YL").GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
+                        //鑾峰彇鍒嗛厤
+                        List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("YLDual")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
+
+                        roadwayNo = HandleRoadway(locationCounts, warehouse);
                     }
-                    List<LocationCount> useLocationCounts = Db.Queryable<Dt_Task>().Where(x => x.WarehouseId == warehouse.WarehouseId
-                    && locationCounts.Select(j => j.RoadwayNo).Contains(x.Roadway)
-                    && TaskInboundTypes.Contains(x.TaskType)).GroupBy(x => x.Roadway).Select(x => new LocationCount { RoadwayNo = x.Roadway, Count = SqlFunc.AggregateCount(x) }).ToList();
-                    foreach (var item in locationCounts)
-                    {
-                        LocationCount? count = useLocationCounts.FirstOrDefault(x => x.RoadwayNo == item.RoadwayNo);
-                        if (count != null)
-                        {
-                            item.Count -= count.Count;
-                        }
-                    }
-                    roadwayNo = locationCounts.OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
                 }
+                else
+                {
+                    //闄愬埗鐩村緞
+                    if (stockInfo.MaterielThickness >= 800 && stockInfo.MaterielThickness <= 1450)
+                    {
+                        //鑾峰彇鍒嗛厤
+                        List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("YL") && !x.RoadwayNo.Contains("YLDual")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
+                        if (stockInfo.MaterielWide > 2200)
+                        {
+                            locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo == "SC02_YL").GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
+                        }
+
+                        roadwayNo = HandleRoadway(locationCounts, warehouse);
+                    }
+                }
+                
                 return !string.IsNullOrEmpty(roadwayNo) ? (roadwayNo) : throw new Exception("鏈壘鍒板彲鍒嗛厤宸烽亾");
             }
             catch (Exception ex)
@@ -306,6 +314,23 @@
                 _unitOfWorkManage.RollbackTran();
                 throw new Exception(ex.Message);
             }
+        }
+        //澶勭悊鍒嗛厤宸烽亾 浠诲姟鏁伴噺
+        public string HandleRoadway(List<LocationCount> locationCounts, Dt_Warehouse warehouse)
+        {
+            //宸烽亾浠诲姟鍒嗛厤鏁伴噺
+            List<LocationCount> useLocationCounts = Db.Queryable<Dt_Task>().Where(x => x.WarehouseId == warehouse.WarehouseId
+            && locationCounts.Select(j => j.RoadwayNo).Distinct().Contains(x.Roadway)
+            && TaskInboundTypes.Contains(x.TaskType)).GroupBy(x => x.Roadway).Select(x => new LocationCount { RoadwayNo = x.Roadway, Count = SqlFunc.AggregateCount(x) }).ToList();
+            foreach (var item in locationCounts)
+            {
+                LocationCount? count = useLocationCounts.FirstOrDefault(x => x.RoadwayNo == item.RoadwayNo);
+                if (count != null)
+                {
+                    item.Count -= count.Count;
+                }
+            }
+            return locationCounts.OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
         }
         /// <summary>
         /// 鍏ュ簱瀹屾垚
@@ -316,7 +341,7 @@
             try
             {
                 Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == task.WarehouseId);
-                if (warehouse.WarehouseCode == WarehouseEnum.LLDCP.ToString()) //鎴愬搧瀹屾垚
+                if (warehouse.WarehouseCode == WarehouseEnum.LLDCP.ToString() || warehouse.WarehouseCode == WarehouseEnum.LLDFL.ToString()) //鎴愬搧/杈呮枡瀹屾垚
                 {
                     Dt_LocationInfo locationInfoEnd = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                     if (locationInfoEnd == null)
@@ -396,21 +421,23 @@
                     _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                     _basicService.LocationInfoService.UpdateLocationStatus(locationInfoEnd, stockInfo.PalletType, LocationStatusEnum.InStock, stockInfo.WarehouseId);
                     BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? WIDESEA_Core.Enums.OperateTypeEnum.浜哄伐瀹屾垚 : WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚);
-                    //if (stockInfo.MaterielInvOrgId==MaterielInvOrgEnum.鑰佸巶.ObjToInt())
-                    //{
-                    //    int Qty = Convert.ToInt32(stockInfo.MaterielWeight);
-                    //    BSTPurchaseUpModel bSTPurchaseUpModel = new BSTPurchaseUpModel()
-                    //    {
-                    //        Barcode = stockInfo.PalletCode,
-                    //        BarcodeQty = Qty,
-                    //        Rfid = stockInfo.PalletCode
-                    //    };
-                    //    BSTResponse bSTResponse = _invokeERPService.BSTPurchaseUp(bSTPurchaseUpModel).DeserializeObject<BSTResponse>();
-                    //    if (bSTResponse.Code==500)
-                    //    {
-                    //        throw new Exception($"BST涓�鏈烢RP鍚屾鍏ュ簱淇℃伅澶辫触,閿欒淇℃伅{bSTResponse.Msg}");
-                    //    }
-                    //}
+                    //涓婃姤鑰佸巶ERP
+                    if (stockInfo.MaterielInvOrgId == MaterielInvOrgEnum.鑰佸巶.ObjToInt())
+                    {
+                        int Qty = Convert.ToInt32(stockInfo.MaterielWeight);
+                        BSTPurchaseUpModel bSTPurchaseUpModel = new BSTPurchaseUpModel()
+                        {
+                            Barcode = stockInfo.PalletCode,
+                            BarcodeQty = Qty,
+                            Rfid = stockInfo.PalletCode,
+                            RfidUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+                        };
+                        BSTResponse bSTResponse = _invokeERPService.BSTPurchaseUp(bSTPurchaseUpModel).DeserializeObject<BSTResponse>();
+                        if (bSTResponse.Code == 500)
+                        {
+                            throw new Exception($"BST涓�鏈烢RP鍚屾鍏ュ簱淇℃伅澶辫触,閿欒淇℃伅锛歿bSTResponse.Msg}");
+                        }
+                    }
                     _unitOfWorkManage.CommitTran();
                 }
                 return content.OK();
@@ -430,16 +457,11 @@
         {
             try
             {
-                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == 2);
-                if (warehouse == null)
-                {
-                    throw new Exception($"鏈壘鍒板贩閬撳搴斾粨搴撲俊鎭�");
-                }
-
                 string roadwayNo = "";
-                List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("CP")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
+                //鑾峰彇宸烽亾鍙垎閰嶇殑璐т綅鏁伴噺
+                List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == WarehouseEnum.LLDCP.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("CP")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
                 //绛涢�夊綋鍓嶅叆搴撲换鍔′腑宸插垎閰嶅贩閬撲换鍔℃暟閲�
-                List<LocationCount> useLocationCounts = Db.Queryable<Dt_Task>().Where(x => x.WarehouseId == warehouse.WarehouseId 
+                List<LocationCount> useLocationCounts = Db.Queryable<Dt_Task>().Where(x => (x.WarehouseId == WarehouseEnum.LLDCP.ObjToInt()|| x.WarehouseId == WarehouseEnum.LLDFL.ObjToInt())
                 && locationCounts.Select(j=>j.RoadwayNo).Contains(x.Roadway)
                 && TaskInboundTypes.Contains(x.TaskType)).GroupBy(x => x.Roadway).Select(x => new LocationCount { RoadwayNo = x.Roadway, Count = SqlFunc.AggregateCount(x) }).ToList();
                 foreach (var item in locationCounts)
@@ -450,6 +472,7 @@
                         item.Count -= count.Count;
                     }
                 }
+                //閫氳繃鍙敤璐т綅鏁伴噺鎺掑簭锛屾渶澶氱殑浼樺厛鍒嗛厤
                 roadwayNo = locationCounts.OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
                 return !string.IsNullOrEmpty(roadwayNo) ? (roadwayNo) : throw new Exception("鏈壘鍒板彲鍒嗛厤宸烽亾");
             }
@@ -498,7 +521,6 @@
                     task.TaskStatus = TaskStatusEnum.SC_Execute.ObjToInt();
                 }
 
-
                 LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
                 //鏇存柊閿佸畾璐т綅
                 _unitOfWorkManage.BeginTran();
@@ -514,54 +536,7 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="taskNum"></param>
-        /// <param name="roadwayNo"></param>
-        /// <param name="heightType"></param>
-        /// <returns></returns>
-        public WebResponseContent AssignInboundTaskLocationByHeight(int taskNum, string roadwayNo, int heightType)
-        {
-            try
-            {
-                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
-                if (task == null)
-                {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鍏ュ簱浠诲姟");
-                }
-
-                if (_basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress) != null)
-                {
-                    return WebResponseContent.Instance.OK(data: task.TargetAddress);
-                }
-
-                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId, heightType: heightType);
-                if (locationInfo == null)
-                {
-                    return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
-                }
-
-                task.Roadway = roadwayNo;
-                task.TargetAddress = locationInfo.LocationCode;
-                task.TaskStatus = TaskStatusEnum.SC_Execute.ObjToInt();
-
-                LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
-
-                _unitOfWorkManage.BeginTran();
-                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation);
-                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, task.PalletType, LocationStatusEnum.Lock, task.WarehouseId);
-                BaseDal.UpdateData(task);
-                _unitOfWorkManage.CommitTran();
-                return WebResponseContent.Instance.OK(data: locationInfo.LocationCode);
-            }
-            catch (Exception ex)
-            {
-                _unitOfWorkManage.RollbackTran();
-                return WebResponseContent.Instance.Error(ex.Message);
-            }
-        }
+        
         /// <summary>
         /// 绌烘鍥炲簱
         /// </summary>
@@ -600,15 +575,13 @@
                 //鍒嗛厤宸烽亾
                 string roadWay=AssignCPRoadwayNo();
                 
-                //鑾峰彇鎴愬搧搴�
-                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.LLDCP.ToString());
                 Dt_ProStockInfo proStockInfo = new Dt_ProStockInfo()
                 {
                     PalletCode=barCode,
                     ProStockAttribute=ProStockAttributeEnum.绌烘墭.ObjToInt(),
                     PalletType=1,
                     LocationCode="",
-                    WarehouseId=warehouse.WarehouseId,
+                    WarehouseId= WarehouseEnum.LLDFL.ObjToInt(),
                     StockStatus=StockStatusEmun.MES绌烘墭閫�搴�.ObjToInt()
                 }; 
 
@@ -623,7 +596,7 @@
                     TargetAddress = "",
                     TaskType = TaskTypeEnum.EmptyProductBack.ObjToInt(),
                     TaskStatus = TaskStatusEnum.New.ObjToInt(),
-                    WarehouseId = warehouse.WarehouseId,
+                    WarehouseId = WarehouseEnum.LLDFL.ObjToInt(),
                     PalletType = 1
                 };
                 _unitOfWorkManage.BeginTran();
@@ -644,7 +617,7 @@
         }
         private readonly static object _lockerFLorCP = new object();
         /// <summary>
-        /// 杈呮枡鎴愬搧鍏ュ簱
+        /// 杈呮枡/鎴愬搧涓存椂鍏ュ簱
         /// </summary>
         /// <returns></returns>
         public WebResponseContent InboundFLOrCPTask(string barCode, string startPoint,string matCode,int matCount)
@@ -660,7 +633,8 @@
                     //{
                     //    return content.Error($"妗嗙爜鏍煎紡閿欒{barCode}");
                     //}
-                    Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == matCode && x.MaterielInvOrgId == MaterielInvOrgEnum.鏂板巶.ObjToInt() && x.WarehouseId==WarehouseEnum.LLDCP.ObjToInt());
+                    //鑾峰彇鐗╂枡
+                    Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == matCode && x.MaterielInvOrgId == MaterielInvOrgEnum.鏂板巶.ObjToInt() && (x.WarehouseId==WarehouseEnum.LLDCP.ObjToInt() || x.WarehouseId == WarehouseEnum.LLDFL.ObjToInt()));
                     if (materielInfo == null)
                     {
                         return content.Error($"鏈壘鍒扮墿鏂欎俊鎭瘂matCode}");
@@ -690,7 +664,7 @@
                     string roadWay = AssignCPRoadwayNo();
 
                     //鑾峰彇鎴愬搧搴�
-                    Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.LLDCP.ToString());
+                    WarehouseEnum warehouseEnum = materielInfo.MaterielSourceType == MaterielTypeEnum.鎴愬搧.ObjToInt() ? WarehouseEnum.LLDCP : WarehouseEnum.LLDFL;
                     Dt_ProStockInfoDetail proStockInfoDetail = new Dt_ProStockInfoDetail()
                     {
                         ProductCode = materielInfo.MaterielCode,
@@ -706,7 +680,7 @@
                         ProStockAttribute = materielInfo.MaterielSourceType,
                         PalletType = 1,
                         LocationCode = "",
-                        WarehouseId = warehouse.WarehouseId,
+                        WarehouseId = warehouseEnum.ObjToInt(),
                         StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt(),
                         proStockInfoDetails = new List<Dt_ProStockInfoDetail> { proStockInfoDetail }
                     };
@@ -722,7 +696,7 @@
                         TargetAddress = "",
                         TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                         TaskStatus = TaskStatusEnum.New.ObjToInt(),
-                        WarehouseId = warehouse.WarehouseId,
+                        WarehouseId = warehouseEnum.ObjToInt(),
                         PalletType = 1
                     };
                     _unitOfWorkManage.BeginTran();

--
Gitblit v1.9.3