From 733c975cd8647f6d006736f1863bad731e32e6fb Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期日, 26 十月 2025 17:15:52 +0800
Subject: [PATCH] 上传最新代码,ERP接口,MES接口优化,WMS业务优化等

---
 项目代码/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Outbound.cs |  482 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 418 insertions(+), 64 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..2b514ef 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"
@@ -22,6 +22,9 @@
 using WIDESEA_DTO.ERP;
 using WIDESEA_Common.MaterielEnum;
 using WIDESEA_Common.WareHouseEnum;
+using WIDESEA_DTO.MES;
+using WIDESEA_DTO.Outbound;
+using Microsoft.IdentityModel.Tokens;
 
 namespace WIDESEA_TaskInfoService
 {
@@ -32,46 +35,79 @@
         /// </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)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 鍚慦MS鐢宠鍑哄簱AGV缁堢偣
+        /// </summary>
+        /// <param name="taskNum">浠诲姟鍙�</param>
+        /// <returns></returns>
+        public WebResponseContent AssignOutTargetAddress(int taskNum)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+                if (task == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鍏ュ簱浠诲姟");
+                }
+                if (_agvStationInfoRepository.QueryFirst(x => x.AGVStationCode == task.TargetAddress) != null)
+                {
+                    return WebResponseContent.Instance.OK(data: task.TargetAddress);
+                }
+                Dt_AGVStationInfo? aGVStationInfo = _agvStationInfoRepository.QueryData(x => x.StationArea == nameof(AGVStationAreaEnum.涓�妤兼湀鍙扮爜澶�) && x.IsOccupied == WhetherEnum.False.ObjToInt()).OrderByDescending(x => x.Depth).FirstOrDefault();
+                if (aGVStationInfo==null)
+                {
+                    return content.Error("鏈壘鍒板彲鍒嗛厤鐨勫嚭搴撶珯鐐�");
+                }
+                aGVStationInfo.IsOccupied = WhetherEnum.True.ObjToInt();
+                _agvStationInfoRepository.UpdateData(aGVStationInfo);
+                content.OK("鎴愬姛",data: aGVStationInfo.AGVStationCode);
             }
             catch (Exception ex)
             {
@@ -126,8 +162,17 @@
                     {
                         task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                         _unitOfWorkManage.BeginTran();
-                        stockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
-                        _stockRepository.StockInfoRepository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId > 0 ? WIDESEA_Core.Enums.OperateTypeEnum.浜哄伐瀹屾垚 : WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚);
+                        if (task.TaskType == TaskTypeEnum.OldYLOutbound.ObjToInt())
+                        {
+                            stockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+                            stockInfo.WarehouseId = WarehouseEnum.LLDOldCache.ObjToInt();
+                            _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+                        }
+                        else
+                        {
+                            stockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+                            _stockRepository.StockInfoRepository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId > 0 ? WIDESEA_Core.Enums.OperateTypeEnum.浜哄伐瀹屾垚 : WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚);
+                        }
                         _basicService.LocationInfoService.UpdateLocationStatus(locationInfoStart, stockInfo.PalletType, LocationStatusEnum.Free, stockInfo.WarehouseId);
                         BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? WIDESEA_Core.Enums.OperateTypeEnum.浜哄伐瀹屾垚 : WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚);
                         _unitOfWorkManage.CommitTran();
@@ -146,7 +191,7 @@
             }
         }
         /// <summary>
-        /// 搴撳瓨鏁版嵁杞嚭搴撲换鍔�
+        /// 搴撳瓨鏁版嵁杞嚭搴撲换鍔�(鍘熸枡/鍗婃垚鍝�)
         /// </summary>
         /// <param name="stockInfos"></param>
         /// <returns></returns>
@@ -177,6 +222,7 @@
                             PalletType = stockInfo.PalletType,
                             WarehouseId = stockInfo.WarehouseId,
                             MaterielCode = stockInfo.MaterielCode,
+                            RfidCode = stockInfo.RfidCode,
                             Quantity = stockInfo.StockLength,
                         };
                         if (stockInfo.MaterielWide>0)
@@ -189,6 +235,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,25 +276,39 @@
         /// 鎴愬搧鍑哄簱
         /// </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
             {
                 List<Dt_AGVStationInfo> aGVStationInfos = _agvStationInfoRepository.QueryData(x=>x.StationArea == targetId && x.IsOccupied==WhetherEnum.False.ObjToInt());
-                if (aGVStationInfos.Count< Count)
+                int useCount=aGVStationInfos.Count;
+                if (targetId == nameof(AGVStationAreaEnum.涓�妤兼湀鍙扮爜澶�))
+                {
+
+                    //鑾峰彇鎵�鏈夋湀鍙板嚭搴撲换鍔�
+                    List<Dt_Task> _TasksOut = BaseDal.QueryData(x => x.TaskType == TaskTypeEnum.OutProduct.ObjToInt() && x.TargetAddress == nameof(AGVStationAreaEnum.涓�妤兼湀鍙扮爜澶�));
+                    useCount -= _TasksOut.Count;
+                }
+                if (useCount < Count)
                 {
                     return content.Error($"鍙敤缂撳瓨鏁颁笉瓒�");
                 }
                 //鑾峰彇璐т綅
                 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,19 +326,40 @@
                 }
                 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,
+                    nameof(AGVStationAreaEnum.涓�妤肩焊寮犳穻鑶�) => TaskTypeEnum.OutPaperLM,
+                    nameof(AGVStationAreaEnum.涓�妤煎垎鍒�) => TaskTypeEnum.OutFenQie,
+                    nameof(AGVStationAreaEnum.涓�妤兼ā鍒�) => TaskTypeEnum.OutMoQie,
+                    nameof(AGVStationAreaEnum.涓�妤煎啿鍒�) => TaskTypeEnum.OutChongQie,
+                    nameof(AGVStationAreaEnum.浜屾ゼ绾歌) => TaskTypeEnum.OutCarton,
                     _ => throw new Exception("鏈壘鍒板搴斾换鍔�")
                 };
+                if (materialCode == "1" && typeEnum!= TaskTypeEnum.OutCarton)
+                {
+                    typeEnum = TaskTypeEnum.OutEmpty;
+                }
                 List<Dt_Task> tasks = GetTasks(stockInfos, typeEnum, AssignLocations);
                 if (tasks == null || tasks.Count <= 0)
                 {
                     return content.Error($"鐢熸垚浠诲姟澶辫触");
                 }
-                for (int i = 0; i < tasks.Count; i++)
+                //鎴愬搧浠诲姟涓嶇洿鎺ュ垎閰嶇粓鐐�
+                if (targetId != nameof(AGVStationAreaEnum.涓�妤兼湀鍙扮爜澶�))
                 {
-                    aGVStationInfos[i].IsOccupied = WhetherEnum.True.ObjToInt();
-                    tasks[i].TargetAddress = aGVStationInfos[i].AGVStationCode;
+                    for (int i = 0; i < tasks.Count; i++)
+                    {
+                        aGVStationInfos[i].IsOccupied = WhetherEnum.True.ObjToInt();
+                        tasks[i].TargetAddress = aGVStationInfos[i].AGVStationCode;
+                    }
+                }
+                else
+                {
+                    for (int i = 0; i < tasks.Count; i++)
+                    {
+                        tasks[i].TargetAddress = nameof(AGVStationAreaEnum.涓�妤兼湀鍙扮爜澶�);
+                    }
                 }
                 //鍒ゆ柇鏄惁鏈夊嚭搴撳崟淇℃伅
                 _unitOfWorkManage.BeginTran();
@@ -306,19 +390,22 @@
         /// <param name="materielWide">鐗╂枡骞呭</param>
         /// <param name="Count">鍗锋暟</param>
         /// <returns></returns>
-        public WebResponseContent RequestYLWMSTaskOut(string materielCode, int materielWide, int Count, string address = "")
+        public WebResponseContent RequestYLWMSTaskOut(YLWMSTaskOutDTO yLWMSTaskOutDTO)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-
+                if (yLWMSTaskOutDTO==null)
+                {
+                    return content.Error("璇峰~鍏ュ嚭搴撲俊鎭�");
+                }
                 //鑾峰彇璐т綅
                 List<Dt_LocationInfo> locationInfos = _basicRepository.LocationInfoRepository.QueryData(x => x.WarehouseId == WarehouseEnum.LLDYL.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt());
                 //鑾峰彇瀵瑰簲搴撳瓨
-                List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.QueryData(x=> locationInfos.Select(x=>x.LocationCode).Contains(x.LocationCode) && x.MaterielCode==materielCode && x.MaterielWide== materielWide && x.StockStatus==StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()).OrderBy(x=>x.CreateDate).Take(Count).ToList();
-                if (stockInfos.Count< Count)
+                List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.QueryData(x => locationInfos.Select(x => x.LocationCode).Contains(x.LocationCode) && x.MaterielCode == yLWMSTaskOutDTO.MaterialCode && x.MaterielWide == yLWMSTaskOutDTO.Wide && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() && x.MaterielInvOrgId == MaterielInvOrgEnum.鏂板巶.ObjToInt()).OrderBy(x => x.CreateDate).Take(yLWMSTaskOutDTO.Count).ToList();
+                if (stockInfos.Count< yLWMSTaskOutDTO.Count)
                 {
-                    return content.Error($"搴撳瓨{materielCode}鏁伴噺涓嶈冻");
+                    return content.Error($"搴撳瓨{yLWMSTaskOutDTO.MaterialCode}鏁伴噺涓嶈冻");
                 }
                 List<Dt_LocationInfo> AssignLocations =new List<Dt_LocationInfo>();
                 foreach (var item in stockInfos)
@@ -330,27 +417,21 @@
                         item.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
                     }
                 }
-                //鍖哄垎浠诲姟
-                TaskTypeEnum taskTypeEnum = new();
-                if (stockInfos.FirstOrDefault()?.MaterielInvOrgId==MaterielInvOrgEnum.鑰佸巶.ObjToInt())
-                {
-                    taskTypeEnum = TaskTypeEnum.OldYLOutbound;
-                }
-                else
-                {
-                    taskTypeEnum = TaskTypeEnum.PrintYLOutbound;
-                }
-                List<Dt_Task> tasks = GetTasks(stockInfos, taskTypeEnum);
+                List<Dt_Task> tasks = GetTasks(stockInfos, TaskTypeEnum.PrintYLOutbound);
                 if (tasks == null || tasks.Count <= 0)
                 {
                     return content.Error($"鐢熸垚浠诲姟澶辫触");
                 }
-                if (!string.IsNullOrEmpty(address))
+                if (!string.IsNullOrEmpty(yLWMSTaskOutDTO.Address))
                 {
                     tasks.ForEach(x =>
                     {
-                        x.TargetAddress= address;
+                        x.TargetAddress= yLWMSTaskOutDTO.Address;
                     });
+                }
+                else
+                {
+                    return content.Error("鍦板潃淇℃伅涓嶈兘涓虹┖");
                 }
                 //鍒ゆ柇鏄惁鏈夊嚭搴撳崟淇℃伅
                 _unitOfWorkManage.BeginTran();
@@ -523,5 +604,278 @@
             }
 
         }
+        /// <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);
+        }
+        /// <summary>
+        /// 澶勭悊鍑哄簱鏁版嵁
+        /// </summary>
+        /// <returns></returns>
+        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();
+
+                if (outStockLockInfos != null && outStockLockInfos.Any())
+                {
+                    tasks.ForEach(x =>
+                    {
+                        string orderNos = string.Join(",", outStockLockInfos.Where(x => x.PalletCode == x.PalletCode).Select(x => x.OrderNo).Distinct());
+                        x.OrderNo = orderNos;
+                    });
+                }
+                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);
+            }
+
+        }
+        List<string> GradeCodes = new List<string>
+        {
+            "001"
+        };
+        /// <summary>
+        /// 鎺ユ敹MES棰嗘枡璁″垝
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent ReceiveOutBound(List<OutMESOrderDTO> outMESOrderDTOs)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                if (outMESOrderDTOs == null || outMESOrderDTOs.Count <= 0)
+                {
+                    return content.Error("棰嗘枡璁″垝浼犲叆淇℃伅涓虹┖");
+                }
+                outMESOrderDTOs.Select(x => x.OutDetailId);
+                List<Dt_Warehouse> warehouses = _basicRepository.WarehouseRepository.QueryData();
+                OutMESOrderDTO? CheckGradeCode = outMESOrderDTOs.FirstOrDefault(x => !GradeCodes.Contains(x.GradeCode));
+                if (CheckGradeCode != null)
+                {
+                    return content.Error($"棰嗘枡璁″垝搴撳尯{nameof(OutMESOrderDTO.GradeCode)}:{CheckGradeCode.GradeCode}涓嶅瓨鍦�");
+                }
+                OutMESOrderDTO? CheckOutDetailId = outMESOrderDTOs.FirstOrDefault(x => x.OutDetailId <= 0);
+                if (CheckOutDetailId != null)
+                {
+                    return content.Error($"棰嗘枡璁″垝{nameof(OutMESOrderDTO.OutDetailId)}:{CheckOutDetailId.ProductOrderNo}闇�瑕佸ぇ浜�0");
+                }
+                OutMESOrderDTO? CheckReqQuantity = outMESOrderDTOs.FirstOrDefault(x => x.ReqQuantity <= 0);
+                if (CheckReqQuantity != null)
+                {
+                    return content.Error($"棰嗘枡璁″垝{nameof(OutMESOrderDTO.ReqQuantity)}:{CheckReqQuantity.ProductOrderNo}闇�瑕佸ぇ浜�0");
+                }
+                //鑾峰彇鎵�鏈夌墿鏂欎俊鎭�
+                List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x => x.MaterielInvOrgId == MaterielInvOrgEnum.鏂板巶.ObjToInt());
+                //鑾峰彇鎵�鏈夐鏂欒鍒�
+                List<Dt_OutMESOrder> outMESOrders = _outboundRepository.OutMESOrderRepository.QueryData();
+
+                OutMESOrderDTO? CheckMaterialCode = outMESOrderDTOs.FirstOrDefault(x => !materielInfos.Select(x => x.MaterielCode).Contains(x.MaterialCode));
+                if (CheckMaterialCode != null)
+                {
+                    return content.Error($"鐗╂枡缂栫爜{nameof(OutMESOrderDTO.MaterialCode)}:{CheckMaterialCode.MaterialCode}淇℃伅涓嶅瓨鍦�");
+                }
+                Dt_OutMESOrder? OldoutMESOrder = outMESOrders.FirstOrDefault(x => outMESOrderDTOs.Select(x => x.OutDetailId).Contains(x.OutDetailId));
+                if (OldoutMESOrder != null)
+                {
+                    return content.Error($"棰嗘枡璁″垝{nameof(OutMESOrderDTO.OutDetailId)}:{OldoutMESOrder.OutDetailId}淇℃伅宸插瓨鍦�");
+                }
+                List<Dt_OutMESOrder> AddoutMESOrders = outMESOrderDTOs.Select(x => _mapper.Map<Dt_OutMESOrder>(x)).ToList();
+                foreach (var item in AddoutMESOrders)
+                {
+                    Dt_MaterielInfo materielInfo = materielInfos.FirstOrDefault(x => x.MaterielCode == item.MaterialCode);
+                    item.WarehouseId = materielInfo.WarehouseId;
+                }
+
+                
+                _unitOfWorkManage.BeginTran();
+
+                _outboundRepository.OutMESOrderRepository.AddData(AddoutMESOrders);
+
+                List<Dt_Task> tasks = new List<Dt_Task>();
+                List<Dt_StockInfo>? stockInfos = null;
+                List<Dt_OutMESOrder>? Orders = null;
+                List<Dt_OutStockLockInfo>? outStockLockInfos = null;
+                List<Dt_LocationInfo>? locationInfos = null;
+                {
+                    //鍒嗛厤搴撳瓨
+                    (List<Dt_StockInfo>, List<Dt_OutMESOrder>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.OutMESOrderService.AssignStockOutbound(AddoutMESOrders);
+                    if (result.Item1 != null && result.Item1.Count > 0)
+                    {
+                        //鍒涘缓浠诲姟
+                        tasks = GetTasks(result.Item1, TaskTypeEnum.PrintYLOutbound);
+                        result.Item2.ForEach(x =>
+                        {
+                            OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
+                        });
+                        result.Item3.ForEach(x =>
+                        {
+                            x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+                        });
+
+                        stockInfos = result.Item1;
+                        Orders = result.Item2;
+                        outStockLockInfos = result.Item3;
+                        locationInfos = result.Item4;
+                    }
+                    else
+                    {
+                        throw new Exception("鏃犲簱瀛�");
+                    }
+                }
+                int id = BaseDal.AddData(tasks);
+
+                if (stockInfos != null && stockInfos.Count > 0 && outStockLockInfos != null && outStockLockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0)
+                {
+                    WebResponseContent contentResponse = _outboundService.OutMESOrderService.LockOutboundStockDataUpdate(stockInfos, Orders, outStockLockInfos, locationInfos, tasks: tasks);
+
+                    if (!contentResponse.Status)
+                    {
+                        _unitOfWorkManage.RollbackTran();
+                        return content.Error(contentResponse.Message);
+                    }
+                }
+
+                _unitOfWorkManage.CommitTran();
+                
+                return content.OK("鎺ユ敹鎴愬姛");
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3