perf👌 : 部门和菜单功能改造

This commit is contained in:
zhangwenjian
2021-01-16 15:05:12 +08:00
parent c0f6fb6b41
commit 8a3659d949
11 changed files with 1002 additions and 37 deletions
+24 -24
View File
@@ -8,7 +8,7 @@ import (
"go-admin/tools"
)
type SysDept struct {
type SysDepts struct {
DeptId int `json:"deptId" gorm:"primary_key;auto_increment;"` //部门编码
ParentId int `json:"parentId" gorm:""` //上级部门
DeptPath string `json:"deptPath" gorm:"size:255;"` //
@@ -24,10 +24,10 @@ type SysDept struct {
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
Children []SysDept `json:"children" gorm:"-"`
Children []SysDepts `json:"children" gorm:"-"`
}
func (SysDept) TableName() string {
func (SysDepts) TableName() string {
return "sys_dept"
}
@@ -37,8 +37,8 @@ type DeptLable struct {
Children []DeptLable `gorm:"-" json:"children"`
}
func (e *SysDept) Create() (SysDept, error) {
var doc SysDept
func (e *SysDepts) Create() (SysDepts, error) {
var doc SysDepts
result := orm.Eloquent.Table(e.TableName()).Create(&e)
if result.Error != nil {
err := result.Error
@@ -46,7 +46,7 @@ func (e *SysDept) Create() (SysDept, error) {
}
deptPath := "/" + tools.IntToString(e.DeptId)
if int(e.ParentId) != 0 {
var deptP SysDept
var deptP SysDepts
orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP)
deptPath = deptP.DeptPath + deptPath
} else {
@@ -63,8 +63,8 @@ func (e *SysDept) Create() (SysDept, error) {
return doc, nil
}
func (e *SysDept) Get() (SysDept, error) {
var doc SysDept
func (e *SysDepts) Get() (SysDepts, error) {
var doc SysDepts
table := orm.Eloquent.Table(e.TableName())
if e.DeptId != 0 {
@@ -80,8 +80,8 @@ func (e *SysDept) Get() (SysDept, error) {
return doc, nil
}
func (e *SysDept) GetList() ([]SysDept, error) {
var doc []SysDept
func (e *SysDepts) GetList() ([]SysDepts, error) {
var doc []SysDepts
table := orm.Eloquent.Table(e.TableName())
if e.DeptId != 0 {
@@ -100,8 +100,8 @@ func (e *SysDept) GetList() ([]SysDept, error) {
return doc, nil
}
func (e *SysDept) GetPage(bl bool) ([]SysDept, error) {
var doc []SysDept
func (e *SysDepts) GetPage(bl bool) ([]SysDepts, error) {
var doc []SysDepts
table := orm.Eloquent.Table(e.TableName())
if e.DeptId != 0 {
@@ -133,10 +133,10 @@ func (e *SysDept) GetPage(bl bool) ([]SysDept, error) {
return doc, nil
}
func (e *SysDept) SetDept(bl bool) ([]SysDept, error) {
func (e *SysDepts) SetDept(bl bool) ([]SysDepts, error) {
list, err := e.GetPage(bl)
m := make([]SysDept, 0)
m := make([]SysDepts, 0)
for i := 0; i < len(list); i++ {
if list[i].ParentId != 0 {
continue
@@ -148,16 +148,16 @@ func (e *SysDept) SetDept(bl bool) ([]SysDept, error) {
return m, err
}
func Digui(deptlist *[]SysDept, menu SysDept) SysDept {
func Digui(deptlist *[]SysDepts, menu SysDepts) SysDepts {
list := *deptlist
min := make([]SysDept, 0)
min := make([]SysDepts, 0)
for j := 0; j < len(list); j++ {
if menu.DeptId != list[j].ParentId {
continue
}
mi := SysDept{}
mi := SysDepts{}
mi.DeptId = list[j].DeptId
mi.ParentId = list[j].ParentId
mi.DeptPath = list[j].DeptPath
@@ -168,7 +168,7 @@ func Digui(deptlist *[]SysDept, menu SysDept) SysDept {
mi.Email = list[j].Email
mi.Status = list[j].Status
mi.CreatedAt = list[j].CreatedAt
mi.Children = []SysDept{}
mi.Children = []SysDepts{}
ms := Digui(deptlist, mi)
min = append(min, ms)
@@ -177,14 +177,14 @@ func Digui(deptlist *[]SysDept, menu SysDept) SysDept {
return menu
}
func (e *SysDept) Update(id int) (update SysDept, err error) {
func (e *SysDepts) Update(id int) (update SysDepts, err error) {
if err = orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", id).First(&update).Error; err != nil {
return
}
deptPath := "/" + tools.IntToString(e.DeptId)
if int(e.ParentId) != 0 {
var deptP SysDept
var deptP SysDepts
orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP)
deptPath = deptP.DeptPath + deptPath
} else {
@@ -206,7 +206,7 @@ func (e *SysDept) Update(id int) (update SysDept, err error) {
return
}
func (e *SysDept) Delete(id int) (success bool, err error) {
func (e *SysDepts) Delete(id int) (success bool, err error) {
user := SysUser{}
user.DeptId = id
@@ -226,7 +226,7 @@ func (e *SysDept) Delete(id int) (success bool, err error) {
return
}
if err = tx.Table(e.TableName()).Where("dept_id = ?", id).Delete(&SysDept{}).Error; err != nil {
if err = tx.Table(e.TableName()).Where("dept_id = ?", id).Delete(&SysDepts{}).Error; err != nil {
success = false
tx.Rollback()
return
@@ -240,7 +240,7 @@ func (e *SysDept) Delete(id int) (success bool, err error) {
return
}
func (dept *SysDept) SetDeptLable() (m []DeptLable, err error) {
func (dept *SysDepts) SetDeptLable() (m []DeptLable, err error) {
deptlist, err := dept.GetList()
m = make([]DeptLable, 0)
@@ -258,7 +258,7 @@ func (dept *SysDept) SetDeptLable() (m []DeptLable, err error) {
return
}
func DiguiDeptLable(deptlist *[]SysDept, dept DeptLable) DeptLable {
func DiguiDeptLable(deptlist *[]SysDepts, dept DeptLable) DeptLable {
list := *deptlist
min := make([]DeptLable, 0)
+33
View File
@@ -0,0 +1,33 @@
package models
import "go-admin/common/models"
type SysDept struct {
DeptId int `json:"deptId" gorm:"primary_key;auto_increment;"` //部门编码
ParentId int `json:"parentId" gorm:""` //上级部门
DeptPath string `json:"deptPath" gorm:"size:255;"` //
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
Sort int `json:"sort" gorm:""` //排序
Leader string `json:"leader" gorm:"size:128;"` //负责人
Phone string `json:"phone" gorm:"size:11;"` //手机
Email string `json:"email" gorm:"size:64;"` //邮箱
Status string `json:"status" gorm:"size:4;"` //状态
models.ControlBy
models.ModelTime
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
Children []SysDept `json:"children" gorm:"-"`
}
func (SysDept) TableName() string {
return "sys_dept"
}
func (e *SysDept) Generate() models.ActiveRecord {
o := *e
return &o
}
func (e *SysDept) GetId() interface{} {
return e.DeptId
}
+64
View File
@@ -0,0 +1,64 @@
package models
import "go-admin/common/models"
type SysMenu struct {
MenuId int `json:"menuId" gorm:"primary_key;AUTO_INCREMENT"`
MenuName string `json:"menuName" gorm:"size:128;"`
Title string `json:"title" gorm:"size:128;"`
Icon string `json:"icon" gorm:"size:128;"`
Path string `json:"path" gorm:"size:128;"`
Paths string `json:"paths" gorm:"size:128;"`
MenuType string `json:"menuType" gorm:"size:1;"`
Action string `json:"action" gorm:"size:16;"`
Permission string `json:"permission" gorm:"size:255;"`
ParentId int `json:"parentId" gorm:"size:11;"`
NoCache bool `json:"noCache" gorm:"size:8;"`
Breadcrumb string `json:"breadcrumb" gorm:"size:255;"`
Component string `json:"component" gorm:"size:255;"`
Sort int `json:"sort" gorm:"size:4;"`
Visible string `json:"visible" gorm:"size:1;"`
IsFrame string `json:"isFrame" gorm:"size:1;DEFAULT:0;"`
models.ControlBy
models.ModelTime
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
RoleId int `gorm:"-"`
Children []SysMenu `json:"children" gorm:"-"`
IsSelect bool `json:"is_select" gorm:"-"`
}
type SysMenus struct {
MenuId int `json:"menuId" gorm:"column:menu_id;primary_key;"`
MenuName string `json:"menuName" gorm:"column:menu_name"`
Title string `json:"title" gorm:"column:title"`
Icon string `json:"icon" gorm:"column:icon"`
Path string `json:"path" gorm:"column:path"`
MenuType string `json:"menuType" gorm:"column:menu_type"`
Action string `json:"action" gorm:"column:action"`
Permission string `json:"permission" gorm:"column:permission"`
ParentId int `json:"parentId" gorm:"column:parent_id"`
NoCache bool `json:"noCache" gorm:"column:no_cache"`
Breadcrumb string `json:"breadcrumb" gorm:"column:breadcrumb"`
Component string `json:"component" gorm:"column:component"`
Sort int `json:"sort" gorm:"column:sort"`
Visible string `json:"visible" gorm:"column:visible"`
Children []SysMenu `json:"children" gorm:"-"`
models.ControlBy
models.ModelTime
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
}
func (SysMenu) TableName() string {
return "sys_menu"
}
func (e *SysMenu) Generate() models.ActiveRecord {
o := *e
return &o
}
func (e *SysMenu) GetId() interface{} {
return e.MenuId
}