1
wankeda
2026-03-12 ababb6ad4189ec943009c0245db6f43396bb36ab
WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -20,20 +20,30 @@
using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Database;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Org.BouncyCastle.Asn1.Tsp;
using Spire.Pdf;
using SqlSugar;
using System;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using WIDESEA_BasicRepository;
using WIDESEA_Common;
using WIDESEA_Common.Log;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Core;
@@ -43,6 +53,7 @@
using WIDESEA_Core.Helper;
using WIDESEA_Core.TaskEnum;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.ERP;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Stock;
using WIDESEA_DTO.Task;
@@ -50,6 +61,7 @@
using WIDESEA_IBasicService;
using WIDESEA_IInboundRepository;
using WIDESEA_IInboundService;
using WIDESEA_InboundRepository;
using WIDESEA_IOutboundRepository;
using WIDESEA_IOutboundService;
using WIDESEA_IRecordService;
@@ -59,13 +71,17 @@
using WIDESEA_ITaskInfoService;
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.Inbound;
using WIDESEA_OutboundRepository;
using WIDESEA_StockRepository;
using WIDESEA_TaskInfoRepository;
using static WIDESEA_Common.Authentication;
using static WIDESEA_Common.HouseBackboundPassBack;
using static WIDESEA_Common.HouseInboundPassBack;
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;
@@ -721,6 +737,7 @@
                                }
                                if (inboundOrder.OrderStatus == InboundStatusEnum.入库完成.ObjToInt() && inboundOrder.OrderType == 0 && inboundOrder.System.Equals("SMOM"))
                                {
                                    List<Dt_StockInfo> StockInfos = _stockRepository.StockInfoRepository.Db
                                        .Queryable<Dt_StockInfo>()
                                        .Includes(x => x.Details, d => d.StockDetails)
@@ -873,7 +890,79 @@
                                        }
                                    }
                                }
                                else if (inboundOrder.OrderStatus == InboundStatusEnum.入库完成.ObjToInt() && inboundOrder.OrderType == 5 && inboundOrder.System.Equals("SMOM"))
                                {
                                    List<Dt_StockInfo> StockInfos = _stockRepository.StockInfoRepository.Db
                                         .Queryable<Dt_StockInfo>()
                                         .Includes(x => x.Details, d => d.StockDetails)
                                         .Where(x => x.WarehouseId == task.WarehouseId &&
                                                     x.Details.Any(v => v.OrderNo == inboundOrder.OrderNo))
                                         .ToList();
                                    Dt_InboundOrder? dt_InboundOrder = _inboundService.InbounOrderService.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == inboundOrder.OrderNo).Includes(x => x.Details).First();
                                    if (StockInfos.Count == 0) throw new Exception("未找到库存信息");
                                    var houseSyncretism = new NewHouseInboundPassBack
                                    {
                                        ApiType = "InventoryMoveController",
                                        Method = "AsrsUnPickingDatas",
                                        Parameters = new List<NewHouseInboundPassBack.Parame>
                                        {
                                            new NewHouseInboundPassBack.Parame
                                            {
                                                Value =  new Parame.Syncretism
                                                    {
                                                        OrderNo = inboundOrder.OrderNo,
                                                        Details =   StockInfos.SelectMany(stockInfo =>
                                                    stockInfo.Details.Select(g =>
                                                    {
                                                       //var InboundOrderde1=dt_InboundOrder.Details.FirstOrDefault;
                                                       return new Parame.Syncretism.details
                                                       {
                                                        MoveType = 0,
                                                        WareHouseCode = warehouse.WarehouseCode,
                                                        ItemCode = g.MaterielCode,
                                                        MoveNumber = g.StockQuantity,
                                                        LotNo = g.BatchNo,
                                                        WipBatch = g.BatchNo,
                                                        Lpn = g.StockDetails.FirstOrDefault().LPNNO,
                                                        LocationName = g.StockDetails.FirstOrDefault().OrinalLocation,
                                                        TargetLocName = stockInfo.LocationCode, // 添加null检查
                                                        TargetLpn = stockInfo.PalletCode, // 添加null检查
                                                       };
                                                    })).ToList()
                                                    }
                                            }
                                        }
                                    };
                                    var authResult = AuthenticateWithWMS();
                                    if (authResult.IsSuccess)
                                    {
                                        houseSyncretism.Context = new Dictionary<string, string>
                                            {
                                                { "Ticket", authResult.Ticket },
                                                { "InvOrgId", authResult.InvOrgId }
                                            };
                                        var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskin, houseSyncretism, "立库入库数量回传WMS");
                                        if (!response.Success)
                                        {
                                            throw new Exception($"操作失败: {response.Message ?? "未提供错误信息"}");
                                        }
                                    }
                                }
                                _unitOfWorkManage.CommitTran();
                                return WebResponseContent.Instance.OK();
                            }
@@ -1687,11 +1776,14 @@
                                       x.LocationName == stockInfo.LocationCode &&
                                       x.LPNNo == stockInfo.PalletCode)
                                .ToList();
                            List<Dt_NewOutboundOrderDetail> outboundOrderDetails1 = _outboundService.NewOutboundOrderDetailService.Db.Queryable<Dt_NewOutboundOrderDetail>()
                                .Where(x => x.OrderId == outboundOrder.Id)
                                .ToList();
                            if ((outboundOrderDetails == null && outboundOrderDetails1 == null) || (outboundOrderDetails.Count == 0  && outboundOrderDetails1.Count == 0))
                            List<Dt_NewOutboundOrderDetail> outboundOrderDetails1 = new List<Dt_NewOutboundOrderDetail>();
                            if (outboundOrderDetails == null || outboundOrderDetails.Count == 0)
                            {
                                outboundOrderDetails1 = _outboundService.NewOutboundOrderDetailService.Db.Queryable<Dt_NewOutboundOrderDetail>()
                                       .Where(x => x.OrderId == outboundOrder.Id)
                                       .ToList();
                            }
                            if ((outboundOrderDetails == null && outboundOrderDetails1 == null) || (outboundOrderDetails.Count == 0 && outboundOrderDetails1.Count == 0))
                            {
                                throw new Exception($"未找到托盘 {stockInfo.PalletCode} 在货位 {stockInfo.LocationCode} 上的出库单明细");
                            }
@@ -1699,6 +1791,7 @@
                            var stockInfoDetails = stockInfo.Details.ToList();
                            int overCount = outboundOrder.Details.Count(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt());
                            if (outboundOrderDetails == null || outboundOrderDetails.Count == 0)
                            {
                                foreach (var stockDetail in stockInfoDetails)
@@ -1859,7 +1952,7 @@
                                        }
                                        // 调拨出库
                                        if (outboundOrder.OrderType == 2)
                                        if (outboundOrder.OrderType == 4)
                                        {
                                            var allocate = new InventoryAllocate
                                            {
@@ -2091,7 +2184,7 @@
                                        }
                                        // 调拨出库
                                        if (outboundOrder.OrderType == 2)
                                        if (outboundOrder.OrderType == 4)
                                        {
                                            var allocate = new InventoryAllocate
                                            {
@@ -2178,14 +2271,14 @@
                        if (inboundOrder == null) return WebResponseContent.Instance.Error("未找到出库单信息");
                        List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
                        foreach(var detail in stockInfo.Details)
                        foreach (var detail in stockInfo.Details)
                        {
                            Dt_OutboundOrderDetail outboundOrderDetail = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrderDetail>()
                           .Where(x => x.OrderId == inboundOrder.Id && x.BatchNo == detail.BatchNo).First();
                            outboundOrderDetails.Add(outboundOrderDetail);
                        }
                        for(var i = 0; i<outboundOrderDetails.Count; i++)
                        for (var i = 0; i < outboundOrderDetails.Count; i++)
                        {
                            if (outboundOrderDetails[i].LocationName != null && outboundOrderDetails[i].LocationName != "")
                            {
@@ -2298,9 +2391,9 @@
                // 更新库存状态 回库单
                 AddRetrueOrder(stockInfo, inboundOrder);
                AddRetrueOrder(stockInfo, inboundOrder);
                // 区分单据数据来源更新货位状态
                if (inboundOrder.System == null)
                {
@@ -2395,7 +2488,7 @@
                var outboundOrder = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrder>()
                    .Where(x => x.OrderNo == inboundOrder.OrderNo).First();
                foreach(var outboundOrderDetail in outboundOrderDetails)
                foreach (var outboundOrderDetail in outboundOrderDetails)
                {
                    var outDetail = _outboundService.OutboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
                   .Where(x => x.OrderId == outboundOrder.Id && x.BatchNo == outboundOrderDetail.BatchNo).First();
@@ -2499,7 +2592,7 @@
                    inboundOrder.OrderStatus = OutboundStatusEnum.出库完成.ObjToInt();
                }
            }
        }
        private void DeleteAndMoveIntoHtStockStatus(Dt_StockInfo stockInfo)
@@ -2955,9 +3048,9 @@
                            }
                        }
                        // 只减去单据明细中的数量
                        matchedStockDetail.OutboundQuantity = 0;
                        matchedStockDetail.StockQuantity = outDetail.OrderQuantity;
                        matchedStockDetail.OrderNo = returnOrder.OrderNo;
                        //matchedStockDetail.OutboundQuantity = 0;
                        //matchedStockDetail.StockQuantity = outDetail.OrderQuantity;
                        //matchedStockDetail.OrderNo = returnOrder.OrderNo;
                        // 更新匹配的明细
                        _stockService.StockInfoDetailService.Repository.UpdateData(matchedStockDetail);
                    }
@@ -2972,163 +3065,165 @@
                else
                {
                    var groupedDetails = outboundOrderDetails
             .GroupBy(d => new { d.MaterielCode, d.BatchNo })
             .ToList();
                        .GroupBy(d => new { d.MaterielCode, d.BatchNo })
                        .ToList();
                    List<Dt_StockInfoDetail> processedStockDetails = new List<Dt_StockInfoDetail>();
                    List<Dt_ReturnOrder> returnOrders = new List<Dt_ReturnOrder>();
                    decimal totalOutboundQuantity = outboundOrderDetails.Sum(x => x.OrderQuantity);
                    decimal totalStockQuantity = stockInfoDetails.Sum(x => x.StockQuantity);
                    foreach (var groupeDetail in groupedDetails)
                    foreach (var detail in stockInfo.Details)
                    {
                        var outboundDetail = groupeDetail.First();
                        decimal totalOrderQuantity = groupeDetail.Sum(x => x.OrderQuantity);
                        var matchedStockDetail = stockInfoDetails.FirstOrDefault(x => x.MaterielCode == outboundDetail.MaterielCode && x.BatchNo == outboundDetail.BatchNo);
                        if (matchedStockDetail == null)
                        foreach (var groupeDetail in groupedDetails)
                        {
                            matchedStockDetail = stockInfoDetails.FirstOrDefault(x => x.MaterielCode == outboundDetail.MaterielCode);
                            if (matchedStockDetail == null)
                            var outboundDetail = groupeDetail.First();
                            if (outboundDetail.MaterielCode == detail.MaterielCode)
                            {
                                throw new Exception($"未找到匹配的库存明细信息,物料:{outboundDetail.MaterielCode}, 批次:{outboundDetail.BatchNo}");
                                decimal totalOrderQuantity = groupeDetail.Sum(x => x.OrderQuantity);
                                var matchedStockDetail = stockInfoDetails.FirstOrDefault(x => x.MaterielCode == outboundDetail.MaterielCode && x.BatchNo == outboundDetail.BatchNo);
                                if (matchedStockDetail == null)
                                {
                                    matchedStockDetail = stockInfoDetails.FirstOrDefault(x => x.MaterielCode == outboundDetail.MaterielCode);
                                    if (matchedStockDetail == null)
                                    {
                                        throw new Exception($"未找到匹配的库存明细信息,物料:{outboundDetail.MaterielCode}, 批次:{outboundDetail.BatchNo}");
                                    }
                                }
                                // 计算当前批次的剩余数量
                                decimal remainingQuantity = matchedStockDetail.StockQuantity - totalOrderQuantity;
                                if (remainingQuantity > 0)
                                {
                                    Dt_ReturnOrder returnOrder = new Dt_ReturnOrder
                                    {
                                        MaterielCode = matchedStockDetail.MaterielCode,
                                        MaterielName = matchedStockDetail.MaterielName,
                                        BatchNo = matchedStockDetail.BatchNo,
                                        OrderQuantity = remainingQuantity,
                                        ReceiptQuantity = remainingQuantity,
                                        OrderStatus = InOrderStatusEnum.未开始.ObjToInt(),
                                        LinId = matchedStockDetail.LinId,
                                        LPNNo = stockInfo.PalletCode,
                                        Creater = "LK",
                                        CreateDate = DateTime.Now,
                                        OrderType = OrderTypeEnum.余料回库单.ObjToInt(),
                                        System = "WMS",
                                        Remark = "多批次返库"  // 添加备注标识
                                    };
                                    if (outboundOrder.System == "SMOM" && stockInfo.LocationCode != null)
                                    {
                                        returnOrder.LocationCode = stockInfo.LocationCode;
                                    }
                                    // 添加返库单
                                    returnOrders.Add(returnOrder);
                                }
                                if (remainingQuantity < 0 && matchedStockDetail.StockQuantity < matchedStockDetail.OutboundQuantity)
                                {
                                    throw new Exception($"出库数量 {outboundDetail.OrderQuantity} 大于库存数量 {matchedStockDetail.StockQuantity}");
                                }
                                processedStockDetails.Add(matchedStockDetail);
                                // 处理其他批次的库存明细(全部返库)
                                var otherBatchDetails = stockInfoDetails
                                    .Where(x => !processedStockDetails.Contains(x) && x.StockQuantity > 0 && x.OutboundQuantity == 0)
                                    .ToList();
                                if (returnOrders == null || returnOrders.Count == 0)
                                {
                                    if (otherBatchDetails.Count > 0)
                                    {
                                        decimal totalOtherQuantity = otherBatchDetails.Sum(x => x.StockQuantity);
                                        // 为其他批次创建返库单(只创建一个,包含所有批次)
                                        var firstOtherDetail = otherBatchDetails.First();
                                        Dt_ReturnOrder otherReturnOrder = new Dt_ReturnOrder
                                        {
                                            MaterielCode = firstOtherDetail.MaterielCode,
                                            MaterielName = firstOtherDetail.MaterielName,
                                            BatchNo = firstOtherDetail.BatchNo,
                                            OrderQuantity = totalOtherQuantity,
                                            ReceiptQuantity = totalOtherQuantity,
                                            OrderStatus = InOrderStatusEnum.未开始.ObjToInt(),
                                            LinId = firstOtherDetail.LinId,
                                            LPNNo = stockInfo.PalletCode,
                                            Creater = "LK",
                                            CreateDate = DateTime.Now,
                                            OrderType = OrderTypeEnum.余料回库单.ObjToInt(),
                                            System = "WMS",
                                            Remark = $"多批次返库,共{otherBatchDetails.Count}个批次"
                                        };
                                        if (outboundOrder.System == "SMOM" && !string.IsNullOrEmpty(stockInfo.LocationCode))
                                        {
                                            otherReturnOrder.LocationCode = stockInfo.LocationCode;
                                        }
                                        returnOrders.Add(otherReturnOrder);
                                    }
                                }
                                else
                                {
                                    decimal totalOtherQuantity = otherBatchDetails.Sum(x => x.StockQuantity);
                                    foreach (var item in returnOrders)
                                    {
                                        item.OrderQuantity = totalOrderQuantity;
                                        item.ReceiptQuantity = totalOrderQuantity;
                                        item.Remark = $"多批次返库,共{otherBatchDetails.Count}个批次";
                                    }
                                }
                                // 批量更新已处理的库存明细
                                var updateDetails = processedStockDetails.Where(x => x.StockQuantity > 0).ToList();
                                if (updateDetails.Any())
                                {
                                    _stockService.StockInfoDetailService.Repository.UpdateData(updateDetails);
                                }
                                // 添加返库单
                                if (returnOrders.Any())
                                {
                                    _returnOrderRepository.AddData(returnOrders);
                                }
                                // 更新库存主表状态
                                decimal returnQuantity = totalStockQuantity - totalOutboundQuantity;
                                if (returnQuantity == 0 || stockInfo.Details.All(x => x.StockQuantity == x.OutboundQuantity))
                                {
                                    if (outboundOrder.System == "SMOM" && stockInfo.LocationCode != null)
                                    {
                                        Dt_LocationInfo dt_LocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
                                        dt_LocationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                                        _basicRepository.LocationInfoRepository.UpdateData(dt_LocationInfo);
                                    }
                                    //全部出库,删除库存
                                    //DeleteAndMoveIntoHtStockStatus(stockInfo);
                                    //foreach (var item in stockInfo.Details)
                                    //{
                                    //    BaseDal.Db.Deleteable(item.StockDetails).ExecuteCommand();
                                    //}
                                }
                                else if (returnQuantity > 0)
                                {
                                    // 有余料返库
                                    stockInfo.LocationCode = "";
                                    stockInfo.StockStatus = StockStatusEmun.余料退库.ObjToInt();
                                    stockInfo.Remark = $"余料退库,共{returnOrders.Count}个返库单";
                                    _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                                }
                            }
                        }
                        // 计算当前批次的剩余数量
                        decimal remainingQuantity = matchedStockDetail.StockQuantity - totalOrderQuantity;
                        if (remainingQuantity > 0)
                        {
                            Dt_ReturnOrder returnOrder = new Dt_ReturnOrder
                            {
                                MaterielCode = matchedStockDetail.MaterielCode,
                                MaterielName = matchedStockDetail.MaterielName,
                                BatchNo = matchedStockDetail.BatchNo,
                                OrderQuantity = remainingQuantity,
                                ReceiptQuantity = remainingQuantity,
                                OrderStatus = InOrderStatusEnum.未开始.ObjToInt(),
                                LinId = matchedStockDetail.LinId,
                                LPNNo = stockInfo.PalletCode,
                                Creater = "LK",
                                CreateDate = DateTime.Now,
                                OrderType = OrderTypeEnum.余料回库单.ObjToInt(),
                                System = "WMS",
                                Remark = "多批次返库"  // 添加备注标识
                            };
                            if (outboundOrder.System == "SMOM" && stockInfo.LocationCode != null)
                            {
                                returnOrder.LocationCode = stockInfo.LocationCode;
                            }
                            // 添加返库单
                            returnOrders.Add(returnOrder);
                            // 更新当前批次明细:只保留出库数量,其余返库
                            matchedStockDetail.StockQuantity = remainingQuantity;
                            matchedStockDetail.OutboundQuantity = outboundDetail.OrderQuantity;
                            //matchedStockDetail.OrderNo = returnOrder.OrderNo;
                        }
                        else if (remainingQuantity == 0)
                        {
                            // 当前批次正好出完
                            matchedStockDetail.OutboundQuantity = matchedStockDetail.StockQuantity;
                            if (matchedStockDetail.StockQuantity == totalOrderQuantity)
                            {
                                _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(
                                    matchedStockDetail, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                            }
                            else
                            {
                                matchedStockDetail.StockQuantity = 0;
                                _stockService.StockInfoDetailService.Repository.UpdateData(matchedStockDetail);
                            }
                        }
                        else
                        {
                            throw new Exception($"出库数量 {outboundDetail.OrderQuantity} 大于库存数量 {matchedStockDetail.StockQuantity}");
                        }
                        processedStockDetails.Add(matchedStockDetail);
                    }
                    // 处理其他批次的库存明细(全部返库)
                    var otherBatchDetails = stockInfoDetails
                        .Where(x => !processedStockDetails.Contains(x) && x.StockQuantity > 0)
                        .ToList();
                    if (otherBatchDetails.Count > 0)
                    {
                        decimal totalOtherQuantity = otherBatchDetails.Sum(x => x.StockQuantity);
                        // 为其他批次创建返库单(只创建一个,包含所有批次)
                        var firstOtherDetail = otherBatchDetails.First();
                        Dt_ReturnOrder otherReturnOrder = new Dt_ReturnOrder
                        {
                            MaterielCode = firstOtherDetail.MaterielCode,
                            MaterielName = firstOtherDetail.MaterielName,
                            BatchNo = firstOtherDetail.BatchNo,
                            OrderQuantity = totalOtherQuantity,
                            ReceiptQuantity = totalOtherQuantity,
                            OrderStatus = InOrderStatusEnum.未开始.ObjToInt(),
                            LinId = firstOtherDetail.LinId,
                            LPNNo = stockInfo.PalletCode,
                            Creater = "LK",
                            CreateDate = DateTime.Now,
                            OrderType = OrderTypeEnum.余料回库单.ObjToInt(),
                            System = "WMS",
                            Remark = $"多批次返库,共{otherBatchDetails.Count}个批次"
                        };
                        if (outboundOrder.System == "SMOM" && !string.IsNullOrEmpty(stockInfo.LocationCode))
                        {
                            otherReturnOrder.LocationCode = stockInfo.LocationCode;
                        }
                        returnOrders.Add(otherReturnOrder);
                    }
                    // 批量更新已处理的库存明细
                    var updateDetails = processedStockDetails.Where(x => x.StockQuantity > 0).ToList();
                    if (updateDetails.Any())
                    {
                        _stockService.StockInfoDetailService.Repository.UpdateData(updateDetails);
                    }
                    // 添加返库单
                    if (returnOrders.Any())
                    {
                        _returnOrderRepository.AddData(returnOrders);
                    }
                    // 更新库存主表状态
                    decimal returnQuantity = totalStockQuantity - totalOutboundQuantity;
                    if (returnQuantity == 0)
                    {
                        if (outboundOrder.System == "SMOM" && stockInfo.LocationCode != null)
                        {
                            Dt_LocationInfo dt_LocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
                            dt_LocationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                            _basicRepository.LocationInfoRepository.UpdateData(dt_LocationInfo);
                        }
                        // 全部出库,删除库存
                        DeleteAndMoveIntoHtStockStatus(stockInfo);
                        foreach (var item in stockInfo.Details)
                        {
                            BaseDal.Db.Deleteable(item.StockDetails).ExecuteCommand();
                        }
                    }
                    else if (returnQuantity > 0)
                    {
                        // 有余料返库
                        stockInfo.LocationCode = "";
                        stockInfo.StockStatus = StockStatusEmun.余料退库.ObjToInt();
                        stockInfo.Remark = $"余料退库,共{returnOrders.Count}个返库单";
                        _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                    }
                    _unitOfWorkManage.CommitTran();
                }
                _unitOfWorkManage.CommitTran();
            }
            catch (Exception ex)
            {
@@ -3494,12 +3589,11 @@
        {
            Console.WriteLine($"📄 正在打印到 {printerName}: {Path.GetFileName(filePath)}");
            string command = $"lpr -P {printerName} \"{filePath}\"";
            // 使用 lp 命令,添加 -o raw 选项
            string command = $"lp -d {printerName} -o raw \"{filePath}\"";
            ExecuteShellCommand(command);
        }
        /// <summary>
        /// 执行 Shell 命令
        /// </summary>