# MES **Repository Path**: weibob/mes ## Basic Information - **Project Name**: MES - **Description**: No description available - **Primary Language**: C# - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-20 - **Last Updated**: 2026-08-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 物联网智能 MES 生产管理系统 > .NET 8 微服务 + Vue 3 + TypeScript + MySQL 8 > 参照 SilkychinaWMS 架构:每个业务服务 4 层拆分(Common / Domain / Infrastructure / WebAPI) ## 分工 | 成员 | 服务 | 端口 | 数据库 | 工单模块 | |---|---|---|---|---| | **A** | MES.Basic.WebAPI | 5101 | mes_basic | 01-BOM · 12-供应商 · 13-客户 · 14-MCP 天气 | | **B** | MES.Production.WebAPI | 5102 | mes_production | 11-生产计划 · 09-生产工单 · 06-工序 · 10-质检 | | **C** | MES.Purchase.WebAPI | 5103 | mes_purchase | 04-采购订单 · 05-到货检验 · 07-开票到票 · 08-审批 | | **D** | MES.Dashboard.WebAPI | 5104 | mes_dashboard | 02-工作台 · 03-报表看板 · 15-LangChain 智能客服 | | 共用 | MES.Identity.WebAPI | 5100 | mes_identity | 登录/JWT/用户 | | 共用 | ServiceManagement.Gateway | 5000 | - | YARP 网关 | ## 目录结构(参照 WMS) ``` MES/ ├── ui/ Vue 前端 └── backend/ ├── MES.sln 解决方案(6 个 Solution Folder,21 个项目) ├── Directory.Build.props 统一 net8.0 + XML 注释 ├── db/init.sql 5 个库 + 全部业务表 │ ├── MES.Identity.Common/ 共用工具类 ├── MES.Identity.Domain/ 实体 + DTO + ApiResult ├── MES.Identity.Infrastructure/ DbContext + Repository + IServers/Servers ├── MES.Identity.WebAPI/ Controllers + Program.cs + appsettings │ ├── MES.Basic.{Common,Domain,Infrastructure,WebAPI}/ A 负责 ├── MES.Production.{Common,Domain,Infrastructure,WebAPI}/ B 负责 ├── MES.Purchase.{Common,Domain,Infrastructure,WebAPI}/ C 负责 ├── MES.Dashboard.{Common,Domain,Infrastructure,WebAPI}/ D 负责 │ └── ServiceManagement.Gateway/ YARP 网关 ``` ## 每个模块的 4 层职责(和 WMS 一致) | 层 | 职责 | 包含内容 | |---|---|---| | **Common** | 工具类 | JwtTokenHelper / PasswordHelper / PageResult | | **Domain** | 领域模型 | Entities(实体)/ Dtos / ApiResult / ApiCode | | **Infrastructure** | 数据访问 | DbContext / IRepository / Repository / IServers / Servers / Migrations | | **WebAPI** | 接口入口 | Program.cs / Controllers / appsettings.json | **引用关系**: - Domain / Common — 无引用 - Infrastructure → Common + Domain - WebAPI → Common + Domain + Infrastructure ## 快速开始 ### 1. 初始化数据库 ```powershell mysql -uroot -p123456 < backend\db\init.sql ``` ### 2. 启动后端 ```powershell cd D:\学习办公\学习\实训二\MES\backend dotnet restore dotnet build # 各自启动 dotnet run --project ServiceManagement.Gateway # 5000 网关 dotnet run --project MES.Identity.WebAPI # 5100 登录 dotnet run --project MES.Basic.WebAPI # 5101 A dotnet run --project MES.Production.WebAPI # 5102 B dotnet run --project MES.Purchase.WebAPI # 5103 C dotnet run --project MES.Dashboard.WebAPI # 5104 D ``` 浏览器打开 `http://localhost:5101`(自动跳转 Swagger)。 ### 3. 前端 ```powershell cd ui npm i npm run dev ``` ## 演示账号 | 账号 | 密码 | 角色 | |---|---|---| | admin | 123456 | 超级管理员 | | zhang | 123456 | 生产经理 | | lee | 123456 | 质检员 | 密码 = `SHA256("123456")`,与 `PasswordHelper.Hash` 一致。 ## 关键设计 ### 1. JWT 密钥从 appsettings 读取,不硬编码 ```json "Jwt": { "SecretKey": "mes-super-secret-key-please-change-this-..." } ``` Program.cs 里启动时校验空值。 ### 2. Service 接口按模块聚合,不拆碎 ```csharp public interface IBomServers { Task<...> ListAsync(...); Task<...> TreeAsync(...); Task<...> AddAsync(...); Task<...> EditAsync(...); } // 不这么拆: IBomAddServers/IBomEditServers/IBomListServers ... ``` 一个业务模块一个 `IXxxServers`,方法按 CRUD/业务动作聚合。 ### 3. EF Core Migrations 规范 - **每个服务自己建表**(4 个数据库互不干扰) - 生成迁移: ```powershell cd backend\MES.Basic.Infrastructure dotnet ef migrations add InitBom -s ..\MES.Basic.WebAPI dotnet ef database update -s ..\MES.Basic.WebAPI ``` - **阶段性清理临时迁移**(add BomV1 / add BomV2 → 合成 1 个 InitBom) ## 各自要写的东西(接下来的工作) 按 Identity 服务的写法照抄: ### Common - 需要的 Helper(可选) - Models(可选,通用分页已在通用 Common 里) ### Domain - Entities/*.cs — 实体类(表已在 init.sql 建好,写 C# 类对应) - Dtos/*.cs — 请求/响应 DTO - Common/ApiResult.cs & ApiCode.cs 已生成 ### Infrastructure - XxxDbContext.cs — 参照 IdentityDbContext - IRepository/ + Repository/ — 通用泛型仓储(可复制 Identity 的) - IServers/IXxxServers.cs — 业务接口 - Servers/XxxServers.cs — 业务实现 ### WebAPI - Program.cs 骨架已生成,你补: - `builder.Services.AddDbContext(...)` - `builder.Services.AddScoped(typeof(IXxxRepository<>), typeof(XxxRepository<>))` - `builder.Services.AddScoped()` - Controllers/*.cs — API 端点