From 8f7e6826d51a25c7b368c210dbb321d423d24a85 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期一, 10 十一月 2025 17:24:12 +0800
Subject: [PATCH] 1

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs |  103 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 73 insertions(+), 30 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 6bf4fec..93056e6 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"
@@ -60,6 +60,7 @@
     private readonly ISys_ConfigService _configService;
     private readonly IDt_OrderOutDetailsRepository _orderOutDetailsRepository;
     private readonly IDt_WareAreaInfoRepository _wareAreaInfoRepository;
+    private readonly IDt_InventoryRecordRepository _inventoryRecordRepository;
 
     public Dt_TaskService(IDt_TaskRepository BaseDal,
                                 IUnitOfWorkManage unitOfWorkManage,
@@ -75,7 +76,8 @@
                                 IDt_StationManagerRepository stationManagerRepository,
                                 ISys_ConfigService configService,
                                 IDt_OrderOutDetailsRepository orderOutDetailsRepository,
-                                IDt_WareAreaInfoRepository wareAreaInfoRepository) : base(BaseDal)
+                                IDt_WareAreaInfoRepository wareAreaInfoRepository,
+                                IDt_InventoryRecordRepository inventoryRecordRepository) : base(BaseDal)
     {
         _unitOfWorkManage = unitOfWorkManage;
         _stockInfoRepository = stockInfoRepository;
@@ -91,6 +93,7 @@
         _configService = configService;
         _orderOutDetailsRepository = orderOutDetailsRepository;
         _wareAreaInfoRepository = wareAreaInfoRepository;
+        _inventoryRecordRepository = inventoryRecordRepository;
     }
 
     #region 澶栭儴鎺ュ彛鏂规硶
@@ -487,6 +490,12 @@
         WebResponseContent content = new WebResponseContent();
         try
         {
+            var task = BaseDal.QueryFirst(x => x.PalletCode == taskDto.PalletCode);
+            if (task != null)
+            {
+                return content.Error("璇ユ墭鐩樺凡缁忓瓨鍦ㄤ换鍔★紝璇峰嬁閲嶅涓嬪彂");
+            }
+
             var boxingInfo = await _boxingInfoRepository.QueryFirstNavAsync(x => x.PalletCode == taskDto.PalletCode && x.StockStatus == (int)StockStateEmun.缁勭洏鏆傚瓨);
 
             if (boxingInfo == null)
@@ -744,14 +753,28 @@
                 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 });
+            List<Dt_InventoryRecord> records = new List<Dt_InventoryRecord>();
+            stcok.StockInfoDetails.ForEach(x =>
+            {
+                records.Add(new Dt_InventoryRecord()
+                {
+                    PalletCode = stcok.PalletCode,
+                    MaterielCode = x.MaterielCode,
+                    MaterielName = x.MaterielName,
+                    Quantity = x.Quantity,
+                    Status = (int)InventoryStatus.Normal,
+                    Remark = remark,
+                });
+            });
 
             var taskDto = CreateListTaskDTO(taskNew);
             var result = GetlcoationState(taskNew, (int)StatusChangeTypeEnum.AutomaticOutbound);
             await _unitOfWorkManage.UseTranAsync(async () =>
             {
-                BaseDal.AddData(taskNew);
-                _stockInfoRepository.UpdateData(stcok);
+                await BaseDal.AddDataAsync(taskNew);
+                await _inventoryRecordRepository.AddDataAsync(records);
+                await _stockInfoRepository.UpdateDataAsync(stcok);
                 await _locationStatusChangeRecordRepository.AddDataAsync(result.Item1);
                 await _locationRepository.UpdateDataAsync(result.Item2);
             });
@@ -966,7 +989,7 @@
         }
         if (!LocationIsOutBound(StartAddress))
         {
-            throw new Exception($"璧风偣搴撲綅{StartAddress.LocationCode}鍑哄簱璺緞琚崰鐢紝璇蜂汉宸ョ‘璁ゅ啀涓嬪彂浠诲姟");
+            throw new Exception($"璧风偣搴撲綅{StartAddress.LocationCode}鍑哄簱璺緞琚崰鐢紝璇风◢鍚庨噸璇�");
         }
         DtLocationInfo location = null;
         if (taskDto.AreaId != 0)
@@ -1238,6 +1261,10 @@
                 //todo鏌ヨ鍐呬晶搴撳瓨淇℃伅
                 var stock = await _stockInfoRepository.QueryFirstAsync(x => x.LocationCode == locationLateral.LocationCode);
 
+                if (stock == null)
+                {
+                    return content.Error($"鏈壘鍒版祬浣峽locationLateral.LocationCode}搴撳瓨淇℃伅");
+                }
                 Dt_Task taskNew = new Dt_Task
                 {
                     Grade = 1,
@@ -1260,7 +1287,6 @@
                 var taskDTO = CreateListTaskDTO(taskNew);
 
                 var isResult = await AddTaskAsync(taskNew, locationLateral, TargetAddress);
-                //UpdateLocationStatus(TargetAddress, LocationEnum.Lock);
                 UpdateLocationStatus(TargetAddress, LocationEnum.Lock, taskNew.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticRelocation);
                 if (!isResult)
                 {
@@ -1333,28 +1359,43 @@
                         return content.Error("璧风偣鏈畾涔夋垨缁堢偣鍖哄煙鏈壘鍒扮┖闂插簱浣�");
                     }
                     //todo鏌ヨ绉诲簱搴撳瓨淇℃伅
-
-                    Dt_Task taskNew = new Dt_Task
+                    var stock = _stockInfoRepository.QueryFirst(x => x.LocationCode == item.LocationCode);
+                    if (stock == null)
                     {
-                        Grade = item.Column,
-                        Roadway = "AGV",
-                        TargetAddress = Targetlocation.LocationCode,
-                        Dispatchertime = DateTime.Now,
-                        MaterialNo = "",
-                        NextAddress = Targetlocation.LocationCode,
-                        OrderNo = null,
-                        PalletCode = _random.Next(0, 10000).ToString(),
-                        SourceAddress = item.LocationCode,
-                        CurrentAddress = item.LocationCode,
-                        TaskState = (int)TaskAGVCarryStatusEnum.CarryNew,
-                        TaskType = (int)TaskRelocationTypeEnum.Relocation,
-                        TaskNum = BaseDal.GetTaskNo().Result,
-                        CreateDate = DateTime.Now,
-                        TaskId = 0,
-                        AGVTaskNum = GenerateUniqueId(),
-                        Floor = item.Floor,
-                        Remark = item.AreaId.ToString(),
-                    };
+                        return content.Error($"鏈壘鍒版祬浣峽item.LocationCode}搴撳瓨淇℃伅");
+                    }
+                    var Relocationtask = BaseDal.QueryFirst(x => x.PalletCode == stock.PalletCode && x.TaskType == (int)TaskRelocationTypeEnum.Relocation);
+                    Dt_Task taskNew = new Dt_Task();
+                    if (Relocationtask != null)
+                    {
+                        taskDTO.Add(CreateTaskDTO(Relocationtask));
+                        //return content.OK(data:taskDTO);
+                        continue;
+                    }
+                    else
+                    {
+                        taskNew = new Dt_Task
+                        {
+                            Grade = item.Column,
+                            Roadway = "AGV",
+                            TargetAddress = Targetlocation.LocationCode,
+                            Dispatchertime = DateTime.Now,
+                            MaterialNo = "",
+                            NextAddress = Targetlocation.LocationCode,
+                            OrderNo = null,
+                            PalletCode = stock.PalletCode,
+                            SourceAddress = item.LocationCode,
+                            CurrentAddress = item.LocationCode,
+                            TaskState = (int)TaskAGVCarryStatusEnum.CarryNew,
+                            TaskType = (int)TaskRelocationTypeEnum.Relocation,
+                            TaskNum = BaseDal.GetTaskNo().Result,
+                            CreateDate = DateTime.Now,
+                            TaskId = 0,
+                            AGVTaskNum = GenerateUniqueId(),
+                            Floor = item.Floor,
+                            Remark = item.AreaId.ToString(),
+                        };
+                    }
                     taskDTO.Add(CreateTaskDTO(taskNew));
 
                     var isResult = await AddTaskAsync(taskNew, item, Targetlocation);
@@ -2062,6 +2103,7 @@
             TaskState = task.TaskState,
             Id = 0,
             TaskType = task.TaskType,
+            Floor =task.Floor,
             AGVTaskNum = task.AGVTaskNum,
         } };
     }
@@ -2080,7 +2122,8 @@
             Id = 0,
             TaskType = task.TaskType,
             AGVTaskNum = task.AGVTaskNum,
-            Remark= task.Remark
+            Remark = task.Remark,
+            Floor = task.Floor,
         };
     }
 
@@ -2264,7 +2307,7 @@
                 TaskNum = task.TaskNum.Value,
                 LocationId = StartAddress.Id,
                 LocationCode = StartAddress.LocationCode,
-                ChangeType = (int)StatusChangeTypeEnum.AutomaticInbound,
+                ChangeType = (int)StatusChangeTypeEnum.AutomaticRelocation,
             },
             new LocationChangeRecordDto()
             {
@@ -2273,7 +2316,7 @@
                 TaskNum = task.TaskNum.Value,
                 LocationId = EndAddress.Id,
                 LocationCode = EndAddress.LocationCode,
-                ChangeType = (int)StatusChangeTypeEnum.AutomaticInbound,
+                ChangeType = (int)StatusChangeTypeEnum.AutomaticRelocation,
             },
         };
 

--
Gitblit v1.9.3