refactor🎨: 生成逻辑调整

This commit is contained in:
zhangwenjian committed 2021-06-30 22:36:26 +08:00
1 parent d82129d364
commit eb8062d19b
5 files changed
+64 -55

No files matched your search

File renamed without changes.
+21 -14
View File
@@ -168,6 +168,7 @@ func (e Gen) GenApiToFile(c *gin.Context) {
func (e Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) { func (e Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) {
e.Context = c e.Context = c
log := e.GetLogger() log := e.GetLogger()
tab.MLTBName = strings.Replace(tab.TBName, "_", "-", -1)
basePath := "template/v4/" basePath := "template/v4/"
routerFile := basePath + "no_actions/router_check_role.go.template" routerFile := basePath + "no_actions/router_check_role.go.template"
@@ -223,8 +224,13 @@ func (e Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) {
_ = pkg.PathCreate("./app/" + tab.PackageName + "/models/") _ = pkg.PathCreate("./app/" + tab.PackageName + "/models/")
_ = pkg.PathCreate("./app/" + tab.PackageName + "/router/") _ = pkg.PathCreate("./app/" + tab.PackageName + "/router/")
_ = pkg.PathCreate("./app/" + tab.PackageName + "/service/dto/") _ = pkg.PathCreate("./app/" + tab.PackageName + "/service/dto/")
_ = pkg.PathCreate(config.GenConfig.FrontPath + "/api/") _ = pkg.PathCreate(config.GenConfig.FrontPath + "/api/" + tab.PackageName+ "/")
_ = pkg.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.ModuleFrontName) err = pkg.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.PackageName + "/" + tab.MLTBName+ "/")
if err != nil {
log.Error(err)
e.Error(500, err, fmt.Sprintf("views目录创建失败!错误详情:%s", err.Error()))
return
}
var b1 bytes.Buffer var b1 bytes.Buffer
err = t1.Execute(&b1, tab) err = t1.Execute(&b1, tab)
@@ -240,13 +246,13 @@ func (e Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) {
err = t6.Execute(&b6, tab) err = t6.Execute(&b6, tab)
var b7 bytes.Buffer var b7 bytes.Buffer
err = t7.Execute(&b7, tab) err = t7.Execute(&b7, tab)
pkg.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.ModuleName+".go") pkg.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.TBName+".go")
pkg.FileCreate(b2, "./app/"+tab.PackageName+"/apis/"+tab.ModuleName+".go") pkg.FileCreate(b2, "./app/"+tab.PackageName+"/apis/"+tab.TBName+".go")
pkg.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.ModuleName+".go") pkg.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.TBName+".go")
pkg.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.ModuleFrontName+".js") pkg.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+"/"+tab.MLTBName+".js")
pkg.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.ModuleFrontName+"/index.vue") pkg.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/"+tab.MLTBName+"/index.vue")
pkg.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.ModuleName+".go") pkg.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.TBName+".go")
pkg.FileCreate(b7, "./app/"+tab.PackageName+"/service/"+tab.ModuleName+".go") pkg.FileCreate(b7, "./app/"+tab.PackageName+"/service/"+tab.TBName+".go")
} }
@@ -365,19 +371,20 @@ func (e Gen) GenMenuAndApi(c *gin.Context) {
table := tools.SysTables{} table := tools.SysTables{}
id, err := pkg.StringToInt(c.Param("tableId")) id, err := pkg.StringToInt(c.Param("tableId"))
if err != nil{ if err != nil {
e.Logger.Error(err) e.Logger.Error(err)
e.Error(500,err,fmt.Sprintf("tableId参数解析失败!错误详情:%s", err.Error())) e.Error(500, err, fmt.Sprintf("tableId参数解析失败!错误详情:%s", err.Error()))
return return
} }
table.TableId = id table.TableId = id
tab, _ := table.Get(e.Orm) tab, _ := table.Get(e.Orm)
tab.MLTBName = strings.Replace(tab.TBName, "_", "-", -1)
Mmenu := dto.SysMenuControl{} Mmenu := dto.SysMenuControl{}
Mmenu.Title = tab.TableComment Mmenu.Title = tab.TableComment
Mmenu.Icon = "pass" Mmenu.Icon = "pass"
Mmenu.Path = "/" + strings.Replace(tab.TBName, "_", "-", -1) Mmenu.Path = "/" +tab.MLTBName
Mmenu.MenuType = "M" Mmenu.MenuType = "M"
Mmenu.Action = "无" Mmenu.Action = "无"
Mmenu.ParentId = 0 Mmenu.ParentId = 0
@@ -393,13 +400,13 @@ func (e Gen) GenMenuAndApi(c *gin.Context) {
Cmenu.MenuName = tab.ClassName + "Manage" Cmenu.MenuName = tab.ClassName + "Manage"
Cmenu.Title = tab.TableComment Cmenu.Title = tab.TableComment
Cmenu.Icon = "pass" Cmenu.Icon = "pass"
Cmenu.Path = tab.TBName Cmenu.Path = "/" + tab.PackageName + "/" + tab.MLTBName
Cmenu.MenuType = "C" Cmenu.MenuType = "C"
Cmenu.Action = "无" Cmenu.Action = "无"
Cmenu.Permission = tab.PackageName + ":" + tab.ModuleFrontName + ":list" Cmenu.Permission = tab.PackageName + ":" + tab.ModuleFrontName + ":list"
Cmenu.ParentId = Mmenu.MenuId Cmenu.ParentId = Mmenu.MenuId
Cmenu.NoCache = false Cmenu.NoCache = false
Cmenu.Component = "/" + tab.ModuleFrontName + "/index" Cmenu.Component = "/" + tab.PackageName + "/" + tab.MLTBName + "/index"
Cmenu.Sort = 0 Cmenu.Sort = 0
Cmenu.Visible = "0" Cmenu.Visible = "0"
Cmenu.IsFrame = "0" Cmenu.IsFrame = "0"
+37 -37
View File
@@ -6,43 +6,43 @@ import (
) )
type SysColumns struct { type SysColumns struct {
ColumnId int `gorm:"primaryKey;autoIncrement" json:"columnId"` ColumnId int `gorm:"primaryKey;autoIncrement" json:"columnId"`
TableId int `gorm:"" json:"tableId"` TableId int `gorm:"" json:"tableId"`
ColumnName string `gorm:"size:128;" json:"columnName"` ColumnName string `gorm:"size:128;" json:"columnName"`
ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"` ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"`
ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"` ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"`
GoType string `gorm:"column:go_type;size:128;" json:"goType"` GoType string `gorm:"column:go_type;size:128;" json:"goType"`
GoField string `gorm:"column:go_field;size:128;" json:"goField"` GoField string `gorm:"column:go_field;size:128;" json:"goField"`
JsonField string `gorm:"column:json_field;size:128;" json:"jsonField"` JsonField string `gorm:"column:json_field;size:128;" json:"jsonField"`
IsPk string `gorm:"column:is_pk;size:4;" json:"isPk"` IsPk string `gorm:"column:is_pk;size:4;" json:"isPk"`
IsIncrement string `gorm:"column:is_increment;size:4;" json:"isIncrement"` IsIncrement string `gorm:"column:is_increment;size:4;" json:"isIncrement"`
IsRequired string `gorm:"column:is_required;size:4;" json:"isRequired"` IsRequired string `gorm:"column:is_required;size:4;" json:"isRequired"`
IsInsert string `gorm:"column:is_insert;size:4;" json:"isInsert"` IsInsert string `gorm:"column:is_insert;size:4;" json:"isInsert"`
IsEdit string `gorm:"column:is_edit;size:4;" json:"isEdit"` IsEdit string `gorm:"column:is_edit;size:4;" json:"isEdit"`
IsList string `gorm:"column:is_list;size:4;" json:"isList"` IsList string `gorm:"column:is_list;size:4;" json:"isList"`
IsQuery string `gorm:"column:is_query;size:4;" json:"isQuery"` IsQuery string `gorm:"column:is_query;size:4;" json:"isQuery"`
QueryType string `gorm:"column:query_type;size:128;" json:"queryType"` QueryType string `gorm:"column:query_type;size:128;" json:"queryType"`
HtmlType string `gorm:"column:html_type;size:128;" json:"htmlType"` HtmlType string `gorm:"column:html_type;size:128;" json:"htmlType"`
DictType string `gorm:"column:dict_type;size:128;" json:"dictType"` DictType string `gorm:"column:dict_type;size:128;" json:"dictType"`
Sort int `gorm:"column:sort;" json:"sort"` Sort int `gorm:"column:sort;" json:"sort"`
List string `gorm:"column:list;size:1;" json:"list"` List string `gorm:"column:list;size:1;" json:"list"`
Pk bool `gorm:"column:pk;size:1;" json:"pk"` Pk bool `gorm:"column:pk;size:1;" json:"pk"`
Required bool `gorm:"column:required;size:1;" json:"required"` Required bool `gorm:"column:required;size:1;" json:"required"`
SuperColumn bool `gorm:"column:super_column;size:1;" json:"superColumn"` SuperColumn bool `gorm:"column:super_column;size:1;" json:"superColumn"`
UsableColumn bool `gorm:"column:usable_column;size:1;" json:"usableColumn"` UsableColumn bool `gorm:"column:usable_column;size:1;" json:"usableColumn"`
Increment bool `gorm:"column:increment;size:1;" json:"increment"` Increment bool `gorm:"column:increment;size:1;" json:"increment"`
Insert bool `gorm:"column:insert;size:1;" json:"insert"` Insert bool `gorm:"column:insert;size:1;" json:"insert"`
Edit bool `gorm:"column:edit;size:1;" json:"edit"` Edit bool `gorm:"column:edit;size:1;" json:"edit"`
Query bool `gorm:"column:query;size:1;" json:"query"` Query bool `gorm:"column:query;size:1;" json:"query"`
Remark string `gorm:"column:remark;size:255;" json:"remark"` Remark string `gorm:"column:remark;size:255;" json:"remark"`
FkTableName string `gorm:"" json:"fkTableName"` FkTableName string `gorm:"" json:"fkTableName"`
FkTableNameClass string `gorm:"" json:"fkTableNameClass"` FkTableNameClass string `gorm:"" json:"fkTableNameClass"`
FkTableNamePackage string `gorm:"" json:"fkTableNamePackage"` FkTableNamePackage string `gorm:"" json:"fkTableNamePackage"`
FkCol []SysColumns `gorm:"-" json:"fkCol"` FkCol []SysColumns `gorm:"-" json:"fkCol"`
FkLabelId string `gorm:"" json:"fkLabelId"` FkLabelId string `gorm:"" json:"fkLabelId"`
FkLabelName string `gorm:"size:255;" json:"fkLabelName"` FkLabelName string `gorm:"size:255;" json:"fkLabelName"`
CreateBy int `gorm:"column:create_by;size:20;" json:"createBy"` CreateBy int `gorm:"column:create_by;size:20;" json:"createBy"`
UpdateBy int `gorm:"column:update_By;size:20;" json:"updateBy"` UpdateBy int `gorm:"column:update_By;size:20;" json:"updateBy"`
models.BaseModel models.BaseModel
} }
+5 -3
View File
@@ -12,6 +12,7 @@ import (
type SysTables struct { type SysTables struct {
TableId int `gorm:"primaryKey;autoIncrement" json:"tableId"` //表编码 TableId int `gorm:"primaryKey;autoIncrement" json:"tableId"` //表编码
TBName string `gorm:"column:table_name;size:255;" json:"tableName"` //表名称 TBName string `gorm:"column:table_name;size:255;" json:"tableName"` //表名称
MLTBName string `gorm:"-" json:"-"` //表名称
TableComment string `gorm:"size:255;" json:"tableComment"` //表备注 TableComment string `gorm:"size:255;" json:"tableComment"` //表备注
ClassName string `gorm:"size:255;" json:"className"` //类名 ClassName string `gorm:"size:255;" json:"className"` //类名
TplCategory string `gorm:"size:255;" json:"tplCategory"` // TplCategory string `gorm:"size:255;" json:"tplCategory"` //
@@ -188,16 +189,17 @@ func (e *SysTables) Update(tx *gorm.DB) (update SysTables, err error) {
t, ok := tableMap[e.Columns[i].FkTableName] t, ok := tableMap[e.Columns[i].FkTableName]
if ok { if ok {
e.Columns[i].FkTableNameClass = t.ClassName e.Columns[i].FkTableNameClass = t.ClassName
e.Columns[i].FkTableNamePackage = t.ModuleName t.MLTBName = strings.Replace(t.TBName, "_", "-", -1)
e.Columns[i].FkTableNamePackage = t.MLTBName
} else { } else {
tableNameList := strings.Split(e.Columns[i].FkTableName, "_") tableNameList := strings.Split(e.Columns[i].FkTableName, "_")
e.Columns[i].FkTableNameClass = "" e.Columns[i].FkTableNameClass = ""
e.Columns[i].FkTableNamePackage = "" //e.Columns[i].FkTableNamePackage = ""
for a := 0; a < len(tableNameList); a++ { for a := 0; a < len(tableNameList); a++ {
strStart := string([]byte(tableNameList[a])[:1]) strStart := string([]byte(tableNameList[a])[:1])
strEnd := string([]byte(tableNameList[a])[1:]) strEnd := string([]byte(tableNameList[a])[1:])
e.Columns[i].FkTableNameClass += strings.ToUpper(strStart) + strEnd e.Columns[i].FkTableNameClass += strings.ToUpper(strStart) + strEnd
e.Columns[i].FkTableNamePackage += strings.ToLower(strStart) + strings.ToLower(strEnd) //e.Columns[i].FkTableNamePackage += strings.ToLower(strStart) + strings.ToLower(strEnd)
} }
} }
} }
+1 -1
View File
@@ -2,7 +2,7 @@ package global
const ( const (
// Version go-admin version info // Version go-admin version info
Version = "2.0.0-beta.7" Version = "2.0.0-beta.8"
) )
var ( var (