feat: 代码生成
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package codegen
|
||||
|
||||
// GenConfig 代码生成完整配置
|
||||
type GenConfig struct {
|
||||
DbConfig DbConfig `json:"dbConfig"`
|
||||
OutputDir string `json:"outputDir"` // 后端输出目录,绝对路径,为空则输出到项目根目录
|
||||
FrontendOutputDir string `json:"frontendOutputDir"` // 前端输出目录,绝对路径,为空则跳过前端生成
|
||||
Overwrite bool `json:"overwrite"` // true=覆盖已有文件 false=增量模式(跳过已存在文件)
|
||||
Modules []Module `json:"modules"`
|
||||
}
|
||||
|
||||
// DbConfig 目标数据库连接配置
|
||||
type DbConfig struct {
|
||||
Host string `json:"host"`
|
||||
Port string `json:"port"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
DbName string `json:"dbName"`
|
||||
DbType string `json:"dbType"` // mysql / postgres / sqlite
|
||||
}
|
||||
|
||||
// Module 模块定义(对应一组功能)
|
||||
type Module struct {
|
||||
Name string `json:"name"` // 模块名(PascalCase),如 "Order"
|
||||
PackageName string `json:"packageName"` // 包名(lowercase),如 "order"
|
||||
Description string `json:"description"`
|
||||
Features []Feature `json:"features"`
|
||||
}
|
||||
|
||||
// Feature 功能单元(对应一张表 / 一个实体)
|
||||
type Feature struct {
|
||||
Name string `json:"name"` // 实体名(PascalCase),如 "Product"
|
||||
TableName string `json:"tableName"` // 数据库表名,如 "product"
|
||||
Comment string `json:"comment"`
|
||||
Fields []Field `json:"fields"`
|
||||
Relations []Relation `json:"relations"`
|
||||
}
|
||||
|
||||
// Field 字段定义
|
||||
type Field struct {
|
||||
Name string `json:"name"` // Go 字段名(PascalCase),如 "OrderNo"
|
||||
ColumnName string `json:"columnName"` // 数据库列名(snake_case),如 "order_no"
|
||||
Type string `json:"type"` // Go 类型,如 string / int / float64 / bool / time.Time
|
||||
GormTag string `json:"gormTag"` // gorm tag 附加内容,如 "size:100;not null"
|
||||
JsonTag string `json:"jsonTag"` // json tag,如 "orderNo"
|
||||
Comment string `json:"comment"` // 字段注释
|
||||
Required bool `json:"required"` // 是否必填(影响 not null)
|
||||
}
|
||||
|
||||
// Relation 表关系定义
|
||||
type Relation struct {
|
||||
Type string `json:"type"` // OneToOne / OneToMany / ManyToMany
|
||||
TargetFeature string `json:"targetFeature"` // 目标实体名(PascalCase)
|
||||
ForeignKey string `json:"foreignKey"` // 外键字段名,如 "UserId"
|
||||
JoinTable string `json:"joinTable"` // ManyToMany 中间表名
|
||||
FieldName string `json:"fieldName"` // Go 中关联字段名,如 "Tags"
|
||||
}
|
||||
|
||||
// TestConnectionReq 测试连接请求
|
||||
type TestConnectionReq struct {
|
||||
DbConfig DbConfig `json:"dbConfig"`
|
||||
}
|
||||
|
||||
// PreviewReq 预览代码请求
|
||||
type PreviewReq struct {
|
||||
GenConfig
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package codegen
|
||||
|
||||
// PreviewFile 预览的单个文件
|
||||
type PreviewFile struct {
|
||||
FilePath string `json:"filePath"` // 相对于输出目录的路径
|
||||
Content string `json:"content"` // 文件内容
|
||||
AlwaysOverwrite bool `json:"alwaysOverwrite,omitempty"` // 聚合文件(如 enter.go),始终覆盖
|
||||
}
|
||||
|
||||
// GenResult 代码生成结果
|
||||
type GenResult struct {
|
||||
OutputDir string `json:"outputDir"` // 实际输出目录
|
||||
Files []PreviewFile `json:"files"` // 生成的文件列表
|
||||
Message string `json:"message"` // 生成结果说明
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package order
|
||||
|
||||
import "sundynix-go/global"
|
||||
|
||||
// Order
|
||||
type Order struct {
|
||||
global.BaseModel
|
||||
UserId string `gorm:"column:user_id;size:50" json:"userId"` //
|
||||
}
|
||||
|
||||
func (Order) TableName() string {
|
||||
return "sundynix_order"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package order
|
||||
|
||||
import "sundynix-go/global"
|
||||
|
||||
// Refund
|
||||
type Refund struct {
|
||||
global.BaseModel
|
||||
UserId string `gorm:"column:user_id;size:50" json:"userId"` //
|
||||
}
|
||||
|
||||
func (Refund) TableName() string {
|
||||
return "sundynix_refund"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package request
|
||||
|
||||
// ---- ----
|
||||
|
||||
// SaveRefundReq 新增请求
|
||||
type SaveRefundReq struct {
|
||||
UserId string `json:"userId" form:"userId"` //
|
||||
}
|
||||
|
||||
// UpdateRefundReq 更新请求
|
||||
type UpdateRefundReq struct {
|
||||
Id string `json:"id" binding:"required"` // ID
|
||||
UserId string `json:"userId" form:"userId"` //
|
||||
}
|
||||
|
||||
// ListRefundReq 分页查询请求
|
||||
type ListRefundReq struct {
|
||||
Current int `json:"current" form:"current"` // 页码
|
||||
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
|
||||
Keyword string `json:"keyword" form:"keyword"` // 关键字搜索
|
||||
}
|
||||
|
||||
// ---- ----
|
||||
|
||||
// SaveStockReq 新增请求
|
||||
type SaveStockReq struct {
|
||||
Amount int64 `json:"amount" form:"amount"` //
|
||||
}
|
||||
|
||||
// UpdateStockReq 更新请求
|
||||
type UpdateStockReq struct {
|
||||
Id string `json:"id" binding:"required"` // ID
|
||||
Amount int64 `json:"amount" form:"amount"` //
|
||||
}
|
||||
|
||||
// ListStockReq 分页查询请求
|
||||
type ListStockReq struct {
|
||||
Current int `json:"current" form:"current"` // 页码
|
||||
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
|
||||
Keyword string `json:"keyword" form:"keyword"` // 关键字搜索
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package order
|
||||
|
||||
import "sundynix-go/global"
|
||||
|
||||
// Stock
|
||||
type Stock struct {
|
||||
global.BaseModel
|
||||
Amount int64 `gorm:"column:amount" json:"amount"` //
|
||||
}
|
||||
|
||||
func (Stock) TableName() string {
|
||||
return "sundynix_stock"
|
||||
}
|
||||
Reference in New Issue
Block a user