yanjinhui
2025-10-26 e1383d0a6ee0558c34f013f4e2561063bc2353b3
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs
@@ -4,7 +4,9 @@
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Common.WareHouseEnum;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
@@ -28,9 +30,12 @@
            {
                List<Dt_DeliveryOrder> deliveryOrders = new List<Dt_DeliveryOrder>();
                List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>();
                List<Dt_InventoryInfo> _InventoryInfos = new List<Dt_InventoryInfo>();
                List<Dt_Inventory_Batch> inventory_Batches = _inventory_BatchServices.Repository.QueryData(x => keys.Contains(x.Id));
                foreach (var item in inventory_Batches)
                {
                    supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
                    if (supplyTasks.Count > 0) throw new Exception($"物料编号【{item.MaterielCode}】批次号【{item.BatchNo}】已存在盘点任务,请先完成当前盘点任务");
                    List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => item.MaterielCode == x.MaterielCode && x.BatchNo == item.BatchNo);
                    if (inventoryInfos.Count > 0)
                    {
@@ -39,7 +44,7 @@
                            Dt_DeliveryOrder deliveryOrder = new Dt_DeliveryOrder()
                            {
                                Out_no = item.MaterielCode + "_" + item.BatchNo,
                                Out_type = "3",
                                Out_type = "20",
                                OutStatus = "新建",
                                Warehouse_no = items.Key,
                                Details = new List<Dt_DeliveryOrderDetail>()
@@ -60,35 +65,41 @@
                            deliveryOrder.Details.Add(deliveryOrderDetail);
                            deliveryOrders.Add(deliveryOrder);
                            #region åˆ›å»ºç›˜ç‚¹ä»»åŠ¡
                            if (items.Key != "001")// éžç«‹åº“区域需要创建盘点任务
                            //if (items.Key != "001")// éžç«‹åº“区域需要创建盘点任务
                            //{
                            foreach (var inventory in items)
                            {
                                foreach (var inventory in items)
                                Dt_SupplyTask supplyTask = new Dt_SupplyTask()
                                {
                                    Dt_SupplyTask supplyTask = new Dt_SupplyTask()
                                    {
                                        WarehouseCode = inventory.WarehouseCode,
                                        TaskStatus = SupplyStatusEnum.NewCheck.ObjToInt(),
                                        BatchNo = inventory.BatchNo,
                                        MaterielName = inventory.MaterielName,
                                        MaterielCode = inventory.MaterielCode,
                                        MaterielSpec = inventory.MaterielSpec,
                                        TaskType = TaskTypeEnum.OutInventory.ObjToInt(),
                                        CreateDate = DateTime.Now,
                                        Creater = App.User.UserName,
                                        LocationCode = inventory.LocationCode,
                                        OrderNo = deliveryOrder.Out_no,
                                        StockQuantity = inventory.StockQuantity,
                                        SupplyQuantity = 0,
                                        Remark = "盘点"
                                    };
                                    supplyTasks.Add(supplyTask);
                                }
                                    WarehouseCode = inventory.WarehouseCode,
                                    TaskStatus = SupplyStatusEnum.NewCheck.ObjToInt(),
                                    BatchNo = inventory.BatchNo,
                                    MaterielName = inventory.MaterielName,
                                    MaterielCode = inventory.MaterielCode,
                                    MaterielSpec = inventory.MaterielSpec,
                                    TaskType = TaskTypeEnum.OutInventory.ObjToInt(),
                                    CreateDate = DateTime.Now,
                                    Creater = App.User.UserName,
                                    LocationCode = inventory.LocationCode,
                                    OrderNo = deliveryOrder.Out_no,
                                    StockQuantity = inventory.StockQuantity,
                                    SupplyQuantity = 0,
                                    Remark = "盘点"
                                };
                                supplyTasks.Add(supplyTask);
                                _InventoryInfos.Add(inventory);
                            }
                            //}
                            #endregion
                        }
                    }
                }
                _InventoryInfos.ForEach(x =>
                {
                    x.StockStatus = StockStatusEmun.盘点锁定.ObjToInt();
                });
                _unitOfWorkManage.BeginTran();
                _inventoryInfoService.UpdateData(_InventoryInfos);
                _supplyTaskService.AddData(supplyTasks);
                BaseDal.Db.InsertNav(deliveryOrders)
                        .Include(x => x.Details)
@@ -104,9 +115,6 @@
            return content;
        }
        #endregion
        #region æŸ¥è¯¢ç›˜ç‚¹å•信息
        /// <summary>
@@ -125,11 +133,11 @@
                List<Dt_DeliveryOrder> dt_ReceiveOrders = new List<Dt_DeliveryOrder>();
                if (string.IsNullOrEmpty(orderNo))
                {
                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.OutStatus == "新建" || x.OutStatus == "开始") && x.Warehouse_no == warehouseCode && x.Out_type == "3").Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5);
                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.OutStatus == "新建" || x.OutStatus == "开始") && x.Warehouse_no == warehouseCode && x.Out_type == "20").Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5);
                }
                else
                {
                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.Out_no.Contains(orderNo) || x.Client_no.Contains(orderNo)) && (x.OutStatus == "新建" || x.OutStatus == "开始") && x.Out_type == "3" && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5);
                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.Out_no.Contains(orderNo) || x.Client_no.Contains(orderNo)) && (x.OutStatus == "新建" || x.OutStatus == "开始") && x.Out_type == "20" && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5);
                }
                content.OK(data: dt_ReceiveOrders);
@@ -142,6 +150,7 @@
            return content;
        }
        #endregion
        #region æŸ¥æ‰¾ç›˜ç‚¹/出库任务
        /// <summary>
        /// æŸ¥æ‰¾ç›˜ç‚¹/出库任务
@@ -163,11 +172,11 @@
                if (string.IsNullOrEmpty(LocationCode))
                {
                    supplyTasks = Db.Queryable<Dt_SupplyTask>().Where(x => x.TaskStatus == TaskStatus && x.OrderNo == orderNo && x.WarehouseCode == warehouseCode).ToPageList(pageNo, 5);
                 }
                }
                else
                {
                    supplyTasks = Db.Queryable<Dt_SupplyTask>().Where(x => x.TaskStatus == TaskStatus && x.OrderNo == orderNo && x.WarehouseCode == warehouseCode && x.LocationCode.Contains(LocationCode)).ToPageList(pageNo, 5);
                    }
                }
                content.OK(data: supplyTasks);
            }
            catch (Exception ex)
@@ -178,6 +187,7 @@
        }
        #endregion
        #region å®Œæˆç›˜ç‚¹ä»»åŠ¡
        public WebResponseContent CheckFinish(SaveModel saveModel)
        {
@@ -191,64 +201,118 @@
                if (supplyTask == null) throw new Exception("当前盘点任务已完成");
                if (supplyTask.LocationCode != LocationCode) throw new Exception($"当前盘点货位【{LocationCode}】与任务分配货位不匹配");
                supplyTask.SupplyQuantity = qty;
                content = CheckTaskFinish(supplyTask, LocationCode);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        #endregion
        #region ç›˜ç‚¹ä»»åŠ¡å®Œæˆ,平库和立库
        public WebResponseContent CheckTaskFinish(Dt_SupplyTask supplyTask, string LocationCode = null)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                supplyTask.TaskStatus = SupplyStatusEnum.CheckFinish.ObjToInt();
                Dt_DeliveryOrder cabinOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == supplyTask.OrderNo && x.Warehouse_no == supplyTask.WarehouseCode && x.Out_type == "3").Includes(x => x.Details).First();
                Dt_DeliveryOrder cabinOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == supplyTask.OrderNo && x.Warehouse_no == supplyTask.WarehouseCode && x.Out_type == "20").Includes(x => x.Details).First();
                if (cabinOrder == null) return WebResponseContent.Instance.Error($"盘点单已完成");
                Dt_DeliveryOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Batch_num == supplyTask.BatchNo && x.Reservoirarea == supplyTask.WarehouseCode && x.Goods_no == supplyTask.MaterielCode).First();
                if (cabinOrderDetail == null) return WebResponseContent.Instance.Error($"盘点单明细已完成");
                Dt_MaterielInfo materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == cabinOrderDetail.Goods_no);
                if (materielInfo == null) return WebResponseContent.Instance.Error($"请维护物料编号【{cabinOrderDetail.Goods_no}】的物料信息");
                cabinOrderDetail.Order_Outqty += supplyTask.SupplyQuantity;
                if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty)
                    return WebResponseContent.Instance.Error($"实盘数量不可超出账面数量");
                #region å¹³åº“盘点只能出现整箱差异
                if (supplyTask.WarehouseCode == WarehouseEnum.大件库.ObjToInt().ToString())
                {
                    var Qty = supplyTask.SupplyQuantity % materielInfo.BoxQty;
                    if (Qty != 0) return WebResponseContent.Instance.Error($"大件库库存为整箱!盘点数量不能存在散件");
                }
                #endregion
                //if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty)
                //    return WebResponseContent.Instance.Error($"实盘数量不可超出账面数量");
                #region å¤„理出库单,货位,库存,库存批次信息
                _unitOfWorkManage.BeginTran();
                #region å‡ºåº“单
                #region ä¿®æ”¹ç›˜ç‚¹å•
                cabinOrder.OutStatus = "开始";
                cabinOrderDetail.OotDetailStatus = "开始";
                if (cabinOrderDetail.Order_Outqty == cabinOrderDetail.Order_qty)
                {
                    cabinOrderDetail.OotDetailStatus = "已完成";
                    _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrderDetail, OperateTypeEnum.自动完成);
                }
                else
                {
                    _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail);
                }
                var cabinOrder1 = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == cabinOrder.Out_no && x.Out_type == "3").Includes(x => x.Details).First();
                if (cabinOrder1.Details == null || cabinOrder1.Details.Count < 1) cabinOrder.OutStatus = "已完成";
                if (cabinOrder.OutStatus == "已完成")
                    Repository.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.自动完成);
                else
                    Repository.UpdateData(cabinOrder);
                Repository.UpdateData(cabinOrder);
                _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail);
                #endregion
                #region åº“å­˜
                Dt_InventoryInfo inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.LocationCode == LocationCode);
                if (inventoryInfo == null) return WebResponseContent.Instance.Error($"未找到货位【{LocationCode}】的库存信息");
                inventoryInfo.StockQuantity = supplyTask.SupplyQuantity;
                Dt_InventoryInfo inventoryInfo = new Dt_InventoryInfo();
                if (supplyTask.WarehouseCode != WarehouseEnum.立库.ObjToInt().ToString("000"))
                {
                    inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.WarehouseCode == supplyTask.WarehouseCode && x.LocationCode == supplyTask.LocationCode);
                    if (inventoryInfo == null) return WebResponseContent.Instance.Error($"未找到货位【{LocationCode}】的库存信息");
                }
                else
                {
                    inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.WarehouseCode == supplyTask.WarehouseCode);
                }
                inventoryInfo.SupplyQuantity = supplyTask.SupplyQuantity;
                _inventoryInfoService.UpdateData(inventoryInfo);
                #endregion
                #region ä»»åŠ¡è®°å½•
                _supplyTaskService.UpdateData(supplyTask);
                //_supplyTaskService.UpdateData(supplyTask);
                _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.自动完成);
                #endregion
                #region åº“存批次
                Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode);
                if (inventory_Batch != null)
                #region åˆ¤æ–­å½“前物料批次的盘点任务是否全部完成
                List<Dt_SupplyTask> supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.WarehouseCode == supplyTask.WarehouseCode).ToList();
                if (supplyTasks.Count < 1)
                {
                    inventory_Batch.SupplyQuantity += supplyTask.SupplyQuantity;
                    _inventory_BatchServices.UpdateData(inventory_Batch);
                    #region å®Œæˆç›˜ç‚¹å•
                    cabinOrder.OutStatus = "已完成";
                    cabinOrder.Details.ForEach(x =>
                    {
                        x.OotDetailStatus = "已完成";
                    });
                    _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrder.Details, OperateTypeEnum.自动完成);
                    cabinOrder.Details = null;
                    Repository.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.自动完成);
                    #endregion
                }
                #endregion
                supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
                if (supplyTasks.Count < 1)
                {
                    #region æŸ¥æ‰¾åº“å­˜
                    var inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
                    var SupplyQuantitys = inventoryInfos.Select(x => x.SupplyQuantity).ToList().Sum();
                    #endregion
                    #region åº“存批次
                    Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
                    if (SupplyQuantitys == inventory_Batch.StockQuantity)
                    {
                        foreach (var item in inventoryInfos)
                        {
                            item.StockQuantity = item.SupplyQuantity;
                            item.SupplyQuantity = 0;
                            item.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                        }
                        _inventoryInfoService.UpdateData(inventoryInfos);
                    }
                    else
                    {
                        inventory_Batch.SupplyQuantity = SupplyQuantitys;
                        _inventory_BatchServices.UpdateData(inventory_Batch);
                    }
                    #endregion
                }
                _unitOfWorkManage.CommitTran();
                #endregion
                content.OK();
                #endregion
            }
            catch (Exception ex)
            {