pan
2025-12-02 373900dfbe3b0c6b435ff85b11bfed14509879e4
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_BasicService/InvokeMESService.cs
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using Dm.filter;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.Ocsp;
using SqlSugar;
@@ -36,11 +37,11 @@
        private readonly IRepository<Dt_StockInfoDetail> _stockInfoDetailRepository;
        private readonly IRepository<Dt_StockInfo> _stockInfoRepository;
        private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
        private readonly IMaterialUnitService _materialUnitService;
        private readonly IOutboundOrderService _outboundOrderService;
        private readonly IOutboundOrderDetailService _outboundOrderDetailService;
        private readonly IOutStockLockInfoService _outStockLockInfoService;
        public InvokeMESService(IHttpClientFactory httpClientFactory, ILogger<InvokeMESService> logger, IRepository<Dt_FeedbackToMes> feedbacktomesRepository, IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IOutStockLockInfoService outStockLockInfoService)
        public InvokeMESService(IHttpClientFactory httpClientFactory, ILogger<InvokeMESService> logger, IRepository<Dt_FeedbackToMes> feedbacktomesRepository, IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IOutStockLockInfoService outStockLockInfoService, IMaterialUnitService materialUnitService)
        {
            _httpClientFactory = httpClientFactory;
            _logger = logger;
@@ -51,6 +52,7 @@
            _outboundOrderService = outboundOrderService;
            _outboundOrderDetailService = outboundOrderDetailService;
            _outStockLockInfoService = outStockLockInfoService;
            _materialUnitService = materialUnitService;
        }
        /// <summary>
@@ -426,27 +428,40 @@
                {
                    // èŽ·å–è¯¥æ˜Žç»†å¯¹åº”çš„æ¡ç ä¿¡æ¯ï¼ˆä»Žé”å®šè®°å½•ï¼‰
                    var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                        .Where(x => x.OrderNo == orderNo && detailids.Contains(x.OrderDetailId) &&
                        .Where(x => x.OrderNo == orderNo && detail.Id == x.OrderDetailId &&
                                   x.Status == (int)OutLockStockStatusEnum.拣选完成)
                        .ToListAsync();
                    var detailModel = new FeedbackOutboundDetailsModel
                    {
                        materialCode = detail.MaterielCode,
                        lineNo = detail.lineNo, // æ³¨æ„ï¼šè¿™é‡Œå¯èƒ½éœ€è¦è°ƒæ•´å­—段名
                        warehouseCode = detail.WarehouseCode,
                        qty = detail.OverOutQuantity, // ä½¿ç”¨è®¢å•明细的已出库数量
                        currentDeliveryQty = detail.OverOutQuantity,
                        unit = detail.Unit,
                        barcodes = detailLocks.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel
                        {
                            barcode = lockInfo.CurrentBarcode,
                            supplyCode = lockInfo.SupplyCode,
                            batchNo = lockInfo.BatchNo,
                            unit = lockInfo.Unit,
                            qty = lockInfo.PickedQty // æ¡ç çº§åˆ«çš„æ•°é‡ä»ç”¨é”å®šè®°å½•
                        }).ToList()
                        qty = detail.BarcodeQty, // ä½¿ç”¨è®¢å•明细的已出库数量
                        currentDeliveryQty = detail.BarcodeQty,
                        unit = detail.BarcodeUnit,
                        barcodes = new List<WIDESEA_DTO.Outbound.BarcodesModel>()
                    };
                    foreach (var item in detailLocks)
                    {
                        var barmodel = new WIDESEA_DTO.Outbound.BarcodesModel
                        {
                            barcode = item.CurrentBarcode,
                            supplyCode = item.SupplyCode,
                            batchNo = item.BatchNo,
                            unit = item.BarcodeUnit,
                            qty = item.BarcodeQty // æ¡ç çº§åˆ«çš„æ•°é‡ä»ç”¨é”å®šè®°å½•
                        };
                        if (item.BarcodeUnit != item.Unit)
                        {
                            var issueoStockResult = await _materialUnitService.ConvertAsync(item.MaterielCode, item.BarcodeQty, item.Unit, item.BarcodeUnit);
                            barmodel.unit = issueoStockResult.Unit;
                            barmodel.qty = issueoStockResult.Quantity;
                        }
                        detailModel.qty += barmodel.qty;
                        detailModel.currentDeliveryQty += barmodel.qty;
                        detailModel.barcodes.Add(barmodel);
                    }
                    feedmodel.details.Add(detailModel);
                }
@@ -470,6 +485,33 @@
                          .SetColumns(x => x.ReturnToMESStatus == 1)
                          .Where(x => x.OrderNo == orderNo)
                          .ExecuteCommandAsync();
                    }
                    else
                    {
                        var dborderDetails = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
                              .LeftJoin<Dt_OutboundOrder>((o, item) => o.OrderId == item.Id)
                              .Where((o, item) => item.OrderNo == orderNo && item.ReturnToMESStatus != 1)
                              .Select((o, item) => o)
                              .ToListAsync();
                        var secallCompleted = true;
                        foreach (var detail in orderDetails.Where(x => x.ReturnToMESStatus == 0).ToList())
                        {
                            if (detail.OverOutQuantity < detail.NeedOutQuantity)
                            {
                                secallCompleted = false;
                            }
                        }
                        if (secallCompleted)
                        {
                            await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
                                 .SetColumns(it => new Dt_OutboundOrder
                                 {
                                     ReturnToMESStatus = 1,
                                     OrderStatus = OutOrderStatusEnum.出库完成.ObjToInt(),
                                 })
                                 .Where(x => x.OrderNo == orderNo)
                                 .ExecuteCommandAsync();
                        }
                    }
                }
                else
@@ -559,16 +601,16 @@
                            materialCode = detail.MaterielCode,
                            lineNo = detail.lineNo, // æ³¨æ„ï¼šè¿™é‡Œå¯èƒ½éœ€è¦è°ƒæ•´å­—段名
                            warehouseCode = detail.WarehouseCode,
                            qty = detail.OverOutQuantity, // ä½¿ç”¨è®¢å•明细的已出库数量
                            currentDeliveryQty = detail.OverOutQuantity,
                            unit = detail.Unit,
                            qty = detail.BarcodeQty,
                            currentDeliveryQty = detail.BarcodeQty,
                            unit = detail.BarcodeUnit,
                            barcodes = detailLocks.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel
                            {
                                barcode = lockInfo.CurrentBarcode,
                                supplyCode = lockInfo.SupplyCode,
                                batchNo = lockInfo.BatchNo,
                                unit = lockInfo.Unit,
                                qty = lockInfo.PickedQty // æ¡ç çº§åˆ«çš„æ•°é‡ä»ç”¨é”å®šè®°å½•
                                unit = lockInfo.BarcodeUnit,
                                qty = lockInfo.BarcodeQty // æ¡ç çº§åˆ«çš„æ•°é‡ä»ç”¨é”å®šè®°å½•
                            }).ToList()
                        };