1
647556386
2026-01-07 d4b697babbaa3703e9b27f919c3bb813ca1c814e
1
已修改1个文件
143 ■■■■■ 文件已修改
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs 143 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs
@@ -34,6 +34,8 @@
using WIDESEA_BasicService.MESOperation;
using WIDESEA_Core.Util;
using WIDESEA_DTO.Allocate;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using WIDESEA_IRecordService;
namespace WIDESEA_OutboundService
{
@@ -70,6 +72,8 @@
        private readonly IFeedbackMesService _feedbackMesService;
        private readonly HttpClientHelper _httpClientHelper;
        private readonly IRepository<Dt_MesReturnRecord> _mesReturnRecord;
        private readonly IStockQuantityChangeRecordService _stockQuantityChangeRecordService;
        private readonly IInboundOrderService _inboundOrderService;
        private Dictionary<string, string> stations = new Dictionary<string, string>
        {
@@ -88,7 +92,7 @@
        public OutboundPickingService(IRepository<Dt_PickingRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IStockService stockService,
            IOutStockLockInfoService outStockLockInfoService, IStockInfoDetailService stockInfoDetailService, ILocationInfoService locationInfoService,
            IOutboundOrderDetailService outboundOrderDetailService, ISplitPackageService splitPackageService, IOutboundOrderService outboundOrderService,
            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository, IInboundOrderDetailService inboundOrderDetailService, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IReCheckOrderService reCheckOrderService, ITask_HtyService task_HtyService, IRepository<Dt_InterfaceLog> interfaceLog, IInboundService inboundService, IFeedbackMesService feedbackMesService, HttpClientHelper httpClientHelper, IRepository<Dt_MesReturnRecord> mesReturnRecord) : base(BaseDal)
            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository, IInboundOrderDetailService inboundOrderDetailService, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IReCheckOrderService reCheckOrderService, ITask_HtyService task_HtyService, IRepository<Dt_InterfaceLog> interfaceLog, IInboundService inboundService, IFeedbackMesService feedbackMesService, HttpClientHelper httpClientHelper, IRepository<Dt_MesReturnRecord> mesReturnRecord,IStockQuantityChangeRecordService stockQuantityChangeRecordService,IInboundOrderService inboundOrderService) : base(BaseDal)
        {
            _unitOfWorkManage = unitOfWorkManage;
            _stockInfoService = stockInfoService;
@@ -115,6 +119,8 @@
            _feedbackMesService = feedbackMesService;
            _httpClientHelper = httpClientHelper;
            _mesReturnRecord = mesReturnRecord;
            _stockQuantityChangeRecordService = stockQuantityChangeRecordService;
            _inboundOrderService = inboundOrderService;
        }
@@ -2592,13 +2598,14 @@
                Dictionary<int, Dt_InboundOrder> updateInboundOrders = new Dictionary<int, Dt_InboundOrder>();
                List<Dt_StockQuantityChangeRecord> changeRecords = new List<Dt_StockQuantityChangeRecord>();
                _unitOfWorkManage.BeginTran();
                List<Dt_InboundOrderDetail> allInboundDetails = _inboundOrderDetailService.Db
                    .Queryable<Dt_InboundOrderDetail>()
                    .Where(detail => noStockOutSubmit.BarCodeSubmit.Contains(detail.Barcode)
                        && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt())
                    .ToList();
                .Queryable<Dt_InboundOrderDetail>()
                .Where(detail => noStockOutSubmit.BarCodeSubmit.Contains(detail.Barcode)
                    && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt())
                .ToList();
                var detailGroupByOrderId = allInboundDetails.GroupBy(d => d.OrderId).ToList();
                foreach (var group in detailGroupByOrderId)
@@ -2607,8 +2614,24 @@
                    List<Dt_InboundOrderDetail> groupDetails = group.ToList();
                    List<string> groupBarCodes = groupDetails.Select(d => d.Barcode).ToList();
                    orderIdBarCodeDict[orderId] = groupBarCodes;
                    Dt_InboundOrder currentInboundOrder = null;
                    if (!updateInboundOrders.TryGetValue(orderId, out currentInboundOrder))
                    {
                        currentInboundOrder = _inboundOrderRepository.Db
                            .Queryable<Dt_InboundOrder>()
                            .Where(x => x.Id == orderId)
                            .Includes(x => x.Details)
                            .First();
                        if (currentInboundOrder == null)
                        {
                            _unitOfWorkManage.RollbackTran();
                            return WebResponseContent.Instance.Error($"未找到入库单ID为 {orderId} çš„单据");
                        }
                        updateInboundOrders[orderId] = currentInboundOrder;
                    }
                    foreach (var detail in groupDetails)
                    {
@@ -2620,53 +2643,49 @@
                            detail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                        }
                        updateInboundDetails.Add(detail);
                    }
                    if (!updateInboundOrders.ContainsKey(orderId))
                    {
                        Dt_InboundOrder inboundOrder = _inboundOrderRepository.Db
                            .Queryable<Dt_InboundOrder>()
                            .Where(x => x.Id == orderId)
                            .Includes(x => x.Details)
                            .First();
                        if (inboundOrder == null)
                        //添加库存变动记录
                        Dt_StockQuantityChangeRecord changeRecord = new Dt_StockQuantityChangeRecord
                        {
                            _unitOfWorkManage.RollbackTran();
                            return WebResponseContent.Instance.Error($"未找到入库单ID为 {orderId} çš„单据");
                        }
                        // åˆ¤æ–­æ•´å•是否全部完成
                        int totalDetailCount = inboundOrder.Details.Count();
                        int beforeDetailCount = inboundOrder.Details.Where(x => x.OrderId == orderId && x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt())
                            .Count();
                        int finishedDetailCount = updateInboundDetails
                            .Where(x => x.OrderId == orderId && x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt())
                            .Count();
                        inboundOrder.OrderStatus = totalDetailCount == finishedDetailCount+beforeDetailCount
                            ? InOrderStatusEnum.入库完成.ObjToInt()
                            : InOrderStatusEnum.入库中.ObjToInt();
                        updateInboundOrders[orderId] = inboundOrder;
                            StockDetailId = detail.Id,
                            PalleCode = DateTime.Now.ToString(),
                            MaterielCode = detail.MaterielCode,
                            MaterielName = detail.MaterielName ?? "",
                            BatchNo = detail.BatchNo ?? "",
                            OriginalSerilNumber = detail.Barcode,
                            NewSerilNumber = "",
                            OrderNo = currentInboundOrder.InboundOrderNo,
                            TaskNum = 0,
                            ChangeType = (int)StockChangeTypeEnum.Inbound,
                            ChangeQuantity = detail.NoStockOutQty,
                            BeforeQuantity = detail.OverInQuantity - detail.NoStockOutQty,
                            AfterQuantity = detail.OverInQuantity,
                            SupplyCode = detail.SupplyCode ?? "",
                            WarehouseCode = detail.WarehouseCode ?? "",
                            Remark = $"虚拟入库"
                        };
                        changeRecords.Add(changeRecord);
                    }
                    var inboundOrder = updateInboundOrders[orderId];
                    int totalDetailCount = inboundOrder.Details.Count;
                    int finishedDetailCount = inboundOrder.Details.Count(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt())
                                             + groupDetails.Count(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt());
                    inboundOrder.OrderStatus = totalDetailCount == finishedDetailCount
                        ? InOrderStatusEnum.入库完成.ObjToInt()
                        : InOrderStatusEnum.入库中.ObjToInt();
                }
                // 6. æ‰¹é‡æ›´æ–°æ˜Žç»†å’Œä¸»å•(批量操作提升性能)
                if (updateInboundDetails.Any())
                {
                    foreach (var detail in updateInboundDetails)
                    {
                        _inboundOrderDetailService.UpdateData(detail);
                    }
                    _inboundOrderDetailService.Db.Updateable(updateInboundDetails).ExecuteCommand();
                }
                if (updateInboundOrders.Any())
                {
                    foreach (var order in updateInboundOrders.Values)
                    {
                        _inboundOrderRepository.UpdateData(order);
                    }
                    // æ‰¹é‡æ›´æ–°å…¥åº“主单
                    _inboundOrderService.Db.Updateable(updateInboundOrders.Values.ToList()).ExecuteCommand();
                }
                // 7. å¾ªçŽ¯åˆ†ç»„ç»“æžœï¼Œè°ƒç”¨MES回传方法(按入库单分组回传)
@@ -2676,15 +2695,15 @@
                    List<string> barCodeList = kvp.Value;
                    //入库回传MES
                    NoStockOutBatchInOrderFeedbackToMes(orderId, barCodeList);
                }
                //只对出库条码的出库单明细进行计算回传
                List<Dt_OutboundOrderDetail> outboundOrderDetail = outboundOrder.Details
    .Where(x => !string.IsNullOrWhiteSpace(x.documentsNO)
        && noStockOutSubmit.BarCodeSubmit.Any(barcode =>
            x.documentsNO.IndexOf(barcode, StringComparison.OrdinalIgnoreCase) >= 0))
    .ToList();
                .Where(x => !string.IsNullOrWhiteSpace(x.documentsNO)
                    && noStockOutSubmit.BarCodeSubmit.Any(barcode =>
                        x.documentsNO.IndexOf(barcode, StringComparison.OrdinalIgnoreCase) >= 0))
                .ToList();
                foreach (var item in outboundOrderDetail)
                {
@@ -2711,12 +2730,36 @@
                        ContractResolver = new CamelCasePropertyNamesContractResolver()
                    };
                    item.ReturnJsonData = JsonConvert.SerializeObject(barcodesList, settings);
                    //添加库存变动记录
                    Dt_StockQuantityChangeRecord changeRecord = new Dt_StockQuantityChangeRecord
                    {
                        StockDetailId = item.Id,
                        PalleCode = DateTime.Now.ToString(),
                        MaterielCode = item.MaterielCode,
                        MaterielName = item.MaterielName ?? "",
                        BatchNo = item.BatchNo ?? "",
                        OriginalSerilNumber = item.ReturnJsonData,
                        NewSerilNumber = "",
                        OrderNo = outboundOrder.OrderNo,
                        TaskNum = 0,
                        ChangeType = (int)StockChangeTypeEnum.Inbound,
                        ChangeQuantity = -item.NoStockOutQty,
                        BeforeQuantity = item.OrderQuantity - item.OverOutQuantity-item.MoveQty,
                        AfterQuantity = item.OrderQuantity - item.OverOutQuantity - item.MoveQty - item.NoStockOutQty,
                        SupplyCode = item.SupplyCode ?? "",
                        WarehouseCode = item.WarehouseCode ?? "",
                        Remark = $"虚拟出库"
                    };
                    changeRecords.Add(changeRecord);
                    outboundOrderDetails.Add(item);
                }
                _outboundOrderDetailService.UpdateData(outboundOrderDetails);
                //批量添加库存变动记录
                if (changeRecords.Any())
                {
                    _stockQuantityChangeRecordService.Db.Insertable(changeRecords).ExecuteCommand();
                }
                // æ£€æŸ¥å‡ºåº“单是否完成
                if (CheckOutboundOrderCompleted(outboundOrder.OrderNo))
                {