yanjinhui
2025-12-01 2b49f7643d15b74889d190f216630559006ed93a
н¨Îļþ¼Ð/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;
@@ -102,15 +104,72 @@
        /// <param name="pageNo"></param>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        //public WebResponseContent GetCabinOrderDetail(int pageNo, string orderNo)
        //{
        //    WebResponseContent content = new WebResponseContent();
        //    Dt_CabinOrder cabinOrder = Db.Queryable<Dt_CabinOrder>().Includes(x => x.Details).First(x => x.Order_no == orderNo);
        //    List<Dt_CabinOrderDetail> cabinOrderDetails = cabinOrder.Details.Where(x => x.Status == 2 && x.OrderDetailStatus != "已完成").ToList();
        //    content.OK(data: cabinOrderDetails);
        //    return content;
        //}
        public WebResponseContent GetCabinOrderDetail(int pageNo, string orderNo)
        {
            WebResponseContent content = new WebResponseContent();
            Dt_CabinOrder cabinOrder = Db.Queryable<Dt_CabinOrder>().Includes(x => x.Details).First(x => x.Order_no == orderNo);
            List<Dt_CabinOrderDetail> cabinOrderDetails = cabinOrder.Details.Where(x => x.Status == 2 && x.OrderDetailStatus != "已完成").ToList();
            content.OK(data: cabinOrderDetails);
            try
            {
                Dt_CabinOrder cabinOrder = Db.Queryable<Dt_CabinOrder>().Includes(x => x.Details).First(x => x.Order_no == orderNo);
                List<Dt_CabinOrderDetail> cabinOrderDetails = cabinOrder.Details.Where(x => x.Status == 2 && x.OrderDetailStatus != "已完成").ToList();
                // èŽ·å–æ‰€æœ‰ç‰©æ–™ç¼–å·
                var materielCodes = cabinOrderDetails.Select(x => x.Goods_no).Distinct().ToList();
                // èŽ·å–ç‰©æ–™ä¿¡æ¯
                var materiels = Db.Queryable<Dt_MaterielInfo>()
                    .Where(x => materielCodes.Contains(x.MaterielCode))
                    .ToList()
                    .ToDictionary(x => x.MaterielCode, x => x);
                // ç»„合数据
                var result = cabinOrderDetails.Select(detail =>
                {
                    var materiel = materiels.ContainsKey(detail.Goods_no) ? materiels[detail.Goods_no] : null;
                    return new
                    {
                        // è®¢å•明细字段
                        detail.Id,
                        detail.Batch_num,
                        detail.Goods_no,
                        detail.Order_qty,
                        detail.Order_Inqty,
                        detail.Status,
                        detail.OrderDetailStatus,
                        detail.Exp_date,//效期
                        // ç‰©æ–™ä¿¡æ¯å­—段
                        MaterielName = materiel?.MaterielName ?? "",
                        item = materiel?.item ?? "", // å“å/通用名
                        MaterielSpec = materiel?.MaterielSpec ?? "", // ç‰©æ–™è§„æ ¼
                        Factory = materiel?.Factory ?? "", // ç”Ÿäº§åނ家
                        MaterielUnit = materiel?.MaterielUnit ?? "", // åŸºæœ¬å•位
                        MaterielStoragecondition = materiel?.MaterielStoragecondition, // å­˜å‚¨æ¡ä»¶/效期
                        MaterielModel = materiel?.MaterielModel ?? "" // ç‰©æ–™åž‹å·
                    };
                }).ToList();
                int pageSize = 5; // æ¯é¡µæ˜¾ç¤º5条
                var pagedResult = result
                    .Skip((pageNo - 1) * pageSize)
                    .Take(pageSize)
                    .ToList();
                content.OK(data: pagedResult);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// Pad入库完成 
@@ -141,6 +200,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 +229,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 +389,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 +455,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)
                    {
@@ -502,6 +581,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,21 +928,29 @@
                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));
                    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();
                    #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();
                        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}】的盘盈数量有误");
                        Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).FirstOrDefault();
                        if (inventory_Batch==null)
                        {
                            _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 (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()
                                {
@@ -548,7 +967,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 = "盘盈入库"
                                };
@@ -556,19 +975,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
                    {
@@ -591,13 +1011,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
@@ -606,23 +1027,41 @@
                    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}】的盘盈数量有误");
                        Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).FirstOrDefault();
                        if (inventory_Batch == null)
                        {
                            _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}】的批次信息错误");
                        }
                        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 åº“存、库存批次平账
@@ -646,7 +1085,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 = "盘盈入库"
                                    };
@@ -654,13 +1093,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);
@@ -693,7 +1134,7 @@
                            cabinOrdersAdd.Add(entityOrder);
                            #endregion
                        }
                        else
                        else // LkQty != 0 è¡¨ç¤ºç«‹åº“有差异
                        {
                            #region å¤§ä»¶åº“库存平账
                            inventoryInfos = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
@@ -717,7 +1158,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 = "盘盈入库"
                                    };
@@ -725,7 +1166,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();
                            }
@@ -776,7 +1218,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,
@@ -790,23 +1232,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>
@@ -825,7 +1270,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;
@@ -837,8 +1283,8 @@
                }
                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 url = "http://192.168.1.100:80/GYZ2/95fck/outOrderOk";
                    if (cabinOrder.Order_type == "2") url = "http://192.168.1.100:80/GYZ2/95fck/outOrderOk";
                    var requestDate = new
                    {
                        order_no = cabinOrder.Order_no