heshaofeng
2025-12-29 266e4bf654c55ce2f7e9271048e4625f1b8b49f6
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundService.cs
@@ -1,4 +1,5 @@
using AutoMapper;
using System.Reflection.Emit;
using AutoMapper;
using Dm.filter;
using MailKit.Search;
using Mapster;
@@ -7,8 +8,8 @@
using Org.BouncyCastle.Asn1.Ocsp;
using Org.BouncyCastle.Crypto;
using SqlSugar;
using System.Reflection.Emit;
using WIDESEA_BasicService;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.StockEnum;
@@ -17,6 +18,7 @@
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.CodeConfigEnum;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.CalcOut;
using WIDESEA_DTO.ReturnMES;
using WIDESEA_IBasicService;
@@ -24,6 +26,7 @@
using WIDESEA_IRecordService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
using static HslCommunication.Profinet.Knx.KnxCode;
namespace WIDESEA_OutboundService
{
@@ -53,8 +56,23 @@
        private readonly IFeedbackMesService _feedbackMesService;
        private readonly IRepository<Dt_Task> _taskRepository;
        private readonly ILocationInfoService _locationInfoService;
        private readonly IESSApiService _eSSApiService;
        private readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository;
        private readonly IRepository<Dt_AllocateMaterialInfo> _allocateMaterialInfoRepository;
        public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService)
        private Dictionary<string, string> stations = new Dictionary<string, string>
        {
            {"2-1","2-9" },
            {"3-1","3-9" },
        };
        private Dictionary<string, string> movestations = new Dictionary<string, string>
        {
            {"2-1","2-5" },
            {"3-1","3-5" },
        };
        public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfoRepository)
        {
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
@@ -74,6 +92,9 @@
            _feedbackMesService = feedbackMesService;
            _taskRepository = taskRepository;
            _locationInfoService = locationInfoService;
            _eSSApiService = eSSApiService;
            _allocateOrderRepository = allocateOrderRepository;
            _allocateMaterialInfoRepository = allocateMaterialInfoRepository;
        }
        #region å‡ºåº“分配
@@ -89,6 +110,7 @@
            PickingOutboundResponseDTO response = new PickingOutboundResponseDTO();
            try
            {
                _unitOfWorkManage.BeginTran();
                // 1. è®¡ç®—出库数量逻辑
                OutboundCalculationDTO calculationResult = CalcOutboundQuantity(request);
@@ -149,7 +171,8 @@
                    pickedDetails.AddRange(materielPickedDetails.PickedDetails);
                    decimal allallocatedQuantity = materielCalc.UnallocatedQuantity;
                    decimal allallocatedQuantity = Math.Min(materielCalc.UnallocatedQuantity, materielPickedDetails.PickedDetails.Sum(x => x.OutboundQuantity));
                    materielCalc.UnallocatedQuantity = allallocatedQuantity;
                    // æ›´æ–°å‡ºåº“单明细(增加锁定数量,不增加已出数量)
                    foreach (var detail in materielCalc.Details)
                    {
@@ -227,14 +250,23 @@
                }
                result.FactoryArea = outboundOrder.FactoryArea;
                List<Dt_OutboundOrderDetail> selectedDetails = new List<Dt_OutboundOrderDetail>();
                // èŽ·å–é€‰æ‹©çš„å‡ºåº“æ˜Žç»†
                List<Dt_OutboundOrderDetail> selectedDetails = _detailRepository.QueryData(x => x.OrderId == outboundOrder.Id && request.DetailIds.Contains(x.Id));
                if (outboundOrder.IsBatch == 1)
                if (request.DetailIds == null || !request.DetailIds.Any())
                {
                    selectedDetails = _detailRepository.QueryData(x => x.WarehouseCode == selectedDetails.First().WarehouseCode && x.MaterielCode == selectedDetails.First().MaterielCode && x.BatchNo == selectedDetails.First().BatchNo && x.SupplyCode == selectedDetails.First().SupplyCode);
                    selectedDetails = _detailRepository.QueryData(x => x.OrderId == outboundOrder.Id);
                }
                else
                {
                    // èŽ·å–é€‰æ‹©çš„å‡ºåº“æ˜Žç»†
                    selectedDetails = _detailRepository.QueryData(x => x.OrderId == outboundOrder.Id && request.DetailIds.Contains(x.Id));
                }
                //if (outboundOrder.IsBatch == 1 && request.DetailIds.Count == 1)
                //{
                //    selectedDetails = _detailRepository.QueryData(x => x.OrderId == selectedDetails.First().OrderId && x.WarehouseCode == selectedDetails.First().WarehouseCode && x.MaterielCode == selectedDetails.First().MaterielCode && x.BatchNo == selectedDetails.First().BatchNo && x.SupplyCode == selectedDetails.First().SupplyCode);
                //}
                if (!selectedDetails.Any())
@@ -255,7 +287,7 @@
                result.OutboundOrder = outboundOrder;
                result.SelectedDetails = selectedDetails;
                if (outboundOrder.IsBatch == 0)
                if (outboundOrder.IsBatch == 0 || request.DetailIds.Count != 1)
                {
                    // å¤šæ˜Žç»†å‡ºåº“:按物料分组处理
                    result.MaterielCalculations = CalcMaterielOutboundQuantities(outboundOrder, selectedDetails.ToList());
@@ -342,7 +374,6 @@
                .GroupBy(x => new
                {
                    x.MaterielCode,
                    x.MaterielName,
                    x.BatchNo,
                    x.SupplyCode,
                    x.WarehouseCode
@@ -350,7 +381,6 @@
                .Select(g => new MaterielOutboundCalculationDTO
                {
                    MaterielCode = g.Key.MaterielCode,
                    MaterielName = g.Key.MaterielName,
                    BatchNo = g.Key.BatchNo,
                    SupplyCode = g.Key.SupplyCode,
                    WarehouseCode = g.Key.WarehouseCode,
@@ -402,13 +432,15 @@
            Dictionary<int, List<Dt_OutStockLockInfo>> lockStockMap = data.LockStockMap;
            // éªŒè¯æ€»å¯ç”¨åº“存是否满足出库需求
            if (totalAvailableStock < materielCalc.UnallocatedQuantity)
            {
                throw new Exception($"物料 {materielCalc.MaterielCode} å¯ç”¨åº“å­˜ {totalAvailableStock} ä¸è¶³å‡ºåº“数量 {materielCalc.UnallocatedQuantity}");
            }
            //if (totalAvailableStock < materielCalc.UnallocatedQuantity)
            //{
            //    throw new Exception($"物料 {materielCalc.MaterielCode} å¯ç”¨åº“å­˜ {totalAvailableStock} ä¸è¶³å‡ºåº“数量 {materielCalc.UnallocatedQuantity}");
            //}
            // éœ€åˆ†é…æ•°é‡
            decimal remainingQuantity = Math.Min(totalAvailableStock, materielCalc.UnallocatedQuantity);
            // éœ€åˆ†é…æ•°é‡
            decimal remainingQuantity = materielCalc.UnallocatedQuantity;
            //decimal remainingQuantity = materielCalc.UnallocatedQuantity;
            // å·²åˆ†é…çš„æ‰˜ç›˜åˆ—表
            List<string> allocatedPallets = new List<string>();
@@ -517,7 +549,7 @@
        private List<Dt_StockInfo> BuildStockQueryWithInfo(MaterielOutboundCalculationDTO materielCalc, string factoryArea)
        {
            // åŸºç¡€æŸ¥è¯¢æ¡ä»¶ï¼šç‰©æ–™ç¼–号、批次号(如果提供)、库存数量>0
            ISugarQueryable<Dt_StockInfoDetail> stockDetails = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.MaterielCode == materielCalc.MaterielCode && x.StockQuantity > 0);
            ISugarQueryable<Dt_StockInfoDetail> stockDetails = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.MaterielCode == materielCalc.MaterielCode && x.StockQuantity > 0 && (x.Status == (int)StockStatusEmun.入库完成 || x.Status == (int)StockStatusEmun.手动解锁));
            // æ ¹æ®æ¡ä»¶æ·»åŠ ä¾›åº”å•†ç¼–å·åŒ¹é…ï¼ˆä¸ä¸ºç©ºæ—¶æ‰éœ€è¦åŒ¹é…ï¼‰
            if (!string.IsNullOrEmpty(materielCalc.SupplyCode))
@@ -822,8 +854,7 @@
        }
        #endregion
        #region æ•´ç®±å‡ºåº“
        public WebResponseContent CompleteOutboundWithPallet(OutboundCompletePalletRequestDTO request)
        {
            WebResponseContent content = WebResponseContent.Instance;
@@ -937,6 +968,33 @@
                    // æ•´ç®±å‡ºåº“无需拆包
                    PerformFullOutboundOperation(stockInfo, request, lockInfo.TaskNum.GetValueOrDefault());
                    if (outboundOrder.OrderType != 0)
                    {
                        Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo);
                        if (allocateOrder != null)
                        {
                            List<Dt_AllocateMaterialInfo> allocateMaterialInfos = new List<Dt_AllocateMaterialInfo>();
                            foreach (var item in stockInfo.Details)
                            {
                                Dt_AllocateMaterialInfo allocateMaterialInfo = new Dt_AllocateMaterialInfo()
                                {
                                    Barcode = item.Barcode,
                                    BatchNo = item.BatchNo,
                                    FactoryArea = item.FactoryArea,
                                    MaterialCode = item.MaterielCode,
                                    MaterialName = item.MaterielName,
                                    OrderId = outboundOrder.Id,
                                    OrderNo = outboundOrder.OrderNo,
                                    Quantity = item.StockQuantity,
                                    SupplyCode = item.SupplyCode,
                                    Unit = item.Unit,
                                    WarehouseCode = allocateOrder.ToWarehouse
                                };
                                allocateMaterialInfos.Add(allocateMaterialInfo);
                            }
                            _allocateMaterialInfoRepository.AddData(allocateMaterialInfos);
                        }
                    }
                    decimal allocatedQuantity = actualOutboundQuantity;
                    List<Dt_OutboundOrderDetail> updateDetails = new();
@@ -957,34 +1015,41 @@
                        //}
                        List<Barcodes> barcodesList = new List<Barcodes>();
                        List<Dt_StockInfoDetail> stockInfoDetails = stockInfo.Details.Where((x => x.StockQuantity > x.OutboundQuantity)).ToList();
                        decimal itemQuantity = item.LockQuantity - item.OverOutQuantity;
                        foreach (var stockDetail in stockInfoDetails)
                        {
                            if (item.LockQuantity - item.OverOutQuantity >= stockDetail.StockQuantity - stockInfoDetail.OutboundQuantity)
                            if (itemQuantity >= stockDetail.StockQuantity - stockDetail.OutboundQuantity)
                            {
                                Barcodes barcodes = new Barcodes
                                {
                                    Barcode = stockDetail.Barcode,
                                    Qty = stockDetail.StockQuantity - stockInfoDetail.OutboundQuantity,
                                    Qty = stockDetail.StockQuantity - stockDetail.OutboundQuantity,
                                    SupplyCode = stockDetail?.SupplyCode ?? "",
                                    BatchNo = stockDetail?.BatchNo ?? "",
                                    Unit = stockDetail?.Unit ?? ""
                                };
                                stockDetail.StockQuantity = stockInfoDetail.OutboundQuantity;
                                itemQuantity -= (stockDetail.StockQuantity - stockDetail.OutboundQuantity);
                                stockDetail.OutboundQuantity = stockDetail.StockQuantity;
                                barcodesList.Add(barcodes);
                                if (itemQuantity <= 0) break;
                            }
                            else
                            {
                                Barcodes barcodes = new Barcodes
                                {
                                    Barcode = stockDetail.Barcode,
                                    Qty = item.LockQuantity - item.OverOutQuantity,
                                    Qty = itemQuantity,
                                    SupplyCode = stockDetail?.SupplyCode ?? "",
                                    BatchNo = stockDetail?.BatchNo ?? "",
                                    Unit = stockDetail?.Unit ?? ""
                                };
                                stockInfoDetail.OutboundQuantity += item.LockQuantity - item.OverOutQuantity;
                                stockDetail.OutboundQuantity += itemQuantity;
                                barcodesList.Add(barcodes);
                                break;
                            }
                        }
@@ -1049,8 +1114,11 @@
                    {
                        UpdateOutboundOrderStatus(request.OrderNo, OutOrderStatusEnum.出库完成.ObjToInt());
                        if (outboundOrder.OrderType != OutOrderTypeEnum.InternalAllocat.ObjToInt())
                        {
                            _feedbackMesService.OutboundFeedback(outboundOrder.OrderNo);
                        }
                        //todo: å›žä¼ MES
                    }
                }
                catch (Exception ex)
@@ -1115,6 +1183,8 @@
                    FactoryArea = item.FactoryArea,
                    WarehouseCode = item.WarehouseCode,
                    Barcode = item.Barcode,
                    CreateDate = item.CreateDate,
                    Creater = item.Creater,
                    Remark = $"整箱出库完成删除,条码:{request.PalletCode},原数量:{item.StockQuantity},出库数量:{item.StockQuantity},操作者:{request.Operator}"
                };
                historyRecords.Add(historyRecord);
@@ -1147,6 +1217,7 @@
            _stockDetailRepository.DeleteData(stockInfo.Details);
            _stockChangeRepository.AddData(changeRecords);
        }
        #endregion
        #region æ‹£é€‰
        /// <summary>
@@ -1253,21 +1324,76 @@
                // 8. åˆ¤æ–­æ˜¯å¦éœ€è¦æ‹†åŒ…(当出库数量小于库存数量时需要拆包)
                bool isUnpacked = actualOutboundQuantity < stockDetail.StockQuantity;
                List<MaterialCodeReturnDTO> returnDTOs = new List<MaterialCodeReturnDTO>();
                string newBarcode = string.Empty;
                // 9. å¼€å¯äº‹åŠ¡
                _unitOfWorkManage.BeginTran();
                try
                {
                    decimal beforeQuantity = stockDetail.StockQuantity; // åŽŸå§‹åº“å­˜é‡
                    Dt_AllocateMaterialInfo allocateMaterialInfo = new Dt_AllocateMaterialInfo();
                    // æ ¹æ®æ˜¯å¦æ‹†åŒ…执行不同的操作
                    if (isUnpacked)
                    {
                        returnDTOs = PerformUnpackOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault());
                        (string NewBarcode, List<MaterialCodeReturnDTO> MaterialCodeReturnDTOs) result = PerformUnpackOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault(), outboundOrder.Id, outboundOrder.OrderNo);
                        returnDTOs = result.MaterialCodeReturnDTOs;
                        newBarcode = result.NewBarcode;
                        MaterialCodeReturnDTO returnDTO = returnDTOs.First(x => x.Barcode == newBarcode);
                        if (outboundOrder.OrderType != 0)
                        {
                            allocateMaterialInfo = new Dt_AllocateMaterialInfo()
                            {
                                Barcode = returnDTO.Barcode,
                                BatchNo = returnDTO.BatchNo,
                                FactoryArea = returnDTO.FactoryArea,
                                MaterialCode = returnDTO.MaterialCode,
                                MaterialName = returnDTO.MaterialName,
                                OrderId = outboundOrder.Id,
                                OrderNo = outboundOrder.OrderNo,
                                Quantity = returnDTO.Quantity,
                                SupplyCode = returnDTO.SuplierCode,
                                Unit = stockDetail.Unit
                            };
                        }
                    }
                    else
                    {
                        PerformFullOutboundOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault());
                        if (outboundOrder.OrderType != 0)
                        {
                            allocateMaterialInfo = new Dt_AllocateMaterialInfo()
                            {
                                Barcode = stockDetail.Barcode,
                                BatchNo = stockDetail.BatchNo,
                                FactoryArea = stockDetail.FactoryArea,
                                MaterialCode = stockDetail.MaterielCode,
                                MaterialName = stockDetail.MaterielName,
                                OrderId = outboundOrder.Id,
                                OrderNo = outboundOrder.OrderNo,
                                Quantity = stockDetail.StockQuantity,
                                SupplyCode = stockDetail.SupplyCode,
                                Unit = stockDetail.Unit
                            };
                        }
                    }
                    // åˆ¤æ–­æ˜¯å¦æ˜¯è°ƒæ‹¨å•
                    if (outboundOrder.OrderType != 0)
                    {
                        Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo);
                        if (allocateOrder != null)
                        {
                            allocateMaterialInfo.WarehouseCode = allocateOrder.ToWarehouse;
                            _allocateMaterialInfoRepository.AddData(allocateMaterialInfo);
                        }
                    }
                    decimal allocatedQuantity = actualOutboundQuantity;
@@ -1309,7 +1435,7 @@
                        List<Barcodes> barcodesList = new List<Barcodes>();
                        Barcodes barcodes = new Barcodes
                        {
                            Barcode = request.Barcode,
                            Barcode = isUnpacked ? newBarcode : stockDetail?.Barcode,
                            Qty = barcodeQuantity,
                            SupplyCode = stockDetail?.SupplyCode ?? "",
                            BatchNo = stockDetail?.BatchNo ?? "",
@@ -1369,13 +1495,21 @@
                    response.ScannedDetail = scannedDetail;
                    response.UpdatedDetails = updateDetails;
                    if (!string.IsNullOrEmpty(newBarcode))
                    {
                        // ç‰©æ–™æ–°æ¡ç å›žä¼ 
                        _feedbackMesService.BarcodeFeedback(newBarcode);
                    }
                    // æ£€æŸ¥å‡ºåº“单是否完成
                    if (CheckOutboundOrderCompleted(request.OrderNo))
                    {
                        UpdateOutboundOrderStatus(request.OrderNo, OutOrderStatusEnum.出库完成.ObjToInt());
                        //todo: å›žä¼ MES
                        if (outboundOrder.OrderType != OutOrderTypeEnum.InternalAllocat.ObjToInt())
                        {
                            _feedbackMesService.OutboundFeedback(outboundOrder.OrderNo);
                        }
                    }
                }
                catch (Exception ex)
@@ -1442,14 +1576,14 @@
        /// <param name="beforeQuantity"></param>
        /// <param name="taskNum"></param>
        /// <returns></returns>
        private List<MaterialCodeReturnDTO> PerformUnpackOperation(Dt_StockInfoDetail stockDetail, Dt_StockInfo stockInfo,
            decimal actualOutboundQuantity, OutboundCompleteRequestDTO request, decimal beforeQuantity, int taskNum)
        private (string NewBarcode, List<MaterialCodeReturnDTO> MaterialCodeReturnDTOs) PerformUnpackOperation(Dt_StockInfoDetail stockDetail, Dt_StockInfo stockInfo,
            decimal actualOutboundQuantity, OutboundCompleteRequestDTO request, decimal beforeQuantity, int taskNum, int orderId, string orderNo)
        {
            string newBarcode = GenerateNewBarcode();
            string remark = $"拆包记录,原条码:{request.Barcode},原数量:{stockDetail.StockQuantity},出库条码:{newBarcode}, å‡ºåº“数量:{actualOutboundQuantity},回库条码:{request.Barcode},回库数量:{stockDetail.StockQuantity - actualOutboundQuantity},操作者:{request.Operator}";
            List<Dt_MaterialCodeInfo> materialCodeInfos = CreateMaterialCodeInfos(stockDetail, newBarcode, actualOutboundQuantity, remark);
            List<Dt_MaterialCodeInfo> materialCodeInfos = CreateMaterialCodeInfos(stockDetail, newBarcode, actualOutboundQuantity, remark, taskNum, orderId, orderNo);
            List<MaterialCodeReturnDTO> returnDTOs = _mapper.Map<List<MaterialCodeReturnDTO>>(materialCodeInfos);
@@ -1473,9 +1607,11 @@
                Unit = stockDetail.Unit,
                InboundOrderRowNo = stockDetail.InboundOrderRowNo,
                SupplyCode = stockDetail.SupplyCode,
                Creater = stockDetail.Creater,
                CreateDate = stockDetail.CreateDate,
                FactoryArea = stockDetail.FactoryArea,
                WarehouseCode = stockDetail.WarehouseCode,
                Remark = $"拆包前原始记录,原条码:{request.Barcode},原数量:{stockDetail.StockQuantity},出库数量:{actualOutboundQuantity},操作者:{request.Operator}"
                Remark = $"拆包前原始记录,出库单号:{orderNo},出库单主键:{orderId},原条码:{request.Barcode},原数量:{stockDetail.StockQuantity},出库数量:{actualOutboundQuantity},操作者:{request.Operator}"
            };
            _stockDetailHistoryRepository.AddData(originalHistoryRecord);
@@ -1486,7 +1622,7 @@
                // æ›´æ–°åŽŸåº“å­˜æ˜Žç»†
                stockDetail.StockQuantity = remainingQuantity;
                //stockDetail.Barcode = newBarcode;
                stockDetail.Remark = $"拆包后更新,原条码:{request.Barcode},新数量:{remainingQuantity},操作者:{request.Operator}";
                stockDetail.Remark = $"拆包后更新,出库单号:{orderNo},出库单主键:{orderId},原条码:{request.Barcode},新数量:{remainingQuantity},操作者:{request.Operator}";
                _stockDetailRepository.UpdateData(stockDetail);
            }
@@ -1508,11 +1644,11 @@
                AfterQuantity = beforeQuantity - actualOutboundQuantity,
                SupplyCode = stockDetail.SupplyCode,
                WarehouseCode = stockDetail.WarehouseCode,
                Remark = $"拆包出库,原条码:{request.Barcode},新条码:{newBarcode},出库数量:{actualOutboundQuantity},剩余:{remainingQuantity},操作者:{request.Operator}"
                Remark = $"拆包出库,出库单号:{orderNo},出库单主键:{orderId},原条码:{request.Barcode},新条码:{newBarcode},出库数量:{actualOutboundQuantity},剩余:{remainingQuantity},操作者:{request.Operator}"
            };
            _stockChangeRepository.AddData(unpackChangeRecord);
            return returnDTOs;
            return (newBarcode, returnDTOs);
        }
        /// <summary>
@@ -1542,6 +1678,8 @@
                InboundOrderRowNo = stockDetail.InboundOrderRowNo,
                SupplyCode = stockDetail.SupplyCode,
                FactoryArea = stockDetail.FactoryArea,
                Creater = stockDetail.Creater,
                CreateDate = stockDetail.CreateDate,
                WarehouseCode = stockDetail.WarehouseCode,
                Remark = $"出库完成删除,条码:{request.Barcode},原数量:{stockDetail.StockQuantity},出库数量:{actualOutboundQuantity},操作者:{request.Operator}"
            };
@@ -1596,7 +1734,7 @@
        /// <param name="afterQuantity"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        private List<Dt_MaterialCodeInfo> CreateMaterialCodeInfos(Dt_StockInfoDetail stockDetail, string newBarcode, decimal splitQuantity, string remark)
        private List<Dt_MaterialCodeInfo> CreateMaterialCodeInfos(Dt_StockInfoDetail stockDetail, string newBarcode, decimal splitQuantity, string remark, int taskNum, int orderId, string orderNo)
        {
            List<Dt_MaterialCodeInfo> materialCodeInfos = new List<Dt_MaterialCodeInfo>();
@@ -1617,7 +1755,11 @@
                SuplierCode = stockDetail.SupplyCode,
                Unit = stockDetail.Unit,
                Date = DateTime.Now.ToString("yyyy-MM-dd"),
                Remark = remark
                Remark = remark,
                WarehouseCode = stockDetail.WarehouseCode,
                OrderNo = orderNo,
                OrderId = orderId,
                ReturnStatus = 0
            };
            materialCodeInfos.Add(outMaterialCodeInfo);
@@ -1636,7 +1778,11 @@
                SuplierCode = stockDetail.SupplyCode,
                Unit = stockDetail.Unit,
                Date = DateTime.Now.ToString("yyyy-MM-dd"),
                Remark = remark
                Remark = remark,
                WarehouseCode = stockDetail.WarehouseCode,
                OrderNo = orderNo,
                OrderId = orderId,
                ReturnStatus = 0
            };
            materialCodeInfos.Add(returnMaterialCodeInfo);
@@ -1696,7 +1842,7 @@
            WebResponseContent content = new WebResponseContent();
            try
            {
                var stock = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x=>x.Details).Where(x => x.PalletCode == palletCode).FirstAsync();
                var stock = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == palletCode).FirstAsync();
                if (stock == null)
                {
@@ -1710,7 +1856,7 @@
                stockInfo_Hty.SourceId = stock.Id;
                stockInfo_Hty.OperateType = "取空箱";
                stockInfo_Hty.InsertTime = DateTime.Now;
                _unitOfWorkManage.BeginTran();
                await _outboundRepository.Db.InsertNav(stockInfo_Hty).IncludesAllFirstLayer().ExecuteCommandAsync();
                await _stockInfoRepository.DeleteDataByIdAsync(stock.Id);
@@ -1726,30 +1872,38 @@
        #endregion
        #region
        public async Task<WebResponseContent> ReturnToWarehouse(string palletCode,string OrderNo,string station)
        #region å›žåº“
        public async Task<WebResponseContent> ReturnToWarehouse(string palletCode, string OrderNo, string station)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var stock = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == palletCode).FirstAsync();
                if(stock == null)
                if (stock == null)
                {
                    return content.Error($"未找到托盘{palletCode}库存信息不允许回库");
                }
                if (stock.Details.Count > 0)
                if (stock.Details.Count <= 0)
                {
                    stock.PalletType = (int)PalletTypeEnum.Empty;
                    stock.StockStatus = (int)StockStatusEmun.组盘暂存;
                    stock.LocationCode = "";
                }
                else if (stock.Details.Count > 0)
                {
                    Dt_OutStockLockInfo lockInfo = _outboundLockInfoRepository.QueryFirst(x =>
                    x.OrderNo == OrderNo &&
                    x.StockId == stock.Id &&
                    x.PalletCode == palletCode);
                       x.OrderNo == OrderNo &&
                       x.StockId == stock.Id &&
                       x.PalletCode == palletCode);
                    if (lockInfo != null && lockInfo.SortedQuantity != lockInfo.AssignQuantity)
                    {
                        return content.Error($"托盘{palletCode}库存未拣选完不允许回库");
                    }
                    stock.StockStatus = (int)StockStatusEmun.组盘暂存;
                    stock.LocationCode = "";
                }
                var task = await _taskRepository.Db.Queryable<Dt_Task>()
@@ -1766,21 +1920,27 @@
                var newTask = new Dt_Task()
                {
                    CurrentAddress = station,
                    CurrentAddress = stations.GetValueOrDefault(station) ?? "",
                    Grade = 0,
                    PalletCode = palletCode,
                    NextAddress = "",
                    OrderNo = OrderNo,
                    Roadway = newLocation.RoadwayNo,
                    SourceAddress = station,
                    SourceAddress = stations.GetValueOrDefault(station) ?? "",
                    TargetAddress = newLocation.LocationCode,
                    TaskStatus = (int)TaskStatusEnum.New,
                    TaskType = stock.Details.Count > 0 ? (int)TaskTypeEnum.InPick : (int)TaskTypeEnum.OutEmpty,
                    TaskType = stock.Details.Count > 0 ? (int)TaskTypeEnum.InPick : (int)TaskTypeEnum.InEmpty,
                    PalletType = stock.PalletType,
                    WarehouseId = stock.WarehouseId
                };
                _stockInfoRepository.UpdateData(stock);
                _taskRepository.AddData(newTask);
                var moveResult = await _eSSApiService.MoveContainerAsync(new MoveContainerRequest
                {
                    slotCode = movestations[station],
                    containerCode = palletCode
                });
                return content.OK();
            }