From 4fc31b41c205507607c91ab3afe10fbc06a9aa09 Mon Sep 17 00:00:00 2001
From: yangpeixing <yangpeixing@hnkhzn.com>
Date: 星期五, 05 十二月 2025 13:52:15 +0800
Subject: [PATCH] 1.添加启动提升机、停止提升机、复位提升机功能 2.优化初始化提升机功能

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs |  190 ++++++++++++++++++++++++++---------------------
 1 files changed, 105 insertions(+), 85 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 971962b..2d9ccaa 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"
@@ -17,6 +17,7 @@
 using System.Reflection;
 using System.Reflection.Metadata;
 using System.Security.Policy;
+using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using WIDESEA_Cache;
@@ -105,6 +106,13 @@
         WebResponseContent content = new WebResponseContent();
         try
         {
+            if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.CarryGroup)
+            {
+                var result1 = UpdateLocationStatus(task.SourceAddress, LocationEnum.Free, task.TaskNum.Value, StatusChangeTypeEnum.AutomaticOutbound);
+                await _locationStatusChangeRecordRepository.AddDataAsync(result1.Item1);
+                await _locationRepository.UpdateDataAsync(result1.Item2);
+            }
+
             task.TaskState = (int)TaskOutStatusEnum.OutFinish;
             var taskHty = task.Adapt<Dt_Task_Hty>();
             taskHty.FinishTime = DateTime.Now;
@@ -113,14 +121,15 @@
             stock.ModifyDate = DateTime.Now;
             stock.LocationCode = task.TargetAddress;
             var result2 = UpdateLocationStatus(task.TargetAddress, LocationEnum.InStock, task.TaskNum.Value, StatusChangeTypeEnum.AutomaticOutbound);
+
             DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>();
             var orderDetails = _orderOutDetailsRepository.QueryData(x => x.PalletCode == task.PalletCode);
             List<Dt_OrderOutDetails_Hty> orderdetailshtys = new List<Dt_OrderOutDetails_Hty>();
 
             orderDetails.ForEach(item =>
-            {
-                orderdetailshtys.Add(item.Adapt<Dt_OrderOutDetails_Hty>());
-            });
+        {
+            orderdetailshtys.Add(item.Adapt<Dt_OrderOutDetails_Hty>());
+        });
 
             await ERPAllocateOut(stock);
 
@@ -172,8 +181,9 @@
                 boxingInfo.BoxingInfoDetails = mergedDetails;
             }
 
-            await _unitOfWorkManage.UseTranAsync(async () =>
-            {
+            //await _unitOfWorkManage.UseTranAsync(async () =>
+            //{
+            _unitOfWorkManage.BeginTran();
                 await DeleteStockInfoAsync(stock.Id);
                 _boxingInfoRepository.UpdateDataNav(boxingInfo);
                 await DeleteStockInfoDetailsAsync(stock.StockInfoDetails);
@@ -185,12 +195,14 @@
 
                 await DeleteTaskAsync(task.TaskId);
                 await AddTaskHtyAsync(taskHty);
-            });
+            _unitOfWorkManage.CommitTran();
+            //});
             content.OK("鍑哄簱瀹屾垚");
 
         }
         catch (Exception ex)
         {
+            _unitOfWorkManage.RollbackTran();
             task.ErrorMessage = ex.Message;
             await BaseDal.UpdateDataAsync(task);
             return content.Error(ex.Message);
@@ -268,7 +280,15 @@
             {
                 return content.Error("鏈壘鍒扮粍鐩樻暟鎹�");
             }
-            await ERPAllocate(boxinfo);
+
+            if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.CarryGroup)
+            {
+                var result1 = UpdateLocationStatus(task.SourceAddress, LocationEnum.Free, task.TaskNum.Value, StatusChangeTypeEnum.AutomaticInbound);
+                await _locationStatusChangeRecordRepository.AddDataAsync(result1.Item1);
+                await _locationRepository.UpdateDataAsync(result1.Item2);
+            }
+
+            
 
             var stock = CreateStock(boxinfo, task);
 
@@ -280,18 +300,22 @@
 
             var result2 = UpdateLocationStatus(task.TargetAddress, LocationEnum.InStock, task.TaskNum.Value, StatusChangeTypeEnum.AutomaticInbound);
 
-            await _unitOfWorkManage.UseTranAsync(async () =>
-            {
-                await _stockInfoRepository.AddDataNavAsync(stock);
+            //await _unitOfWorkManage.UseTranAsync(async () =>
+            //{
+            _unitOfWorkManage.BeginTran();
+            await _stockInfoRepository.AddDataNavAsync(stock);
                 await DeleteTaskAsync(task.TaskId);
                 await AddTaskHtyAsync(taskHty);
                 await _locationStatusChangeRecordRepository.AddDataAsync(result2.Item1);
                 await _locationRepository.UpdateDataAsync(result2.Item2);
-            });
+            _unitOfWorkManage.CommitTran();
+            //});
+            await ERPAllocate(boxinfo);
             content.OK("鍏ュ簱瀹屾垚");
         }
         catch (Exception ex)
         {
+            _unitOfWorkManage.RollbackTran();
             task.ErrorMessage = ex.Message;
             await BaseDal.UpdateDataAsync(task);
             return content.Error(ex.Message);
@@ -339,64 +363,6 @@
         };
     }
     #endregion 鍏ュ簱浠诲姟瀹屾垚
-
-    #region AGV鎼繍浠诲姟瀹屾垚
-    public async Task<WebResponseContent> CompleteCarryTaskAsync(Dt_Task task,DtStockInfo stockInfo)
-    {
-        WebResponseContent content = new WebResponseContent();
-        try
-        {
-            var Sourcelocation = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.SourceAddress);
-            var Targetlocation = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress);
-
-            //UpdateLocationStatus(Sourcelocation, LocationEnum.Free);
-            //UpdateLocationStatus(Targetlocation, LocationEnum.InStock);
-
-            task.TaskState = (int)TaskAGVCarryStatusEnum.CarryFinish;
-            var taskHty = task.Adapt<Dt_Task_Hty>();
-            taskHty.FinishTime = DateTime.Now;
-            taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.浜哄伐瀹屾垚 : (int)OperateTypeEnum.鑷姩瀹屾垚;
-            taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System";
-            await _unitOfWorkManage.UseTranAsync(async () =>
-            {
-                await DeleteTaskAsync(task.TaskId);
-                await AddTaskHtyAsync(taskHty);
-            });
-        }
-        catch (Exception ex)
-        {
-            return content.Error(ex.Message);
-        }
-        return content;
-    }
-
-    #endregion
-
-    #region AGV璺ㄦゼ灞備换鍔″畬鎴�
-    public async Task<WebResponseContent> CompleteAcrossFloorTaskAsync(Dt_Task task, DtStockInfo stockInfo)
-    {
-        WebResponseContent content = new WebResponseContent();
-        try
-        {
-            task.TaskState = (int)TaskAcrossFloorStatusEnum.CarryFinish;
-            var taskHty = task.Adapt<Dt_Task_Hty>();
-            taskHty.FinishTime = DateTime.Now;
-            taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.浜哄伐瀹屾垚 : (int)OperateTypeEnum.鑷姩瀹屾垚;
-            taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System";
-            await _unitOfWorkManage.UseTranAsync(async () =>
-            {
-                await DeleteTaskAsync(task.TaskId);
-                await AddTaskHtyAsync(taskHty);
-            });
-        }
-        catch (Exception ex)
-        {
-            return content.Error(ex.Message);
-        }
-        return content;
-    }
-
-    #endregion
 
     #region 浠诲姟瀹屾垚
 
@@ -499,14 +465,14 @@
                 return content.Error("鎵樼洏淇℃伅涓嶅瓨鍦紝璇风‘璁ゆ墭鐩樺凡缁勭洏鎴愬姛");
             }
 
-            foreach (var item in boxingInfo.BoxingInfoDetails)
-            {
-                var ERPStock = SqlSugarHelper.DBERP.Queryable<鐢ㄥ弸鍗虫椂搴撳瓨_ST>().Where(x => x.瀛樺偍鍦扮偣鍚嶇О == item.Warehouse && x.鏂欏彿 == item.MaterielCode && x.鍝佸悕 == item.MaterielName && x.搴撳瓨鏁伴噺 >= item.Quantity).ToList().FirstOrDefault();
-                if (ERPStock == null)
-                {
-                    return content.Error($"缁勭洏鏁版嵁鏈湪ERP搴撳瓨鏁版嵁涓紝璇蜂汉宸ョ‘璁ゆ暟鎹槸鍚︽纭�");
-                }
-            }
+            //foreach (var item in boxingInfo.BoxingInfoDetails)
+            //{
+            //    var ERPStock = SqlSugarHelper.DBERP.Queryable<鐢ㄥ弸鍗虫椂搴撳瓨_ST>().Where(x => x.瀛樺偍鍦扮偣鍚嶇О == item.Warehouse && x.鏂欏彿 == item.MaterielCode && x.鍝佸悕 == item.MaterielName && x.搴撳瓨鏁伴噺 >= item.Quantity).ToList().FirstOrDefault();
+            //    if (ERPStock == null)
+            //    {
+            //        return content.Error($"缁勭洏鏁版嵁鏈湪ERP搴撳瓨鏁版嵁涓紝璇蜂汉宸ョ‘璁ゆ暟鎹槸鍚︽纭�");
+            //    }
+            //}
 
             var StartAddress = await _locationRepository.QueryFirstAsync(x => x.LocationCode == taskDto.Position);
             if (StartAddress == null)
@@ -543,6 +509,7 @@
                 case 4:
                 case 5:
                 case 6:
+                case 7:
                     taskNew = InboundAGVCacheArea(taskDto, StartAddress, area);
                     break;
                 default:
@@ -554,6 +521,12 @@
 
             await _unitOfWorkManage.UseTranAsync(async () =>
             {
+                if (taskDto.AreaId == 3 || taskDto.AreaId == 7)
+                {
+                    var result2 = UpdateLocationStatus(taskNew.TargetAddress, LocationEnum.Lock, taskNew.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticInbound);
+                    await _locationStatusChangeRecordRepository.AddDataAsync(result2.Item1);
+                    await _locationRepository.UpdateDataAsync(result2.Item2);
+                }
                 await _locationStatusChangeRecordRepository.AddDataAsync(result.Item1);
                 await _locationRepository.UpdateDataAsync(result.Item2);
                 BaseDal.AddData(taskNew);
@@ -649,7 +622,7 @@
     /// </summary>
     /// <param name="palletCode"></param>
     /// <returns></returns>
-    public async Task<WebResponseContent> OutBoundTaskAsync(string palletCode,string remark)
+    public async Task<WebResponseContent> OutBoundTaskAsync(string palletCode,string remark,int doubleTray)
     {
         WebResponseContent content = new WebResponseContent();
         try
@@ -676,7 +649,7 @@
                 return content.Error("璇ユ墭鐩樺簱瀛樺凡鍦ㄥ嚭搴撶紦瀛樺尯");
             }
 
-            Dt_Task taskNew = await RequestOutboundTaskAsync(new RequestTaskDto { PalletCode = palletCode, AreaId = 2, Position = stcok.LocationCode, TaskType = (int)TaskOutboundTypeEnum.Outbound });
+            Dt_Task taskNew = await RequestOutboundTaskAsync(new RequestTaskDto { PalletCode = palletCode, AreaId = 2, Position = stcok.LocationCode, TaskType = (int)TaskOutboundTypeEnum.Outbound, DoubleTray= doubleTray });
             List<Dt_InventoryRecord> records = new List<Dt_InventoryRecord>();
             stcok.StockInfoDetails.ForEach(x =>
             {
@@ -692,7 +665,7 @@
             });
 
             var taskDto = CreateListTaskDTO(taskNew);
-            var result = GetlcoationState(taskNew, StatusChangeTypeEnum.AutomaticOutbound);
+            var result = GetlcoationState(taskNew, StatusChangeTypeEnum.AutomaticOutbound, location);
             await _unitOfWorkManage.UseTranAsync(async () =>
             {
                 await BaseDal.AddDataAsync(taskNew);
@@ -709,6 +682,12 @@
         }
     }
 
+
+    /// <summary>
+    /// 鍏朵粬鍑哄簱
+    /// </summary>
+    /// <param name="details"></param>
+    /// <returns></returns>
 
     public async Task<WebResponseContent> OtherOutBoundTaskAsync(List<DtStockInfoDetail> details)
     {
@@ -761,7 +740,7 @@
             stock.StockInfoDetails = details;
 
             var taskDto = CreateListTaskDTO(taskNew);
-            var result = GetlcoationState(taskNew, StatusChangeTypeEnum.AutomaticOutbound);
+            var result = GetlcoationState(taskNew, StatusChangeTypeEnum.AutomaticOutbound, stock.LocationInfo);
             await _unitOfWorkManage.UseTranAsync(async () =>
             {
                 await BaseDal.AddDataAsync(taskNew);
@@ -844,7 +823,7 @@
             stock.StockInfoDetails = details;
 
             var taskDto = CreateListTaskDTO(taskNew);
-            var result = GetlcoationState(taskNew, StatusChangeTypeEnum.AutomaticOutbound);
+            var result = GetlcoationState(taskNew, StatusChangeTypeEnum.AutomaticOutbound, stock.LocationInfo);
             await _unitOfWorkManage.UseTranAsync(async () =>
             {
                 await BaseDal.AddDataAsync(taskNew);
@@ -861,13 +840,20 @@
         }
     }
 
-    public (List<DtLocationStatusChangeRecord>,List<DtLocationInfo>) GetlcoationState(Dt_Task task, StatusChangeTypeEnum StatusChangeTypeEnum)
+    public (List<DtLocationStatusChangeRecord>,List<DtLocationInfo>) GetlcoationState(Dt_Task task, StatusChangeTypeEnum StatusChangeTypeEnum, DtLocationInfo location)
     {
         List<DtLocationStatusChangeRecord> locationStatusChangeRecords = new List<DtLocationStatusChangeRecord>();
         List<DtLocationInfo> locations = new List<DtLocationInfo>();
         var result = UpdateLocationStatus(task.SourceAddress, LocationEnum.InStockDisable, task.TaskNum.Value, (int)StatusChangeTypeEnum);
         locationStatusChangeRecords.AddRange(result.Item1);
         locations.AddRange(result.Item2);
+
+        if(location.AreaId ==3|| location.AreaId == 7)
+        {
+            var result2 = UpdateLocationStatus(task.TargetAddress, LocationEnum.Lock, task.TaskNum.Value, (int)StatusChangeTypeEnum);
+            locationStatusChangeRecords.AddRange(result2.Item1);
+            locations.AddRange(result2.Item2);
+        }
 
         return (locationStatusChangeRecords,locations);
     }
@@ -915,6 +901,7 @@
             case 4:
             case 5:
             case 6:
+            case 7:
                 return OutboundAGVCacheArea(taskDto, StartAddress, area);
             default:
                 throw new Exception("璇烽�夋嫨姝g‘鐨勫尯鍩熶俊鎭�");
@@ -1126,6 +1113,7 @@
             Remark = StartAddress.AreaId.ToString(),
             AGVTaskNum = GenerateUniqueId(),
             Floor = StartAddress.Floor,
+            DoubleTray = taskDto.DoubleTray,
         };
 
     }
@@ -1272,6 +1260,7 @@
             switch (location.AreaId)
             {
                 case 2:
+                case 7:
                     locationInfos = _locationRepository.QueryData(x => x.Row == location.Row && x.Column > location.Column && x.Remark == location.Remark && x.AreaId == location.AreaId);
                     break;
                 case 5:
@@ -1407,6 +1396,7 @@
                 case 4:
                 case 5:
                 case 6:
+                case 7:
                     locationInfo = await GetAGVEmptyCacheLocation(areaInfo.AreaID, location);
                     break;
                 default:
@@ -2012,6 +2002,32 @@
         return (changeRecordDto, locations);
     }
 
+    public (DtLocationStatusChangeRecord, DtLocationInfo) UpdateEndLocationStatus(string locationCode, LocationEnum locationStatus, int taskNum, StatusChangeTypeEnum StatusChangeType)
+    {
+        var location = _locationRepository.QueryFirst(x => x.LocationCode == locationCode);
+
+        if (location != null && (location.AreaId == 3 || location.AreaId == 7))
+        {
+            int Beforelocation = location.LocationStatus;
+
+            location.LocationStatus = (int)locationStatus;
+
+            DtLocationStatusChangeRecord dtLocationStatusChangeRecord = new DtLocationStatusChangeRecord()
+            {
+                ChangeType = (int)StatusChangeType,
+                LocationCode = locationCode,
+                LocationId = location.Id,
+                Creater = "System",
+                TaskNum = taskNum,
+                AfterStatus = location.LocationStatus,
+                BeforeStatus = Beforelocation,
+            };
+
+            return (dtLocationStatusChangeRecord, location);
+        }
+        return (null, null);
+    }
+
     public (DtLocationStatusChangeRecord, DtLocationInfo) UpdateLocationStatus(string locationCode, LocationEnum locationStatus, int taskNum, StatusChangeTypeEnum StatusChangeType)
     {
         var location = _locationRepository.QueryFirst(x => x.LocationCode == locationCode);
@@ -2048,7 +2064,7 @@
                 }
             }
         }
-        else if (location.AreaId == 2)
+        else if (location.AreaId == 2 || location.AreaId == 7)
         {
             var locationLateral = _locationRepository.QueryData(x => x.Row == location.Row && x.Column > location.Column && x.Remark == location.Remark);
             if (locationLateral.Count > 0)
@@ -2086,6 +2102,7 @@
             TaskType = task.TaskType,
             Floor =task.Floor,
             AGVTaskNum = task.AGVTaskNum,
+            DoubleTray = task.DoubleTray,
         } };
     }
 
@@ -2105,6 +2122,7 @@
             AGVTaskNum = task.AGVTaskNum,
             Remark = task.Remark,
             Floor = task.Floor,
+            DoubleTray = task.DoubleTray,
         };
     }
     private List<WMSTaskDTO> CreateTaskDTO(List<Dt_Task> task)
@@ -2126,6 +2144,7 @@
                 AGVTaskNum = item.AGVTaskNum,
                 Remark = item.Remark,
                 Floor = item.Floor,
+                DoubleTray = item.DoubleTray,
             });
         }
 
@@ -2422,6 +2441,7 @@
         switch (AreaId)
         {
             case 2:
+            case 7:
                 return await FromShallowToDeep(AreaId, loc);
             case 3:
                 return await AGVLIKU(AreaId);
@@ -2553,7 +2573,7 @@
             }
         }
 
-        else if (location.AreaId == 2)
+        else if (location.AreaId == 2 || location.AreaId == 7)
         {
             var locationLateral = _locationRepository.QueryData(x => x.Row == location.Row && x.Column > location.Column && x.Remark == location.Remark);
 

--
Gitblit v1.9.3