From baad30699918c536d0b96e36df70b8f352d520e4 Mon Sep 17 00:00:00 2001
From: 刘磊 <1161824510@qq.com>
Date: 星期五, 15 八月 2025 10:15:53 +0800
Subject: [PATCH] 同步

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs |  181 ++++++++++++++++++++++++---------------------
 1 files changed, 97 insertions(+), 84 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs"
index d57a2d1..e5deb00 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs"
@@ -131,9 +131,10 @@
         WebResponseContent content = new WebResponseContent();
         try
         {
-            // 鏇存柊搴撲綅鐘舵�佷笌浠诲姟鐘舵��
-            var stock = _palletStockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+            //鏌ユ壘搴撳瓨
+            var stock = await _palletStockInfoRepository.QueryFirstNavAsync(x => x.PalletCode == task.PalletCode);
 
+            // 鏇存柊搴撲綅鐘舵�佷笌浠诲姟鐘舵��
             (var loc, var tas) = UpdateStockAndTaskStatus(stock, task);
             var taskHty = task.Adapt<Dt_Task_Hty>();
             taskHty.FinishTime = DateTime.Now;
@@ -258,7 +259,6 @@
 
     #endregion 澶栭儴鎺ュ彛鏂规硶
 
-
     #region 浠诲姟鐘舵�佹洿鏀�
 
     /// <summary>
@@ -319,93 +319,106 @@
             string palletCode = saveModel.MainData["palletCode"].ToString();
             string station = saveModel.MainData["station"].ToString();
 
-            // 鏌ヨ搴撳瓨淇℃伅
-            var stockInfo = _palletStockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
-            if (stockInfo == null)
+            var barcode = JsonConvert.DeserializeObject<List<string>>(saveModel.MainData["palletCode"].ToString());
+
+            if (barcode == null && barcode.Count == 0) throw new Exception($"鏃犳墭鐩樺弬鏁�,璇烽噸璇�!");
+
+            foreach (var item in barcode)
             {
-                return content.Error("鏈煡璇㈠埌瀵瑰簲鐨勫簱瀛樹俊鎭�");
+                // 鏌ヨ搴撳瓨淇℃伅
+                var stockInfo = _palletStockInfoRepository.QueryFirst(x => x.PalletCode == item);
+
+                if (stockInfo == null)
+                {
+                    return content.Error("鏈煡璇㈠埌瀵瑰簲鐨勫簱瀛樹俊鎭�");
+                }
+
+                if (stockInfo.StockStatus != 2) return content.Error($"鎸囧畾澶辫触锛氭墭鐩榹item}褰撳墠鐘舵�佷笉鍏佽鎸囧畾鍑哄簱");
+
+                stockInfo.StockStatus = 3;
+
+                //鏌ヨ搴撲綅鏄惁閿佸畾锛�
+                var location = _locationRepository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
+
+                if (location.LocationStatus == (int)LocationEnum.Lock) return content.Error("搴撲綅閿佸畾,璇峰厛瑙i攣鍚庡啀鎸囧畾鍑哄簱");
+
+                location.LocationStatus = (int)LocationEnum.InStockDisable;
+
+                var task = BaseDal.QueryFirst(x => x.PalletCode == palletCode);
+                if (task != null)
+                {
+                    return content.Error($"銆恵item}銆戝凡瀛樺湪浠诲姟");
+                }
+
+                var stationInfo = _stationManagerRepository.QueryFirst(x => x.stationChildCode == station);
+
+                if (stationInfo.Roadway != stockInfo.AreaCode) throw new Exception($"褰撳墠鎵樼洏{item}涓庝笅鏂欎綅涓嶅悓鍖哄煙锛岃閲嶆柊閫夋嫨锛�");
+
+                // 鍒涘缓骞舵坊鍔犱换鍔″埌鏁版嵁搴�
+                string agvId = Guid.NewGuid().ToString().Replace("-", "").Take(16);
+                task = new Dt_Task
+                {
+                    Grade = 1,
+                    Roadway = stationInfo.Roadway,
+                    TargetAddress = stationInfo.stationLocation,
+                    Dispatchertime = DateTime.Now,
+                    MaterialNo = "",
+                    NextAddress = stationInfo.stationLocation,
+                    OrderNo = null,
+                    PalletCode = stockInfo.PalletCode,
+                    SourceAddress = stockInfo.LocationCode,
+                    CurrentAddress = stockInfo.LocationCode,
+                    TaskState = (int)TaskOutStatusEnum.OutNew,
+                    TaskType = (int)TaskOutboundTypeEnum.Outbound,
+                    TaskNum = BaseDal.GetTaskNo().Result,
+                    Creater = "System",
+                    CreateDate = DateTime.Now,
+                    TaskId = 0,
+                    AGVtaskId = agvId
+                };
+
+
+                addtask schedulingTask = new addtask
+                {
+                    task_id = task.AGVtaskId,
+                    task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? "push" : "pop",
+                    work_begin = task.SourceAddress,
+                    work_end = task.TargetAddress
+                };
+
+                string address = AGV_Interface + "add_task";
+
+                string result = HttpsClient.PostAsync(address, schedulingTask.ToDictionary()).Result;
+
+                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+
+                if (content.ack != 0)
+                {
+                    Console.WriteLine($"璇锋眰RCS寮傚父锛歿content.msg}");
+                    LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"\r\r--------------------------------------");
+                    LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"璇锋眰鍙傛暟锛歿schedulingTask.ToJsonString()}");
+                    LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"鍝嶅簲鍙傛暟锛歿content.ToJsonString()}");
+                    throw new Exception(content.msg);
+                }
+
+                _unitOfWorkManage.BeginTran();
+                // 娣诲姞浠诲姟鍒版暟鎹簱
+                BaseDal.AddData(task);
+                // 鏇存柊搴撲綅浣嶇疆鐘舵�佷负涓嶅彲鐢�
+                _locationRepository.UpdateData(location);
+                _palletStockInfoRepository.UpdateData(stockInfo);
+
+                _unitOfWorkManage.CommitTran();
             }
-
-            if (stockInfo.StockStatus != 2) return content.Error("鎸囧畾澶辫触锛氬綋鍓嶇姸鎬佷笉鍏佽鎸囧畾鍑哄簱");
-
-            stockInfo.StockStatus = 3;
-
-            //鏌ヨ搴撲綅鏄惁閿佸畾锛�
-            var location = _locationRepository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
-
-            if (location.LocationStatus == (int)LocationEnum.Lock) return content.Error("搴撲綅閿佸畾,璇峰厛瑙i攣鍚庡啀鎸囧畾鍑哄簱");
-
-            location.LocationStatus = (int)LocationEnum.InStockDisable;
-
-            var task = BaseDal.QueryFirst(x => x.PalletCode == palletCode);
-            if (task != null)
-            {
-                return content.Error($"銆恵palletCode}銆戝凡瀛樺湪浠诲姟");
-            }
-
-            var stationInfo = _stationManagerRepository.QueryFirst(x => x.stationChildCode == station);
-
-
-            // 鍒涘缓骞舵坊鍔犱换鍔″埌鏁版嵁搴�
-            string agvId = Guid.NewGuid().ToString().Replace("-", "").Take(16);
-            task = new Dt_Task
-            {
-                Grade = 1,
-                Roadway = stationInfo.Roadway,
-                TargetAddress = stationInfo.stationLocation,
-                Dispatchertime = DateTime.Now,
-                MaterialNo = "",
-                NextAddress = stationInfo.stationLocation,
-                OrderNo = null,
-                PalletCode = stockInfo.PalletCode,
-                SourceAddress = stockInfo.LocationCode,
-                CurrentAddress = stockInfo.LocationCode,
-                TaskState = (int)TaskOutStatusEnum.OutNew,
-                TaskType = (int)TaskOutboundTypeEnum.Outbound,
-                TaskNum = BaseDal.GetTaskNo().Result,
-                Creater = "System",
-                CreateDate = DateTime.Now,
-                TaskId = 0,
-                AGVtaskId = agvId
-            };
-
-
-            addtask schedulingTask = new addtask
-            {
-                task_id = task.AGVtaskId,
-                task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? "push" : "pop",
-                work_begin = task.SourceAddress,
-                work_end = task.TargetAddress
-            };
-
-            string address = AGV_Interface + "add_task";
-
-            string result = HttpsClient.PostAsync(address, schedulingTask.ToDictionary()).Result;
-
-            content = JsonConvert.DeserializeObject<WebResponseContent>(result);
-
-            if (content.ack != 0)
-            {
-                Console.WriteLine($"璇锋眰RCS寮傚父锛歿content.msg}");
-                LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"\r\r--------------------------------------");
-                LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"璇锋眰鍙傛暟锛歿schedulingTask.ToJsonString()}");
-                LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"鍝嶅簲鍙傛暟锛歿content.ToJsonString()}");
-                throw new Exception(content.msg);
-            }
-
-            _unitOfWorkManage.BeginTran();
-            // 娣诲姞浠诲姟鍒版暟鎹簱
-            BaseDal.AddData(task);
-            // 鏇存柊搴撲綅浣嶇疆鐘舵�佷负涓嶅彲鐢�
-            _locationRepository.UpdateData(location);
-            _palletStockInfoRepository.UpdateData(stockInfo);
-
-            _unitOfWorkManage.CommitTran();
+            
+            content.OK();
         }
         catch (Exception ex)
         {
             _unitOfWorkManage.RollbackTran();
-            Console.WriteLine($"鍙戠敓寮傚父: {ex.Message}");
+            Console.WriteLine($"鎸囧畾鍑哄簱寮傚父: {ex.Message}");
+            LogFactory.GetLog("鎸囧畾鍑哄簱寮傚父").Info(true, $"\r\r--------------------------------------");
+            LogFactory.GetLog("鎸囧畾鍑哄簱寮傚父").Info(true, $"璇锋眰鍙傛暟锛歿saveModel.ToJsonString()}");
             content.Error(ex.Message);
         }
         return content;

--
Gitblit v1.9.3