From 7086c88c6c080aa9ff15664c5c97aee7bbcdc55b Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期三, 05 三月 2025 16:56:11 +0800
Subject: [PATCH] 阻焊仓堆垛机对接

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs |  285 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 246 insertions(+), 39 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
index 8bdc9d9..1eaaae3 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
@@ -17,6 +17,7 @@
 using WIDESEA_Common.LocationEnum;
 using MailKit.Search;
 using WIDESEA_External.Model;
+using WIDESEA_Core.CodeConfigEnum;
 
 namespace WIDESEA_TaskInfoService
 {
@@ -143,6 +144,14 @@
                 (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.OutboundOrderDetailService.AssignStockOutbound(outboundOrderDetail, stockSelectViews);
                 if (result.Item1 != null && result.Item1.Count > 0)
                 {
+                    Dt_OutboundOrder outboundOrder = _outboundService.OutboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetail.OrderId);
+                    TaskTypeEnum typeEnum = outboundOrder.OrderType switch
+                    {
+                        (int)OutOrderTypeEnum.Issue => TaskTypeEnum.Outbound,
+                        (int)OutOrderTypeEnum.Allocate => TaskTypeEnum.OutAllocate,
+                        (int)OutOrderTypeEnum.Quality => TaskTypeEnum.OutQuality,
+                        _ => new TaskTypeEnum()
+                    };
                     tasks = GetTasks(result.Item1, TaskTypeEnum.Outbound);
                     result.Item2.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                     result.Item3.ForEach(x =>
@@ -189,7 +198,7 @@
             {
                 throw new Exception("鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
             }
-            if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus >= OrderDetailStatusEnum.New.ObjToInt())!=null)
+            if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null)
             {
                 throw new Exception("鎵�閫夊嚭搴撳崟鏄庣粏瀛樺湪鍑哄簱涓垨宸插畬鎴�");
             }
@@ -202,7 +211,15 @@
                 (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.OutboundOrderDetailService.AssignStockOutbound(outboundOrderDetails);
                 if (result.Item1 != null && result.Item1.Count > 0)
                 {
-                    tasks = GetTasks(result.Item1, TaskTypeEnum.Outbound);
+                    Dt_OutboundOrder outboundOrder =_outboundService.OutboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId);
+                    TaskTypeEnum typeEnum = outboundOrder.OrderType switch
+                    {
+                        (int)OutOrderTypeEnum.Issue => TaskTypeEnum.Outbound,
+                        (int)OutOrderTypeEnum.Allocate=> TaskTypeEnum.OutAllocate,
+                        (int)OutOrderTypeEnum.Quality => TaskTypeEnum.OutQuality,
+                        _ =>new TaskTypeEnum()
+                    };
+                    tasks = GetTasks(result.Item1, typeEnum);
                     result.Item2.ForEach(x =>
                     {
                         x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
@@ -267,6 +284,7 @@
         {
             try
             {
+                #region MyRegion
                 Dt_OutboundOrderDetail OrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == orderDetailId);
 
                 if (OrderDetail == null)
@@ -355,44 +373,48 @@
                 _stockRepository.StockInfoDetailRepository.UpdateData(upstockDetails);
                 _stockRepository.StockInfoDetailRepository.DeleteData(destockDetails);
                 _unitOfWorkManage.CommitTran();
+                #endregion
 
                 #region 涓婃姤ERP
-                List<ERPPickModel> eRPPickModels = new List<ERPPickModel>();
-                outStockLockInfos.ForEach(x =>
+                if (outboundOrder.OrderStatus == OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt() && outboundOrder.OrderType==OutOrderTypeEnum.Issue.ObjToInt())
                 {
-                    ERPPickItemModel pickItemModel = new ERPPickItemModel()
-                    {
-                        Lotno = x.BatchNo,
-                        Qty = x.AssignQuantity.ToString(),
-                        Location = warehouse.WarehouseCode
-                    };
-                    ERPPickModel pickModel = new ERPPickModel()
-                    {
-                        Rowindex = OrderDetail.RowNo,
-                        Material = OrderDetail.MaterielCode,
-                        Qty = pickItemModel.Qty,
-                        Dataitem = new List<ERPPickItemModel> { pickItemModel }
-                    };
-                    eRPPickModels.Add(pickModel);
-                });
-                ERPIssueItemModel issueItemModel = new ERPIssueItemModel()
-                {
-                    Pickcode = outboundOrder.UpperOrderNo,
-                    PickList = eRPPickModels
-                };
-                ERPIssueModel issueModel = new ERPIssueModel()
-                {
-                    UniqueTag = outboundOrder.Id.ToString(),
-                    Code = outboundOrder.OrderNo,
-                    WarehouseCode = warehouse.WarehouseCode,
-                    Docremark = "",
-                    Deptno = outboundOrder.DepartmentCode,
-                    Deptname = outboundOrder.DepartmentName,
-                    Createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
-                    Createuser = App.User.UserName,
-                    Issitem = new List<ERPIssueItemModel>() { issueItemModel }
-                };
-                _invokeERPService.InvokeOutStandardsApi(issueModel);
+                    //List<ERPPickModel> eRPPickModels = new List<ERPPickModel>();
+                    //outStockLockInfos.ForEach(x =>
+                    //{
+                    //    ERPPickItemModel pickItemModel = new ERPPickItemModel()
+                    //    {
+                    //        Lotno = x.BatchNo,
+                    //        Qty = x.AssignQuantity.ToString(),
+                    //        Location = warehouse.WarehouseCode
+                    //    };
+                    //    ERPPickModel pickModel = new ERPPickModel()
+                    //    {
+                    //        Rowindex = OrderDetail.RowNo,
+                    //        Material = OrderDetail.MaterielCode,
+                    //        Qty = pickItemModel.Qty,
+                    //        Dataitem = new List<ERPPickItemModel> { pickItemModel }
+                    //    };
+                    //    eRPPickModels.Add(pickModel);
+                    //});
+                    //ERPIssueItemModel issueItemModel = new ERPIssueItemModel()
+                    //{
+                    //    Pickcode = outboundOrder.UpperOrderNo,
+                    //    PickList = eRPPickModels
+                    //};
+                    //ERPIssueModel issueModel = new ERPIssueModel()
+                    //{
+                    //    UniqueTag = outboundOrder.Id.ToString(),
+                    //    Code = _outboundService.OutboundOrderService.CreateCodeByRule(nameof(RuleCodeEnum.FLCodeRule)),
+                    //    WarehouseCode = warehouse.WarehouseCode,
+                    //    Docremark = "",
+                    //    Deptno = outboundOrder.DepartmentCode,
+                    //    Deptname = outboundOrder.DepartmentName,
+                    //    Createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                    //    Createuser = App.User.UserName,
+                    //    Issitem = new List<ERPIssueItemModel>() { issueItemModel }
+                    //};
+                    _invokeERPService.InvokeOutStandardsApi(_outboundService.OutboundOrderService.GetERPIssueModel(outboundOrder, warehouse.WarehouseCode));
+                }
                 #endregion
 
                 return WebResponseContent.Instance.OK();
@@ -421,6 +443,10 @@
                 BaseDal.AddData(tasks);
                 if (stockInfos != null && stockInfos.Count > 0 && outboundOrderDetails != null && outboundOrderDetails.Count > 0 && outStockLockInfos != null && outStockLockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0)
                 {
+                    stockInfos.ForEach(x =>
+                    {
+                        x.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                    });
                     WebResponseContent content = _outboundService.OutboundOrderDetailService.LockOutboundStockDataUpdate(stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos, tasks: tasks);
 
                     if (!content.Status)
@@ -455,7 +481,7 @@
         /// </summary>
         /// <param name="keys">鍑哄簱鍗曟槑缁嗕富閿�</param>
         /// <returns></returns>
-        public WebResponseContent GenerateOutboundTask(int[] keys)
+        public WebResponseContent GenerateOutboundTasks(int[] keys)
         {
             try
             {
@@ -509,7 +535,7 @@
             {
                 List<int> keys = _outboundService.OutboundOrderDetailService.Repository.QueryData(x => x.Id, x => x.OrderId == outboundId);
 
-                return GenerateOutboundTask(keys.ToArray());
+                return GenerateOutboundTasks(keys.ToArray());
             }
             catch (Exception ex)
             {
@@ -517,5 +543,186 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
+
+        #region
+        ///// <summary>
+        ///// 鐢熸垚鍑哄簱浠诲姟
+        ///// </summary>
+        ///// <param name="keys">鍑哄簱鍗曟槑缁嗕富閿�</param>
+        ///// <returns></returns>
+        //public WebResponseContent MESPPGenerateOutboundTasks(int[] keys)
+        //{
+        //    try
+        //    {
+        //        List<Dt_Task> tasks = new List<Dt_Task>();
+        //        List<StockSelectViewDTO> stockSelectViews = new List<StockSelectViewDTO>();
+        //        List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>();
+        //        List<Dt_MesPPOutboundOrderDetail> outboundOrderDetails = new List<Dt_MesPPOutboundOrderDetail>();
+        //        List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
+        //        List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+
+        //        (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_MesPPOutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = MESPPOutboundTaskDataHandle(keys);
+        //        if (result.Item2 != null && result.Item2.Count > 0)
+        //        {
+        //            stockInfos.AddRange(result.Item2);
+        //        }
+        //        if (result.Item3 != null && result.Item3.Count > 0)
+        //        {
+        //            outboundOrderDetails.AddRange(result.Item3);
+        //        }
+        //        if (result.Item4 != null && result.Item4.Count > 0)
+        //        {
+        //            outStockLockInfos.AddRange(result.Item4);
+        //        }
+        //        if (result.Item5 != null && result.Item5.Count > 0)
+        //        {
+        //            locationInfos.AddRange(result.Item5);
+        //        }
+        //        if (result.Item1 != null && result.Item1.Count > 0)
+        //        {
+        //            tasks.AddRange(result.Item1);
+        //        }
+
+        //        WebResponseContent content = MESPPGenerateOutboundTaskDataUpdate(tasks, stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos);
+        //        return content;
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        _unitOfWorkManage.RollbackTran();
+        //        return WebResponseContent.Instance.Error(ex.Message);
+        //    }
+        //}
+
+        ///// <summary>
+        ///// 鍑哄簱浠诲姟鏁版嵁澶勭悊
+        ///// </summary>
+        ///// <param name="orderDetailId"></param>
+        ///// <param name="stockSelectViews"></param>
+        ///// <returns></returns>
+        ///// <exception cref="Exception"></exception>
+        //public (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_MesPPOutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) MESPPOutboundTaskDataHandle(int[] keys)
+        //{
+        //    List<Dt_Task> tasks = new List<Dt_Task>();
+        //    List<Dt_MesPPOutboundOrderDetail> outboundOrderDetailss = _outboundService.MesPPOutboundOrderDetailService.Repository.QueryData(x => keys.Contains(x.Id));
+        //    List<Dt_MesPPOutboundOrderDetail> outboundOrderDetails = BaseDal.Db.Queryable<Dt_MesPPOutboundOrderDetail>().Where(x => keys.Contains(x.Id)).ToList();
+        //    if (outboundOrderDetails == null || outboundOrderDetails.Count == 0)
+        //    {
+        //        throw new Exception("鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
+        //    }
+        //    if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null)
+        //    {
+        //        throw new Exception("鎵�閫夊嚭搴撳崟鏄庣粏瀛樺湪鍑哄簱涓垨宸插畬鎴�");
+        //    }
+        //    List<Dt_StockInfo>? stockInfos = null;
+        //    List<Dt_MesPPOutboundOrderDetail>? orderDetails = null;
+        //    List<Dt_OutStockLockInfo>? outStockLockInfos = null;
+        //    List<Dt_LocationInfo>? locationInfos = null;
+        //    //if (outboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+        //    {
+        //        (List<Dt_StockInfo>, List<Dt_MesPPOutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.MesPPOutboundOrderDetailService.AssignStockOutbound(outboundOrderDetails);
+
+        //        if (result.Item1 != null && result.Item1.Count > 0)
+        //        {
+        //            Dt_MesPPOutboundOrder outboundOrder = _outboundService.MesPPOutboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId);
+        //            TaskTypeEnum typeEnum = outboundOrder.OrderType switch
+        //            {
+        //                (int)OutOrderTypeEnum.Issue => TaskTypeEnum.Outbound,
+        //                (int)OutOrderTypeEnum.Allocate => TaskTypeEnum.OutAllocate,
+        //                (int)OutOrderTypeEnum.Quality => TaskTypeEnum.OutQuality,
+        //                _ => new TaskTypeEnum()
+        //            };
+        //            tasks = GetTasks(result.Item1, typeEnum);
+        //            result.Item2.ForEach(x =>
+        //            {
+        //                x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+        //            });
+        //            result.Item3.ForEach(x =>
+        //            {
+        //                x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+        //            });
+
+        //            stockInfos = result.Item1;
+        //            orderDetails = result.Item2;
+        //            outStockLockInfos = result.Item3;
+        //            locationInfos = result.Item4;
+        //        }
+        //        else
+        //        {
+        //            throw new Exception("鏃犲簱瀛�");
+        //        }
+        //    }
+        //    //else
+        //    //{
+        //    //    List<Dt_OutStockLockInfo> stockLockInfos = _outboundService.OutboundStockLockInfoService.GetByOrderDetailId(outboundOrderDetail.OrderId, OutLockStockStatusEnum.宸插垎閰�);
+        //    //    if (stockLockInfos != null && stockLockInfos.Count > 0)
+        //    //    {
+        //    //        List<Dt_StockInfo> stocks = _stockService.StockInfoService.Repository.GetStockInfosByPalletCodes(stockLockInfos.Select(x => x.PalletCode).Distinct().ToList());
+        //    //        tasks = GetTasks(stocks);
+        //    //    }
+        //    //}
+
+        //    return (tasks, stockInfos, orderDetails, outStockLockInfos, locationInfos);
+        //}
+
+        ///// <summary>
+        ///// 鐢熸垚鍑哄簱浠诲姟鍚庢暟鎹洿鏂板埌鏁版嵁搴�
+        ///// </summary>
+        ///// <param name="tasks"></param>
+        ///// <param name="stockInfos"></param>
+        ///// <param name="outboundOrderDetails"></param>
+        ///// <param name="outStockLockInfos"></param>
+        ///// <param name="locationInfos"></param>
+        ///// <returns></returns>
+        //public WebResponseContent MESPPGenerateOutboundTaskDataUpdate(List<Dt_Task> tasks, List<Dt_StockInfo>? stockInfos = null, List<Dt_MesPPOutboundOrderDetail>? outboundOrderDetails = null, List<Dt_OutStockLockInfo>? outStockLockInfos = null, List<Dt_LocationInfo>? locationInfos = null)
+        //{
+        //    try
+        //    {
+        //        _unitOfWorkManage.BeginTran();
+
+        //        BaseDal.AddData(tasks);
+        //        if (stockInfos != null && stockInfos.Count > 0 && outboundOrderDetails != null && outboundOrderDetails.Count > 0 && outStockLockInfos != null && outStockLockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0)
+        //        {
+        //            stockInfos.ForEach(x =>
+        //            {
+        //                x.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+        //            });
+        //            WebResponseContent content = _outboundService.MesPPOutboundOrderDetailService.LockOutboundStockDataUpdate(stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos, tasks: tasks);
+
+        //            if (!content.Status)
+        //            {
+        //                _unitOfWorkManage.RollbackTran();
+        //                return content;
+        //            }
+        //        }
+        //        else if (outboundOrderDetails != null && outboundOrderDetails.Count > 0)
+        //        {
+        //            outboundOrderDetails.ForEach(x =>
+        //            {
+        //                x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+        //            });
+
+        //            _outboundService.MesPPOutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
+        //        }
+        //        _unitOfWorkManage.CommitTran();
+        //        PushTasksToWCS(tasks);
+        //        return WebResponseContent.Instance.OK();
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        _unitOfWorkManage.RollbackTran();
+        //        return WebResponseContent.Instance.Error(ex.Message);
+        //    }
+
+        //}
+        #endregion
+
+
+
+
+
+
+
+
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3