heshaofeng
2026-01-29 728f8d9084b15f8a347d62199ee6c3eead004e66
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_InboundService/InboundService.cs
@@ -18,6 +18,7 @@
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.WareHouseEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.Helper;
@@ -167,7 +168,16 @@
                {
                    return content.Error($"该托盘组盘仓库为{stockInfo.Details.FirstOrDefault()?.WarehouseCode}与当前仓库{palletDto.WarehouseType}不一致,不允许组盘");
                }
                var isWarehouse = _inboundOrderDetailRepository.QueryFirst(x => x.OrderId == inboundOrder.Id && !string.IsNullOrEmpty(x.WarehouseCode));
                if (isWarehouse != null && inboundOrder.BusinessType == "11" && isWarehouse.WarehouseCode != palletDto.WarehouseType)
                {
                    return content.Error($"一个采购单据里面不允许组盘两个仓库,请重新选择仓库,上一个组盘仓库为{isWarehouse.WarehouseCode}");
                }
                if (inboundOrder.BusinessType == "11" && inboundOrder.IsTestMaterials == 1 && (palletDto.WarehouseType != "1076" || palletDto.WarehouseType != "5057"))
                {
                    return content.Error($"该单据为试产物料,需要入库到试产仓,请重新根据厂区选择试产仓库进行组盘入库");
                }
                if (!_locationInfoService.QueryLocationCount(Convert.ToInt32(palletDto.locationType)))
                {
                    return content.Error($"该库区{palletDto.locationType}不存在空闲库位");
@@ -177,6 +187,11 @@
                if (nullpallet != null)
                {
                    return content.Error($"该托盘{palletDto.PalletCode}已经进行空托组盘,不能在进行组盘");
                }
               var outbundPallet = _stockInfoRepository.QueryFirst(x => x.StockStatus == (int)StockStatusEmun.出库完成 && x.PalletCode == palletDto.PalletCode);
                if (outbundPallet != null)
                {
                    return content.Error($"该托盘{palletDto.PalletCode}未进行取空箱,不能进行组盘");
                }
                foreach (var item in details)
@@ -436,13 +451,24 @@
                    //}
                }
                _mesReturnRecord.UpdateData(returnRecords);
                //重新回调完成的单据,更新库存状态
                foreach (var returnRecord in returnRecords)
                {
                    if (returnRecord.ReturnStatus == 1)
                    {
                        _stockInfoRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail
                        {
                            Status = StockStatusEmun.入库完成.ObjToInt()
                        }).Where(it => it.OrderNo == returnRecord.OrderNo && returnRecord.RequestData.Contains(it.Barcode)).ExecuteCommand();
                    }
                }
                var inboundOrderDetail = _inboundOrderRepository.Db.Queryable<Dt_InboundOrderDetail>()
                                        .Where(x => x.OrderId == inboundOrder.Id && x.OrderDetailStatus==(int)OrderDetailStatusEnum.Over && x.ReturnToMESStatus == 0)
                                        .Where(x => x.OrderId == inboundOrder.Id && x.OrderDetailStatus == (int)OrderDetailStatusEnum.Over && x.ReturnToMESStatus == 0)
                                        .ToList();
                var stocks = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.StockStatus == (int)StockStatusEmun.入库完成)
                                            .Where(it => SqlFunc.Subqueryable<Dt_StockInfoDetail>().Where(s => s.StockId == it.Id && s.OrderNo == inboundOrder.InboundOrderNo).Any())
                                            .Where(it => SqlFunc.Subqueryable<Dt_StockInfoDetail>().Where(s => s.StockId == it.Id && s.OrderNo == inboundOrder.InboundOrderNo && s.Status == StockStatusEmun.入库确认.ObjToInt()).Any())
                                            .ToList();
                var stockIds = stocks.Select(s => s.Id).ToList();
@@ -463,6 +489,13 @@
                                    inbound => inbound.Barcode,
                                    stockdetail => stockdetail.Barcode,
                                    (inbound, stockdetail) => inbound.Id)
                                .ToList();
                var inbounddetailBarcode = inboundOrderDetail
                                .Join(allDetailsData,
                                    inbound => inbound.Barcode,
                                    stockdetail => stockdetail.Barcode,
                                    (inbound, stockdetail) => stockdetail.Barcode)
                                .ToList();
                var detail = allDetailsData.Where(x => matchedData.Contains(x.Barcode)).ToList();
@@ -508,6 +541,11 @@
                    {
                        _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
                        .Where(it => it.OrderId == inboundOrder.Id && inbounddetailID.Contains(it.Id)).ExecuteCommand();
                        _stockInfoRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail
                        {
                            Status = StockStatusEmun.入库完成.ObjToInt()
                        }).Where(it => it.OrderNo == inboundOrder.InboundOrderNo && inbounddetailBarcode.Contains(it.Barcode)).ExecuteCommand();
                    }
                    else
                    {
@@ -531,7 +569,7 @@
                        details = FeedbackInboundDetailsModelDto(detail)
                    };
                    if (feedmodel.details.Count<=0)
                    if (feedmodel.details.Count <= 0)
                    {
                        if (returnRecords.Count() == returnRecords.Count(x => x.ReturnStatus == 1))
                        {
@@ -554,6 +592,11 @@
                    {
                        _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
                        .Where(it => inbounddetailID.Contains(it.Id)).ExecuteCommand();
                        _stockInfoRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail
                        {
                            Status = StockStatusEmun.入库完成.ObjToInt()
                        }).Where(it => it.OrderNo == inboundOrder.InboundOrderNo && inbounddetailBarcode.Contains(it.Barcode)).ExecuteCommand();
                    }
                    else
                    {
@@ -571,6 +614,7 @@
            }
        }
        public List<AllocateDtoDetail> GetAllocateDtoDetails(List<Dt_StockInfoDetail> stockInfoDetails)
        {
            var groupedData = stockInfoDetails.GroupBy(item => new { item.MaterielCode, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode })