mirror of
https://github.com/tiger1103/gfast.git
synced 2026-09-21 10:12:59 +00:00
代码生成类型匹配
This commit is contained in:
@@ -257,7 +257,7 @@ func (c *Gen) BatchGenCode(r *ghttp.Request) {
|
||||
//获取生成文件的目录
|
||||
func (c *Gen) getPath(entity *gen_table.EntityExtend) g.MapStrStr {
|
||||
controller := "app/controller/" + entity.ModuleName + "/" + entity.ClassName + ".go"
|
||||
service := "app/service/" + entity.ModuleName + "/" + entity.BusinessName + "/" + entity.ClassName + ".go"
|
||||
service := "app/service/" + entity.ModuleName + "/" + entity.BusinessName + "_service/" + entity.ClassName + ".go"
|
||||
model := "app/model/" + entity.ModuleName + "/" + entity.BusinessName + "/" + entity.ClassName + ".go"
|
||||
vue := "views/" + entity.ModuleName + "/" + entity.BusinessName + "/index.vue"
|
||||
api := "api/" + entity.ModuleName + "/" + entity.BusinessName + ".js"
|
||||
|
||||
@@ -42,7 +42,10 @@ func SelectDbTableColumnsByName(tableName string) ([]*Entity, error) {
|
||||
g.Log().Error(err)
|
||||
return nil, gerror.New("查询列信息失败")
|
||||
}
|
||||
result.Structs(&entity)
|
||||
err = result.Structs(&entity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/os/gtime"
|
||||
"github.com/gogf/gf/text/gregex"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -59,7 +61,6 @@ func ImportGenTable(tableList []*gen_table.Entity, operName string) error {
|
||||
tx.Rollback()
|
||||
return gerror.New("获取列数据失败")
|
||||
}
|
||||
|
||||
for _, column := range genTableColumns {
|
||||
InitColumnField(column, table)
|
||||
_, err = tx.Table("gen_table_column").Insert(column)
|
||||
@@ -167,21 +168,25 @@ func InitColumnField(column *gen_table_column.Entity, table *gen_table.Entity) {
|
||||
} else if gen_table_column.IsNumberObject(dataType) {
|
||||
//字段为数字类型
|
||||
column.HtmlType = "input"
|
||||
t, _ := gregex.ReplaceString(`\(.+\)`, "", column.ColumnType)
|
||||
t = gstr.Split(gstr.Trim(t), " ")[0]
|
||||
t = gstr.ToLower(t)
|
||||
// 如果是浮点型
|
||||
tmp := column.ColumnType
|
||||
start := strings.Index(tmp, "(")
|
||||
end := strings.Index(tmp, ")")
|
||||
result := "0"
|
||||
if start > 0 && end > 0 {
|
||||
result = tmp[start+1 : end]
|
||||
}
|
||||
arr := strings.Split(result, ",")
|
||||
if len(arr) == 2 && gconv.Int(arr[1]) > 0 {
|
||||
switch t {
|
||||
case "float", "double", "decimal":
|
||||
column.GoType = "float64"
|
||||
} else if len(arr) == 1 && gconv.Int(arr[0]) <= 10 {
|
||||
column.GoType = "int"
|
||||
} else {
|
||||
column.GoType = "int64"
|
||||
case "bit", "int", "tinyint", "small_int", "smallint", "medium_int", "mediumint":
|
||||
if gstr.ContainsI(column.ColumnType, "unsigned") {
|
||||
column.GoType = "uint"
|
||||
} else {
|
||||
column.GoType = "int"
|
||||
}
|
||||
case "big_int", "bigint":
|
||||
if gstr.ContainsI(column.ColumnType, "unsigned") {
|
||||
column.GoType = "uint64"
|
||||
} else {
|
||||
column.GoType = "int64"
|
||||
}
|
||||
}
|
||||
}
|
||||
//新增字段
|
||||
|
||||
Reference in New Issue
Block a user