结构调整添加cmd

This commit is contained in:
zhangwenjian committed 2020-04-18 10:06:44 +08:00
1 parent f2829bfd98
commit a2f4c00246
72 files changed
+838 -597

No files matched your search

+2 -2
View File
@@ -2,7 +2,7 @@ package models
import (
orm "go-admin/database"
"go-admin/pkg/utils"
"go-admin/tools"
)
type SysConfig struct {
@@ -71,7 +71,7 @@ func (e *SysConfig) GetPage(pageSize int, pageIndex int) ([]SysConfig, int, erro
// 数据权限控制
dataPermission := new(DataPermission)
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
table = dataPermission.GetDataScope("sys_config", table)
var count int
+2 -2
View File
@@ -2,7 +2,7 @@ package models
import (
"github.com/jinzhu/gorm"
"go-admin/pkg/utils"
"go-admin/tools"
)
type DataPermission struct {
@@ -27,7 +27,7 @@ func (e *DataPermission) GetDataScope(tbname string, table *gorm.DB) *gorm.DB {
table = table.Where(tbname+".create_by in (SELECT user_id from sys_user where dept_id = ? )", user.DeptId)
}
if role.DataScope == "4" {
table = table.Where(tbname+".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 ? ))", "%"+utils.IntToString(user.DeptId)+"%")
table = table.Where(tbname+".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)+"%")
}
if role.DataScope == "5" || role.DataScope == "" {
table = table.Where(tbname+".create_by = ?", e.UserId)
+4 -4
View File
@@ -2,7 +2,7 @@ package models
import (
orm "go-admin/database"
"go-admin/pkg/utils"
"go-admin/tools"
)
type Dept struct {
@@ -40,7 +40,7 @@ func (e *Dept) Create() (Dept, error) {
err := result.Error
return doc, err
}
deptPath := "/" + utils.IntToString(e.DeptId)
deptPath := "/" + tools.IntToString(e.DeptId)
if int(e.ParentId) != 0 {
var deptP Dept
orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP)
@@ -115,7 +115,7 @@ func (e *Dept) GetPage(bl bool) ([]Dept, error) {
if bl {
// 数据权限控制
dataPermission := new(DataPermission)
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
table = dataPermission.GetDataScope("sys_dept", table)
}
@@ -173,7 +173,7 @@ func (e *Dept) Update(id int) (update Dept, err error) {
return
}
deptPath := "/" + utils.IntToString(e.DeptId)
deptPath := "/" + tools.IntToString(e.DeptId)
if int(e.ParentId) != 0 {
var deptP Dept
orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP)
+2 -2
View File
@@ -2,7 +2,7 @@ package models
import (
orm "go-admin/database"
"go-admin/pkg/utils"
"go-admin/tools"
)
type DictData struct {
@@ -98,7 +98,7 @@ func (e *DictData) GetPage(pageSize int, pageIndex int) ([]DictData, int, error)
// 数据权限控制
dataPermission := new(DataPermission)
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
table = dataPermission.GetDataScope("sys_dict_data", table)
var count int
+2 -2
View File
@@ -2,7 +2,7 @@ package models
import (
orm "go-admin/database"
"go-admin/pkg/utils"
"go-admin/tools"
)
type DictType struct {
@@ -86,7 +86,7 @@ func (e *DictType) GetPage(pageSize int, pageIndex int) ([]DictType, int, error)
// 数据权限控制
dataPermission := new(DataPermission)
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
table = dataPermission.GetDataScope("sys_dict_type", table)
var count int
+2 -2
View File
@@ -2,13 +2,13 @@ package gorm
import (
"github.com/jinzhu/gorm"
"go-admin/config"
"go-admin/models"
"go-admin/models/tools"
config2 "go-admin/tools/config"
)
func AutoMigrate(db *gorm.DB) error {
if config.DatabaseConfig.Dbtype == "mysql" {
if config2.DatabaseConfig.Dbtype == "mysql" {
db = db.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4")
}
db.SingularTable(true)
+2 -2
View File
@@ -2,15 +2,15 @@ package models
import (
"fmt"
"go-admin/config"
orm "go-admin/database"
config2 "go-admin/tools/config"
"io/ioutil"
"strings"
)
func InitDb() error {
filePath := "config/db.sql"
if config.DatabaseConfig.Dbtype == "sqlite3" {
if config2.DatabaseConfig.Dbtype == "sqlite3" {
fmt.Println("sqlite3数据库无需初始化!")
return nil
}
+4 -4
View File
@@ -2,7 +2,7 @@ package models
import (
orm "go-admin/database"
"go-admin/pkg"
"go-admin/tools"
"log"
"strings"
)
@@ -19,15 +19,15 @@ func (u *Login) GetUser() (user SysUser, role SysRole, e error) {
e = orm.Eloquent.Table("sys_user").Where("username = ? ", u.Username).Find(&user).Error
if e != nil {
if strings.Contains(e.Error(), "record not found") {
pkg.HasError(e, "账号或密码错误(代码204)", 500)
tools.HasError(e, "账号或密码错误(代码204)", 500)
}
log.Print(e)
return
}
_, e = pkg.CompareHashAndPassword(user.Password, u.Password)
_, e = tools.CompareHashAndPassword(user.Password, u.Password)
if e != nil {
if strings.Contains(e.Error(), "hashedPassword is not the hash of the given password") {
pkg.HasError(e, "账号或密码错误(代码201)", 500)
tools.HasError(e, "账号或密码错误(代码201)", 500)
}
log.Print(e)
return
+4 -4
View File
@@ -3,7 +3,7 @@ package models
import (
"errors"
orm "go-admin/database"
"go-admin/pkg/utils"
"go-admin/tools"
)
type Menu struct {
@@ -254,7 +254,7 @@ func (e *Menu) GetPage() (Menus []Menu, err error) {
// 数据权限控制
dataPermission := new(DataPermission)
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
table = dataPermission.GetDataScope("sys_menu", table)
if err = table.Order("sort").Find(&Menus).Error; err != nil {
@@ -285,9 +285,9 @@ func InitPaths(menu *Menu) (err error) {
err = errors.New("父级paths异常,请尝试对当前节点父级菜单进行更新操作!")
return
}
menu.Paths = parentMenu.Paths + "/" + utils.IntToString(menu.MenuId)
menu.Paths = parentMenu.Paths + "/" + tools.IntToString(menu.MenuId)
} else {
menu.Paths = "/0/" + utils.IntToString(menu.MenuId)
menu.Paths = "/0/" + tools.IntToString(menu.MenuId)
}
orm.Eloquent.Table("sys_menu").Where("menu_id = ?", menu.MenuId).Update("paths", menu.Paths)
return
+2 -2
View File
@@ -2,7 +2,7 @@ package models
import (
orm "go-admin/database"
"go-admin/pkg/utils"
"go-admin/tools"
)
type Post struct {
@@ -96,7 +96,7 @@ func (e *Post) GetPage(pageSize int, pageIndex int) ([]Post, int, error) {
// 数据权限控制
dataPermission := new(DataPermission)
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
table = dataPermission.GetDataScope("sys_post", table)
var count int
+2 -2
View File
@@ -2,7 +2,7 @@ package models
import (
orm "go-admin/database"
"go-admin/pkg/utils"
"go-admin/tools"
)
type SysRole struct {
@@ -50,7 +50,7 @@ func (e *SysRole) GetPage(pageSize int, pageIndex int) ([]SysRole, int, error) {
// 数据权限控制
dataPermission := new(DataPermission)
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
table = dataPermission.GetDataScope("sys_role", table)
var count int
+2 -2
View File
@@ -3,7 +3,7 @@ package models
import (
"fmt"
orm "go-admin/database"
"go-admin/pkg/utils"
"go-admin/tools"
)
type RoleMenu struct {
@@ -134,7 +134,7 @@ func (rm *RoleMenu) Insert(roleId int, menuId []int) (bool, error) {
}
func (rm *RoleMenu) Delete(RoleId string, MenuID string) (bool, error) {
rm.RoleId, _ = utils.StringToInt(RoleId)
rm.RoleId, _ = tools.StringToInt(RoleId)
table := orm.Eloquent.Table("sys_role_menu").Where("role_id = ?", RoleId)
if MenuID != "" {
table = table.Where("menu_id = ?", MenuID)
+7 -8
View File
@@ -5,10 +5,10 @@ import (
orm "go-admin/database"
"go-admin/pkg"
"go-admin/pkg/utils"
"go-admin/tools"
"golang.org/x/crypto/bcrypt"
"log"
"strings"
"golang.org/x/crypto/bcrypt"
)
// User
@@ -128,7 +128,6 @@ func (e *SysUser) Get() (SysUserView SysUserView, err error) {
func (e *SysUser) GetPage(pageSize int, pageIndex int) ([]SysUserPage, int, error) {
var doc []SysUserPage
table := orm.Eloquent.Select("sys_user.*,sys_dept.dept_name").Table(e.TableName())
table = table.Joins("left join sys_dept on sys_dept.dept_id = sys_user.dept_id")
if e.Username != "" {
@@ -136,12 +135,12 @@ func (e *SysUser) GetPage(pageSize int, pageIndex int) ([]SysUserPage, int, erro
}
if e.DeptId != 0 {
table = table.Where("sys_user.dept_id in (select dept_id from sys_dept where dept_path like ? )", "%"+utils.IntToString(e.DeptId)+"%")
table = table.Where("sys_user.dept_id in (select dept_id from sys_dept where dept_path like ? )", "%"+tools.IntToString(e.DeptId)+"%")
}
// 数据权限控制
dataPermission := new(DataPermission)
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
table = dataPermission.GetDataScope("sys_user", table)
var count int
@@ -221,16 +220,16 @@ func (e *SysUser) BatchDelete(id []int) (Result bool, err error) {
func (e *SysUser) SetPwd(pwd SysUserPwd) (Result bool, err error) {
user, _ := e.Get()
_, err = pkg.CompareHashAndPassword(user.Password, pwd.OldPassword)
_, err = tools.CompareHashAndPassword(user.Password, pwd.OldPassword)
if err != nil {
if strings.Contains(err.Error(), "hashedPassword is not the hash of the given password") {
pkg.HasError(err, "密码错误(代码202)", 500)
tools.HasError(err, "密码错误(代码202)", 500)
}
log.Print(err)
return
}
e.Password = pwd.NewPassword
_, err = e.Update(e.UserId)
pkg.HasError(err, "更新密码失败(代码202)", 500)
tools.HasError(err, "更新密码失败(代码202)", 500)
return
}
+3 -3
View File
@@ -2,8 +2,8 @@ package tools
import (
"errors"
"go-admin/config"
orm "go-admin/database"
config2 "go-admin/tools/config"
)
type DBColumns struct {
@@ -25,7 +25,7 @@ func (e *DBColumns) GetPage(pageSize int, pageIndex int) ([]DBColumns, int, erro
var doc []DBColumns
table := orm.Eloquent.Select("*").Table("information_schema.`COLUMNS`")
table = table.Where("table_schema= ? ", config.DatabaseConfig.Database)
table = table.Where("table_schema= ? ", config2.DatabaseConfig.Name)
if e.TableName != "" {
return nil, 0, errors.New("table name cannot be empty!")
@@ -46,7 +46,7 @@ func (e *DBColumns) GetList() ([]DBColumns, error) {
var doc []DBColumns
table := orm.Eloquent.Select("*").Table("information_schema.columns")
table = table.Where("table_schema= ? ", config.DatabaseConfig.Database)
table = table.Where("table_schema= ? ", config2.DatabaseConfig.Name)
if e.TableName == "" {
return nil, errors.New("table name cannot be empty!")
+3 -3
View File
@@ -2,8 +2,8 @@ package tools
import (
"errors"
"go-admin/config"
orm "go-admin/database"
config2 "go-admin/tools/config"
)
type DBTables struct {
@@ -20,7 +20,7 @@ func (e *DBTables) GetPage(pageSize int, pageIndex int) ([]DBTables, int, error)
var doc []DBTables
table := orm.Eloquent.Select("*").Table("information_schema.tables")
table = table.Where("table_schema= ? ", config.DatabaseConfig.Database)
table = table.Where("table_schema= ? ", config2.DatabaseConfig.Name)
if e.TableName != "" {
table = table.Where("TABLE_NAME = ?", e.TableName)
@@ -39,7 +39,7 @@ func (e *DBTables) Get() (DBTables, error) {
var doc DBTables
table := orm.Eloquent.Select("*").Table("information_schema.tables")
table = table.Where("table_schema= ? ", config.DatabaseConfig.Database)
table = table.Where("table_schema= ? ", config2.DatabaseConfig.Name)
if e.TableName == "" {
return doc, errors.New("table name cannot be empty!")
}