87 lines
2.6 KiB
Smarty
87 lines
2.6 KiB
Smarty
{{- if .IsAdd}}
|
|
// 在 model.{{.StructName}} 结构体中新增如下字段
|
|
{{- range .Fields}}
|
|
{{ GenerateModelField . }}
|
|
{{- end }}
|
|
|
|
{{ else }}
|
|
// Code generated by KRA AutoCode. DO NOT EDIT.
|
|
// 自动生成模板 {{.StructName}}
|
|
package model
|
|
|
|
import (
|
|
{{- if .GvaModel }}
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
{{- else }}
|
|
{{- if or .HasTimer }}
|
|
"time"
|
|
{{- end }}
|
|
{{- if .NeedJSON }}
|
|
"gorm.io/datatypes"
|
|
{{- end }}
|
|
{{- end }}
|
|
)
|
|
|
|
const TableName{{.StructName}} = "{{.TableName}}"
|
|
|
|
// {{.StructName}} {{.Description}}
|
|
// mapped from table <{{.TableName}}>
|
|
type {{.StructName}} struct {
|
|
{{- if .GvaModel }}
|
|
ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"`
|
|
CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_{{.TableName}}_deleted_at,priority:1" json:"deleted_at"`
|
|
{{- else }}
|
|
{{- with .PrimaryField}}
|
|
{{.FieldName}} int64 `gorm:"column:{{.ColumnName}};type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"{{.FieldJson}}"` // {{.FieldDesc}}
|
|
{{- end}}
|
|
{{- end }}
|
|
{{- range .Fields}}
|
|
{{- if not .PrimaryKey}}
|
|
{{ GenerateModelField . }}
|
|
{{- end}}
|
|
{{- end }}
|
|
{{- if .AutoCreateResource }}
|
|
CreatedBy int64 `gorm:"column:created_by;type:bigint(20) unsigned;comment:创建者" json:"created_by"` // 创建者
|
|
UpdatedBy int64 `gorm:"column:updated_by;type:bigint(20) unsigned;comment:更新者" json:"updated_by"` // 更新者
|
|
DeletedBy int64 `gorm:"column:deleted_by;type:bigint(20) unsigned;comment:删除者" json:"deleted_by"` // 删除者
|
|
{{- end }}
|
|
{{- if .IsTree }}
|
|
ParentID int64 `gorm:"column:parent_id;type:bigint(20);comment:父节点ID" json:"parent_id"` // 父节点ID
|
|
Children []*{{.StructName}} `gorm:"-" json:"children"` // 子节点
|
|
{{- end }}
|
|
}
|
|
|
|
// TableName {{.StructName}}'s table name
|
|
func (*{{.StructName}}) TableName() string {
|
|
return TableName{{.StructName}}
|
|
}
|
|
|
|
{{- if .IsTree }}
|
|
|
|
// GetChildren 实现 TreeNode 接口
|
|
func (s *{{.StructName}}) GetChildren() []*{{.StructName}} {
|
|
return s.Children
|
|
}
|
|
|
|
// SetChildren 实现 TreeNode 接口
|
|
func (s *{{.StructName}}) SetChildren(child *{{.StructName}}) {
|
|
s.Children = append(s.Children, child)
|
|
}
|
|
|
|
// GetID 实现 TreeNode 接口
|
|
func (s *{{.StructName}}) GetID() int {
|
|
return int(s.{{- if .GvaModel}}ID{{- else}}{{.PrimaryField.FieldName}}{{- end}})
|
|
}
|
|
|
|
// GetParentID 实现 TreeNode 接口
|
|
func (s *{{.StructName}}) GetParentID() int {
|
|
return int(s.ParentID)
|
|
}
|
|
{{- end }}
|
|
|
|
{{ end }}
|