yanjinhui
2025-11-19 02e4718a9a3f03e2385d4e26ffbedf1ceb89908e
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs
@@ -9,8 +9,10 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using WIDESEA_Common;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.MaterielEnum;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
@@ -133,7 +135,7 @@
                if (cabinOrder == null || cabinOrder.OdrderStatus == "已完成")
                    return WebResponseContent.Instance.Error($"入库单已完成");
                //Dt_CabinOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Goods_no == materielCode && x.Batch_num == batchNo && x.Status == 2).FirstOrDefault();
                Dt_CabinOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Id == id).FirstOrDefault();
                Dt_CabinOrderDetail? cabinOrderDetail = cabinOrder.Details.Where(x => x.Id == id).FirstOrDefault();
                if (cabinOrderDetail == null || cabinOrderDetail.OrderDetailStatus == "已完成")
                    return WebResponseContent.Instance.Error($"入库单明细已完成");
                Dt_MaterielInfo materielInfo = _materielInfoService.Repository.QueryFirst(x => x.MaterielCode == cabinOrderDetail.Goods_no);
@@ -141,6 +143,15 @@
                cabinOrderDetail.Order_Inqty += Inqty;
                if (cabinOrderDetail.Order_Inqty > cabinOrderDetail.Order_qty)
                    return WebResponseContent.Instance.Error($"入库数量不可超出单据数量");
                //大件库整箱校验
                if (warehouseCode == WarehouseEnum.大件库.ObjToInt().ToString("000")&& (materielInfo.MaterielSourceType==MaterielSourceTypeEnum.SelfMadePart))
                {
                    var BoxRule = materielInfo.BoxQty;
                    if (BoxRule > 0 && Inqty % BoxRule != 0)
                    {
                        return WebResponseContent.Instance.Error($"大件库只允许存放整箱货物!当前入库数量 {Convert.ToInt32(Inqty)} ä¸æ˜¯ç®±è§„ {Convert.ToInt32(BoxRule)} çš„æ•´æ•°å€");
                    }
                }
                #region å¤„理入库单,货位,库存,库存批次信息
                _unitOfWorkManage.BeginTran();
@@ -161,8 +172,9 @@
                #region è´§ä½
                var location = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode);
                if (location == null) return WebResponseContent.Instance.Error($"请维护货位编号【{LocationCode}】的货位信息");
                if (location.EnableStatus == EnableStatusEnum.Disable.ObjToInt())
                    return WebResponseContent.Instance.Error($"货位编号【{LocationCode}】已禁用,请恢复正常再使用");
                //if (location.EnableStatus == EnableStatusEnum.Disable.ObjToInt())
                //    return WebResponseContent.Instance.Error($"货位编号【{LocationCode}】已禁用,请恢复正常再使用");
                if (location.WarehouseCode != cabinOrderDetail.Reservoirarea)
                    return WebResponseContent.Instance.Error($"货位编号【{LocationCode}】所属库房与当前入库单所属库房不匹配");
                if (location.LocationStatus == LocationStatusEnum.Free.ObjToInt())
@@ -320,6 +332,16 @@
            {
                string WareCodeMJ = WarehouseEnum.麻精库.ObjToInt().ToString("000");
                string WareCodeLD = WarehouseEnum.冷冻库.ObjToInt().ToString("000");
                #region æ£€æŸ¥æ˜¯å¦æœ‰æœªå®Œæˆçš„盘点任务
                var dt_bath = _inventory_BatchServices.Repository.QueryData(x => order.details.Select(d => d.goods_no).Contains(x.MaterielCode)).ToList();
                if (dt_bath.Count>=1)
                {
                    foreach (var item in dt_bath)
                    {
                        if (item.SupplyQuantity > 0) throw new Exception($"入库单【{order.order_no}】物料编号【{dt_bath[0].MaterielCode}】存在未完成的盘盈入库任务,请处理完成后再进行正常入库操作");
                    }
                }
                #endregion
                List<Dt_CabinOrder> dt_CabinOrders = new List<Dt_CabinOrder>();
                #region ç‰¹æ®Šè¯å“å…¥ç‰¹æ®Šåº“房
                if (order.warehouse_no == WareCodeMJ || order.warehouse_no == WareCodeLD)
@@ -376,7 +398,7 @@
                    };
                    #endregion
                    List<Dt_MaterielInfo> materielInfos = _materielInfoService.Repository.QueryData(x => order.details.Select(x => x.goods_no).Contains(x.MaterielCode));
                    List<Dt_MaterielInfo> materielInfos = _materielInfoService.Repository.QueryData(x => order.details.Select(x => x.goods_no).Contains(x.MaterielCode)).ToList();
                    List<Dt_MaterielInfo> materielInfosUp = new List<Dt_MaterielInfo>();
                    foreach (var item in order.details)
                    {
@@ -476,18 +498,25 @@
                        }
                        //_materielInfoService.UpdateData(materielInfo);
                    }
                    _unitOfWorkManage.BeginTran();
                    if (materielInfosUp.Count > 0) _materielInfoService.UpdateData(materielInfosUp);
                    if (entityOrder.Details.Count > 0) dt_CabinOrders.Add(entityOrder);
                    if (entityOrderLK.Details.Count > 0) dt_CabinOrders.Add(entityOrderLK);
                    if (dt_CabinOrders.Count > 0) BaseDal.Db.InsertNav(dt_CabinOrders).Include(x => x.Details).ExecuteCommand();
                    _unitOfWorkManage.CommitTran();
                    try
                    {
                        _unitOfWorkManage.BeginTran();
                        if (materielInfosUp.Count > 0) _materielInfoService.UpdateData(materielInfosUp);
                        if (entityOrder.Details.Count > 0) dt_CabinOrders.Add(entityOrder);
                        if (entityOrderLK.Details.Count > 0) dt_CabinOrders.Add(entityOrderLK);
                        if (dt_CabinOrders.Count > 0) BaseDal.Db.InsertNav(dt_CabinOrders).Include(x => x.Details).ExecuteCommand();
                        _unitOfWorkManage.CommitTran();
                    }
                    catch (Exception)
                    {
                        _unitOfWorkManage.RollbackTran();
                    }
                    //webResponseContent.OK(data: dt_CabinOrders);
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                _messageInfoService.AddMessageInfo(MessageGroupByEnum.InOrderAlarm, (order.order_type == "2" ? "出库退货" : "正常入库") + $":单号【{order.order_no}】", ex.Message);
                webResponseContent.Error(ex.Message);
            }
            return webResponseContent;
@@ -495,6 +524,338 @@
        #endregion
        #region åˆ›å»ºç›˜ç›ˆå…¥åº“单
        //public WebResponseContent CreateCheckInOrder(UpstreamOrderInfo order)
        //{
        //    WebResponseContent content = new WebResponseContent();
        //    try
        //    {
        //        string WareCodeMJ = WarehouseEnum.麻精库.ObjToInt().ToString("000");
        //        string WareCodeLD = WarehouseEnum.冷冻库.ObjToInt().ToString("000");
        //        List<Dt_SupplyTask_Hty> supplyTask_Hties = new List<Dt_SupplyTask_Hty>();
        //        List<Dt_Inventory_Batch> batchesUp = new List<Dt_Inventory_Batch>();
        //        List<Dt_InventoryInfo> infosUp = new List<Dt_InventoryInfo>();
        //        var codes = order.details.Select(x => x.goods_no).ToList();
        //        #region ç‰¹æ®Šåº“房
        //        if (order.warehouse_no == WareCodeMJ || order.warehouse_no == WareCodeLD)
        //        {
        //            List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => codes.Contains(x.MaterielCode));
        //            List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoService.Repository.QueryData(x => codes.Contains(x.MaterielCode));
        //            #region åº“存、库存批次平账
        //            foreach (var item in order.details)
        //            {
        //                //找库存批次信息
        //                Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).First();
        //                if (inventory_Batch.SupplyQuantity != item.order_qty)
        //                {
        //                    _messageInfoService.AddMessageInfo(MessageGroupByEnum.InOrderAlarm, "ERP报报溢入库错误", $"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
        //                    throw new Exception($"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
        //                }
        //                //找所有库存
        //                List<Dt_InventoryInfo> inventoryInfos = _InventoryInfos.Where(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo).ToList();
        //                foreach (var inventoryInfo in inventoryInfos)
        //                {
        //                    #region æ·»åŠ ç›˜ç›ˆå…¥åº“ä»»åŠ¡
        //                    if (inventoryInfo.SupplyQuantity != 0)
        //                    {
        //                        Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
        //                        {
        //                            WarehouseCode = inventoryInfo.WarehouseCode,
        //                            OperateType = OperateTypeEnum.自动完成.ToString(),
        //                            InsertTime = DateTime.Now,
        //                            TaskStatus = SupplyStatusEnum.InFinish.ObjToInt(),
        //                            BatchNo = inventoryInfo.BatchNo,
        //                            MaterielName = inventoryInfo.MaterielName,
        //                            MaterielCode = inventoryInfo.MaterielCode,
        //                            MaterielSpec = inventoryInfo.MaterielSpec,
        //                            TaskType = TaskTypeEnum.ChenckIn.ObjToInt(),
        //                            CreateDate = DateTime.Now,
        //                            Creater = App.User.UserName,
        //                            LocationCode = inventoryInfo.LocationCode,
        //                            OrderNo = order.order_no,
        //                            StockQuantity = inventoryInfo.SupplyQuantity,
        //                            SupplyQuantity = 0,
        //                            Remark = "盘盈入库"
        //                        };
        //                        //_supplyTaskHtyService.AddData(supplyTask_Hty);
        //                        supplyTask_Hties.Add(supplyTask_Hty);
        //                    }
        //                    #endregion
        //                    inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
        //                    inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
        //                    inventoryInfo.SupplyQuantity = 0;
        //                    inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
        //                }
        //                infosUp.AddRange(inventoryInfos);
        //                inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
        //                inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
        //                inventory_Batch.SupplyQuantity = 0;
        //                batchesUp.Add(inventory_Batch);
        //                //_inventoryInfoService.UpdateData(inventoryInfos);
        //                //_inventory_BatchServices.UpdateData(inventory_Batch);
        //            }
        //            #endregion
        //            #region åˆ›å»ºç›˜ç‚¹å•
        //            var entityOrder = new Dt_CabinOrder
        //            {
        //                Order_no = order.order_no,
        //                Order_type = order.order_type,
        //                Supplier_no = order.supplier_no,
        //                Account_tiem = order.account_time,
        //                OdrderStatus = "已完成",
        //                Supplier_name = order.supplier_name,
        //                Warehouse_no = order.warehouse_no,
        //                Details = order.details.Select(d => new Dt_CabinOrderDetail
        //                {
        //                    Goods_no = d.goods_no,
        //                    Order_qty = Math.Abs(d.order_qty),
        //                    Order_Inqty = Math.Abs(d.order_qty),
        //                    Batch_num = d.batch_num,
        //                    Exp_date = d.exp_date,
        //                    Reservoirarea = order.warehouse_no,
        //                    OrderDetailStatus = "已完成",
        //                    Status = 2,
        //                }).ToList()
        //            };
        //            _unitOfWorkManage.BeginTran();
        //            if (supplyTask_Hties.Count > 0) _supplyTaskHtyService.AddData(supplyTask_Hties);
        //            if (infosUp.Count > 0) _inventoryInfoService.UpdateData(infosUp);
        //            if (batchesUp.Count > 0) _inventory_BatchServices.UpdateData(batchesUp);
        //            BaseDal.Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
        //            _unitOfWorkManage.CommitTran();
        //            //Repository.AddData(entityOrder);
        //            #endregion
        //        }
        //        #endregion
        //        else
        //        {
        //            List<Dt_CabinOrder> cabinOrdersAdd = new List<Dt_CabinOrder>();
        //            string WareCodeLK = WarehouseEnum.立库.ObjToInt().ToString("000");
        //            string WareCodeDJ = WarehouseEnum.大件库.ObjToInt().ToString("000");
        //            List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => codes.Contains(x.MaterielCode)).ToList();
        //            List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoService.Repository.QueryData(x => codes.Contains(x.MaterielCode)).ToList();
        //            foreach (var item in order.details)
        //            {
        //                //找库存批次信息
        //                Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).First();
        //                var Qty = Math.Abs(inventory_Batch.SupplyQuantity);
        //                if (Qty != item.order_qty)
        //                {
        //                    _messageInfoService.AddMessageInfo(MessageGroupByEnum.InOrderAlarm, "ERP报报溢入库错误", $"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
        //                    throw new Exception($"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
        //                }
        //                //找所有库存
        //                List<Dt_InventoryInfo> inventoryInfos = _InventoryInfos.Where(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo).ToList();
        //                //获取立库盘点差异数
        //                var inventoryLK = inventoryInfos.Where(x => x.WarehouseCode == WareCodeLK).FirstOrDefault(); //修改这里有可能只有大件库才会存在差异
        //                //var LkQty = Math.Abs(inventoryLK.SupplyQuantity);
        //                var LkQty = inventoryLK?.SupplyQuantity ?? 0;
        //                //获取大件库盘点差异数
        //                var inventoryDJ = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
        //                //var DJQty = Math.Abs(inventoryDJ.Sum(x => x.SupplyQuantity));
        //                var DJQty = inventoryDJ.Sum(x => x.SupplyQuantity);
        //                if (LkQty + DJQty != Qty)
        //                {
        //                    _messageInfoService.AddMessageInfo(MessageGroupByEnum.InOrderAlarm, "ERP报报溢入库错误", $"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
        //                    throw new Exception($"【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的物料信息与物料批次信息盘盈数量不符");
        //                }
        //                if (LkQty == 0)//立库无差异
        //                {
        //                    #region åº“存、库存批次平账
        //                    foreach (var inventoryInfo in inventoryInfos)
        //                    {
        //                        #region æ·»åŠ ç›˜ç›ˆå…¥åº“ä»»åŠ¡
        //                        if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity)
        //                        {
        //                            Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
        //                            {
        //                                WarehouseCode = inventoryInfo.WarehouseCode,
        //                                OperateType = OperateTypeEnum.自动完成.ToString(),
        //                                InsertTime = DateTime.Now,
        //                                TaskStatus = SupplyStatusEnum.InFinish.ObjToInt(),
        //                                BatchNo = inventoryInfo.BatchNo,
        //                                MaterielName = inventoryInfo.MaterielName,
        //                                MaterielCode = inventoryInfo.MaterielCode,
        //                                MaterielSpec = inventoryInfo.MaterielSpec,
        //                                TaskType = TaskTypeEnum.ChenckIn.ObjToInt(),
        //                                CreateDate = DateTime.Now,
        //                                Creater = App.User.UserName,
        //                                LocationCode = inventoryInfo.LocationCode,
        //                                OrderNo = order.order_no,
        //                                StockQuantity = Math.Abs(inventoryInfo.SupplyQuantity),
        //                                SupplyQuantity = 0,
        //                                Remark = "盘盈入库"
        //                            };
        //                            //_supplyTaskHtyService.AddData(supplyTask_Hty);
        //                            supplyTask_Hties.Add(supplyTask_Hty);
        //                        }
        //                        #endregion
        //                        inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
        //                        inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
        //                        inventoryInfo.SupplyQuantity = 0;
        //                        inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
        //                    }
        //                    //_inventoryInfoService.UpdateData(inventoryInfos);
        //                    infosUp.AddRange(inventoryInfos);
        //                    inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
        //                    inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
        //                    inventory_Batch.SupplyQuantity = 0;
        //                    //_inventory_BatchServices.UpdateData(inventory_Batch);
        //                    batchesUp.Add(inventory_Batch);
        //                    #endregion
        //                    #region åˆ›å»ºå¤§ä»¶åº“盘点单
        //                    var entityOrder = new Dt_CabinOrder
        //                    {
        //                        Order_no = order.order_no,
        //                        Order_type = order.order_type,
        //                        Supplier_no = order.supplier_no,
        //                        Account_tiem = order.account_time,
        //                        OdrderStatus = "已完成",
        //                        Supplier_name = order.supplier_name,
        //                        Warehouse_no = WareCodeDJ,
        //                        Details = order.details.Select(d => new Dt_CabinOrderDetail
        //                        {
        //                            Goods_no = d.goods_no,
        //                            Order_qty = Math.Abs(d.order_qty),
        //                            Order_Inqty = Math.Abs(d.order_qty),
        //                            Batch_num = d.batch_num,
        //                            Exp_date = d.exp_date,
        //                            Reservoirarea = WareCodeDJ,
        //                            OrderDetailStatus = "已完成",
        //                            Status = 2,
        //                        }).ToList()
        //                    };
        //                    //Repository.AddData(entityOrder);
        //                    //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
        //                    cabinOrdersAdd.Add(entityOrder);
        //                    #endregion
        //                }
        //                else // LkQty != 0 è¡¨ç¤ºç«‹åº“有差异
        //                {
        //                    #region å¤§ä»¶åº“库存平账
        //                    inventoryInfos = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
        //                    foreach (var inventoryInfo in inventoryInfos)
        //                    {
        //                        #region æ·»åŠ ç›˜ç›ˆå…¥åº“ä»»åŠ¡
        //                        if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity)
        //                        {
        //                            Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
        //                            {
        //                                WarehouseCode = inventoryInfo.WarehouseCode,
        //                                OperateType = OperateTypeEnum.自动完成.ToString(),
        //                                InsertTime = DateTime.Now,
        //                                TaskStatus = SupplyStatusEnum.InFinish.ObjToInt(),
        //                                BatchNo = inventoryInfo.BatchNo,
        //                                MaterielName = inventoryInfo.MaterielName,
        //                                MaterielCode = inventoryInfo.MaterielCode,
        //                                MaterielSpec = inventoryInfo.MaterielSpec,
        //                                TaskType = TaskTypeEnum.ChenckIn.ObjToInt(),
        //                                CreateDate = DateTime.Now,
        //                                Creater = App.User.UserName,
        //                                LocationCode = inventoryInfo.LocationCode,
        //                                OrderNo = order.order_no,
        //                                StockQuantity = Math.Abs(inventoryInfo.SupplyQuantity),
        //                                SupplyQuantity = 0,
        //                                Remark = "盘盈入库"
        //                            };
        //                            //_supplyTaskHtyService.AddData(supplyTask_Hty);
        //                            supplyTask_Hties.Add(supplyTask_Hty);
        //                        }
        //                        #endregion
        //                        inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
        //                        inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
        //                        inventoryInfo.SupplyQuantity = 0;
        //                        inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
        //                    }
        //                    //_inventoryInfoService.UpdateData(inventoryInfos);
        //                    infosUp.AddRange(inventoryInfos);
        //                    #endregion
        //                    #region åˆ›å»ºå¤§ä»¶åº“盘点单
        //                    if (DJQty != 0)
        //                    {
        //                        var cabinOrder = new Dt_CabinOrder
        //                        {
        //                            Order_no = order.order_no,
        //                            Order_type = order.order_type,
        //                            Supplier_no = order.supplier_no,
        //                            Account_tiem = order.account_time,
        //                            OdrderStatus = "已完成",
        //                            Supplier_name = order.supplier_name,
        //                            Warehouse_no = WareCodeDJ,
        //                            Details = order.details.Select(d => new Dt_CabinOrderDetail
        //                            {
        //                                Goods_no = d.goods_no,
        //                                Order_qty = DJQty,
        //                                Order_Inqty = DJQty,
        //                                Batch_num = d.batch_num,
        //                                Exp_date = d.exp_date,
        //                                Reservoirarea = WareCodeDJ,
        //                                OrderDetailStatus = "已完成",
        //                                Status = 2,
        //                            }).ToList()
        //                        };
        //                        //Repository.AddData(cabinOrder);
        //                        //Db.InsertNav(cabinOrder).Include(it => it.Details).ExecuteCommand();
        //                        cabinOrdersAdd.Add(cabinOrder);
        //                    }
        //                    #endregion
        //                    #region åˆ›å»ºç«‹åº“盘点单
        //                    var entityOrder = new Dt_CabinOrder
        //                    {
        //                        Order_no = order.order_no,
        //                        Order_type = order.order_type,
        //                        Supplier_no = order.supplier_no,
        //                        Account_tiem = order.account_time,
        //                        OdrderStatus = "新建",
        //                        Supplier_name = order.supplier_name,
        //                        Warehouse_no = WareCodeLK,
        //                        Details = order.details.Select(d => new Dt_CabinOrderDetail
        //                        {
        //                            Goods_no = d.goods_no,
        //                            Order_qty = Math.Abs(LkQty),
        //                            Batch_num = d.batch_num,
        //                            Exp_date = d.exp_date,
        //                            Reservoirarea = WareCodeLK,
        //                            OrderDetailStatus = "新建",
        //                            Status = 0,
        //                        }).ToList()
        //                    };
        //                    //Repository.AddData(entityOrder);
        //                    //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
        //                    cabinOrdersAdd.Add(entityOrder);
        //                    #endregion
        //                }
        //            }
        //            _unitOfWorkManage.BeginTran();
        //            if (supplyTask_Hties.Count > 1) _supplyTaskHtyService.AddData(supplyTask_Hties);
        //            if (infosUp.Count > 0) _inventoryInfoService.UpdateData(infosUp);
        //            if (batchesUp.Count > 0) _inventory_BatchServices.UpdateData(batchesUp);
        //            if (cabinOrdersAdd.Count > 0) BaseDal.Db.InsertNav(cabinOrdersAdd).Include(it => it.Details).ExecuteCommand();
        //            _unitOfWorkManage.CommitTran();
        //            // æ·»åŠ äº‹åŠ¡æäº¤åŽçš„æ£€æŸ¥
        //            Console.WriteLine($"事务提交完成,准备返回。cabinOrdersAdd数量: {cabinOrdersAdd.Count}");
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        _unitOfWorkManage.RollbackTran();
        //        //_messageInfoService.AddMessageInfo(MessageGroupByEnum.InOrderAlarm, "创建盘盈入库单", ex.Message);
        //        //return content.Error(ex.Message);
        //        throw ex;
        //    }
        //    //return content;
        //    return content.OK($"盘盈入库单 {order.order_no} åˆ›å»ºæˆåŠŸ");
        //}
        #endregion
        #region åˆ›å»ºç›˜ç›ˆå…¥åº“单(修改原版因为前面订单创建失败导致后面也创建不了问题)
        public WebResponseContent CreateCheckInOrder(UpstreamOrderInfo order)
        {
            WebResponseContent content = new WebResponseContent();
@@ -517,14 +878,17 @@
                    {
                        //找库存批次信息
                        Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).First();
                        var Qty = Math.Abs(inventory_Batch.StockQuantity - inventory_Batch.SupplyQuantity);
                        if (Qty != item.order_qty) throw new Exception($"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
                        if (inventory_Batch.SupplyQuantity != item.order_qty)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.InOrderAlarm, "ERP报报溢入库错误", $"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
                            throw new Exception($"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
                        }
                        //找所有库存
                        List<Dt_InventoryInfo> inventoryInfos = _InventoryInfos.Where(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo).ToList();
                        foreach (var inventoryInfo in inventoryInfos)
                        {
                            #region æ·»åŠ ç›˜ç›ˆå…¥åº“ä»»åŠ¡
                            if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity)
                            if (inventoryInfo.SupplyQuantity != 0)
                            {
                                Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
                                {
@@ -541,7 +905,7 @@
                                    Creater = App.User.UserName,
                                    LocationCode = inventoryInfo.LocationCode,
                                    OrderNo = order.order_no,
                                    StockQuantity = Math.Abs(inventoryInfo.StockQuantity - inventoryInfo.SupplyQuantity),
                                    StockQuantity = inventoryInfo.SupplyQuantity,
                                    SupplyQuantity = 0,
                                    Remark = "盘盈入库"
                                };
@@ -549,19 +913,20 @@
                                supplyTask_Hties.Add(supplyTask_Hty);
                            }
                            #endregion
                            inventoryInfo.StockQuantity = inventoryInfo.SupplyQuantity;
                            inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
                            inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
                            inventoryInfo.SupplyQuantity = 0;
                            inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                        }
                        infosUp.AddRange(inventoryInfos);
                        inventory_Batch.StockQuantity = inventory_Batch.SupplyQuantity;
                        inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
                        inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
                        inventory_Batch.SupplyQuantity = 0;
                        batchesUp.Add(inventory_Batch);
                        //_inventoryInfoService.UpdateData(inventoryInfos);
                        //_inventory_BatchServices.UpdateData(inventory_Batch);
                    }
                    #endregion
                    #region åˆ›å»ºç›˜ç‚¹å•
                    var entityOrder = new Dt_CabinOrder
                    {
@@ -584,13 +949,14 @@
                            Status = 2,
                        }).ToList()
                    };
                    _unitOfWorkManage.BeginTran();
                    _supplyTaskHtyService.AddData(supplyTask_Hties);
                    _inventoryInfoService.UpdateData(infosUp);
                    _inventory_BatchServices.UpdateData(batchesUp);
                    BaseDal.Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
                    _unitOfWorkManage.CommitTran();
                    //Repository.AddData(entityOrder);
                    using (var scop = new TransactionScope(TransactionScopeOption.RequiresNew))
                    {
                        if (supplyTask_Hties.Count > 0) _supplyTaskHtyService.AddData(supplyTask_Hties);
                        if (infosUp.Count > 0) _inventoryInfoService.UpdateData(infosUp);
                        if (batchesUp.Count > 0) _inventory_BatchServices.UpdateData(batchesUp);
                        BaseDal.Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
                        scop.Complete();
                    }
                    #endregion
                }
                #endregion
@@ -599,23 +965,36 @@
                    List<Dt_CabinOrder> cabinOrdersAdd = new List<Dt_CabinOrder>();
                    string WareCodeLK = WarehouseEnum.立库.ObjToInt().ToString("000");
                    string WareCodeDJ = WarehouseEnum.大件库.ObjToInt().ToString("000");
                    List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => codes.Contains(x.MaterielCode));
                    List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoService.Repository.QueryData(x => codes.Contains(x.MaterielCode));
                    List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => codes.Contains(x.MaterielCode)).ToList();
                    List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoService.Repository.QueryData(x => codes.Contains(x.MaterielCode)).ToList();
                    foreach (var item in order.details)
                    {
                        //找库存批次信息
                        Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).First();
                        var Qty = Math.Abs(inventory_Batch.StockQuantity - inventory_Batch.SupplyQuantity);
                        if (Qty != item.order_qty) throw new Exception($"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
                        var Qty = Math.Abs(inventory_Batch.SupplyQuantity);
                        if (Qty != item.order_qty)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.InOrderAlarm, "ERP报报溢入库错误", $"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
                            throw new Exception($"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
                        }
                        //找所有库存
                        List<Dt_InventoryInfo> inventoryInfos = _InventoryInfos.Where(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo).ToList();
                        //获取立库盘点差异数
                        var inventoryLK = inventoryInfos.Where(x => x.WarehouseCode == WareCodeLK).First();
                        var LkQty = Math.Abs(inventoryLK.StockQuantity - inventoryLK.SupplyQuantity);
                        var inventoryLK = inventoryInfos.Where(x => x.WarehouseCode == WareCodeLK).FirstOrDefault(); //修改这里有可能只有大件库才会存在差异
                        //var LkQty = Math.Abs(inventoryLK.SupplyQuantity);
                        var LkQty = inventoryLK?.SupplyQuantity ?? 0;
                        //获取大件库盘点差异数
                        var inventoryDJ = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
                        var DJQty = Math.Abs(inventoryDJ.Sum(x => x.StockQuantity) - inventoryDJ.Sum(x => x.SupplyQuantity));
                        if (LkQty + DJQty != Qty) throw new Exception($"【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的物料信息与物料批次信息盘盈数量不符");
                        //var DJQty = Math.Abs(inventoryDJ.Sum(x => x.SupplyQuantity));
                        var DJQty = inventoryDJ.Sum(x => x.SupplyQuantity);
                        if (LkQty + DJQty != Qty)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.InOrderAlarm, "ERP报报溢入库错误", $"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
                            throw new Exception($"【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的物料信息与物料批次信息盘盈数量不符");
                        }
                        if (LkQty == 0)//立库无差异
                        {
                            #region åº“存、库存批次平账
@@ -639,7 +1018,7 @@
                                        Creater = App.User.UserName,
                                        LocationCode = inventoryInfo.LocationCode,
                                        OrderNo = order.order_no,
                                        StockQuantity = Math.Abs(inventoryInfo.StockQuantity - inventoryInfo.SupplyQuantity),
                                        StockQuantity = Math.Abs(inventoryInfo.SupplyQuantity),
                                        SupplyQuantity = 0,
                                        Remark = "盘盈入库"
                                    };
@@ -647,13 +1026,15 @@
                                    supplyTask_Hties.Add(supplyTask_Hty);
                                }
                                #endregion
                                inventoryInfo.StockQuantity = inventoryInfo.SupplyQuantity;
                                inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
                                inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
                                inventoryInfo.SupplyQuantity = 0;
                                inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                            }
                            //_inventoryInfoService.UpdateData(inventoryInfos);
                            infosUp.AddRange(inventoryInfos);
                            inventory_Batch.StockQuantity = inventory_Batch.SupplyQuantity;
                            inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
                            inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
                            inventory_Batch.SupplyQuantity = 0;
                            //_inventory_BatchServices.UpdateData(inventory_Batch);
                            batchesUp.Add(inventory_Batch);
@@ -686,7 +1067,7 @@
                            cabinOrdersAdd.Add(entityOrder);
                            #endregion
                        }
                        else
                        else // LkQty != 0 è¡¨ç¤ºç«‹åº“有差异
                        {
                            #region å¤§ä»¶åº“库存平账
                            inventoryInfos = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
@@ -710,7 +1091,7 @@
                                        Creater = App.User.UserName,
                                        LocationCode = inventoryInfo.LocationCode,
                                        OrderNo = order.order_no,
                                        StockQuantity = Math.Abs(inventoryInfo.StockQuantity - inventoryInfo.SupplyQuantity),
                                        StockQuantity = Math.Abs(inventoryInfo.SupplyQuantity),
                                        SupplyQuantity = 0,
                                        Remark = "盘盈入库"
                                    };
@@ -718,7 +1099,8 @@
                                    supplyTask_Hties.Add(supplyTask_Hty);
                                }
                                #endregion
                                inventoryInfo.StockQuantity = inventoryInfo.SupplyQuantity;
                                inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
                                inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
                                inventoryInfo.SupplyQuantity = 0;
                                inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                            }
@@ -769,7 +1151,7 @@
                                Details = order.details.Select(d => new Dt_CabinOrderDetail
                                {
                                    Goods_no = d.goods_no,
                                    Order_qty = LkQty,
                                    Order_qty = Math.Abs(LkQty),
                                    Batch_num = d.batch_num,
                                    Exp_date = d.exp_date,
                                    Reservoirarea = WareCodeLK,
@@ -783,23 +1165,26 @@
                            #endregion
                        }
                    }
                    _unitOfWorkManage.BeginTran();
                    _supplyTaskHtyService.AddData(supplyTask_Hties);
                    _inventoryInfoService.UpdateData(infosUp);
                    _inventory_BatchServices.UpdateData(batchesUp);
                    BaseDal.Db.InsertNav(cabinOrdersAdd).Include(it => it.Details).ExecuteCommand();
                    _unitOfWorkManage.CommitTran();
                    using (var scop = new TransactionScope(TransactionScopeOption.RequiresNew))
                    {
                        if (supplyTask_Hties.Count > 0) _supplyTaskHtyService.AddData(supplyTask_Hties);
                        if (infosUp.Count > 0) _inventoryInfoService.UpdateData(infosUp);
                        if (batchesUp.Count > 0) _inventory_BatchServices.UpdateData(batchesUp);
                        if (cabinOrdersAdd.Count > 0) BaseDal.Db.InsertNav(cabinOrdersAdd).Include(it => it.Details).ExecuteCommand();
                        scop.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                //_messageInfoService.AddMessageInfo(MessageGroupByEnum.InOrderAlarm, "创建盘盈入库单", ex.Message);
                content.Error(ex.Message);
                //throw ex;
                return content.Error(ex.Message);
            }
            return content;
            //return content;
            return content.OK($"盘盈入库单创建成功");
        }
        #endregion
        /// <summary>
@@ -818,7 +1203,8 @@
                List<Dt_CabinOrderDetail> cabinOrderDetails = new List<Dt_CabinOrderDetail>();
                foreach (var item in cabinOrders)
                {
                    if (item.Details != null) cabinOrderDetails.AddRange(cabinOrderDetails);
                    if (item.Details != null) cabinOrderDetails.AddRange(item.Details);
                    item.Modifier = App.User.UserName;
                    item.ModifyDate = DateTime.Now;
                    item.Details = null;
@@ -831,6 +1217,7 @@
                else
                {
                    var url = "http://121.37.118.63:80/GYZ2/95fck/outOrderOk";
                    if (cabinOrder.Order_type == "2") url = "http://121.37.118.63:80/GYZ2/95fck/outOrderOk";
                    var requestDate = new
                    {
                        order_no = cabinOrder.Order_no
@@ -838,7 +1225,7 @@
                    var result = HttpHelper.Post(url, requestDate.ToJsonString());
                    var response = JsonConvert.DeserializeObject<UpstreamOrderResponse>(result);
                    if (response == null) throw new Exception("上报ERP入库单完成失败!");
                    if (response.resultCode != "0") throw new Exception(response.resultMsg);
                    if (response.resultCode != "0" && response.resultMsg != "未找到合法单据") throw new Exception(response.resultMsg);
                    _cabinOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrderDetails, OperateTypeEnum.人工完成);
                    BaseDal.DeleteAndMoveIntoHty(cabinOrders, OperateTypeEnum.人工完成);