dengjunjie
2025-10-25 3212f32acdce5938956131ecfb530e361250f82f
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs
@@ -101,7 +101,7 @@
                {
                    return new ApiResponse<Dt_InventoryInfo> { code = "500", msg = "请求参数无效" };
                }
                var reslut = WarehouseEnum.立库.ObjToInt().ToString("000");
                // 2️⃣ å¼€å¯äº‹åŠ¡
                BaseDal.Db.Ado.BeginTran();
                foreach (var detail in request.details)
@@ -122,9 +122,60 @@
                        case "1": //入库
                            {
                                #region å¤„理入库订单
                                var reslut = WarehouseEnum.立库.ObjToInt().ToString("000");
                                Dt_CabinOrder cabinOrder = Db.Queryable<Dt_CabinOrder>().Where(x => x.Order_no == request.orderNo && x.Warehouse_no ==reslut).Includes(x => x.Details).First();
                                //Dt_CabinOrder cabinOrder = Db.Queryable<Dt_CabinOrder>().Where(x => x.Order_no == request.orderNo && x.Warehouse_no == "001").Includes(x => x.Details).First();
                                #region åˆ¤æ–­æ˜¯å¦ä¸ºç›˜ç›ˆå…¥åº“单
                                if (cabinOrder.Order_type == "5")
                                {
                                    foreach (var item in cabinOrder.Details)
                                    {
                                        Dt_InventoryInfo inventoryInfo = BaseDal.Db.Queryable<Dt_InventoryInfo>()
                                        .First(x => x.MaterielCode == item.Goods_no && x.BatchNo == item.Batch_num && x.LocationCode == reslut);
                                        var qty = inventoryInfo.SupplyQuantity - inventoryInfo.StockQuantity;
                                        if (orderQty != qty)
                                            throw new Exception($"盘盈入库数量不一致,上传数量【{orderQty}】,库存盘盈数量【{qty}】");
                                        inventoryInfo.StockQuantity = inventoryInfo.SupplyQuantity;
                                        inventoryInfo.SupplyQuantity = 0;
                                        inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                                        #region æ·»åŠ ç›˜ç›ˆå…¥åº“ä»»åŠ¡
                                        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 = cabinOrder.Order_no,
                                            StockQuantity = orderQty,
                                            SupplyQuantity = 0,
                                            Remark = "盘盈入库"
                                        };
                                        #endregion
                                        var inventory_Batch = BaseDal.Db.Queryable<Dt_Inventory_Batch>()
                                        .First(x => x.MaterielCode == inventoryInfo.MaterielCode && x.BatchNo == inventoryInfo.BatchNo);
                                        inventory_Batch.StockQuantity = inventory_Batch.SupplyQuantity;
                                        inventory_Batch.SupplyQuantity = 0;
                                        item.OrderDetailStatus = "已完成";
                                        BaseDal.Db.Updateable(item).ExecuteCommand();
                                        BaseDal.Db.Updateable(inventoryInfo).ExecuteCommand();
                                        BaseDal.Db.Updateable(inventory_Batch).ExecuteCommand();
                                        BaseDal.Db.Insertable(supplyTask_Hty).ExecuteCommand();
                                    }
                                    var cabinOrder1 = BaseDal.Db.Queryable<Dt_CabinOrder>().Where(x => x.Id == cabinOrder.Id).Includes(x => x.Details).First();
                                    if (!cabinOrder1.Details.Where(x => x.OrderDetailStatus != "已完成").Any())
                                        cabinOrder.OdrderStatus = "已完成";
                                    BaseDal.Db.Updateable(cabinOrder).ExecuteCommand();
                                }
                                #endregion
                                else
                                {
                                if (cabinOrder == null || cabinOrder.OdrderStatus == "已完成")
                                    throw new Exception($"入库单已完成");
                                Dt_CabinOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Goods_no == detail.productCode && x.Batch_num == detail.batchNo && x.Status == 1).First();
@@ -226,7 +277,7 @@
                                    MaterielName = inventoryInfo.MaterielName,
                                    MaterielCode = inventoryInfo.MaterielCode,
                                    MaterielSpec = inventoryInfo.MaterielSpec,
                                    TaskType = TaskTypeEnum.InPick.ObjToInt(),
                                        TaskType = cabinOrder.Order_type == "1" ? TaskTypeEnum.In.ObjToInt() : TaskTypeEnum.OutReturn.ObjToInt(),
                                    CreateDate = DateTime.Now,
                                    Creater = App.User.UserName,
                                    LocationCode = inventoryInfo.LocationCode,
@@ -237,14 +288,64 @@
                                };
                                BaseDal.Db.Insertable(supplyTask_Hty).ExecuteCommand();
                                #endregion
                                //UpdateInboundOrderDetailStatus(request.orderNo, detail.batchNo, detail.productCode);
                                }
                            }
                            break;
                        case "2":
                            {
                                Dt_DeliveryOrder cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == request.orderNo && x.Warehouse_no == reslut).Includes(x => x.Details).First();
                                if (cabinOrder.Out_type == "6")
                                {
                                    foreach (var item in cabinOrder.Details)
                                    {
                                        Dt_InventoryInfo inventoryInfo = BaseDal.Db.Queryable<Dt_InventoryInfo>()
                                        .First(x => x.MaterielCode == item.Goods_no && x.BatchNo == item.Batch_num && x.LocationCode == reslut);
                                        var qty = inventoryInfo.StockQuantity - inventoryInfo.SupplyQuantity;
                                        if (orderQty != qty)
                                            throw new Exception($"盘亏出库数量不一致,上传数量【{orderQty}】,库存盘亏数量【{qty}】");
                                        inventoryInfo.StockQuantity = inventoryInfo.SupplyQuantity;
                                        inventoryInfo.SupplyQuantity = 0;
                                        inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                                        #region æ·»åŠ ç›˜äºå‡ºåº“ä»»åŠ¡
                                        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 = cabinOrder.Out_no,
                                            StockQuantity = orderQty,
                                            SupplyQuantity = 0,
                                            Remark = "盘亏出库"
                                        };
                                        #endregion
                                        var inventory_Batch = BaseDal.Db.Queryable<Dt_Inventory_Batch>()
                                        .First(x => x.MaterielCode == inventoryInfo.MaterielCode && x.BatchNo == inventoryInfo.BatchNo);
                                        inventory_Batch.StockQuantity = inventory_Batch.SupplyQuantity;
                                        inventory_Batch.SupplyQuantity = 0;
                                        item.OotDetailStatus = "已完成";
                                        BaseDal.Db.Updateable(item).ExecuteCommand();
                                        BaseDal.Db.Updateable(inventoryInfo).ExecuteCommand();
                                        BaseDal.Db.Updateable(inventory_Batch).ExecuteCommand();
                                        BaseDal.Db.Insertable(supplyTask_Hty).ExecuteCommand();
                                    }
                                    var cabinOrder1 = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Id == cabinOrder.Id).Includes(x => x.Details).First();
                                    if (!cabinOrder1.Details.Where(x => x.OotDetailStatus != "已完成").Any())
                                        cabinOrder.OutStatus = "已完成";
                                    BaseDal.Db.Updateable(cabinOrder).ExecuteCommand();
                                }
                                else
                                {
                                #region æ‰¾å‡ºåº“任务
                                Dt_SupplyTask supplyTask = Db.Queryable<Dt_SupplyTask>().Where(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo && x.OrderNo == request.orderNo && x.WarehouseCode == WarehouseEnum.立库.ObjToInt().ToString("000") && x.TaskStatus == SupplyStatusEnum.NewOut.ObjToInt()).First();
                                    Dt_SupplyTask supplyTask = Db.Queryable<Dt_SupplyTask>().Where(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo && x.OrderNo == request.orderNo && x.WarehouseCode == reslut && x.TaskStatus == SupplyStatusEnum.NewOut.ObjToInt()).First();
                                if (supplyTask == null) throw new Exception($"未找到订单号【{request.orderNo}】物料编号【{detail.productCode}】的出库任务");
                                if (supplyTask.StockQuantity != orderQty) throw new Exception($"订单号【{request.orderNo}】物料编号【{detail.productCode}】的出库数量与出库任务数量不相等");
                                #endregion
@@ -253,6 +354,7 @@
                                _deliveryOrderServices.OutTaskFinish(supplyTask);
                                #endregion
                            }
                            }
                            break;
                        case "3": // ç›˜ç‚¹
                            {