tjx
2025-11-05 682e7301250701c55c0f645d8de849cc4663d8e8
CLAUDE.md
@@ -24,10 +24,12 @@
### Database Layer
- Uses **SqlSugar ORM** for data access with Oracle database
- Connection string configured in `appsettings.json`
- Two database contexts available:
  - `DbContext<T>` (MES.Service/DB/DbContext.cs:10) - Generic repository pattern
  - `SqlSugarHelper` (MES.Service/DB/SqlSugarHelper.cs:6) - Oracle-specific helper with transaction support
- Connection string configured in `appsettings.json` and loaded via `AppsettingsUtility.Settings.DataBaseConn`
- Three database access patterns available:
  - `Repository<T>` (MES.Service/DB/Repository.cs:6) - Base class for all Manager classes, extends SqlSugar's SimpleClient with Oracle configuration and transaction support via `UseTransaction()` method
  - `DbContext<T>` (MES.Service/DB/DbContext.cs:10) - Generic repository pattern for SqlServer (legacy, not actively used)
  - `SqlSugarHelper` (MES.Service/DB/SqlSugarHelper.cs:6) - Static Oracle helper with `GetInstance()` and `UseTransactionWithOracle()` methods
- **IMPORTANT**: Most services inherit from `Repository<T>`, which provides pre-configured Oracle connection and built-in transaction management
### Service Layer Structure
- **BasicData**: Core business entities (customers, items, suppliers, etc.)
@@ -38,11 +40,13 @@
  - `webApi/`: External API DTOs for ERP integration
### API Layer
- ASP.NET Core Web API with Swagger documentation
- Controllers organized by domain (BasicData, QC, Warehouse)
- Newtonsoft.Json for serialization with camelCase naming
- ASP.NET Core Web API with Swagger documentation (available in Development mode)
- Controllers organized by domain (BasicData, QC, Warehouse, FBSDB)
- Newtonsoft.Json for serialization with camelCase naming (configured in Startup.cs:46)
- CORS enabled for cross-origin requests
- Custom ActionFilter for request/response handling
- Custom ActionFilter (MESApplication/Filter/ActionFilter.cs) for global request/response logging
- All endpoints use `[HttpPost]` by convention, even for read operations
- Route pattern: `api/[controller]/[action]`
## Common Development Commands
@@ -89,19 +93,54 @@
## Important Patterns
### Repository Pattern
Most business logic follows the Manager pattern:
- Managers in `MES.Service/service/` handle business operations
- Controllers in `MESApplication/Controllers/` handle HTTP requests
- Models in `MES.Service/Modes/` represent database entities
All business logic follows the Manager pattern with inheritance-based repository access:
- **Managers** in `MES.Service/service/` inherit from `Repository<T>` and handle business operations
  - Example: `MesCustomerManager : Repository<MesCustomer>` (47 Manager classes total)
  - Managers use `UseTransaction(db => {...})` for transactional operations
  - Directly access SqlSugar methods via inherited SimpleClient functionality
- **Controllers** in `MESApplication/Controllers/` handle HTTP requests and instantiate Manager classes
  - Controllers manually create Manager instances (e.g., `new MesCustomerManager()`)
  - Use `ResponseResult` utility class for standardized API responses
  - Controllers wrap Manager calls in try-catch blocks and log to MessageCenter
- **Models** in `MES.Service/Modes/` represent database entities with SqlSugar attributes
### Service Registration
Services are manually instantiated rather than using dependency injection containers. When adding new services, follow the existing pattern in the respective Manager classes.
### Service Registration and Response Format
Services are manually instantiated rather than using dependency injection containers:
- Controllers directly instantiate Managers: `private readonly MesCustomerManager m = new();`
- Startup.cs configures `AppSettings` from appsettings.json into static `AppsettingsUtility.Settings`
- No DI container for business logic - all service creation is explicit
All API endpoints return `ResponseResult` (MES.Service/util/ResponseResult.cs:7) with structure:
```csharp
{
  status: 0,        // 0 = success, 1 = failure
  message: "OK",    // error message or "OK"
  data: object,     // response payload wrapped in ExpandoObject
  TotalCount: 0     // optional pagination count
}
```
### Error Handling
- ActionFilter handles global request/response processing
- SQL logging enabled via SqlSugar AOP for debugging
- Console output for SQL query debugging
- `ActionFilter` (MESApplication/Filter/ActionFilter.cs:13) handles global request/response processing
  - Logs all requests with headers and body parameters
  - Logs all responses with execution time
  - Catches exceptions and logs via `ErrorLog.Write()`
- SQL logging enabled via SqlSugar AOP for debugging (prints to Console)
- All Controller methods catch exceptions and return `ResponseResult.ResponseError(ex)`
- ERP integration operations logged to `MessageCenter` table with status tracking
## API Documentation
API documentation is available in the `MESApplication/Docs/` folder:
- `Spi_API.md` - SPI (Solder Paste Inspection) API documentation
- `Aoi_API.md` - AOI (Automated Optical Inspection) API documentation
## Testing
No test projects are currently configured in this solution. When adding tests, create separate test projects following .NET testing conventions.
No test projects are currently configured in this solution. When adding tests, create separate test projects following .NET testing conventions.
## Key Utilities
- `AppsettingsUtility` (MES.Service/util/AppsettingsUtility.cs:6) - Loads configuration into static `Settings` property
- `ResponseResult` (MES.Service/util/ResponseResult.cs:7) - Standardized API response wrapper
- `ErrorLog` - Custom error logging utility used by ActionFilter