From d4b029d2697c265fd575549db79cd55bb4f9532e Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期一, 27 四月 2026 14:41:08 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/JiAnLiKu

---
 WMS/WIDESEA_WMSServer/WIDESEA_Core/Enums/OrderEnum.cs                       |    1 
 WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs |   57 ++++++++++-
 WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs                |  183 ++++++++++++++++++++----------------
 WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs                          |   34 +++---
 WMS/WIDESEA_WMSServer/WIDESEA_Model/WMSNoticeHub.cs                         |   13 ++
 5 files changed, 182 insertions(+), 106 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_Core/Enums/OrderEnum.cs b/WMS/WIDESEA_WMSServer/WIDESEA_Core/Enums/OrderEnum.cs
index 9979d2b..c2cc61f 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_Core/Enums/OrderEnum.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_Core/Enums/OrderEnum.cs
@@ -225,7 +225,6 @@
         /// </summary>
         [Description("鐢熶骇鍏ュ簱鍗�")]
         works = 2,
-
         /// <summary>
         /// 璋冩嫧鍑哄簱鍗�
         /// </summary>
diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_Model/WMSNoticeHub.cs b/WMS/WIDESEA_WMSServer/WIDESEA_Model/WMSNoticeHub.cs
new file mode 100644
index 0000000..5f79c76
--- /dev/null
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_Model/WMSNoticeHub.cs
@@ -0,0 +1,13 @@
+锘縰sing Microsoft.AspNetCore.SignalR;
+
+namespace WIDESEA_Model
+{
+    public class WMSNoticeHub : Hub
+    {
+        // 鍓嶇鐩戝惉杩欎釜鏂规硶灏辫兘鏀跺埌娑堟伅
+        public async Task SendMessage(string message)
+        {
+            await Clients.All.SendAsync("ReceiveMessage", message);
+        }
+    }
+}
diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs
index 6409743..aa230b4 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs
@@ -1,4 +1,5 @@
 锘縰sing MailKit.Search;
+using Microsoft.AspNetCore.SignalR;
 using Microsoft.Extensions.Logging;
 using System;
 using System.Collections.Generic;
@@ -169,20 +170,43 @@
                 //        newTask.TaskType = TaskTypeEnum.MesPalletSmallReturn.ObjToInt();
                 //    }
                 //}
-                //else
-                //{
+                 //{
                 stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
                 locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
                 //}
 
-                _unitOfWorkManage.BeginTran();
-                int taskId = BaseDal.AddData(newTask);
+                _unitOfWorkManage.BeginTran();  
+                int taskId = BaseDal.AddData(newTask); 
                 newTask.TaskId = taskId;
+
+                 List<Dt_StockInfoDetail> stockInfoDetails = stockInfo.Details;
+                foreach (var stockInfoDetail in stockInfoDetails)
+                {
+                    WriteLog.Write_Log("API", "鍏ュ簱鈥旇姹侺ED", "璇锋眰鎴愬姛", new { 璇锋眰鎶ユ枃 = 1 });
+                    var postData = new
+                    {
+                        DeviceCode = "1005",    // 灞忓箷缂栧彿
+                        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 });
+                }
                 if (returnOrder != null)
                 {
-                    returnOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+                    returnOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt(); 
                     _returnOrderRepository.UpdateData(returnOrder);
-                }
+                }       
                 _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                 _locationInfoService.UpdateData(locationInfo);
 
@@ -212,12 +236,15 @@
                 Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
                 if (task != null)
                 {
+                    _hubContext.Clients.All.SendAsync("ReceiveMessage", $"璇ユ墭鐩榹palletCode}宸茬敓鎴愪换鍔�");
                     return WebResponseContent.Instance.Error($"璇ユ墭鐩榹palletCode}宸茬敓鎴愪换鍔�");
                 }
                 Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
 
                 if (stockInfo == null)
                 {
+                    _hubContext.Clients.All.SendAsync("ReceiveMessage", $"鏈壘鍒扮粍鐩樹俊鎭�");
+
                     return WebResponseContent.Instance.Error($"鏈壘鍒扮粍鐩樹俊鎭�");
                 }
 
@@ -227,6 +254,8 @@
                     Dt_LocationInfo locationInfo1 = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
                     if (locationInfo1 == null)
                     {
+                        _hubContext.Clients.All.SendAsync("ReceiveMessage", $"鍥炲簱鍗曚腑璇ュ簱浣峽stockInfo.LocationCode}鏈壘鍒�");
+
                         return WebResponseContent.Instance.Error($"鍥炲簱鍗曚腑璇ュ簱浣峽stockInfo.LocationCode}鏈壘鍒�");
                     }
                     returnRoadwayInfo = _basicRepository.RoadwayInfoRepository.QueryFirst(x => x.RoadwayNo == locationInfo1.RoadwayNo && x.InStationCode == (returnRoadwayInfo.InStationCode != null ? returnRoadwayInfo.InStationCode : stationCode));
@@ -239,6 +268,8 @@
                     Dt_LocationInfo locationInfo1 = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == returnOrder.LocationCode);
                     if (locationInfo1 == null)
                     {
+                        _hubContext.Clients.All.SendAsync("ReceiveMessage", $"鍥炲簱鍗曚腑璇ュ簱浣峽returnOrder.LocationCode}鏈壘鍒�");
+
                         return WebResponseContent.Instance.Error($"鍥炲簱鍗曚腑璇ュ簱浣峽returnOrder.LocationCode}鏈壘鍒�");
                     }
                     returnRoadwayInfo = _basicRepository.RoadwayInfoRepository.QueryFirst(x => x.RoadwayNo == locationInfo1.RoadwayNo && x.InStationCode == (returnRoadwayInfo.InStationCode != null ? returnRoadwayInfo.InStationCode : stationCode));
@@ -246,23 +277,31 @@
 
                 if (Repository.QueryFirst(x => x.SourceAddress == (returnRoadwayInfo.InStationCode != null ? returnRoadwayInfo.InStationCode : stationCode) && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null)
                 {
+                    _hubContext.Clients.All.SendAsync("ReceiveMessage", $"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�");
+
                     return WebResponseContent.Instance.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�");
                 }
 
                 var details = stockInfo.Details.FirstOrDefault();
                 if (!string.IsNullOrEmpty(stockInfo.LocationCode))
                 {
+                    _hubContext.Clients.All.SendAsync("ReceiveMessage", $"璇ユ墭鐩樺凡缁戝畾璐т綅");
+
                     return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅");
                 }
                 Dt_RoadwayInfo roadwayInfo = _basicRepository.RoadwayInfoRepository.QueryFirst(x => x.InStationCode == (returnRoadwayInfo.InStationCode != null ? returnRoadwayInfo.InStationCode : stationCode));
                 if (roadwayInfo == null)
                 {
+                    _hubContext.Clients.All.SendAsync("ReceiveMessage", $"鏈壘鍒拌鍏ュ簱绔欏彴鍦板潃");
+
                     return WebResponseContent.Instance.Error($"鏈壘鍒拌鍏ュ簱绔欏彴鍦板潃");
                 }
 
                 Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == roadwayInfo.RoadwayNo);
                 if (warehouse == null)
                 {
+                    _hubContext.Clients.All.SendAsync("ReceiveMessage", $"鏈壘鍒拌浠撳簱");
+
                     return WebResponseContent.Instance.Error("鏈壘鍒拌浠撳簱");
                 }
 
@@ -272,6 +311,8 @@
                     locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == returnOrder.LocationCode);
                     if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt() || locationInfo.EnableStatus == EnableStatusEnum.Disable.ObjToInt() || locationInfo.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt())
                     {
+                        _hubContext.Clients.All.SendAsync("ReceiveMessage", $"璇ュ洖搴撳崟璐т綅{locationInfo.LocationCode}闈為攣瀹氱姸鎬佹垨璐т綅鍚敤鐘舵�佷笉姝g‘锛岃妫�鏌�");
+
                         return WebResponseContent.Instance.Error($"璇ュ洖搴撳崟璐т綅{locationInfo.LocationCode}闈為攣瀹氱姸鎬佹垨璐т綅鍚敤鐘舵�佷笉姝g‘锛岃妫�鏌�");
                     }
                 }
@@ -280,6 +321,8 @@
                     locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayInfo.RoadwayNo, stockInfo.PalletType, warehouse.WarehouseId, "", heightType);//, stockInfo.WarehouseId
                     if (locationInfo == null)
                     {
+                        _hubContext.Clients.All.SendAsync("ReceiveMessage", $"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
+
                         return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
                     }
                 }
@@ -371,7 +414,7 @@
                     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;
diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
index 6bb48ed..a5d8808 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"];
@@ -2866,89 +2870,102 @@
 
         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
-            {
-                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 });
-
-                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();
+                    }
                 }
             }
-
-
         }
 
         //浣庢俯銆佽嵂姘村洖搴撳崟
diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs b/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
index 66bae07..4e61f7d 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
@@ -1,24 +1,25 @@
-using WIDESEA_Core.Helper;
-using WIDESEA_Core.Extensions;
-using WIDESEA_Core.Middlewares;
-using System.Reflection;
-using WIDESEA_Core.Filter;
+using Autofac;
+using Autofac.Core;
+using Autofac.Extensions.DependencyInjection;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Mvc.Controllers;
+using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using Newtonsoft.Json;
 using Newtonsoft.Json.Converters;
 using Newtonsoft.Json.Serialization;
-using Newtonsoft.Json;
+using System.Reflection;
 using System.Text;
-using Microsoft.AspNetCore.Mvc.Controllers;
-using Microsoft.Extensions.DependencyInjection.Extensions;
-using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
 using WIDESEA_Core;
-using WIDESEA_Core.BaseServices;
-using Autofac.Extensions.DependencyInjection;
-using Autofac;
-using WIDESEA_WMSServer.Filter;
 using WIDESEA_Core.Authorization;
+using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Core;
-using Autofac.Core;
-using Microsoft.AspNetCore.Builder;
+using WIDESEA_Core.Extensions;
+using WIDESEA_Core.Filter;
+using WIDESEA_Core.Helper;
+using WIDESEA_Core.Middlewares;
+using WIDESEA_Model;
+using WIDESEA_WMSServer.Filter;
 
 var builder = WebApplication.CreateBuilder(args);
 
@@ -90,9 +91,12 @@
 builder.Services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
 
+builder.Services.AddSignalR();
 
 var app = builder.Build();
 
+app.MapHub<WMSNoticeHub>("/wmsNoticeHub"); // 路由
+
 // 3、配置中间件
 app.UseMiniProfiler();//性能分析器
 app.ConfigureApplication();//配置文件

--
Gitblit v1.9.3