day day up
This commit is contained in:
@@ -54,3 +54,25 @@ func getUninStr(left, middle, right string) string {
|
||||
}
|
||||
return re
|
||||
}
|
||||
|
||||
func getGormModelElement() []ColumusInfo {
|
||||
var result []ColumusInfo
|
||||
result = append(result, ColumusInfo{
|
||||
BaseInfo: BaseInfo{Name: "id", Notes: "Primary key"},
|
||||
Type: "int64", // Type.类型标记
|
||||
Index: []KList{KList{Key: ColumusKeyPrimary}}, // index list.index列表
|
||||
})
|
||||
result = append(result, ColumusInfo{
|
||||
BaseInfo: BaseInfo{Name: "created_at", Notes: "created time"},
|
||||
Type: "time.Time", // Type.类型标记
|
||||
})
|
||||
result = append(result, ColumusInfo{
|
||||
BaseInfo: BaseInfo{Name: "updated_at", Notes: "updated time"},
|
||||
Type: "time.Time", // Type.类型标记
|
||||
})
|
||||
result = append(result, ColumusInfo{
|
||||
BaseInfo: BaseInfo{Name: "deleted_at", Notes: "deleted time"},
|
||||
Type: "time.Time", // Type.类型标记
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/xxjwxc/gormt/data/view/cnf"
|
||||
|
||||
"github.com/xxjwxc/public/mybigcamel"
|
||||
|
||||
"github.com/xxjwxc/gormt/data/config"
|
||||
@@ -203,14 +205,39 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
|
||||
for _, tab := range m.info.TabList {
|
||||
var pkg genstruct.GenPackage
|
||||
pkg.SetPackage(m.info.PackageName) //package name
|
||||
pkg.AddImport(`"github.com/jinzhu/gorm"`)
|
||||
pkg.AddImport(`"fmt"`)
|
||||
|
||||
// tmpl, err := template.New("gen_logic").Funcs(template.FuncMap{"GetStringList": GetStringList}).Parse(genfunc.GetGenBaseTemp())
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// var buf bytes.Buffer
|
||||
// tmpl.Execute(&buf, m.info)
|
||||
data := struct {
|
||||
StructName string
|
||||
TableName string
|
||||
Em []ColumusInfo
|
||||
}{
|
||||
StructName: getCamelName(tab.Name),
|
||||
TableName: tab.Name,
|
||||
}
|
||||
|
||||
for _, el := range tab.Em {
|
||||
if strings.EqualFold(el.Type, "gorm.Model") {
|
||||
data.Em = append(data.Em, getGormModelElement()...)
|
||||
} else {
|
||||
data.Em = append(data.Em, el)
|
||||
if v2, ok := cnf.EImportsHead[el.Type]; ok {
|
||||
if len(v2) > 0 {
|
||||
pkg.AddImport(v2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tmpl, err := template.New("gen_logic").Parse(genfunc.GetGenLogicTemp())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
tmpl.Execute(&buf, data)
|
||||
|
||||
pkg.AddFuncStr(buf.String())
|
||||
genOut = append(genOut, GenOutInfo{
|
||||
FileName: fmt.Sprintf("gen.%v.go", tab.Name),
|
||||
FileCtx: pkg.Generate(),
|
||||
|
||||
Reference in New Issue
Block a user