From 0955ceea9157ac92513cab3b5ba3d3c9760886d2 Mon Sep 17 00:00:00 2001
From: yangpeixing <yangpeixing@hnkhzn.com>
Date: 星期二, 28 四月 2026 16:19:09 +0800
Subject: [PATCH] 1

---
 WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs |  175 ++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 132 insertions(+), 43 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs
index d95c3cc..c9a0485 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs
@@ -1,30 +1,35 @@
-锘縰sing System;
+锘縰sing MailKit.Search;
+using Microsoft.AspNetCore.SignalR;
+using Microsoft.Extensions.Logging;
+using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Net.WebSockets;
 using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
-using WIDESEA_Core.Enums;
-using WIDESEA_Core;
-using WIDESEA_Model.Models;
-using WIDESEA_Core.Helper;
-using Microsoft.Extensions.Logging;
-using MailKit.Search;
 using System.Reflection.Metadata;
-using static WIDESEA_ITaskInfoService.ITaskService;
-using static WIDESEA_Common.HouseInventoryIn;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
 using WIDESEA_Common;
-using Parameter = WIDESEA_Common.Parameter;
-using WIDESEA_Core.LogHelper;
-using WIDESEA_DTO.Task;
-using WIDESEA_Core.TaskEnum;
-using WIDESEA_Model.Models.Inbound;
+using WIDESEA_Common.Log;
 using WIDESEA_Common.OrderEnum;
+using WIDESEA_Core;
+using WIDESEA_Core.Enums;
+using WIDESEA_Core.Helper;
+using WIDESEA_Core.LogHelper;
+using WIDESEA_Core.TaskEnum;
+using WIDESEA_DTO.Task;
+using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Inbound;
+using static WIDESEA_Common.HouseInventoryIn;
+using static WIDESEA_ITaskInfoService.ITaskService;
+using Parameter = WIDESEA_Common.Parameter;
 
 namespace WIDESEA_TaskInfoService
 {
     public partial class TaskService
     {
+
 
         /// <summary>
         /// 浠呯敵璇蜂换鍔★紝璁¦CS鏍规嵁璺敱纭畾涓嬩竴鍦板潃
@@ -40,17 +45,27 @@
                 if (task != null)
                 {
                     //PushTasksToWCS(new List<Dt_Task> { task });
+                    _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($"鏈壘鍒扮粍鐩樹俊鎭�");
                 }
                 if (stockInfo.StockStatus == StockStatusEmun.鍚堟墭鍑哄簱瀹屾垚.ObjToInt())
                 {
 
+                }
+                if (stockInfo.StockStatus == StockStatusEmun.鐩樼偣鍑哄簱瀹屾垚.ObjToInt())
+                {
+                    _hubContext.Clients.All.SendAsync("ReceiveMessage", $"璇ユ墭鐩榹palletCode}宸茬敓鎴愪换鍔�");
+
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩榹palletCode}鏈洏鐐�");
                 }
                 ///鍒ゆ柇鏄惁瀛樺湪鍥炲簱鍗�,杩涜鍥炲師搴撲綅閫昏緫
                 string returnOrderNo = stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.OrderNo;
@@ -61,6 +76,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);
@@ -68,22 +85,30 @@
 
                 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("鏈壘鍒拌浠撳簱");
                 }
                 Dt_LocationInfo? locationInfo = new Dt_LocationInfo();
@@ -92,6 +117,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‘锛岃妫�鏌�");
                     }
                 }
@@ -100,6 +127,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($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
                     }
                 }
@@ -161,20 +190,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);
 
@@ -193,6 +245,8 @@
             catch (Exception ex)
             {
                 _unitOfWorkManage.RollbackTran();
+                _hubContext.Clients.All.SendAsync("ReceiveMessage", $"{ex.Message}");
+
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
@@ -204,12 +258,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($"鏈壘鍒扮粍鐩樹俊鎭�");
                 }
 
@@ -219,6 +276,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));
@@ -231,6 +290,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));
@@ -238,23 +299,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("鏈壘鍒拌浠撳簱");
                 }
 
@@ -264,6 +333,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‘锛岃妫�鏌�");
                     }
                 }
@@ -272,6 +343,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($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
                     }
                 }
@@ -348,6 +421,30 @@
                 _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 = newTask.CurrentAddress,    // 灞忓箷缂栧彿
+                        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();
@@ -366,6 +463,8 @@
             catch (Exception ex)
             {
                 _unitOfWorkManage.RollbackTran();
+                _hubContext.Clients.All.SendAsync("ReceiveMessage", $"{ex.Message}");
+
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
@@ -644,9 +743,8 @@
         //鏌ヨ浠撳簱鎵樼洏璐х墿绫诲瀷
         public int GetPalletType(Dt_Warehouse warehouse, string palletCode)
         {
-            if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ObjToString() || warehouse.WarehouseCode == WarehouseEnum.SC02_BC.ObjToString())
+            if (warehouse.WarehouseCode.Contains("BC"))
             {
-
                 Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 3));
                 if (palletTypeInfo == null)
                 {
@@ -654,25 +752,16 @@
                 }
                 return palletTypeInfo.PalletType;
             }
-            //else if (warehouse.WarehouseCode == WarehouseEnum.HA152.ObjToString())
-            //{
-            //    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
-            //    if (palletTypeInfo == null)
-            //    {
-            //        throw new Exception($"鎵樼洏鍙烽敊璇�");
-            //    }
-            //    return palletTypeInfo.PalletType;
-            //}
-            //else if (warehouse.WarehouseCode == WarehouseEnum.HA57.ObjToString())
-            //{
-            //    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 3));
-            //    if (palletTypeInfo == null)
-            //    {
-            //        throw new Exception($"鎵樼洏鍙烽敊璇�");
-            //    }
-            //    return palletTypeInfo.PalletType;
-            //}
-            return -1;
+            else
+            {
+                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
+                if (palletTypeInfo == null)
+                {
+                    throw new Exception($"鎵樼洏鍙烽敊璇�");
+                }
+                return palletTypeInfo.PalletType;
+            }
+            return 0;
         }
 
 

--
Gitblit v1.9.3