This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
LB_PdaService (蓝宝PDA后台) is a .NET 8 Web API service for PDA (Personal Digital Assistant) backend operations in a MES (Manufacturing Execution System). The service provides REST APIs for warehouse management, production order management, quality control, and ERP integration.
# Restore dependencies
dotnet restore
# Build the project
dotnet build NewPdaSqlServer.csproj -c Debug
# Run in development (watches appsettings.Development.json)
dotnet run --project NewPdaSqlServer.csproj --launch-profile Development
# Format code before committing
dotnet format
# Publish for production
dotnet publish -c Release -o bin/Publish/net8.0
Development server runs on https://localhost:5001 with Swagger at /swagger.
The application follows a layered architecture with direct SQL access (no ORM):
HTTP Request → Controllers/ → service/ → DbHelperSQL → SQL Server
↓
RequestInfo (scoped)
Key insights:
- RequestInfo is injected via BaseController as a scoped service in DI (see Startup.cs:33). All controllers inherit from BaseController to access request context.
- RequestInfo is a DynamicObject that extracts HTTP headers (like OrgId) and stores them as dynamic properties for use throughout the request lifecycle.
- DbHelperSQL is a static utility class in util/ that wraps ADO.NET for direct SQL Server access via System.Data.SqlClient.
BaseController.cs: Provides scoped RequestInfo access to all controllersbase/: Shared endpoints like WmsBaseController.csservice/: Business logic following manager pattern
MesWarehouseManager, MesQcManager, etc.service/base/ (e.g., LoginService.cs, MesDepotsManager.cs)entity/: Data models organized by domain
Base/: Shared entities like RequestInfoDto/: Request/response transfer objects
util/: Core utilities
DbHelperSQL.cs: Static helper for SQL execution with parameterized queries, transactions, and stored procedure callsResponseResult.cs: Unified response wrapper (status: 0=success, 1=error)AppsettingsUtility.cs: Configuration initializationAppSettings.cs: Configuration containerBillNo.cs: Sequential number generationLogUtil.cs: Logging helperUserUtil.cs, StringUtil.cs, CollectionUtil.cs: Common utilitiesDirect ADO.NET via DbHelperSQL static methods:
- Query execution: DbHelperSQL.Query(sql) returns DataSet
- Scalar: DbHelperSQL.GetSingle(sql) returns object
- Execute: DbHelperSQL.ExecuteSql(sql) returns affected rows
- Transactions: DbHelperSQL.ExecuteSqlTran(Hashtable) for multi-statement ACID operations
- Stored procedures: DbHelperSQL.RunProcedure() and variants
All methods support parameterized queries via SqlParameter[] to prevent SQL injection.
RequestInfo injected as scoped service (line 33)HttpContextAccessor registered to enable RequestInfo header extractionappsettings.json / appsettings.Development.json:
AppSettings:DataBaseConn: SQL Server connection string (accessed by DbHelperSQL)AppSettings:TestErpUrl and AppSettings:ProductionErpUrl: ERP WebService endpointsdotnet user-secrets in development to avoid committing sensitive connection stringsProgram.cs: Standard .NET 8 entry point using Host.CreateDefaultBuilder() with Startup class
Key NuGet Dependencies (from NewPdaSqlServer.csproj):
SqlSugarCore 5.1.4.169: Referenced but not actively used; DbHelperSQL handles data accessSystem.Data.SqlClient 4.8.6: ADO.NET provider for SQL ServerMicrosoft.AspNetCore.Mvc.NewtonsoftJson 8.0.8: JSON serializationSwashbuckle.AspNetCore 6.8.0: Swagger/OpenAPI documentationMasuit.Tools.Core 2024.5.8: Utility libraryPortable.BouncyCastle 1.9.0: Cryptography supportControllers/[Domain]/[Entity]Controller.csBaseControllerRequestInfo propertyservice/Mes[Entity]Manager.csDbHelperSQL.Query() or DbHelperSQL.ExecuteSql() for data accessUse ResponseResult for all responses:
csharp return new ResponseResult { status = 0, data = result };
Return Task<ResponseResult> for async endpoints
Always use parameterized queries to prevent SQL injection:
var param = new[] {
new SqlParameter("@id", id),
new SqlParameter("@name", name)
};
var ds = DbHelperSQL.Query("SELECT * FROM Table WHERE id=@id AND name=@name", param);
Use ResponseResult.ResponseError(exception) for exception wrapping:
catch (Exception ex)
{
return ResponseResult.ResponseError(ex);
}
Controller to controller classesTask/Task<T> must end with Async suffix; never use async void except event hooksdotnet format before committingNo automated test framework currently wired into the solution. To add testing:
1. Create Tests/ directory and add xUnit project
2. Name test files <Feature>Tests.cs with methods named Method_Scenario_ExpectedResult
3. Run with dotnet test
4. Reference tests in PR descriptions with coverage notes
Controllers are organized into these business domains:
MesInvItemInCDetailsController, MesDbckController, TransferOutControllerIpqcController, LljController, OaToMesControllerMesWorkProdController, WomdaaController, WwGdControllerWmsBaseController, MesDepotsController, MessageCenterControllerDbHelperSQL) instead of modern ORM—SqlSugarCore is referenced but not actively useddotnet user-secrets instead)