From 6e9f630e4e12738d98241b684e6227e02010b6c5 Mon Sep 17 00:00:00 2001
From: Huangxiaoqiang-03 <1247017146@qq.com>
Date: 星期五, 01 十一月 2024 17:30:30 +0800
Subject: [PATCH] 1

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Outbound.cs |  226 ++++++++++++++++----------------------------------------
 1 files changed, 64 insertions(+), 162 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Outbound.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Outbound.cs"
index 2022f55..897c659 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Outbound.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Outbound.cs"
@@ -11,6 +11,7 @@
 using Microsoft.AspNetCore.Http;
 using System.Reflection.Metadata;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+using SkiaSharp;
 
 namespace WIDESEA_TaskInfoService
 {
@@ -38,7 +39,7 @@
                         Dt_Task task = new()
                         {
                             CurrentAddress = stockInfo.LocationCode,
-                            Grade = 0,
+                            Grade = 2,
                             PalletCode = stockInfo.PalletCode,
                             NextAddress = roadwayInfo.OutSCStationCode,
                             Roadway = locationInfo.RoadwayNo,
@@ -154,17 +155,18 @@
                 WebResponseContent content=new WebResponseContent();
                 _unitOfWorkManage.BeginTran();
                 //鍒ゆ柇绉诲簱
-                content=RelocationTasks(tasks.OrderBy(x=>x.Depth).ToList());
-                if (content.Status)
+                (List<Dt_Task>?, List<Dt_Task>?) result=RelocationTasks(tasks.OrderBy(x=>x.Depth).ToList());
+
+                if(result.Item1 != null)
                 {
-                    _unitOfWorkManage.CommitTran();
+
                 }
-                else
+                for (int i = 0; i < result.Item2.Count; i++)
                 {
-                    _unitOfWorkManage.RollbackTran();
-                    return content;
+
                 }
-                //BaseDal.AddData(tasks);
+
+                
                 if (stockInfos != null && outboundOrderDetails != null && outStockLockInfos != null && locationInfos != null)
                 {
                     content = _outboundService.OutboundOrderDetailService.LockOutboundStockDataUpdate(stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos, tasks: tasks);
@@ -198,90 +200,86 @@
             }
 
         }
-        public WebResponseContent RelocationTasks(List<Dt_Task> task)
+        public (List<Dt_Task>?, List<Dt_Task>?) RelocationTasks(List<Dt_Task> task)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-                _unitOfWorkManage.BeginTran();
+                List<Dt_Task>  tasks = new List<Dt_Task>();
+                List<Dt_Task> relocationList=new List<Dt_Task>();
                 if (task.Count > 0)
                 {
-
                     for (int i = 0; i < task.Count; i++)
                     {
                         Dt_LocationInfo location = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task[i].SourceAddress && x.RoadwayNo == task[i].Roadway);
+                        int befoStatus=location.LocationStatus.ObjToInt();
                         if (location != null)
                         {
-                            //(Dt_LocationInfo?, int?) result = _basicService.LocationInfoService.isDepth(location);
-                            (Dt_LocationInfo?, int?) result = isDepth(location);
-                            if (result.Item1 != null && result.Item2 != LocationStatusEnum.Lock.ObjToInt() && result.Item2 != LocationStatusEnum.PalletLock.ObjToInt() && result.Item2 != LocationStatusEnum.Free.ObjToInt())
+                            Dt_LocationInfo result = isDepth(location);
+                            if (result != null && result.LocationStatus == LocationStatusEnum.Lock.ObjToInt() && result.LocationStatus != LocationStatusEnum.PalletLock.ObjToInt() && result.LocationStatus != LocationStatusEnum.Free.ObjToInt())
                             {
                                 int sum = 0;
                                 for (int j = 0; j < task.Count; j++)
                                 {
-                                    if (result.Item1.LocationCode == task[j].SourceAddress)
+                                    if (result.LocationCode == task[j].SourceAddress)
                                     {
                                         sum++;
                                     }
                                 }
                                 if (sum == 0)
                                 {
-                                    return content = RelocationTask(task[i]);
+                                    Dt_Task relocariontask = RelocationTask(result);
+                                    task[i].Grade=1;
+                                    tasks.Add(task[i]);
+                                    relocationList.Add(relocariontask);
                                 }
                                 else
                                 {
-                                    BaseDal.AddData(task[i]);
-                                    _basicService.LocationInfoService.UpdateLocationLock(location, task[i].TaskNum, StockChangeType.Outbound.ObjToInt(), true);
+                                    tasks.Add(task[i]);
+                                    content = WebResponseContent.Instance.OK();
                                 }
                             }
-                            else if (result.Item1 == null && result.Item2 == LocationStatusEnum.Free.ObjToInt())
+                            else if (result == null)
                             {
-                                BaseDal.AddData(task[i]);
-                                location.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
-                                _basicService.LocationInfoService.UpdateData(location);
+                                tasks.Add(task[i]);
                                 content = WebResponseContent.Instance.OK();
                             }
-                            else if (result.Item1 != null && result.Item2 == LocationStatusEnum.Free.ObjToInt())
+                            else if (result != null && result.LocationStatus == LocationStatusEnum.Free.ObjToInt())
                             {
-                                BaseDal.AddData(task[i]);
-                                location.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
-                                _basicService.LocationInfoService.UpdateData(location);
-                                _basicService.LocationInfoService.UpdateLocationLock(location, task[i].TaskNum, StockChangeType.Outbound.ObjToInt(), false);
+                                tasks.Add(task[i]);
                                 content = WebResponseContent.Instance.OK();
                             }
-                            else if (result.Item1 != null && (result.Item2 == LocationStatusEnum.Lock.ObjToInt() || result.Item2 == LocationStatusEnum.PalletLock.ObjToInt()))
+                            else if (result != null && (result.LocationStatus == LocationStatusEnum.Lock.ObjToInt() || result.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt()))
                             {
-                                Dt_Task TaskInfo = BaseDal.QueryFirst(x => x.SourceAddress == result.Item1.LocationCode);
+                                Dt_Task TaskInfo = BaseDal.QueryFirst(x => x.SourceAddress == result.LocationCode);
                                 if (TaskInfo == null)
                                 {
-                                    return content = WebResponseContent.Instance.Error("璐т綅琚攣瀹氫笉鍙嚭搴�");
+                                    content = WebResponseContent.Instance.Error("璐т綅琚攣瀹氫笉鍙嚭搴�");
+                                    break;
                                 }
                                 else
                                 {
-                                    BaseDal.AddData(task[i]);
-                                    location.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
-                                    _basicService.LocationInfoService.UpdateData(location);
+                                    tasks.Add(task[i]);
                                     content = WebResponseContent.Instance.OK();
                                 }
                             }
                         }
                         else
                         {
-                            return content = WebResponseContent.Instance.Error("浠诲姟寮傚父");
+                            content = WebResponseContent.Instance.Error("浠诲姟寮傚父");
+                            break;
                         }
                     }
+                    return (tasks, relocationList);
                 }
                 else
                 {
-                    return content = WebResponseContent.Instance.Error("娌℃湁搴撳瓨鐢熸垚浠诲姟");
+                    throw new Exception($"鐢熸垚绉诲簱浠诲姟澶辫触");
                 }
-                _unitOfWorkManage.CommitTran();
-                return content;
             }
             catch (Exception ex)
             {
-                _unitOfWorkManage.RollbackTran();
-                return content = WebResponseContent.Instance.Error(ex.Message);
+                return (null, null);
             }
          }
         /// <summary>
@@ -289,111 +287,46 @@
         /// </summary>
         /// <param name="task"></param>
         /// <returns></returns>
-        public WebResponseContent RelocationTask(Dt_Task task)
+        public Dt_Task RelocationTask(Dt_LocationInfo location)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress && x.RoadwayNo == task.Roadway);
-                if (locationInfo != null)
+                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == location.LocationCode);
+                if (stockInfo != null)
                 {
-                    int beforeStatus = locationInfo.LocationStatus;
-                    //(Dt_LocationInfo?,int?) Result = _basicService.LocationInfoService.isDepth(locationInfo);
-                    (Dt_LocationInfo?,int?) Result = isDepth(locationInfo);
-                    if (Result.Item1 != null&& Result.Item2== LocationStatusEnum.InStock.ObjToInt())
+                    Dt_LocationInfo? locationInfos = _basicService.LocationInfoService.AssignLocation(location.RoadwayNo);
+                    if (locationInfos != null)
                     {
-                        Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == Result.Item1.LocationCode);
-                        Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId==stockInfo.Id);
-                        if (stockInfo != null&& stockInfoDetail != null)
+                        Dt_Task tasks = new()
                         {
-                            (Dt_Task ?, Dt_LocationInfo ?) result= AddRelocationTask(Result.Item1, stockInfo, task); 
-                            if (result.Item1!=null&&result.Item2!=null)
-                            {
-                                _basicService.LocationInfoService.RelocationLock(Result.Item1, result.Item2, result.Item1.TaskNum);
-                                locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
-                                _basicService.LocationInfoService.UpdateData(locationInfo);
-                                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Relocation.ObjToInt(), "", task.TaskNum);
-                                return content = WebResponseContent.Instance.OK();
-                            }
-                            else
-                            {
-                                return content = WebResponseContent.Instance.Error("绉诲簱浠诲姟鐢熸垚澶辫触");
-                            }
-                        } 
-                        else
-                        {
-                            return content = WebResponseContent.Instance.Error("鏈壘鍒板簱瀛樹俊鎭�");
-                        }
-                    }
-                    else if(Result.Item1 != null && Result.Item2 == LocationStatusEnum.Pallet.ObjToInt())
-                    {
-                        Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == Result.Item1.LocationCode);
-                        if (stockInfo != null)
-                        {
-                            (Dt_Task?, Dt_LocationInfo?) result = AddRelocationTask(Result.Item1, stockInfo, task);
-                            if (result.Item1 != null && result.Item2 != null)
-                            {
-                                _basicService.LocationInfoService.RelocationLock(Result.Item1, result.Item2, result.Item1.TaskNum);
-                                locationInfo.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt();
-                                _basicService.LocationInfoService.UpdateData(locationInfo);
-                                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Relocation.ObjToInt(), "", task.TaskNum);
-                                return content = WebResponseContent.Instance.OK();
-                            }
-                            else
-                            {
-                                return content = WebResponseContent.Instance.Error("绉诲簱浠诲姟鐢熸垚澶辫触");
-                            }
-                        }
-                        else
-                        {
-                            return content = WebResponseContent.Instance.Error("鏈壘鍒板簱瀛樹俊鎭�");
-                        }
+                            CurrentAddress = location.LocationCode,
+                            Grade = 0,
+                            PalletCode = stockInfo.PalletCode,
+                            NextAddress = locationInfos.LocationCode,
+                            Roadway = location.RoadwayNo,
+                            SourceAddress = location.LocationCode,
+                            TargetAddress = locationInfos.LocationCode,
+                            TaskStatus = InTaskStatusEnum.RelocationNew.ObjToInt(),
+                            TaskType = TaskTypeEnum.Relocation.ObjToInt(),
+                            TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum))
+                        };
+                        return tasks;
                     }
                     else
                     {
-                        return content = WebResponseContent.Instance.Error("寮傚父");
+                        throw new Exception($"鐢熸垚绉诲簱浠诲姟澶辫触");
                     }
                 }
                 else
                 {
-                    return content = WebResponseContent.Instance.Error("浠诲姟淇℃伅寮傚父");
+                    throw new Exception("鏈壘鍒板簱瀛樹俊鎭�");
                 }
             }
             catch (Exception ex)
             {
-                return content = WebResponseContent.Instance.Error(ex.Message);
+                throw new Exception($"鐢熸垚绉诲簱浠诲姟澶辫触"); ;
             }
-            finally
-            {
-                
-            }
-
-            
-        }
-        public (Dt_Task?,Dt_LocationInfo?) AddRelocationTask(Dt_LocationInfo location,Dt_StockInfo stockInfo,Dt_Task task)
-        {
-            Dt_LocationInfo? locationInfos = _basicService.LocationInfoService.AssignLocation(location.RoadwayNo);
-            if (locationInfos != null)
-            {
-                Dt_Task tasks = new()
-                {
-                    CurrentAddress = location.LocationCode,
-                    Grade = 0,
-                    PalletCode = stockInfo.PalletCode,
-                    NextAddress = locationInfos.LocationCode,
-                    Roadway = location.RoadwayNo,
-                    SourceAddress = location.LocationCode,
-                    TargetAddress = locationInfos.LocationCode,
-                    TaskStatus = InTaskStatusEnum.RelocationNew.ObjToInt(),
-                    TaskType = TaskTypeEnum.Relocation.ObjToInt(),
-                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum))
-                };
-                BaseDal.AddData(tasks);
-                BaseDal.AddData(task);
-                stockInfo.StockStatus = StockStatusEmun.绉诲簱閿佸畾.ObjToInt();
-                _stockService.StockInfoService.UpdateData(stockInfo);
-            }
-            return (task, locationInfos);
         }
         /// <summary>
         /// 鐢熸垚鍑哄簱浠诲姟
@@ -508,7 +441,7 @@
             }
         }
 
-        public (Dt_LocationInfo?, int?) isDepth(Dt_LocationInfo locationInfo)
+        public Dt_LocationInfo isDepth(Dt_LocationInfo locationInfo)
         {
             if (locationInfo.Depth == 2)
             {
@@ -516,26 +449,11 @@
                 {
                     Dt_LocationInfo dt_LocationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.Row == locationInfo.Row + 1 && x.Layer == locationInfo.Layer && x.Column == locationInfo.Column && x.RoadwayNo == locationInfo.RoadwayNo);
 
-                    if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+                    if (dt_LocationInfo != null)
                     {
-                        return (dt_LocationInfo, LocationStatusEnum.InStock.ObjToInt());
+                        return dt_LocationInfo;
                     }
-                    if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Free.ObjToInt())
-                    {
-                        return (dt_LocationInfo, LocationStatusEnum.Free.ObjToInt());
-                    }
-                    if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt())
-                    {
-                        return (dt_LocationInfo, LocationStatusEnum.Lock.ObjToInt());
-                    }
-                    if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt())
-                    {
-                        return (dt_LocationInfo, LocationStatusEnum.PalletLock.ObjToInt());
-                    }
-                    if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Pallet.ObjToInt())
-                    {
-                        return (dt_LocationInfo, LocationStatusEnum.Pallet.ObjToInt());
-                    }
+                    
                 }
                 else if (locationInfo.Row == 4 || locationInfo.Row == 8)
                 {
@@ -543,27 +461,11 @@
 
                     if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
                     {
-                        return (dt_LocationInfo, LocationStatusEnum.InStock.ObjToInt());
-                    }
-                    if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Free.ObjToInt())
-                    {
-                        return (dt_LocationInfo, LocationStatusEnum.Free.ObjToInt());
-                    }
-                    if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt())
-                    {
-                        return (dt_LocationInfo, LocationStatusEnum.Lock.ObjToInt());
-                    }
-                    if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt())
-                    {
-                        return (dt_LocationInfo, LocationStatusEnum.PalletLock.ObjToInt());
-                    }
-                    if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Pallet.ObjToInt())
-                    {
-                        return (dt_LocationInfo, LocationStatusEnum.Pallet.ObjToInt());
+                        return dt_LocationInfo;
                     }
                 }
             }
-            return (null, LocationStatusEnum.Free.ObjToInt());
+            return null;
         }
     }
 }

--
Gitblit v1.9.3