From 844c7c3ce2c39139490a6ecb0f35170f6cade290 Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期二, 28 四月 2026 16:31:54 +0800
Subject: [PATCH] 1

---
 WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  379 +++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 261 insertions(+), 118 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
index f40feae..b0eb149 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -24,25 +24,35 @@
 using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using Org.BouncyCastle.Asn1.Tsp;
 using Spire.Pdf;
+using Spire.Pdf;
 using SqlSugar;
+using System;
+using System;
 using System;
 using System;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations;
+using System.Diagnostics;
 using System.Diagnostics.CodeAnalysis;
 using System.Drawing.Printing;
+using System.Drawing.Printing;
+using System.IO;
 using System.IO;
 using System.Linq;
+using System.Net.Http;
 using System.Net.Http;
 using System.Reflection;
 using System.Reflection.Metadata;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
+using System.Threading.Tasks;
 using WIDESEA_BasicRepository;
 using WIDESEA_Common;
+using WIDESEA_Common.Log;
 using WIDESEA_Common.Log;
 using WIDESEA_Common.OrderEnum;
 using WIDESEA_Common.TaskEnum;
@@ -54,6 +64,7 @@
 using WIDESEA_Core.TaskEnum;
 using WIDESEA_DTO.Basic;
 using WIDESEA_DTO.ERP;
+using WIDESEA_DTO.ERP;
 using WIDESEA_DTO.Inbound;
 using WIDESEA_DTO.Stock;
 using WIDESEA_DTO.Task;
@@ -62,6 +73,7 @@
 using WIDESEA_IInboundRepository;
 using WIDESEA_IInboundService;
 using WIDESEA_InboundRepository;
+using WIDESEA_InboundRepository;
 using WIDESEA_IOutboundRepository;
 using WIDESEA_IOutboundService;
 using WIDESEA_IRecordService;
@@ -69,8 +81,10 @@
 using WIDESEA_IStockService;
 using WIDESEA_ITaskInfoRepository;
 using WIDESEA_ITaskInfoService;
+using WIDESEA_Model;
 using WIDESEA_Model.Models;
 using WIDESEA_Model.Models.Inbound;
+using WIDESEA_OutboundRepository;
 using WIDESEA_OutboundRepository;
 using WIDESEA_StockRepository;
 using WIDESEA_TaskInfoRepository;
@@ -78,26 +92,13 @@
 using static WIDESEA_Common.HouseBackboundPassBack;
 using static WIDESEA_Common.HouseInboundPassBack;
 using static WIDESEA_Common.HouseInboundPassBack.data.data1;
+using static WIDESEA_Common.HouseInboundPassBack.data.data1;
 using static WIDESEA_Common.HouseoutboundPassBack;
 using static WIDESEA_Common.InventoryAllocate;
 using static WIDESEA_Common.NewHouseInboundPassBack;
 using static WIDESEA_Common.NewHouseInboundPassBack.Parame.Syncretism;
 using static WIDESEA_ITaskInfoService.ITaskService;
 using Parameter = WIDESEA_Common.Parameter;
-using WIDESEA_DTO.ERP;
-using WIDESEA_OutboundRepository;
-using System.ComponentModel.DataAnnotations;
-using System;
-using System.IO;
-using System.Net.Http;
-using System.Threading.Tasks;
-using Spire.Pdf;
-using WIDESEA_InboundRepository;
-using System.Drawing.Printing;
-using System;
-using WIDESEA_Common.Log;
-using static WIDESEA_Common.HouseInboundPassBack.data.data1;
-using System.Diagnostics;
 
 namespace WIDESEA_TaskInfoService
 {
@@ -131,9 +132,11 @@
         private readonly IInboundRepository _inboundRepository;
         private readonly ITakeStockOrderCPRepository _takeStockOrderCPRepository;
         private readonly ITakeStockOrderDetailCPRepository _takeStockOrderDetailCPRepository;
+        private readonly IHubContext<WMSNoticeHub> _hubContext;
         public ITaskRepository Repository => BaseDal;
 
-        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IMaterielInfoService materielInfoService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IOutboundOrder_HtyService outboundOrder_HtyService, IOutboundOrderDetail_HtyService outboundOrderDetail_HtyService, IInboundOrder_HtyService inboundOrder_HtyService, IStockRepository stockRepository, IInboundOrderDetailService inboundOrderDetailService, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IBasicRepository basicRepository, IStockInfoDetailRepository stockInfoDetailRepository, IPalletTypeInfoRepository palletTypeInfoRepository, IReturnOrderRepository returnOrderRepository, IProductionRepository productionRepository, IInboundRepository inboundRepository, INewOutboundOrderDetailRepository newOutboundOrderDetailRepository, ITakeStockOrderCPRepository takeStockOrderCPRepository, ITakeStockOrderDetailCPRepository takeStockOrderDetailCPRepository, IStockInfoDetailCPRepository stockInfoDetailCPRepository) : base(BaseDal)
+        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IMaterielInfoService materielInfoService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IOutboundOrder_HtyService outboundOrder_HtyService, IOutboundOrderDetail_HtyService outboundOrderDetail_HtyService, IInboundOrder_HtyService inboundOrder_HtyService, IStockRepository stockRepository, IInboundOrderDetailService inboundOrderDetailService, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IBasicRepository basicRepository, IStockInfoDetailRepository stockInfoDetailRepository, IPalletTypeInfoRepository palletTypeInfoRepository, IReturnOrderRepository returnOrderRepository, IProductionRepository productionRepository, IInboundRepository inboundRepository, INewOutboundOrderDetailRepository newOutboundOrderDetailRepository, ITakeStockOrderCPRepository takeStockOrderCPRepository, ITakeStockOrderDetailCPRepository takeStockOrderDetailCPRepository, IStockInfoDetailCPRepository stockInfoDetailCPRepository,
+          IHubContext<WMSNoticeHub> hubContext) : base(BaseDal)
         {
             _mapper = mapper;
             _stockRepository = stockRepository;
@@ -162,6 +165,7 @@
             _takeStockOrderCPRepository = takeStockOrderCPRepository;
             _takeStockOrderDetailCPRepository = takeStockOrderDetailCPRepository;
             _stockInfoDetailCPRepository = stockInfoDetailCPRepository;
+            _hubContext = hubContext;
         }
 
         public string ReceiveWMSTaskin = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskin"];
@@ -809,7 +813,14 @@
                                         // 鍒ゆ柇Success鐨勫��
                                         if (!response.Success)
                                         {
+                                            WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = houseInboundPassBack, 鎺ユ敹鎶ユ枃 = response });
+
                                             throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
+                                        }
+                                        else
+                                        {
+                                            WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = houseInboundPassBack, 鎺ユ敹鎶ユ枃 = response });
+
                                         }
 
                                     }
@@ -887,7 +898,14 @@
                                         var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskAllocatein, inventoryAllocate, "璋冩嫧鍏ュ簱鏁伴噺鍥炰紶WMS");
                                         if (!response.Success)
                                         {
+                                            WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = inventoryAllocate, 鎺ユ敹鎶ユ枃 = response });
+
                                             throw new Exception($"鎿嶄綔澶辫触锛歿response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
+                                        }
+                                        else
+                                        {
+                                            WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = inventoryAllocate, 鎺ユ敹鎶ユ枃 = response });
+
                                         }
                                     }
                                 }
@@ -949,16 +967,23 @@
                                     if (authResult.IsSuccess)
                                     {
                                         houseSyncretism.Context = new Dictionary<string, string>
-                                            {
-                                                { "Ticket", authResult.Ticket },
-                                                { "InvOrgId", authResult.InvOrgId }
+                                        {
+                                            { "Ticket", authResult.Ticket },
+                                            { "InvOrgId", authResult.InvOrgId }
 
-                                            };
+                                        };
 
                                         var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskin, houseSyncretism, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
                                         if (!response.Success)
                                         {
+                                            WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = houseSyncretism, 鎺ユ敹鎶ユ枃 = response });
+
                                             throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
+                                        }
+                                        else
+                                        {
+                                            WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = houseSyncretism, 鎺ユ敹鎶ユ枃 = response });
+
                                         }
 
                                     }
@@ -1498,20 +1523,24 @@
             if (authResult.IsSuccess)
             {
                 houseInboundPassBack.Context = new Dictionary<string, string>
-            {
-                { "Ticket", authResult.Ticket },
-                { "InvOrgId", authResult.InvOrgId }
-            };
+                {
+                    { "Ticket", authResult.Ticket },
+                    { "InvOrgId", authResult.InvOrgId }
+                };
 
                 var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskin, houseInboundPassBack, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
                 // 鍒ゆ柇Success鐨勫��
                 if (response.Success)
                 {
+                    WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = houseInboundPassBack, 鎺ユ敹鎶ユ枃 = response });
+
                     // 濡傛灉Success涓簍rue锛岃繑鍥為渶瑕佺殑鍊硷紙杩欓噷浠ヨ繑鍥炴暣涓搷搴斿璞′负渚嬶級
                     return WebResponseContent.Instance.OK();
                 }
                 else
                 {
+                    WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = houseInboundPassBack, 鎺ユ敹鎶ユ枃 = response });
+
                     // 濡傛灉Success涓篺alse锛屾姏鍑哄紓甯稿苟鍖呭惈閿欒淇℃伅
                     throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
                 }
@@ -1558,19 +1587,23 @@
             if (authResult.IsSuccess)
             {
                 houseReturnOrders.Context = new Dictionary<string, string>
-            {
-                { "Ticket", authResult.Ticket },
-                { "InvOrgId", authResult.InvOrgId }
-            };
+                {
+                    { "Ticket", authResult.Ticket },
+                    { "InvOrgId", authResult.InvOrgId }
+                };
                 var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskreturn, houseReturnOrders, "鍙栨秷鍙戣揣鍚庣珛搴撳弽鎷e叆搴撳洖浼燱MS");
                 // 鍒ゆ柇Success鐨勫��
                 if (response.Success)
                 {
+                    WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = houseReturnOrders, 鎺ユ敹鎶ユ枃 = response });
+
                     // 濡傛灉Success涓簍rue锛岃繑鍥為渶瑕佺殑鍊硷紙杩欓噷浠ヨ繑鍥炴暣涓搷搴斿璞′负渚嬶級
                     return WebResponseContent.Instance.OK();
                 }
                 else
                 {
+                    WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = houseReturnOrders, 鎺ユ敹鎶ユ枃 = response });
+
                     // 濡傛灉Success涓篺alse锛屾姏鍑哄紓甯稿苟鍖呭惈閿欒淇℃伅
                     throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
                 }
@@ -1635,45 +1668,54 @@
                 ApiType = "InventoryAllocateController",
                 Method = "AsrsFinishedStockCount",
                 Parameters = new List<InventoryAllocate.Allocate>
-        {
-             new InventoryAllocate.Allocate
-            {
-                Value = new List<Allocate.data1>
                 {
-                new Allocate.data1
-                {
-                    No = inboundOrder.OrderNo,
-                    //InWarehouse = task.Roadway,
-                    TransactionCode = inboundOrder.TransactionCode,
-                    InoutType = inboundOrder.OrderType,
-                    OrderType = inboundOrder.InoutType,
-                    // 閬嶅巻鎵�鏈夊簱瀛樻槑缁嗭紝娣诲姞鍒� DetailList
-                    DetailList = StockInfos.Select(d => new Allocate.data1.Inventory
-                    {
-                        LinId = d.Details.FirstOrDefault()?.LinId?? "",
-                        MaterielCode = d.Details.FirstOrDefault()?.MaterielCode?? "",
-                        OrderQuantity = d.Details.FirstOrDefault().StockQuantity,
-                        BatchNo = d.BatchNo,
-                        LPNNo = d.PalletCode,
-                        FinishQty = d.Details.FirstOrDefault().StockQuantity,
-                        LocationName = d.LocationCode
-                    }).ToList()
+                     new InventoryAllocate.Allocate
+                     {
+                        Value = new List<Allocate.data1>
+                        {
+                            new Allocate.data1
+                            {
+                                No = inboundOrder.OrderNo,
+                                //InWarehouse = task.Roadway,
+                                TransactionCode = inboundOrder.TransactionCode,
+                                InoutType = inboundOrder.OrderType,
+                                OrderType = inboundOrder.InoutType,
+                                // 閬嶅巻鎵�鏈夊簱瀛樻槑缁嗭紝娣诲姞鍒� DetailList
+                                DetailList = StockInfos.Select(d => new Allocate.data1.Inventory
+                                {
+                                    LinId = d.Details.FirstOrDefault()?.LinId?? "",
+                                    MaterielCode = d.Details.FirstOrDefault()?.MaterielCode?? "",
+                                    OrderQuantity = d.Details.FirstOrDefault().StockQuantity,
+                                    BatchNo = d.BatchNo,
+                                    LPNNo = d.PalletCode,
+                                    FinishQty = d.Details.FirstOrDefault().StockQuantity,
+                                    LocationName = d.LocationCode
+                                }).ToList()
+                            }
+                        }
+                     }
                 }
-                }
-            }
-        }
             };
 
             var authResult = AuthenticateWithWMS();
             if (authResult.IsSuccess)
             {
                 inventoryAllocate.Context = new Dictionary<string, string>
-        {
-            { "Ticket", authResult.Ticket },
-            { "InvOrgId", authResult.InvOrgId }
-        };
+                {
+                    { "Ticket", authResult.Ticket },
+                    { "InvOrgId", authResult.InvOrgId }
+                };
 
-                HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAllocatein, inventoryAllocate, "璋冩嫧鍏ュ簱鏁伴噺鍥炰紶WMS");
+                var response = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAllocatein, inventoryAllocate, "璋冩嫧鍏ュ簱鏁伴噺鍥炰紶WMS");
+                if (!response.Status)
+                {
+                    WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = inventoryAllocate, 鎺ユ敹鎶ユ枃 = response });
+                }
+                else
+                {
+                    WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僑MOM(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = inventoryAllocate, 鎺ユ敹鎶ユ枃 = response });
+
+                }
             }
         }
 
@@ -1849,7 +1891,7 @@
                                     _outboundService.NewOutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails1);
 
 
-                                    AddCPRetrueOrder(stockInfo, outboundOrder, outboundOrderDetails1);
+                                    AddCPRetrueOrder(task,stockInfo, outboundOrder, outboundOrderDetails1);
 
                                     // 鍖哄垎鍗曟嵁鏁版嵁鏉ユ簮鏇存柊璐т綅鐘舵��
                                     if (outboundOrder.System == null)
@@ -1947,8 +1989,14 @@
                                                 var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskout, passBack, "绔嬪簱鍑哄簱鏁伴噺鍥炰紶WMS");
                                                 if (!response.Success)
                                                 {
+                                                    WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僑MOM(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = passBack, 鎺ユ敹鎶ユ枃 = response });
+
                                                     throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
                                                 }
+                                                else
+                                                {
+                                                    WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僑MOM(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = passBack, 鎺ユ敹鎶ユ枃 = response });
+                                                }                                                 
                                             }
                                         }
 
@@ -2004,8 +2052,14 @@
                                                 var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskin, allocate, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
                                                 if (!response.Success)
                                                 {
+                                                    WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僑MOM(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = allocate, 鎺ユ敹鎶ユ枃 = response });
+
                                                     throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
                                                 }
+                                                else
+                                                {
+                                                    WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僑MOM(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = allocate, 鎺ユ敹鎶ユ枃 = response });
+                                                }                                                   
                                             }
                                         }
                                     }
@@ -2081,7 +2135,7 @@
                                     _outboundService.NewOutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
 
 
-                                    AddCPRetrueOrder(stockInfo, outboundOrder, outboundOrderDetails);
+                                    AddCPRetrueOrder(task,stockInfo, outboundOrder, outboundOrderDetails);
 
                                     // 鍖哄垎鍗曟嵁鏁版嵁鏉ユ簮鏇存柊璐т綅鐘舵��
                                     if (outboundOrder.System == null)
@@ -2179,7 +2233,14 @@
                                                 var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskout, passBack, "绔嬪簱鍑哄簱鏁伴噺鍥炰紶WMS");
                                                 if (!response.Success)
                                                 {
+                                                    WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僑MOM(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = passBack, 鎺ユ敹鎶ユ枃 = response });
+
                                                     throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
+                                                }
+                                                else
+                                                {
+                                                    WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僑MOM(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = passBack, 鎺ユ敹鎶ユ枃 = response });
+
                                                 }
                                             }
                                         }
@@ -2236,7 +2297,14 @@
                                                 var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskin, allocate, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
                                                 if (!response.Success)
                                                 {
+                                                    WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僑MOM(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = allocate, 鎺ユ敹鎶ユ枃 = response });
+
                                                     throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
+                                                }
+                                                else
+                                                {
+                                                    WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僑MOM(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = allocate, 鎺ユ敹鎶ユ枃 = response });
+
                                                 }
                                             }
                                         }
@@ -2396,7 +2464,7 @@
 
                 // 鏇存柊搴撳瓨鐘舵�� 鍥炲簱鍗�
 
-                AddRetrueOrder(stockInfo, inboundOrder);
+                AddRetrueOrder(task,stockInfo, inboundOrder);
 
 
                 // 鍖哄垎鍗曟嵁鏁版嵁鏉ユ簮鏇存柊璐т綅鐘舵��
@@ -2586,9 +2654,7 @@
                             CompeletedNum++;
                         }
                         else if (newOutboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
-                        {
-                            newOutboundOrderDetail.OrderDetailStatus = OutboundStatusEnum.鍑哄簱涓�.ObjToInt();
-
+                        {    
                             inboundOrder.OrderStatus = OutboundStatusEnum.鍑哄簱涓�.ObjToInt();
                         }
                     }
@@ -2854,7 +2920,16 @@
             { "InvOrgId", authResult.InvOrgId }
         };
 
-                HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, allocate, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
+                var response =  HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, allocate, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
+                if (!response.Status)
+                {
+                    WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僑MOM(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = allocate, 鎺ユ敹鎶ユ枃 = response });
+
+                }
+                else
+                {
+                    WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僑MOM(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = allocate, 鎺ユ敹鎶ユ枃 = response });
+                }
             }
         }
 
@@ -2866,71 +2941,104 @@
                 App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
         }
 
-        private void AddRetrueOrder(Dt_StockInfo stockInfo, Dt_OutboundOrder outboundOrder)
+        private void AddRetrueOrder(Dt_Task task,Dt_StockInfo stockInfo, Dt_OutboundOrder outboundOrder)
         {
-            Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
-           .Where(x => x.StockId == stockInfo.Id).First();
-            if (stockInfoDetail == null)
+            List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+           .Where(x => x.StockId == stockInfo.Id).ToList();
+            if (stockInfoDetails == null || stockInfoDetails.Count == 0)
             {
                 throw new Exception("寤虹珛鍥炲簱鍗曟椂锛屾湭鎵惧埌璇ュ簱瀛樹俊鎭�");
             }
-            if (outboundOrder.OrderType == OrderTypeEnum.鍙嶆嫞鍑哄簱鍗�.ObjToInt())
+            Dt_ReturnOrder? lastReturnOrder = null;
+            foreach (var stockInfoDetail in stockInfoDetails)
             {
-                Dt_ReturnOrder returnOrder = _returnOrderRepository.QueryFirst(x => x.LPNNo == stockInfo.PalletCode && x.LocationCode == stockInfo.LocationCode && x.OrderStatus == InOrderStatusEnum.鏈紑濮�.ObjToInt());
-                if (returnOrder == null)
+                if (outboundOrder.OrderType == OrderTypeEnum.鍙嶆嫞鍑哄簱鍗�.ObjToInt())
                 {
-                    throw new Exception("鍙嶆嫞鍑哄簱鍚庯紝鏈壘鍒板搴斿弽鎷e洖搴撳崟淇℃伅");
-                }
-                stockInfo.LocationCode = "";
-                stockInfo.StockStatus = StockStatusEmun.鍙嶆嫞鍏ュ簱.ObjToInt();
-                stockInfo.Remark = "鍙嶆嫞鍏ュ簱";
-                stockInfoDetail.OutboundQuantity = 0;
-                stockInfoDetail.StockQuantity += returnOrder.OrderQuantity;
-                stockInfoDetail.OrderNo = returnOrder.OrderNo;
-            }
-            else
-            {
-                decimal returnQuantity = stockInfoDetail.StockQuantity - stockInfoDetail.OutboundQuantity;
-                if (returnQuantity > 0)
-                {
-                    Dt_ReturnOrder returnOrder = new Dt_ReturnOrder
+                    Dt_ReturnOrder returnOrder = _returnOrderRepository.QueryFirst(x => x.LPNNo == stockInfo.PalletCode && x.LocationCode == stockInfo.LocationCode && x.OrderStatus == InOrderStatusEnum.鏈紑濮�.ObjToInt());
+                    if (returnOrder == null)
                     {
-                        MaterielCode = stockInfoDetail.MaterielCode,
-                        MaterielName = stockInfoDetail.MaterielName,
-                        BatchNo = stockInfoDetail.BatchNo,
-                        OrderQuantity = returnQuantity,
-                        ReceiptQuantity = returnQuantity,
-                        OrderStatus = InOrderStatusEnum.鏈紑濮�.ObjToInt(),
-                        LinId = stockInfoDetail.LinId,
-                        LPNNo = stockInfo.PalletCode,
-                        Creater = "LK",
-                        CreateDate = DateTime.Now,
-                        OrderType = OrderTypeEnum.浣欐枡鍥炲簱鍗�.ObjToInt(),
-                        System = "WMS"
-                    };
-                    if (outboundOrder.System == "SMOM" && stockInfo.LocationCode != null)
-                    {
-                        returnOrder.LocationCode = stockInfo.LocationCode;
+                        throw new Exception("鍙嶆嫞鍑哄簱鍚庯紝鏈壘鍒板搴斿弽鎷e洖搴撳崟淇℃伅");
                     }
-                    _unitOfWorkManage.BeginTran();
-                    _returnOrderRepository.AddData(returnOrder);
                     stockInfo.LocationCode = "";
-                    stockInfo.StockStatus = StockStatusEmun.浣欐枡閫�搴�.ObjToInt();
-                    stockInfo.Remark = "浣欐枡閫�搴�";
+                    stockInfo.StockStatus = StockStatusEmun.鍙嶆嫞鍏ュ簱.ObjToInt();
+                    stockInfo.Remark = "鍙嶆嫞鍏ュ簱";
                     stockInfoDetail.OutboundQuantity = 0;
-                    stockInfoDetail.StockQuantity = returnQuantity;
+                    stockInfoDetail.StockQuantity += returnOrder.OrderQuantity;
                     stockInfoDetail.OrderNo = returnOrder.OrderNo;
-                    _stockService.StockInfoService.Repository.UpdateData(stockInfo);
-                    _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
-                    _unitOfWorkManage.CommitTran();
                 }
                 else
                 {
-                    DeleteAndMoveIntoHtStockStatus(stockInfo);
+                    WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = 1 });
+                    var postData = new
+                    {
+                        DeviceCode = task.NextAddress,    // 灞忓箷缂栧彿
+                        MaterialCode = stockInfoDetail.MaterielCode,//鐗╂枡绫诲瀷
+                        SendNum = stockInfoDetail.OutboundQuantity,//鍙戞枡鏁�
+                        BackNum = stockInfoDetail.StockQuantity - stockInfoDetail.OutboundQuantity//鍥炲簱鏁�   
+                    };
+                    WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃2 = postData });
+                    string json = Newtonsoft.Json.JsonConvert.SerializeObject(postData);
+                    WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃3 = json });
+                    using (var client = new HttpClient())
+                    {
+                        var content = new StringContent(json, Encoding.UTF8, "application/json");
+                        var response = client.PostAsync(LEDAPI, content).Result;
+                        string result = response.Content.ReadAsStringAsync().Result;
+                        WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = response, 鎺ユ敹鎶ユ枃 = result });
+                    }
+                    WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = 4 });
+
+                    bool allowCompeted = stockInfo.Details.All(x => x.StockQuantity == x.OutboundQuantity);
+                    if (allowCompeted)
+                    {
+                        DeleteAndMoveIntoHtStockStatus(stockInfo);
+
+                    }     
+                    else
+                    {
+                        decimal returnQuantity = stockInfoDetail.StockQuantity - stockInfoDetail.OutboundQuantity;
+                        Dt_ReturnOrder returnOrder = new Dt_ReturnOrder
+                        {
+                            MaterielCode = stockInfoDetail.MaterielCode,
+                            MaterielName = stockInfoDetail.MaterielName,
+                            BatchNo = stockInfoDetail.BatchNo,
+                            OrderQuantity = returnQuantity,
+                            ReceiptQuantity = returnQuantity,
+                            OrderStatus = InOrderStatusEnum.鏈紑濮�.ObjToInt(),
+                            LinId = stockInfoDetail.LinId,
+                            LPNNo = stockInfo.PalletCode,
+                            Creater = "LK",
+                            CreateDate = DateTime.Now,
+                            OrderType = OrderTypeEnum.浣欐枡鍥炲簱鍗�.ObjToInt(),
+                            System = "WMS"
+                        };
+                        if(lastReturnOrder != null)
+                        {
+                            lastReturnOrder.Remark = lastReturnOrder.Remark + $",{returnOrder.BatchNo}";
+                            _returnOrderRepository.UpdateData(lastReturnOrder);
+                        }
+                        if (outboundOrder.System == "SMOM" && stockInfo.LocationCode != null)
+                        {
+                            returnOrder.LocationCode = stockInfo.LocationCode;
+                        }
+                        _unitOfWorkManage.BeginTran();
+                        if(lastReturnOrder == null)
+                        {
+                            _returnOrderRepository.AddData(returnOrder);
+                            lastReturnOrder = returnOrder;
+                        }
+                        stockInfo.LocationCode = "";
+                        stockInfo.StockStatus = StockStatusEmun.浣欐枡閫�搴�.ObjToInt();
+                        stockInfo.Remark = "浣欐枡閫�搴�";
+                        stockInfoDetail.OutboundQuantity = 0;
+                        stockInfoDetail.StockQuantity = returnQuantity;
+                        stockInfoDetail.OrderNo = lastReturnOrder.OrderNo;
+                        _stockService.StockInfoService.Repository.UpdateData(stockInfo);
+                        _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
+                        _unitOfWorkManage.CommitTran();
+                    }
                 }
             }
-
-
         }
 
         //浣庢俯銆佽嵂姘村洖搴撳崟
@@ -2963,21 +3071,25 @@
                 }
                 else
                 {
+                    WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = 1 });
                     var postData = new
                     {
                         DeviceCode = task.NextAddress,    // 灞忓箷缂栧彿
-                        MaterialCode = outboundOrder.Details.FirstOrDefault()?.MaterielCode,//鐗╂枡绫诲瀷
-                        BackNum = stockInfoDetail.StockQuantity - stockInfoDetail.OutboundQuantity,//鍥炲簱鏁�
-                        SendNum = outboundOrder.Details.FirstOrDefault()?.OrderQuantity//鍙戞枡鏁�
+                        MaterialCode = stockInfoDetail.MaterielCode,//鐗╂枡绫诲瀷
+                        SendNum = stockInfoDetail.OutboundQuantity,//鍙戞枡鏁�
+                        BackNum = stockInfoDetail.StockQuantity - stockInfoDetail.OutboundQuantity//鍥炲簱鏁�   
                     };
+                    WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃2 = postData });
                     string json = Newtonsoft.Json.JsonConvert.SerializeObject(postData);
+                    WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃3 = json });
                     using (var client = new HttpClient())
                     {
                         var content = new StringContent(json, Encoding.UTF8, "application/json");
                         var response = client.PostAsync(LEDAPI, content).Result;
                         string result = response.Content.ReadAsStringAsync().Result;
+                        WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = response, 鎺ユ敹鎶ユ枃 = result });
                     }
-
+                    WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = 4 });
 
                     bool allowCompeted = stockInfo.Details.All(x => x.StockQuantity == x.OutboundQuantity);
                     if (allowCompeted)
@@ -3038,7 +3150,7 @@
         }
 
         //鎴愬搧鍥炲簱鍗�
-        private void AddCPRetrueOrder(Dt_StockInfo stockInfo, Dt_NewOutboundOrder outboundOrder, List<Dt_NewOutboundOrderDetail> outboundOrderDetails)
+        private void AddCPRetrueOrder(Dt_Task task,Dt_StockInfo stockInfo, Dt_NewOutboundOrder outboundOrder, List<Dt_NewOutboundOrderDetail> outboundOrderDetails)
         {
             List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
                 .Where(x => x.StockId == stockInfo.Id)
@@ -3092,6 +3204,28 @@
                 }
                 else
                 {
+                    foreach(var stockInfoDetail in stockInfoDetails)
+                    {
+                        WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = 1 });
+                        var postData = new
+                        {
+                            DeviceCode = task.NextAddress,    // 灞忓箷缂栧彿
+                            MaterialCode = stockInfoDetail.MaterielCode,//鐗╂枡绫诲瀷
+                            SendNum = stockInfoDetail.OutboundQuantity,//鍙戞枡鏁�
+                            BackNum = stockInfoDetail.StockQuantity - stockInfoDetail.OutboundQuantity//鍥炲簱鏁�   
+                        };
+                        WriteLog.Write_Log("API", "鎴愬搧搴撳叆搴撯�旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃2 = postData });
+                        string json = Newtonsoft.Json.JsonConvert.SerializeObject(postData);
+                        WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃3 = json });
+                        using (var client = new HttpClient())
+                        {
+                            var content = new StringContent(json, Encoding.UTF8, "application/json");
+                            var response = client.PostAsync(LEDAPI, content).Result;
+                            string result = response.Content.ReadAsStringAsync().Result;
+                            WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = response, 鎺ユ敹鎶ユ枃 = result });
+                        }
+                        WriteLog.Write_Log("API", "鍑哄簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = 4 });
+                    }
                     var groupedDetails = outboundOrderDetails
                         .GroupBy(d => new { d.MaterielCode, d.BatchNo })
                         .ToList();
@@ -3293,17 +3427,22 @@
                     result = response.Content.ReadAsStringAsync()
                         .ConfigureAwait(false).GetAwaiter().GetResult();
                 }
+                WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僂RP(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = postContent, 鎺ユ敹鎶ユ枃 = result });
 
                 // 鍋囪ERP杩斿洖鎴愬姛鏃惰繑鍥炴垚鍔熷搷搴�
                 return WebResponseContent.Instance.OK(result);
             }
             catch (HttpRequestException ex)
             {
+                WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僂RP(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = postContent, 鎺ユ敹鎶ユ枃 = ex.Message });
+
                 // 澶勭悊HTTP璇锋眰鐩稿叧寮傚父
                 return WebResponseContent.Instance.Error($"HTTP璇锋眰閿欒: {ex.Message}");
             }
             catch (Exception ex)
             {
+                WriteLog.Write_Log("API", "鍑哄簱鈥斿洖璋僂RP(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = postContent, 鎺ユ敹鎶ユ枃 = ex.Message });
+
                 // 澶勭悊鍏朵粬寮傚父
                 return WebResponseContent.Instance.Error($"澶勭悊澶辫触: {ex.Message}");
             }
@@ -3331,11 +3470,15 @@
             // 鍒ゆ柇Success鐨勫��
             if (response.Code == 0)
             {
+                WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僂RP(鎴愬姛)", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = feedbackInboundOrderERPs, 鎺ユ敹鎶ユ枃 = response });
+
                 // 濡傛灉Success涓簍rue锛岃繑鍥為渶瑕佺殑鍊硷紙杩欓噷浠ヨ繑鍥炴暣涓搷搴斿璞′负渚嬶級
                 return WebResponseContent.Instance.OK();
             }
             else
             {
+                WriteLog.Write_Log("API", "鍏ュ簱鈥斿洖璋僂RP(澶辫触)", "璇锋眰澶辫触", new { 璇锋眰鎶ユ枃 = feedbackInboundOrderERPs, 鎺ユ敹鎶ユ枃 = response });
+
                 // 濡傛灉Success涓篺alse锛屾姏鍑哄紓甯稿苟鍖呭惈閿欒淇℃伅
                 throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
             }

--
Gitblit v1.9.3