From 84f785cd03a79114cffcb6671b3ee2154a382a72 Mon Sep 17 00:00:00 2001 From: yxh Date: Tue, 15 Jul 2025 14:46:51 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90pg?= =?UTF-8?q?=E7=89=88=E5=AE=8C=E5=96=84=EF=BC=8C=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=97=A5=E5=BF=97=E6=B8=85=E7=90=86=EF=BC=8C=E5=85=B6?= =?UTF-8?q?=E5=AE=83=E7=BB=86=E8=8A=82=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/system/sys_job.go | 2 +- internal/app/system/controller/sys_job.go | 2 +- internal/app/system/logic/sysJob/sys_job.go | 3 - .../tools_gen_table_column.go | 136 +++++++++++------- internal/consts/version.go | 2 +- resource/template/vm/vue/edit-vue.template | 12 +- 6 files changed, 93 insertions(+), 64 deletions(-) diff --git a/api/v1/system/sys_job.go b/api/v1/system/sys_job.go index 4745536..2be458c 100644 --- a/api/v1/system/sys_job.go +++ b/api/v1/system/sys_job.go @@ -146,7 +146,7 @@ type SysJobLogListRes struct { type SysJobLogDeleteReq struct { g.Meta `path:"/deleteLogs" tags:"系统后台/定时任务" method:"delete" summary:"删除执行日志"` commonApi.Author - LogIds []uint64 `p:"logIds" v:"required#主键必须"` + TargetName string `p:"targetName" v:"required#日志标签名不能为空"` } type SysJobLogDeleteRes struct { diff --git a/internal/app/system/controller/sys_job.go b/internal/app/system/controller/sys_job.go index ded3f8b..1f1fbd4 100644 --- a/internal/app/system/controller/sys_job.go +++ b/internal/app/system/controller/sys_job.go @@ -77,6 +77,6 @@ func (c *sysJobController) Log(ctx context.Context, req *system.SysJobLogListReq } func (c *sysJobController) LogDelete(ctx context.Context, req *system.SysJobLogDeleteReq) (res *system.SysJobLogDeleteRes, err error) { - err = service.SysJobLog().Delete(ctx, req.LogIds) + err = service.SysJobLog().Delete(ctx, req.TargetName) return } diff --git a/internal/app/system/logic/sysJob/sys_job.go b/internal/app/system/logic/sysJob/sys_job.go index 9852a7d..719dbd4 100644 --- a/internal/app/system/logic/sysJob/sys_job.go +++ b/internal/app/system/logic/sysJob/sys_job.go @@ -60,9 +60,6 @@ func (s *sSysJob) List(ctx context.Context, req *system.SysJobSearchReq) (listRe req.PageSize = consts.PageSize } order := "job_id asc" - if req.OrderBy != "" { - order = req.OrderBy - } var res []*model.SysJobInfoRes err = m.Fields(system.SysJobSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res) liberr.ErrIsNil(ctx, err, "获取数据失败") diff --git a/internal/app/system/logic/toolsGenTableColumn/tools_gen_table_column.go b/internal/app/system/logic/toolsGenTableColumn/tools_gen_table_column.go index 13f91fb..48f423e 100644 --- a/internal/app/system/logic/toolsGenTableColumn/tools_gen_table_column.go +++ b/internal/app/system/logic/toolsGenTableColumn/tools_gen_table_column.go @@ -29,9 +29,9 @@ func init() { func New() service.IToolsGenTableColumn { return &sToolsGenTableColumn{ - ColumnTypeStr: []string{"char", "varchar", "narchar", "varchar2", "tinytext", "text", "mediumtext", "longtext"}, + ColumnTypeStr: []string{"char", "varchar", "narchar", "varchar2", "tinytext", "text", "mediumtext", "longtext", "character", "character varying", "json", "jsonb"}, ColumnTypeTime: []string{"datetime", "time", "date", "timestamp"}, - ColumnTypeNumber: []string{"tinyint", "smallint", "mediumint", "int", "number", "integer", "bigint", "float", "float", "double", "decimal"}, + ColumnTypeNumber: []string{"tinyint", "smallint", "mediumint", "int", "number", "integer", "bigint", "float", "float", "double", "decimal", "real", "numeric"}, ColumnNameNotEdit: []string{"created_by", "created_at", "updated_by", "updated_at", "deleted_at", "dept_id"}, ColumnNameNotList: []string{"updated_by", "updated_at", "deleted_at"}, ColumnNameNotDetail: []string{"updated_at", "deleted_at"}, @@ -65,16 +65,41 @@ func (s *sToolsGenTableColumn) SelectDbTableColumnsByName(ctx context.Context, t var res []*entity.ToolsGenTableColumn err := g.Try(ctx, func(ctx context.Context) { db := g.DB() + namespace := db.GetConfig().Namespace + if namespace == "" { + namespace = "public" + } var sql string if service.ToolsGenTable().IsPg() { //pg数据库 - sql = "select c.column_name,(case when c.is_nullable='YES' || k.column_name is not null then '1' else '0' end) as is_required," + - "(case when k.column_name is not null then '1' else '0' end) as is_pk,c.ordinal_position as sort_order_edit,d.description column_comment," + - "(case when c.column_default like 'nextval%' then '1' else '0' end) as is_increment,c.udt_name as column_type " + - "from information_schema.columns c " + - "left join pg_description d on d.objsubid=c.ordinal_position and d.objoid=c.table_name :: regclass " + - "left join information_schema.key_column_usage k on c.table_name=k.table_name and c.column_name=k.column_name and c.table_catalog=k.table_catalog and c.table_schema=k.table_schema " - sql += "where " + gdb.FormatSqlWithArgs(" c.table_name=? ", []interface{}{tableName}) + " order by c.ordinal_position" + sql = "SELECT" + + " a.attname AS column_name," + + " (NOT a.attnotnull OR i.indisprimary::int > 0)::text AS is_required," + + " i.indisprimary::text AS is_pk," + + " a.attnum AS sort_order_edit," + + " des.description AS column_comment," + + " (a.atthasdef OR (pg_get_expr(def.adbin, def.adrelid) ~ '^nextval'))::text AS is_increment," + + " format_type(a.atttypid, a.atttypmod) AS column_type" + + " FROM" + + " pg_class t" + + " JOIN" + + " pg_namespace n ON n.oid = t.relnamespace" + + " JOIN" + + " pg_attribute a ON a.attrelid = t.oid" + + " LEFT JOIN" + + " pg_description des ON des.objoid = t.oid AND des.objsubid = a.attnum" + + " LEFT JOIN" + + " pg_attrdef def ON def.adrelid = t.oid AND def.adnum = a.attnum" + + " LEFT JOIN (" + + " SELECT " + + " indrelid, " + + " UNNEST(indkey) AS colidx, " + + " indisprimary" + + " FROM " + + " pg_index" + + " ) i ON i.indrelid = t.oid AND i.colidx = a.attnum " + sql += " WHERE t.relkind = 'r' AND a.attnum > 0 AND NOT a.attisdropped AND" + + gdb.FormatSqlWithArgs(" t.relname = ? AND n.nspname = ? ", []interface{}{tableName, namespace}) + " order by a.attnum" } else if service.ToolsGenTable().IsDM() { dbName := g.DB().GetSchema() //达梦数据库 @@ -156,49 +181,8 @@ func (s *sToolsGenTableColumn) InitColumnField(column *entity.ToolsGenTableColum column.GoField = gstr.CaseCamel(columnName) column.HtmlField = gstr.CaseCamelLower(columnName) - if s.IsStringObject(dataType) { - //字段为字符串类型 - column.GoType = "string" - column.TsType = "string" - columnLength := s.GetColumnLength(column.ColumnType) - if columnLength >= 500 { - column.HtmlType = "textarea" - } else { - column.HtmlType = "input" - } - } else if s.IsTimeObject(dataType) { - //字段为时间类型 - column.GoType = "Time" - column.TsType = "string" - column.HtmlType = "datetime" - } else if s.IsNumberObject(dataType) { - //字段为数字类型 - column.HtmlType = "input" - t, _ := gregex.ReplaceString(`\(.+\)`, "", column.ColumnType) - t = gstr.Split(gstr.Trim(t), " ")[0] - t = gstr.ToLower(t) - // 如果是浮点型 - switch t { - case "float", "double", "decimal": - column.GoType = "float64" - 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" - } - } - column.TsType = "number" - } else if dataType == "bit" { - column.GoType = "bool" - column.TsType = "boolean" - } + //字段类型 + column.GoType, column.TsType, column.HtmlType = s.SetFieldType(dataType, column.ColumnType) // 编辑字段 if s.IsNotEdit(columnName) { @@ -261,6 +245,54 @@ func (s *sToolsGenTableColumn) InitColumnField(column *entity.ToolsGenTableColum column.CascadeColumnName = "" } +func (s *sToolsGenTableColumn) SetFieldType(sqlType, columnType string) (goType, tsType, htmlType string) { + if s.IsStringObject(sqlType) { + //字段为字符串类型 + goType = "string" + tsType = "string" + columnLength := s.GetColumnLength(columnType) + if columnLength >= 500 { + htmlType = "textarea" + } else { + htmlType = "input" + } + } else if s.IsTimeObject(sqlType) { + //字段为时间类型 + goType = "Time" + tsType = "string" + htmlType = "datetime" + } else if s.IsNumberObject(sqlType) { + //字段为数字类型 + htmlType = "input" + t, _ := gregex.ReplaceString(`\(.+\)`, "", columnType) + t = gstr.Split(gstr.Trim(t), " ")[0] + t = gstr.ToLower(t) + // 如果是浮点型 + switch t { + case "float", "double", "decimal", "numeric", "real": + goType = "float64" + case "bit", "int", "tinyint", "small_int", "smallint", "medium_int", "mediumint", "integer": + if gstr.ContainsI(columnType, "unsigned") { + goType = "uint" + } else { + goType = "int" + } + case "big_int", "bigint": + if gstr.ContainsI(columnType, "unsigned") { + goType = "uint64" + } else { + goType = "int64" + } + } + tsType = "number" + } else if sqlType == "bit" || sqlType == "boolean" || sqlType == "bool" { + goType = "bool" + tsType = "boolean" + } + + return +} + // GetDbType 获取数据库类型字段 func (s *sToolsGenTableColumn) GetDbType(columnType string) string { if strings.Index(columnType, "(") > 0 { diff --git a/internal/consts/version.go b/internal/consts/version.go index b1d378c..df14447 100644 --- a/internal/consts/version.go +++ b/internal/consts/version.go @@ -9,5 +9,5 @@ package consts const ( Logo = `CiAgIF9fX19fX19fX19fXyAgICAgICAgICAgX18gCiAgLyBfX19fLyBfX19fL19fXyBfX19fX18vIC9fCiAvIC8gX18vIC9fICAvIF9fIGAvIF9fXy8gX18vCi8gL18vIC8gX18vIC8gL18vIChfXyAgKSAvXyAgClxfX19fL18vICAgIFxfXyxfL19fX18vXF9fLyAg` - Version = "3.3.6" + Version = "3.3.7" ) diff --git a/resource/template/vm/vue/edit-vue.template b/resource/template/vm/vue/edit-vue.template index de61590..5a33151 100644 --- a/resource/template/vm/vue/edit-vue.template +++ b/resource/template/vm/vue/edit-vue.template @@ -13,7 +13,7 @@ {{if .table.IsPkInsertable}} - + {{end}} {{range $index, $column := .table.EditColumns}} @@ -30,16 +30,16 @@ {{else if eq $column.HtmlType "input"}} - + {{else if eq $column.HtmlType "inputNumber"}} - + {{else if eq $column.HtmlType "select" "selects"}} {{if ne $column.LinkTableName ""}} - + {{else if ne $column.DictType ""}} - + {{else}} - +