From 4b483d9d06bead231b88ca212fd799196668a057 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 28 四月 2026 22:58:27 +0800
Subject: [PATCH] fix(任务服务): 修复出库任务选择逻辑和货位分配问题

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_GradingMachine.cs |  111 +++++++++++++++++++++++++------------------------------
 1 files changed, 50 insertions(+), 61 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_GradingMachine.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_GradingMachine.cs
index 29ecd75..b5dd9cb 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_GradingMachine.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_GradingMachine.cs
@@ -1,27 +1,10 @@
-using Mapster;
-using MapsterMapper;
-using Microsoft.Extensions.Configuration;
-using SqlSugar;
-using System.DirectoryServices.Protocols;
 using System.Text.Json;
 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.BaseRepository;
-using WIDESEA_Core.BaseServices;
-using WIDESEA_Core.Core;
-using WIDESEA_Core.Enums;
-using WIDESEA_Core.Helper;
 using WIDESEA_DTO.GradingMachine;
-using WIDESEA_DTO.MES;
-using WIDESEA_DTO.Stock;
 using WIDESEA_DTO.Task;
-using WIDESEA_IBasicService;
-using WIDESEA_IStockService;
-using WIDESEA_ITaskInfoService;
 using WIDESEA_Model.Models;
 
 namespace WIDESEA_TaskInfoService
@@ -36,30 +19,31 @@
         public async Task<WebResponseContent> InOrOutCompletedAsync(GradingMachineInputDto input)
         {
             WebResponseContent content = new WebResponseContent();
-            if (string.IsNullOrWhiteSpace(input.PalletCode) || string.IsNullOrWhiteSpace(input.LocationCode))
+            if (string.IsNullOrWhiteSpace(input.LocationCode))
             {
-                return content.Error($"鎵樼洏鍙锋垨鑰呰揣浣嶇紪鍙蜂笉鑳戒负绌�");
+                return content.Error($"璐т綅缂栧彿涓嶈兘涓虹┖");
             }
 
             try
             {
-                var stockInfo = await _stockInfoService.GetStockInfoAsync(input.PalletCode, input.LocationCode);
+                var stockInfo = await _stockInfoService.GetStockInfoAsync(3, input.LocationCode);
 
                 int locationStatus;
                 if (stockInfo == null)
+                    return content.Error("WMS鏈壘鍒板簱瀛樹俊鎭�");
+                locationStatus = MapLocationStatus(stockInfo.StockStatus);
+
+                int MapLocationStatus(int stockStatus) => stockStatus switch
                 {
-                    var location = await _locationInfoService.GetLocationInfoAsync(input.LocationCode);
-                    locationStatus = location?.LocationStatus ?? 0;
-                }
-                else
-                {
-                    locationStatus = stockInfo.LocationDetails?.LocationStatus ?? 0;
-                }
+                    (int)StockStatusEmun.鍏ュ簱瀹屾垚 => 10,
+                    (int)StockStatusEmun.绌烘墭鐩樺簱瀛� => 11,
+                    _ => 0
+                };
 
                 OutputDto outPutDto = new OutputDto()
                 {
                     LocationCode = input.LocationCode,
-                    PalletCode = input.PalletCode,
+                    PalletCode = stockInfo.PalletCode,
                     IsNormalProcedure = 1,
                     LocationStatus = locationStatus
                 };
@@ -91,8 +75,8 @@
                 var result = await _locationInfoService.Db.Updateable<Dt_LocationInfo>()
                     .SetColumns(s => new Dt_LocationInfo
                     {
-                        LocationStatus = input.LocationStatus
-                    }).Where(s => s.LocationCode == input.LocationCode).ExecuteCommandAsync() > 0;
+                        EnableStatus = input.LocationStatus == 1 ? 0 : 3,
+                    }).Where(s => s.LocationCode == input.LocationCode && s.RoadwayNo == TaskAddressConstants.GRADING_RoadWayNo).ExecuteCommandAsync() > 0;
 
                 if (result)
                 {
@@ -127,40 +111,41 @@
                 var stock = await _stockInfoService.GetStockInfoAsync(input.PalletCode, input.LocationCode);
                 if (stock == null)
                 {
-                    content.Error("鏈壘鍒板搴旂殑鎵樼洏");
+                    return content.Error("鏈壘鍒板搴旂殑鎵樼洏");
                 }
-                else
-                {
-                    var taskList = new Dt_Task
-                    {
-                        WarehouseId = stock.WarehouseId,
-                        PalletCode = stock.PalletCode,
-                        PalletType = stock.PalletType,
-                        SourceAddress = stock.LocationCode,
-                        CurrentAddress = stock.LocationCode,
-                        NextAddress = TaskAddressConstants.DEFAULT_ADDRESS,
-                        TargetAddress = TaskAddressConstants.GRADING_OUTBOUND_ADDRESS,
-                        Roadway = stock.LocationDetails.RoadwayNo,
-                        TaskType = TaskOutboundTypeEnum.Outbound.GetHashCode(),
-                        TaskStatus = TaskOutStatusEnum.OutNew.GetHashCode(),
-                        Grade = 1,
-                        TaskNum = await BaseDal.GetTaskNo(),
-                        Creater = "system",
-                    };
 
+                var taskList = new Dt_Task
+                {
+                    WarehouseId = stock.WarehouseId,
+                    PalletCode = stock.PalletCode,
+                    PalletType = stock.PalletType,
+                    SourceAddress = stock.LocationCode,
+                    CurrentAddress = stock.LocationCode,
+                    NextAddress = TaskAddressConstants.GRADING_OUTBOUND_ADDRESS,
+                    TargetAddress = TaskAddressConstants.GRADING_OUTBOUND_ADDRESS,
+                    Roadway = stock.LocationDetails.RoadwayNo,
+                    TaskType = TaskOutboundTypeEnum.Outbound.GetHashCode(),
+                    TaskStatus = TaskOutStatusEnum.OutNew.GetHashCode(),
+                    Grade = 1,
+                    TaskNum = await BaseDal.GetTaskNo(),
+                    Creater = "system",
+                };
+
+                return await _unitOfWorkManage.BeginTranAsync(async () =>
+                {
                     var result = await BaseDal.AddDataAsync(taskList) > 0;
                     var wmstaskDto = result ? _mapper.Map<WMSTaskDTO>(taskList) : null;
-
-                    var httpResponse = _httpClientHelper.Post<WebResponseContent>("http://logistics-service/api/logistics/notifyoutbound", JsonSerializer.Serialize(wmstaskDto)).Data;
+                    var wmsTaskDtos = new List<WMSTaskDTO> { wmstaskDto };
+                    var httpResponse = _httpClientHelper.Post<WebResponseContent>("http://localhost:9292/api/Task/ReceiveTask", JsonSerializer.Serialize(wmsTaskDtos)).Data;
                     if (result && httpResponse != null)
                     {
-                        content.OK("鍑哄簱璇锋眰鎴愬姛");
+                        return content.OK("鍑哄簱璇锋眰鎴愬姛");
                     }
                     else
                     {
-                        content.Error("鍑哄簱璇锋眰澶辫触");
+                        return content.Error("鍑哄簱璇锋眰澶辫触");
                     }
-                }
+                });
             }
             catch (Exception ex)
             {
@@ -188,15 +173,19 @@
                 {
                     return content.Error("鏈壘鍒板搴旂殑鎵樼洏");
                 }
-                var outPutDtos = stockInfo.Details.Select(x => new OutputDto()
+
+                var outPutDtos = new
                 {
-                    LocationCode = input.LocationCode,
-                    PalletCode = input.PalletCode,
+                    input.LocationCode,
+                    input.PalletCode,
                     IsNormalProcedure = 1,
-                    LocationStatus = stockInfo.LocationDetails.LocationStatus,
-                    CellCode = x.SerialNumber,
-                    Channel = x.InboundOrderRowNo.ToString()
-                }).ToList();
+                    stockInfo.LocationDetails.LocationStatus,
+                    Data = stockInfo.Details.Select(x => new CellCodeData
+                    {
+                        CellCode = x.SerialNumber,
+                        Channel = x.InboundOrderRowNo.ToString()
+                    }).ToList()
+                };
                 return content.OK(data: outPutDtos);
             }
             catch (Exception ex)

--
Gitblit v1.9.3