yanjinhui
昨天 07b532a6a6adf0a9d965b037cf98c1f98accd138
优化出入退货代码
已修改7个文件
803 ■■■■■ 文件已修改
新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/Business.cs 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs 478 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/LKBusiness/DeliveryOrderServicesLK.cs 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/NewBusiness.cs 227 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Allocat.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/Business.cs
@@ -48,11 +48,11 @@
            try
            {
                var reslut = WarehouseEnum.立库.ObjToInt().ToString("000");
                var orders = _cabinOrderServices.Repository.QueryData(x => x.OdrderStatus == "新建" && x.Warehouse_no == reslut);
                var orders = _cabinOrderServices.Repository.QueryData(x => x.OdrderStatus == "新建" && x.Warehouse_no == reslut).ToList();
                if (orders.Count < 1) return WebResponseContent.Instance.OK();
                string url = "http://172.16.1.2:9357/file-admin/api/in/ediIn";
                var cabinOrderDetails = _cabinDetailServices.Repository.QueryData(x => orders.Select(x => x.Id).ToList().Contains(x.OrderId));
                var materielInfos = _materielInfoService.Repository.QueryData(x => cabinOrderDetails.Select(x => x.Goods_no).Contains(x.MaterielCode));
                var cabinOrderDetails = _cabinDetailServices.Repository.QueryData(x => orders.Select(x => x.Id).ToList().Contains(x.OrderId)).ToList();
                var materielInfos = _materielInfoService.Repository.QueryData(x => cabinOrderDetails.Select(x => x.Goods_no).Contains(x.MaterielCode)).ToList();
                foreach (var order in orders)
                {
                    order.Details = cabinOrderDetails.Where(x => x.OrderId == order.Id).ToList();
@@ -127,11 +127,11 @@
            try
            {
                var reslut = WarehouseEnum.立库.ObjToInt().ToString("000");
                var orders = _deliveryOrderServices.Repository.QueryData(x => x.OutStatus == "新建" && x.Warehouse_no == reslut);
                var orders = _deliveryOrderServices.Repository.QueryData(x => x.OutStatus == "新建" && x.Warehouse_no == reslut).ToList();
                if (orders.Count < 1) return WebResponseContent.Instance.OK();
                string url = "http://172.16.1.2:9357/file-admin/api/out/ediOut";
                var deliveryOrderDetails = _deliveryOrderDetailServices.Repository.QueryData(x => orders.Select(x => x.Id).ToList().Contains(x.DeliveryOrderId));
                var materielInfos = _materielInfoService.Repository.QueryData(x => deliveryOrderDetails.Select(x => x.Goods_no).Contains(x.MaterielCode));
                var deliveryOrderDetails = _deliveryOrderDetailServices.Repository.QueryData(x => orders.Select(x => x.Id).ToList().Contains(x.DeliveryOrderId)).ToList();
                var materielInfos = _materielInfoService.Repository.QueryData(x => deliveryOrderDetails.Select(x => x.Goods_no).Contains(x.MaterielCode)).ToList();
                foreach (var order in orders)
                {
                    order.Details = deliveryOrderDetails.Where(x => x.DeliveryOrderId == order.Id).ToList();
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs
@@ -524,7 +524,11 @@
                    {
                        //找库存批次信息
                        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) 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)
@@ -614,7 +618,12 @@
                        //找库存批次信息
                        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) throw new Exception($"盘盈入库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘盈数量有误");
                        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();
                        //获取立库盘点差异数
@@ -626,9 +635,12 @@
                        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 + DJQty != Qty) throw new Exception($"【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的物料信息与物料批次信息盘盈数量不符");
                        if (LkQty == 0)//立库无差异
                        {
                            #region åº“存、库存批次平账
@@ -701,7 +713,7 @@
                            cabinOrdersAdd.Add(entityOrder);
                            #endregion
                        }
                        else
                        else // LkQty != 0 è¡¨ç¤ºç«‹åº“有差异
                        {
                            #region å¤§ä»¶åº“库存平账
                            inventoryInfos = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs
@@ -633,6 +633,340 @@
        #endregion
        #region åˆ›å»ºç›˜äºå‡ºåº“单
        //public WebResponseContent CreateCheckOutOrder(UpstramOutOrderInfo 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)).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.SupplyQuantity);
        //                if (Qty != item.order_qty)
        //                {
        //                    _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "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)
        //                    {
        //                        Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
        //                        {
        //                            WarehouseCode = inventoryInfo.WarehouseCode,
        //                            OperateType = OperateTypeEnum.自动完成.ToString(),
        //                            InsertTime = DateTime.Now,
        //                            TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(),
        //                            BatchNo = inventoryInfo.BatchNo,
        //                            MaterielName = inventoryInfo.MaterielName,
        //                            MaterielCode = inventoryInfo.MaterielCode,
        //                            MaterielSpec = inventoryInfo.MaterielSpec,
        //                            TaskType = TaskTypeEnum.ChenckOut.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();
        //                    // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
        //                }
        //                inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
        //                inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
        //                inventory_Batch.SupplyQuantity = 0;
        //                infosUp.AddRange(inventoryInfos);
        //                batchesUp.Add(inventory_Batch);
        //                // æ£€æŸ¥æ‰¹æ¬¡åº“存是否为0,如果是则标记为删除
        //                //_inventoryInfoService.UpdateData(inventoryInfos);
        //                //_inventory_BatchServices.UpdateData(inventory_Batch);
        //            }
        //            #endregion
        //            #region åˆ›å»ºç›˜ç‚¹å•
        //            var entityOrder = new Dt_DeliveryOrder
        //            {
        //                Out_no = order.order_no,
        //                Out_type = order.order_type,
        //                Client_no = order.client_no,
        //                Client_name = order.client_name,
        //                OutStatus = "已完成",
        //                Account_time = order.account_time,
        //                Warehouse_no = order.warehouse_no,
        //                Details = order.details.Select(d => new Dt_DeliveryOrderDetail
        //                {
        //                    Goods_no = d.goods_no,
        //                    Order_qty = Math.Abs(d.order_qty),
        //                    Order_Outqty = Math.Abs(d.order_qty),
        //                    Batch_num = d.batch_num,
        //                    Exp_date = d.exp_date,
        //                    Reservoirarea = order.warehouse_no,
        //                    OotDetailStatus = "已完成",
        //                    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();
        //            #endregion
        //        }
        //        #endregion
        //        else
        //        {
        //            List<Dt_DeliveryOrder> deliveryOrdersAdd = new List<Dt_DeliveryOrder>();
        //            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));
        //            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.OutOrderAlarm, "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.SupplyQuantity);
        //                var LkQty = inventoryLK.SupplyQuantity;
        //                //获取大件库盘点差异数
        //                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);
        //                var count = Math.Abs(LkQty + DJQty);
        //                if (count != Qty) {
        //                    _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "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.OutFinish.ObjToInt(),
        //                                BatchNo = inventoryInfo.BatchNo,
        //                                MaterielName = inventoryInfo.MaterielName,
        //                                MaterielCode = inventoryInfo.MaterielCode,
        //                                MaterielSpec = inventoryInfo.MaterielSpec,
        //                                TaskType = TaskTypeEnum.ChenckOut.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();
        //                        // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
        //                    }
        //                    //更新批次信息
        //                    //_inventoryInfoService.UpdateData(inventoryInfos);
        //                    inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
        //                    inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
        //                    inventory_Batch.SupplyQuantity = 0;
        //                    //_inventory_BatchServices.UpdateData(inventory_Batch);
        //                    infosUp.AddRange(inventoryInfos);
        //                    batchesUp.Add(inventory_Batch);
        //                    #endregion
        //                    #region åˆ›å»ºå¤§ä»¶åº“盘点单
        //                    var entityOrder = new Dt_DeliveryOrder
        //                    {
        //                        Out_no = order.order_no,
        //                        Out_type = order.order_type,
        //                        Client_no = order.client_no,
        //                        Account_time = order.account_time,
        //                        OutStatus = "已完成",
        //                        Client_name = order.client_name,
        //                        Warehouse_no = WareCodeDJ,
        //                        Details = order.details.Select(d => new Dt_DeliveryOrderDetail
        //                        {
        //                            Goods_no = d.goods_no,
        //                            Order_qty = Math.Abs(d.order_qty),
        //                            Order_Outqty = Math.Abs(d.order_qty),
        //                            Batch_num = d.batch_num,
        //                            Exp_date = d.exp_date,
        //                            Reservoirarea = WareCodeDJ,
        //                            OotDetailStatus = "已完成",
        //                            Status = 2,
        //                        }).ToList()
        //                    };
        //                    //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
        //                    //Repository.AddData(entityOrder);
        //                    deliveryOrdersAdd.Add(entityOrder);
        //                    #endregion
        //                }
        //                else //立库有盘点差异(需要出库),大件库可能有或没有差异
        //                {
        //                    #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.OutFinish.ObjToInt(),
        //                                BatchNo = inventoryInfo.BatchNo,
        //                                MaterielName = inventoryInfo.MaterielName,
        //                                MaterielCode = inventoryInfo.MaterielCode,
        //                                MaterielSpec = inventoryInfo.MaterielSpec,
        //                                TaskType = TaskTypeEnum.ChenckOut.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_DeliveryOrder
        //                        {
        //                            Out_no = order.order_no,
        //                            Out_type = order.order_type,
        //                            Client_name = order.client_name,
        //                            Account_time = order.account_time,
        //                            OutStatus = "已完成",
        //                            Client_no = order.client_no,
        //                            Warehouse_no = WareCodeDJ,
        //                            Details = order.details.Select(d => new Dt_DeliveryOrderDetail
        //                            {
        //                                Goods_no = d.goods_no,
        //                                Order_qty = DJQty,
        //                                Order_Outqty = DJQty,
        //                                Batch_num = d.batch_num,
        //                                Exp_date = d.exp_date,
        //                                Reservoirarea = WareCodeDJ,
        //                                OotDetailStatus = "已完成",
        //                                Status = 2,
        //                            }).ToList()
        //                        };
        //                        //Repository.AddData(cabinOrder);
        //                        //Db.InsertNav(cabinOrder).Include(it => it.Details).ExecuteCommand();
        //                        deliveryOrdersAdd.Add(cabinOrder);
        //                    }
        //                    #endregion
        //                    //这里
        //                    #region åˆ›å»ºç«‹åº“盘点单
        //                    var entityOrder = new Dt_DeliveryOrder
        //                    {
        //                        Out_no = order.order_no,
        //                        Out_type = order.order_type,
        //                        Client_no = order.client_no,
        //                        Account_time = order.account_time,
        //                        OutStatus = "新建",
        //                        Client_name = order.client_name,
        //                        Warehouse_no = WareCodeLK,
        //                        Details = order.details.Select(d => new Dt_DeliveryOrderDetail
        //                        {
        //                            Goods_no = d.goods_no,
        //                            Order_qty = Math.Abs(LkQty), //给下游WCS的是要整数
        //                            Batch_num = d.batch_num,
        //                            Exp_date = d.exp_date,
        //                            Reservoirarea = WareCodeLK,
        //                            OotDetailStatus = "新建",
        //                            Status = 0,
        //                        }).ToList()
        //                    };
        //                    //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
        //                    //Repository.AddData(entityOrder);
        //                    deliveryOrdersAdd.Add(entityOrder);
        //                    #endregion
        //                }
        //                //return WebResponseContent.Instance.OK("成功");
        //            }
        //            _unitOfWorkManage.BeginTran();
        //            _supplyTaskHtyService.AddData(supplyTask_Hties);
        //            _inventoryInfoService.UpdateData(infosUp);
        //            _inventory_BatchServices.UpdateData(batchesUp);
        //            BaseDal.Db.InsertNav(deliveryOrdersAdd).Include(it => it.Details).ExecuteCommand();
        //            _unitOfWorkManage.CommitTran();
        //        }
        //        return WebResponseContent.Instance.OK("成功");
        //    }
        //    catch (Exception ex)
        //    {
        //        _unitOfWorkManage.RollbackTran();
        //        content.Error(ex.Message);
        //    }
        //    return content;
        //}
        #endregion
        #region åˆ›å»ºç›˜äºå‡ºåº“单 ï¼ˆæ·»åŠ åˆ é™¤åº“å­˜ä¸º0的情况)
        public WebResponseContent CreateCheckOutOrder(UpstramOutOrderInfo order)
        {
            WebResponseContent content = new WebResponseContent();
@@ -642,20 +976,29 @@
                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_Inventory_Batch> batchesDel = new List<Dt_Inventory_Batch>();//删除
                List<Dt_InventoryInfo> infosUp = new List<Dt_InventoryInfo>();
                List<Dt_InventoryInfo> infosDel = 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));
                    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.SupplyQuantity);
                        if (Qty != item.order_qty) throw new Exception($"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
                        if (Qty != item.order_qty)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "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)
@@ -682,22 +1025,31 @@
                                    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();
                            // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
                            if (inventoryInfo.StockQuantity <= 0)
                                infosDel.Add(inventoryInfo);
                            else
                                infosUp.Add(inventoryInfo);
                        }
                        inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
                        inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
                        inventory_Batch.SupplyQuantity = 0;
                        infosUp.AddRange(inventoryInfos);
                        batchesUp.Add(inventory_Batch);
                        //_inventoryInfoService.UpdateData(inventoryInfos);
                        //_inventory_BatchServices.UpdateData(inventory_Batch);
                        // æ£€æŸ¥æ‰¹æ¬¡åº“存是否为0,如果是则标记为删除
                        if (inventory_Batch.StockQuantity <= 0)
                            batchesDel.Add(inventory_Batch);
                        else
                            batchesUp.Add(inventory_Batch);
                    }
                    #endregion
@@ -723,10 +1075,19 @@
                            Status = 2,
                        }).ToList()
                    };
                    _unitOfWorkManage.BeginTran();
                    _supplyTaskHtyService.AddData(supplyTask_Hties);
                    _inventoryInfoService.UpdateData(infosUp);
                    _inventory_BatchServices.UpdateData(batchesUp);
                    if (infosUp.Any())
                        _inventoryInfoService.UpdateData(infosUp);
                    if (infosDel.Any())
                        _inventoryInfoService.DeleteData(infosDel);
                    if (batchesUp.Any())
                        _inventory_BatchServices.UpdateData(batchesUp);
                    if (batchesDel.Any())
                        _inventory_BatchServices.DeleteData(batchesDel);
                    BaseDal.Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
                    _unitOfWorkManage.CommitTran();
                    #endregion
@@ -739,25 +1100,35 @@
                    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));
                    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) throw new Exception($"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
                        if (Qty != item.order_qty)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "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.SupplyQuantity);
                        var LkQty = inventoryLK.SupplyQuantity;
                        //获取大件库盘点差异数
                        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);
                        var count = Math.Abs(LkQty + DJQty);
                        if (count != Qty) throw new Exception($"【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的物料信息与物料批次信息盘亏数量不符");
                        if (LkQty == 0)//立库无差异
                        if (count != Qty)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "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)
@@ -784,22 +1155,33 @@
                                        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();
                                // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
                                if (inventoryInfo.StockQuantity <= 0)
                                    infosDel.Add(inventoryInfo);
                                else
                                    infosUp.Add(inventoryInfo);
                            }
                            //_inventoryInfoService.UpdateData(inventoryInfos);
                            //更新批次信息
                            inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
                            inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
                            inventory_Batch.SupplyQuantity = 0;
                            //_inventory_BatchServices.UpdateData(inventory_Batch);
                            infosUp.AddRange(inventoryInfos);
                            batchesUp.Add(inventory_Batch);
                            // æ£€æŸ¥æ‰¹æ¬¡åº“存是否为0,如果是则标记为删除
                            if (inventory_Batch.StockQuantity <= 0)
                                batchesDel.Add(inventory_Batch);
                            else
                                batchesUp.Add(inventory_Batch);
                            #endregion
                            #region åˆ›å»ºå¤§ä»¶åº“盘点单
@@ -824,16 +1206,14 @@
                                    Status = 2,
                                }).ToList()
                            };
                            //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
                            //Repository.AddData(entityOrder);
                            deliveryOrdersAdd.Add(entityOrder);
                            #endregion
                        }
                        else
                        else //立库有盘点差异(需要出库),大件库可能有或没有差异
                        {
                            #region å¤§ä»¶åº“库存平账
                            inventoryInfos = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
                            foreach (var inventoryInfo in inventoryInfos)
                            var inventoryInfosDJ = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
                            foreach (var inventoryInfo in inventoryInfosDJ)
                            {
                                #region æ·»åŠ ç›˜äºå‡ºåº“ä»»åŠ¡
                                if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity)
@@ -857,17 +1237,21 @@
                                        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();
                                // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
                                if (inventoryInfo.StockQuantity <= 0)
                                    infosDel.Add(inventoryInfo);
                                else
                                    infosUp.Add(inventoryInfo);
                            }
                            //_inventoryInfoService.UpdateData(inventoryInfos);
                            infosUp.AddRange(inventoryInfos);
                            #endregion
                            #region åˆ›å»ºå¤§ä»¶åº“盘点单
@@ -894,12 +1278,10 @@
                                        Status = 2,
                                    }).ToList()
                                };
                                //Repository.AddData(cabinOrder);
                                //Db.InsertNav(cabinOrder).Include(it => it.Details).ExecuteCommand();
                                deliveryOrdersAdd.Add(cabinOrder);
                            }
                            #endregion
                            //这里
                            #region åˆ›å»ºç«‹åº“盘点单
                            var entityOrder = new Dt_DeliveryOrder
                            {
@@ -921,20 +1303,27 @@
                                    Status = 0,
                                }).ToList()
                            };
                            //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
                            //Repository.AddData(entityOrder);
                            deliveryOrdersAdd.Add(entityOrder);
                            #endregion
                        }
                        //return WebResponseContent.Instance.OK("成功");
                    }
                    _unitOfWorkManage.BeginTran();
                    _supplyTaskHtyService.AddData(supplyTask_Hties);
                    _inventoryInfoService.UpdateData(infosUp);
                    _inventory_BatchServices.UpdateData(batchesUp);
                    if (infosUp.Any())
                        _inventoryInfoService.UpdateData(infosUp);
                    if (infosDel.Any())
                        _inventoryInfoService.DeleteData(infosDel);
                    if (batchesUp.Any())
                        _inventory_BatchServices.UpdateData(batchesUp);
                    if (batchesDel.Any())
                        _inventory_BatchServices.DeleteData(batchesDel);
                    BaseDal.Db.InsertNav(deliveryOrdersAdd).Include(it => it.Details).ExecuteCommand();
                    _unitOfWorkManage.CommitTran();
                }
                return WebResponseContent.Instance.OK("成功");
            }
            catch (Exception ex)
@@ -1029,7 +1418,12 @@
            return content;
        }
        /// <summary>
        /// å¤„理出库单、库存信息、出库任务、调拨任务
        /// </summary>
        /// <param name="supplyTask"></param>
        /// <returns></returns>
        public WebResponseContent OutTaskFinish(Dt_SupplyTask supplyTask, Dt_DeliveryOrder deliveryOrder)
        {
            WebResponseContent content = new WebResponseContent();
@@ -1063,8 +1457,7 @@
                #endregion
                #region åº“存批次 å¦‚果任务类型是调拨出库任务(8)就不修改批次库存
                Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode ==
                    inventoryInfo.MaterielCode);
                Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode ==inventoryInfo.MaterielCode);
                if (supplyTask.TaskType != TaskTypeEnum.AllocatOut.ObjToInt())
                {
                    inventory_Batch.StockQuantity -= supplyTask.StockQuantity;
@@ -1074,12 +1467,12 @@
                supplyTask.TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt();
                _unitOfWorkManage.BeginTran();
                if (inventory_Batch.StockQuantity <= 0)
                if (inventory_Batch.StockQuantity <= 0)//如果库存数量小于0就删除库存批次信息
                    _inventory_BatchServices.DeleteData(inventory_Batch);
                else
                    _inventory_BatchServices.UpdateData(inventory_Batch);
                //_materielInfoService.UpdateData(materielInfo);
                if (inventoryInfo.StockQuantity <= 0)
                if (inventoryInfo.StockQuantity <= 0)//如果库存数量小于0就删除库存信息
                    _inventoryInfoService.DeleteData(inventoryInfo);
                else
                    _inventoryInfoService.UpdateData(inventoryInfo);
@@ -1118,6 +1511,7 @@
            return content;
        }
        public WebResponseContent OutTaskFinish(Dt_SupplyTask supplyTask)
        {
            WebResponseContent content = new WebResponseContent();
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/LKBusiness/DeliveryOrderServicesLK.cs
@@ -11,6 +11,8 @@
using WIDESEA_Core.Enums;
using WIDESEA_ISquareCabinServices;
using WIDESEA_Core.Helper;
using WIDESEA_Common;
using static WIDESEA_DTO.SquareCabin.OrderDto;
namespace WIDESEA_SquareCabinServices
{
@@ -25,6 +27,8 @@
                List<Dt_SupplyTask_Hty> supplyTask_Hties = new List<Dt_SupplyTask_Hty>();
                List<Dt_InventoryInfo> infosUp = new List<Dt_InventoryInfo>();
                List<Dt_Inventory_Batch> batchesUp = new List<Dt_Inventory_Batch>();
                List<Dt_InventoryInfo> infosDel = new List<Dt_InventoryInfo>();//添加删除
                List<Dt_Inventory_Batch> batchesDel = new List<Dt_Inventory_Batch>();
                List<Dt_MaterielInfo> materielInfos = _materielInfoService.Repository.QueryData(x => deliveryOrder.Details.Select(x => x.Goods_no).ToList().Contains(x.MaterielCode));
                List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => deliveryOrder.Warehouse_no == x.WarehouseCode && deliveryOrder.Details.Select(x => x.Goods_no).ToList().Contains(x.MaterielCode));
                List<Dt_Inventory_Batch> inventory_Batches = _inventory_BatchServices.Repository.QueryData(x => deliveryOrder.Details.Select(x => x.Goods_no).ToList().Contains(x.MaterielCode));
@@ -37,11 +41,20 @@
                        foreach (var detail in request.details)
                        {
                            Dt_DeliveryOrderDetail? orderDetail = deliveryOrder.Details.FirstOrDefault(x => x.Goods_no == detail.productCode && x.Batch_num == detail.batchNo);
                            if (orderDetail == null) throw new Exception($"未找到盘点单【{deliveryOrder.Out_no}】物料编号【{detail.productCode}】物料批次【{detail.batchNo}】的明细信息");
                            if (orderDetail == null)
                            {
                                _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "盘亏出库单", $"未找到盘点单【{deliveryOrder.Out_no}】物料编号【{detail.productCode}】物料批次【{detail.batchNo}】的明细信息");
                                throw new Exception($"未找到盘点单【{deliveryOrder.Out_no}】物料编号【{detail.productCode}】物料批次【{detail.batchNo}】的明细信息");
                            }
                            decimal orderQty = detail.orderDetails?.Sum(x => decimal.TryParse(x.quantity, out var q) ? Math.Abs(q) : 0) ?? 0;
                            Dt_InventoryInfo inventoryInfo = inventoryInfos.Where(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo).First();
                            if (orderQty != Math.Abs(inventoryInfo.SupplyQuantity))
                            {
                                _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "盘亏出库单", $"盘亏出库数量不一致,上传数量【{orderQty}】,库存盘亏数量【{Math.Abs(inventoryInfo.SupplyQuantity)}】");
                                throw new Exception($"盘亏出库数量不一致,上传数量【{orderQty}】,库存盘亏数量【{Math.Abs(inventoryInfo.SupplyQuantity)}】");
                            }
                            //添加物料信息中的立库业务库存信息
                            var mater = materielInfos.FirstOrDefault(x => x.MaterielCode == detail.productCode);
                            if (mater != null)
@@ -53,13 +66,24 @@
                            inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
                            inventoryInfo.SupplyQuantity = 0;
                            inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                            infosUp.Add(inventoryInfo);
                            // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
                            if (inventoryInfo.StockQuantity <= 0)
                                infosDel.Add(inventoryInfo);
                            else
                                infosUp.Add(inventoryInfo);
                            //infosUp.Add(inventoryInfo);
                            //库存批次
                            Dt_Inventory_Batch inventory_Batch = inventory_Batches.First(x => x.MaterielCode == inventoryInfo.MaterielCode && x.BatchNo == inventoryInfo.BatchNo);
                            inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
                            inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
                            inventory_Batch.SupplyQuantity = 0;
                            batchesUp.Add(inventory_Batch);
                            orderDetail.OotDetailStatus = "已完成";
                            orderDetail.Order_Outqty = orderQty; //完成数量
                            if (inventory_Batch.StockQuantity<=0)
                                batchesDel.Add(inventory_Batch);
                            else
                                batchesUp.Add(inventory_Batch);
                            cabinOrderDetailsUp.Add(orderDetail);
                            #region æ·»åŠ ç›˜äºå‡ºåº“ä»»åŠ¡
                            Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
@@ -85,6 +109,7 @@
                            #endregion
                        }
                        deliveryOrder.OutStatus = "已完成";
                        //从所有出库明细中,筛选出那些不在已完成列表中的明细项
                        if (deliveryOrder.Details.Where(x => !cabinOrderDetailsUp.Select(x => x.Id).Contains(x.Id)).Any())
                            deliveryOrder.OutStatus = "开始";
                        _unitOfWorkManage.BeginTran();
@@ -111,9 +136,17 @@
                    {
                        decimal orderQty = detail.orderDetails?.Sum(x => decimal.TryParse(x.quantity, out var q) ? Math.Abs(q) : 0) ?? 0;
                        Dt_SupplyTask? supplyTask = supplyTasks.FirstOrDefault(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo);
                        if (supplyTask == null) throw new Exception($"未找到订单号【{request.externalOrderNo}】物料编号【{detail.productCode}】的出库任务");
                        if (supplyTask == null)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "出库单", $"未找到订单号【{request.externalOrderNo}】物料编号【{detail.productCode}】的出库任务");
                            throw new Exception($"未找到订单号【{request.externalOrderNo}】物料编号【{detail.productCode}】的出库任务");
                        }
                        if (supplyTask.StockQuantity != orderQty)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "出库单", $"订单号【{request.orderNo}】物料编号【{detail.productCode}】的出库数量与出库任务数量不相等");
                            throw new Exception($"订单号【{request.orderNo}】物料编号【{detail.productCode}】的出库数量与出库任务数量不相等");
                        }
                        //处理出库单、库存信息、出库任务、调拨任务
                        content = OutTaskFinish(supplyTask, deliveryOrder);
                        if (!content.Status) throw new Exception(content.Message);
                    }
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/NewBusiness.cs
@@ -16,6 +16,171 @@
    public partial class Business
    {
        #region èŽ·å–ERP入库单
        //static string SearchInOrderDate = "2025-11-01 00:00:00";
        //public WebResponseContent GetInOrder()
        //{
        //    WebResponseContent content = new WebResponseContent();
        //    try
        //    {
        //        var url = "http://121.37.118.63:80/GYZ2/95fck/inOrder";
        //        string GetOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        //        if (string.IsNullOrEmpty(SearchInOrderDate)) SearchInOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        //        var requestData = new { searchDate = SearchInOrderDate };
        //        //SearchInOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        //        var result = HttpHelper.Post(url, requestData.ToJsonString());
        //        var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstreamOrderInfo>>(result);
        //        if (response == null) return content;
        //        if (response.data.Count < 1)
        //        {
        //            SearchInOrderDate = GetOutOrderDate;
        //            return content;
        //        }
        //        var ordernos = response.data.Select(x => x.order_no).ToList();
        //        var existingOrderNos = _cabinOrderServices.Repository.QueryData(x => ordernos.Contains(x.Order_no)).Select(x => x.Order_no).Distinct().ToList();
        //        var newOrders = response.data.Where(order => !existingOrderNos.Contains(order.order_no)).ToList();
        //        if (newOrders.Count < 1)
        //        {
        //            SearchInOrderDate = GetOutOrderDate;
        //            return content;
        //        }
        //        int messQty = 0;
        //        foreach (var order in newOrders)
        //        {
        //            try
        //            {
        //                if (order.order_type == "1")
        //                {
        //                    content = _cabinOrderServices.CreateInboundOrder(order);
        //                    if (!content.Status) messQty++;
        //                }
        //                else if (order.order_type == "3")//入库退料
        //                {
        //                    #region è½¬æ¢ä¸ºå‡ºåº“单
        //                    UpstramOutOrderInfo upstramOutOrderInfo = new UpstramOutOrderInfo()
        //                    {
        //                        order_no = order.order_no,
        //                        order_type = order.order_type,
        //                        warehouse_no = order.warehouse_no,
        //                        details = new List<UpstreamOutOrderDetail>()
        //                    };
        //                    foreach (var item in order.details)
        //                    {
        //                        UpstreamOutOrderDetail detail = new UpstreamOutOrderDetail()
        //                        {
        //                            batch_num = item.batch_num,
        //                            goods_no = item.goods_no,
        //                            order_qty = item.order_qty,
        //                            exp_date = item.exp_date,
        //                        };
        //                        upstramOutOrderInfo.details.Add(detail);
        //                    }
        //                    #endregion
        //                    content = _deliveryOrderServices.CreateOutboundOrder(upstramOutOrderInfo);
        //                    if (!content.Status) messQty++;
        //                }
        //                else if (order.order_type == "5")//报溢入库
        //                {
        //                    content = _cabinOrderServices.CreateCheckInOrder(order);
        //                    if (!content.Status) messQty++;
        //                }
        //            }
        //            catch (Exception ex)
        //            {
        //                continue;
        //            }
        //        }
        //        if (messQty == 0) SearchInOrderDate = GetOutOrderDate;
        //        return content.OK();
        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine("获取ERP入库单信息异常:" + ex.Message);
        //        return content.Error(ex.Message);
        //    }
        //}
        #endregion
        #region èŽ·å–ERP出库单
        //static string SearchOutOrderDate = "2025-11-01 00:00:00";
        //public WebResponseContent GetOutOrder()
        //{
        //    WebResponseContent content = new WebResponseContent();
        //    try
        //    {
        //        //var url = "http://121.37.118.63:80/GYZ2/95fck/outOrder";
        //         var url = "http://127.0.0.1:4523/m2/5660322-5340849-default/366751306?apifoxApiId=366751306";
        //        string GetOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        //        if (string.IsNullOrEmpty(SearchOutOrderDate)) SearchOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        //        var requestData = new { searchDate = SearchOutOrderDate };
        //        var result = HttpHelper.Post(url, requestData.ToJsonString());
        //        var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstramOutOrderInfo>>(result);
        //        if (response == null) return content;
        //        if (response.data.Count < 1)
        //        {
        //            SearchOutOrderDate = GetOutOrderDate;
        //            return content;
        //        }
        //        var ordernos = response.data.Select(x => x.order_no).ToList();
        //        var existingOutOrderNos = _deliveryOrderServices.Repository.QueryData(x => ordernos.Contains(x.Out_no)).Select(x => x.Out_no).Distinct().ToList();
        //        var newOutOrders = response.data.Where(outorder => !existingOutOrderNos.Contains(outorder.order_no)).ToList();
        //        if (newOutOrders.Count < 1)
        //        {
        //            SearchOutOrderDate = GetOutOrderDate;
        //            return content;
        //        }
        //        int messQty = 0;
        //        foreach (var outorder in newOutOrders)
        //        {
        //            if (outorder.order_type == "1")// æ­£å¸¸å‡ºåº“单
        //            {
        //                content = _deliveryOrderServices.CreateOutboundOrder(outorder);
        //                if (!content.Status) messQty++;
        //            }
        //            else if (outorder.order_type == "2")//出库退货
        //            {
        //                #region è½¬æ¢æˆå…¥åº“单
        //                UpstreamOrderInfo order = new UpstreamOrderInfo()
        //                {
        //                    order_no = outorder.order_no,
        //                    order_type = outorder.order_type,
        //                    warehouse_no = outorder.warehouse_no,
        //                    details = new List<UpstreamOrderDetail>()
        //                };
        //                foreach (var item in outorder.details)
        //                {
        //                    UpstreamOrderDetail detail = new UpstreamOrderDetail()
        //                    {
        //                        batch_num = item.batch_num,
        //                        goods_no = item.goods_no,
        //                        order_qty = item.order_qty,
        //                        exp_date = item.exp_date,
        //                    };
        //                    order.details.Add(detail);
        //                }
        //                #endregion
        //                content = _cabinOrderServices.CreateInboundOrder(order);
        //                if (!content.Status) messQty++;
        //            }
        //            else if (outorder.order_type == "6")//报损出库
        //            {
        //                content = _deliveryOrderServices.CreateCheckOutOrder(outorder);
        //                if (!content.Status) messQty++;
        //            }
        //        }
        //        if (messQty == 0) SearchOutOrderDate = GetOutOrderDate;
        //    }
        //    catch (Exception ex)
        //    {
        //        content.Error(ex.Message);
        //    }
        //    return content;
        //}
        #endregion
        #region èŽ·å–ERP入库单
        static string SearchInOrderDate = "2025-11-01 00:00:00";
        public WebResponseContent GetInOrder()
        {
@@ -26,7 +191,6 @@
                string GetOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (string.IsNullOrEmpty(SearchInOrderDate)) SearchInOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                var requestData = new { searchDate = SearchInOrderDate };
                //SearchInOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                var result = HttpHelper.Post(url, requestData.ToJsonString());
                var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstreamOrderInfo>>(result);
                if (response == null) return content;
@@ -35,14 +199,33 @@
                    SearchInOrderDate = GetOutOrderDate;
                    return content;
                }
                var ordernos = response.data.Select(x => x.order_no).ToList();
                var existingOrderNos = _cabinOrderServices.Repository.QueryData(x => ordernos.Contains(x.Order_no)).Select(x => x.Order_no).Distinct().ToList();
                var newOrders = response.data.Where(order => !existingOrderNos.Contains(order.order_no)).ToList();
                // å…³é”®ä¿®æ”¹ï¼šæŒ‰è®¢å•类型分别检查对应的表
                var inOrderTypes = new List<string> { "1", "5" }; // å…¥åº“类型
                var outOrderTypes = new List<string> { "3" };      // å‡ºåº“类型
                // æ£€æŸ¥å…¥åº“单表(只检查入库类型的订单)是否存在
                var existingInOrderNos = _cabinOrderServices.Repository.QueryData(x => ordernos.Contains(x.Order_no))
                    .Select(x => x.Order_no).Distinct().ToList();
                // æ£€æŸ¥å‡ºåº“单表(只检查出库类型的订单)
                var existingOutOrderNos = _deliveryOrderServices.Repository.QueryData(x => ordernos.Contains(x.Out_no))
                    .Select(x => x.Out_no).Distinct().ToList();
                // ç­›é€‰æ–°è®¢å•:入库类型检查入库表,出库类型检查出库表 é€‰å‡ºä¸åŒ…含已存在在
                var newOrders = response.data.Where(order =>
                    (inOrderTypes.Contains(order.order_type) && !existingInOrderNos.Contains(order.order_no)) ||
                    (outOrderTypes.Contains(order.order_type) && !existingOutOrderNos.Contains(order.order_no))
                ).ToList();
                if (newOrders.Count < 1)
                {
                    SearchInOrderDate = GetOutOrderDate;
                    return content;
                }
                int messQty = 0;
                foreach (var order in newOrders)
                {
@@ -60,6 +243,9 @@
                            {
                                order_no = order.order_no,
                                order_type = order.order_type,
                                client_no=order.supplier_no,
                                client_name=order.supplier_name,
                                account_time=order.account_time,
                                warehouse_no = order.warehouse_no,
                                details = new List<UpstreamOutOrderDetail>()
                            };
@@ -120,16 +306,35 @@
                    SearchOutOrderDate = GetOutOrderDate;
                    return content;
                }
                var ordernos = response.data.Select(x => x.order_no).ToList();
                var existingOutOrderNos = _deliveryOrderServices.Repository.QueryData(x => ordernos.Contains(x.Out_no)).Select(x => x.Out_no).Distinct().ToList();
                var newOutOrders = response.data.Where(outorder => !existingOutOrderNos.Contains(outorder.order_no)).ToList();
                if (newOutOrders.Count < 1)
                // æŒ‰è®¢å•类型分别检查对应的表
                var outOrderTypes = new List<string> { "1", "6" }; // å‡ºåº“类型
                var inOrderTypes = new List<string> { "2" };       // å…¥åº“类型
                // æ£€æŸ¥å‡ºåº“单表(只检查出库类型的订单)
                var existingOutOrderNos = _deliveryOrderServices.Repository.QueryData(x => ordernos.Contains(x.Out_no))
                    .Select(x => x.Out_no).Distinct().ToList();
                // æ£€æŸ¥å…¥åº“单表(只检查入库类型的订单)
                var existingInOrderNos = _cabinOrderServices.Repository.QueryData(x => ordernos.Contains(x.Order_no))
                    .Select(x => x.Order_no).Distinct().ToList();
                // ç­›é€‰æ–°è®¢å•:出库类型检查出库表,入库类型检查入库表
                var newOrders = response.data.Where(order =>
                    (outOrderTypes.Contains(order.order_type) && !existingOutOrderNos.Contains(order.order_no)) ||
                    (inOrderTypes.Contains(order.order_type) && !existingInOrderNos.Contains(order.order_no))
                ).ToList();
                if (newOrders.Count < 1)
                {
                    SearchOutOrderDate = GetOutOrderDate;
                    return content;
                }
                int messQty = 0;
                foreach (var outorder in newOutOrders)
                foreach (var outorder in newOrders)
                {
                    if (outorder.order_type == "1")// æ­£å¸¸å‡ºåº“单
                    {
@@ -143,6 +348,9 @@
                        {
                            order_no = outorder.order_no,
                            order_type = outorder.order_type,
                            supplier_no=outorder.client_no,
                            supplier_name=outorder.client_name,
                            account_time=outorder.account_time,
                            warehouse_no = outorder.warehouse_no,
                            details = new List<UpstreamOrderDetail>()
                        };
@@ -167,6 +375,7 @@
                        if (!content.Status) messQty++;
                    }
                }
                if (messQty == 0) SearchOutOrderDate = GetOutOrderDate;
            }
            catch (Exception ex)
@@ -175,6 +384,8 @@
            }
            return content;
        }
        #endregion
        #endregion
    }
}
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Allocat.cs
@@ -112,7 +112,7 @@
                #endregion
                #region å¤§ä»¶åº“补立库后立库业务库存数还是小于立库最小库存数,添加提示信息
                #region å¤§ä»¶åº“补立库后立库业务库materielInfo.Business_qty存数还是小于立库最小库存数,添加提示信息
                //添加报警信息
                if (materielInfo.Business_qty < materielInfo.MinQty)
                {
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs
@@ -33,11 +33,18 @@
                //List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>();
                List<Dt_SupplyTask> supplyTasks1 = 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));
                List<Dt_Inventory_Batch> inventory_Batches = _inventory_BatchServices.Repository.QueryData(x => keys.Contains(x.Id)).ToList();
                foreach (var item in inventory_Batches)
                {
                    var supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
                    if (item.SupplyQuantity != 0) throw new Exception($"物料编号【{item.MaterielCode}】批次号【{item.BatchNo}】已存在盘点差异!");
                    //if (item.SupplyQuantity != 0) throw new Exception($"物料编号【{item.MaterielCode}】批次号【{item.BatchNo}】已存在盘点差异!");
                    if (item.SupplyQuantity != 0)
                    {
                        item.SupplyQuantity = 0;
                        // è¿™é‡Œéœ€è¦æ›´æ–°æ‰¹æ¬¡è¡¨çš„差异数量
                        _inventory_BatchServices.UpdateData(item);
                    }
                    if (supplyTasks.Count > 0) throw new Exception($"物料编号【{item.MaterielCode}】批次号【{item.BatchNo}】已存在盘点任务,请先完成当前盘点任务");
                    supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewOut.ObjToInt()).ToList();
                    if (supplyTasks.Count > 0) throw new Exception($"物料编号【{item.MaterielCode}】批次号【{item.BatchNo}】已存在出库任务,请先完成当前出库任务");
@@ -79,6 +86,8 @@
                            #region åˆ›å»ºç›˜ç‚¹ä»»åŠ¡
                            foreach (var inventory in items)
                            {
                                //在创建盘点任务时重置库存的盘点差异为0
                                inventory.SupplyQuantity = 0;
                                Dt_SupplyTask supplyTask = new Dt_SupplyTask()
                                {
                                    WarehouseCode = inventory.WarehouseCode,
@@ -206,7 +215,7 @@
            {
                var LocationCode = saveModel.MainData["locationCode"].ToString();
                var TaskId = saveModel.MainData["taskId"].ObjToInt();
                var qty = saveModel.MainData["qty"].ObjToInt();
                var qty = saveModel.MainData["qty"].ObjToDecimal();
                Dt_SupplyTask supplyTask = _supplyTaskService.Repository.QueryFirst(x => x.TaskId == TaskId && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt());
                if (supplyTask == null) throw new Exception("当前盘点任务已完成");
                if (supplyTask.LocationCode != LocationCode) throw new Exception($"当前盘点货位【{LocationCode}】与任务分配货位不匹配");
@@ -249,8 +258,8 @@
                #endregion
                #region åº“å­˜
                List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => cabinOrder.Details.Select(x => x.Goods_no).Contains(x.MaterielCode));
                List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => cabinOrder.Details.Select(x => x.Goods_no).Contains(x.MaterielCode) && x.WarehouseCode == supplyTask.WarehouseCode && x.StockStatus == StockStatusEmun.盘点锁定.ObjToInt());
                List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => cabinOrder.Details.Select(x => x.Goods_no).Contains(x.MaterielCode)).ToList();
                List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => cabinOrder.Details.Select(x => x.Goods_no).Contains(x.MaterielCode) && x.WarehouseCode == supplyTask.WarehouseCode && x.StockStatus == StockStatusEmun.盘点锁定.ObjToInt()).ToList();
                Dt_InventoryInfo? inventoryInfo = new();
                List<Dt_InventoryInfo> inventoryInfosDel = new List<Dt_InventoryInfo>();
                if (supplyTask.WarehouseCode != WarehouseEnum.立库.ObjToInt().ToString("000"))
@@ -263,7 +272,7 @@
                    inventoryInfo = inventoryInfos.FirstOrDefault(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
                }
                if (inventoryInfo == null) return WebResponseContent.Instance.Error($"未找到立库的库存信息");
                inventoryInfo.SupplyQuantity = supplyTask.SupplyQuantity - inventoryInfo.StockQuantity;
                inventoryInfo.SupplyQuantity = supplyTask.SupplyQuantity - inventoryInfo.StockQuantity;//盘点差异数
                #endregion
                List<Dt_SupplyTask> supplyTasks = _supplyTaskService.Repository.QueryData(x => x.OrderNo == supplyTask.OrderNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.TaskId != supplyTask.TaskId).ToList();//查找当前盘点单的盘点任务
@@ -275,7 +284,7 @@
                    #region å¤„理当前物料批次的库存和批次信息
                    Dt_Inventory_Batch inventory_Batch = inventory_Batchs.First(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode);
                    var SupplyQuantitys = inventoryInfos.Where(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode).Sum(x => x.SupplyQuantity);
                    if (SupplyQuantitys == 0)
                    if (SupplyQuantitys == 0)//不存在盘点差异
                    {
                        foreach (var item in inventoryInfos.Where(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode))
                        {