修复模版生成bug
关联表 新增字段选择
This commit is contained in:
1 parent
50464dc6e6
commit
21d217c42a
3 files changed
+43
-12
No files matched your search
@@ -141,6 +141,13 @@ func GenCodeV2(c *gin.Context) {
|
|||||||
tools2.HasError(err, "", -1)
|
tools2.HasError(err, "", -1)
|
||||||
table.TableId = id
|
table.TableId = id
|
||||||
tab, _ := table.Get()
|
tab, _ := table.Get()
|
||||||
|
//for i := range tab.Columns {
|
||||||
|
// if tab.Columns[i].IsInsert == "1" {
|
||||||
|
// tab.Columns[i].IsInsert = "true"
|
||||||
|
// continue
|
||||||
|
// }
|
||||||
|
// tab.Columns[i].IsInsert = "false"
|
||||||
|
//}
|
||||||
|
|
||||||
if tab.IsActions == 1 {
|
if tab.IsActions == 1 {
|
||||||
ActionsGen(tab)
|
ActionsGen(tab)
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ type SysTables struct {
|
|||||||
Tree bool `gorm:"size:1;" json:"tree"`
|
Tree bool `gorm:"size:1;" json:"tree"`
|
||||||
Crud bool `gorm:"size:1;" json:"crud"`
|
Crud bool `gorm:"size:1;" json:"crud"`
|
||||||
Remark string `gorm:"size:255;" json:"remark"`
|
Remark string `gorm:"size:255;" json:"remark"`
|
||||||
IsDataScope int `gorm:"size:1;" json:"isDataScope"`
|
IsDataScope int `gorm:"size:1;" json:"isDataScope"`
|
||||||
IsActions int `gorm:"size:1;" json:"isActions"`
|
IsActions int `gorm:"size:1;" json:"isActions"`
|
||||||
IsAuth int `gorm:"size:1;" json:"isAuth"`
|
IsAuth int `gorm:"size:1;" json:"isAuth"`
|
||||||
IsLogicalDelete string `gorm:"size:1;" json:"isLogicalDelete"`
|
IsLogicalDelete string `gorm:"size:1;" json:"isLogicalDelete"`
|
||||||
LogicalDelete bool `gorm:"size:1;" json:"logicalDelete"`
|
LogicalDelete bool `gorm:"size:1;" json:"logicalDelete"`
|
||||||
LogicalDeleteColumn string `gorm:"size:128;" json:"logicalDeleteColumn"`
|
LogicalDeleteColumn string `gorm:"size:128;" json:"logicalDeleteColumn"`
|
||||||
@@ -160,16 +160,40 @@ func (e *SysTables) Update() (update SysTables, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tableNames := make([]string, 0)
|
||||||
|
for i := range e.Columns {
|
||||||
|
if e.Columns[i].FkTableName != "" {
|
||||||
|
tableNames = append(tableNames, e.Columns[i].FkTableName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tables := make([]SysTables, 0)
|
||||||
|
tableMap := make(map[string]*SysTables)
|
||||||
|
if len(tableNames) > 0 {
|
||||||
|
if err = orm.Eloquent.Table("sys_tables").Where("table_name in (?)", tableNames).Find(&tables).Error; err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i := range tables {
|
||||||
|
tableMap[tables[i].TBName] = &tables[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < len(e.Columns); i++ {
|
for i := 0; i < len(e.Columns); i++ {
|
||||||
if e.Columns[i].FkTableName != "" {
|
if e.Columns[i].FkTableName != "" {
|
||||||
tableNameList := strings.Split(e.Columns[i].FkTableName, "_")
|
t, ok := tableMap[e.Columns[i].FkTableName]
|
||||||
e.Columns[i].FkTableNameClass = ""
|
if ok {
|
||||||
e.Columns[i].FkTableNamePackage = ""
|
e.Columns[i].FkTableNameClass = t.ClassName
|
||||||
for a := 0; a < len(tableNameList); a++ {
|
e.Columns[i].FkTableNamePackage = t.ModuleName
|
||||||
strStart := string([]byte(tableNameList[a])[:1])
|
} else {
|
||||||
strEnd := string([]byte(tableNameList[a])[1:])
|
tableNameList := strings.Split(e.Columns[i].FkTableName, "_")
|
||||||
e.Columns[i].FkTableNameClass += strings.ToUpper(strStart) + strEnd
|
e.Columns[i].FkTableNameClass = ""
|
||||||
e.Columns[i].FkTableNamePackage += strings.ToLower(strStart) + strings.ToLower(strEnd)
|
e.Columns[i].FkTableNamePackage = ""
|
||||||
|
for a := 0; a < len(tableNameList); a++ {
|
||||||
|
strStart := string([]byte(tableNameList[a])[:1])
|
||||||
|
strEnd := string([]byte(tableNameList[a])[1:])
|
||||||
|
e.Columns[i].FkTableNameClass += strings.ToUpper(strStart) + strEnd
|
||||||
|
e.Columns[i].FkTableNamePackage += strings.ToLower(strStart) + strings.ToLower(strEnd)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, _ = e.Columns[i].Update()
|
_, _ = e.Columns[i].Update()
|
||||||
|
|||||||
@@ -143,7 +143,7 @@
|
|||||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||||
{{ range .Columns }}
|
{{ range .Columns }}
|
||||||
{{- $x := .IsInsert -}}
|
{{- $x := .IsInsert -}}
|
||||||
{{- if ($x) -}}
|
{{- if (eq $x "1") -}}
|
||||||
{{- if (.Pk) }}
|
{{- if (.Pk) }}
|
||||||
{{- else if eq .GoField "CreatedAt" -}}
|
{{- else if eq .GoField "CreatedAt" -}}
|
||||||
{{- else if eq .GoField "UpdatedAt" -}}
|
{{- else if eq .GoField "UpdatedAt" -}}
|
||||||
|
|||||||
Reference in new issue
Block a user