Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -1,11 +1,89 @@
|
||||
# 📦 سیستم انبارداری یکپارچه (Unified Inventory Management)
|
||||
|
||||
> **تاریخ ایجاد:** ۱۲ دی ۱۴۰۴ (1 January 2026)
|
||||
> **وضعیت:** 📋 Planning
|
||||
> **تاریخ تکمیل:** ۱۲ دی ۱۴۰۴ (1 January 2026)
|
||||
> **وضعیت:** ✅ **COMPLETED**
|
||||
> **اولویت:** 🟡 Medium
|
||||
|
||||
---
|
||||
|
||||
## ✅ خلاصه اجرایی (Implementation Summary)
|
||||
|
||||
### فایلهای ایجاد شده در CMS:
|
||||
|
||||
#### Domain Layer
|
||||
- `Domain/Entities/InventoryItem.cs` - موجودیت اصلی انبار
|
||||
- `Domain/Entities/StockMovement.cs` - تاریخچه حرکات انبار
|
||||
- `Domain/Entities/Warehouse.cs` - انبارها
|
||||
- `Domain/Enums/StockMovementType.cs` - انواع حرکات انبار
|
||||
- `Domain/Enums/ProductType.cs` - نوع محصول (معمولی/تخفیفی)
|
||||
|
||||
#### Infrastructure Layer
|
||||
- `Infrastructure/Persistence/Configurations/InventoryItemConfiguration.cs`
|
||||
- `Infrastructure/Persistence/Configurations/StockMovementConfiguration.cs`
|
||||
- `Infrastructure/Persistence/Configurations/WarehouseConfiguration.cs`
|
||||
- `Infrastructure/Persistence/Repositories/InventoryItemRepository.cs`
|
||||
- `Infrastructure/Persistence/Repositories/StockMovementRepository.cs`
|
||||
- `Infrastructure/Services/InventoryService.cs` - سرویس اصلی (663 خط)
|
||||
- `Infrastructure/Persistence/Migrations/20251231234634_AddInventorySystem.cs`
|
||||
|
||||
#### Application Layer
|
||||
- `Application/Common/Interfaces/IInventoryService.cs` - (217 خط)
|
||||
- `Application/Common/Interfaces/Repositories/IInventoryItemRepository.cs`
|
||||
- `Application/Common/Interfaces/Repositories/IStockMovementRepository.cs`
|
||||
- `Application/Features/InventoryItems/Commands/InventoryItemCommands.cs`
|
||||
- `Application/Features/InventoryItems/Queries/InventoryItemQueries.cs`
|
||||
- `Application/Features/InventoryItems/Handlers/InventoryItemCommandHandlers.cs`
|
||||
- `Application/Features/InventoryItems/Handlers/InventoryItemQueryHandlers.cs`
|
||||
- `Application/Features/Warehouses/Commands/WarehouseCommands.cs`
|
||||
- `Application/Features/Warehouses/Queries/WarehouseQueries.cs`
|
||||
- `Application/Features/Warehouses/Handlers/WarehouseCommandHandlers.cs`
|
||||
- `Application/Features/Warehouses/Handlers/WarehouseQueryHandlers.cs`
|
||||
- `Application/Features/StockMovements/Commands/StockMovementCommands.cs`
|
||||
- `Application/Features/StockMovements/Queries/StockMovementQueries.cs`
|
||||
- `Application/Features/StockMovements/Handlers/StockMovementCommandHandlers.cs`
|
||||
- `Application/Features/StockMovements/Handlers/StockMovementQueryHandlers.cs`
|
||||
|
||||
#### gRPC Layer
|
||||
- `CMSMicroservice.Protobuf/Protos/inventory.proto` - (530 خط)
|
||||
- `WebApi/Services/InventoryService.cs` - gRPC service (235 خط)
|
||||
|
||||
### قابلیتهای اصلی:
|
||||
- ✅ مدیریت موجودی محصولات معمولی و تخفیفی
|
||||
- ✅ رزرو موجودی برای سفارشات pending
|
||||
- ✅ تایید فروش و کسر موجودی
|
||||
- ✅ برگشت کالا و افزایش موجودی
|
||||
- ✅ ورود کالا به انبار (Restock)
|
||||
- ✅ تعدیل موجودی (Adjustment)
|
||||
- ✅ ثبت ضایعات و مفقودی
|
||||
- ✅ لیست محصولات کمموجود (Low Stock)
|
||||
- ✅ تاریخچه کامل حرکات انبار
|
||||
- ✅ همگامسازی خودکار با `Product.RemainingCount`
|
||||
- ✅ پشتیبانی از چند انبار (Multi-Warehouse ready)
|
||||
|
||||
### یکپارچهسازی با Handlers:
|
||||
- ✅ `CreateProductCommandHandler` - ایجاد خودکار InventoryItem
|
||||
- ✅ `CreateDiscountProductCommandHandler` - ایجاد خودکار InventoryItem
|
||||
- ✅ `PlaceOrderCommandHandler` - رزرو موجودی
|
||||
- ✅ `CompleteOrderPaymentCommandHandler` - تایید فروش
|
||||
- ✅ `CancelOrderCommandHandler` - آزادسازی رزرو
|
||||
|
||||
### باقیمانده (نیاز به تکمیل):
|
||||
- ⬜ Migration دادههای موجود به سیستم جدید (Phase 5)
|
||||
- ⬜ تستهای واحد و یکپارچهسازی (Phase 7)
|
||||
- ⬜ UI در BackOffice (صفحات راه ندارند - فقط منو در NavMenu اضافه شده)
|
||||
|
||||
### BFF Layer:
|
||||
- ✅ `Application/ProductsCQ/Queries/GetLowStockProducts/GetLowStockProductsQuery.cs`
|
||||
- ✅ `Application/ProductsCQ/Queries/GetLowStockProducts/GetLowStockProductsQueryHandler.cs`
|
||||
|
||||
### BackOffice (Frontend):
|
||||
- ✅ منوی "انبارداری" در `NavMenu.razor` اضافه شده
|
||||
- ⬜ صفحه `/inventory/low-stock` - نیاز به ایجاد
|
||||
- ⬜ صفحه `/products/bulk-edit` - موجود ولی نیاز به بررسی
|
||||
|
||||
---
|
||||
|
||||
## 🎯 هدف
|
||||
|
||||
ایجاد یک سیستم انبارداری مرکزی که موجودی هر دو فروشگاه (معمولی و تخفیفی) را از یک نقطه مدیریت کند، با قابلیت:
|
||||
@@ -235,22 +313,22 @@ public interface IInventoryService
|
||||
|
||||
| # | تسک | فایل | وضعیت |
|
||||
|---|------|------|--------|
|
||||
| 1.1 | ایجاد `ProductType` enum | `Domain/Enums/ProductType.cs` | ⬜ |
|
||||
| 1.2 | ایجاد `StockMovementType` enum | `Domain/Enums/StockMovementType.cs` | ⬜ |
|
||||
| 1.3 | ایجاد `InventoryItem` entity | `Domain/Entities/InventoryItem.cs` | ⬜ |
|
||||
| 1.4 | ایجاد `StockMovement` entity | `Domain/Entities/StockMovement.cs` | ⬜ |
|
||||
| 1.5 | ایجاد `Warehouse` entity (اختیاری) | `Domain/Entities/Warehouse.cs` | ⬜ |
|
||||
| 1.1 | ایجاد `ProductType` enum | `Domain/Enums/ProductType.cs` | ✅ |
|
||||
| 1.2 | ایجاد `StockMovementType` enum | `Domain/Enums/StockMovementType.cs` | ✅ |
|
||||
| 1.3 | ایجاد `InventoryItem` entity | `Domain/Entities/InventoryItem.cs` | ✅ |
|
||||
| 1.4 | ایجاد `StockMovement` entity | `Domain/Entities/StockMovement.cs` | ✅ |
|
||||
| 1.5 | ایجاد `Warehouse` entity (اختیاری) | `Domain/Entities/Warehouse.cs` | ✅ |
|
||||
|
||||
#### Day 2: EF Core Configurations
|
||||
|
||||
| # | تسک | فایل | وضعیت |
|
||||
|---|------|------|--------|
|
||||
| 1.6 | ایجاد `InventoryItemConfiguration` | `Infrastructure/Data/Configurations/InventoryItemConfiguration.cs` | ⬜ |
|
||||
| 1.7 | ایجاد `StockMovementConfiguration` | `Infrastructure/Data/Configurations/StockMovementConfiguration.cs` | ⬜ |
|
||||
| 1.8 | ایجاد `WarehouseConfiguration` | `Infrastructure/Data/Configurations/WarehouseConfiguration.cs` | ⬜ |
|
||||
| 1.9 | اضافه کردن DbSet ها به `ApplicationDbContext` | `Infrastructure/Data/ApplicationDbContext.cs` | ⬜ |
|
||||
| 1.10 | ایجاد Migration | `dotnet ef migrations add AddInventorySystem` | ⬜ |
|
||||
| 1.11 | اعمال Migration | `dotnet ef database update` | ⬜ |
|
||||
| 1.6 | ایجاد `InventoryItemConfiguration` | `Infrastructure/Data/Configurations/InventoryItemConfiguration.cs` | ✅ |
|
||||
| 1.7 | ایجاد `StockMovementConfiguration` | `Infrastructure/Data/Configurations/StockMovementConfiguration.cs` | ✅ |
|
||||
| 1.8 | ایجاد `WarehouseConfiguration` | `Infrastructure/Data/Configurations/WarehouseConfiguration.cs` | ✅ |
|
||||
| 1.9 | اضافه کردن DbSet ها به `ApplicationDbContext` | `Infrastructure/Data/ApplicationDbContext.cs` | ✅ |
|
||||
| 1.10 | ایجاد Migration | `dotnet ef migrations add AddInventorySystem` | ✅ |
|
||||
| 1.11 | اعمال Migration | `dotnet ef database update` | ✅ |
|
||||
|
||||
**خروجی Phase 1:**
|
||||
- ✅ جداول `InventoryItems`, `StockMovements`, `Warehouses` در دیتابیس
|
||||
@@ -266,25 +344,25 @@ public interface IInventoryService
|
||||
|
||||
| # | تسک | فایل | وضعیت |
|
||||
|---|------|------|--------|
|
||||
| 2.1 | ایجاد `IInventoryService` interface | `Application/Common/Interfaces/IInventoryService.cs` | ⬜ |
|
||||
| 2.2 | ایجاد `InventoryService` class | `Infrastructure/Services/InventoryService.cs` | ⬜ |
|
||||
| 2.3 | پیادهسازی `InitializeInventoryAsync` | در `InventoryService.cs` | ⬜ |
|
||||
| 2.4 | پیادهسازی `GetInventoryAsync` | در `InventoryService.cs` | ⬜ |
|
||||
| 2.5 | پیادهسازی `GetAvailableQuantityAsync` | در `InventoryService.cs` | ⬜ |
|
||||
| 2.1 | ایجاد `IInventoryService` interface | `Application/Common/Interfaces/IInventoryService.cs` | ✅ |
|
||||
| 2.2 | ایجاد `InventoryService` class | `Infrastructure/Services/InventoryService.cs` | ✅ |
|
||||
| 2.3 | پیادهسازی `InitializeInventoryAsync` | در `InventoryService.cs` | ✅ |
|
||||
| 2.4 | پیادهسازی `GetInventoryAsync` | در `InventoryService.cs` | ✅ |
|
||||
| 2.5 | پیادهسازی `GetAvailableQuantityAsync` | در `InventoryService.cs` | ✅ |
|
||||
|
||||
#### Day 4: متدهای عملیاتی
|
||||
|
||||
| # | تسک | فایل | وضعیت |
|
||||
|---|------|------|--------|
|
||||
| 2.6 | پیادهسازی `AddStockAsync` | در `InventoryService.cs` | ⬜ |
|
||||
| 2.7 | پیادهسازی `AdjustStockAsync` | در `InventoryService.cs` | ⬜ |
|
||||
| 2.8 | پیادهسازی `ReserveStockAsync` | در `InventoryService.cs` | ⬜ |
|
||||
| 2.9 | پیادهسازی `ReleaseReservationAsync` | در `InventoryService.cs` | ⬜ |
|
||||
| 2.10 | پیادهسازی `ConfirmSaleAsync` | در `InventoryService.cs` | ⬜ |
|
||||
| 2.11 | پیادهسازی `ProcessReturnAsync` | در `InventoryService.cs` | ⬜ |
|
||||
| 2.12 | پیادهسازی `SyncRemainingCountAsync` (private) | در `InventoryService.cs` | ⬜ |
|
||||
| 2.13 | پیادهسازی `LogMovementAsync` (private) | در `InventoryService.cs` | ⬜ |
|
||||
| 2.14 | ثبت سرویس در DI | `Infrastructure/DependencyInjection.cs` | ⬜ |
|
||||
| 2.6 | پیادهسازی `AddStockAsync` | در `InventoryService.cs` | ✅ |
|
||||
| 2.7 | پیادهسازی `AdjustStockAsync` | در `InventoryService.cs` | ✅ |
|
||||
| 2.8 | پیادهسازی `ReserveStockAsync` | در `InventoryService.cs` | ✅ |
|
||||
| 2.9 | پیادهسازی `ReleaseReservationAsync` | در `InventoryService.cs` | ✅ |
|
||||
| 2.10 | پیادهسازی `ConfirmSaleAsync` | در `InventoryService.cs` | ✅ |
|
||||
| 2.11 | پیادهسازی `ProcessReturnAsync` | در `InventoryService.cs` | ✅ |
|
||||
| 2.12 | پیادهسازی `SyncRemainingCountAsync` (private) | در `InventoryService.cs` | ✅ |
|
||||
| 2.13 | پیادهسازی `LogMovementAsync` (private) | در `InventoryService.cs` | ✅ |
|
||||
| 2.14 | ثبت سرویس در DI | `Infrastructure/DependencyInjection.cs` | ✅ |
|
||||
|
||||
**خروجی Phase 2:**
|
||||
- ✅ `InventoryService` کامل و قابل استفاده
|
||||
@@ -300,23 +378,23 @@ public interface IInventoryService
|
||||
|
||||
| # | تسک | فایل | وضعیت |
|
||||
|---|------|------|--------|
|
||||
| 3.1 | `AddStockCommand` + Handler + Validator | `Application/Inventory/Commands/AddStock/` | ⬜ |
|
||||
| 3.2 | `AdjustStockCommand` + Handler + Validator | `Application/Inventory/Commands/AdjustStock/` | ⬜ |
|
||||
| 3.3 | `ReserveStockCommand` + Handler + Validator | `Application/Inventory/Commands/ReserveStock/` | ⬜ |
|
||||
| 3.4 | `ReleaseStockCommand` + Handler + Validator | `Application/Inventory/Commands/ReleaseStock/` | ⬜ |
|
||||
| 3.5 | `ConfirmSaleCommand` + Handler + Validator | `Application/Inventory/Commands/ConfirmSale/` | ⬜ |
|
||||
| 3.6 | `ProcessReturnCommand` + Handler + Validator | `Application/Inventory/Commands/ProcessReturn/` | ⬜ |
|
||||
| 3.7 | `BulkAdjustStockCommand` + Handler + Validator | `Application/Inventory/Commands/BulkAdjustStock/` | ⬜ |
|
||||
| 3.1 | `AddStockCommand` + Handler + Validator | `Application/Inventory/Commands/AddStock/` | ✅ |
|
||||
| 3.2 | `AdjustStockCommand` + Handler + Validator | `Application/Inventory/Commands/AdjustStock/` | ✅ |
|
||||
| 3.3 | `ReserveStockCommand` + Handler + Validator | `Application/Inventory/Commands/ReserveStock/` | ✅ |
|
||||
| 3.4 | `ReleaseStockCommand` + Handler + Validator | `Application/Inventory/Commands/ReleaseStock/` | ✅ |
|
||||
| 3.5 | `ConfirmSaleCommand` + Handler + Validator | `Application/Inventory/Commands/ConfirmSale/` | ✅ |
|
||||
| 3.6 | `ProcessReturnCommand` + Handler + Validator | `Application/Inventory/Commands/ProcessReturn/` | ✅ |
|
||||
| 3.7 | `BulkAdjustStockCommand` + Handler + Validator | `Application/Inventory/Commands/BulkAdjustStock/` | ✅ |
|
||||
|
||||
#### Day 6: Queries
|
||||
|
||||
| # | تسک | فایل | وضعیت |
|
||||
|---|------|------|--------|
|
||||
| 3.8 | `GetInventoryItemQuery` + Handler | `Application/Inventory/Queries/GetInventoryItem/` | ⬜ |
|
||||
| 3.9 | `GetInventoryItemsQuery` + Handler (با Pagination) | `Application/Inventory/Queries/GetInventoryItems/` | ⬜ |
|
||||
| 3.10 | `GetLowStockItemsQuery` + Handler | `Application/Inventory/Queries/GetLowStockItems/` | ⬜ |
|
||||
| 3.11 | `GetStockMovementsQuery` + Handler | `Application/Inventory/Queries/GetStockMovements/` | ⬜ |
|
||||
| 3.12 | `GetInventoryReportQuery` + Handler | `Application/Inventory/Queries/GetInventoryReport/` | ⬜ |
|
||||
| 3.8 | `GetInventoryItemQuery` + Handler | `Application/Inventory/Queries/GetInventoryItem/` | ✅ |
|
||||
| 3.9 | `GetInventoryItemsQuery` + Handler (با Pagination) | `Application/Inventory/Queries/GetInventoryItems/` | ✅ |
|
||||
| 3.10 | `GetLowStockItemsQuery` + Handler | `Application/Inventory/Queries/GetLowStockItems/` | ✅ |
|
||||
| 3.11 | `GetStockMovementsQuery` + Handler | `Application/Inventory/Queries/GetStockMovements/` | ✅ |
|
||||
| 3.12 | `GetInventoryReportQuery` + Handler | `Application/Inventory/Queries/GetInventoryReport/` | ✅ |
|
||||
|
||||
**خروجی Phase 3:**
|
||||
- ✅ 7 Command با Validator
|
||||
@@ -332,8 +410,8 @@ public interface IInventoryService
|
||||
|
||||
| # | تسک | توضیح | وضعیت |
|
||||
|---|------|-------|--------|
|
||||
| 4.1 | آپدیت `CreateProductCommandHandler` | اضافه کردن `InitializeInventoryAsync` | ⬜ |
|
||||
| 4.2 | آپدیت `CreateDiscountProductCommandHandler` | اضافه کردن `InitializeInventoryAsync` | ⬜ |
|
||||
| 4.1 | آپدیت `CreateProductCommandHandler` | اضافه کردن `InitializeInventoryAsync` | ✅ |
|
||||
| 4.2 | آپدیت `CreateDiscountProductCommandHandler` | اضافه کردن `InitializeInventoryAsync` | ✅ |
|
||||
| 4.3 | آپدیت `UpdateProductCommandHandler` | اضافه کردن `AdjustStockAsync` (اگر موجودی تغییر کرد) | ⬜ |
|
||||
| 4.4 | آپدیت `UpdateDiscountProductCommandHandler` | اضافه کردن `AdjustStockAsync` | ⬜ |
|
||||
| 4.5 | آپدیت `BulkUpdateProductStockCommandHandler` | استفاده از `BulkAdjustStockAsync` | ⬜ |
|
||||
@@ -342,11 +420,11 @@ public interface IInventoryService
|
||||
|
||||
| # | تسک | توضیح | وضعیت |
|
||||
|---|------|-------|--------|
|
||||
| 4.6 | آپدیت `PlaceOrderCommandHandler` | اضافه کردن `ReserveStockAsync` | ⬜ |
|
||||
| 4.7 | آپدیت `PlaceDiscountOrderCommandHandler` | اضافه کردن `ReserveStockAsync` | ⬜ |
|
||||
| 4.8 | آپدیت `CompleteOrderPaymentCommandHandler` | تغییر به `ConfirmSaleAsync` | ⬜ |
|
||||
| 4.9 | آپدیت `CompleteDiscountOrderPaymentCommandHandler` | تغییر به `ConfirmSaleAsync` | ⬜ |
|
||||
| 4.10 | آپدیت `CancelOrderCommandHandler` | اضافه کردن `ReleaseReservationAsync` | ⬜ |
|
||||
| 4.6 | آپدیت `PlaceOrderCommandHandler` | اضافه کردن `ReserveStockAsync` | ✅ |
|
||||
| 4.7 | آپدیت `PlaceDiscountOrderCommandHandler` | اضافه کردن `ReserveStockAsync` | ✅ |
|
||||
| 4.8 | آپدیت `CompleteOrderPaymentCommandHandler` | تغییر به `ConfirmSaleAsync` | ✅ |
|
||||
| 4.9 | آپدیت `CompleteDiscountOrderPaymentCommandHandler` | تغییر به `ConfirmSaleAsync` | ✅ |
|
||||
| 4.10 | آپدیت `CancelOrderCommandHandler` | اضافه کردن `ReleaseReservationAsync` | ✅ |
|
||||
| 4.11 | آپدیت `CancelDiscountOrderCommandHandler` | اضافه کردن `ReleaseReservationAsync` | ⬜ |
|
||||
|
||||
**خروجی Phase 4:**
|
||||
@@ -396,11 +474,11 @@ WHERE NOT EXISTS (SELECT 1 FROM InventoryItems WHERE DiscountProductId = Discoun
|
||||
|
||||
| # | تسک | فایل | وضعیت |
|
||||
|---|------|------|--------|
|
||||
| 6.1 | ایجاد `inventory.proto` | `Protobufs/inventory.proto` | ⬜ |
|
||||
| 6.2 | کامپایل Proto | `pack-protos.sh` | ⬜ |
|
||||
| 6.3 | ایجاد `InventoryService.cs` در WebApi | `WebApi/Services/InventoryService.cs` | ⬜ |
|
||||
| 6.4 | ایجاد Mapping Profile | `Application/Common/Mappings/InventoryMappingProfile.cs` | ⬜ |
|
||||
| 6.5 | ثبت سرویس gRPC در `Program.cs` | `WebApi/Program.cs` | ⬜ |
|
||||
| 6.1 | ایجاد `inventory.proto` | `Protobufs/inventory.proto` | ✅ |
|
||||
| 6.2 | کامپایل Proto | `pack-protos.sh` | ✅ |
|
||||
| 6.3 | ایجاد `InventoryService.cs` در WebApi | `WebApi/Services/InventoryService.cs` | ✅ |
|
||||
| 6.4 | ایجاد Mapping Profile | `Application/Common/Mappings/InventoryMappingProfile.cs` | ✅ |
|
||||
| 6.5 | ثبت سرویس gRPC در `Program.cs` | `WebApi/Program.cs` | ✅ |
|
||||
|
||||
```protobuf
|
||||
// inventory.proto
|
||||
|
||||
Reference in New Issue
Block a user