From f423e1277f91427f0a767bd1224c1260dcb73086 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期一, 20 四月 2026 22:47:54 +0800
Subject: [PATCH] feat: 添加空箱入库功能及相关优化

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Inbound.cs |  118 ++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 85 insertions(+), 33 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Inbound.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Inbound.cs
index b68c724..20956e7 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Inbound.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Inbound.cs
@@ -1,11 +1,16 @@
+using Microsoft.AspNetCore.Http.HttpResults;
+using Newtonsoft.Json;
+using System.Diagnostics;
 using WIDESEA_Common.Constants;
 using WIDESEA_Common.LocationEnum;
 using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
 using WIDESEA_Common.WareHouseEnum;
 using WIDESEA_Core;
+using WIDESEA_Core.Helper;
 using WIDESEA_DTO.MES;
 using WIDESEA_DTO.Task;
+using WIDESEA_IBasicService;
 using WIDESEA_Model.Models;
 
 namespace WIDESEA_TaskInfoService
@@ -117,6 +122,7 @@
         /// </summary>
         public async Task<WebResponseContent> InboundFinishTaskAsync(CreateTaskDto taskDto)
         {
+            var stopwatch = Stopwatch.StartNew();
             try
             {
                 var task = await BaseDal.QueryFirstAsync(s => s.PalletCode == taskDto.PalletCode);
@@ -126,45 +132,91 @@
                 if (location == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑璐т綅");
 
                 var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode);
-                if (stockInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴斿簱瀛樹俊鎭�");
-
-                // 鍒ゆ柇鏄笉鏄瀬鍗峰簱浠诲姟
-                if (taskDto.WarehouseId == (int)WarehouseEnum.FJ1 || taskDto.WarehouseId == (int)WarehouseEnum.ZJ1)
+                if (stockInfo == null)
                 {
-                    return await CompleteAgvInboundTaskAsync(taskDto);
+                    return await _unitOfWorkManage.BeginTranAsync(async () =>
+                    {
+                        stockInfo = new Dt_StockInfo
+                        {
+                            PalletCode = taskDto.PalletCode,
+                            WarehouseId = task.WarehouseId,
+                            StockStatus = StockStatusEmun.绌烘墭鐩樺簱瀛�.GetHashCode(),
+                            Creater = StockConstants.SYSTEM_USER,
+                            Details = null,
+                            LocationCode = location.LocationCode,
+                            LocationId = location.Id
+                        };
+                        var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
+                        var updateStockResult = await _stockInfoService.Repository.AddDataAsync(stockInfo);
+                        return await CompleteTaskAsync(task, "鍏ュ簱瀹屾垚");
+                    });
                 }
-
-                return await _unitOfWorkManage.BeginTranAsync(async () =>
+                else
                 {
-                    WebResponseContent content = new WebResponseContent();
-                    stockInfo.LocationCode = location.LocationCode;
-                    stockInfo.LocationId = location.Id;
 
-                    SetOutboundDateByRoadway(task, stockInfo);
 
-                    stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode();
-
-                    location.LocationStatus = LocationStatusEnum.InStock.GetHashCode();
-
-                    var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
-                    var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
-                    if (!updateLocationResult || !updateStockResult)
-                        return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
-                    // 璋冪敤MES鎵樼洏杩涚珯
-                    var inboundRequest = new InboundInContainerRequest
+                    // 鍒ゆ柇鏄笉鏄瀬鍗峰簱浠诲姟
+                    if (taskDto.WarehouseId == (int)WarehouseEnum.FJ1 || taskDto.WarehouseId == (int)WarehouseEnum.ZJ1)
                     {
-                        EquipmentCode = "STK-GROUP-001",
-                        ResourceCode = "STK-GROUP-001",
-                        LocalTime = DateTime.Now,
-                        ContainerCode = taskDto.PalletCode
-                    };
-                    var inboundResult = _mesService.InboundInContainer(inboundRequest);
-                    if (inboundResult == null || inboundResult.Data == null || !inboundResult.Data.IsSuccess)
-                    {
-                        return content.Error($"浠诲姟瀹屾垚澶辫触锛歁ES杩涚珯澶辫触: {inboundResult?.Data?.Msg ?? inboundResult?.ErrorMessage ?? "鏈煡閿欒"}");
+                        return await CompleteAgvInboundTaskAsync(taskDto);
                     }
-                    return await CompleteTaskAsync(task, "鍏ュ簱瀹屾垚");
-                });
+
+                    return await _unitOfWorkManage.BeginTranAsync(async () =>
+                    {
+                        WebResponseContent content = new WebResponseContent();
+                        stockInfo.LocationCode = location.LocationCode;
+                        stockInfo.LocationId = location.Id;
+
+                        SetOutboundDateByRoadway(task, stockInfo);
+
+                        stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode();
+
+                        location.LocationStatus = LocationStatusEnum.InStock.GetHashCode();
+
+                        var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
+                        var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
+                        if (!updateLocationResult || !updateStockResult)
+                            return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
+
+                        // 鏍规嵁搴撳瓨Remark閫夋嫨闈欑疆璁惧锛屾煡MES鍔ㄦ�佸嚟璇�
+                        //string deviceName = stockInfo.Remark == "GW_1" ? "楂樻俯闈欑疆1"
+                        //    : stockInfo.Remark == "GW_2" ? "楂樻俯闈欑疆2"
+                        //    : "甯告俯闈欑疆1";
+                        //var mesConfig = _mesDeviceConfigService.GetByDeviceName(deviceName);
+                        //string equipmentCode = mesConfig?.EquipmentCode ?? StockConstants.MES_EQUIPMENT_CODE;
+                        //string resourceCode = mesConfig?.ResourceCode ?? StockConstants.MES_RESOURCE_CODE;
+                        //string token = mesConfig?.Token;
+
+                        // 璋冪敤MES鎵樼洏杩涚珯
+                        //var inboundRequest = new InboundInContainerRequest
+                        //{
+                        //    EquipmentCode = equipmentCode,
+                        //    ResourceCode = resourceCode,
+                        //    LocalTime = DateTime.Now,
+                        //    ContainerCode = taskDto.PalletCode
+                        //};
+                        //string requestJson = inboundRequest.ToJson();
+                        //var inboundResult = string.IsNullOrWhiteSpace(token)
+                        //    ? _mesService.InboundInContainer(inboundRequest)
+                        //    : _mesService.InboundInContainer(inboundRequest, token);
+                        //stopwatch.Stop();
+                        //await _mesLogService.LogAsync(new MesApiLogDto
+                        //{
+                        //    ApiType = "InboundInContainer",
+                        //    RequestJson = requestJson,
+                        //    ResponseJson = JsonConvert.SerializeObject(inboundResult),
+                        //    IsSuccess = inboundResult.IsSuccess,
+                        //    ErrorMessage = inboundResult.ErrorMessage,
+                        //    ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
+                        //    Creator = "systeam"
+                        //});
+                        //if (inboundResult == null || inboundResult.Data == null || !inboundResult.Data.IsSuccess)
+                        //{
+                        //    return content.Error($"浠诲姟瀹屾垚澶辫触锛歁ES杩涚珯澶辫触: {inboundResult?.Data?.Msg ?? inboundResult?.ErrorMessage ?? "鏈煡閿欒"}");
+                        //}
+                        return await CompleteTaskAsync(task, "鍏ュ簱瀹屾垚");
+                    });
+                }
             }
             catch (Exception ex)
             {
@@ -208,4 +260,4 @@
 
         #endregion 鍏ュ簱浠诲姟
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3