This commit is contained in:
2025-07-15 13:21:34 +08:00
parent 807004f78d
commit 83bf9aea7d
44 changed files with 9798 additions and 8 deletions

View File

@@ -0,0 +1,953 @@
# DDD代码生成器可视化界面策划方案
## 概述
DDD代码生成器可视化界面是一个基于Web的图形化工具提供直观的拖拽式界面来设计和生成DDD架构代码。通过可视化界面用户可以更轻松地设计领域模型、配置实体关系、预览生成的代码大幅降低DDD架构的学习和使用门槛。
## 界面架构
### 1. 整体布局
```
┌─────────────────────────────────────────────────────────────┐
│ DDD代码生成器 │
├─────────────────────────────────────────────────────────────┤
│ 导航栏: [项目] [领域] [实体] [服务] [API] [配置] [生成] │
├─────────────────────────────────────────────────────────────┤
│ 工具栏: [新建] [打开] [保存] [导入] [导出] [预览] [生成] │
├─────────────────────────────────────────────────────────────┤
│ 左侧面板 │ 主工作区 │ 右侧面板 │
│ ├─ 项目树 │ ├─ 可视化设计器 │ ├─ 属性面板 │
│ ├─ 组件库 │ ├─ 关系图 │ ├─ 代码预览 │
│ └─ 模板库 │ └─ 配置表单 │ └─ 日志面板 │
└─────────────────────────────────────────────────────────────┘
```
### 2. 核心界面组件
#### 2.1 导航栏
- **项目管理**: 项目列表、新建项目、项目设置
- **领域设计**: 领域列表、领域配置、领域关系
- **实体管理**: 实体设计器、字段配置、业务方法
- **服务配置**: 应用服务、领域服务、仓储配置
- **API设计**: 接口设计、路由配置、响应格式
- **代码生成**: 生成配置、预览、导出
#### 2.2 左侧面板
- **项目树**: 显示项目结构和文件组织
- **组件库**: 拖拽式组件实体、枚举、服务、API
- **模板库**: 预定义模板和自定义模板
#### 2.3 主工作区
- **可视化设计器**: 拖拽式界面设计
- **关系图**: 实体间关系可视化
- **配置表单**: 详细的配置选项
#### 2.4 右侧面板
- **属性面板**: 选中元素的属性编辑
- **代码预览**: 实时预览生成的代码
- **日志面板**: 操作日志和错误信息
## 功能模块
### 1. 项目管理系统
#### 1.1 项目创建向导
```
┌─────────────────────────────────────────┐
│ 新建项目向导 │
├─────────────────────────────────────────┤
│ 步骤 1: 项目基本信息 │
│ ┌─────────────────────────────────────┐ │
│ │ 项目名称: [tyapi-server ] │ │
│ │ 模块路径: [tyapi-server/internal] │ │
│ │ 作者: [开发团队 ] │ │
│ │ 版本: [1.0.0 ] │ │
│ └─────────────────────────────────────┘ │
│ │
│ 步骤 2: 项目结构选择 │
│ ┌─────────────────────────────────────┐ │
│ │ ☑ 标准DDD结构 │ │
│ │ ☑ 包含认证模块 │ │
│ │ ☑ 包含日志系统 │ │
│ │ ☑ 包含测试框架 │ │
│ └─────────────────────────────────────┘ │
│ │
│ 步骤 3: 模板选择 │
│ ┌─────────────────────────────────────┐ │
│ │ ☑ 中文注释模板 │ │
│ │ ☑ RESTful API模板 │ │
│ │ ☑ Swagger文档模板 │ │
│ └─────────────────────────────────────┘ │
│ │
│ [上一步] [下一步] [完成] │
└─────────────────────────────────────────┘
```
#### 1.2 项目仪表板
```
┌─────────────────────────────────────────┐
│ 项目仪表板 │
├─────────────────────────────────────────┤
│ 项目概览 │
│ ┌─────────────┬─────────────┬─────────┐ │
│ │ 领域数量 │ 实体数量 │ API数量 │ │
│ │ 3 │ 12 │ 24 │ │
│ └─────────────┴─────────────┴─────────┘ │
│ │
│ 最近活动 │
│ • 2024-01-15 14:30 创建用户域 │
│ • 2024-01-15 14:25 添加产品实体 │
│ • 2024-01-15 14:20 生成订单API │
│ │
│ 快速操作 │
│ [新建领域] [导入配置] [生成代码] [导出] │
└─────────────────────────────────────────┘
```
### 2. 领域设计器
#### 2.1 领域概览
```
┌─────────────────────────────────────────┐
│ 领域设计器 │
├─────────────────────────────────────────┤
│ 领域列表 │
│ ┌─────────────────────────────────────┐ │
│ │ 📁 用户域 (user) │ │
│ │ ├─ 👤 用户实体 (3个字段) │ │
│ │ ├─ 🔐 角色实体 (2个字段) │ │
│ │ └─ 🛡️ 权限实体 (2个字段) │ │
│ │ │ │
│ │ 📁 产品域 (product) │ │
│ │ ├─ 📦 产品实体 (5个字段) │ │
│ │ ├─ 🏷️ 分类实体 (3个字段) │ │
│ │ └─ 📄 文档实体 (4个字段) │ │
│ │ │ │
│ │ 📁 订单域 (order) │ │
│ │ ├─ 🛒 订单实体 (6个字段) │ │
│ │ └─ 📋 订单项实体 (4个字段) │ │
│ └─────────────────────────────────────┘ │
│ │
│ [新建领域] [编辑领域] [删除领域] │
└─────────────────────────────────────────┘
```
#### 2.2 领域关系图
```
┌─────────────────────────────────────────┐
│ 领域关系图 │
├─────────────────────────────────────────┤
│ │
│ ┌─────────┐ ┌─────────┐ │
│ │ 用户域 │ │ 产品域 │ │
│ │ │ │ │ │
│ │ ┌─────┐ │ │ ┌─────┐ │ │
│ │ │用户 │ │ │ │产品 │ │ │
│ │ └─────┘ │ │ └─────┘ │ │
│ │ │ │ │ │ │ │
│ │ ┌─────┐ │ │ ┌─────┐ │ │
│ │ │角色 │ │ │ │分类 │ │ │
│ │ └─────┘ │ │ └─────┘ │ │
│ └─────────┘ └─────────┘ │
│ │ │ │
│ └────────────────┘ │
│ │ │
│ ┌─────────┐ │
│ │ 订单域 │ │
│ │ │ │
│ │ ┌─────┐ │ │
│ │ │订单 │ │ │
│ │ └─────┘ │ │
│ │ │ │ │
│ │ ┌─────┐ │ │
│ │ │订单项│ │ │
│ │ └─────┘ │ │
│ └─────────┘ │
│ │
│ [添加关系] [编辑关系] [删除关系] │
└─────────────────────────────────────────┘
```
### 3. 实体设计器
#### 3.1 实体可视化设计
```
┌─────────────────────────────────────────┐
│ 实体设计器 │
├─────────────────────────────────────────┤
│ 实体: 用户 (User) │
│ ┌─────────────────────────────────────┐ │
│ │ ┌─────────────────────────────────┐ │ │
│ │ │ 用户实体 │ │ │
│ │ ├─────────────────────────────────┤ │ │
│ │ │ ID string (主键) │ │ │
│ │ │ Username string (唯一) │ │ │
│ │ │ Email string (唯一) │ │ │
│ │ │ Password string (密码) │ │ │
│ │ │ Status UserStatus (状态) │ │ │
│ │ │ CreatedAt time.Time (创建时间) │ │ │
│ │ │ UpdatedAt time.Time (更新时间) │ │ │
│ │ │ DeletedAt gorm.DeletedAt │ │ │
│ │ └─────────────────────────────────┘ │ │
│ └─────────────────────────────────────┘ │
│ │
│ 业务方法 │
│ ┌─────────────────────────────────────┐ │
│ │ ☑ IsActive() bool │ │
│ │ ☑ CanLogin() bool │ │
│ │ ☑ IsDeleted() bool │ │
│ │ ☑ Enable() │ │
│ │ ☑ Disable() │ │
│ └─────────────────────────────────────┘ │
│ │
│ [添加字段] [编辑字段] [删除字段] │
│ [添加方法] [编辑方法] [删除方法] │
└─────────────────────────────────────────┘
```
#### 3.2 字段配置面板
```
┌─────────────────────────────────────────┐
│ 字段配置 │
├─────────────────────────────────────────┤
│ 字段名称: [Username ] │
│ 字段类型: [string ▼] │
│ 字段标签: [gorm:"type:varchar(50);uniqueIndex;not null"] │
│ 字段注释: [用户名] │
│ │
│ 验证规则 │
│ ┌─────────────────────────────────────┐ │
│ │ ☑ required (必填) │ │
│ │ ☑ min=3 (最小长度3) │ │
│ │ ☑ max=50 (最大长度50) │ │
│ │ ☑ unique (唯一性) │ │
│ │ ☑ pattern=^[a-zA-Z0-9_]+$ (正则) │ │
│ └─────────────────────────────────────┘ │
│ │
│ 数据库配置 │
│ ┌─────────────────────────────────────┐ │
│ │ 类型: varchar(50) │ │
│ │ 索引: ☑ 普通索引 ☑ 唯一索引 │ │
│ │ 约束: ☑ NOT NULL ☑ 默认值 │ │
│ │ 默认值: [ ] │ │
│ └─────────────────────────────────────┘ │
│ │
│ [保存] [取消] [预览代码] │
└─────────────────────────────────────────┘
```
### 4. 服务配置器
#### 4.1 应用服务设计
```
┌─────────────────────────────────────────┐
│ 应用服务配置 │
├─────────────────────────────────────────┤
│ 服务: 用户应用服务 (UserApplicationService) │
│ ┌─────────────────────────────────────┐ │
│ │ 基础CRUD操作 │ │
│ │ ☑ CreateUser (创建用户) │ │
│ │ ☑ UpdateUser (更新用户) │ │
│ │ ☑ DeleteUser (删除用户) │ │
│ │ ☑ GetUserByID (获取用户) │ │
│ │ ☑ ListUsers (用户列表) │ │
│ │ │ │
│ │ 业务操作 │ │
│ │ ☑ EnableUser (启用用户) │ │
│ │ ☑ DisableUser (禁用用户) │ │
│ │ ☑ ResetPassword (重置密码) │ │
│ │ ☑ ChangeStatus (修改状态) │ │
│ │ │ │
│ │ 统计功能 │ │
│ │ ☑ GetUserStats (用户统计) │ │
│ │ ☑ GetUserCount (用户数量) │ │
│ └─────────────────────────────────────┘ │
│ │
│ DTO配置 │
│ ┌─────────────────────────────────────┐ │
│ │ 命令DTO: ☑ CreateUserCommand │ │
│ │ 查询DTO: ☑ GetUserQuery │ │
│ │ 响应DTO: ☑ UserInfoResponse │ │
│ │ 列表DTO: ☑ UserListResponse │ │
│ └─────────────────────────────────────┘ │
│ │
│ [添加方法] [编辑方法] [删除方法] │
└─────────────────────────────────────────┘
```
### 5. API设计器
#### 5.1 接口设计
```
┌─────────────────────────────────────────┐
│ API接口设计 │
├─────────────────────────────────────────┤
│ 接口列表 │
│ ┌─────────────────────────────────────┐ │
│ │ GET /api/v1/users │ │
│ │ POST /api/v1/users │ │
│ │ GET /api/v1/users/:id │ │
│ │ PUT /api/v1/users/:id │ │
│ │ DELETE /api/v1/users/:id │ │
│ │ POST /api/v1/users/:id/enable │ │
│ │ POST /api/v1/users/:id/disable │ │
│ │ GET /api/v1/users/stats │ │
│ └─────────────────────────────────────┘ │
│ │
│ 接口详情 │
│ ┌─────────────────────────────────────┐ │
│ │ 路径: /api/v1/users │ │
│ │ 方法: GET │ │
│ │ 处理器: ListUsers │ │
│ │ 描述: 获取用户列表 │ │
│ │ │ │
│ │ 查询参数: │ │
│ │ • page (int) - 页码 │ │
│ │ • page_size (int) - 每页数量 │ │
│ │ • status (string) - 状态筛选 │ │
│ │ • sort_by (string) - 排序字段 │ │
│ │ │ │
│ │ 响应格式: │ │
│ │ • 200: UserListResponse │ │
│ │ • 400: ErrorResponse │ │
│ │ • 500: ErrorResponse │ │
│ └─────────────────────────────────────┘ │
│ │
│ [添加接口] [编辑接口] [删除接口] │
└─────────────────────────────────────────┘
```
### 6. 代码预览器
#### 6.1 实时代码预览
```
┌─────────────────────────────────────────┐
│ 代码预览 │
├─────────────────────────────────────────┤
│ 文件类型: [实体 ▼] [仓储] [服务] [API] │
│ ┌─────────────────────────────────────┐ │
│ │ // 用户实体 │ │
│ │ package entities │ │
│ │ │ │
│ │ import ( │ │
│ │ "time" │ │
│ │ "gorm.io/gorm" │ │
│ │ ) │ │
│ │ │ │
│ │ // User 用户实体 │ │
│ │ type User struct { │ │
│ │ ID string `gorm:"primaryKey;type:varchar(36)" comment:"用户ID"` │
│ │ Username string `gorm:"type:varchar(50);uniqueIndex;not null" comment:"用户名"` │
│ │ Email string `gorm:"type:varchar(100);uniqueIndex;not null" comment:"邮箱"` │
│ │ Password string `gorm:"type:varchar(255);not null" comment:"密码"` │
│ │ Status UserStatus `gorm:"type:varchar(20);default:'active'" comment:"用户状态"` │
│ │ CreatedAt time.Time `gorm:"autoCreateTime" comment:"创建时间"` │
│ │ UpdatedAt time.Time `gorm:"autoUpdateTime" comment:"更新时间"` │
│ │ DeletedAt gorm.DeletedAt `gorm:"index" comment:"软删除时间"` │
│ │ } │ │
│ │ │ │
│ │ // 业务方法 │ │
│ │ func (u *User) IsActive() bool { │ │
│ │ return u.Status == UserStatusActive │
│ │ } │ │
│ │ │ │
│ │ func (u *User) CanLogin() bool { │ │
│ │ return u.IsActive() && !u.IsDeleted() │
│ │ } │ │
│ └─────────────────────────────────────┘ │
│ │
│ [复制代码] [下载文件] [格式化] [语法检查] │
└─────────────────────────────────────────┘
```
### 7. 生成配置器
#### 7.1 生成选项配置
```
┌─────────────────────────────────────────┐
│ 生成配置 │
├─────────────────────────────────────────┤
│ 生成选项 │
│ ┌─────────────────────────────────────┐ │
│ │ ☑ 生成实体文件 │ │
│ │ ☑ 生成仓储接口和实现 │ │
│ │ ☑ 生成应用服务 │ │
│ │ ☑ 生成DTO对象 │ │
│ │ ☑ 生成HTTP处理器 │ │
│ │ ☑ 生成路由配置 │ │
│ │ ☑ 生成单元测试 │ │
│ │ ☑ 生成集成测试 │ │
│ │ ☑ 生成API文档 │ │
│ │ ☑ 更新依赖注入配置 │ │
│ └─────────────────────────────────────┘ │
│ │
│ 输出配置 │
│ ┌─────────────────────────────────────┐ │
│ │ 输出目录: [./internal ] │ │
│ │ 备份文件: ☑ 是 ☐ 否 │ │
│ │ 格式化代码: ☑ 是 ☐ 否 │ │
│ │ 运行测试: ☑ 是 ☐ 否 │ │
│ │ 语法检查: ☑ 是 ☐ 否 │ │
│ └─────────────────────────────────────┘ │
│ │
│ 模板配置 │
│ ┌─────────────────────────────────────┐ │
│ │ 语言: [中文 ▼] [英文] │ │
│ │ 风格: [标准 ▼] [简洁] [详细] │ │
│ │ 注释风格: [中文 ▼] [英文] [混合] │ │
│ │ 错误处理: [统一 ▼] [详细] [简洁] │ │
│ └─────────────────────────────────────┘ │
│ │
│ [生成代码] [预览生成] [保存配置] │
└─────────────────────────────────────────┘
```
## 技术实现
### 1. 前端技术栈
#### 1.1 核心框架
```javascript
// 技术栈选择
- React 18 + TypeScript
- Vite (构建工具)
- Tailwind CSS (样式框架)
- Zustand (状态管理)
- React Router (路由管理)
```
#### 1.2 UI组件库
```javascript
// 组件库
- Ant Design / Element Plus
- React Flow (流程图)
- Monaco Editor (代码编辑器)
- React DnD (拖拽功能)
- React Hook Form (表单管理)
```
#### 1.3 可视化库
```javascript
// 可视化组件
- D3.js (数据可视化)
- React Flow (流程图)
- Vis.js (关系图)
- Chart.js (图表)
```
### 2. 后端技术栈
#### 2.1 API服务
```go
// 后端技术栈
- Gin (Web框架)
- GORM (数据库ORM)
- JWT (认证)
- Swagger (API文档)
- WebSocket (实时通信)
```
#### 2.2 代码生成引擎
```go
// 生成引擎
- Go Template (模板引擎)
- AST (代码分析)
- File System (文件操作)
- Git (版本控制)
```
### 3. 数据存储
#### 3.1 数据库设计
```sql
-- 项目表
CREATE TABLE projects (
id VARCHAR(36) PRIMARY KEY,
name VARCHAR(100) NOT NULL,
module_path VARCHAR(200) NOT NULL,
author VARCHAR(100),
version VARCHAR(20),
config JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 领域表
CREATE TABLE domains (
id VARCHAR(36) PRIMARY KEY,
project_id VARCHAR(36) NOT NULL,
name VARCHAR(50) NOT NULL,
description TEXT,
config JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES projects(id)
);
-- 实体表
CREATE TABLE entities (
id VARCHAR(36) PRIMARY KEY,
domain_id VARCHAR(36) NOT NULL,
name VARCHAR(50) NOT NULL,
description TEXT,
fields JSON,
methods JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (domain_id) REFERENCES domains(id)
);
-- 服务表
CREATE TABLE services (
id VARCHAR(36) PRIMARY KEY,
domain_id VARCHAR(36) NOT NULL,
name VARCHAR(50) NOT NULL,
type ENUM('application', 'domain', 'infrastructure'),
methods JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (domain_id) REFERENCES domains(id)
);
-- API表
CREATE TABLE apis (
id VARCHAR(36) PRIMARY KEY,
domain_id VARCHAR(36) NOT NULL,
path VARCHAR(200) NOT NULL,
method VARCHAR(10) NOT NULL,
handler VARCHAR(100),
summary TEXT,
config JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (domain_id) REFERENCES domains(id)
);
```
## 部署方案
### 1. 开发环境
#### 1.1 本地开发
```bash
# 前端开发
cd ddd-gen-ui
npm install
npm run dev
# 后端开发
cd ddd-gen-server
go mod tidy
go run main.go
# 数据库
docker-compose up -d postgres redis
```
#### 1.2 Docker开发
```yaml
# docker-compose.dev.yml
version: '3.8'
services:
frontend:
build: ./ddd-gen-ui
ports:
- "3000:3000"
volumes:
- ./ddd-gen-ui:/app
- /app/node_modules
environment:
- REACT_APP_API_URL=http://localhost:8080
backend:
build: ./ddd-gen-server
ports:
- "8080:8080"
volumes:
- ./ddd-gen-server:/app
environment:
- DB_HOST=postgres
- REDIS_HOST=redis
postgres:
image: postgres:15
environment:
- POSTGRES_DB=ddd_gen
- POSTGRES_USER=ddd_gen
- POSTGRES_PASSWORD=ddd_gen
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
postgres_data:
```
### 2. 生产环境
#### 2.1 容器化部署
```yaml
# docker-compose.prod.yml
version: '3.8'
services:
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./ssl:/etc/nginx/ssl
depends_on:
- frontend
- backend
frontend:
build: ./ddd-gen-ui
environment:
- NODE_ENV=production
- REACT_APP_API_URL=https://api.ddd-gen.com
backend:
build: ./ddd-gen-server
environment:
- GIN_MODE=release
- DB_HOST=postgres
- REDIS_HOST=redis
depends_on:
- postgres
- redis
postgres:
image: postgres:15
environment:
- POSTGRES_DB=ddd_gen
- POSTGRES_USER=ddd_gen
- POSTGRES_PASSWORD=${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
restart: unless-stopped
redis:
image: redis:7-alpine
volumes:
- redis_data:/data
restart: unless-stopped
volumes:
postgres_data:
redis_data:
```
#### 2.2 Kubernetes部署
```yaml
# k8s-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ddd-gen-frontend
spec:
replicas: 3
selector:
matchLabels:
app: ddd-gen-frontend
template:
metadata:
labels:
app: ddd-gen-frontend
spec:
containers:
- name: frontend
image: ddd-gen/frontend:latest
ports:
- containerPort: 3000
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "200m"
---
apiVersion: v1
kind: Service
metadata:
name: ddd-gen-frontend-service
spec:
selector:
app: ddd-gen-frontend
ports:
- port: 80
targetPort: 3000
type: LoadBalancer
```
## 用户体验设计
### 1. 交互设计
#### 1.1 拖拽操作
- **实体拖拽**: 从组件库拖拽实体到设计器
- **字段拖拽**: 拖拽字段到实体中
- **关系拖拽**: 拖拽连线建立实体关系
- **方法拖拽**: 拖拽方法到实体或服务中
#### 1.2 快捷键支持
```javascript
// 快捷键配置
const shortcuts = {
'Ctrl+N': '新建项目',
'Ctrl+O': '打开项目',
'Ctrl+S': '保存项目',
'Ctrl+Shift+S': '另存为',
'Ctrl+Z': '撤销',
'Ctrl+Y': '重做',
'Ctrl+D': '复制',
'Ctrl+X': '剪切',
'Ctrl+V': '粘贴',
'Delete': '删除',
'F5': '刷新',
'Ctrl+P': '预览',
'Ctrl+G': '生成代码'
};
```
#### 1.3 智能提示
- **字段类型提示**: 根据字段名自动推荐类型
- **验证规则提示**: 根据字段类型推荐验证规则
- **方法名提示**: 根据实体名推荐方法名
- **API路径提示**: 根据RESTful规范推荐路径
### 2. 响应式设计
#### 2.1 多设备支持
```css
/* 响应式断点 */
@media (max-width: 768px) {
/* 移动端布局 */
.sidebar { display: none; }
.main-content { width: 100%; }
.toolbar { flex-direction: column; }
}
@media (max-width: 1024px) {
/* 平板端布局 */
.sidebar { width: 200px; }
.main-content { width: calc(100% - 200px); }
}
@media (min-width: 1025px) {
/* 桌面端布局 */
.sidebar { width: 250px; }
.main-content { width: calc(100% - 250px); }
}
```
#### 2.2 主题支持
```javascript
// 主题配置
const themes = {
light: {
primary: '#1890ff',
background: '#ffffff',
text: '#000000',
border: '#d9d9d9'
},
dark: {
primary: '#177ddc',
background: '#141414',
text: '#ffffff',
border: '#434343'
}
};
```
## 扩展功能
### 1. 插件系统
#### 1.1 插件接口
```typescript
// 插件接口定义
interface Plugin {
name: string;
version: string;
description: string;
author: string;
icon: string;
// 生命周期钩子
onInstall(): void;
onUninstall(): void;
onActivate(): void;
onDeactivate(): void;
// 功能钩子
onEntityCreate?(entity: Entity): void;
onEntityUpdate?(entity: Entity): void;
onCodeGenerate?(config: GenerateConfig): void;
}
```
#### 1.2 内置插件
```javascript
// 内置插件列表
const builtinPlugins = [
{
name: 'linter',
description: '代码规范检查',
icon: '🔍'
},
{
name: 'test-generator',
description: '测试代码生成',
icon: '🧪'
},
{
name: 'docs-generator',
description: '文档生成',
icon: '📚'
},
{
name: 'migration-generator',
description: '数据库迁移生成',
icon: '🗄️'
}
];
```
### 2. 协作功能
#### 2.1 实时协作
```javascript
// WebSocket实时通信
const socket = new WebSocket('ws://localhost:8080/ws');
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
switch (data.type) {
case 'entity_updated':
updateEntity(data.entity);
break;
case 'user_joined':
addCollaborator(data.user);
break;
case 'user_left':
removeCollaborator(data.user);
break;
}
};
```
#### 2.2 版本控制
```javascript
// Git集成
class GitManager {
async init() {
// 初始化Git仓库
}
async commit(message) {
// 提交更改
}
async push() {
// 推送到远程
}
async pull() {
// 拉取更新
}
async branch(name) {
// 创建分支
}
}
```
### 3. 导入导出
#### 3.1 格式支持
```javascript
// 支持的导入格式
const importFormats = [
'json', // JSON配置
'yaml', // YAML配置
'xml', // XML配置
'sql', // 数据库结构
'openapi', // OpenAPI规范
'swagger', // Swagger文档
'plantuml', // PlantUML图
'mermaid' // Mermaid图
];
// 支持的导出格式
const exportFormats = [
'json', // JSON配置
'yaml', // YAML配置
'zip', // 完整项目
'tar.gz', // 压缩包
'docker', // Docker镜像
'helm', // Helm Chart
'terraform' // Terraform配置
];
```
## 开发计划
### 第一阶段:基础界面 (4周)
- [ ] 项目管理系统
- [ ] 基础UI框架
- [ ] 实体设计器
- [ ] 字段配置器
### 第二阶段:核心功能 (6周)
- [ ] 领域设计器
- [ ] 服务配置器
- [ ] API设计器
- [ ] 代码预览器
### 第三阶段:高级功能 (4周)
- [ ] 可视化关系图
- [ ] 拖拽操作
- [ ] 实时协作
- [ ] 插件系统
### 第四阶段:优化完善 (2周)
- [ ] 性能优化
- [ ] 用户体验
- [ ] 文档完善
- [ ] 测试覆盖
## 总结
这个可视化界面将为DDD代码生成器提供
### 🎯 核心优势
1. **直观易用**: 图形化界面,降低学习门槛
2. **可视化设计**: 拖拽式操作,所见即所得
3. **实时预览**: 代码实时预览,即时反馈
4. **协作支持**: 多人实时协作,提升团队效率
5. **扩展性强**: 插件系统,支持功能扩展
### 🚀 技术特色
1. **现代化技术栈**: React + TypeScript + Go
2. **响应式设计**: 支持多设备访问
3. **实时通信**: WebSocket实时协作
4. **版本控制**: Git集成
5. **容器化部署**: Docker + Kubernetes
### 💡 创新点
1. **可视化DDD设计**: 首次将DDD设计可视化
2. **智能代码生成**: 基于配置的智能生成
3. **实时协作**: 支持多人同时编辑
4. **插件生态**: 可扩展的插件系统
这个可视化界面将大大提升DDD代码生成器的易用性和实用性让DDD架构设计变得更加直观和高效
你觉得这个可视化界面策划方案如何?需要我开始实现吗?

View File

@@ -0,0 +1,653 @@
# DDD代码生成器策划方案
## 概述
DDD代码生成器是一个命令行工具用于快速生成符合DDD架构模式的领域代码。支持生成完整的领域结构包括实体、仓储、应用服务、DTO、HTTP处理器等大幅提升开发效率。
## 功能特性
### 1. 核心功能
#### 1.1 领域生成
- **完整领域生成**: 一次性生成整个领域的所有代码文件
- **实体生成**: 生成实体、枚举、业务方法
- **仓储生成**: 生成仓储接口和GORM实现
- **应用服务生成**: 生成应用服务接口和实现
- **DTO生成**: 生成命令、查询、响应DTO
- **HTTP层生成**: 生成处理器和路由
- **依赖注入配置**: 自动更新容器配置
#### 1.2 增量功能
- **新增实体**: 在现有领域中添加新实体
- **新增服务**: 为现有实体添加新的应用服务
- **新增API**: 为现有实体添加新的HTTP接口
- **字段扩展**: 为现有实体添加新字段
#### 1.3 模板功能
- **自定义模板**: 支持自定义代码模板
- **模板变量**: 支持丰富的模板变量替换
- **多语言支持**: 支持中文和英文模板
### 2. 高级功能
#### 2.1 智能分析
- **依赖分析**: 自动分析实体间关系
- **命名规范**: 自动生成符合规范的命名
- **类型推断**: 根据字段名自动推断数据类型
- **验证规则**: 自动生成字段验证规则
#### 2.2 代码质量
- **Linter集成**: 生成后自动运行代码检查
- **格式化**: 自动格式化生成的代码
- **测试生成**: 自动生成单元测试和集成测试
- **文档生成**: 自动生成API文档注释
#### 2.3 项目管理
- **项目扫描**: 扫描现有项目结构
- **配置管理**: 管理生成器配置
- **历史记录**: 记录生成历史
- **回滚功能**: 支持代码回滚
## 技术架构
### 1. 整体架构
```
DDD Generator
├── CLI Interface # 命令行接口
├── Core Engine # 核心引擎
├── Template Engine # 模板引擎
├── Code Analyzer # 代码分析器
├── File Manager # 文件管理器
└── Validator # 验证器
```
### 2. 核心组件
#### 2.1 CLI Interface
- **命令解析**: 解析命令行参数
- **交互式输入**: 提供友好的交互界面
- **帮助系统**: 提供详细的帮助信息
- **配置管理**: 管理用户配置
#### 2.2 Core Engine
- **生成流程控制**: 控制代码生成流程
- **依赖管理**: 管理组件间依赖关系
- **错误处理**: 统一的错误处理机制
- **日志系统**: 详细的日志记录
#### 2.3 Template Engine
- **模板解析**: 解析Go模板语法
- **变量替换**: 执行模板变量替换
- **条件渲染**: 支持条件渲染逻辑
- **循环渲染**: 支持循环渲染逻辑
#### 2.4 Code Analyzer
- **AST解析**: 解析Go代码AST
- **依赖分析**: 分析代码依赖关系
- **结构分析**: 分析项目结构
- **命名分析**: 分析命名规范
#### 2.5 File Manager
- **文件操作**: 安全的文件读写操作
- **目录管理**: 创建和管理目录结构
- **备份恢复**: 文件备份和恢复
- **权限管理**: 文件权限管理
#### 2.6 Validator
- **语法验证**: 验证生成的代码语法
- **规范检查**: 检查代码规范
- **依赖验证**: 验证依赖关系
- **冲突检测**: 检测文件冲突
## 使用场景
### 1. 新项目初始化
```bash
# 生成完整的用户域
ddd-gen domain user --entities user,role,permission --features auth,profile
# 生成产品域
ddd-gen domain product --entities product,category,order --features catalog,order
```
### 2. 现有项目扩展
```bash
# 在用户域中添加新实体
ddd-gen entity user subscription --fields id,name,price,status
# 为产品添加新服务
ddd-gen service product inventory --methods check,update,reserve
# 添加新的API接口
ddd-gen api product search --methods search,filter,sort
```
### 3. 批量操作
```bash
# 批量生成多个域
ddd-gen batch --config domains.yaml
# 批量添加字段
ddd-gen batch-fields --config fields.yaml
```
## 配置文件
### 1. 项目配置 (ddd-config.yaml)
```yaml
project:
name: "tyapi-server"
module: "tyapi-server/internal"
author: "开发团队"
version: "1.0.0"
templates:
path: "./templates"
language: "zh"
style: "standard"
output:
path: "./internal"
backup: true
format: true
test: true
validation:
lint: true
test: true
docs: true
```
### 2. 领域配置 (domain-config.yaml)
```yaml
domain:
name: "user"
description: "用户管理域"
entities:
- name: "user"
fields:
- name: "id"
type: "string"
tag: "gorm:\"primaryKey;type:varchar(36)\""
comment: "用户ID"
- name: "username"
type: "string"
tag: "gorm:\"type:varchar(50);uniqueIndex;not null\""
comment: "用户名"
validation: "required,min=3,max=50"
- name: "email"
type: "string"
tag: "gorm:\"type:varchar(100);uniqueIndex;not null\""
comment: "邮箱"
validation: "required,email"
- name: "password"
type: "string"
tag: "gorm:\"type:varchar(255);not null\""
comment: "密码"
validation: "required,min=6"
- name: "status"
type: "UserStatus"
tag: "gorm:\"type:varchar(20);default:'active'\""
comment: "用户状态"
methods:
- name: "IsActive"
return: "bool"
body: "return u.Status == UserStatusActive"
- name: "CanLogin"
return: "bool"
body: "return u.IsActive() && !u.IsDeleted()"
- name: "role"
fields:
- name: "id"
type: "string"
tag: "gorm:\"primaryKey;type:varchar(36)\""
comment: "角色ID"
- name: "name"
type: "string"
tag: "gorm:\"type:varchar(50);uniqueIndex;not null\""
comment: "角色名称"
validation: "required,min=2,max=50"
- name: "description"
type: "string"
tag: "gorm:\"type:text\""
comment: "角色描述"
enums:
- name: "UserStatus"
values:
- name: "Active"
value: "active"
comment: "激活状态"
- name: "Inactive"
value: "inactive"
comment: "未激活状态"
- name: "Suspended"
value: "suspended"
comment: "暂停状态"
services:
- name: "user"
methods:
- name: "CreateUser"
command: "CreateUserCommand"
response: "UserInfoResponse"
- name: "UpdateUser"
command: "UpdateUserCommand"
response: "UserInfoResponse"
- name: "DeleteUser"
command: "DeleteUserCommand"
- name: "GetUserByID"
query: "GetUserQuery"
response: "UserInfoResponse"
- name: "ListUsers"
query: "ListUsersQuery"
response: "UserListResponse"
- name: "EnableUser"
command: "EnableUserCommand"
- name: "DisableUser"
command: "DisableUserCommand"
apis:
- path: "/users"
methods:
- method: "GET"
handler: "ListUsers"
summary: "获取用户列表"
- method: "POST"
handler: "CreateUser"
summary: "创建用户"
- path: "/users/:id"
methods:
- method: "GET"
handler: "GetUserDetail"
summary: "获取用户详情"
- method: "PUT"
handler: "UpdateUser"
summary: "更新用户"
- method: "DELETE"
handler: "DeleteUser"
summary: "删除用户"
- path: "/users/:id/enable"
methods:
- method: "POST"
handler: "EnableUser"
summary: "启用用户"
- path: "/users/:id/disable"
methods:
- method: "POST"
handler: "DisableUser"
summary: "禁用用户"
```
## 命令行接口
### 1. 主要命令
```bash
# 生成完整领域
ddd-gen domain <domain-name> [options]
# 生成实体
ddd-gen entity <domain-name> <entity-name> [options]
# 生成服务
ddd-gen service <domain-name> <service-name> [options]
# 生成API
ddd-gen api <domain-name> <api-name> [options]
# 生成DTO
ddd-gen dto <domain-name> <dto-type> [options]
# 生成测试
ddd-gen test <domain-name> <test-type> [options]
# 项目初始化
ddd-gen init [options]
# 配置管理
ddd-gen config [subcommand] [options]
# 模板管理
ddd-gen template [subcommand] [options]
```
### 2. 选项参数
```bash
# 通用选项
--config, -c 指定配置文件
--output, -o 指定输出目录
--template, -t 指定模板目录
--force, -f 强制覆盖文件
--dry-run 试运行模式
--verbose, -v 详细输出
--quiet, -q 静默模式
# 领域选项
--entities 指定实体列表
--features 指定功能特性
--services 指定服务列表
--apis 指定API列表
# 实体选项
--fields 指定字段定义
--methods 指定业务方法
--enums 指定枚举定义
--relations 指定关联关系
# 服务选项
--methods 指定服务方法
--commands 指定命令DTO
--queries 指定查询DTO
--responses 指定响应DTO
```
### 3. 交互式模式
```bash
# 交互式生成领域
ddd-gen domain --interactive
# 交互式生成实体
ddd-gen entity --interactive
# 交互式配置
ddd-gen config --interactive
```
## 模板系统
### 1. 模板结构
```
templates/
├── domain/ # 领域模板
│ ├── entities/ # 实体模板
│ ├── repositories/ # 仓储模板
│ ├── services/ # 服务模板
│ └── http/ # HTTP模板
├── dto/ # DTO模板
├── test/ # 测试模板
├── config/ # 配置模板
└── docs/ # 文档模板
```
### 2. 模板变量
```go
// 基础变量
{{.DomainName}} // 领域名称
{{.EntityName}} // 实体名称
{{.ServiceName}} // 服务名称
{{.PackageName}} // 包名称
{{.ModulePath}} // 模块路径
// 实体变量
{{.Fields}} // 字段列表
{{.Methods}} // 方法列表
{{.Enums}} // 枚举列表
{{.Relations}} // 关联关系
// 服务变量
{{.Commands}} // 命令列表
{{.Queries}} // 查询列表
{{.Responses}} // 响应列表
// API变量
{{.Routes}} // 路由列表
{{.Handlers}} // 处理器列表
{{.Middlewares}} // 中间件列表
// 项目变量
{{.ProjectName}} // 项目名称
{{.Author}} // 作者
{{.Version}} // 版本
{{.Timestamp}} // 时间戳
```
### 3. 条件渲染
```go
{{if .HasEnums}}
// 枚举定义
{{range .Enums}}
type {{.Name}} {{.Type}}
const (
{{range .Values}}
{{.Name}}{{.Name}} {{.Type}} = "{{.Value}}"
{{end}}
)
{{end}}
{{end}}
{{if .HasRelations}}
// 关联关系
{{range .Relations}}
{{.FieldName}} {{.Type}} `gorm:"foreignKey:{{.ForeignKey}}"`
{{end}}
{{end}}
```
## 代码分析
### 1. AST分析
```go
// 分析现有代码结构
type CodeAnalyzer struct {
parser *ast.Parser
types *types.Info
}
// 分析实体结构
func (ca *CodeAnalyzer) AnalyzeEntity(filePath string) (*EntityInfo, error) {
// 解析Go文件AST
// 提取结构体信息
// 分析字段和方法
// 识别关联关系
}
// 分析依赖关系
func (ca *CodeAnalyzer) AnalyzeDependencies(packagePath string) (*DependencyInfo, error) {
// 分析包依赖
// 识别循环依赖
// 生成依赖图
}
```
### 2. 命名分析
```go
// 命名规范检查
type NamingAnalyzer struct {
rules []NamingRule
}
// 检查命名规范
func (na *NamingAnalyzer) CheckNaming(name, type string) error {
// 检查命名规范
// 提供建议
// 自动修正
}
```
## 验证系统
### 1. 语法验证
```go
// 验证生成的代码
func ValidateCode(code string) error {
// 解析Go代码
// 检查语法错误
// 验证类型
// 检查导入
}
```
### 2. 规范检查
```go
// 检查代码规范
func CheckCodeStyle(code string) []StyleIssue {
// 检查格式
// 检查命名
// 检查注释
// 检查复杂度
}
```
### 3. 依赖验证
```go
// 验证依赖关系
func ValidateDependencies(domain *Domain) error {
// 检查循环依赖
// 验证接口实现
// 检查导入路径
}
```
## 扩展功能
### 1. 插件系统
```go
// 插件接口
type Plugin interface {
Name() string
Execute(ctx *Context) error
Validate(ctx *Context) error
}
// 内置插件
var BuiltinPlugins = []Plugin{
&LinterPlugin{},
&TestPlugin{},
&DocsPlugin{},
&MigrationPlugin{},
}
```
### 2. 自定义模板
```go
// 模板注册
func RegisterTemplate(name, content string) error {
// 验证模板语法
// 注册模板
// 更新索引
}
```
### 3. 代码转换
```go
// 代码转换器
type CodeTransformer struct {
rules []TransformRule
}
// 转换现有代码
func (ct *CodeTransformer) Transform(code string) (string, error) {
// 应用转换规则
// 保持代码结构
// 更新引用
}
```
## 部署方案
### 1. 安装方式
```bash
# Go安装
go install github.com/your-org/ddd-gen@latest
# 二进制安装
curl -L https://github.com/your-org/ddd-gen/releases/latest/download/ddd-gen-$(uname -s)-$(uname -m) -o ddd-gen
chmod +x ddd-gen
sudo mv ddd-gen /usr/local/bin/
# Docker安装
docker run --rm -v $(pwd):/workspace ddd-gen domain user
```
### 2. 配置管理
```bash
# 初始化配置
ddd-gen init
# 查看配置
ddd-gen config show
# 编辑配置
ddd-gen config edit
# 验证配置
ddd-gen config validate
```
### 3. 集成CI/CD
```yaml
# GitHub Actions
- name: Generate DDD Code
run: |
ddd-gen domain user --config domains/user.yaml
ddd-gen domain product --config domains/product.yaml
- name: Validate Generated Code
run: |
go mod tidy
go vet ./...
golangci-lint run
```
## 开发计划
### 第一阶段:核心功能
- [ ] CLI框架搭建
- [ ] 基础模板系统
- [ ] 实体生成功能
- [ ] 仓储生成功能
- [ ] 应用服务生成功能
### 第二阶段:完整功能
- [ ] HTTP层生成
- [ ] DTO生成
- [ ] 测试生成
- [ ] 依赖注入配置
- [ ] 代码验证
### 第三阶段:高级功能
- [ ] 代码分析
- [ ] 智能建议
- [ ] 插件系统
- [ ] 自定义模板
- [ ] 批量操作
### 第四阶段:优化完善
- [ ] 性能优化
- [ ] 错误处理
- [ ] 文档完善
- [ ] 测试覆盖
- [ ] 用户反馈
## 总结
这个DDD代码生成器将显著提升开发效率确保代码质量和架构一致性。通过配置驱动的方式可以快速生成符合DDD架构的完整代码结构同时支持灵活的定制和扩展。
关键优势:
1. **高效开发**: 大幅减少重复代码编写
2. **架构一致**: 确保所有代码符合DDD规范
3. **质量保证**: 内置代码验证和测试生成
4. **灵活扩展**: 支持自定义模板和插件
5. **易于使用**: 友好的CLI和交互界面
你觉得这个策划方案如何?需要我开始实现吗?

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -68,6 +68,25 @@ definitions:
- role
- username
type: object
commands.CreateSubscriptionCommand:
properties:
api_limit:
type: integer
auto_renew:
type: boolean
duration:
type: string
price:
minimum: 0
type: number
product_id:
type: string
user_id:
type: string
required:
- product_id
- user_id
type: object
commands.CreateUserSecretsCommand:
properties:
expires_at:
@@ -156,6 +175,29 @@ definitions:
- password
- phone
type: object
commands.ResetPasswordCommand:
description: 重置用户密码请求参数(忘记密码时使用)
properties:
code:
example: "123456"
type: string
confirm_new_password:
example: newpassword123
type: string
new_password:
example: newpassword123
maxLength: 128
minLength: 6
type: string
phone:
example: "13800138000"
type: string
required:
- code
- confirm_new_password
- new_password
- phone
type: object
commands.SendCodeCommand:
description: 发送短信验证码请求参数
properties:
@@ -428,6 +470,52 @@ definitions:
total_operations:
type: integer
type: object
responses.CategoryInfoResponse:
properties:
children:
items:
$ref: '#/definitions/responses.CategoryInfoResponse'
type: array
code:
type: string
created_at:
type: string
description:
type: string
id:
type: string
is_enabled:
type: boolean
is_visible:
type: boolean
level:
type: integer
name:
type: string
parent:
allOf:
- $ref: '#/definitions/responses.CategoryInfoResponse'
description: 关联信息
parent_id:
type: string
sort:
type: integer
updated_at:
type: string
type: object
responses.CategoryListResponse:
properties:
items:
items:
$ref: '#/definitions/responses.CategoryInfoResponse'
type: array
page:
type: integer
size:
type: integer
total:
type: integer
type: object
responses.CertificationResponse:
properties:
completed_at:
@@ -496,6 +584,83 @@ definitions:
user:
$ref: '#/definitions/responses.UserProfileResponse'
type: object
responses.ProductInfoResponse:
properties:
category:
allOf:
- $ref: '#/definitions/responses.CategoryInfoResponse'
description: 关联信息
category_id:
type: string
code:
type: string
content:
type: string
created_at:
type: string
description:
type: string
id:
type: string
is_enabled:
type: boolean
is_package:
type: boolean
is_visible:
type: boolean
name:
type: string
price:
type: number
seo_description:
type: string
seo_keywords:
type: string
seo_title:
description: SEO信息
type: string
updated_at:
type: string
type: object
responses.ProductListResponse:
properties:
items:
items:
$ref: '#/definitions/responses.ProductInfoResponse'
type: array
page:
type: integer
size:
type: integer
total:
type: integer
type: object
responses.ProductSimpleResponse:
properties:
code:
type: string
description:
type: string
id:
type: string
is_package:
type: boolean
name:
type: string
price:
type: number
type: object
responses.ProductStatsResponse:
properties:
enabled_products:
type: integer
package_products:
type: integer
total_products:
type: integer
visible_products:
type: integer
type: object
responses.RegisterUserResponse:
description: 用户注册成功响应
properties:
@@ -506,6 +671,56 @@ definitions:
example: "13800138000"
type: string
type: object
responses.SubscriptionInfoResponse:
properties:
api_used:
type: integer
created_at:
type: string
id:
type: string
price:
type: number
product:
allOf:
- $ref: '#/definitions/responses.ProductSimpleResponse'
description: 关联信息
product_id:
type: string
updated_at:
type: string
user_id:
type: string
type: object
responses.SubscriptionListResponse:
properties:
items:
items:
$ref: '#/definitions/responses.SubscriptionInfoResponse'
type: array
page:
type: integer
size:
type: integer
total:
type: integer
type: object
responses.SubscriptionStatsResponse:
properties:
total_revenue:
type: number
total_subscriptions:
type: integer
type: object
responses.SubscriptionUsageResponse:
properties:
api_used:
type: integer
id:
type: string
product_id:
type: string
type: object
responses.TransactionResponse:
properties:
amount:
@@ -558,6 +773,9 @@ definitions:
id:
example: 123e4567-e89b-12d3-a456-426614174000
type: string
is_certified:
example: false
type: boolean
phone:
example: "13800138000"
type: string
@@ -905,7 +1123,7 @@ paths:
type: object
summary: 管理员登录
tags:
- 管理员认证
- 管理员管理
/api/v1/admin/change-password:
post:
consumes:
@@ -973,6 +1191,71 @@ paths:
summary: 获取管理员统计信息
tags:
- 管理员管理
/api/v1/categories:
get:
consumes:
- application/json
description: 获取产品分类列表,支持层级筛选
parameters:
- description: 父级分类ID
in: query
name: parent_id
type: string
- description: 分类层级
in: query
name: level
type: integer
produces:
- application/json
responses:
"200":
description: 获取分类列表成功
schema:
$ref: '#/definitions/responses.CategoryListResponse'
"500":
description: 服务器内部错误
schema:
additionalProperties: true
type: object
summary: 获取分类列表
tags:
- 数据大厅
/api/v1/categories/{id}:
get:
consumes:
- application/json
description: 根据分类ID获取分类详细信息
parameters:
- description: 分类ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: 获取分类详情成功
schema:
$ref: '#/definitions/responses.CategoryInfoResponse'
"400":
description: 请求参数错误
schema:
additionalProperties: true
type: object
"404":
description: 分类不存在
schema:
additionalProperties: true
type: object
"500":
description: 服务器内部错误
schema:
additionalProperties: true
type: object
summary: 获取分类详情
tags:
- 数据大厅
/api/v1/certification:
post:
consumes:
@@ -1364,7 +1647,7 @@ paths:
- Bearer: []
summary: 上传营业执照并同步OCR识别
tags:
- 认证管理
- 企业认证
/api/v1/finance/secrets:
get:
consumes:
@@ -1756,6 +2039,358 @@ paths:
summary: 钱包提现
tags:
- 钱包管理
/api/v1/my/subscriptions:
get:
consumes:
- application/json
description: 获取当前用户的订阅列表
parameters:
- default: 1
description: 页码
in: query
name: page
type: integer
- default: 10
description: 每页数量
in: query
name: page_size
type: integer
- description: 订阅状态
in: query
name: status
type: string
- description: 排序字段
in: query
name: sort_by
type: string
- description: 排序方向
enum:
- asc
- desc
in: query
name: sort_order
type: string
produces:
- application/json
responses:
"200":
description: 获取订阅列表成功
schema:
$ref: '#/definitions/responses.SubscriptionListResponse'
"400":
description: 请求参数错误
schema:
additionalProperties: true
type: object
"401":
description: 未认证
schema:
additionalProperties: true
type: object
"500":
description: 服务器内部错误
schema:
additionalProperties: true
type: object
security:
- Bearer: []
summary: 获取我的订阅列表
tags:
- 我的订阅
/api/v1/my/subscriptions/{id}:
get:
consumes:
- application/json
description: 获取指定订阅的详细信息
parameters:
- description: 订阅ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: 获取订阅详情成功
schema:
$ref: '#/definitions/responses.SubscriptionInfoResponse'
"400":
description: 请求参数错误
schema:
additionalProperties: true
type: object
"401":
description: 未认证
schema:
additionalProperties: true
type: object
"404":
description: 订阅不存在
schema:
additionalProperties: true
type: object
"500":
description: 服务器内部错误
schema:
additionalProperties: true
type: object
security:
- Bearer: []
summary: 获取我的订阅详情
tags:
- 我的订阅
/api/v1/my/subscriptions/{id}/usage:
get:
consumes:
- application/json
description: 获取指定订阅的使用情况统计
parameters:
- description: 订阅ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: 获取使用情况成功
schema:
$ref: '#/definitions/responses.SubscriptionUsageResponse'
"400":
description: 请求参数错误
schema:
additionalProperties: true
type: object
"401":
description: 未认证
schema:
additionalProperties: true
type: object
"404":
description: 订阅不存在
schema:
additionalProperties: true
type: object
"500":
description: 服务器内部错误
schema:
additionalProperties: true
type: object
security:
- Bearer: []
summary: 获取我的订阅使用情况
tags:
- 我的订阅
/api/v1/my/subscriptions/stats:
get:
consumes:
- application/json
description: 获取当前用户的订阅统计信息
produces:
- application/json
responses:
"200":
description: 获取订阅统计成功
schema:
$ref: '#/definitions/responses.SubscriptionStatsResponse'
"401":
description: 未认证
schema:
additionalProperties: true
type: object
"500":
description: 服务器内部错误
schema:
additionalProperties: true
type: object
security:
- Bearer: []
summary: 获取我的订阅统计
tags:
- 我的订阅
/api/v1/products:
get:
consumes:
- application/json
description: 分页获取可用的产品列表,支持筛选
parameters:
- default: 1
description: 页码
in: query
name: page
type: integer
- default: 10
description: 每页数量
in: query
name: page_size
type: integer
- description: 搜索关键词
in: query
name: keyword
type: string
- description: 分类ID
in: query
name: category_id
type: string
- description: 最低价格
in: query
name: min_price
type: number
- description: 最高价格
in: query
name: max_price
type: number
- description: 是否启用
in: query
name: is_enabled
type: boolean
- description: 是否可见
in: query
name: is_visible
type: boolean
- description: 是否组合包
in: query
name: is_package
type: boolean
- description: 排序字段
in: query
name: sort_by
type: string
- description: 排序方向
enum:
- asc
- desc
in: query
name: sort_order
type: string
produces:
- application/json
responses:
"200":
description: 获取产品列表成功
schema:
$ref: '#/definitions/responses.ProductListResponse'
"400":
description: 请求参数错误
schema:
additionalProperties: true
type: object
"500":
description: 服务器内部错误
schema:
additionalProperties: true
type: object
summary: 获取产品列表
tags:
- 数据大厅
/api/v1/products/{id}:
get:
consumes:
- application/json
description: 根据产品ID获取产品详细信息
parameters:
- description: 产品ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: 获取产品详情成功
schema:
$ref: '#/definitions/responses.ProductInfoResponse'
"400":
description: 请求参数错误
schema:
additionalProperties: true
type: object
"404":
description: 产品不存在
schema:
additionalProperties: true
type: object
"500":
description: 服务器内部错误
schema:
additionalProperties: true
type: object
summary: 获取产品详情
tags:
- 数据大厅
/api/v1/products/{id}/subscribe:
post:
consumes:
- application/json
description: 用户订阅指定产品
parameters:
- description: 产品ID
in: path
name: id
required: true
type: string
- description: 订阅请求
in: body
name: request
required: true
schema:
$ref: '#/definitions/commands.CreateSubscriptionCommand'
produces:
- application/json
responses:
"200":
description: 订阅成功
schema:
additionalProperties: true
type: object
"400":
description: 请求参数错误
schema:
additionalProperties: true
type: object
"401":
description: 未认证
schema:
additionalProperties: true
type: object
"404":
description: 产品不存在
schema:
additionalProperties: true
type: object
"500":
description: 服务器内部错误
schema:
additionalProperties: true
type: object
security:
- Bearer: []
summary: 订阅产品
tags:
- 数据大厅
/api/v1/products/stats:
get:
consumes:
- application/json
description: 获取产品相关的统计信息
produces:
- application/json
responses:
"200":
description: 获取统计信息成功
schema:
$ref: '#/definitions/responses.ProductStatsResponse'
"500":
description: 服务器内部错误
schema:
additionalProperties: true
type: object
summary: 获取产品统计
tags:
- 数据大厅
/api/v1/users/login-password:
post:
consumes:
@@ -1939,6 +2574,44 @@ paths:
summary: 用户注册
tags:
- 用户认证
/api/v1/users/reset-password:
post:
consumes:
- application/json
description: 使用手机号、验证码和新密码重置用户密码(忘记密码时使用)
parameters:
- description: 重置密码请求
in: body
name: request
required: true
schema:
$ref: '#/definitions/commands.ResetPasswordCommand'
produces:
- application/json
responses:
"200":
description: 密码重置成功
schema:
additionalProperties: true
type: object
"400":
description: 请求参数错误或验证码无效
schema:
additionalProperties: true
type: object
"404":
description: 用户不存在
schema:
additionalProperties: true
type: object
"500":
description: 服务器内部错误
schema:
additionalProperties: true
type: object
summary: 重置密码
tags:
- 用户认证
/api/v1/users/send-code:
post:
consumes: