修改,兼容go-admin sdk方案

This commit is contained in:
linwenxiang committed 2021-03-09 19:12:49 +08:00
1 parent c541d09076
commit 25d8364bf4
151 files changed
+578 -3525

No files matched your search

+2 -2
View File
@@ -2,7 +2,7 @@ package models
import (
"fmt"
"go-admin/tools/app"
"go-admin/common/global"
"gorm.io/gorm"
"io/ioutil"
"log"
@@ -12,7 +12,7 @@ import (
func InitDb(db *gorm.DB) (err error) {
filePath := "config/db.sql"
err = ExecSql(db, filePath)
if app.Driver == "postgres" {
if global.Driver == "postgres" {
filePath = "config/pg.sql"
err = ExecSql(db, filePath)
}
+4 -4
View File
@@ -2,11 +2,11 @@ package models
import (
"errors"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"
"go-admin/app/admin/models/system"
"go-admin/tools"
)
type Menu struct {
@@ -274,7 +274,7 @@ func (e *Menu) GetPage(tx *gorm.DB) (Menus []Menu, err error) {
// 数据权限控制
dataPermission := new(system.DataPermission)
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
dataPermission.UserId, _ = pkg.StringToInt(e.DataScope)
table, err = dataPermission.GetDataScope("sys_menu", table)
if err != nil {
return nil, err
@@ -307,9 +307,9 @@ func InitPaths(tx *gorm.DB, menu *Menu) (err error) {
err = errors.New("父级paths异常,请尝试对当前节点父级菜单进行更新操作!")
return
}
menu.Paths = parentMenu.Paths + "/" + tools.IntToString(menu.MenuId)
menu.Paths = parentMenu.Paths + "/" + pkg.IntToString(menu.MenuId)
} else {
menu.Paths = "/0/" + tools.IntToString(menu.MenuId)
menu.Paths = "/0/" + pkg.IntToString(menu.MenuId)
}
tx.Table("sys_menu").Where("menu_id = ?", menu.MenuId).Update("paths", menu.Paths)
return
+1 -1
View File
@@ -37,4 +37,4 @@ func (e *SysFileDir) Generate() models.ActiveRecord {
func (e *SysFileDir) GetId() interface{} {
return e.Id
}
}
+2 -2
View File
@@ -9,7 +9,7 @@ type SysFileInfo struct {
Type string `json:"type" gorm:"type:varchar(255);comment:类型"` //
Name string `json:"name" gorm:"type:varchar(255);comment:名称"` //
Size string `json:"size" gorm:"type:int(11);comment:大小"` //
PId int `json:"pId" gorm:"type:int(11);comment:目录"` //
PId int `json:"pId" gorm:"type:int(11);comment:目录"` //
Source string `json:"source" gorm:"type:varchar(255);comment:来源"` //
Url string `json:"url" gorm:"type:varchar(255);comment:地址"` //
FullUrl string `json:"fullUrl" gorm:"type:varchar(255);comment:全地址"` //
@@ -28,4 +28,4 @@ func (e *SysFileInfo) Generate() models.ActiveRecord {
func (e *SysFileInfo) GetId() interface{} {
return e.Id
}
}
+1 -1
View File
@@ -26,4 +26,4 @@ func (e *SysCategory) Generate() models.ActiveRecord {
func (e *SysCategory) GetId() interface{} {
return e.Id
}
}
+10 -10
View File
@@ -6,18 +6,18 @@ import (
)
type SysChinaAreaData struct {
models.Model
models.ControlBy
PId string `json:"pId" gorm:"type:int(11);comment:上级编码"`
Name string `json:"name" gorm:"type:varchar(128);comment:名称"`
CreateTime time.Time `json:"createTime" gorm:"type:timestamp;comment:CreateTime"`
UpdateTime time.Time `json:"updateTime" gorm:"type:timestamp;comment:UpdateTime"`
DeleteTime time.Time `json:"deleteTime" gorm:"type:timestamp;comment:DeleteTime"`
models.Model
models.ControlBy
PId string `json:"pId" gorm:"type:int(11);comment:上级编码"`
Name string `json:"name" gorm:"type:varchar(128);comment:名称"`
CreateTime time.Time `json:"createTime" gorm:"type:timestamp;comment:CreateTime"`
UpdateTime time.Time `json:"updateTime" gorm:"type:timestamp;comment:UpdateTime"`
DeleteTime time.Time `json:"deleteTime" gorm:"type:timestamp;comment:DeleteTime"`
}
func (SysChinaAreaData) TableName() string {
return "sys_china_area_data"
return "sys_china_area_data"
}
func (e *SysChinaAreaData) Generate() models.ActiveRecord {
@@ -27,4 +27,4 @@ func (e *SysChinaAreaData) Generate() models.ActiveRecord {
func (e *SysChinaAreaData) GetId() interface{} {
return e.Id
}
}
+5 -5
View File
@@ -2,11 +2,11 @@ package system
import (
"errors"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"
log "github.com/go-admin-team/go-admin-core/logger"
"go-admin/tools"
"go-admin/tools/config"
"github.com/go-admin-team/go-admin-core/sdk/config"
)
type DataPermission struct {
@@ -19,7 +19,7 @@ type DataPermission struct {
func (e *DataPermission) GetDataScope(tableName string, db *gorm.DB) (*gorm.DB, error) {
if !config.ApplicationConfig.EnableDP {
usageStr := `数据权限已经为您` + tools.Green(`关闭`) + `,如需开启请参考配置文件字段说明`
usageStr := `数据权限已经为您` + pkg.Green(`关闭`) + `,如需开启请参考配置文件字段说明`
log.Debug("%s\n", usageStr)
return db, nil
}
@@ -40,7 +40,7 @@ func (e *DataPermission) GetDataScope(tableName string, db *gorm.DB) (*gorm.DB,
db = db.Where(tableName+".create_by in (SELECT user_id from sys_user where dept_id = ? )", user.DeptId)
}
if role.DataScope == "4" {
db = db.Where(tableName+".create_by in (SELECT user_id from sys_user where sys_user.dept_id in(select dept_id from sys_dept where dept_path like ? ))", "%"+tools.IntToString(user.DeptId)+"%")
db = db.Where(tableName+".create_by in (SELECT user_id from sys_user where sys_user.dept_id in(select dept_id from sys_dept where dept_path like ? ))", "%"+pkg.IntToString(user.DeptId)+"%")
}
if role.DataScope == "5" || role.DataScope == "" {
db = db.Where(tableName+".create_by = ?", e.UserId)
@@ -71,7 +71,7 @@ func DataScopes(tableName string, userId int) func(db *gorm.DB) *gorm.DB {
return db.Where(tableName+".create_by in (SELECT user_id from sys_user where dept_id = ? )", user.DeptId)
}
if role.DataScope == "4" {
return db.Where(tableName+".create_by in (SELECT user_id from sys_user where sys_user.dept_id in(select dept_id from sys_dept where dept_path like ? ))", "%"+tools.IntToString(user.DeptId)+"%")
return db.Where(tableName+".create_by in (SELECT user_id from sys_user where sys_user.dept_id in(select dept_id from sys_dept where dept_path like ? ))", "%"+pkg.IntToString(user.DeptId)+"%")
}
if role.DataScope == "5" || role.DataScope == "" {
return db.Where(tableName+".create_by = ?", userId)
+2 -2
View File
@@ -3,7 +3,7 @@ package system
import (
"fmt"
log "github.com/go-admin-team/go-admin-core/logger"
"go-admin/tools"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"
)
@@ -21,7 +21,7 @@ func (u *Login) GetUser(tx *gorm.DB) (user SysUser, role SysRole, err error) {
return
}
fmt.Println(user.Password, u.Password)
_, err = tools.CompareHashAndPassword(user.Password, u.Password)
_, err = pkg.CompareHashAndPassword(user.Password, u.Password)
if err != nil {
log.Errorf("user login error, %s", err.Error())
return
+2 -3
View File
@@ -2,11 +2,10 @@ package system
import (
"fmt"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/casbin/casbin/v2"
"gorm.io/gorm"
"go-admin/tools"
)
type RoleMenu struct {
@@ -159,7 +158,7 @@ func (rm *RoleMenu) Insert(tx *gorm.DB, enforcer *casbin.SyncedEnforcer, roleId
}
func (rm *RoleMenu) Delete(tx *gorm.DB, RoleId string, MenuID string) (bool, error) {
rm.RoleId, _ = tools.StringToInt(RoleId)
rm.RoleId, _ = pkg.StringToInt(RoleId)
table := tx.Table("sys_role_menu").Where("role_id = ?", RoleId)
if MenuID != "" {
table = table.Where("menu_id = ?", MenuID)
+1 -1
View File
@@ -26,4 +26,4 @@ func (e *SysConfig) Generate() models.ActiveRecord {
func (e *SysConfig) GetId() interface{} {
return e.Id
}
}
+1 -1
View File
@@ -34,4 +34,4 @@ func (e *SysLoginLog) Generate() models.ActiveRecord {
func (e *SysLoginLog) GetId() interface{} {
return e.Id
}
}
+1 -1
View File
@@ -42,4 +42,4 @@ func (e *SysOperaLog) Generate() models.ActiveRecord {
func (e *SysOperaLog) GetId() interface{} {
return e.Id
}
}
+5 -5
View File
@@ -4,11 +4,11 @@ import "go-admin/common/models"
type SysPost struct {
PostId int `gorm:"primaryKey;autoIncrement" json:"postId"` //岗位编号
PostName string `gorm:"size:128;" json:"postName"` //岗位名称
PostCode string `gorm:"size:128;" json:"postCode"` //岗位代码
Sort int `gorm:"" json:"sort"` //岗位排序
Status int `gorm:"size:4;" json:"status"` //状态
Remark string `gorm:"size:255;" json:"remark"` //描述
PostName string `gorm:"size:128;" json:"postName"` //岗位名称
PostCode string `gorm:"size:128;" json:"postCode"` //岗位代码
Sort int `gorm:"" json:"sort"` //岗位排序
Status int `gorm:"size:4;" json:"status"` //状态
Remark string `gorm:"size:255;" json:"remark"` //描述
models.ControlBy
models.ModelTime
+6 -6
View File
@@ -4,12 +4,12 @@ import "go-admin/common/models"
type SysRole struct {
RoleId int `json:"roleId" gorm:"primaryKey;autoIncrement"` // 角色编码
RoleName string `json:"roleName" gorm:"size:128;"` // 角色名称
Status string `json:"status" gorm:"size:4;"` //
RoleKey string `json:"roleKey" gorm:"size:128;"` //角色代码
RoleSort int `json:"roleSort" gorm:""` //角色排序
Flag string `json:"flag" gorm:"size:128;"` //
Remark string `json:"remark" gorm:"size:255;"` //备注
RoleName string `json:"roleName" gorm:"size:128;"` // 角色名称
Status string `json:"status" gorm:"size:4;"` //
RoleKey string `json:"roleKey" gorm:"size:128;"` //角色代码
RoleSort int `json:"roleSort" gorm:""` //角色排序
Flag string `json:"flag" gorm:"size:128;"` //
Remark string `json:"remark" gorm:"size:255;"` //备注
Admin bool `json:"admin" gorm:"size:4;"`
DataScope string `json:"dataScope" gorm:"size:128;"`
Params string `json:"params" gorm:"-"`
+3 -3
View File
@@ -2,11 +2,11 @@ package tools
import (
"errors"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"
"go-admin/tools"
"go-admin/tools/config"
"github.com/go-admin-team/go-admin-core/sdk/config"
)
type DBColumns struct {
@@ -62,7 +62,7 @@ func (e *DBColumns) GetList(tx *gorm.DB) ([]DBColumns, error) {
table = table.Where("TABLE_NAME = ?", e.TableName).Order("ORDINAL_POSITION asc")
} else {
tools.Assert(true, "目前只支持mysql数据库", 500)
pkg.Assert(true, "目前只支持mysql数据库", 500)
}
if err := table.Find(&doc).Error; err != nil {
return doc, err
+4 -4
View File
@@ -2,11 +2,11 @@ package tools
import (
"errors"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"
"go-admin/tools"
config2 "go-admin/tools/config"
config2 "github.com/go-admin-team/go-admin-core/sdk/config"
)
type DBTables struct {
@@ -36,7 +36,7 @@ func (e *DBTables) GetPage(tx *gorm.DB, pageSize int, pageIndex int) ([]DBTables
return nil, 0, err
}
} else {
tools.Assert(true, "目前只支持mysql数据库", 500)
pkg.Assert(true, "目前只支持mysql数据库", 500)
}
//table.Count(&count)
@@ -56,7 +56,7 @@ func (e *DBTables) Get(tx *gorm.DB) (DBTables, error) {
return doc, err
}
} else {
tools.Assert(true, "目前只支持mysql数据库", 500)
pkg.Assert(true, "目前只支持mysql数据库", 500)
}
return doc, nil
}
+7 -7
View File
@@ -1,20 +1,20 @@
package models
import (
// "gorm.io/gorm"
// "gorm.io/gorm"
"go-admin/common/models"
)
type WfProcessClassify struct {
models.Model
models.ControlBy
Name string `json:"name" gorm:"type:varchar(255);comment:名称"`
models.Model
models.ControlBy
Name string `json:"name" gorm:"type:varchar(255);comment:名称"`
}
func (WfProcessClassify) TableName() string {
return "wf_process_classify"
return "wf_process_classify"
}
func (e *WfProcessClassify) Generate() models.ActiveRecord {
@@ -24,4 +24,4 @@ func (e *WfProcessClassify) Generate() models.ActiveRecord {
func (e *WfProcessClassify) GetId() interface{} {
return e.Id
}
}