feat: format reference
This commit is contained in:
1 parent
6877e1324c
commit
c69a7d9fd9
87 files changed
+1124
-287
No files matched your search
+5
-4
@@ -2,9 +2,10 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
_ "time"
|
||||
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
_ "time"
|
||||
)
|
||||
|
||||
type SysConfig struct {
|
||||
@@ -71,7 +72,7 @@ func (e *SysConfig) Get() (SysConfig, error) {
|
||||
func (e *SysConfig) GetPage(pageSize int, pageIndex int) ([]SysConfig, int, error) {
|
||||
var doc []SysConfig
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
if e.ConfigName != "" {
|
||||
table = table.Where("config_name = ?", e.ConfigName)
|
||||
@@ -92,10 +93,10 @@ func (e *SysConfig) GetPage(pageSize int, pageIndex int) ([]SysConfig, int, erro
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -3,9 +3,11 @@ package models
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"go-admin/tools"
|
||||
"go-admin/tools/config"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type DataPermission struct {
|
||||
|
||||
+3
-2
@@ -2,9 +2,10 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
_ "time"
|
||||
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
_ "time"
|
||||
)
|
||||
|
||||
type SysDept struct {
|
||||
@@ -101,7 +102,7 @@ func (e *SysDept) GetList() ([]SysDept, error) {
|
||||
func (e *SysDept) GetPage(bl bool) ([]SysDept, error) {
|
||||
var doc []SysDept
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.DeptId != 0 {
|
||||
table = table.Where("dept_id = ?", e.DeptId)
|
||||
}
|
||||
|
||||
+4
-3
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
)
|
||||
@@ -90,7 +91,7 @@ func (e *DictData) Get() ([]DictData, error) {
|
||||
func (e *DictData) GetPage(pageSize int, pageIndex int) ([]DictData, int, error) {
|
||||
var doc []DictData
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.DictCode != 0 {
|
||||
table = table.Where("dict_code = ?", e.DictCode)
|
||||
}
|
||||
@@ -113,10 +114,10 @@ func (e *DictData) GetPage(pageSize int, pageIndex int) ([]DictData, int, error)
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Order("dict_sort").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Order("dict_sort").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
+9
-5
@@ -2,6 +2,9 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
)
|
||||
@@ -83,13 +86,14 @@ func (e *DictType) GetList() ([]DictType, error) {
|
||||
|
||||
func (e *DictType) GetPage(pageSize int, pageIndex int) ([]DictType, int, error) {
|
||||
var doc []DictType
|
||||
var db *gorm.DB
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.DictId != 0 {
|
||||
table = table.Where("dict_id = ?", e.DictId)
|
||||
db = db.Where("dict_id = ?", e.DictId)
|
||||
}
|
||||
if e.DictName != "" {
|
||||
table = table.Where("dict_name = ?", e.DictName)
|
||||
db = db.Where("dict_name = ?", e.DictName)
|
||||
}
|
||||
|
||||
// 数据权限控制
|
||||
@@ -101,10 +105,10 @@ func (e *DictType) GetPage(pageSize int, pageIndex int) ([]DictType, int, error)
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ func (e *SysFileDir) Get() (SysFileDir, error) {
|
||||
func (e *SysFileDir) GetPage() ([]SysFileDir, int, error) {
|
||||
var doc []SysFileDir
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
//dataPermission := new(DataPermission)
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package gorm
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"go-admin/models"
|
||||
)
|
||||
|
||||
func InitData(db *gorm.DB) {
|
||||
|
||||
list := []models.CasbinRule{
|
||||
{"p", "admin", "/api/v1/menulist", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/menu", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/databytype/", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/menu", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/menu/:id", "DELETE", "", "", ""},
|
||||
{"p", "admin", "/api/v1/sysUserList", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/sysUser/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/sysUser/", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/sysUser", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/sysUser", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/sysUser/:id", "DELETE", "", "", ""},
|
||||
{"p", "admin", "/api/v1/user/profile", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/rolelist", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/role/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/role", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/role", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/role/:id", "DELETE", "", "", ""},
|
||||
{"p", "admin", "/api/v1/configList", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/config/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/config", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/config", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/config/:id", "DELETE", "", "", ""},
|
||||
{"p", "admin", "/api/v1/menurole", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/roleMenuTreeselect/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/menuTreeselect", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/rolemenu", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/rolemenu", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/rolemenu/:id", "DELETE", "", "", ""},
|
||||
{"p", "admin", "/api/v1/deptList", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dept/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dept", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dept", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dept/:id", "DELETE", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/datalist", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/data/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/databytype/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/data", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/data/", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/data/:id", "DELETE", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/typelist", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/type/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/type", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/type", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/type/:id", "DELETE", "", "", ""},
|
||||
{"p", "admin", "/api/v1/postlist", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/post/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/post", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/post", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/post/:id", "DELETE", "", "", ""},
|
||||
{"p", "admin", "/api/v1/menu/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/menuids", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/loginloglist", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/loginlog/:id", "DELETE", "", "", ""},
|
||||
{"p", "admin", "/api/v1/operloglist", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/getinfo", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/roledatascope", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/roleDeptTreeselect/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/deptTree", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/configKey/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/logout", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/user/avatar", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/user/pwd", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/dict/typeoptionselect", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/sysjobList", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/sysjob/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/sysjob", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/sysjob", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/sysjob/:id", "DELETE", "", "", ""},
|
||||
{"p", "admin", "/api/v1/syssettingList", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/syssetting/:id", "GET", "", "", ""},
|
||||
{"p", "admin", "/api/v1/syssetting", "POST", "", "", ""},
|
||||
{"p", "admin", "/api/v1/syssetting", "PUT", "", "", ""},
|
||||
{"p", "admin", "/api/v1/syssetting/:id", "DELETE", "", "", ""},
|
||||
}
|
||||
|
||||
db.Table("casbin_rule").Create(list)
|
||||
}
|
||||
+24
-83
@@ -1,93 +1,34 @@
|
||||
package gorm
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"go-admin/models"
|
||||
"go-admin/models/tools"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func AutoMigrate(db *gorm.DB) error {
|
||||
err := db.AutoMigrate(new(models.CasbinRule))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysDept))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysConfig))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(tools.SysTables))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(tools.SysColumns))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.Menu))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.LoginLog))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysOperLog))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.RoleMenu))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysRoleDept))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysUser))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysRole))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.Post))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.DictData))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.DictType))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysJob))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysConfig))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysSetting))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysFileDir))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysCategory))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(new(models.SysContent))
|
||||
func AutoMigrate(db *gorm.DB) (err error) {
|
||||
err = db.AutoMigrate(new(models.CasbinRule),
|
||||
new(models.SysDept),
|
||||
new(models.SysConfig),
|
||||
new(tools.SysTables),
|
||||
new(tools.SysColumns),
|
||||
new(models.Menu),
|
||||
new(models.LoginLog),
|
||||
new(models.SysOperLog),
|
||||
new(models.RoleMenu),
|
||||
new(models.SysRoleDept),
|
||||
new(models.SysUser),
|
||||
new(models.SysRole),
|
||||
new(models.Post),
|
||||
new(models.DictData),
|
||||
new(models.DictType),
|
||||
new(models.SysJob),
|
||||
new(models.SysConfig),
|
||||
new(models.SysSetting),
|
||||
new(models.SysFileDir),
|
||||
new(models.SysCategory),
|
||||
new(models.SysContent))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+4
-3
@@ -2,15 +2,16 @@ package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go-admin/global"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"go-admin/global"
|
||||
)
|
||||
|
||||
func InitDb() error {
|
||||
func InitDb() (err error) {
|
||||
filePath := "config/db.sql"
|
||||
err := ExecSql(filePath)
|
||||
err = ExecSql(filePath)
|
||||
if global.Driver == "postgres" {
|
||||
filePath = "config/pg.sql"
|
||||
err = ExecSql(filePath)
|
||||
|
||||
+5
-4
@@ -1,8 +1,9 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
orm "go-admin/global"
|
||||
"time"
|
||||
|
||||
orm "go-admin/global"
|
||||
)
|
||||
|
||||
type LoginLog struct {
|
||||
@@ -48,7 +49,7 @@ func (e *LoginLog) Get() (LoginLog, error) {
|
||||
func (e *LoginLog) GetPage(pageSize int, pageIndex int) ([]LoginLog, int, error) {
|
||||
var doc []LoginLog
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.Ipaddr != "" {
|
||||
table = table.Where("ipaddr = ?", e.Ipaddr)
|
||||
}
|
||||
@@ -61,10 +62,10 @@ func (e *LoginLog) GetPage(pageSize int, pageIndex int) ([]LoginLog, int, error)
|
||||
|
||||
var count int64
|
||||
|
||||
if err := table.Order("info_id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Order("info_id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
+5
-4
@@ -1,8 +1,9 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
orm "go-admin/global"
|
||||
"time"
|
||||
|
||||
orm "go-admin/global"
|
||||
)
|
||||
|
||||
//sys_operlog
|
||||
@@ -57,7 +58,7 @@ func (e *SysOperLog) Get() (SysOperLog, error) {
|
||||
func (e *SysOperLog) GetPage(pageSize int, pageIndex int) ([]SysOperLog, int, error) {
|
||||
var doc []SysOperLog
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.OperIp != "" {
|
||||
table = table.Where("oper_ip = ?", e.OperIp)
|
||||
}
|
||||
@@ -73,10 +74,10 @@ func (e *SysOperLog) GetPage(pageSize int, pageIndex int) ([]SysOperLog, int, er
|
||||
|
||||
var count int64
|
||||
|
||||
if err := table.Order("oper_id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Order("oper_id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -83,7 +83,7 @@ func (e *Post) GetList() ([]Post, error) {
|
||||
func (e *Post) GetPage(pageSize int, pageIndex int) ([]Post, int, error) {
|
||||
var doc []Post
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
if e.PostId != 0 {
|
||||
table = table.Where("post_id = ?", e.PostId)
|
||||
}
|
||||
@@ -106,10 +106,10 @@ func (e *Post) GetPage(pageSize int, pageIndex int) ([]Post, int, error) {
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Order("sort").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Order("sort").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
)
|
||||
@@ -35,7 +36,7 @@ type MenuIdList struct {
|
||||
func (role *SysRole) GetPage(pageSize int, pageIndex int) ([]SysRole, int, error) {
|
||||
var doc []SysRole
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("sys_role")
|
||||
table := orm.Eloquent.Table("sys_role")
|
||||
if role.RoleId != 0 {
|
||||
table = table.Where("role_id = ?", role.RoleId)
|
||||
}
|
||||
@@ -58,10 +59,10 @@ func (role *SysRole) GetPage(pageSize int, pageIndex int) ([]SysRole, int, error
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Order("role_sort").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Order("role_sort").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
orm "go-admin/global"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
@@ -62,7 +62,7 @@ func (e *SysCategory) Get() (SysCategory, error) {
|
||||
func (e *SysCategory) GetPage(pageSize int, pageIndex int) ([]SysCategory, int, error) {
|
||||
var doc []SysCategory
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
if e.Name != "" {
|
||||
table = table.Where("name = ?", e.Name)
|
||||
@@ -81,10 +81,10 @@ func (e *SysCategory) GetPage(pageSize int, pageIndex int) ([]SysCategory, int,
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ func (e *SysContent) Get() (SysContent, error) {
|
||||
func (e *SysContent) GetPage(pageSize int, pageIndex int) ([]SysContent, int, error) {
|
||||
var doc []SysContent
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
if e.CateId != "" {
|
||||
table = table.Where("cate_id = ?", e.CateId)
|
||||
@@ -91,10 +91,10 @@ func (e *SysContent) GetPage(pageSize int, pageIndex int) ([]SysContent, int, er
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ func (e *SysFileInfo) Get() (SysFileInfo, error) {
|
||||
func (e *SysFileInfo) GetPage(pageSize int, pageIndex int) ([]SysFileInfo, int, error) {
|
||||
var doc []SysFileInfo
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
if e.PId != 0 {
|
||||
table = table.Where("p_id = ?", e.PId)
|
||||
@@ -71,10 +71,10 @@ func (e *SysFileInfo) GetPage(pageSize int, pageIndex int) ([]SysFileInfo, int,
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -78,7 +78,7 @@ func (e *SysJob) Get() (SysJob, error) {
|
||||
func (e *SysJob) GetPage(pageSize int, pageIndex int) ([]SysJob, int, error) {
|
||||
var doc []SysJob
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
if e.JobId != 0 {
|
||||
table = table.Where("job_id = ?", e.JobId)
|
||||
@@ -113,17 +113,17 @@ func (e *SysJob) GetPage(pageSize int, pageIndex int) ([]SysJob, int, error) {
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
func (e *SysJob) GetList() ([]SysJob, error) {
|
||||
var doc []SysJob
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
table = table.Where("status = ?", 2)
|
||||
|
||||
|
||||
+7
-5
@@ -2,11 +2,13 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
// User
|
||||
@@ -222,10 +224,10 @@ func (e *SysUser) GetPage(pageSize int, pageIndex int) ([]SysUserPage, int, erro
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("sys_user.deleted_at IS NULL").Count(&count)
|
||||
//table.Where("sys_user.deleted_at IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,12 @@ package tools
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
config2 "go-admin/tools/config"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type DBColumns struct {
|
||||
@@ -29,7 +31,7 @@ func (e *DBColumns) GetPage(pageSize int, pageIndex int) ([]DBColumns, int, erro
|
||||
table := new(gorm.DB)
|
||||
|
||||
if config2.DatabaseConfig.Driver == "mysql" {
|
||||
table = orm.Eloquent.Select("*").Table("information_schema.`COLUMNS`")
|
||||
table = orm.Eloquent.Table("information_schema.`COLUMNS`")
|
||||
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
|
||||
|
||||
if e.TableName != "" {
|
||||
@@ -39,10 +41,10 @@ func (e *DBColumns) GetPage(pageSize int, pageIndex int) ([]DBColumns, int, erro
|
||||
table = table.Where("TABLE_NAME = ?", e.TableName)
|
||||
}
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
//table.Count(&count)
|
||||
return doc, int(count), nil
|
||||
|
||||
}
|
||||
@@ -56,7 +58,7 @@ func (e *DBColumns) GetList() ([]DBColumns, error) {
|
||||
}
|
||||
|
||||
if config2.DatabaseConfig.Driver == "mysql" {
|
||||
table = orm.Eloquent.Select("*").Table("information_schema.columns")
|
||||
table = orm.Eloquent.Table("information_schema.columns")
|
||||
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
|
||||
|
||||
table = table.Where("TABLE_NAME = ?", e.TableName).Order("ORDINAL_POSITION asc")
|
||||
|
||||
@@ -2,10 +2,12 @@ package tools
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
config2 "go-admin/tools/config"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type DBTables struct {
|
||||
@@ -24,21 +26,21 @@ func (e *DBTables) GetPage(pageSize int, pageIndex int) ([]DBTables, int, error)
|
||||
var count int64
|
||||
|
||||
if config2.DatabaseConfig.Driver == "mysql" {
|
||||
table = orm.Eloquent.Select("*").Table("information_schema.tables")
|
||||
table = orm.Eloquent.Table("information_schema.tables")
|
||||
table = table.Where("TABLE_NAME not in (select table_name from " + config2.GenConfig.DBName + ".sys_tables) ")
|
||||
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
|
||||
|
||||
if e.TableName != "" {
|
||||
table = table.Where("TABLE_NAME = ?", e.TableName)
|
||||
}
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
} else {
|
||||
tools.Assert(true, "目前只支持mysql数据库", 500)
|
||||
}
|
||||
|
||||
table.Count(&count)
|
||||
//table.Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
@@ -46,7 +48,7 @@ func (e *DBTables) Get() (DBTables, error) {
|
||||
var doc DBTables
|
||||
table := new(gorm.DB)
|
||||
if config2.DatabaseConfig.Driver == "mysql" {
|
||||
table = orm.Eloquent.Select("*").Table("information_schema.tables")
|
||||
table = orm.Eloquent.Table("information_schema.tables")
|
||||
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
|
||||
if e.TableName == "" {
|
||||
return doc, errors.New("table name cannot be empty!")
|
||||
|
||||
@@ -54,7 +54,7 @@ func (SysColumns) TableName() string {
|
||||
func (e *SysColumns) GetList() ([]SysColumns, error) {
|
||||
var doc []SysColumns
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("sys_columns")
|
||||
table := orm.Eloquent.Table("sys_columns")
|
||||
|
||||
table = table.Where("table_id = ?", e.TableId)
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
orm "go-admin/global"
|
||||
"go-admin/models"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SysTables struct {
|
||||
@@ -52,7 +53,7 @@ type Params struct {
|
||||
func (e *SysTables) GetPage(pageSize int, pageIndex int) ([]SysTables, int, error) {
|
||||
var doc []SysTables
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("sys_tables")
|
||||
table := orm.Eloquent.Table("sys_tables")
|
||||
|
||||
if e.TBName != "" {
|
||||
table = table.Where("table_name = ?", e.TBName)
|
||||
@@ -63,17 +64,17 @@ func (e *SysTables) GetPage(pageSize int, pageIndex int) ([]SysTables, int, erro
|
||||
|
||||
var count int64
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
func (e *SysTables) Get() (SysTables, error) {
|
||||
var doc SysTables
|
||||
var err error
|
||||
table := orm.Eloquent.Select("*").Table("sys_tables")
|
||||
table := orm.Eloquent.Table("sys_tables")
|
||||
|
||||
if e.TBName != "" {
|
||||
table = table.Where("table_name = ?", e.TBName)
|
||||
@@ -100,7 +101,7 @@ func (e *SysTables) Get() (SysTables, error) {
|
||||
func (e *SysTables) GetTree() ([]SysTables, error) {
|
||||
var doc []SysTables
|
||||
var err error
|
||||
table := orm.Eloquent.Select("*").Table("sys_tables")
|
||||
table := orm.Eloquent.Table("sys_tables")
|
||||
|
||||
if e.TBName != "" {
|
||||
table = table.Where("table_name = ?", e.TBName)
|
||||
|
||||
Reference in new issue
Block a user