From ed3a236c4ec7f79c9d94b241d3520fcaf1bf2708 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期三, 15 一月 2025 10:10:22 +0800
Subject: [PATCH] 1

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/AssignInboundTaskLocation_BC.cs |  106 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 99 insertions(+), 7 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/AssignInboundTaskLocation_BC.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/AssignInboundTaskLocation_BC.cs"
index 9dcadff..34f74bb 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/AssignInboundTaskLocation_BC.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/AssignInboundTaskLocation_BC.cs"
@@ -5,9 +5,13 @@
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.OrderEnum;
+using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.Helper;
+using WIDESEA_DTO;
+using WIDESEA_DTO.MES;
 using WIDESEA_Model.Models;
 
 namespace WIDESEA_TaskInfoService
@@ -20,11 +24,11 @@
         /// <param name="taskNum">浠诲姟鍙�</param>
         /// <param name="roadwayNos">宸烽亾鍙�</param>
         /// <returns></returns>
-        public WebResponseContent AssignRoadway(List<string> roadwayNos, int taskNum,  int heightType = 0)
+        public WebResponseContent AssignRoadway(List<string> roadwayNos, int taskNum, int heightType = 0)
         {
             try
             {
-                if(heightType == 0 || heightType > 3)
+                if (heightType == 0 || heightType > 3)
                 {
                     return WebResponseContent.Instance.Error($"楂樺害閿欒");
                 }
@@ -89,8 +93,8 @@
                 List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => (x.LocationType == task.PalletType || x.LocationType == LocationTypeEnum.Undefined.ObjToInt()) && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && roadwayNos.Contains(x.RoadwayNo)).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
 
                 string roadwayNo = locationCounts.OrderBy(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
-                
-                return !string.IsNullOrEmpty(roadwayNo) ? WebResponseContent.Instance.OK(data: roadwayNo): WebResponseContent.Instance.Error("鏈壘鍒板彲鍒嗛厤宸烽亾");
+
+                return !string.IsNullOrEmpty(roadwayNo) ? WebResponseContent.Instance.OK(data: roadwayNo) : WebResponseContent.Instance.Error("鏈壘鍒板彲鍒嗛厤宸烽亾");
             }
             catch (Exception ex)
             {
@@ -121,11 +125,99 @@
             }
         }
 
-        public class LocationCount
+        public WebResponseContent HandSubstrateOut(int orderId)
         {
-            public string RoadwayNo { get; set; }
+            try
+            {
+                Dt_MesOutboundOrder mesOutboundOrder = _outboundService.MesOutboundOrderService.Repository.QueryFirst(x => x.Id == orderId);
+                if (mesOutboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌璁㈠崟");
+                }
 
-            public int Count { get; set; }
+                if (mesOutboundOrder.OrderStatus != OutOrderStatusEnum.鏈紑濮�.ObjToInt())
+                {
+                    return WebResponseContent.Instance.Error($"璇ヨ鍗曚笉鍙啀鍑哄簱");
+                }
+
+                List<Dt_Task> tasks = new List<Dt_Task>();
+
+                List<Dt_StockInfo>? stockInfos = null;
+                List<Dt_OutStockLockInfo>? outStockLockInfos = null;
+                List<Dt_LocationInfo>? locationInfos = null;
+                {
+                    (List<Dt_StockInfo>, Dt_MesOutboundOrder, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.MesOutboundOrderService.AssignStockOutbound(mesOutboundOrder);
+                    if (result.Item1 != null && result.Item1.Count > 0)
+                    {
+                        tasks = GetTasks(result.Item1, TaskTypeEnum.MesOutbound);
+                        result.Item2.OrderStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+                        result.Item3.ForEach(x =>
+                        {
+                            x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+                        });
+
+                        stockInfos = result.Item1;
+                        mesOutboundOrder = result.Item2;
+                        outStockLockInfos = result.Item3;
+                        locationInfos = result.Item4;
+                    }
+                    else
+                    {
+                        throw new Exception("鏃犲簱瀛�");
+                    }
+                }
+
+                tasks.ForEach(x =>
+                {
+                    if (mesOutboundOrder.OrderType == MesOutboundOrderTypeEnum.HandSubstrateOut.ObjToInt())
+                    {
+                        x.TaskType = TaskTypeEnum.MesHandOutbound.ObjToInt();
+                    }
+                    else if (mesOutboundOrder.OrderType == MesOutboundOrderTypeEnum.HandSubstrateOutPick.ObjToInt())
+                    {
+                        x.TaskType = TaskTypeEnum.MesHandPickOutbound.ObjToInt();
+                    }
+                });
+
+                mesOutboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
+
+                _unitOfWorkManage.BeginTran();
+
+                int id = BaseDal.AddData(tasks);
+                outStockLockInfos.ForEach(x =>
+                {
+                    x.OrderNo = mesOutboundOrder.TaskNo;
+                    x.OrderDetailId = id;
+                });
+                _outboundService.MesOutboundOrderService.Repository.UpdateData(mesOutboundOrder);
+                if (stockInfos != null && stockInfos.Count > 0 && outStockLockInfos != null && outStockLockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0)
+                {
+                    WebResponseContent content = _outboundService.MesOutboundOrderService.LockOutboundStockDataUpdate(stockInfos, outStockLockInfos, locationInfos, tasks: tasks);
+
+                    if (!content.Status)
+                    {
+                        _unitOfWorkManage.RollbackTran();
+                        return WebResponseContent.Instance.Error(content.Message);
+                    }
+                }
+                _unitOfWorkManage.CommitTran();
+                PushTasksToWCS(tasks);
+
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
         }
+
+
+    }
+
+    public class LocationCount
+    {
+        public string RoadwayNo { get; set; }
+
+        public int Count { get; set; }
     }
 }

--
Gitblit v1.9.3