|
|
@ -6,6 +6,8 @@ import (
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"text/template"
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/xxjwxc/gormt/data/view/cnf"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/xxjwxc/public/mybigcamel"
|
|
|
|
"github.com/xxjwxc/public/mybigcamel"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/xxjwxc/gormt/data/config"
|
|
|
|
"github.com/xxjwxc/gormt/data/config"
|
|
|
@ -203,14 +205,39 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
|
|
|
|
for _, tab := range m.info.TabList {
|
|
|
|
for _, tab := range m.info.TabList {
|
|
|
|
var pkg genstruct.GenPackage
|
|
|
|
var pkg genstruct.GenPackage
|
|
|
|
pkg.SetPackage(m.info.PackageName) //package name
|
|
|
|
pkg.SetPackage(m.info.PackageName) //package name
|
|
|
|
|
|
|
|
pkg.AddImport(`"github.com/jinzhu/gorm"`)
|
|
|
|
|
|
|
|
pkg.AddImport(`"fmt"`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data := struct {
|
|
|
|
|
|
|
|
StructName string
|
|
|
|
|
|
|
|
TableName string
|
|
|
|
|
|
|
|
Em []ColumusInfo
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
StructName: getCamelName(tab.Name),
|
|
|
|
|
|
|
|
TableName: tab.Name,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// tmpl, err := template.New("gen_logic").Funcs(template.FuncMap{"GetStringList": GetStringList}).Parse(genfunc.GetGenBaseTemp())
|
|
|
|
for _, el := range tab.Em {
|
|
|
|
// if err != nil {
|
|
|
|
if strings.EqualFold(el.Type, "gorm.Model") {
|
|
|
|
// panic(err)
|
|
|
|
data.Em = append(data.Em, getGormModelElement()...)
|
|
|
|
// }
|
|
|
|
} else {
|
|
|
|
// var buf bytes.Buffer
|
|
|
|
data.Em = append(data.Em, el)
|
|
|
|
// tmpl.Execute(&buf, m.info)
|
|
|
|
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{
|
|
|
|
genOut = append(genOut, GenOutInfo{
|
|
|
|
FileName: fmt.Sprintf("gen.%v.go", tab.Name),
|
|
|
|
FileName: fmt.Sprintf("gen.%v.go", tab.Name),
|
|
|
|
FileCtx: pkg.Generate(),
|
|
|
|
FileCtx: pkg.Generate(),
|
|
|
|