diff --git a/server/model/request/sys_autocode.go b/server/model/request/sys_autocode.go index e163fef4..e5cbcc90 100644 --- a/server/model/request/sys_autocode.go +++ b/server/model/request/sys_autocode.go @@ -11,5 +11,6 @@ type TableReq struct { type ColumeReq struct { ColumeName string `json:"columeName";gorm:"column:colume_name"` DataType string `json:"dataType";gorm:"column:data_type"` + DataTypeLong string `json:"dataTypeLong";gorm:"column:data_type_long"` ColumeComment string `json:"columeComment";gorm:"column:colume_comment"` } diff --git a/server/model/sys_auto_code.go b/server/model/sys_auto_code.go index 6947995f..a4dc3e93 100644 --- a/server/model/sys_auto_code.go +++ b/server/model/sys_auto_code.go @@ -3,6 +3,7 @@ package model // 初始版本自动化代码工具 type AutoCodeStruct struct { StructName string `json:"structName"` + TableName string `json:"tableName"` PackageName string `json:"packageName"` Abbreviation string `json:"abbreviation"` Description string `json:"description"` @@ -15,6 +16,8 @@ type Field struct { FieldDesc string `json:"fieldDesc"` FieldType string `json:"fieldType"` FieldJson string `json:"fieldJson"` + DataType string `json:"dataType"` + DataTypeLong string `json:"dataTypeLong"` Comment string `json:"comment"` ColumnName string `json:"columnName"` FieldSearchType string `json:"fieldSearchType"` diff --git a/server/resource/template/te/model.go.tpl b/server/resource/template/te/model.go.tpl index 4d3a8dba..3125c14b 100644 --- a/server/resource/template/te/model.go.tpl +++ b/server/resource/template/te/model.go.tpl @@ -9,8 +9,14 @@ import ( type {{.StructName}} struct { gorm.Model {{- range .Fields}} {{- if eq .FieldType "bool" }} - {{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'"` + {{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:'{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}'{{- end -}}"` {{- else }} - {{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'"` + {{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:'{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}'{{- end -}}"` {{- end }} {{- end }} } + +{{ if .TableName }} +func ({{.StructName}}) TableName() string { + return "{{.TableName}}" +} +{{ end }} \ No newline at end of file diff --git a/server/service/sys_auto_code.go b/server/service/sys_auto_code.go index 8e785541..49b66c85 100644 --- a/server/service/sys_auto_code.go +++ b/server/service/sys_auto_code.go @@ -129,6 +129,6 @@ func GetDB() (err error, DBNames []request.DBReq) { } func GetColume(tableName string, dbName string) (err error, Columes []request.ColumeReq) { - err = global.GVA_DB.Raw("select COLUMN_NAME as 'colume_name', DATA_TYPE as 'data_type', COLUMN_COMMENT as 'colume_comment' from information_schema.COLUMNS where table_name = ? and table_schema = ?", tableName, dbName).Scan(&Columes).Error + err = global.GVA_DB.Raw("SELECT COLUMN_NAME colume_name,DATA_TYPE data_type,CASE DATA_TYPE WHEN 'longtext' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'varchar' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'double' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'decimal' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'int' THEN c.NUMERIC_PRECISION WHEN 'bigint' THEN c.NUMERIC_PRECISION ELSE '' END AS data_type_long,COLUMN_COMMENT colume_comment FROM INFORMATION_SCHEMA.COLUMNS c WHERE table_name = ? AND table_schema = ?", tableName, dbName).Scan(&Columes).Error return err, Columes } diff --git a/web/src/utils/stringFun.js b/web/src/utils/stringFun.js index b0b6fb84..e8e61dce 100644 --- a/web/src/utils/stringFun.js +++ b/web/src/utils/stringFun.js @@ -10,4 +10,11 @@ export const toUpperCase = (str) => { export const toSQLLine = (str) => { if (str=="ID") return "ID" return str.replace(/([A-Z])/g,"_$1").toLowerCase(); - } \ No newline at end of file + } + + // 下划线转换驼峰 + export const toHump = (name) => { + return name.replace(/\_(\w)/g, function(all, letter){ + return letter.toUpperCase(); + }); +} \ No newline at end of file diff --git a/web/src/view/systemTools/autoCode/component/fieldDialog.vue b/web/src/view/systemTools/autoCode/component/fieldDialog.vue index 66c4011a..f8c5cda0 100644 --- a/web/src/view/systemTools/autoCode/component/fieldDialog.vue +++ b/web/src/view/systemTools/autoCode/component/fieldDialog.vue @@ -29,7 +29,7 @@ - + - + - + + + + + + - +
- + @@ -48,6 +48,9 @@ + + + @@ -71,7 +74,8 @@ - + + @@ -106,13 +110,14 @@ + id , created_at , updated_at , deleted_at 会自动生成请勿重复创建
生成代码包
- +