From ce40df5daffae0d17b4e9fa7cb6d677afaa4d66f Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期五, 17 十月 2025 11:20:30 +0800
Subject: [PATCH] 更新最新程序,ERP代码,MES代码等

---
 项目代码/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Outbound.cs |  239 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 199 insertions(+), 40 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Outbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
index 23241b2..476fc92 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
@@ -32,46 +32,45 @@
         /// </summary>
         /// <param name="id"></param>
         /// <returns></returns>
-        public WebResponseContent Outbound(int id)
+        public WebResponseContent Outbound(List<int> ids)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.Id == id).First();
-                if (stockInfo == null)
+                //鑾峰彇閫夊畾搴撳瓨
+                List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => ids.Contains(x.Id) && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() && x.MaterielInvOrgId == MaterielInvOrgEnum.鑰佸巶.ObjToInt()).ToList();
+                if (stockInfos == null || stockInfos.Count != ids.Count)
                 {
                     return content.Error($"鏈壘鍒板簱瀛�");
                 }
-                Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
-                if (locationInfo != null && (locationInfo.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt() || locationInfo.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt() && stockInfo.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt())
+                //鑾峰彇搴撳瓨璐т綅
+                List<Dt_LocationInfo> locationInfos = _basicRepository.LocationInfoRepository.QueryData(x =>x.WarehouseId == WarehouseEnum.LLDYL.ObjToInt() && stockInfos.Select(x=>x.LocationCode).Contains(x.LocationCode) && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()));
+                if (locationInfos == null || locationInfos.Count != stockInfos.Count)
                 {
-                    List<Dt_Task> tasks = GetTasks(new List<Dt_StockInfo>() { stockInfo }, TaskTypeEnum.Outbound);
-                    if (tasks == null || tasks.Count <= 0)
-                    {
-                        return content.Error($"鐢熸垚浠诲姟澶辫触");
-                    }
-                    //澶勭悊搴撳瓨鏁版嵁
-                    stockInfo.StockStatus = (int)StockStatusEmun.鍑哄簱閿佸畾;
-                    LocationStatusEnum locationStatus = (LocationStatusEnum)locationInfo.LocationStatus;
-                    locationInfo.LocationStatus = (int)LocationStatusEnum.Lock;
-                    //鍒ゆ柇鏄惁鏈夊嚭搴撳崟淇℃伅
-                    _unitOfWorkManage.BeginTran();
-                    //鏇存柊搴撳瓨鐘舵��
-                    _stockRepository.StockInfoRepository.UpdateData(stockInfo);
-                    //鏇存柊璐т綅鐘舵��
-                    _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.Lock, stockInfo.WarehouseId);
-                    //鏂板缓浠诲姟
-                    BaseDal.AddData(tasks);
-                    //鍔犲叆璐т綅鍙樺姩璁板綍
-                    _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, locationStatus, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, stockInfo.OrderNo ?? "", tasks[0].TaskNum);
-                    _unitOfWorkManage.CommitTran();
-                    PushTasksToWCS(tasks);
-                    content.OK();
+                    return content.Error($"璐т綅鍑哄簱鏉′欢涓嶆弧瓒�");
                 }
-                else
+                //浠诲姟鐢熸垚
+                List<Dt_Task> tasks = GetTasks(stockInfos, TaskTypeEnum.OldYLOutbound);
+                if (tasks == null || tasks.Count <= 0)
                 {
-                    content.Error($"璐т綅鍑哄簱鏉′欢涓嶆弧瓒�");
+                    return content.Error($"鐢熸垚浠诲姟澶辫触");
                 }
+                stockInfos.ForEach(x =>
+                {
+                    x.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                });
+                _unitOfWorkManage.BeginTran();
+                //鏇存柊搴撳瓨鐘舵��
+                _stockRepository.StockInfoRepository.UpdateData(stockInfos);
+                //鏇存柊璐т綅鐘舵��
+                _basicRepository.LocationInfoRepository.UpdateLocationStatus(locationInfos, LocationStatusEnum.Lock);
+                //鍔犲叆璐т綅鍙樺姩璁板綍
+                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, taskNums: tasks.Select(x => x.TaskNum).ToList());
+                //鏂板缓浠诲姟
+                BaseDal.AddData(tasks);
+                _unitOfWorkManage.CommitTran();
+                PushTasksToWCS(tasks);
+                content.OK();
             }
             catch (Exception ex)
             {
@@ -146,7 +145,7 @@
             }
         }
         /// <summary>
-        /// 搴撳瓨鏁版嵁杞嚭搴撲换鍔�
+        /// 搴撳瓨鏁版嵁杞嚭搴撲换鍔�(鍘熸枡/鍗婃垚鍝�)
         /// </summary>
         /// <param name="stockInfos"></param>
         /// <returns></returns>
@@ -189,6 +188,9 @@
             }
             return tasks;
         }
+        /// <summary>
+        /// 搴撳瓨鏁版嵁杞嚭搴撲换鍔�(杈呮枡/鎴愬搧)
+        /// </summary>
         public List<Dt_Task> GetTasks(List<Dt_ProStockInfo> stockInfos, TaskTypeEnum taskType,List<Dt_LocationInfo> locationInfos)
         {
             List<Dt_Task> tasks = new List<Dt_Task>();
@@ -227,7 +229,7 @@
         /// 鎴愬搧鍑哄簱
         /// </summary>
         /// <returns></returns>
-        public WebResponseContent RequestCPWMSTaskOut(string materialCode,int Count, int targetId)
+        public WebResponseContent RequestCPWMSTaskOut(string materialCode,int Count, string targetId)
         {
             WebResponseContent content = new WebResponseContent();
             try
@@ -239,13 +241,19 @@
                 }
                 //鑾峰彇璐т綅
                 List<Dt_LocationInfo> locationInfos = _basicRepository.LocationInfoRepository.QueryData(x => x.WarehouseId == WarehouseEnum.LLDCP.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt());
-                
-                //鑾峰彇鍙敤搴撳瓨
-                List<Dt_ProStockInfo> stockInfos = BaseDal.Db.Queryable<Dt_ProStockInfo>().Where(x => locationInfos.Select(x => x.LocationCode).Contains(x.LocationCode) && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()).Includes(x => x.proStockInfoDetails)
-                .Where(x => x.proStockInfoDetails
-                .Any(v =>
-                    v.ProductCode == materialCode)
-                ).ToList();
+                List<Dt_ProStockInfo> stockInfos = new List<Dt_ProStockInfo>();
+                if (materialCode=="1")
+                {
+                    stockInfos = BaseDal.Db.Queryable<Dt_ProStockInfo>().Where(x => locationInfos.Select(x => x.LocationCode).Contains(x.LocationCode) && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() && x.ProStockAttribute==ProStockAttributeEnum.绌烘墭.ObjToInt()).Take(Count).ToList();
+                }
+                else
+                {
+                    stockInfos = BaseDal.Db.Queryable<Dt_ProStockInfo>().Where(x => locationInfos.Select(x => x.LocationCode).Contains(x.LocationCode) && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()).Includes(x => x.proStockInfoDetails)
+                    .Where(x => x.proStockInfoDetails
+                    .Any(v =>
+                        v.ProductCode == materialCode)
+                    ).Take(Count).ToList();
+                }
 
                 if (stockInfos.Count!=Count)
                 {
@@ -263,10 +271,15 @@
                 }
                 TaskTypeEnum typeEnum = targetId switch
                 {
-                    (int)AGVStationAreaEnum.AreaA => TaskTypeEnum.OutProduct,
-                    (int)AGVStationAreaEnum.AreaC => TaskTypeEnum.OutWFB,
+                    nameof(AGVStationAreaEnum.涓�妤兼湀鍙扮爜澶�) => TaskTypeEnum.OutProduct,
+                    nameof(AGVStationAreaEnum.涓�妤兼棤绾虹粐甯�) => TaskTypeEnum.OutWFB,
+                    nameof(AGVStationAreaEnum.涓�妤兼棤绾烘穻鑶�) => TaskTypeEnum.OutWFBLM,
                     _ => throw new Exception("鏈壘鍒板搴斾换鍔�")
                 };
+                if (materialCode == "1")
+                {
+                    typeEnum = TaskTypeEnum.OutEmpty;
+                }
                 List<Dt_Task> tasks = GetTasks(stockInfos, typeEnum, AssignLocations);
                 if (tasks == null || tasks.Count <= 0)
                 {
@@ -523,5 +536,151 @@
             }
 
         }
+        /// <summary>
+        /// 鍒涘缓鍘熺焊鐢熺鎺掔▼鍑哄簱浠诲姟
+        /// </summary>
+        /// <param name="keys"></param>
+        /// <returns></returns>
+        public WebResponseContent CreateSGOutboundTasks(int[] keys)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                List<Dt_Task> tasks = new List<Dt_Task>();
+                List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>();
+                List<Dt_OutSGOrderDetail> outSGOrderDetails = new List<Dt_OutSGOrderDetail>();
+                List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
+                List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+                //鐢熸垚浠诲姟銆佸簱瀛樼瓑淇℃伅
+                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutSGOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutSGTaskDataHandle(keys);
+                if (result.Item2 != null && result.Item2.Count > 0)
+                {
+                    stockInfos.AddRange(result.Item2);
+                }
+                if (result.Item3 != null && result.Item3.Count > 0)
+                {
+                    outSGOrderDetails.AddRange(result.Item3);
+                }
+                if (result.Item4 != null && result.Item4.Count > 0)
+                {
+                    outStockLockInfos.AddRange(result.Item4);
+                }
+                if (result.Item5 != null && result.Item5.Count > 0)
+                {
+                    locationInfos.AddRange(result.Item5);
+                }
+                if (result.Item1 != null && result.Item1.Count > 0)
+                {
+                    tasks.AddRange(result.Item1);
+                }
+                //澶勭悊鍑哄簱鏁版嵁
+                return GenerateOutboundTaskDataUpdate(tasks, stockInfos, outSGOrderDetails, outStockLockInfos, locationInfos);
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 鍑哄簱浠诲姟鏁版嵁澶勭悊
+        /// </summary>
+        /// <param name="orderDetailId"></param>
+        /// <param name="stockSelectViews"></param>
+        /// <returns></returns>
+        /// <exception cref="Exception"></exception>
+        public (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutSGOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) OutSGTaskDataHandle(int[] keys)
+        {
+            List<Dt_Task> tasks = new List<Dt_Task>();
+            List<Dt_OutSGOrderDetail> outSGOrderDetails = _outboundRepository.OutSGOrderDetailRepository.QueryData(x => keys.Contains(x.Id));
+
+            if (outSGOrderDetails == null || outSGOrderDetails.Count == 0)
+            {
+                throw new Exception("鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
+            }
+            Dt_OutSGOrderDetail? outBSTOrderDetail = outSGOrderDetails.FirstOrDefault(x => x.OutSGOrderDetailStatus != OutOrderStatusEnum.鏈紑濮�.ObjToInt());
+            if (outBSTOrderDetail != null)
+            {
+                throw new Exception($"鍑哄簱鏄庣粏{nameof(Dt_OutSGOrderDetail.BoardMpsDetailId)}{outBSTOrderDetail.BoardMpsDetailId}鐗╂枡{outBSTOrderDetail.MaterialNo},鍑哄簱涓垨宸插畬鎴�");
+            }
+            List<Dt_StockInfo>? stockInfos = null;
+            List<Dt_OutSGOrderDetail>? orderDetails = null;
+            List<Dt_OutStockLockInfo>? outStockLockInfos = null;
+            List<Dt_LocationInfo>? locationInfos = null;
+
+            //鍒嗛厤搴撳瓨
+            (List<Dt_StockInfo>, List<Dt_OutSGOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.OutSGOrderDetailService.AssignStockOutbound(outSGOrderDetails);
+            if (result.Item1 != null && result.Item1.Count > 0)
+            {
+                //鑾峰彇浠诲姟
+                tasks = GetTasks(result.Item1, TaskTypeEnum.OldYLOutbound);
+                
+                result.Item2.ForEach(x =>
+                {
+                    x.OutSGOrderDetailStatus = OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
+                });
+                result.Item3.ForEach(x =>
+                {
+                    x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+                });
+
+                stockInfos = result.Item1;
+                orderDetails = result.Item2;
+                outStockLockInfos = result.Item3;
+                locationInfos = result.Item4;
+            }
+            else
+            {
+                throw new Exception("鏃犲簱瀛�");
+            }
+
+            return (tasks, stockInfos, orderDetails, outStockLockInfos, locationInfos);
+        }
+        public WebResponseContent GenerateOutboundTaskDataUpdate(List<Dt_Task> tasks, List<Dt_StockInfo>? stockInfos = null, List<Dt_OutSGOrderDetail>? outboundOrderDetails = null, List<Dt_OutStockLockInfo>? outStockLockInfos = null, List<Dt_LocationInfo>? locationInfos = null)
+        {
+            try
+            {
+                _unitOfWorkManage.BeginTran();
+
+                BaseDal.AddData(tasks);
+                if (stockInfos != null && stockInfos.Count > 0 && outboundOrderDetails != null && outboundOrderDetails.Count > 0 && outStockLockInfos != null && outStockLockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0)
+                {
+                    stockInfos.ForEach(x =>
+                    {
+                        x.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                    });
+                    outboundOrderDetails.ForEach(x =>
+                    {
+                        x.OutSGOrderDetailStatus = OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
+                    });
+                    List<Dt_OutSGOrder> outSGOrders = _outboundRepository.OutSGOrderRepository.QueryData(x => outboundOrderDetails.Select(x=>x.OutSGOrderId).Distinct().Contains(x.Id));
+                    if (outSGOrders.Count<=0)
+                    {
+                        throw new Exception("鏈壘鍒板崟鎹俊鎭�");
+                    }
+                    outSGOrders.ForEach(x =>
+                    {
+                        x.OutSGOrderStatus = OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
+                    });
+                    _outboundRepository.OutSGOrderRepository.UpdateData(outSGOrders);
+                    WebResponseContent content = _outboundService.OutSGOrderDetailService.LockOutboundStockDataUpdate(stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos, tasks: tasks);
+                    if (!content.Status)
+                    {
+                        _unitOfWorkManage.RollbackTran();
+                        return content;
+                    }
+                }
+                _unitOfWorkManage.CommitTran();
+                PushTasksToWCS(tasks);
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3