heshaofeng
10 天以前 b6a40a2d8fdcffb3accfc7e424c0726a87a59ddf
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs
@@ -1,5 +1,6 @@
using AutoMapper;
using SqlSugar;
using System.Dynamic;
using System.Threading.Tasks;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.OrderEnum;
@@ -96,8 +97,11 @@
                        item.Unit = purchaseToStockResult.Unit;
                        item.OrderQuantity = purchaseToStockResult.Quantity;
                    }
                    if (model.OrderType != InOrderTypeEnum.AllocatInbound.ObjToInt())
                    {
                        model.InboundOrderNo = CreateCodeByRule(nameof(RuleCodeEnum.InboundOrderRule));
                    }
                    model.InboundOrderNo = CreateCodeByRule(nameof(RuleCodeEnum.InboundOrderRule));
                    Db.InsertNav(model).Include(x => x.Details).ExecuteCommand();
                }
                return WebResponseContent.Instance.OK();
@@ -121,6 +125,10 @@
                    if (inboundOrder.Details == null || inboundOrder.Details.Count == 0)
                    {
                        return WebResponseContent.Instance.Error($"未找到入库单明细信息");
                    }
                    if (inboundOrder.OrderStatus != InOrderStatusEnum.未开始.ObjToInt())
                    {
                        return WebResponseContent.Instance.Error($"该订单状态不允许修改");
                    }
                    List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>();
                    List<Dt_InboundOrderDetail> updateInboundOrderDetails = new List<Dt_InboundOrderDetail>();
@@ -226,6 +234,10 @@
                    {
                        return WebResponseContent.Instance.Error($"未找到入库单明细信息");
                    }
                    if (inboundOrder.OrderStatus != InOrderStatusEnum.未开始.ObjToInt())
                    {
                        return WebResponseContent.Instance.Error($"该订单状态不允许删除");
                    }
                    //Db.DeleteNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                    _unitOfWorkManage.BeginTran();
                    //BaseDal.DeleteAndMoveIntoHty(inboundOrder, OperateTypeEnum.自动删除);
@@ -330,12 +342,12 @@
                if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
                //  materielGroupDTO.WarehouseCode
                var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == materielGroupDTO.WarehouseType).Select(x=>x.Code).First();
                if(string.IsNullOrEmpty(code))
                var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == materielGroupDTO.WarehouseType).Select(x => x.Code).First();
                if (string.IsNullOrEmpty(code))
                {
                    return content = WebResponseContent.Instance.Error($"仓库中没有该{materielGroupDTO.WarehouseType}编号。");
                }
                Dt_InboundOrder inboundOrder = GetInboundOrder(materielGroupDTO.OrderNo);
@@ -357,10 +369,10 @@
                if (stockInfo == null)
                {
                    stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None,LocationType=materielGroupDTO.locationType.ObjToInt() };
                    stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None, LocationType = materielGroupDTO.locationType.ObjToInt() };
                    stockInfo.Details = new List<Dt_StockInfoDetail>();
                }
                foreach (var item in dbinboundOrderDetails)
                {
                    stockInfo.Details.Add(new Dt_StockInfoDetail
@@ -374,15 +386,15 @@
                        SupplyCode = item.SupplyCode,
                        WarehouseCode = materielGroupDTO.WarehouseType,
                        StockQuantity = item.OrderQuantity,
                        BarcodeQty=item.BarcodeQty,
                        BarcodeUnit=item.BarcodeUnit,
                        FactoryArea= inboundOrder.FactoryArea,
                        Status = 0,
                        BarcodeQty = item.BarcodeQty,
                        BarcodeUnit = item.BarcodeUnit,
                        FactoryArea = inboundOrder.FactoryArea,
                        Status = 0,
                        OrderNo = inboundOrder.InboundOrderNo,
                        BusinessType = inboundOrder.BusinessType,
                    });
                    item.ReceiptQuantity = item.BarcodeQty;
                    item.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                    item.WarehouseCode = materielGroupDTO.WarehouseType;
@@ -429,7 +441,7 @@
            WebResponseContent content = new WebResponseContent();
            try
            {
            {
                (bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO);
                if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
@@ -439,7 +451,8 @@
                    return content = WebResponseContent.Instance.Error($"区域中没有该{materielGroupDTO.WarehouseCode}编号。");
                }
                if(_stockRepository.QueryFirst(x=>x.PalletCode == materielGroupDTO.PalletCode)!=null){
                if (_stockRepository.QueryFirst(x => x.PalletCode == materielGroupDTO.PalletCode) != null)
                {
                    return WebResponseContent.Instance.Error("该托盘已经组过盘");
                }
@@ -458,7 +471,7 @@
                {
                    if (stockInfo == null)
                    {
                        stockInfo = new Dt_StockInfo() { PalletType = PalletTypeEnum.Empty.ObjToInt(), StockStatus = StockStatusEmun.组盘暂存.ObjToInt(), PalletCode = materielGroupDTO.PalletCode,LocationType= materielGroupDTO.WarehouseCode.ObjToInt() };
                        stockInfo = new Dt_StockInfo() { PalletType = PalletTypeEnum.Empty.ObjToInt(), StockStatus = StockStatusEmun.组盘暂存.ObjToInt(), PalletCode = materielGroupDTO.PalletCode, LocationType = materielGroupDTO.WarehouseCode.ObjToInt() };
                        stockInfo.Details = new List<Dt_StockInfoDetail>();
                    }
                    else
@@ -639,25 +652,31 @@
            {
                return WebResponseContent.Instance.Error("托盘号不能为空");
            }
           var stock= _stockRepository.Db.Queryable<Dt_StockInfo>().Includes(o=>o.Details).First(x => x.PalletCode == palletCode );
            var stock = _stockRepository.Db.Queryable<Dt_StockInfo>().Includes(o => o.Details).First(x => x.PalletCode == palletCode && x.StockStatus == (int)StockStatusEmun.组盘暂存);
            if (stock == null)
            {
                return WebResponseContent.Instance.Error($"未找到托盘号{palletCode}对应的库存记录");
            }
            if (stock.Details == null || !stock.Details.Any())
            {
                _stockRepository.DeleteData(stock);
                return WebResponseContent.Instance.OK();
            }
            //  èŽ·å–åº“å­˜è¯¦æƒ…å…³è”çš„æ‰€æœ‰å…¥åº“å•å·
            var relatedOrderNos = stock.Details.Select(d => d.OrderNo).First();
            //  æŸ¥è¯¢æ‰€æœ‰å…³è”的入库单(含详情)
            var inboundOrders = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>()
                .Includes(x => x.Details)
                .Where(x => relatedOrderNos==x.InboundOrderNo)
                .Includes(x => x.Details)
                .Where(x => relatedOrderNos == x.InboundOrderNo)
                .First();
            var barcodes = stock.Details.Select(d => d.Barcode).ToList();
                // åŒ¹é…åº“存条码对应的入库单明细
                var matchedInboundDetails = inboundOrders.Details
                    ?.Where(d => barcodes.Contains(d.Barcode))
                    .ToList();
            // åŒ¹é…åº“存条码对应的入库单明细
            var matchedInboundDetails = inboundOrders.Details
                ?.Where(d => barcodes.Contains(d.Barcode))
                .ToList();
            foreach (var detail in matchedInboundDetails)
            {
                detail.ReceiptQuantity = 0;
@@ -667,7 +686,44 @@
            _stockDetailRepository.DeleteData(stock.Details);
            _stockRepository.DeleteData(stock);
            return WebResponseContent.Instance.OK();
            return WebResponseContent.Instance.OK("托盘撤销成功");
        }
        public override PageGridData<Dt_InboundOrder> GetPageData(PageDataOptions options)
        {
            string wheres = ValidatePageOptions(options);
            //获取排序字段
            Dictionary<string, SqlSugar.OrderByType> orderbyDic = GetPageDataSort(options, TProperties);
            List<OrderByModel> orderByModels = new List<OrderByModel>();
            foreach (var item in orderbyDic)
            {
                OrderByModel orderByModel = new()
                {
                    FieldName = item.Key,
                    OrderByType = item.Value
                };
                orderByModels.Add(orderByModel);
            }
            int totalCount = 0;
            List<SearchParameters> searchParametersList = new List<SearchParameters>();
            if (!string.IsNullOrEmpty(options.Wheres))
            {
                try
                {
                    searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
                    options.Filter = searchParametersList;
                }
                catch { }
            }
            var data = BaseDal.Db.Queryable<Dt_InboundOrder>()
                .WhereIF(!wheres.IsNullOrEmpty(), wheres)
                .OrderBy(orderByModels).Includes(x=>x.Details)
                .ToPageList(options.Page, options.Rows, ref totalCount);
            return new PageGridData<Dt_InboundOrder>(totalCount, data);
        }
    }
}