mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-14 05:03:49 +08:00
feat 调整 mysql 、pgsql 初始化数据; 完善pgsql 兼容性,适配代码生成逻辑
This commit is contained in:
@@ -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, "")
|
||||
)
|
||||
|
||||
// 非超管验证允许的菜单列表
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user