From 45a90fb86b8819b537e66f93969b534b0d3ad352 Mon Sep 17 00:00:00 2001 From: xh <11675084@qq.com> Date: Wed, 26 Nov 2025 01:21:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=A8=A1=E5=9E=8B=E8=A1=A5?= =?UTF-8?q?=E5=85=85type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tpl_utils/templates/gocode/model.go.tpl | 8 ++++---- .../tpl_utils/templates/gocode/sql.sql.tpl | 10 ++++++++++ server/app/service/generatorService/tpl_utils/tpl.go | 1 + server/app/service/generatorService/tpl_utils/utils.go | 10 ++++++++++ server/go.mod | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 server/app/service/generatorService/tpl_utils/templates/gocode/sql.sql.tpl diff --git a/server/app/service/generatorService/tpl_utils/templates/gocode/model.go.tpl b/server/app/service/generatorService/tpl_utils/templates/gocode/model.go.tpl index 5881f70..b78ba8e 100644 --- a/server/app/service/generatorService/tpl_utils/templates/gocode/model.go.tpl +++ b/server/app/service/generatorService/tpl_utils/templates/gocode/model.go.tpl @@ -11,14 +11,14 @@ type {{{ toUpperCamelCase .EntityName }}} struct { {{{- range .Columns }}} {{{- if not (contains $.SubTableFields .ColumnName) }}} {{{- if eq .GoField "is_delete" }}} - IsDelete soft_delete.DeletedAt `gorm:"column:{{{.ColumnName}}};not null;default:0;softDelete:flag,DeletedAtField:DeleteTime;comment:'是否删除: 0=否, 1=是'"` + IsDelete soft_delete.DeletedAt `gorm:"column:{{{.ColumnName}}};type:{{{toSqlType .ColumnType .ColumnLength}}};not null;default:0;softDelete:flag,DeletedAtField:DeleteTime;comment:'是否删除: 0=否, 1=是'"` {{{- else }}} {{{- if eq .GoType "core.NullTime" }}} - {{{ toUpperCamelCase .GoField }}} core.NullTime `gorm:"column:{{{.ColumnName}}};{{{ if eq .GoField "create_time" }}}autoCreateTime;{{{ else }}}{{{if eq .GoField "update_time"}}}autoUpdateTime;{{{ end }}}{{{ end }}}comment:'{{{ .ColumnComment }}}'"` + {{{ toUpperCamelCase .GoField }}} core.NullTime `gorm:"column:{{{.ColumnName}}};type:{{{toSqlType .ColumnType .ColumnLength}}};{{{ if eq .GoField "create_time" }}}autoCreateTime;{{{ else }}}{{{if eq .GoField "update_time"}}}autoUpdateTime;{{{ end }}}{{{ end }}}comment:'{{{ .ColumnComment }}}'"` {{{- else if .IsPk }}} - {{{ toUpperCamelCase .GoField }}} {{{.GoType }}} `gorm:"column:{{{.ColumnName}}};primarykey;{{{ if .IsIncrement}}}autoIncrement;{{{end}}}comment:'{{{ .ColumnComment }}}'"` + {{{ toUpperCamelCase .GoField }}} {{{.GoType }}} `gorm:"column:{{{.ColumnName}}};type:{{{toSqlType .ColumnType .ColumnLength}}};primarykey;{{{ if .IsIncrement}}}autoIncrement;{{{end}}}comment:'{{{ .ColumnComment }}}'"` {{{- else }}} - {{{ toUpperCamelCase .GoField }}} {{{goWithRespType .GoType }}} `gorm:"column:{{{.ColumnName}}};comment:'{{{ .ColumnComment }}}'"` + {{{ toUpperCamelCase .GoField }}} {{{goWithRespType .GoType }}} `gorm:"column:{{{.ColumnName}}};type:{{{toSqlType .ColumnType .ColumnLength}}};comment:'{{{ .ColumnComment }}}'"` {{{- end }}} {{{- end }}} diff --git a/server/app/service/generatorService/tpl_utils/templates/gocode/sql.sql.tpl b/server/app/service/generatorService/tpl_utils/templates/gocode/sql.sql.tpl new file mode 100644 index 0000000..3d199ae --- /dev/null +++ b/server/app/service/generatorService/tpl_utils/templates/gocode/sql.sql.tpl @@ -0,0 +1,10 @@ +INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, paths, component, is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'C', '{{{ .FunctionName }}}', '{{{nameToPath .ModuleName }}}/index', '{{{nameToPath .ModuleName }}}/index', 0, 1, 0, now(), now()); +INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) SELECT id, 'A', '{{{ .FunctionName }}}列表','admin:{{{ .ModuleName }}}:list', 0, 1, 0, now(), now() FROM x_system_auth_menu WHERE component='{{{nameToPath .ModuleName }}}/index'; +INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) SELECT id, 'A', '{{{ .FunctionName }}}全部列表','admin:{{{ .ModuleName }}}:listAll', 0, 1, 0, now(), now() FROM x_system_auth_menu WHERE component='{{{nameToPath .ModuleName }}}/index'; +INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) SELECT id, 'A', '{{{ .FunctionName }}}添加','admin:{{{ .ModuleName }}}:add', 0, 1, 0, now(), now() FROM x_system_auth_menu WHERE component='{{{nameToPath .ModuleName }}}/index'; +INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) SELECT id, 'A', '{{{ .FunctionName }}}编辑','admin:{{{ .ModuleName }}}:edit', 0, 1, 0, now(), now() FROM x_system_auth_menu WHERE component='{{{nameToPath .ModuleName }}}/index'; +INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) SELECT id, 'A', '{{{ .FunctionName }}}删除','admin:{{{ .ModuleName }}}:del', 0, 1, 0, now(), now() FROM x_system_auth_menu WHERE component='{{{nameToPath .ModuleName }}}/index'; +INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) SELECT id, 'A', '{{{ .FunctionName }}}删除-批量','admin:{{{ .ModuleName }}}:delBatch', 0, 1, 0, now(), now() FROM x_system_auth_menu WHERE component='{{{nameToPath .ModuleName }}}/index'; +INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) SELECT id, 'A', '{{{ .FunctionName }}}详情','admin:{{{ .ModuleName }}}:detail', 0, 1, 0, now(), now() FROM x_system_auth_menu WHERE component='{{{nameToPath .ModuleName }}}/index'; +INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) SELECT id, 'A', '{{{ .FunctionName }}}导出excel','admin:{{{ .ModuleName }}}:ExportFile', 0, 1, 0, now(), now() FROM x_system_auth_menu WHERE component='{{{nameToPath .ModuleName }}}/index'; +INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) SELECT id, 'A', '{{{ .FunctionName }}}导入excel','admin:{{{ .ModuleName }}}:ImportFile', 0, 1, 0, now(), now() FROM x_system_auth_menu WHERE component='{{{nameToPath .ModuleName }}}/index'; diff --git a/server/app/service/generatorService/tpl_utils/tpl.go b/server/app/service/generatorService/tpl_utils/tpl.go index 682b61a..14e8953 100644 --- a/server/app/service/generatorService/tpl_utils/tpl.go +++ b/server/app/service/generatorService/tpl_utils/tpl.go @@ -31,6 +31,7 @@ var TemplateUtil = templateUtil{ "nameToPath": GenUtil.NameToPath, "pathToName": GenUtil.PathToName, "deletePathPrefix": GenUtil.DeletePathPrefix, + "toSqlType": GenUtil.ToSqlType, }), } diff --git a/server/app/service/generatorService/tpl_utils/utils.go b/server/app/service/generatorService/tpl_utils/utils.go index 7fb3f01..4c779df 100644 --- a/server/app/service/generatorService/tpl_utils/utils.go +++ b/server/app/service/generatorService/tpl_utils/utils.go @@ -1,6 +1,7 @@ package tpl_utils import ( + "fmt" "strconv" "strings" "x_admin/config" @@ -324,3 +325,12 @@ func (gu genUtil) DeletePathPrefix(s string) string { s = strings.Replace(s, "/api/admin", "", 1) return s } + +// ToSqlType 转换数据库类型 +func (gu genUtil) ToSqlType(t string, len int) string { + // 去掉前缀urlPrefix + if len > 0 { + t += fmt.Sprintf("(%d)", len) + } + return t +} diff --git a/server/go.mod b/server/go.mod index f022273..a557435 100644 --- a/server/go.mod +++ b/server/go.mod @@ -34,6 +34,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/redis/go-redis/v9 v9.16.0 github.com/robfig/cron/v3 v3.0.1 + github.com/wneessen/go-mail v0.7.2 go.uber.org/ratelimit v0.3.1 golang.org/x/sync v0.18.0 golang.org/x/text v0.31.0 @@ -90,7 +91,6 @@ require ( github.com/tklauser/numcpus v0.11.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.3.1 // indirect - github.com/wneessen/go-mail v0.7.2 // indirect github.com/xuri/efp v0.0.1 // indirect github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect