feat 调整 mysql 、pgsql 初始化数据; 完善pgsql 兼容性,适配代码生成逻辑

This commit is contained in:
孟帅
2025-11-08 12:40:03 +08:00
parent 3989996448
commit a7234bc330
49 changed files with 5360 additions and 5201 deletions

View File

@@ -9,12 +9,12 @@ package consts
const (
DemoTips = "演示系统已隐藏" // 演示系统敏感数据打码
NilJsonToString = "{}" // 空json初始化值
RegionSpilt = " / " // 地区分隔符
Unknown = "Unknown" // Unknown
SuperRoleKey = "super" // 超管角色唯一标识符,通过角色验证超管
MaxServeLogContentLen = 2048 // 最大保留服务日志内容大小
SysDefaultLanguage = "zh_CN" // 系统默认语言,当配置文件没有国际化配置时生效
NilJsonToString = "{}" // 空json初始化值
RegionSpilt = " / " // 地区分隔符
Unknown = "Unknown" // Unknown
SuperRoleKey = "super" // 超管角色唯一标识符,通过角色验证超管
MaxServeLogContentLen = 2048 // 最大保留服务日志内容大小
SysDefaultLanguage = "zh_CN" // 系统默认语言,当配置文件没有国际化配置时生效
)
// curd.
@@ -30,3 +30,8 @@ const (
MerchantId = "merchant_id" // 商户ID
UserId = "user_id" // 用户ID
)
const (
DBMysql = "mysql"
DBPgsql = "pgsql"
)

View File

@@ -1,9 +1,9 @@
// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2024 HotGo CLI
// @Copyright Copyright (c) 2025 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.7
// @AutoGenerate Version 2.18.6
package sys
import (
@@ -88,4 +88,4 @@ func (c *cCurdDemo) Status(ctx context.Context, req *curddemo.StatusReq) (res *c
func (c *cCurdDemo) Switch(ctx context.Context, req *curddemo.SwitchReq) (res *curddemo.SwitchRes, err error) {
err = service.SysCurdDemo().Switch(ctx, &req.CurdDemoSwitchInp)
return
}
}

View File

@@ -25,7 +25,7 @@ type SysAddonsConfigColumns struct {
AddonName string // 插件名称
Group string // 分组
Name string // 参数名称
Type string // 键值类型:string,int,uint,bool,datetime,date
Type string // 键值类型:string,int,uint,bool,TIMESTAMP,date
Key string // 参数键名
Value string // 参数键值
DefaultValue string // 默认值

View File

@@ -24,7 +24,7 @@ type SysConfigColumns struct {
Id string // 配置ID
Group string // 配置分组
Name string // 参数名称
Type string // 键值类型:string,int,uint,bool,datetime,date
Type string // 键值类型:string,int,uint,bool,TIMESTAMP,date
Key string // 参数键名
Value string // 参数键值
DefaultValue string // 默认值

View File

@@ -24,7 +24,7 @@ type SysDictDataColumns struct {
Id string // 字典数据ID
Label string // 字典标签
Value string // 字典键值
ValueType string // 键值数据类型string,int,uint,bool,datetime,date
ValueType string // 键值数据类型string,int,uint,bool,TIMESTAMP,date
Type string // 字典类型
ListClass string // 表格回显样式
IsDefault string // 是否为系统默认

View File

@@ -9,6 +9,7 @@ import (
"context"
"errors"
"fmt"
"hotgo/internal/consts"
"hotgo/internal/dao"
"math"
"strings"
@@ -35,6 +36,23 @@ CREATE TABLE IF NOT EXISTS %s (
PRIMARY KEY (id) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '管理员_casbin权限表' ROW_FORMAT = Dynamic;
`
createPolicyTablePgSql = `CREATE TABLE IF NOT EXISTS "public"."%s" (
"id" int8 NOT NULL DEFAULT nextval('hg_admin_role_casbin_id_seq'::regclass),
"p_type" varchar(64) COLLATE "pg_catalog"."default",
"v0" varchar(256) COLLATE "pg_catalog"."default",
"v1" varchar(256) COLLATE "pg_catalog"."default",
"v2" varchar(256) COLLATE "pg_catalog"."default",
"v3" varchar(256) COLLATE "pg_catalog"."default",
"v4" varchar(256) COLLATE "pg_catalog"."default",
"v5" varchar(256) COLLATE "pg_catalog"."default",
CONSTRAINT "hg_admin_role_casbin_pkey" PRIMARY KEY ("id")
)
;
ALTER TABLE "public"."%s"
OWNER TO "postgres";
COMMENT ON TABLE "public"."%s" IS '管理员_casbin权限表';`
)
type (
@@ -106,6 +124,10 @@ func (a *adapter) model() *gdb.Model {
// create a policy table when it's not exists.
func (a *adapter) createPolicyTable() (err error) {
if a.db.GetConfig().Type == consts.DBPgsql {
_, err = a.db.Exec(context.TODO(), fmt.Sprintf(createPolicyTablePgSql, a.table, a.table, a.table))
return
}
_, err = a.db.Exec(context.TODO(), fmt.Sprintf(createPolicyTableSql, a.table))
return
}
@@ -154,7 +176,7 @@ func (a *adapter) SavePolicy(model model.Model) (err error) {
}
if count := len(policyRules); count > 0 {
if _, err = a.model().OmitEmptyData().Insert(policyRules); err != nil {
if _, err = a.model().OmitEmptyData().FieldsEx(policyColumnsName.ID).Insert(policyRules); err != nil {
return
}
}
@@ -163,7 +185,7 @@ func (a *adapter) SavePolicy(model model.Model) (err error) {
// AddPolicy adds a policy rule to the storage.
func (a *adapter) AddPolicy(sec string, ptype string, rule []string) (err error) {
_, err = a.model().OmitEmptyData().Insert(a.buildPolicyRule(ptype, rule))
_, err = a.model().OmitEmptyData().FieldsEx(policyColumnsName.ID).Insert(a.buildPolicyRule(ptype, rule))
return
}
@@ -179,7 +201,7 @@ func (a *adapter) AddPolicies(sec string, ptype string, rules [][]string) (err e
policyRules = append(policyRules, a.buildPolicyRule(ptype, rule))
}
_, err = a.model().OmitEmptyData().Insert(policyRules)
_, err = a.model().OmitEmptyData().FieldsEx(policyColumnsName.ID).Insert(policyRules)
return
}

View File

@@ -11,7 +11,7 @@ import (
//_ "github.com/gogf/gf/contrib/drivers/mssql/v2"
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
//_ "github.com/gogf/gf/contrib/drivers/oracle/v2"
//_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
//_ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
// do not add dm in cli pre-compilation,

View File

@@ -8,24 +8,72 @@ package views
import (
"context"
"fmt"
"strings"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"hotgo/internal/consts"
"hotgo/internal/library/hggen/internal/cmd/gendao"
"hotgo/internal/model/input/sysin"
"strings"
)
// DoTableColumns 获取指定表生成字段列表
func DoTableColumns(ctx context.Context, in *sysin.GenCodesColumnListInp, config gendao.CGenDaoInput) (fields []*sysin.GenCodesColumnListModel, err error) {
var (
sql = "select ORDINAL_POSITION as `id`, COLUMN_NAME as `name`, COLUMN_COMMENT as `dc`, DATA_TYPE as `dataType`, COLUMN_TYPE as `sqlType`, CHARACTER_MAXIMUM_LENGTH as `length`, IS_NULLABLE as `isAllowNull`, COLUMN_DEFAULT as `defaultValue`, COLUMN_KEY as `index`, EXTRA as `extra` from information_schema.COLUMNS where TABLE_SCHEMA = '%s' and TABLE_NAME = '%s' ORDER BY `id` ASC"
sql string
conf = g.DB(in.Name).GetConfig()
)
err = g.DB(in.Name).Ctx(ctx).Raw(fmt.Sprintf(sql, conf.Name, in.Table)).Scan(&fields)
// 根据数据库类型使用不同的SQL
if conf.Type == consts.DBPgsql {
// PostgreSQL: 使用pg_catalog查询列详细信息
sql = `
SELECT
a.attnum as id,
a.attname as name,
COALESCE(col_description(a.attrelid, a.attnum), '') as dc,
t.typname as dataType,
CASE
WHEN a.atttypmod > 0 THEN t.typname || '(' || (a.atttypmod - 4) || ')'
ELSE t.typname
END as sqlType,
CASE
WHEN a.atttypmod > 0 THEN a.atttypmod - 4
ELSE NULL
END as length,
CASE WHEN a.attnotnull THEN 'NO' ELSE 'YES' END as isAllowNull,
pg_get_expr(ad.adbin, ad.adrelid) as defaultValue,
CASE
WHEN pk.contype = 'p' THEN 'PRI'
WHEN uk.contype = 'u' THEN 'UNI'
ELSE ''
END as "index",
CASE
WHEN ad.adbin IS NOT NULL AND ad.adbin LIKE '%nextval%' THEN 'auto_increment'
ELSE ''
END as extra
FROM pg_attribute a
JOIN pg_class c ON a.attrelid = c.oid
JOIN pg_namespace n ON c.relnamespace = n.oid
JOIN pg_type t ON a.atttypid = t.oid
LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum
LEFT JOIN pg_constraint pk ON pk.conrelid = c.oid AND pk.contype = 'p' AND a.attnum = ANY(pk.conkey)
LEFT JOIN pg_constraint uk ON uk.conrelid = c.oid AND uk.contype = 'u' AND a.attnum = ANY(uk.conkey)
WHERE n.nspname = 'public'
AND c.relname = '%s'
AND a.attnum > 0
AND NOT a.attisdropped
ORDER BY a.attnum`
sql = fmt.Sprintf(sql, in.Table)
} else {
// MySQL: 使用information_schema.COLUMNS
sql = fmt.Sprintf("SELECT ORDINAL_POSITION as id, COLUMN_NAME as name, COLUMN_COMMENT as dc, DATA_TYPE as dataType, COLUMN_TYPE as sqlType, CHARACTER_MAXIMUM_LENGTH as length, IS_NULLABLE as isAllowNull, COLUMN_DEFAULT as defaultValue, COLUMN_KEY as `index`, EXTRA as extra FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s' ORDER BY id ASC", conf.Name, in.Table)
}
err = g.DB(in.Name).Ctx(ctx).Raw(sql).Scan(&fields)
if err != nil {
return nil, err
}

View File

@@ -9,12 +9,15 @@ package hgorm
import (
"context"
"fmt"
"strings"
"hotgo/utility/convert"
"hotgo/utility/db"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/text/gstr"
"hotgo/utility/convert"
"strings"
)
type daoInstance interface {
@@ -35,7 +38,8 @@ func LeftJoin(m *gdb.Model, masterTable, masterField, joinTable, alias, onField
// GenJoinOnRelation 生成关联表关联条件
func GenJoinOnRelation(masterTable, masterField, joinTable, alias, onField string) []string {
relation := fmt.Sprintf("`%s`.`%s` = `%s`.`%s`", alias, onField, masterTable, masterField)
q := db.GetQuoteChar()
relation := fmt.Sprintf("%s%s%s.%s%s%s = %s%s%s.%s%s%s", q, alias, q, q, onField, q, q, masterTable, q, q, masterField, q)
return []string{joinTable, alias, relation}
}
@@ -62,7 +66,7 @@ func JoinFields(ctx context.Context, entity interface{}, dao daoInstance, as str
field := gstr.CaseSnakeFirstUpper(gstr.StrEx(v, as))
if _, ok := fields[field]; ok {
columns = append(columns, fmt.Sprintf("`%s`.`%s` as `%s`", dao.Table(), field, v))
columns = append(columns, db.QuoteFieldAs(dao.Table(), field, v))
}
}
@@ -117,7 +121,7 @@ func GenJoinSelect(ctx context.Context, entity interface{}, dao daoInstance, joi
jd, joinField := getJoinAttribute(field)
if jd != nil {
if _, ok := jd.fields[joinField]; ok {
tmpFields = append(tmpFields, fmt.Sprintf("`%s`.`%s` as `%s`", jd.Alias, joinField, field))
tmpFields = append(tmpFields, db.QuoteFieldAs(jd.Alias, joinField, field))
continue
}
}
@@ -125,7 +129,7 @@ func GenJoinSelect(ctx context.Context, entity interface{}, dao daoInstance, joi
// 主表
originalField := gstr.CaseSnakeFirstUpper(field)
if _, ok := masterFields[originalField]; ok {
tmpFields = append(tmpFields, fmt.Sprintf("`%s`.`%s`", dao.Table(), originalField))
tmpFields = append(tmpFields, db.QuoteField(dao.Table(), originalField))
continue
}
}
@@ -143,7 +147,7 @@ func GetPkField(ctx context.Context, dao daoInstance) (string, error) {
}
for _, field := range fields {
if strings.ToUpper(field.Key) == "PRI" {
if strings.ToUpper(field.Key) == "PRI" {
return field.Name, nil
}
}

View File

@@ -6,16 +6,18 @@
package handler
import (
"fmt"
"regexp"
"hotgo/internal/consts"
"hotgo/internal/model/input/form"
"hotgo/utility/convert"
"hotgo/utility/db"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gutil"
"hotgo/internal/consts"
"hotgo/internal/model/input/form"
"hotgo/utility/convert"
"regexp"
)
// ISorter 排序器接口实现该接口即可使用Handler匹配排序支持多字段排序
@@ -62,7 +64,7 @@ func Sorter(in ISorter) func(m *gdb.Model) *gdb.Model {
if len(sorter2) > 0 {
sorter2 = mappingAndFilterToTableFields(fds, sorter2)
for _, v := range sorter2 {
v.ColumnKey = fmt.Sprintf("`%v`.`%v`", as, v.ColumnKey)
v.ColumnKey = db.QuoteField(as, v.ColumnKey)
}
newSorters = append(newSorters, sorter2...)
}
@@ -71,7 +73,7 @@ func Sorter(in ISorter) func(m *gdb.Model) *gdb.Model {
// 移除关联表字段
sorters = mappingAndFilterToTableFields(fields, removeSorterIndexes(sorters, removeIndex))
for _, v := range sorters {
v.ColumnKey = fmt.Sprintf("`%v`.`%v`", masterTable, v.ColumnKey)
v.ColumnKey = db.QuoteField(masterTable, v.ColumnKey)
}
sorters = append(newSorters, sorters...)
@@ -79,7 +81,7 @@ func Sorter(in ISorter) func(m *gdb.Model) *gdb.Model {
// 单表
sorters = mappingAndFilterToTableFields(fields, sorters)
for _, v := range sorters {
v.ColumnKey = fmt.Sprintf("`%v`.`%v`", masterTable, v.ColumnKey)
v.ColumnKey = db.QuoteField(masterTable, v.ColumnKey)
}
}
@@ -123,11 +125,11 @@ func Sorter(in ISorter) func(m *gdb.Model) *gdb.Model {
if len(aliases) > 0 {
for as, table := range aliases {
if table == masterTable {
return m.OrderDesc(fmt.Sprintf("`%v`.`%v`", as, pk))
return m.OrderDesc(db.QuoteField(as, pk))
}
}
}
return m.OrderDesc(fmt.Sprintf("`%v`.`%v`", masterTable, pk))
return m.OrderDesc(db.QuoteField(masterTable, pk))
}
}

View File

@@ -99,6 +99,11 @@ func (s *sAdminMenu) Edit(ctx context.Context, in *adminin.MenuEditInp) (err err
return
}
if (in.Type == 1 || in.Type == 2) && len(in.Component) == 0 {
err = gerror.Newf("请先设置目录组件/路径")
return
}
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
in.Pid, in.Level, in.Tree, err = hgorm.AutoUpdateTree(ctx, &dao.AdminMenu, in.Id, in.Pid)
if err != nil {
@@ -111,7 +116,7 @@ func (s *sAdminMenu) Edit(ctx context.Context, in *adminin.MenuEditInp) (err err
return err
}
} else {
if _, err = dao.AdminMenu.Ctx(ctx).Data(in).OmitNilData().Insert(); err != nil {
if _, err = dao.AdminMenu.Ctx(ctx).Data(in).OmitEmptyData().Insert(); err != nil {
err = gerror.Wrap(err, "新增菜单失败!")
return err
}
@@ -239,8 +244,8 @@ func (s *sAdminMenu) LoginPermissions(ctx context.Context, memberId int64) (list
var (
allPermissions []*Permissions
mod = dao.AdminMenu.Ctx(ctx).Fields(dao.AdminMenu.Columns().Permissions).
Where(dao.AdminMenu.Columns().Status, consts.StatusEnabled).
WhereNot(dao.AdminMenu.Columns().Permissions, "")
Where(dao.AdminMenu.Columns().Status, consts.StatusEnabled).
WhereNot(dao.AdminMenu.Columns().Permissions, "")
)
// 非超管验证允许的菜单列表

View File

@@ -60,6 +60,11 @@ func (s *sAdminNotice) Edit(ctx context.Context, in *adminin.NoticeEditInp) (err
return
}
if in.Content == "" {
err = gerror.New("请输入消息内容")
return
}
if in.Type == consts.NoticeTypeLetter && len(in.Receiver) == 0 {
err = gerror.New("私信类型必须选择接收人")
return

View File

@@ -297,7 +297,7 @@ func (s *sAdminOrder) List(ctx context.Context, in *adminin.OrderListInp) (list
// 操作人摘要信息
mod = mod.Hook(hook.MemberSummary)
totalCount, err = mod.Clone().Count(1)
totalCount, err = mod.Clone().Count()
if err != nil {
return
}

View File

@@ -178,7 +178,7 @@ func (s *sPayRefund) List(ctx context.Context, in *payin.PayRefundListInp) (list
mod = mod.WhereBetween(dao.PayRefund.Columns().CreatedAt, in.CreatedAt[0], in.CreatedAt[1])
}
totalCount, err = mod.Clone().Count(1)
totalCount, err = mod.Clone().Count()
if err != nil {
return
}

View File

@@ -1,9 +1,9 @@
// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2024 HotGo CLI
// @Copyright Copyright (c) 2025 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.7
// @AutoGenerate Version 2.18.6
package sys
import (
@@ -79,6 +79,15 @@ func (s *sSysCurdDemo) List(ctx context.Context, in *sysin.CurdDemoListInp) (lis
mod = mod.WhereIn(dao.SysGenCurdDemo.Columns().CreatedBy, ids)
}
// 查询删除者
if in.DeletedBy != "" {
ids, err := service.AdminMember().GetIdsByKeyword(ctx, in.DeletedBy)
if err != nil {
return nil, 0, err
}
mod = mod.WhereIn(dao.SysGenCurdDemo.Columns().DeletedBy, ids)
}
// 查询创建时间
if len(in.CreatedAt) == 2 {
mod = mod.WhereBetween(dao.SysGenCurdDemo.Columns().CreatedAt, in.CreatedAt[0], in.CreatedAt[1])
@@ -165,7 +174,7 @@ func (s *sSysCurdDemo) Delete(ctx context.Context, in *sysin.CurdDemoDeleteInp)
if _, err = s.Model(ctx).WherePri(in.Id).Data(g.Map{
dao.SysGenCurdDemo.Columns().DeletedBy: contexts.GetUserId(ctx),
dao.SysGenCurdDemo.Columns().DeletedAt: gtime.Now(),
}).Update(); err != nil {
}).Unscoped().Update(); err != nil {
err = gerror.Wrap(err, "删除CURD列表失败请稍后重试")
return
}
@@ -228,4 +237,4 @@ func (s *sSysCurdDemo) Switch(ctx context.Context, in *sysin.CurdDemoSwitchInp)
return
}
return
}
}

View File

@@ -8,12 +8,6 @@ package sys
import (
"context"
"fmt"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"
"hotgo/internal/consts"
"hotgo/internal/dao"
"hotgo/internal/library/hggen"
@@ -22,6 +16,13 @@ import (
"hotgo/internal/model/input/sysin"
"hotgo/internal/service"
"hotgo/utility/validate"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"
)
type sSysGenCodes struct{}
@@ -211,13 +212,30 @@ func (s *sSysGenCodes) Selects(ctx context.Context, in *sysin.GenCodesSelectsInp
// TableSelect 表选项
func (s *sSysGenCodes) TableSelect(ctx context.Context, in *sysin.GenCodesTableSelectInp) (res []*sysin.GenCodesTableSelectModel, err error) {
var (
sql = "SELECT TABLE_NAME as value, TABLE_COMMENT as label FROM information_schema.`TABLES` WHERE TABLE_SCHEMA = '%s'"
sql string
config = g.DB(in.Name).GetConfig()
disableTables = g.Cfg().MustGet(ctx, "hggen.disableTables").Strings()
lists []*sysin.GenCodesTableSelectModel
)
if err = g.DB(in.Name).Ctx(ctx).Raw(fmt.Sprintf(sql, config.Name)).Scan(&lists); err != nil {
// 根据数据库类型使用不同的SQL
if config.Type == consts.DBPgsql {
// PostgreSQL: 使用pg_catalog查询表和注释
sql = `
SELECT
c.relname as value,
COALESCE(obj_description(c.oid), '') as label
FROM pg_class c
JOIN pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
AND c.relkind = 'r'
ORDER BY c.relname`
} else {
// MySQL: 使用information_schema.TABLES
sql = fmt.Sprintf("SELECT TABLE_NAME as value, TABLE_COMMENT as label FROM information_schema.TABLES WHERE TABLE_SCHEMA = '%s'", config.Name)
}
if err = g.DB(in.Name).Ctx(ctx).Raw(sql).Scan(&lists); err != nil {
return
}
@@ -260,11 +278,32 @@ func (s *sSysGenCodes) TableSelect(ctx context.Context, in *sysin.GenCodesTableS
// ColumnSelect 表字段选项
func (s *sSysGenCodes) ColumnSelect(ctx context.Context, in *sysin.GenCodesColumnSelectInp) (res []*sysin.GenCodesColumnSelectModel, err error) {
var (
sql = "select COLUMN_NAME as value,COLUMN_COMMENT as label from information_schema.COLUMNS where TABLE_SCHEMA = '%s' and TABLE_NAME = '%s'"
sql string
config = g.DB(in.Name).GetConfig()
)
if err = g.DB(in.Name).Ctx(ctx).Raw(fmt.Sprintf(sql, config.Name, in.Table)).Scan(&res); err != nil {
// 根据数据库类型使用不同的SQL
if config.Type == consts.DBPgsql {
// PostgreSQL: 使用pg_catalog查询列注释
sql = `
SELECT
a.attname as value,
COALESCE(col_description(a.attrelid, a.attnum), '') as label
FROM pg_attribute a
JOIN pg_class c ON a.attrelid = c.oid
JOIN pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
AND c.relname = '%s'
AND a.attnum > 0
AND NOT a.attisdropped
ORDER BY a.attnum`
sql = fmt.Sprintf(sql, in.Table)
} else {
// MySQL: 使用information_schema.COLUMNS
sql = fmt.Sprintf("SELECT COLUMN_NAME as value, COLUMN_COMMENT as label FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'", config.Name, in.Table)
}
if err = g.DB(in.Name).Ctx(ctx).Raw(sql).Scan(&res); err != nil {
return
}

View File

@@ -71,7 +71,7 @@ func (s *sSysLoginLog) List(ctx context.Context, in *sysin.LoginLogListInp) (lis
mod = mod.Where(dao.SysLoginLog.Columns().Username, in.Username)
}
totalCount, err = mod.Clone().Count(1)
totalCount, err = mod.Clone().Count()
if err != nil || totalCount == 0 {
return
}

View File

@@ -74,7 +74,7 @@ func (s *sSysServeLog) List(ctx context.Context, in *sysin.ServeLogListInp) (lis
dao.SysLog.Table(), "sysLog", dao.SysLog.Columns().ReqId, // 关联表表名,别名,关联条件
)...)
totalCount, err = mod.Clone().Count(1)
totalCount, err = mod.Clone().Count()
if err != nil || totalCount == 0 {
return
}

View File

@@ -16,7 +16,7 @@ type SysAddonsConfig struct {
AddonName any // 插件名称
Group any // 分组
Name any // 参数名称
Type any // 键值类型:string,int,uint,bool,datetime,date
Type any // 键值类型:string,int,uint,bool,TIMESTAMP,date
Key any // 参数键名
Value any // 参数键值
DefaultValue any // 默认值

View File

@@ -15,7 +15,7 @@ type SysConfig struct {
Id any // 配置ID
Group any // 配置分组
Name any // 参数名称
Type any // 键值类型:string,int,uint,bool,datetime,date
Type any // 键值类型:string,int,uint,bool,TIMESTAMP,date
Key any // 参数键名
Value any // 参数键值
DefaultValue any // 默认值

View File

@@ -15,7 +15,7 @@ type SysDictData struct {
Id any // 字典数据ID
Label any // 字典标签
Value any // 字典键值
ValueType any // 键值数据类型string,int,uint,bool,datetime,date
ValueType any // 键值数据类型string,int,uint,bool,TIMESTAMP,date
Type any // 字典类型
ListClass any // 表格回显样式
IsDefault any // 是否为系统默认

View File

@@ -10,7 +10,7 @@ import (
// PayRefund is the golang structure for table pay_refund.
type PayRefund struct {
Id uint64 `json:"id" orm:"id" description:"主键ID"`
Id int64 `json:"id" orm:"id" description:"主键ID"`
MemberId int64 `json:"memberId" orm:"member_id" description:"会员ID"`
AppId string `json:"appId" orm:"app_id" description:"应用ID"`
OrderSn string `json:"orderSn" orm:"order_sn" description:"业务订单号"`

View File

@@ -14,7 +14,7 @@ type SysAddonsConfig struct {
AddonName string `json:"addonName" orm:"addon_name" description:"插件名称"`
Group string `json:"group" orm:"group" description:"分组"`
Name string `json:"name" orm:"name" description:"参数名称"`
Type string `json:"type" orm:"type" description:"键值类型:string,int,uint,bool,datetime,date"`
Type string `json:"type" orm:"type" description:"键值类型:string,int,uint,bool,TIMESTAMP,date"`
Key string `json:"key" orm:"key" description:"参数键名"`
Value string `json:"value" orm:"value" description:"参数键值"`
DefaultValue string `json:"defaultValue" orm:"default_value" description:"默认值"`

View File

@@ -13,7 +13,7 @@ type SysAttachment struct {
Id int64 `json:"id" orm:"id" description:"文件ID"`
AppId string `json:"appId" orm:"app_id" description:"应用ID"`
MemberId int64 `json:"memberId" orm:"member_id" description:"管理员ID"`
CateId uint64 `json:"cateId" orm:"cate_id" description:"上传分类"`
CateId int64 `json:"cateId" orm:"cate_id" description:"上传分类"`
Drive string `json:"drive" orm:"drive" description:"上传驱动"`
Name string `json:"name" orm:"name" description:"文件原始名"`
Kind string `json:"kind" orm:"kind" description:"上传类型"`

View File

@@ -13,7 +13,7 @@ type SysConfig struct {
Id int64 `json:"id" orm:"id" description:"配置ID"`
Group string `json:"group" orm:"group" description:"配置分组"`
Name string `json:"name" orm:"name" description:"参数名称"`
Type string `json:"type" orm:"type" description:"键值类型:string,int,uint,bool,datetime,date"`
Type string `json:"type" orm:"type" description:"键值类型:string,int,uint,bool,TIMESTAMP,date"`
Key string `json:"key" orm:"key" description:"参数键名"`
Value string `json:"value" orm:"value" description:"参数键值"`
DefaultValue string `json:"defaultValue" orm:"default_value" description:"默认值"`

View File

@@ -13,7 +13,7 @@ type SysDictData struct {
Id int64 `json:"id" orm:"id" description:"字典数据ID"`
Label string `json:"label" orm:"label" description:"字典标签"`
Value string `json:"value" orm:"value" description:"字典键值"`
ValueType string `json:"valueType" orm:"value_type" description:"键值数据类型string,int,uint,bool,datetime,date"`
ValueType string `json:"valueType" orm:"value_type" description:"键值数据类型string,int,uint,bool,TIMESTAMP,date"`
Type string `json:"type" orm:"type" description:"字典类型"`
ListClass string `json:"listClass" orm:"list_class" description:"表格回显样式"`
IsDefault int `json:"isDefault" orm:"is_default" description:"是否为系统默认"`

View File

@@ -12,7 +12,7 @@ import (
// SysGenCodes is the golang structure for table sys_gen_codes.
type SysGenCodes struct {
Id int64 `json:"id" orm:"id" description:"生成ID"`
GenType uint `json:"genType" orm:"gen_type" description:"生成类型"`
GenType int `json:"genType" orm:"gen_type" description:"生成类型"`
GenTemplate int `json:"genTemplate" orm:"gen_template" description:"生成模板"`
VarName string `json:"varName" orm:"var_name" description:"实体命名"`
Options *gjson.Json `json:"options" orm:"options" description:"配置选项"`

View File

@@ -14,7 +14,7 @@ type SysLog struct {
Id int64 `json:"id" orm:"id" description:"日志ID"`
ReqId string `json:"reqId" orm:"req_id" description:"对外ID"`
AppId string `json:"appId" orm:"app_id" description:"应用ID"`
MerchantId uint64 `json:"merchantId" orm:"merchant_id" description:"商户ID"`
MerchantId int64 `json:"merchantId" orm:"merchant_id" description:"商户ID"`
MemberId int64 `json:"memberId" orm:"member_id" description:"用户ID"`
Method string `json:"method" orm:"method" description:"提交类型"`
Module string `json:"module" orm:"module" description:"访问模块"`

View File

@@ -1,9 +1,9 @@
// Package sysin
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2024 HotGo CLI
// @Copyright Copyright (c) 2025 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.7
// @AutoGenerate Version 2.18.6
package sysin
import (
@@ -55,22 +55,18 @@ func (in *CurdDemoEditInp) Filter(ctx context.Context) (err error) {
if err := g.Validator().Rules("required").Data(in.Title).Messages("标题不能为空").Run(ctx); err != nil {
return err.Current()
}
// 验证描述
if err := g.Validator().Rules("required").Data(in.Description).Messages("描述不能为空").Run(ctx); err != nil {
return err.Current()
}
// 验证内容
if err := g.Validator().Rules("required").Data(in.Content).Messages("内容不能为空").Run(ctx); err != nil {
return err.Current()
}
// 验证排序
if err := g.Validator().Rules("required").Data(in.Sort).Messages("排序不能为空").Run(ctx); err != nil {
return err.Current()
}
return
}
@@ -100,6 +96,7 @@ type CurdDemoViewModel struct {
entity.SysGenCurdDemo
CreatedBySumma *hook.MemberSumma `json:"createdBySumma" dc:"创建者摘要信息"`
UpdatedBySumma *hook.MemberSumma `json:"updatedBySumma" dc:"更新者摘要信息"`
DeletedBySumma *hook.MemberSumma `json:"deletedBySumma" dc:"删除者摘要信息"`
}
// CurdDemoListInp 获取CURD列表列表
@@ -109,6 +106,7 @@ type CurdDemoListInp struct {
Title string `json:"title" dc:"标题"`
Description string `json:"description" dc:"描述"`
CreatedBy string `json:"createdBy" dc:"创建者"`
DeletedBy string `json:"deletedBy" dc:"删除者"`
CreatedAt []*gtime.Time `json:"createdAt" dc:"创建时间"`
TestCategoryName string `json:"testCategoryName" dc:"关联分类"`
}
@@ -129,6 +127,8 @@ type CurdDemoListModel struct {
CreatedBySumma *hook.MemberSumma `json:"createdBySumma" dc:"创建者摘要信息"`
UpdatedBy int64 `json:"updatedBy" dc:"更新者"`
UpdatedBySumma *hook.MemberSumma `json:"updatedBySumma" dc:"更新者摘要信息"`
DeletedBy int64 `json:"deletedBy" dc:"删除者"`
DeletedBySumma *hook.MemberSumma `json:"deletedBySumma" dc:"删除者摘要信息"`
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
UpdatedAt *gtime.Time `json:"updatedAt" dc:"修改时间"`
TestCategoryName string `json:"testCategoryName" dc:"关联分类"`
@@ -146,6 +146,7 @@ type CurdDemoExportModel struct {
Sort int `json:"sort" dc:"排序"`
CreatedBy int64 `json:"createdBy" dc:"创建者"`
UpdatedBy int64 `json:"updatedBy" dc:"更新者"`
DeletedBy int64 `json:"deletedBy" dc:"删除者"`
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
TestCategoryName string `json:"testCategoryName" dc:"关联分类"`
}
@@ -197,4 +198,4 @@ func (in *CurdDemoSwitchInp) Filter(ctx context.Context) (err error) {
return
}
type CurdDemoSwitchModel struct{}
type CurdDemoSwitchModel struct{}

View File

@@ -1,13 +1,13 @@
// Package genrouter
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2024 HotGo CLI
// @Copyright Copyright (c) 2025 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.7
// @AutoGenerate Version 2.18.6
package genrouter
import "hotgo/internal/controller/admin/sys"
func init() {
LoginRequiredRouter = append(LoginRequiredRouter, sys.CurdDemo) // CURD列表
}
}